Vertex Animation exporting from MAX

Moderators: GSH, VSMIT, Red Devil, Commando

User avatar
MrTwosheds
Recycler
Posts: 3059
Joined: Sat Feb 19, 2011 8:37 am
Location: Outer Space
Contact:

Re: Vertex Animation exporting from MAX

Post by MrTwosheds »

3dsMax 7
Does it every time.
User avatar
Nielk1
Flying Mauler
Posts: 2991
Joined: Fri Feb 18, 2011 10:35 pm
Contact:

Re: Vertex Animation exporting from MAX

Post by Nielk1 »

OK error understood now. I bet that that version of max doesn't support dotNetControls. That was used to create the multi-line text area to copy the text from. It needs another output method then. I will whip something up quick.

Try this, you will have to open the MaxScript Listener first and be sure you clear all the text out of it before you run this. It will add some extra crap too and even a " on either side of the bit you want, but you should be able to recognize what you will want to copy out and into the XSI vs the rest of the random output from the script.

Code: Select all

sXSIData = ""
envelopeCount = 0
setOfAll = $*
for obj in setOfAll do
(
	skinModifier = obj.modifiers[#skin]
	if (skinModifier != undefined) do -- check for skin modifier
	(
		PrepareMaxForSkinOps obj
		for i=1 to skinOps.GetNumberBones skinModifier do
		(
			envelopeCount += 1
			
			boneName = skinOps.GetBoneName skinModifier i 0
			
			sXSIData += "  SI_Envelope {\r\n"
			sXSIData += "    \"frm-" + obj.name + "\";\r\n"
			sXSIData += "    \"frm-" + boneName + "\";\r\n"
			
			vertArray = getAffectedVerts skinModifier i
			
			sXSIData += "    " + vertArray.count as string + ";\r\n"
			
			for j=1 to vertArray.count do
			(
				vertNumber = vertArray[j]
				vertNumber -= 1
				weight = getVertexWeightFromWorldBone skinModifier vertArray[j] i
				weight *= 100
				
				sXSIData += "    " + vertNumber as string + ";" + weight as string + ";,\r\n"
			)
			
			sXSIData += "  }\r\n"
		)
	)
)
	
if (envelopeCount > 0) then
(
	sXSIData = "SI_EnvelopeList {\r\n   " + envelopeCount as string + ";\r\n" + sXSIData + "}"

	print sXSIData
)

Function PrepareMaxForSkinOps _pNode =
(
	-- Select @_pNode if needed.
	if not _pNode.IsSelected do
	(
		Select _pNode
	)

	-- Unfreeze @_pNode if needed.
	if _pNode.IsFrozen do
	(
		Unfreeze _pNode DoLayer:true
	)

	-- Set Modify Panel active if needed.
	if GetCommandPanelTaskMode() != #modify do
	(
		SetCommandPanelTaskMode mode:#modify
	)

	-- Set @_pNode skin modifier as current object in modpanel if needed.
	if ModPanel.GetCurrentObject() != _pNode.skin do
	(
		ModPanel.SetCurrentObject _pNode.skin
	)
)

fn getAffectedVerts skinMod boneID=
(
	vertAr=#()
	numVerts=skinOps.getNumberVertices skinMod
	for i = 1 to numVerts do
	(
		numBoneAffectVert=skinOps.GetVertexWeightCount skinMod i
		
		for boneNum = 1 to numBoneAffectVert do
		(
			sysBoneID=skinOps.GetVertexWeightBoneID skinMod i boneNum
			if sysBoneID==boneID then append vertAr i
		)
	)
	vertAr
)

fn getVertexWeightFromWorldBone skinMod vertID boneID=
(
	weight = 0
	
	countBones = skinOps.GetVertexWeightCount skinMod vertID
	for i = 1 to countBones do
	(
		if boneID == skinOps.GetVertexWeightBoneID skinMod vertID i then
		(
			weight = skinOps.GetVertexWeight skinMod vertID i
			break
		)
	)
	
	weight
)
User avatar
MrTwosheds
Recycler
Posts: 3059
Joined: Sat Feb 19, 2011 8:37 am
Location: Outer Space
Contact:

Re: Vertex Animation exporting from MAX

Post by MrTwosheds »

Pasted into envelope.ms, opened maxscript listener, run script, nothing at all happens.
Got an Idiots guide?
User avatar
Nielk1
Flying Mauler
Posts: 2991
Joined: Fri Feb 18, 2011 10:35 pm
Contact:

Re: Vertex Animation exporting from MAX

Post by Nielk1 »

MrTwosheds wrote:Pasted into envelope.ms, opened maxscript listener, run script, nothing at all happens.
Got an Idiots guide?
You need to actually have skins and bones in the model. If you do, no idea. The print command should be working. Before it didn't die till it got to the line to generate the output display. Only thing I could do is try to do it remotely on your PC to see why it isn't working. I cant use that version of MAX here.
User avatar
MrTwosheds
Recycler
Posts: 3059
Joined: Sat Feb 19, 2011 8:37 am
Location: Outer Space
Contact:

Re: Vertex Animation exporting from MAX

Post by MrTwosheds »

You need to actually have skins and bones in the model
Which means what exactly? I had used the skin modifier, with ordinary objects, collapsed and saved, as a tutorial showed. I have seen mention of bones in places in Max, but as usual they are there in a "you already know how to use this so no logical layout is required" manner.
It does seem to me that the skin tool is very much designed with figure type models in mind, I had a fair amount of trouble getting it to do "Tank" :)
User avatar
Nielk1
Flying Mauler
Posts: 2991
Joined: Fri Feb 18, 2011 10:35 pm
Contact:

Re: Vertex Animation exporting from MAX

Post by Nielk1 »

Is the skin modifier still in the list, it sort of needs to be. You said collapsed. Technically you would want to collapse the modifier stack to just Editable Mesh, and then put the skin on top of that. If the skin is on top you can right click the option under it and tell it to collapse up to that point. The skin modifier still has to be in the list.
User avatar
MrTwosheds
Recycler
Posts: 3059
Joined: Sat Feb 19, 2011 8:37 am
Location: Outer Space
Contact:

Re: Vertex Animation exporting from MAX

Post by MrTwosheds »

Right that's what I did wrong then.
User avatar
MrTwosheds
Recycler
Posts: 3059
Joined: Sat Feb 19, 2011 8:37 am
Location: Outer Space
Contact:

Re: Vertex Animation exporting from MAX

Post by MrTwosheds »

Tried again, got this.

-- Error occurred in Obj loop
-- Frame:
-- skinModifier: Skin:Skin
-- Obj: $Editable_Mesh:turret_y @ [-0.000919,-0.547622,1.887849]
-- PrepareMaxForSkinOps: undefined
-- Error occurred during fileIn in <File:D:\3dsmax\scripts\envelope.ms>
>> MAXScript FileIn Exception: -- Type error: Call needs function or class, got: undefined <<
User avatar
Nielk1
Flying Mauler
Posts: 2991
Joined: Fri Feb 18, 2011 10:35 pm
Contact:

Re: Vertex Animation exporting from MAX

Post by Nielk1 »

MrTwosheds wrote:Tried again, got this.

-- Error occurred in Obj loop
-- Frame:
-- skinModifier: Skin:Skin
-- Obj: $Editable_Mesh:turret_y @ [-0.000919,-0.547622,1.887849]
-- PrepareMaxForSkinOps: undefined
-- Error occurred during fileIn in <File:D:\3dsmax\scripts\envelope.ms>
>> MAXScript FileIn Exception: -- Type error: Call needs function or class, got: undefined <<
It is saying that the function 'PrepareMaxForSkinOps' doesn't exist, but it does. it is one of the pile of functions on the bottom of the script.

That function selects the object then selects the skin modifier so that it can access its data.
User avatar
MrTwosheds
Recycler
Posts: 3059
Joined: Sat Feb 19, 2011 8:37 am
Location: Outer Space
Contact:

Re: Vertex Animation exporting from MAX

Post by MrTwosheds »

