Curved Poly – Shape Editor runtime support ?

Mushrooms Labs Q&ACategory: Curved Poly Shape EditorCurved Poly – Shape Editor runtime support ?
mun sungwon asked 5 years ago

Dear sirs,
 
I tested your
Curved Poly – Shape Editor.
it’s good.  do you support the runtime vertex moving ? 
I need the runtime modification function.
 
advice to me.
 
thanks
 
 
 

1 Answers
Alessandro MartinelliAlessandro Martinelli Staff answered 5 years ago

Yes, moving vertices at runtime is possible. But: It’s not yet documented.
The reason of this is simple: the core of Curved Poly runtime is a module named ShadowFramework (https://www.shadowframework.com), which is going to be released as Open Source software on github soon (as soon as possible, honestly speaking, i hope to get it ready before christmas). In the meantime, the core API controlling Curved Poly Tessellation is available, but not definitive.
I’ve prepared for you (and for everybody else) a simple code example showing how you can access and change vertices at runtime now, but please: keep in mind that this may change. The definitive API for Curved Poly Runtime ( covering CPRuntime.dll and ShadowFramework.dll ) will be out and documented with version 1.2 of Curved Poly Shape Editor (Version 1.1 of the Shape Editor was focused on the release on Curved Poly Maker). It will, indeed, be Open Source.
The code here shows how to move the first vertex of a Curved Poly at runtime with a simple oscillation using Math.sin.
using System;
using UnityEngine;
using MLab.CurvedPoly;
using MLabs.ShadowFramework.Interpolation;
class CurvedPolySampleBehaviour : MonoBehaviour
{
    public CurvedPoly curvedPoly;

    public void Update() {
        CurvedPolyAsset cpAsset = curvedPoly.curvedPoly;
       CurvedPolygonsNet curvedPolygonsNet = cpAsset.GetTessellationProcess(). GetCurvedPolygonsNet();
       Vector3[] vertices = curvedPolygonsNet.GetVertices();
       Vector3[] normals = curvedPolygonsNet.GetNormals();
       int numberOfVertices = curvedPolygonsNet.GetNumberOfVertices();
       //Here we only change the first vertex
       vertices[0].x = Mathf.Sin(Time.fixedTime*3);

       /*Need a reset, without reset any change on vertices is ignored*/
       curvedPolygonsNet.Reset();
       /*Call UpdateMesh on CurvedPoly*/
       curvedPoly.UpdateMesh(true);
   }
}
Notes:
    * using MLabs.ShadowFramework.Interpolation : This gives you access to the core tessellation features.
    * cpAsset.GetTessellationProcess(): return the tessellation process, which is responsible to recompute meshes at runtime (or in edit mode, it’s the same).
    * CurvedPolygonsNet :  This is the core runtime structure of a Curved Poly. It contains vertices, normals, edges, uvs, geometries and polygons.
    * Vector3[] vertices = curvedPolygonsNet.GetVertices(); : this is the complete list of raw vertices in the model. For example, if you use the ‘Sphere.asset’ primitive, it’a a list of 30 positions; numberOfVertices is the number of main vertices, which is 6 for the sphere asset. The other values are the position of the 24 handles, 2 for each of the 12 edges of the model.
    * Vector3[] normals = curvedPolygonsNet.GetNormals(); : if you want to change vertices, you may wish to change also normals. here you go. There is one normal for each vertex and one normal for each edge. So, if we take the ‘Sphere.asset’ primitive, we will find a total of 18 normals. The first 6 (numberOfVertices) are the normals of the main vertices, the other 12 are the normals of the 12 edges of the model.
    * curvedPolygonsNet.Reset(); : the tesellation process is optimized with a set of boolean variables which are used to tell it which part of a Curved Poly should be recomputed. With reset, you simply tell the process that everything needs an update. I could tell you how to exploit the optimized process, but it would take a long time and i prefer to do that once the API of the ShadowFramework will be fully documented and available on the site.
   * curvedPoly.UpdateMesh(true): in this way you are asking curvedpoly to update its mesh when possible. This is asynchronous, because the tessellation will take effect the next time the Update() method (of the curvedPolyBehaviour) is called by the system.
   * About Duplicated Vertices : you may find that some vertices are duplicated, depending on what primitive you are using. Duplicated veritces are present in primitives with unwraps and primitives with sharp parts. There are technical reasons for this, you can read Online Docs to know more about this. Follow this two links:   https://www.curvedpoly.com/guide/cpdocs/20#cpanatomy  and https://www.curvedpoly.com/guide/cpdocs/18#uvoperator.
 
If this answer was useful for you, please, consider giving a good review to the Asset on the Asset Store 🙂