struct AEMesh
(
vertices,
indices,
animations,
animationStrings,
maxMesh,
bones,
skinMod,
fn GenSkin =
(
mods = maxMesh.modifiers
-- look for the skin modifier
for i=1 to mods.count do
(
-- if the mesh has a skin modifier
if(classof mods as string == "Skin") then
(
skinMod = mods
modPanel.setCurrentObject maxMesh.modifiers -- Set the modify stack to the current object and the skin modifier
exit
)
)
if(classof skinMod as string != "Skin") then
return undefined -- Return if there is no skin modifier.
),
fn GenerateBones =
(
-- Set up and link the bones
if skinMod == 0 then
return undefined
boneCount = skinops.getNumberBones skinMod -- Get the number of bones from the skin modifier
for i=1 to boneCount do
(
boneName = skinops.GetBoneName skinMod i 1 -- Returns the name of the bone which is stored in the listbox
bone = AEBone name:boneName
boneObjName = skinops.GetBoneName skinMod i 0 -- Returns the actual name of the bone
boneNode = getNodeByName boneObjName -- Get the bone object in the scene based off of the name in the skin modifier
bone.boneObj = boneNode
if(boneNode.parent != undefined) then bone.parent = boneNode.parent
append bones bone
)
),
fn LinkBones =
(
for i = 1 to bones.count do
(
if bones.parent != undefined then
(
for j = 1 to bones.count do
(
if bones.parentBone == bones[j].boneObj then
bones.parent = bones[j]
)
if bones.parentBone == undefined then
bones.parent = undefined
)
)
)
)
-- A struct to hold the data needed for animations
struct AEAnimation
(
name,
begin,
end,
frames = AEFrame #(),
fn GenerateAnimation bones =
(
frames = #()
frameCount = end-begin+1
for i = 1 to framecount do
(
set time (begin+i-1)
frame = AEFrame #()
for b in bones do
(
if b.parent != undefined then
(
trans = copy b.parentBone.transforms
if export.coordinateSystem then
trans = (rightHanded trans)
trans = inverse trans
)
else
trans = matrix3 1
trans = b.boneObj.transform * trans
--trans = b.boneObj.transform
if export.coordinateSystem == 2 then
trans = (rightHanded trans)
-- Append the calculated transforms to the transform array
append frame.transforms trans
)
append frames frame
)
)
)
Max script and bones
Sorry, I don't know if this is the correct forum but I am having some problems with my Max Script and bone animation. I wrote an exporter which exports the vertices, indices, normals, and texcoords and all of those work fine for static meshes. I added bones which get the weights and boneIds and added those to my vertex structure. That appears to be working as well. I tested this by using the skinning shader which comes with the DirectX sdk and passing in an identity matrix as the transform for the bones.
Here is my script for generating bones, linking them up, and getting the bone transforms. I am new to skinning so I am fairly certain that I am multiplying the matrices wrong or not linking up the bones correctly.
Any help appreciated,
John
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement