Using one pivot for many meshes

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  02 February 2013
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.
__________________
|*BILLY$CLINT*|




Last edited by BillyClint : 02 February 2013 at 06:46 PM.
 
  02 February 2013
how is about to attach all meshes in the group?
 
  02 February 2013
Originally Posted by denisT: how is about to attach all meshes in the group?


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.
__________________
|*BILLY$CLINT*|



 
  02 February 2013
I fixed it

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
__________________
|*BILLY$CLINT*|



 
  02 February 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:50 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.