Mesh Deformation

The script is available at the end of this post. Attach it to whatever object you want to be deformable. 

 

Until the release of Unity 3, I've stopped any work on this project as I'll most likely change it when Unity 3 is released, to be based on the new cloth/softbody feature instead. I'm releasing this simple, completely stable script now, which doesn't have that many features but could still be useful. 

Release Notes: 
File is attached to this post. Deforming meshes is fairly fast, but updating convexhulls is not. If you want to deform a lot of simple objects, it may be better not to update collision. 

(click image for a demo, older version but works the same way) 
 

current features: 

min force bellow which collisions are ignored 

multiplier the deformation value is the force of the collision * this. 

deform radius the radius of the deformation from a collision point. 

max deform 0 = n/a. this sets the maximum distance from it's original position that a vertex can move. 

bounce back speed 0 = no bounce back. this will make the object's mesh go back to it's original state after a while. pretty useful for giving an illusion of softbodies. 

bounce back sleep if all verts in a mesh are within this range from their original positions, bounce back will not be called until the mesh is deformed again. This means any number of objects can have bounce back in a scene without affecting the frame rate much at all, as long as they aren't being deformed at the time. 

on collision true will mean that this object deforms when it collides. 

update collider if this is enabled, and if the object has a mesh collider, the collider will be updated along with the mesh when it is deformed. Only works with the same mesh, not proxy meshes. Works with convexhulls, but updating convexhulls seems to be fairly slow. 

update collider on bounce if this is enabled, and if the object has a mesh collider, the collider will be updated along with the mesh as it bounces back. Only works with the same mesh, not proxy meshes. Works with convexhulls, but updating convexhulls seems to be fairly slow. This was separate from update collider originally so I could test it, but can be used separately to tweak for performance or other reasons. 

on call true will mean that other scripts can tell this object to deform a certain way by sending a point and a vector to represent a collision point and force. this is what a gun or other non-collider would use to tell it to deform. when telling the object to deform from another object, use whateverthe objectis you want to deform. Deform. Deform (somepointinworld,someforceinworld); 

 

 

转自:http://forum.unity3d.com/viewtopic.php?t=55588&highlight=mesh+deformation

代码下载链接:http://files.cnblogs.com/KidReborn/Deform.js

你可能感兴趣的:(format)