Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Reliably reset scale of object while maintaining its physical size, rotation and position

Reliably reset scale of object while maintaining its physical size, rotation and position

wyomingstateflag
Contributor Contributor
508 Views
7 Replies
Message 1 of 8

Reliably reset scale of object while maintaining its physical size, rotation and position

wyomingstateflag
Contributor
Contributor

Hey sorry for all the questions, but I'm looking for a way to:


Reliably reset an objects' scale value to [1, 1, 1] without affecting the actual physical size of the object. Similar to the way resetxform resets the scale value without affecting the size of the object. However I want to keep the rotation value preserved so resetxform isn't an option.

In other words I'm basically just looking for a resetxform but only for the scale value, while preserving the rotation and position.

Most importantly I'm looking for a solution that works with mirrored objects which have a negative scale

 

TLDR; ResetXForm but exclusively for scale


0 Likes
Accepted solutions (2)
509 Views
7 Replies
Replies (7)
Message 2 of 8

miauuuu
Collaborator
Collaborator
Accepted solution

What about:

ResetScale <node>-- mapped method 
https://miauu-maxscript.com/
Message 3 of 8

MartinBeh
Advisor
Advisor
Accepted solution

ResetScale() (as suggested by miauuu) will push the node transformation into the Object-Offset Transform Matrix - you can undo it using ResetPivot(), which shows that the negative node transform is not really embedded into the geometry (as it would be with a ResetXform modifier) but into the "pivot".

Some parts of 3ds Max might not work as expected with such scene elements - but maybe that is good enough for your needs? 

 

Here is hopefully an alternative solution that keeps pos and rot in the node, and moves scale into an Xform modifer:

mapped fn resetXformScaleOnly obj = (
	local oldTM = obj.transform
	-- get transform matrix decomposition
	local oldP = transMatrix oldTM.pos
	local oldR = oldTM.rotation as matrix3
	local oldS = ScaleMatrix oldTM.scale
	-- now we have:  oldTM == ( oldS * oldR * oldP )
	obj.transform = oldR * oldP		-- keep rot and pos in node transform
	local xf = xform()
	addModifier obj xf
	-- place scale part in xform modifier
	xf.gizmo = oldS
)

resetXformScaleOnly $

NB: Works with objects linked into a hierarchy (as long as the parent does not also use scale!) but not tested yet for objects with non-default pivot locations...

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
Message 4 of 8

wyomingstateflag
Contributor
Contributor

Thanks for the solutions 🙂  they're definitely giving better results than I'm starting with making my test case a bit easier to work with but have some issues
@MartinBeh solution seems to have some side effects with certain objects in my test case and the modifier seems to be brittle in situations where the object has a negative scale muddling UV coords
@miauuuu solution seems more stable but it seems like some negative scale value is still persisting in both solutions since if I reimport the objects its applied to, the mirrored objects come in with inverted normals unless I'm misattributing that, even after resetting normals any mirrored object comes in with inverted normals still

0 Likes
Message 5 of 8

MartinBeh
Advisor
Advisor

Can you post a test .max file?

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
Message 6 of 8

wyomingstateflag
Contributor
Contributor

Here's the object's I was using to test with, thanks

0 Likes
Message 7 of 8

MartinBeh
Advisor
Advisor

(Nice typewriter objects. Are those object names on purpose?)

 

Maybe I am missing something but I tried my code and it seemed to work for all objects in that .max file (I also do not see any issues with normals, and UVs seem to be preserved, too) EXCEPT the central one with the letter "h/H". That one has a large pivot offset (you can see it by pressing Reset Pivot in the Hierarchy panel) which seems to cause issues. Luckily that object does not have any rotation, so we can simply reset xform it... 

 

You can verify what the code did by toggling off/on the new XForm modifier it applied. With the modifier off, the object keeps its orientation but is mirrored in all axes (such that the type letters are no longer mirrored, too).

 

BTW, what version of 3ds Max are you using? There might be differences in newer versions of 3ds Max how Reset XForm and the XForm modifier handle normals...

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
Message 8 of 8

wyomingstateflag
Contributor
Contributor

Thanks, the max version was the culprit. I tried your script in max 2024 and it worked flawlessly aside from the H you pointed out. My main version is max 2022 which is where that scene file came from. As for the names, yeah that was intentional. I've just given them random names to make sure they're all unique for matching high to low with a baker. I think unless there's a simple way of making it work with 2022, I'll have to use 2024 as a middle-man before exporting

Thanks for all your help 🙂