View Full Version : recalculating a deforming mesh
poopipe
03-16-2012, 02:31 PM
How do I persuade unity to recognise that a mesh has changed shape?
basically I'm trying to stick a box to the surface of a rippling plane
I've stolen the example code for deforming a mesh according to a sine wave but seem to be unable to get a raycast from the box to recognise the changing shape of the plane
I'm recalculating normals and bounds at the end of the mesh deformation script and couldn't see anything in the reference that said "recalculate where all the vertices and stuff are"
Am I missing something? I'm using free unity if that makes a difference
Thanks in advance :)
LoTekK
03-17-2012, 12:13 AM
if you're using the official examples (Procedural (http://unity3d.com/support/resources/example-projects/procedural-examples.html)), have a look at the "Sculpt Vertices" scene (in particular the "PaintVertices" script. From the looks of it, you have to reapply the new mesh to the mesh collider component for it to update that as well.
cupsster
03-17-2012, 03:19 AM
Procedural exmaples should work even with free version but I'm not sure if all of them
commander_keen
03-17-2012, 03:33 AM
You assign Mesh.vertices to modify the vertices. Note that you cannot assign individual elements of Mesh.vertices, you have to assign the entire array, for instance:
Vector3[] verts = myMesh.vertices;
verts[0] = new Vector3(0,10,0);
myMesh.vertices = verts;
poopipe
03-17-2012, 03:36 AM
Lotekk. a bit more reading suggested the same thing. im a little nervous about chucking that much data around on every update but its worth a pop.
Presumably i could use a lower res mesh collider and apply the ripple to that as well?
Cheers
LoTekK
03-17-2012, 06:22 AM
Lotekk. a bit more reading suggested the same thing. im a little nervous about chucking that much data around on every update but its worth a pop.
Presumably i could use a lower res mesh collider and apply the ripple to that as well?
Cheers
One thing you could try doing is sticking a rigidbody component on the mesh (sans gravity, etc). Physx apparently does an optimisation pass on collision, which is [initially] expensive to do, but I doesn't do this for rigidbodies, which should help the update loop.
poopipe
03-17-2012, 10:56 AM
Is that going to make a difference on phones? The theory is to put it out on android eventually
commander_keen
I have the deformation bit all sorted (didn't post back earlier as I was on my phone and edits are a pain), its getting a raycast to recognise that the mesh has changed that wasn't working out.
ill try lotekk's suggestion a little later - I'll also be looking into simply moving the box according to a kind of global sine wave thingy which i imagine will be a lot faster but will lose me quite a lot of useful information
poopipe
03-19-2012, 04:15 AM
Nice one chaps, that all worked great and with a little bit of additional mathematical magic I've now got a box happily driving over a rolling sea in response to mouse clicks.
vBulletin® v3.8.4, Copyright ©2000-2013, Jelsoft Enterprises Ltd.