Advertisement

Maxscript: Retrieving bone transformation (HELP! ANYONE?)

Started by May 30, 2010 05:47 PM
2 comments, last by unclebenz30 14 years, 6 months ago
I'm almost at the point where I can export bones properly.

Check out the relevant function:

function write_bones mesh file =-- writes bone related data to a file(		if mesh.modifiers[#skin] != undefined then	-- if there is a skin modifier	(		-- selecting the mesh and going into modify mode		-- is necessary for some of the following commands		select mesh		max modify mode						-- write out total bone count for the mesh		total_bone_count = skinops.getnumberbones mesh.modifiers[#skin]		writelong file total_bone_count #unsigned				for bone = 1 to total_bone_count do		-- loop through all the bones in this mesh		(			-- write out the name of this bone			bone_name = skinops.getbonename mesh.modifiers[#skin] bone 0			writestring file bone_name						-- retrieve the bone node by the name			bone_node = getnodebyname bone_name						controller = bone_node.position.controller;						for index = 1 to 2 do			(				-- write out keyframe count				keyframe_count = numkeys controller;				writelong file keyframe_count #unsigned							for keyframe = 1 to keyframe_count do				-- loop through all keyframes				(					-- get the time for this keyframe					keyframe_time = ( getkeytime controller keyframe ).frame as integer												-- write it to the file					writelong file keyframe_time #unsigned												-- retrieve the proper transform matrix for the bone					transform = bone_node.transform										if ( bone_node.parent != undefined ) then					-- if this isn't the root bone						-- apply the parent's transform on top						transform = transform * ( inverse ( bone_node.parent.transform ) )										if index == 1 then					-- if we are dealing with a positional keyframe					(						-- retrieve the translation (point)						translation = transform.translationpart											-- write out translation						at time keyframe_time writefloat file translation.x						at time keyframe_time writefloat file translation.y						at time keyframe_time writefloat file translation.z					)					else					-- we are dealing with a rotational keyframe					(						-- retrieve the rotation (quaternion)						rotation = transform.rotationpart;						-- write out rotation						at time keyframe_time writefloat file rotation.x						at time keyframe_time writefloat file rotation.y						at time keyframe_time writefloat file rotation.z						at time keyframe_time writefloat file rotation.w					)				)				controller = bone_node.rotation.controller;			)		)				for vertex = 1 to getnumverts mesh do		-- loop through all mesh vertices in this mesh		(			-- write out number of bones affecting this mesh vertex			vertex_bone_count = skinops.getvertexweightcount mesh.modifiers[#skin] vertex			writelong file vertex_bone_count #unsigned						for bone = 1 to vertex_bone_count do			-- loop through all the bones that affect this mesh vertex			(				-- write out the bone id for this mesh vertex				bone_id = skinops.getvertexweightboneid mesh.modifiers[#skin] vertex bone				writelong file bone_id #unsigned								-- write out the bone weight for this mesh vertex				weight = skinops.getvertexweight mesh.modifiers[#skin] vertex bone				writefloat file weight			)		)	)	else	-- there is no skin modifier		-- we have no bones		writelong file 0 #unsigned	)


It exports the proper timings and everything but for some reason all the actual transformation data (all the lines with "at time ...") contain the exact same values for a mesh that is animated.

What could cause this behavior? I've spend a day and haven't been able to find anything, I'm very new to Maxscript however, maybe somebody can point me in the right direction. I'm using 3ds Max 9 if that matters.

Thanks ahead of time.

[Edited by - d h k on June 8, 2010 12:37:34 PM]
One final bump as the thread just fell to the second page, I won't bump it again if nobody answers.

[rant]
Man, it is SOO hard to get ANY kind of support for Maxscript, I really don't get it. I've tried every forum there is for it (it feels like) and it's almost like nobody ever wrote an exporter with it that's capable of more than just pure vertices and indices. On the other hand, I KNOW that people do this all the time (and, as long as you don't need help, it's amazing). Really puzzled.
[/rant]

Any questions/interest/etc. is well appreciated. Let me know if you need more info too!
Advertisement
Been awhile since I've done Maxscript, and most of the exporters I've done have been using the actual MaxSDK (i.e. C++), but you should just be able to treat bones as regular INode instances in order to get their transform info - i.e., maybe trying to search for "Bone" related info in the docs is throwing you off course - just look for INode or whatever they call it. In order to sample the bones at different times you have to actually set the scene time: i.e., get the range of the scene timeline, start at the beginning, loop over all bone nodes to get their transform at that time, incremenet the scene time by whatever delta you want to sample at (30hz/60hz), then repeat until you've reached the end.
you may have found something now

if not

try :

sliderTime = keyframe_time;

before asking for the positions and orientations

by the way the max quaternions are left handed ,,as the matrices,,you will have to invert your quaternions to have proper right handed rotations

The art director of Big Fish's successful casual series Drawn explains how he married his non-gaming inspiration and outside perspective with his experiences and thoughts about the game industry to create a visually arresting adventure.





View the full article

This topic is closed to new replies.

Advertisement