jerome Posted January 29, 2015 Share Posted January 29, 2015 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 ) Quote Link to comment Share on other sites More sharing options...
Temechon Posted January 29, 2015 Share Posted January 29, 2015 Hi Jerome, Shameless auto-promotion : http://pixelcodr.com/tutos/trees/trees.html Hope it helps ! jerome, GameMonetize and jahow 3 Quote Link to comment Share on other sites More sharing options...
jerome Posted January 29, 2015 Author Share Posted January 29, 2015 Thank youLol for "shameless" (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 ? 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: Quote Link to comment Share on other sites More sharing options...
altreality Posted January 29, 2015 Share Posted January 29, 2015 http://playground.babylonjs.com/#1AVEYO#13 jerome 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted January 29, 2015 Author Share Posted January 29, 2015 thank you so much Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted January 29, 2015 Share Posted January 29, 2015 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.1https://googledrive.com/host/0B6-s6ZjHyEwUdHp3a3pJdlgwS0U see Automaton (old name), and Multi Grouphttps://googledrive.com/host/0B6-s6ZjHyEwUSDVBUGpHOXdtbHc for Voice syncing Quote Link to comment Share on other sites More sharing options...
jerome Posted January 29, 2015 Author Share Posted January 29, 2015 looks nicethough I don't know anything about Blender Quote Link to comment Share on other sites More sharing options...
jerome Posted January 30, 2015 Author Share Posted January 30, 2015 ok, I understant the code, so it answers my #2 initial question butstill #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 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted January 30, 2015 Share Posted January 30, 2015 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. Quote Link to comment Share on other sites More sharing options...
jerome Posted January 30, 2015 Author Share Posted January 30, 2015 ok I understand and agree with you what is the difference between updateVerticesDataDirectly() and updateVerticesData() ?something to do with the passing to the GPU ?seems very obscure to me Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted January 30, 2015 Share Posted January 30, 2015 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 arraysends it via webGLkeeps 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. jerome 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.