Jump to content

Creating animation by switching between meshes/vertexdata


Nesh108
 Share

Recommended Posts

Hello!

I am working on importing an animation from http://voxelbuilder.com. There the animations are simply a set of frames which are switched in order.

So, if I want to create an animation with 3 meshes I should do:

1. Show 1st mesh for 1/3 of a second
2. Show 2nd mesh for 1/3 of a second
3. Show 3rd mesh for 1/3 of a second
4. Show 1st mesh again.

Logically that is fine but how can I do this properly?

From each mesh I have the following information:

vertexData.positions = positions;
vertexData.indices = indices;
vertexData.normals = normals;
vertexData.colors = colorlist;

Is it possible to create an animation by just setting the different indices/positions/normals/colors for each frame? It would be sweet if after `vertexData.applyToMesh(myMesh, true)` and `myMesh.bakeCurrentTransformIntoVertices()` I could also be able to start the animation with `scene.beginAnimation(myMesh, 0, 3, true, 1)`. 

Thanks! 

EDIT: To add more information: the amount of vertices, their positions and their uv's can drastically change from a frame to another, so the system should handle ANY mesh sequence and not the same vertices but in different positions.

Link to comment
Share on other sites

Have you considered using scene.registerAfterRender (or scene.registerBeforeRender) to do the animation.

This PG shows a very simple use http://www.babylonjs-playground.com/#92EYG#10

22 hours ago, Nesh108 said:

To add more information: the amount of vertices, their positions and their uv's can drastically change from a frame to another, so the system should handle ANY mesh sequence and not the same vertices but in different positions.

IMHO to do this you would need, in the registerAfterRender function call, to get the vertex data from the existing mesh, dispose the existing mesh and form new vertexdata by adjusting existing vertex data adding/subtracting new vertices and then create a new mesh with the new data. Everything I know currently about vertexdata for an existing mesh restricts you to updates only on the existing vertices.

You probably know this already but just in case here is a tutorial about creating a custom mesh

Good luck

EDIT as an alternative use a sequence of animations on your 3 meshes

http://babylonjsguide.github.io/basics/Starter

http://babylonjsguide.github.io/basics/Combine.html

http://babylonjsguide.github.io/gamelets/Sequence

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