Last active
September 28, 2020 12:13
-
-
Save CGLion/22d18597cb7a8b4801d31ed7176ec9f9 to your computer and use it in GitHub Desktop.
Python for 3ds max - animate vertices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MaxPlus | |
import math | |
from MaxPlus import INode | |
from MaxPlus import TriObject | |
from MaxPlus import SelectionManager | |
from MaxPlus import Factory | |
from MaxPlus import Animation | |
from MaxPlus import Point3 | |
from MaxPlus import Control | |
ticks_frame = 160 | |
#Selection | |
sel = [] | |
for n in SelectionManager.Nodes: | |
sel.append(n) | |
node = sel[0] | |
#Setup Controllers | |
obj = node.GetObject() | |
Tri = TriObject._CastFrom(obj) | |
mesh = Tri.GetMesh() | |
num_verts = mesh.GetNumVertices() | |
mesh_anim = obj.GetSubAnim(0) | |
pnt_ctrl = Factory.CreateDefaultMasterPointController() | |
node.AssignController(pnt_ctrl,1) | |
for i in range(num_verts): | |
bezp3 = Factory.CreateDefaultPoint3Controller() | |
bezp3.SetPoint3Value(mesh.GetVertex(i)) | |
mesh_anim.AssignController(bezp3,i) | |
#Animation | |
Animation.SetAnimateButtonState(True) | |
for t in range(100): | |
time = t * ticks_frame | |
Animation.SetTime(time) | |
mesh_anim.AddNewKey(time,0) | |
for i in range(num_verts): | |
vert_anim = mesh_anim.GetSubAnim(i) | |
vert_ctrl = Control._CastFrom(vert_anim) | |
vert_val = mesh.GetVertex(i) | |
vert_val.SetZ(vert_val.GetZ() + math.sin(((Animation.GetTime()*0.5)/(ticks_frame))+i)) | |
vert_ctrl.SetPoint3Value(vert_val) | |
Animation.SetAnimateButtonState(False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment