Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python for 3ds max - Generate ripple deformation centered aroung referenced object
import math
from MaxPlus import Factory
from MaxPlus import ClassIds
from MaxPlus import INode
from MaxPlus import TriObject
from MaxPlus import Matrix3
from MaxPlus import Point3
# Intensity:
effecr_mult = 1.0
# Effect center:
effector = INode.GetINodeByName('Point001')
effect_pos = effector.GetWorldPosition()
# Prepare object and eccess it's mesh data:
node = INode.GetINodeByName('Box001')
new_edit_mesh_mod = Factory.CreateObjectModifier(ClassIds.Edit_Mesh)
node.AddModifier(new_edit_mesh_mod)
node.Collapse(True)
node_tm = node.GetWorldTM()
node_pos = node.GetWorldPosition()
obj = node.GetObject()
triobj = TriObject._CastFrom(obj)
mesh = triobj.GetMesh()
# Process the object's vertices:
for i in range(mesh.GetNumVertices()):
# Get vertex in world space
vert_pos = mesh.GetVertex(i)
vert_world_pos = node_tm.VectorTransform(vert_pos)
vert_world_pos = vert_world_pos + node_pos
# Get vertex distance from effect center:
diff_vec = vert_world_pos - effect_pos
diff_vec.Z = 0
dist = diff_vec.GetLength()
# Set new vertex position:
mesh.SetVert(i,vert_pos.X,vert_pos.Y,vert_pos.Z + math.sin(dist)*effecr_mult)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment