Jump to content

UpdateVerticesData(positions) dose not update collisions


Suphi
 Share

Recommended Posts

Hi it's me again hope you guys don't mind me asking all these questions but i have a small problem.

So i have a custom mesh and the mesh is dynamic and needs to get updated so this is how i do it:

var positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
// edit positions
mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions);

Then when i moveWithCollisions the collisions are not updated.

I have worked out a few ways to update the collisions but i'm not sure what is the correct/fastest method

1) mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, true);
2) mesh.setIndices(mesh.getIndices());
3) mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions);

Whats the correct/fastest method?

Link to comment
Share on other sites

i just ran some tests and this is what i got

mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, false);
mesh.setIndices(mesh.getIndices());
around  0.13  milliseconds

mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, true);
around  0.70 milliseconds

mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions);
around  0.20 milliseconds

so from my tests looks like resetting the Indices is the fastest method is this the best way to do this it feels hacky

Link to comment
Share on other sites

OK this is super strange

updating indices does not update collisions correctly anymore

but mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, true); is now working when it was not before

i have no idea what i changed i think this is the correct way to do this it takes about 0.30 milliseconds 

 

EDIT*
mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, true);
is not working again i'm confused

Link to comment
Share on other sites

To trigger recompute of BoundingInfo, on which collisions are highly likely to be based, make sure the third parameter of updateVerticesData() is set to true.  If you decide to also recompute normals, there is a method in mesh, updateMeshPositions(), which can do do it automatically.  Unfortunately, it does not have a recompute BoundingInfo arg.  Perhaps edit it & PR, if you like.  Looks like there is also a bug in Geometry.updateVerticesData().  It probably should be ignoring updateExtends unless type is positions.

Link to comment
Share on other sites

Woot:) the best thing to do first is to provide a playground.

 

Basically, calling mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, true) should update the bounding info as you can see here:

https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.geometry.ts#L118

 

Link to comment
Share on other sites

OK this shows the problem: http://www.babylonjs-playground.com/#NTUKO#0

if we update the mesh inside registerBeforeRender collisions will not work correctly unless we setIndices again

--------------------------------

Also if we set updateExtends to false and setIndices then the collisions does a strange bouncing thing :P but this is not really a problem just showing it to you

http://www.babylonjs-playground.com/#NTUKO#1

Link to comment
Share on other sites

  • 7 months later...

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