MaxScript – bake animation to vertex

Okay, so this was an attempt to transfer some animation into vertex positions and set key-frames on each vertex . Remove the animation at the end from the object itself, so that we  are left with “baked” vertices.  If you try to copy/paste and run this – probably a ton of errors will take place, but if you study this -> a lot of good can come out ( now this is mainly a personal note 😉 )

fn collectVertPosition geometryNode VertexList  = 
(
	for v=1 to (polyop.getNumVerts geometryNode) do
		(
			vertex = polyop.getVert geometryNode v
			append VertexList vertex
		)
)

fn getXYZlocation vertexList axis = 
(
	for v = 1 to vertexList.count do 
	(
		if (axis == "x" or axis == "X") then 
			(
				vertX = vertexList[v].x
				return vertX
			)
		if (axis == "y" or axis == "Y") then 
			(
				vertY = vertexList[v].y
				return vertY
			)
		if (axis == "z" or axis == "Z") then 
			(
				vertZ = vertexList[v].z
				return vertZ
			)
	)
)

fn updateXYZlocation vertList axis location = 
(
	for v = 1 to vertexList.count do 
	(
		if (axis == "x" or axis == "X") then 
			(
				vertexList[v].x = location
			)
		if (axis == "y" or axis == "Y") then 
			(
				vertexList[v].y = location
			)
		if (axis == "z" or axis == "Z") then 
			(
				vertexList[v].z = location
			)
	)
)

-------------------------
sliderTime = 0
--animateVertex $ #all
originalModel = $

------------------------------------------------------------
--Create TMP model and append to TMP Layer
targetMeshModel = copy originalModel
targetMeshModel.name = "baked_" + originalModel.name
targetAnimation = LayerManager.newLayer()
targetAnimation.setname "Baked_Animation"
targetAnimation.addnode targetMeshModel
----------------------------------------------------------
targetMeshModel = convertToMesh targetMeshModel
--targetMeshModel = convertToPoly targetMeshModel

sourceVertexList = #()
targetVertexList = #()

collectVertPosition originalModel sourceVertexList
collectVertPosition targetMeshModel targetVertexList

format "source Verts Count: %" sourceVertexList.count
format "target Verts Count: %" targetVertexList.count

--enable animation of the Vertex for Target Node
animateVertex targetMeshModel #all

--set keys to Target Node
with animate on
	(
		for frame=0 to 120 do 
		(
			for v = 1 to meshop.getNumVerts targetMeshModel do 
				(
					with animate on at time frame meshop.setVert targetMeshModel v sourceVertexList[v]
					x = getXYZlocation sourceVertexList "x"
					y = getXYZlocation sourceVertexList "y"
					z = getXYZlocation sourceVertexList "z"
					updateXYZlocation targetVertexList "x" x
					updateXYZlocation targetVertexList "y" y
					updateXYZlocation targetVertexList "z" z
				)
			sliderTime = frame
			sourceVertexList = #()
			collectVertPosition originalModel sourceVertexList
					
		)

	)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s