Does the capital S of SkinOps matter, some places it is S others s
User avatar
Nielk1
Flying Mauler
Posts: 2991
Joined: Fri Feb 18, 2011 10:35 pm
Contact:

Re: Vertex Animation exporting from MAX

Post by Nielk1 »

MrTwosheds wrote:Does the capital S of SkinOps matter, some places it is S others s
No, skinOps is a variable, PrepareMaxForSkinOps is a function.

EDIT: try this:

Code: Select all

sXSIData = ""
envelopeCount = 0
setOfAll = $*
for obj in setOfAll do
(
	skinModifier = obj.modifiers[#skin]
	if (skinModifier != undefined) do -- check for skin modifier
	(
		PrepareMaxForSkinOps obj
		for i=1 to skinOps.GetNumberBones skinModifier do
		(
			envelopeCount += 1
			
			boneName = skinOps.GetBoneName skinModifier i 0
			
			sXSIData += "  SI_Envelope {\r\n"
			sXSIData += "    \"frm-" + obj.name + "\";\r\n"
			sXSIData += "    \"frm-" + boneName + "\";\r\n"
			
			vertArray = getAffectedVerts skinModifier i
			
			sXSIData += "    " + vertArray.count as string + ";\r\n"
			
			for j=1 to vertArray.count do
			(
				vertNumber = vertArray[j]
				vertNumber -= 1
				weight = getVertexWeightFromWorldBone skinModifier vertArray[j] i
				weight *= 100
				
				sXSIData += "    " + vertNumber as string + ";" + weight as string + ";,\r\n"
			)
			
			sXSIData += "  }\r\n"
		)
	)
)
	
if (envelopeCount > 0) then
(
	sXSIData = "SI_EnvelopeList {\r\n   " + envelopeCount as string + ";\r\n" + sXSIData + "}"

	print sXSIData
)

fn PrepareMaxForSkinOps _pNode =
(
	-- Select @_pNode if needed.
	if not _pNode.IsSelected do
	(
		Select _pNode
	)

	-- Unfreeze @_pNode if needed.
	if _pNode.IsFrozen do
	(
		Unfreeze _pNode DoLayer:true
	)

	-- Set Modify Panel active if needed.
	if GetCommandPanelTaskMode() != #modify do
	(
		SetCommandPanelTaskMode mode:#modify
	)

	-- Set @_pNode skin modifier as current object in modpanel if needed.
	if ModPanel.GetCurrentObject() != _pNode.skin do
	(
		ModPanel.SetCurrentObject _pNode.skin
	)
)

fn getAffectedVerts skinMod boneID=
(
	vertAr=#()
	numVerts=skinOps.getNumberVertices skinMod
	for i = 1 to numVerts do
	(
		numBoneAffectVert=skinOps.GetVertexWeightCount skinMod i
		
		for boneNum = 1 to numBoneAffectVert do
		(
			sysBoneID=skinOps.GetVertexWeightBoneID skinMod i boneNum
			if sysBoneID==boneID then append vertAr i
		)
	)
	vertAr
)

fn getVertexWeightFromWorldBone skinMod vertID boneID=
(
	weight = 0
	
	countBones = skinOps.GetVertexWeightCount skinMod vertID
	for i = 1 to countBones do
	(
		if boneID == skinOps.GetVertexWeightBoneID skinMod vertID i then
		(
			weight = skinOps.GetVertexWeight skinMod vertID i
			break
		)
	)
	
	weight
)
If that doesn't work I have another idea.
User avatar
MrTwosheds
Recycler
Posts: 3059
Joined: Sat Feb 19, 2011 8:37 am
Location: Outer Space
Contact:

Re: Vertex Animation exporting from MAX

Post by MrTwosheds »

Did the same again.
-- Error occurred in Obj loop
-- Frame:
-- PrepareMaxForSkinOps: undefined
-- Obj: $Editable_Mesh:turret_y @ [-0.000919,7.422085,2.949151]
-- skinModifier: Skin:Skin
-- Error occurred during fileIn in <File:D:\3dsmax\scripts\envelope.ms>
>> MAXScript FileIn Exception: -- Type error: Call needs function or class, got: undefined <<
User avatar
Nielk1
Flying Mauler
Posts: 2991
Joined: Fri Feb 18, 2011 10:35 pm
Contact:

Re: Vertex Animation exporting from MAX

Post by Nielk1 »

Try this:

Code: Select all

sXSIData = ""
envelopeCount = 0
setOfAll = $*

fn PrepareMaxForSkinOps _pNode =
(
	-- Select @_pNode if needed.
	if not _pNode.IsSelected do
	(
		Select _pNode
	)

	-- Unfreeze @_pNode if needed.
	if _pNode.IsFrozen do
	(
		Unfreeze _pNode DoLayer:true
	)

	-- Set Modify Panel active if needed.
	if GetCommandPanelTaskMode() != #modify do
	(
		SetCommandPanelTaskMode mode:#modify
	)

	-- Set @_pNode skin modifier as current object in modpanel if needed.
	if ModPanel.GetCurrentObject() != _pNode.skin do
	(
		ModPanel.SetCurrentObject _pNode.skin
	)
)

fn getAffectedVerts skinMod boneID=
(
	vertAr=#()
	numVerts=skinOps.getNumberVertices skinMod
	for i = 1 to numVerts do
	(
		numBoneAffectVert=skinOps.GetVertexWeightCount skinMod i
		
		for boneNum = 1 to numBoneAffectVert do
		(
			sysBoneID=skinOps.GetVertexWeightBoneID skinMod i boneNum
			if sysBoneID==boneID then append vertAr i
		)
	)
	vertAr
)

fn getVertexWeightFromWorldBone skinMod vertID boneID=
(
	weight = 0
	
	countBones = skinOps.GetVertexWeightCount skinMod vertID
	for i = 1 to countBones do
	(
		if boneID == skinOps.GetVertexWeightBoneID skinMod vertID i then
		(
			weight = skinOps.GetVertexWeight skinMod vertID i
			break
		)
	)
	
	weight
)

for obj in setOfAll do
(
	skinModifier = obj.modifiers[#skin]
	if (skinModifier != undefined) do -- check for skin modifier
	(
		PrepareMaxForSkinOps obj
		for i=1 to skinOps.GetNumberBones skinModifier do
		(
			envelopeCount += 1
			
			boneName = skinOps.GetBoneName skinModifier i 0
			
			sXSIData += "  SI_Envelope {\r\n"
			sXSIData += "    \"frm-" + obj.name + "\";\r\n"
			sXSIData += "    \"frm-" + boneName + "\";\r\n"
			
			vertArray = getAffectedVerts skinModifier i
			
			sXSIData += "    " + vertArray.count as string + ";\r\n"
			
			for j=1 to vertArray.count do
			(
				vertNumber = vertArray[j]
				vertNumber -= 1
				weight = getVertexWeightFromWorldBone skinModifier vertArray[j] i
				weight *= 100
				
				sXSIData += "    " + vertNumber as string + ";" + weight as string + ";,\r\n"
			)
			
			sXSIData += "  }\r\n"
		)
	)
)
	
if (envelopeCount > 0) then
(
	sXSIData = "SI_EnvelopeList {\r\n   " + envelopeCount as string + ";\r\n" + sXSIData + "}"

	print sXSIData
)
User avatar
MrTwosheds
Recycler
Posts: 3059
Joined: Sat Feb 19, 2011 8:37 am
Location: Outer Space
Contact:

Re: Vertex Animation exporting from MAX

Post by MrTwosheds »

That worked! :D

Hmmm.

"SI_EnvelopeList {

etc


}
}"
Don't think the 2 " want to be there. Not greatly important as long as the user knows to not copy them.
User avatar
Nielk1
Flying Mauler
Posts: 2991
Joined: Fri Feb 18, 2011 10:35 pm
Contact:

Re: Vertex Animation exporting from MAX

Post by Nielk1 »

Yea they are there because of the sucky output method I had to use when the dotnetcontrol wasn't working for you.
Post Reply