Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Path drawing
#2
Hi,
The PaintSpline script used in that scene does two things:
- Painting the spline
- Modifying the settings of the given controller, mainly setting the controller at the spline's start when a new spline is painted.
You can find bellow a modified version of that script. In this version, the script does only the painting. No controller is involved. This way you can use the script in your scene and set the controllers the way you like.
Code:
// =====================================================================
// Copyright 2013-2018 ToolBuddy
// All rights reserved
//
// http://www.toolbuddy.net
// =====================================================================

using UnityEngine;
using System.Collections;
using FluffyUnderware.Curvy;
using FluffyUnderware.DevTools.Extensions;
using FluffyUnderware.Curvy.Controllers;
using UnityEngine.UI;

/*
* In this example we let the user draw a spline on screen!
*
*/
namespace FluffyUnderware.Curvy.Examples
{
   public class PaintSpline : MonoBehaviour
   {
       public float StepDistance = 30;
       public Text InfoText;

       CurvySpline mSpline;
       Vector2 mLastControlPointPos;
       bool mResetSpline = true;

       void Awake()
       {
           // for this example we assume the component is attached to a GameObject holding a spline
           mSpline = GetComponent<CurvySpline>();
       }

       void OnGUI()
       {
           // before using the spline, ensure it's initialized and the Controller is available
           if (mSpline == null || !mSpline.IsInitialized)
               return;

           var e = Event.current;
           switch (e.type)
           {
               case EventType.MouseDrag:
                   // Start a new line?
                   if (mResetSpline)
                   {
                       mSpline.Clear(); // delete all Control Points
                       addCP(e.mousePosition); // add the first Control Point
                       mLastControlPointPos = e.mousePosition; // Store current mouse position
                       mResetSpline = false;
                   }
                   else
                   {
                       // only create a new Control Point if the minimum distance is reached
                       float dist = (e.mousePosition - mLastControlPointPos).magnitude;
                       if (dist >= StepDistance)
                       {
                           mLastControlPointPos = e.mousePosition;
                           addCP(e.mousePosition);
                       }
                   }

                   break;
               case EventType.MouseUp:
                   mResetSpline = true;

                   break;
           }
       }

       // Add a Control Point and set it's position
       CurvySplineSegment addCP(Vector3 mousePos)
       {
           Vector3 p = Camera.main.ScreenToWorldPoint(mousePos);
           p.y *= -1; // flip Y to get the correct world position
           p.z += 100; //To move further than camera's plane. The value 100 comes from the Canvas' plane distance
           var cp = mSpline.InsertAfter(null, p, false);

           InfoText.text = "Control Points: " + mSpline.ControlPointCount.ToString(); // set info text

           return cp;
       }
   }
}

Now about setting the controllers, you can do that though the inspector of course, but if you need some logic without coding, then you can use PlayMaker (which is an asset you should consider anyways if you want to make game logic without coding), it has a Curvy addon that allows you to setup controllers.

Now about painting a spline in 3D: the example scene's painting spline basically detects the position of mouse cursor in screen space, and creates the spline's control points accordingly. To do 3D painting is not just a coding problem, it's a game design one: how will you translate a mouse movement (2D) to 3D space? This isn't some easy question I can just send you a simple script to do, this is real feature coding that needs back and forth discussion between coder and game designer. I don't really see a solution to this problem that would not require a coder to be in your team.

Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Messages In This Thread
Path drawing - by Fraktalia - 04-30-2020, 03:44 PM
RE: Path drawing - by _Aka_ - 04-30-2020, 04:14 PM
RE: Path drawing - by Fraktalia - 04-30-2020, 05:42 PM
RE: Path drawing - by _Aka_ - 05-02-2020, 01:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rasterized Path Range issue proton 3 15 04-27-2024, 09:26 AM
Last Post: proton
  Incorrect mesh alignment after extrusion on curved path Thinkurvy 10 21 04-17-2024, 10:57 AM
Last Post: _Aka_
Wink Train carriage with 2 bogies following a path arcadeperfect 9 27 08-25-2023, 02:56 PM
Last Post: arcadeperfect
  Volume Spots not even when "drawing" spline too fast at runtime. _RicO 9 11 08-11-2023, 09:22 AM
Last Post: _Aka_

Forum Jump: