messed up Marshall's underscores from earlier

My bad :\  It's fixed now..

function CreateAlembicMetadataModifier selectedObject name value = (

	if selectedObject != undefined then (
		--only allow one modifier
		if selectedObject.modifiers["Alembic Metadata"] == undefined then (

			AlembicMetaDataModifier = EmptyModifier()
			AlembicMetaDataModifier.name = "Alembic Metadata"
			modCount = selectedObject.modifiers.count
			addmodifier selectedObject AlembicMetaDataModifier before:modCount
			selectedObject.modifiers["Alembic Metadata"].enabled = false
		)

		count = custattributes.count selectedObject.modifiers["Alembic Metadata"]
		count = count + 1

		evalstr = "AlembicMetadata = attributes AlembicMetadata\n" +
		"(\n" +
		"	parameters AlembicMetadataPRM1 rollout:AlembicMetadataRLT1\n" +
		"	(\n" +
		"		_name type:#string ui:eName default:\"" + name + "\"\n" +
		"		_value type:#string ui:eValue default:\"" + (value as string) + "\"\n" +
		"	)\n" +
		"	rollout AlembicMetadataRLT1 \"Alembic Metadata " + (count as string) + "\"\n" +
		"	(\n" +
		"		edittext eName \"n\" fieldWidth:120 labelOnTop:false\n" +
		"		edittext eValue \"v\" fieldWidth:120 labelOnTop:false\n" +
		"	)\n" +
		")"

		AlembicMetadata = execute(evalstr);

		custattributes.add selectedObject.modifiers["Alembic Metadata"] AlembicMetadata baseobject:false

	)
)

function ImportMetadata selectedObject metadataArray = (

	if selectedObject != undefined then
	(
		size = metadataArray.count/2
		a = 1
		for i = 1 to size do
		(
			name = metadataArray[a]
			a = a + 1
			value = metadataArray[a]
			a = a + 1
			CreateAlembicMetadataModifier selectedObject name value
		)

	)
)

---------------------------------------------------------------------------------------------------------
-- MacroScript to link the menu items to MAXScript functions

macroScript AlembicCreateMetadataModifier
    category:"Alembic"
    buttonText:"Add Alembic Metadata..."
    tooltip:"Add Alembic Metadata Display Modifier To Current Selection..."
(
    on execute do
    (
    	for i = 1 to selection.count do
    	(
    		CreateAlembicMetadataModifier selection[i] "" ""
    	)
    )
)

function CreateAlembicMetadataModifier selectedObject name value = (

	if selectedObject != undefined then (
		--only allow one modifier
		if selectedObject.modifiers["Alembic Metadata"] == undefined then (

			AlembicMetaDataModifier = EmptyModifier()
			AlembicMetaDataModifier.name = "Alembic Metadata"
			modCount = selectedObject.modifiers.count
			addmodifier selectedObject AlembicMetaDataModifier before:modCount
			selectedObject.modifiers["Alembic Metadata"].enabled = false
		)

		count = custattributes.count selectedObject.modifiers["Alembic Metadata"]
		count = count + 1

		evalstr = "AlembicMetadata = attributes AlembicMetadata\n" +
		"(\n" +
		"	parameters AlembicMetadataPRM1 rollout:AlembicMetadataRLT1\n" +
		"	(\n" +
		"		name type:#string ui:eName default:\"" + name + "\"\n" +
		"		value type:#string ui:eValue default:\"" + (value as string) + "\"\n" +
		"	)\n" +
		"	rollout AlembicMetadataRLT1 \"Alembic Metadata " + (count as string) + "\"\n" +
		"	(\n" +
		"		edittext eName \"n\" fieldWidth:120 labelOnTop:false\n" +
		"		edittext eValue \"v\" fieldWidth:120 labelOnTop:false\n" +
		"	)\n" +
		")"

		AlembicMetadata = execute(evalstr);

		custattributes.add selectedObject.modifiers["Alembic Metadata"] AlembicMetadata baseobject:false

	)
)

function ImportMetadata selectedObject metadataArray = (

	if selectedObject != undefined then
	(
		size = metadataArray.count/2
		a = 1
		for i = 1 to size do
		(
			name = metadataArray[a]
			a = a + 1
			value = metadataArray[a]
			a = a + 1
			CreateAlembicMetadataModifier selectedObject name value
		)

	)
)

---------------------------------------------------------------------------------------------------------
-- MacroScript to link the menu items to MAXScript functions

macroScript AlembicCreateMetadataModifier
    category:"Alembic"
    buttonText:"Add Alembic Metadata..."
    tooltip:"Add Alembic Metadata Display Modifier To Current Selection..."
(
    on execute do
    (
    	for i = 1 to selection.count do
    	(
    		CreateAlembicMetadataModifier selection[i] "" ""
    	)
    )
)


Erotoman added support to export bones movements in export_genmesh_skelanim.mcr

git-svn-id: 28d9401aa571d5108e51b194aae6f24ca5964c06@20463 8cc4aa7f-3514-0410-904f-f2cc9021211c

macroScript Export_GenMesh_Skelanim_CS
category:"Crystal Space"
internalcategory:"Crystal Space"
ButtonText:"Export GenMesh Skelanim CS"
tooltip:"Export GenMesh Skelanim CS" Icon:#("Maxscript",1)
(

rollout Test1 "Export GenMesh Skelanim to CS" width:238 height:345
(
	edittext edt3 "" pos:[17,32] width:192 height:21
	label lbl1 "Export GenMesh Skelanim To:" pos:[21,7] width:145 height:20
	button btn2 "Export!" pos:[42,110] width:152 height:24

	edittext edtScale "" pos:[57,68] width:50 height:27
	label lbl2 "Scale:" pos:[20,70] width:40 height:22

	on Test1 open do
	(
		edt3.text = "D:\\genmesh"
		edtScale.text = "1"
	)

	on btn2 pressed do
	(
		filename = edt3.text
		outFile = createFile filename
		debug=false
		global xscale = edtScale.text as Float
		global yscale = edtScale.text as Float
		global zscale = edtScale.text as Float

		global xrelocate = 0
		global yrelocate = 0
		global zrelocate = 0

		-- functions declaration
		global tokenize
		global export_bones_transform
		struct bone_vertex_weight (bone, v_idx, weight)
		struct vertex_convert_data (vtx_id, original_vtx_id)
		struct biped_transform (biped_name, pos, rotx, roty, rotz)

		-- Tokenize utility function
		fn tokenize instring sep =
		(
			outarray = #()
			temp=copy instring
			i = 1
			while (true) do
			(
				index = findstring temp sep
				if (index==undefined) then
				(
					outarray[i]=temp
					exit
				)
				else
				(
					outarray[i] = substring temp 1 (index-1)
					temp = substring temp (index+1) -1
				)
				i = i + 1
			)
			outarray
		)

		fn export_bones_transform obj bone_obj spd bones_verts outFile=
		(
			format "%<bone name=\"%\">\n" spd bone_obj.name to:outFile

			help_tr = undefined
			if (bone_obj.parent != undefined) then
			(
				local_rotation = (bone_obj.transform*(inverse bone_obj.parent.transform))as Quat
				local_position = bone_obj.transform.pos *(inverse bone_obj.parent.transform)
				rotvalues = quattoeuler local_rotation order:2

				local xMove = (local_position.x * xscale) + xrelocate
				local yMove = (local_position.y * yscale) + yrelocate
				local zMove = (local_position.z * zscale) + zrelocate
				format "%  <move>\n" spd to:outFile
				format "%    <v x=\"%\" y=\"%\" z=\"%\" />\n" spd xMove zMove yMove to:outFile

				rotx = (rotvalues.x * pi)/180
				roty = -((rotvalues.y) * pi)/180
				rotz = (rotvalues.z * pi)/180

				format "%    <matrix>\n" spd to:outFile
				format "%      <rotx>%</rotx>\n" spd rotx to:outFile
				format "%      <roty>%</roty>\n" spd roty to:outFile
				format "%      <rotz>%</rotz>\n" spd rotz to:outFile
				format "%    </matrix>\n" spd to:outFile
				format "%  </move>\n" spd to:outFile

				for bv in bones_verts do
				(
					if (bv.bone == bone_obj) then
						format "%  <vertex idx=\"%\" weight=\"%\"/>\n" spd bv.v_idx bv.weight to:outFile
				)
			)
			else
			(
				position = bone_obj.transform.pos
				local xMove = (position.x * xscale) + xrelocate
				local yMove =(position.y * yscale) + yrelocate
				local zMove = (position.z * zscale) + zrelocate

				format "%  <move>\n" spd to:outFile
				format "%    <v x=\"%\" y=\"%\" z=\"%\" />\n" spd xMove zMove yMove to:outFile

				rotation = bone_obj.transform as Quat
				rotvalues = quattoeuler rotation order:2
				rotx = (rotvalues.x * pi)/180
				roty = -((rotvalues.y) * pi)/180
				rotz = (rotvalues.z * pi)/180

				format "%    <matrix>\n" spd to:outFile
				format "%      <rotx>%</rotx>\n" spd rotx to:outFile
				format "%      <roty>%</roty>\n" spd roty to:outFile
				format "%      <rotz>%</rotz>\n" spd rotz to:outFile
				format "%    </matrix>\n" spd to:outFile
				format "%  </move>\n" spd to:outFile

				for bv in bones_verts do
				(
					if (bv.bone == bone_obj) then
						format "%  <vertex idx=\"%\" weight=\"%\"/>\n" spd bv.v_idx bv.weight to:outFile
				)
			)

			for child in bone_obj.children do
			(
				export_bones_transform obj child (spd + "  ") bones_verts outFile
			)
			format "%</bone>\n" spd to:outFile
		)

		obj = undefined
		slidertime = 0

		main_object_index = 0

		root_bone = undefined
		for i=1 to objects.count do
		(
			if ((classOf objects[i] == Biped_Object) and (objects[i].parent == undefined)) then
				root_bone = objects[i]
			if (classOf objects[i] == Editable_Mesh) then
				obj = objects[i]
		)

		--m = root_bone.transform.controller.figureMode = true
		-------------------------------------GENMESH--------------------------------------

		objectname = obj.name
		--image = obj.material.maps[2].filename
		--indx = tokenize image "\\"
		--materialname = indx[indx.count]
		materialname = "JPG"

		-- output name of object and some info
		format "\n\nFound Object Name: % Faces: %\n" objectname obj.numfaces

		-- write header
		format "  <meshfact name=\"%\">\n"objectname to: outFile
		format "    <plugin>crystalspace.mesh.loader.factory.genmesh</plugin>\n" to: outFile
		format "    <params>\n" to: outFile
		format "      <numvt>%</numvt>\n" (getNumTVerts obj) to: outFile
		format "      <numtri>%</numtri>\n" obj.numfaces to:outFile

		-- check texture
		if (getNumTVerts obj==0) then
		(
			message = "Export aborted: No UV maps assigned to genmesh object: " + obj.name
			messageBox message
			close outFile
			return 1
		)

		vertTInfo = #(getNumTVerts obj)
		vertTInfo[1] = undefined
		vertTInfoIndeces = #()
		vertTInfoTVIndeces = #(getNumTVerts obj)
		vertTInfoTVIndeces[1] = undefined

		-- cycle on all Faces of the object to get Tverts x,y,z positions
		for i=1 to obj.numfaces do
		(
			-- get face
			Tface = getTVFace obj i
			face = getFace obj i

			-- get its 3 vertices
			for h=1 to 3 do
			(
				curVert=getVert obj face[h]

				if (curVert==undefined) then
					format "\n\nUNDEF: %\n\n" Tface[h]
				if (debug) then
					format " face: % curVert %: %\n" i Tface[h] curVert

				-- if the value is different we have a problem on Welded UV
				if (vertTInfo[Tface[h]]!=undefined and vertTInfo[Tface[h]]!=curVert) then
				(

					message = "PROBLEM on object " + obj.name + ": welded UV on vertex " + (Tface[h] as String)
					messageBox message
					close outFile
					return 1
				)
				vertTInfo[Tface[h]]=curVert
				vertTInfoTVIndeces[Tface[h]] = face[h]
			)
		)

		-- cycle on all TVerts of the object
		for i =1 to (getNumTVerts obj) do
		(
			-- get its 3 vertices as a point3
			-- export in XZY format
			vert=vertTInfo[i]
			xvert = (vert.x * xscale) + xrelocate
			yvert = (vert.y * yscale) + yrelocate
			zvert = (vert.z * zscale) + zrelocate

			Tvert = getTVert obj i
			append vertTInfoIndeces (vertex_convert_data i vertTInfoTVIndeces[i])

			--format "        <v x=\"%\" y=\"%\" z=\"%\" u=\"%\" v=\"%\" /> %\n" xvert zvert yvert Tvert[1] (1-Tvert[2]) vertTInfoTVIndeces[i] to:outFile
			format "        <v x=\"%\" y=\"%\" z=\"%\" u=\"%\" v=\"%\" /> \n" xvert zvert yvert Tvert[1] (1-Tvert[2]) to:outFile
		)

		format "\n" to:outFile

		-- cycle on all faces of object
		for i =1 to obj.numFaces do
		(
			faceVerts=getTVface obj i
			a = (faceVerts[1]-1) as Integer
			b = (faceVerts[3]-1) as Integer
			c = (faceVerts[2]-1) as Integer

			--format "        <t v1=\"%\" v2=\"%\" v3=\"%\" />\n" a b c to:outFile
			format "        <t v1=\"%\" v2=\"%\" v3=\"%\" />\n" c b a to:outFile
		)

		format "    <autonormals />\n" to:outFile

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

		obj_physique = undefined
		for i = 1 to obj.modifiers.count do
		(
			if (classOf obj.modifiers[i] == Physique) then
			(
				obj_physique = obj.modifiers[i]
			)
		)

		bones_vertices =#()
		for v=1 to (getNumTVerts obj) do
		(
			original_vtx_id = undefined
			for vtx_data in vertTInfoIndeces do
			(
				if (v == vtx_data.vtx_id) then
					original_vtx_id = vtx_data.original_vtx_id
			)

			for b=1 to physiqueOps.getVertexBoneCount obj original_vtx_id do
			(
				bone = physiqueOps.getVertexBone obj original_vtx_id b
				weight = physiqueOps.getVertexWeight obj original_vtx_id b
				b_found = false
				for b in bones_vertices do
				(
					if ((b.bone == bone) and (b.v_idx == (v - 1))) then
					(
						b.weight = b.weight + weight
						b_found = true
					)
				)

				if (b_found == false) then
					append bones_vertices (bone_vertex_weight bone (v-1) weight )
			)
		)

		format "\n" to:outFile
		format "    <animcontrol plugin=\"crystalspace.mesh.anim.skeleton\">\n" to:outFile

		export_bones_transform obj root_bone "      " bones_vertices outFile

		format "\n" to:outFile
		format "      <script name=\"main\">\n" to:outFile

		----------------------ANIMATION SCRIPT---------------------------
		format "\n" to:outFile

		key_frame_times = #()
		for t in objects do
		(
			if ((classOf t) == Biped_Object) then
			(
				try
				(
					bip = t.transform.controller
					for t in bip.keys do
					(
						found = false
						for fr in key_frame_times do
						(
							if (t.time == fr) then
							(
								found = true
							)
						)
						if (found == false) then
							append key_frame_times t.time
					)
				)
				catch
				(
				)
			)
		)

		biped_transforms = #()
		sort key_frame_times

		for t in objects do
		(
			if ((classOf t) == Biped_Object) then
			(
				if (t.parent != undefined) then
				(
					biped_rotation = (t.transform*(inverse t.parent.transform))as Quat
					biped_position = t.transform.pos *(inverse t.parent.transform)
					rotvalues = quattoeuler biped_rotation order:2
					base_rotx = rotvalues.x
					base_roty = rotvalues.y
					base_rotz = rotvalues.z

					append biped_transforms (biped_transform t.name biped_position base_rotx base_roty base_rotz)
				)
				else
				(
					b_transform = t.transform
					biped_rotation = (b_transform) as Quat
					biped_position = b_transform.pos
					rotvalues = quattoeuler biped_rotation order:2
					base_rotx = rotvalues.x
					base_roty = rotvalues.y
					base_rotz = rotvalues.z
					append biped_transforms (biped_transform t.name biped_position base_rotx base_roty base_rotz)
				)
			)
		)

		--m = root_bone.transform.controller.figureMode = false

		for kf=2 to key_frame_times.count do
		(
			slidertime = key_frame_times[kf]
			duration = ((key_frame_times[kf] as integer - key_frame_times[kf - 1] as integer))/4 as integer
			biped_animation_found = false
			for t in objects do
			(
				--if ((classOf t) == Biped_Object and t.name == "Bip01 L Thigh") then
				if ((classOf t) == Biped_Object) then
				(
					biped_base_transform = undefined

					bp_index = 0
					for i=1 to biped_transforms.count do
					(
						if (biped_transforms[i].biped_name == t.name) then
						(
							bp_index = i
						)
					)

					biped_rotation = undefined
					biped_position = undefined
					if (t.parent != undefined) then
					(
						biped_rotation = (t.transform*(inverse t.parent.transform)) as Quat
						biped_position = t.transform.pos *(inverse t.parent.transform)
					)
					else
					(
						b_transform = t.transform
						biped_rotation = (b_transform) as Quat
						biped_position = b_transform.pos
					)

					write_x_rot = false
					write_y_rot = false
					write_z_rot = false

					new_rotvalues = quattoeuler biped_rotation order:2

					if abs(new_rotvalues.x - biped_transforms[bp_index].rotx) > 0.0001 then
						write_x_rot = true;
					if abs(new_rotvalues.y - biped_transforms[bp_index].roty) > 0.0001 then
						write_y_rot = true;
					if abs(new_rotvalues.z - biped_transforms[bp_index].rotz) > 0.0001 then
						write_z_rot = true;

					if write_x_rot or write_y_rot or write_z_rot then
					(
						biped_animation_found = true
						final_rotx = (new_rotvalues.x * pi)/180
						final_roty = -(new_rotvalues.y * pi)/180
						final_rotz = (new_rotvalues.z * pi)/180
						format "        <rot bone=\"%\" duration=\"%\" x=\"%\" y=\"%\" z=\"%\"/>\n" t.name duration final_rotx final_roty final_rotz to:outFile

					)

					write_x_rot = false
					write_y_rot = false
					write_z_rot = false
					if (abs(biped_position.x - biped_transforms[bp_index].pos.x) > 0.0001) then
						write_x_rot = true
					if (abs(biped_position.y - biped_transforms[bp_index].pos.y) > 0.0001) then
						write_y_rot = true
					if (abs(biped_position.z - biped_transforms[bp_index].pos.z) > 0.0001) then
						write_z_rot = true

					if write_x_rot or write_y_rot or write_z_rot then
					(
						biped_animation_found = true
						format "        <move bone=\"%\" duration=\"%\" x=\"%\" y=\"%\" z=\"%\"/>\n" t.name duration biped_position.x biped_position.z biped_position.y to:outFile
					)

					biped_transforms[bp_index].pos = biped_position
					biped_transforms[bp_index].rotx = new_rotvalues.x
					biped_transforms[bp_index].roty = new_rotvalues.y
					biped_transforms[bp_index].rotz = new_rotvalues.z
				)
			)
			if (biped_animation_found == true) then
				format "        <delay time=\"%\" />\n\n" duration to:outFile
		)

		format "\n" to:outFile
		-----------------------------------------------------------------

		format "        <repeat />\n" to:outFile
		format "      </script>\n" to:outFile
		format "      <run script=\"main\"/>\n" to:outFile
		format "    </animcontrol>\n" to:outFile
		format "  </params>\n" to:outFile
		format "</meshfact>\n" to:outFile

-------------------------------------------------------------------------------
		close outFile
		message = "Done!"
		messageBox message

	)
)

gw = newRolloutFloater "Export GenMesh Animation" 300 170
addRollout Test1 gw
)

macroScript Export_GenMesh_Skelanim_CS
category:"Crystal Space"
internalcategory:"Crystal Space"
ButtonText:"Export GenMesh Skelanim CS"
tooltip:"Export GenMesh Skelanim CS" Icon:#("Maxscript",1)
(

rollout Test1 "Export GenMesh Skelanim to CS" width:238 height:345
(
	edittext edt3 "" pos:[17,32] width:192 height:21
	label lbl1 "Export GenMesh Skelanim To:" pos:[21,7] width:145 height:20
	button btn2 "Export!" pos:[42,110] width:152 height:24

	edittext edtScale "" pos:[57,68] width:50 height:27
	label lbl2 "Scale:" pos:[20,70] width:40 height:22

	on Test1 open do
	(
		edt3.text = "D:\\genmesh"
		edtScale.text = "1"
	)

	on btn2 pressed do
	(
		filename = edt3.text
		outFile = createFile filename
		debug=false
		global xscale = edtScale.text as Float
		global yscale = edtScale.text as Float
		global zscale = edtScale.text as Float

		global xrelocate = 0
		global yrelocate = 0
		global zrelocate = 0

		-- functions declaration
		global tokenize
		global export_bones_transform
		struct bone_vertex_weight (bone, v_idx, weight)
		struct vertex_convert_data (vtx_id, original_vtx_id)
		struct biped_transform (biped_name, pos, rotx, roty, rotz)

		-- Tokenize utility function
		fn tokenize instring sep =
		(
			outarray = #()
			temp=copy instring
			i = 1
			while (true) do
			(
				index = findstring temp sep
				if (index==undefined) then
				(
					outarray[i]=temp
					exit
				)
				else
				(
					outarray[i] = substring temp 1 (index-1)
					temp = substring temp (index+1) -1
				)
				i = i + 1
			)
			outarray
		)

		fn export_bones_transform obj bone_obj spd bones_verts outFile=
		(
			format "%<bone name=\"%\">\n" spd bone_obj.name to:outFile

			help_tr = undefined
			if (bone_obj.parent != undefined) then
			(
				local_rotation = (bone_obj.transform*(inverse bone_obj.parent.transform))as Quat
				local_position = bone_obj.transform.pos *(inverse bone_obj.parent.transform)
				rotvalues = quattoeuler local_rotation order:2

				local xMove = (local_position.x * xscale) + xrelocate
				local yMove = (local_position.y * yscale) + yrelocate
				local zMove = (local_position.z * zscale) + zrelocate
				format "%  <move>\n" spd to:outFile
				format "%    <v x=\"%\" y=\"%\" z=\"%\" />\n" spd xMove zMove yMove to:outFile

				rotx = (rotvalues.x * pi)/180
				roty = -((rotvalues.y) * pi)/180
				rotz = (rotvalues.z * pi)/180

				format "%    <matrix>\n" spd to:outFile
				format "%      <rotx>%</rotx>\n" spd rotx to:outFile
				format "%      <roty>%</roty>\n" spd roty to:outFile
				format "%      <rotz>%</rotz>\n" spd rotz to:outFile
				format "%    </matrix>\n" spd to:outFile
				format "%  </move>\n" spd to:outFile

				for bv in bones_verts do
				(
					if (bv.bone == bone_obj) then
						format "%  <vertex idx=\"%\" weight=\"%\"/>\n" spd bv.v_idx bv.weight to:outFile
				)
			)
			else
			(
				position = bone_obj.transform.pos
				local xMove = (position.x * xscale) + xrelocate
				local yMove =(position.y * yscale) + yrelocate
				local zMove = (position.z * zscale) + zrelocate

				format "%  <move>\n" spd to:outFile
				format "%    <v x=\"%\" y=\"%\" z=\"%\" />\n" spd xMove zMove yMove to:outFile

				rotation = bone_obj.transform as Quat
				rotvalues = quattoeuler rotation order:2
				rotx = (rotvalues.x * pi)/180
				roty = -((rotvalues.y) * pi)/180
				rotz = (rotvalues.z * pi)/180

				format "%    <matrix>\n" spd to:outFile
				format "%      <rotx>%</rotx>\n" spd rotx to:outFile
				format "%      <roty>%</roty>\n" spd roty to:outFile
				format "%      <rotz>%</rotz>\n" spd rotz to:outFile
				format "%    </matrix>\n" spd to:outFile
				format "%  </move>\n" spd to:outFile

				for bv in bones_verts do
				(
					if (bv.bone == bone_obj) then
						format "%  <vertex idx=\"%\" weight=\"%\"/>\n" spd bv.v_idx bv.weight to:outFile
				)
			)

			for child in bone_obj.children do
			(
				export_bones_transform obj child (spd + "  ") bones_verts outFile
			)
			format "%</bone>\n" spd to:outFile
		)

		obj = undefined
		slidertime = 0

		main_object_index = 0

		root_bone = undefined
		for i=1 to objects.count do
		(
			if ((classOf objects[i] == Biped_Object) and (objects[i].parent == undefined)) then
				root_bone = objects[i]
			if (classOf objects[i] == Editable_Mesh) then
				obj = objects[i]
		)

		--m = root_bone.transform.controller.figureMode = true
		-------------------------------------GENMESH--------------------------------------

		objectname = obj.name
		--image = obj.material.maps[2].filename
		--indx = tokenize image "\\"
		--materialname = indx[indx.count]
		materialname = "JPG"

		-- output name of object and some info
		format "\n\nFound Object Name: % Faces: %\n" objectname obj.numfaces

		-- write header
		format "  <meshfact name=\"%\">\n"objectname to: outFile
		format "    <plugin>crystalspace.mesh.loader.factory.genmesh</plugin>\n" to: outFile
		format "    <params>\n" to: outFile
		format "      <numvt>%</numvt>\n" (getNumTVerts obj) to: outFile
		format "      <numtri>%</numtri>\n" obj.numfaces to:outFile

		-- check texture
		if (getNumTVerts obj==0) then
		(
			message = "Export aborted: No UV maps assigned to genmesh object: " + obj.name
			messageBox message
			close outFile
			return 1
		)

		vertTInfo = #(getNumTVerts obj)
		vertTInfo[1] = undefined
		vertTInfoIndeces = #()
		vertTInfoTVIndeces = #(getNumTVerts obj)
		vertTInfoTVIndeces[1] = undefined

		-- cycle on all Faces of the object to get Tverts x,y,z positions
		for i=1 to obj.numfaces do
		(
			-- get face
			Tface = getTVFace obj i
			face = getFace obj i

			-- get its 3 vertices
			for h=1 to 3 do
			(
				curVert=getVert obj face[h]

				if (curVert==undefined) then
					format "\n\nUNDEF: %\n\n" Tface[h]
				if (debug) then
					format " face: % curVert %: %\n" i Tface[h] curVert

				-- if the value is different we have a problem on Welded UV
				if (vertTInfo[Tface[h]]!=undefined and vertTInfo[Tface[h]]!=curVert) then
				(

					message = "PROBLEM on object " + obj.name + ": welded UV on vertex " + (Tface[h] as String)
					messageBox message
					close outFile
					return 1
				)
				vertTInfo[Tface[h]]=curVert
				vertTInfoTVIndeces[Tface[h]] = face[h]
			)
		)

		-- cycle on all TVerts of the object
		for i =1 to (getNumTVerts obj) do
		(
			-- get its 3 vertices as a point3
			-- export in XZY format
			vert=vertTInfo[i]
			xvert = (vert.x * xscale) + xrelocate
			yvert = (vert.y * yscale) + yrelocate
			zvert = (vert.z * zscale) + zrelocate

			Tvert = getTVert obj i
			append vertTInfoIndeces (vertex_convert_data i vertTInfoTVIndeces[i])

			--format "        <v x=\"%\" y=\"%\" z=\"%\" u=\"%\" v=\"%\" /> %\n" xvert zvert yvert Tvert[1] (1-Tvert[2]) vertTInfoTVIndeces[i] to:outFile
			format "        <v x=\"%\" y=\"%\" z=\"%\" u=\"%\" v=\"%\" /> \n" xvert zvert yvert Tvert[1] (1-Tvert[2]) to:outFile
		)

		format "\n" to:outFile

		-- cycle on all faces of object
		for i =1 to obj.numFaces do
		(
			faceVerts=getTVface obj i
			a = (faceVerts[1]-1) as Integer
			b = (faceVerts[3]-1) as Integer
			c = (faceVerts[2]-1) as Integer

			--format "        <t v1=\"%\" v2=\"%\" v3=\"%\" />\n" a b c to:outFile
			format "        <t v1=\"%\" v2=\"%\" v3=\"%\" />\n" c b a to:outFile
		)

		format "    <autonormals />\n" to:outFile

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

		obj_physique = undefined
		for i = 1 to obj.modifiers.count do
		(
			if (classOf obj.modifiers[i] == Physique) then
			(
				obj_physique = obj.modifiers[i]
			)
		)

		bones_vertices =#()
		for v=1 to (getNumTVerts obj) do
		(
			original_vtx_id = undefined
			for vtx_data in vertTInfoIndeces do
			(
				if (v == vtx_data.vtx_id) then
					original_vtx_id = vtx_data.original_vtx_id
			)

			for b=1 to physiqueOps.getVertexBoneCount obj original_vtx_id do
			(
				bone = physiqueOps.getVertexBone obj original_vtx_id b
				weight = physiqueOps.getVertexWeight obj original_vtx_id b
				b_found = false
				for b in bones_vertices do
				(
					if ((b.bone == bone) and (b.v_idx == (v - 1))) then
					(
						b.weight = b.weight + weight
						b_found = true
					)
				)

				if (b_found == false) then
					append bones_vertices (bone_vertex_weight bone (v-1) weight )
			)
		)

		format "\n" to:outFile
		format "    <animcontrol plugin=\"crystalspace.mesh.anim.skeleton\">\n" to:outFile

		export_bones_transform obj root_bone "      " bones_vertices outFile

		format "\n" to:outFile
		format "      <script name=\"main\">\n" to:outFile

		----------------------ANIMATION SCRIPT---------------------------
		format "\n" to:outFile

		key_frame_times = #()
		for t in objects do
		(
			if ((classOf t) == Biped_Object) then
			(
				try
				(
					bip = t.transform.controller
					for t in bip.keys do
					(
						found = false
						for fr in key_frame_times do
						(
							if (t.time == fr) then
							(
								found = true
							)
						)
						if (found == false) then
							append key_frame_times t.time
					)
				)
				catch
				(
				)
			)
		)

		biped_transforms = #()
		sort key_frame_times

		for t in objects do
		(
			if ((classOf t) == Biped_Object) then
			(
				if (t.parent != undefined) then
				(
					biped_rotation = (t.transform*(inverse t.parent.transform))as Quat
					biped_position = t.transform.pos *(inverse t.parent.transform)
					rotvalues = quattoeuler biped_rotation order:2
					base_rotx = rotvalues.x
					base_roty = rotvalues.y
					base_rotz = rotvalues.z

					append biped_transforms (biped_transform t.name biped_position base_rotx base_roty base_rotz)
				)
				else
				(
					b_transform = t.transform
					biped_rotation = (b_transform) as Quat
					biped_position = b_transform.pos
					rotvalues = quattoeuler biped_rotation order:2
					base_rotx = rotvalues.x
					base_roty = rotvalues.y
					base_rotz = rotvalues.z
					append biped_transforms (biped_transform t.name biped_position base_rotx base_roty base_rotz)
				)
			)
		)

		--m = root_bone.transform.controller.figureMode = false

		for kf=2 to key_frame_times.count do
		(
			slidertime = key_frame_times[kf]
			duration = ((key_frame_times[kf] as integer - key_frame_times[kf - 1] as integer))/4 as integer
			biped_animation_found = false
			for t in objects do
			(
				--if ((classOf t) == Biped_Object and t.name == "Bip01 L Thigh") then
				if ((classOf t) == Biped_Object) then
				(
					biped_base_transform = undefined

					bp_index = 0
					for i=1 to biped_transforms.count do
					(
						if (biped_transforms[i].biped_name == t.name) then
						(
							bp_index = i
						)
					)

					biped_rotation = undefined
					biped_position = undefined
					if (t.parent != undefined) then
					(
						biped_rotation = (t.transform*(inverse t.parent.transform)) as Quat
						biped_position = t.transform.pos *(inverse t.parent.transform)
					)
					else
					(
						b_transform = t.transform
						biped_rotation = (b_transform) as Quat
						biped_position = b_transform.pos
					)

					write_x_rot = false
					write_y_rot = false
					write_z_rot = false

					new_rotvalues = quattoeuler biped_rotation order:2

					if abs(new_rotvalues.x - biped_transforms[bp_index].rotx) > 0.0001 then
						write_x_rot = true;
					if abs(new_rotvalues.y - biped_transforms[bp_index].roty) > 0.0001 then
						write_y_rot = true;
					if abs(new_rotvalues.z - biped_transforms[bp_index].rotz) > 0.0001 then
						write_z_rot = true;

					if write_x_rot or write_y_rot or write_z_rot then
					(
						biped_animation_found = true
						final_rotx = (new_rotvalues.x * pi)/180
						final_roty = -(new_rotvalues.y * pi)/180
						final_rotz = (new_rotvalues.z * pi)/180
						format "        <rot bone=\"%\" duration=\"%\" x=\"%\" y=\"%\" z=\"%\"/>\n" t.name duration final_rotx final_roty final_rotz to:outFile
					)

					biped_transforms[bp_index].rotx = new_rotvalues.x
					biped_transforms[bp_index].roty = new_rotvalues.y
					biped_transforms[bp_index].rotz = new_rotvalues.z
				)
			)
			if (biped_animation_found == true) then
				format "        <delay time=\"%\" />\n\n" duration to:outFile
		)

		format "\n" to:outFile
		-----------------------------------------------------------------

		format "        <repeat />\n" to:outFile
		format "      </script>\n" to:outFile
		format "      <run script=\"main\"/>\n" to:outFile
		format "    </animcontrol>\n" to:outFile
		format "  </params>\n" to:outFile
		format "</meshfact>\n" to:outFile

-------------------------------------------------------------------------------
		close outFile
		message = "Done!"
		messageBox message

	)
)

gw = newRolloutFloater "Export GenMesh Animation" 300 170
addRollout Test1 gw
)


fixes #124 - removed visibility option from import UI

---------------------------------------------------------------------------------------------------------
-- Custom import/export dialog with settings

rollout AlembicImportSettings "Alembic Import Settings" width:288 height:150
(
    local filename

	GroupBox geoGroup "Geometry" pos:[8,8] width:272 height:104
	checkbox normalCheckbox "Normals" pos:[48,32] width:200 height:15 checked:true
	checkbox uvCheckbox "UVs" pos:[48,48] width:200 height:15 checked:true
    --checkbox clustersCheckbox "Clusters" pos:[48,64] width:200 height:15 checked:true
	checkbox attachCheckbox "Attach to existing objects" pos:[48,64] width:200 height:15 checked:true

	button importButton "Import" pos:[16,120] width:64 height:24
	button cancelButton "Cancel" pos:[208,120] width:64 height:24
	--GroupBox grpVisibility "Visibility" pos:[9,121] width:272 height:46
	--dropdownList dropDownVis "" pos:[20,140] width:252 height:21 items:#("Just Import Value", "Connected Controllers") selection:1
	checkbox materialIdsCheckbox "Material Ids" pos:[48,82] width:145 height:16 checked:true

	on importButton pressed do
	(
	    result = ExocortexAlembic.import filename normalCheckbox.checked uvCheckbox.checked materialIdsCheckbox.checked attachCheckbox.checked 0
	    if( result != 0 ) do
	    (
	    	messageBox "Failure - See Maxscript Listener for details." title:"Exocortex Alembic Import"
	    )
		destroyDialog AlembicImportSettings
	)
	on cancelButton pressed do
	(
	    destroyDialog AlembicImportSettings
	)
)
---------------------------------------------------------------------------------------------------------
-- MAXScript functions to bring up the options dialogs

fn alembicImportDialog =
(
    filename = getOpenFileName caption:"Import from Alembic File:" types:"Alembic(*.abc)|*.abc|All(*.*)|*.*" historyCategory:"Alembic"
    if (filename != undefined) do
    (
        createDialog AlembicImportSettings
        AlembicImportSettings.filename = filename
    )
)

---------------------------------------------------------------------------------------------------------
-- MacroScript to link the menu items to MAXScript functions

macroScript AlembicImportUI
    category:"Alembic"
    buttonText:"Alembic Import..."
    tooltip:"Alembic Import..."
(
    on execute do
    (
        alembicImportDialog()
    )
)

---------------------------------------------------------------------------------------------------------
-- Custom import/export dialog with settings

rollout AlembicImportSettings "Alembic Import Settings" width:288 height:236
(
    local filename

	GroupBox geoGroup "Geometry" pos:[8,8] width:272 height:104
	checkbox normalCheckbox "Normals" pos:[48,32] width:200 height:15 checked:true
	checkbox uvCheckbox "UVs" pos:[48,48] width:200 height:15 checked:true
    --checkbox clustersCheckbox "Clusters" pos:[48,64] width:200 height:15 checked:true
	checkbox attachCheckbox "Attach to existing objects" pos:[48,64] width:200 height:15 checked:true

	button importButton "Import" pos:[16,200] width:64 height:24
	button cancelButton "Cancel" pos:[208,200] width:64 height:24
	GroupBox grpVisibility "Visibility" pos:[9,121] width:272 height:46
	dropdownList dropDownVis "" pos:[20,140] width:252 height:21 items:#("Just Import Value", "Connected Controllers") selection:1
	checkbox materialIdsCheckbox "Material Ids" pos:[48,82] width:145 height:16 checked:true

	on importButton pressed do
	(
	    result = ExocortexAlembic.import filename normalCheckbox.checked uvCheckbox.checked materialIdsCheckbox.checked attachCheckbox.checked dropDownVis.selection
	    if( result != 0 ) do
	    (
	    	messageBox "Failure - See Maxscript Listener for details." title:"Exocortex Alembic Import"
	    )
		destroyDialog AlembicImportSettings
	)
	on cancelButton pressed do
	(
	    destroyDialog AlembicImportSettings
	)
)
---------------------------------------------------------------------------------------------------------
-- MAXScript functions to bring up the options dialogs

fn alembicImportDialog =
(
    filename = getOpenFileName caption:"Import from Alembic File:" types:"Alembic(*.abc)|*.abc|All(*.*)|*.*" historyCategory:"Alembic"
    if (filename != undefined) do
    (
        createDialog AlembicImportSettings
        AlembicImportSettings.filename = filename
    )
)

---------------------------------------------------------------------------------------------------------
-- MacroScript to link the menu items to MAXScript functions

macroScript AlembicImportUI
    category:"Alembic"
    buttonText:"Alembic Import..."
    tooltip:"Alembic Import..."
(
    on execute do
    (
        alembicImportDialog()
    )
)