Jump to content

dynamic mesh deformation example wanted


jerome
 Share

Recommended Posts

Hello,

 

I would like to dynamically deform a mesh.

I mean, given a mesh, I just want its vertices to change position dynamically, not the face definitions.

 

I guess the Mesh object updateVerticesData() or updateVerticesDataDirectly() methods should be used.

But I don't know really how and if this kind of update will have the deformed mesh rendered at next frame without doing anything more ...

 

#1 : Is this the right way to achieve this kind of deformation ?

 

#2 : If yes, is there an example of these methods usage anywhere in the playground or somewhere else ?

( I have to admit I haven't yet finished to watch the 7 hours video tutorial, maybe it is talked about )

Link to comment
Share on other sites

Thank you

Lol for "shameless" :lol: (you should be proud of your work !)

 

I can't see you use updateVerticesData() in your code. Maybe it is not mandatory so ?

As far as I understand, you deform a sphere mesh once for the foliages and use then this initial deformation.  Or maybe, didn't I understand well ? :wacko:

 

I intend to dynamically, meaning each frame of the render loop, deform/update a mesh on the VertexBuffer.PositionKind basis.

As if the foliage deformation were computed and rendered the best way possible each frame ... ;)

 

Or imagine the radius of the tube mesh varying dynamically so we could show big lumps slide along the curve of the tube : http://www.html5gamedevs.com/topic/11772-tube-mesh/?p=69198 :lol: :lol: :lol: :lol:

Link to comment
Share on other sites

Have built a MORPH module, in extensions.  Is implemented from Blender shapekeys, preocessed by Tower of Babel exporter.  Morph 1.2 is under dev to make ready for Babylon 2.0.  Changes include:

  • Tower of Babel 2.0 (Mesh factory cloning, not for Morphing)
  • The POV BeforeRenderer pulled out into its own module  (sublcassed by MORPH)
  • Integrated with Web Audio (waiting for Sound.setAudioBuffer() method to be added)

Still here are three published examples based on 1.1

Link to comment
Share on other sites

ok, I understant the code, so it answers my #2 initial question :)

 

but

still #1 : Is this the best way to achieve this kind of deformation ?

 

this is a design pattern question ;)

 

I know we could use vertex shaders and they are the most powerful.

But it might be sometimes not that easy to pass structured data to the vertex shader (say, an array of js objects, each having different values for each different vertex).

 

So I'm looking for a way  :

- to keep indices, so the mesh remains "substantial"

- to change only positions according to some pure js logic, which may be as complex as needed

- not to dispose, delete objects (the mesh itself, and arrays) so the GC is not requested

- to optimize the full process just described : is it better to recreate from scratch the internal vertexData of a given mesh ? or use the updateVerticesData() ? or any other way ?

 

My deformations should happen each frame with no performance drops :huh:

Link to comment
Share on other sites

MORPH achieves its performance by building endpoints for positions & normals first (you can actually "compile" endpoints in advance).  Each beforeRender triggers an interpolation of positions / normals indices to change .  This is about as fast as you can get.

 

The full set of positions / normals is retransmitted up to the GPU using updateVerticesDataDirectly().  This requires that the data be in Float32Array. Everything is kept in that format to begin with.  This also limits GC.  Building throw away Float32Arrays every frame is an unnecessary drag.

 

Your requirement of

 

My deformations should happen each frame with no performance drops

 

is not the most realistic to "frame" it.  Better would be "deform as smoothly as possible in the exact amount of time allotted , on any hardware".

 

Interpolating the % of the deformation that should have occurred by then, allows the animation to catch up if behind & work good on different hardware.  Frame rate is a red herring.

Link to comment
Share on other sites

updateVerticesDataDirectly() is a short cut put in for MORPH (DeltaKosh, did not like the direct call to a public but low level method in Engine I was using).  It is newer than updateVerticesData().  Nothing is saved or destroyed.

 

Updating directly uses permanent Float32Arrays that are required to be sent by webGL to the GPU.  The older way takes a Javascript Array, inside the Heap and:

  • builds a throw away native memory array (Float32Array)
  • copies from the heap array to the native array
  • sends it via webGL
  • keeps a reference copy of the heap array in VertexBuffer, I think.

EDIT: updateVerticesDataDirectly() does actually destroy something, the copy of the Heap array var  in VertexBuffer past in from the original SetVerticesData() during initialization.

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...