Notifications
Clear all

[Closed] Substracting transform matrixes and moving object to new transform

Hello,

I’m trying to get a simple script work.
1.) Let’s say I have 10 objects which are instances, but half of them are mirrored and they have bad pivot position
2.) I have a new object (visually the same as those instances) with different pivot position
3.) I want to replace each of the 10 instances with the new object
4.) I made a script which works like this:
a.) I place the new object over one of the instances and align it by hand to visually match the position
b.) now I select the “bad” object, select the new object, script subtracts their transforms and stores the offset
c.) then I select another “bad” object, select a copy of the new object and script moves the new object to the new position (“new object transform” = “bad object transform” – “stored offset”)

All that works until I get to the mirrored objects. Using the script on those deforms the mesh…
I guess the mirrored matrix calculations mess things up. Unfortunately I don’t know much about matrix calculations…

Is there some easy way how to store the separate parts of the transform matrix (for position and rotation) and then just apply those by rebuilding the new matrix?

Here is the script I have so far which works for some objects but breaks on those that are mirrored:


(
	global CopyTransformOffset
	try(destroyDialog CopyTransformOffset)catch()
	rollout CopyTransformOffset "CopyTransformOffset" width:170
	(
		local OldObject
		local NewObject
		local offsetvalue
		
		group ""
		(
			pickbutton PickButtOld "Master" width:110 across:2 align:#left
			button ButtOldGet "Get" width:30 align:#right
			pickbutton PickButtNew "New" width:110 across:2 align:#left
			button ButtNewGet "Get" width:30 align:#right
			button ButtStoreOffset "StoreOffset" width: 145 align:#center
			label labInfo "No offset stored!"
		)
		group ""
		(
			button ButtAlign "Align" width: 145 align:#center
		)
		/*pickbutton loads it's name target and loads the object to variable*/
		on PickButtOld picked obj do
		(
			PickButtOld.text = obj.name
			OldObject = obj
		)
		
		/*loads selected object to variable and changes text of PickButtWhich*/
		on ButtOldGet pressed do
		(
			if selection.count == 1 then
			(
				obj = $
				PickButtOld.text = obj.name
				OldObject = obj
			)
			else
			(
				messagebox "You have to select one object!" title:"Error, terrific error!"
			)
		)
		/*pickbutton loads it's name target and loads the object to variable*/
		on PickButtNew picked obj do
		(
			PickButtNew.text = obj.name
			NewObject = obj
		)
		/*loads selected object to variable and changes text of PickButtWhere*/
		on ButtNewGet pressed do
		(
			if selection.count == 1 then
			(
				obj = $
				PickButtNew.text = obj.name
				NewObject = obj
			)
			else
			(
				messagebox "You have to select one object!" title:"Error, terrific error!"
			)
		)
		
		on ButtStoreOffset pressed do
		(
			if ((OldObject != undefined) and (NewObject != undefined)) then
			(
				offsetvalue = OldObject.transform - NewObject.transform
				labInfo.text = offsetvalue as string
				
			)
			else
			(
				messagebox "Master or new objects are empty!" title:"Problem?"
			)
		)
		
		on ButtAlign pressed do
		(
			if ((OldObject != undefined) and (NewObject != undefined) and (offsetvalue != undefined)) then
			(
				NewObject.transform = OldObject.transform - offsetvalue
			)
			else
			(
				messagebox "Master or new objects are empty or no offset is stored"
			)
		)
	)
createDialog CopyTransformOffset -- create main dialog
)

3 Replies

could you attach a sample max file with objects to fix? only three nodes… the right one, the wrong one, and the wrong mirrored.
or you can make a snippet that creates these nodes…

I’m sorry, but couldn’t find the time for the test scene. Started working on it like 4 times just to get much more important task :shrug:
I don’t won’t have access to the computer with those files over the weekend, so I will post the scene on Monday.

Thanks for willing to look into this.

1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

if you don’t have time to make a test scene how is hard for us to do it?