Home Unity

recalculating a deforming mesh

poopipe
grand marshal polycounter
Offline / Send Message
poopipe grand marshal polycounter
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 :)

Replies

  • LoTekK
    Options
    Offline / Send Message
    LoTekK polycounter lvl 17
    if you're using the official examples (Procedural), 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
    Options
    Offline / Send Message
    cupsster polycounter lvl 11
    Procedural exmaples should work even with free version but I'm not sure if all of them
  • commander_keen
    Options
    Offline / Send Message
    commander_keen polycounter lvl 18
    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
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
    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
    Options
    Offline / Send Message
    LoTekK polycounter lvl 17
    poopipe wrote: »
    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
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
    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
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
    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.
Sign In or Register to comment.