Notifications
Clear all

[Closed] Combining boned objects

I’m trying to write a script that will handle the assembly of several boned and keyframed objects into a single object, for export into a game engine. Alas, for it is not working!

What I’m trying to do is copy the objects to a final master-object one at a time, adding their bones to the final object’s skin list in sequence, and weighting each new vertex in the final object rigidly to the bone that has just been added. A better, more sophisticated script would preserve bone weights, but what I’m doing is all rigid (object shattering as skeleton animation).

The result, unfortunately, seems to be bones that are weighted rigidly based on the original envelope weights. I’m not really sure why that is. Any assistance would be greatly appreciated.


--Initialize
	clearlistener()
	--This assumes the existence of a series of skinned and keyframed objects called Outgoing_1, Outgoing_2... Outgoing_n
	Incoming = $*Outgoing* as array
	j=0
	--I've been trying to run this several times in succesion, so I get rid of the last attempt here
	delete $*FC*
	delete $*Final
	delete $*Final_component
	Final_Component=editable_mesh()
	Final=editable_mesh()
	Final.name="Final"
	addmodifier final (Skin())
	select final
	finalskin =$.modifiers[#skin]
		
		
--Main Loop
for i in Incoming do (
	--Track iterations
	j=j+1
	--Get the number of verts in Final
		oldVerts = getNumVerts Final
	--Get the name of the bone of i as iBoneName
	select i
	iSkin = $.modifiers["skin"]
	SetCommandPanelTaskMode mode:#modify
	iBoneName= Skinops.GetBoneName iSkin 1 1 
	--Attach copy i to Final
		select i
		Final_Component= copy i
		Final_Component.name= "FC"+j as string
		select Final_Component
		attach Final Final_Component	
	-- Get the number of verts in Final
		newVerts = getNumVerts Final
	--Add i the bone of i to final skin bone list
	select final
	skinOps.addBone finalSkin (GetNodeByName(iBoneName)) 1
		--skin vert 100% to bone j
	--for oldverts to newverts in final
				for VertexNumber = (oldVerts+1) to newVerts do (
			--Get ready to do a skinop 
			select final 
			modpanel.setCurrentObject finalSkin
			--Set Vert to Rigid
			skinOps.rigidVertex finalSkin VertexNumber true
			--Skin Viert 100% to bone number j
                        --I /think/ this is what's going wrong.
			skinOps.SetVertexWeights finalSkin VertexNumber  j 1.0
		
			)	

	)

Failing this, is there a more elegant way to combine several meshes into one object, without losing keyframe and skinning information?