Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Artist placed control points.
#1
Hi There, 

Apologies in advance if the question has already been asked.  I have scan thru the threads but unable to find similar issue.

Instead of me creating the control points in Unity, the artist is exporting NULLs respresenting the spline (Catmull-Rom).
A single spline has around 30 control.
Eg:
SplinePath
- Node01
- Node02
- Node03
- ...

All the nodes are correctly named and arranged accordingly.

After importing the file into Unity, I selected all the gameObject (NULLs) and added the SplineSegment script in one go.  The parent spline pick up all the segment but it mixed up the ordering.
I can't trace the order because Spline script will rename the gameObjects to CP001, CP002...etc.
I have tried adding the SplineSegment script one by one, but it doesn't update itself and eventually changes the order as well.  

Is there a better way to setup the CurvySpline with artist exported nodes/NULLs? 
Or even having a script that can clone a CurySpline from an existing node hierarchy.
(I'm new to Unity, some pointer how to start would be great).

I'm expecting a number of splines in each level, so I can't see myself manually adding this in.

I'm running Curvy 1.60 and Unity 4.5.

kimc.

 

 

 
Reply
#2
Hi,

did you applied the editor script that forces Unity Editor to use alphasort like in previous versions? See here.

Instead of adding the CurvySplineSegment script to existing GameObjects and parent them to a spline, I would use a helper script that scans for your NULL GameObjects, take their positions and create a spline from it (or use an existing spline object and use Add(pos1,pos2,pos3....) to add the segments). Much like this thread.

Does that help?
Reply
#3
Hi Jake,

I don't really know what Unity Editor alphasort means.  
The empty nodes that my artist gave me are already sorted correctly when i brought them into Unity.
You second idea and link to other thread has given me the idea how to solve my problem. Thank you.

For everyone else benefit.
I have created a new menuItem (along the top of the menus) to clone the hierarchy of the gameObjects that represent the spline.





Code:
[MenuItem ("MyMenu/Create Curvy from GameOject")]
static void CreatCurvyFromGO()
{
// Get the active selected GameObject.
GameObject node = Selection.activeGameObject;
if (node != null)
{
// Get the number of children.
int childCount = node.transform.childCount;
if (childCount > 0)
{
// Create a new GameObject to host CurvySpline..
GameObject newSpline = new GameObject("Curvy "+node.name);
// Add CurvySpline to new GameObject
CurvySpline cs = newSpline.AddComponent<CurvySpline>;();

// Here you can apply some sorting here if required.
// My nodes already sorted correctly, so no sorting is required for me.
for (int i=0; i<childCount; i++)
{
Transform trans = node.transform.GetChild(i);
CurvySplineSegment css = cs.Add();
css.transform.position = trans.position;
css.transform.rotation = trans.rotation;
}
}
else
{
Debug.Log ("There is no child. No curvy spline created.");
}
}
else
{
Debug.Log ("There is no GameObject selected. No curvy spline created.");
}
}
(sorry the formatting is out of wack. I have wrap it around a code tag but still not showing correctly).


I believe you can just paste the code any where in your code (within a Monobehaviour class, and include "using UnityEditor" at the top) and Unity will just picked it up. 
(not 100% sure. it's the first time I did something with MenuItem).
 

 

 

 

Just found out I can just paste the code here. But my color scheme in MonoBehavour is dark, so the colors wont show up nicely here. 


[MenuItem ("MyMenu/Create Curvy from GameOject")]
    static void CreatCurvyFromGO() 
    {
        // Get the active selected GameObject.
        GameObject node = Selection.activeGameObject;
        if (node != null)
        {
            // Get the number of children.
            int childCount = node.transform.childCount;
            if (childCount > 0)
            {
                // Create a new GameObject to host CurvySpline..
                GameObject newSpline = new GameObject("Curvy "+node.name);
                // Add CurvySpline to new GameObject
                CurvySpline cs = newSpline.AddComponent<CurvySpline>;();

                // Here you can apply some sorting here if required.
                // My nodes already sorted correctlyso no sorting is required for me.
                for (int i=0i<childCounti++)
                {
                    Transform trans = node.transform.GetChild(i);
                    CurvySplineSegment css = cs.Add();
                    css.transform.position = trans.position;
                    css.transform.rotation = trans.rotation;
                }
            }
            else
            {
                Debug.Log ("There is no child.  No curvy spline created.");
            }
        }
        else
        {
            Debug.Log ("There is no GameObject selected. No curvy spline created.");
        }
    }

 

 
Reply
#4
That code looks fine. However, if I remember right you can't be sure that Transform.GetChild() gives you the gameobjects in the order you see in the hierarchy window (add a quick debug.log() to your loop to check that). Unity 4.5 adds the possibility to define the order in the hierarchy window itself (as well as by code). The "alphasort" script I linked forces Unity to use the "old" Unity sorting style.

So you have to do two things:
- add the script I linked somewhere in your project
- ensure you read your input nodes in right order

Jake
Reply
#5
Thanks Jake.  I'll keep that in mind.

I did the Debug.Log() and have inspected the order manually.  It worked fine for that file.  
I only have 1 file for now, once i have more files to work with I'll let you know how it goes (but that's probably months away).  

 
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Dummy spline points hnngaf 0 12 11-14-2019, 02:08 PM
Last Post: hnngaf
  Invert the spline points ? UsernameHed 1 147 09-21-2019, 03:22 PM
Last Post: _Aka_
  Equally spaced points on Bezier alanlawrance 2 327 08-07-2019, 04:52 PM
Last Post: alanlawrance
  How to get list of control points dazz777 1 450 05-22-2019, 02:12 PM
Last Post: _Aka_

Forum Jump: