Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Transform Gizmos into real 3d meshes
#1
Hi again Jake ! I'm making a game where the user will be able to draw roads.
Is there an easy way to transform the gizmos of the curvy line Scripts into real 3D meshes ?
The idea is to let the user modify/delete the shape.

Thanks in advance Smile

Seb
 
Edit :
For exemple I have a script (JS) attached to the Object containing the CurvyLine Script.
I would like to add by script a mesh renderer and a meshFilter to all the CP.
Something like that : GetComponent(typeof(CurvySpline)).ControlPoints[0].AddComponent(MeshRenderer); // Testing the first CP
but it does'nt work.

However your script in your online Manual works perfectly :
GetComponent(typeof(CurvySpline)).ControlPoints[1].Transform.position.x+=50;

Could you help me to find the way ? Thanks a lot (I'm pretty new with C#)
Reply
#2
Okay, I figured it out with a little script which allows me to create geometries and colliders on the childs when I create a new CP :
(But if there is an other way, it would be nice to know about it Smile )

function addMeshtoControlPoint (indexCP:int)
    {
        // On définit la taille du control point
        transform.GetChild(indexCP).gameObject.transform.localScale = new Vector3(10,10,10);
        // On ajoute le MeshFilter au child crée
        transform.GetChild(indexCP).gameObject.AddComponent(MeshFilter);
        // On injecte dans ce nouveau MeshFilter, le meshFilter de notre Sphere de reference
        transform.GetChild(indexCP).gameObject.GetComponent(MeshFilter).mesh = sphereMeshToUse.GetComponent(MeshFilter).sharedMesh;
        
        // On ajoute le meshCollider au child crée
        transform.GetChild(indexCP).gameObject.AddComponent(MeshCollider);
        
        // On ajoute le meshRenderer au child crée
        transform.GetChild(indexCP).gameObject.AddComponent(MeshRenderer);
}

 
Reply
#3
Hi,

instead of using GetChild, better store a reference to the Spline and access it's segments directly, like mySpline[2] to get the 2nd spline segment. If you want to access the CP's directly, use the mySpline.ControlPoints[] list.

Don't get confused: Control Points and Segments are more or less the same (a CurvySplineSegment component). The difference is that the term Segment refers to a visible spline part (=a CP and curve part ranging from there to the next CP), so if you have a nonclosed spline it has n segments and n+1 CP's.
Reply
#4
Thanks for this explanations Jake !!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Gizmos not showing in the editor 2019.3.1 & 3.6 athos_k 5 861 06-15-2020, 01:25 PM
Last Post: _Aka_
  Rigidbody or Transform Movement ATHellboy 10 2,730 02-04-2020, 08:37 PM
Last Post: _Aka_
  Bending meshes along splines digot 2 944 01-30-2020, 02:15 PM
Last Post: digot
  Generating Meshes ATHellboy 1 713 01-28-2020, 04:49 PM
Last Post: _Aka_

Forum Jump: