Notifications
Clear all

[Closed] Using one pivot for many meshes

I am currently working on an .FBX exporter to speed up Static Mesh work flow between 3Ds Max and Unreal and I have hit a bump in the road. The issue is that when I have a single mesh with multiple collision hulls the pivot points when trying to export from 0,0,0 in the world will not be taken from the base mesh, but from what I am assuming is the average of the pivot points of all meshes in the group. Here is the code that I am currently working with.


---------------------------------------------------
-- Single .FBX object exporter V. 1.2
-- 01.17.2012
-- Sam Deiter
---------------------------------------------------

---------------------------------------------------
-- Currently this tool will only work if the 3Ds Max file is saved somewhere.
-- The name of the exported mesh is taken from the name of the file.

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



rollout myRoll "Export FBX"
	
(
	-- Setup the the UI Elemnts that need to be used. 
	
	checkbox CenterBox "Center at [0,0,0]" pos:[16,152] width:185 height:40 type:#boolean enabled:true default:false 
	button b1 "Export"align:#left width:60 height:20 pos:[430,60]
	button b2 "Browse" align:#left width:60 height:20 pos:[430,35]
	edittext SourcePath "Export File Location  :" text: "<Select Valid source path>" fieldWidth:250  align:#right pos:[15,50] readOnly:true
	
		
	--This is the Export button. 	
	on b1 pressed do 
	(
		
		--If nothing is selected then tell the user to select something to export.
		if selection.count == 0  then 
		( 
			messagebox "Please select something to export."
		) 
		
		/*
		else if selection.count >= 2 then
		(
			messagebox"Please only select one mesh and one collison hull"
		)
		*/
		
		--Else run the following function.
		--else if selection.count == 2 then
		else
		(
			-- Add current selection as an array.
			a = selection as array 
			
			-- DeSelect all UCX collision hulls.
			Deselect $UCX*
			
			--Add the current selected objects name here so that it can be used for export later.
			global b = $.name

			-- Select the objects array that was just created.
			select a
			
			--Group the objects so that we can move the group and not each object.
			group objects name:"TG"
			
			-- Now we are going to store a refferance to the new groups position so we can put this back where we got it from.
			OldPosition = $tg.pos
			
			-- Move the selected objects to 0,0,0 in the world.
			
			if (CenterBox.checked) !=true then ($tg.pos= OldPosition)else
			if (CenterBox.checked) == true then ($tg.pos = [0,0,0]) 
			
			
			--This will setup the file with the correct name and format to be exported
			destinationFile = SourceDirectoryName_STR + "\\" + b + ".FBX"
			
			-- This will export the file with no settings or overwrites prompts
			exportFile (destinationFile)#noPrompt selectedOnly:True 
			
			-- This needs to be done so that we can access all of the FBX exporter subgroups.
			pluginManager.loadClass FBXEXPORTER
			FBXExporterSetParam "SmoothingGroups"  true
			FBXExporterSetParam "SmoothMeshExport" false
			FBXExporterSetParam "Triangulate"  false
			FBXExporterSetParam "Animation" false
			FBXExporterSetParam "Lights"  false
			FBXExporterSetParam "ASCII"  true
			
			--Move the objects back to their original position.
			$tg.pos = OldPosition
			ungroup $TG

		)
	)
	
	--This is the Browse button. 
	on b2 pressed do
	(		
		--Get the location of where we want to export the file to. 
		SourcePath_Var = getSavePath caption:"Please select a Folder to export";
		
		-- Store the selected path so that we can use it / change it later on.
		Global SourceDirectoryName_STR = SourcePath_Var 
		
		--If there is no path selected promt the user to select a path.
		if SourcePath_Var == undefined then messagebox "Please select an Export location";
		
		-- This stores the soruce path as a string. 
		else SourcePath.text = SourceDirectoryName_STR 
		
	)
	
)

createdialog myroll width: 500 height:200


For this script to work correctly you need to have at least three objects in the scene. One object needs to be called something like SM_Blah and the the other two objects names need to start with UCX_Something_Cool_Here.

What I can not figure out is how I take and store the base mesh pivot point and move the group using that pivot point. This way the artist always has full control over the pivot point placement. I want to make sure that when they move the object to 0,0,0 they know that the object will move there but the pivot point will always be where they placed it.

Please let me know if you have any questions about this or about what I am trying to do. I had a big huge explanation about what I was trying to do but I felt that it might just confuse people.

3 Replies

how is about to attach all meshes in the group?

1 Reply
(@billyclint)
Joined: 11 months ago

Posts: 0

I am not following you on this. I did try grouping the meshes and then moving the group but I have the issue of the pivot not being correct. I am not really sure where the error lies so I am not sure how to go about fixing it. If I do have a break through I will post my results back here.

Okay I got it working the way that I wanted to. I solved the problem by storing the pivot of the main as a variable…

OP = $.pivot

Then further on down in the code after I group all of the selected items I set the groups pivot point the to stored value in

OP

and BAM…Everything works the way that I wanted. I guess in the end I just needed a few days to stew on it until I got the correct answer. Thanks for the help. here is the final code if any one would like to use it. I know that its simple but it was a big learning step for me. If any one has any ideas or critiques on the script please feel free to let me know.


---------------------------------------------------
-- Single .FBX object exporter V. 1.2
-- 01.17.2012
-- Sam Deiter
---------------------------------------------------

---------------------------------------------------
-- Currently this tool will only work if the 3Ds Max file is saved somewhere.
-- The name of the exported mesh is taken from the name of the file.

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



rollout myRoll "Export FBX"
	
(
	-- Setup the the UI Elemnts that need to be used. 
	
	checkbox CenterBox "Center at [0,0,0]" pos:[16,152] width:185 height:40 type:#boolean enabled:true default:false 
	button b1 "Export"align:#left width:60 height:20 pos:[430,60]
	button b2 "Browse" align:#left width:60 height:20 pos:[430,35]
	edittext SourcePath "Export File Location  :" text: "<Select Valid source path>" fieldWidth:250  align:#right pos:[15,50] readOnly:true
	
		
	--This is the Export button. 	
	on b1 pressed do 
	(
		
		--If nothing is selected then tell the user to select something to export.
		if selection.count == 0  then 
		( 
			messagebox "Please select something to export."
		) 
		
		/*
		else if selection.count >= 2 then
		(
			messagebox"Please only select one mesh and one collison hull"
		)
		*/
		
		--Else run the following function.
		--else if selection.count == 2 then
		else
		(
			-- Add current selection as an array.
			a = selection as array 
			
			-- DeSelect all UCX collision hulls.
			Deselect $UCX*
			
			-- Store the pivot of the min mesh object so that when grouped, the group can have the same pivot point. 
			OP = $.pivot 
			
			--Add the current selected objects name here so that it can be used for export later.
			global b = $.name

			-- Select the objects array that was just created.
			select a
			
			--Group the objects so that we can move the group and not each object.
			group objects name:"TG"
			
			-- Give the group the pivot point of the main mesh object.
			$tg.pivot = OP
			
			-- Now we are going to store a refferance to the new groups position so we can put this back where we got it from.
			OldPosition = $tg.pos
			
			-- Move the selected objects to 0,0,0 in the world.
			
			if (CenterBox.checked) !=true then ($tg.pos= OldPosition)else
			if (CenterBox.checked) == true then ($tg.pos = [0,0,0]) 
			
			
			--This will setup the file with the correct name and format to be exported
			destinationFile = SourceDirectoryName_STR + "\\" + b + ".FBX"
			
			-- This will export the file with no settings or overwrites prompts
			exportFile (destinationFile)#noPrompt selectedOnly:True 
			
			-- This needs to be done so that we can access all of the FBX exporter subgroups.
			pluginManager.loadClass FBXEXPORTER
			FBXExporterSetParam "SmoothingGroups"  true
			FBXExporterSetParam "SmoothMeshExport" false
			FBXExporterSetParam "Triangulate"  false
			FBXExporterSetParam "Animation" false
			FBXExporterSetParam "Lights"  false
			FBXExporterSetParam "ASCII"  true
			
			--Move the objects back to their original position.
			$tg.pos = OldPosition
			ungroup $TG

		)
	)
	
	--This is the Browse button. 
	on b2 pressed do
	(		
		--Get the location of where we want to export the file to. 
		SourcePath_Var = getSavePath caption:"Please select a Folder to export";
		
		-- Store the selected path so that we can use it / change it later on.
		Global SourceDirectoryName_STR = SourcePath_Var 
		
		--If there is no path selected promt the user to select a path.
		if SourcePath_Var == undefined then messagebox "Please select an Export location";
		
		-- This stores the soruce path as a string. 
		else SourcePath.text = SourceDirectoryName_STR 
		
	)
	
)

createdialog myroll width: 500 height:200