Jump to content

parametric shape update


jerome
 Share

Recommended Posts

Hi people,

 

All parametric shapes have now (once pending PR will be merged ;) ) their own update method.

Concerned mesh types : lines, ribbons, tubes and extruded shapes.

 

How does it work ?

When you create a parametric shape, you pass to the mesh CreateXXX() method one, or more, parameter(s) which will determines the final shape of your mesh.

Exemple : an axis path and a radius for a tube, a path of points for a line, a set of paths for a ribbon, a shape, an axis path, a scale and a rotation value for extrusion.

 

The CreateXXX() method then creates your mesh.

 

Until now, as it is quite impossible to know how or where the vertices were set in space after computation (because of the "parametric" aspect), it is very difficult to modify the created mesh.

The simplest, but not efficient way - especially in the render loop -, was then to destroy the mesh and to re-create another one with different parameter values.

 

From up now, you can modify an existing instance of a parametric shape. So no more deletion, re-creation, neither memory allocation.

 

Create your mesh as usual with your favorite CreateXXX() method (don't forget to set the updatable parameter to true)... and just re-use it with new values (path, radius, etc) and wtih the instance itself as last parameter :

var path1 = [v1, v2 ... vN];    // Vector3 arrayvar path2 = [u1, u2 ... uN];   // another Vector3 array// mesh creationvar lines = BABYLON.Mesh.CreateLines("lines", path1, scene, true); // mesh updatelines = BABYLON.Mesh.CreateLines(null, path2, null, null, null, lines);

As you can notice, the non-pertinent parameters for update (those which can't change the mesh shape) are just ignored, so I set them to null here for better readibility : name, scene, side orientation, updatable?

 

Of course, it works also with advanced methods such as ExtrudeShapeCustom() or CreateTube() when you pass your own functions as parameters (radiusFunction, scaleFunction, rotateFunction) instead of numeric values : you can update a mesh by updating your own functions !

 

These methods are quite optimized (I hope ! everything was tested and stressed) so you can use them in the render loop.

 

 

 

ahemmm... no PG this time... I let your imagination do the job :lol:

Link to comment
Share on other sites

documentation updated (pending for validation ;) ),

almost finished (still need the PG merge to code the PG examples)

 

Look for "how to dynamically morph a mesh ?" in the doc site : Tutorials / 04. More Advanced Features

Link to comment
Share on other sites

Did ya feel the POWER in that validation?  WOW!  When The Grand Wizard Curator validates something, boy, you KNOW it's been validated.  Notice how it took a few seconds for the room lights to return to full brightness?  *nod*.  That's a sure sign that a Level 9 curator has waved his validation wand. 

 

Wildlife and pets might act strangely for a few minutes.  They feel the Earth's core... still vibrating. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...