Jump to content
  • Advertisement
Sign in to follow this  
d h k

MAXscript: Getting vertex weights...

This topic is 3150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I use 3ds max 9 and its scripting language to export models into my custom file format. So far, everything is working great but I have one annoying problem: I can't seem to retrieve the weights for the (mesh) vertices.
-- write out bone count
bone_count = skinops.getnumberbones mesh.modifiers[#skin]
vertex_count = mesh.numverts --getnumvertices
	
for i = 1 to vertex_count do
-- loop through all mesh vertices in this mesh
(
	for bone = 1 to bone_count do
	-- loop through all bones in this mesh
	(
		skinops.getvertexweight mesh.modifiers[#skin] i bone
	)
)
On the skinops.getvertexweight line it tells me that it requires the skin modifier to be selected. Is that really true? If so, I'll have to figure out a way to make the script do this automatically I guess (which I haven't been able to so far) - however, if I manually select the skin modifier and then run the script, it actually complains:
-- Runtime error: Exceeded the vertex weight list countSkin:Skin
I start to wonder whether this is the correct approach to do this at all. I'm pretty new to MAXscript so please do go easy on me in case this is a redundant or trivial question. I have found cgtalk.com to be the most active MAXscript community but didn't get an answer over there, hopefully there are some people here who can. Thanks ahead of time. [Edited by - d h k on April 29, 2010 7:04:00 AM]

Share this post


Link to post
Share on other sites
Advertisement
One single bump for this. I could really use support here. I apologize for the bumping, I waited a long time and I won't do it again.

If _anybody_ has _any_ sort of idea or knowledge about the issue or even MAX script in general, I would _really_ appreciate any input. :D

So far, using MAX script to export into a custom model format is absolutely awesome and tons better than using 3ds, obj or x or even fbx but the support is horrible. I tried finding any good places for the scripting language but wasn't able to find any except for this place and cgtalk.com (where nobody answered either).

If you need more info/code/whatever, I'll share all that gladly. Just let me know!!

Share this post


Link to post
Share on other sites
This belongs in graphics since the people there will be much more knowledgeable about MaxScript. Ask the Moderator to move it for you.

-ddn

Share this post


Link to post
Share on other sites
First of all.... dont use max keywords as variable names.
bone
mesh

The problem you are having is that you are getting total number of bones used
in skin modifier. You want the total number of bones weighting a given vertex.
I updated your code to also switch to the modify panel. You should turn on
'Macro Recorder' so you can see all the commands Max is doing underneath.

---------------------------

msh = $body

select msh
max modify mode

-- get bone info
bones_total_count = skinops.getnumberbones msh.modifiers[#skin]
vertex_count = getNumverts msh --getnumvertices

-- loop through all mesh vertices in this mesh
for i = 1 to vertex_count do
(
-- loop through all bones affecting this vertex
vertex_bone_count = skinOps.GetVertexWeightCount msh.modifiers[#skin] i
for bn = 1 to vertex_bone_count do
(
weight = skinops.getvertexweight msh.modifiers[#skin] i bn
)
)

Share this post


Link to post
Share on other sites
Thanks for the move, Kylotan.

WOsborn: Wow! Thanks A TON! It's working, very nice. Super happy to finally have found somebody. :D r++

Now I'm figuring out what the best way to get the transformations for each of the total bones. I'm sure I'll get it by reading the manual - if there's an easy way, tho, and you have the time, feel free to put me on the right track.

Again, major thank you!

Share this post


Link to post
Share on other sites
I haven't written a skeleton exporter in a long time so this might be a little off.
For each bone you want to write its local position and rotation releative to
parent. The ROOT bone will be in world_space. For every CHILD bone you want to
take its transform and multiply against the inverse of its parents transform.
That will give you its local transform.

--------------------------------

trans = bn.transform
if ( bn.parent != undefined ) then
trans = trans * (inverse (bn.parent.transform))

t = trans.translationpart // point3
r = trans.rotationpart; // quat

--------------------------------

For animations I think you want to write the transform difference from the last frame.

Side Note:
You should look at Cal3D.
It's an easy to use skeletal animation library. It comes with maya/max exporters.
It's opensource so it is good for reference even if you don't end up using it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!