PDA

View Full Version : Scale/Rotate a child around the parents pivot point???


lehthanis
07-03-2008, 11:35 PM
I am looping through a collection of selected geometry and performing a scale/rotate on each object prior to doing a bunch of stuff for exporting it...

One of the modifiers is for rotating the object around a pivot...I'm using a point helper as a child of that object to specify the pivot for the animation modifier...since the objects actual pivot for export needs to be the same as the others (basically the object will have an actual pivot (usually 0,0,0), and a point helper specifies the pivot to be used by the exported-to program)

So...when I get to the object with the rotation modifier, I get the .pivot of the point helper that is its child and use that as the reference...BUT...it needs to be scaled and rotated to follow the parent...but it needs to be rotated around and scaled by the same actual pivot point of the parent...

Is this possible? Do I need to provide a screenshot of what I'm talking about?

PEN
07-04-2008, 01:32 AM
Check out

in coordsys

lehthanis
07-04-2008, 01:51 AM
Doesn't seem to work...its performing the rotate and scale, but it seems to be doing it around its own pivot still.

Thanks for all the help btw.

lehthanis
07-04-2008, 01:57 AM
According to those docs...thats the same as the reference coordinate system in the dropdown...which is fine...but what I need is to set the pivot point center for the operation to that of the parent...I think if I were going to do this in the interface without script, I would actually have to set a working pivot equal to the parents pivot, and then perform the operation...make sense?

lehthanis
07-04-2008, 02:06 AM
Would <node>.objectOffsetPos do it?

RobGalanakis
07-05-2008, 04:15 AM
I just did something like this for my animate align tool, if this isn't solved by Monday, ping me again and I'll look at how I did it and give you a suggestion.

Basically, I made it so a slave object can be animated aligned 'as child', which is what you need to do, I think- position/rotate/scale around an arbitrary point.

eek
07-05-2008, 06:04 AM
You need to get the transform space of the object relative to a reference system namely the point in your case.

tm = $object.transform * inverse $point.transform

Then you would multiply this transform about a matrix:

$object.transform = tm * $point.transform

if you wanted it to rotate about a arbitrary matrix you could do:

(tm * (eulerangles (0 90 0) as matrix3)) * $point.transform

Remember you using a reference coordinate system i.e , its using the 'about' methodology. With this method position, can be classed as a magnitude from the origin - and is a good aproach to scaling rigs e.g.

tm = $point.transform * base.transform -- get the base reference system

finalTm = base.transform
finalTm.row4 = base.transform.row4 * 0.5 -- scale ammount


$point.transform = tm * finalTm

or

$point.transform * (base.transform * 0.5)

lehthanis
07-06-2008, 06:03 AM
Thanks Prof420 and eek!

I can't try this yet because I've switched from having the pivot as a child to using a pickbutton to select the pivot, and the selected pivot isn't staying as the selected pivot...gotta figure out how to have the .obj of the pickbutton on the simplemod saved with the other parameters of my simplemod...

In your example there, is $object the object to be rotated/scaled and $point the point that I want to rotate/scale it around or vice/versa?

eek
07-06-2008, 06:24 PM
Thanks Prof420 and eek!

I can't try this yet because I've switched from having the pivot as a child to using a pickbutton to select the pivot, and the selected pivot isn't staying as the selected pivot...gotta figure out how to have the .obj of the pickbutton on the simplemod saved with the other parameters of my simplemod...

In your example there, is $object the object to be rotated/scaled and $point the point that I want to rotate/scale it around or vice/versa?

try(destroyDialog testAlign)catch()
(
local tmSpace = undefined
local objSpace = undefined rollout testAlign
(
pickbutton pickPivot "Pick Pivot"

Spinner rotX "X:" range:[-180,180,0]
on pickPivot picked obj do
(
tmSpace = selection[1].transform * inverse obj.transform
objSpace = obj
pickPivot.text = obj.name
)
on rotX changed val do
( if tmSpace != undefined do
(
selection[1].transform = tmSpace * ((eulerangles val 0 0) as matrix3) * objSpace.transform
)
)
)
createDialog testAlign
)


roughly something like this - i get confused on the order of matrix multiplication and im not at my desk atm.

lehthanis
07-07-2008, 04:16 PM
Just tried running your script and I get a really weird error...

undefined
-- Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2009\Scripts\transformtest.ms; position: 402
-- Syntax error: at on, expected while
-- In line: on r

This is referring to the "on rotX changed val do" line...

I searched google and found two instances of this error, and they both go unexplained...

lehthanis
07-07-2008, 08:28 PM
I've narrowed it down to the fact that its the second on...do thats causing the problem...I get the error on the second one, no matter which one it is...I've tried swapping them...

Weird...


try(destroyDialog testAlign)catch()
(
local tmSpace = undefined
local objSpace = undefined

rollout testAlign
(
pickbutton pickPivot "Pick Pivot" autodisplay:true
Spinner rotX "X:" range:[-180,180,0]
on pickPivot picked obj do
(
tmSpace = selection[1].transform * inverse obj.transform
objSpace = obj
)
on rotX changed val do
if tmSpace != undefined do
selection[1].transform = tmSpace * ((eulerangles val 0 0) as matrix3) * objSpace.transform
)
createDialog testAlign
)

lehthanis
07-07-2008, 08:38 PM
Figured it out...It was the rollout not having a name in quotes...I gave it a string name and it worked...dang...

lehthanis
07-07-2008, 08:56 PM
I'm having a hard time understanding which pieces your referring to in your description...Tried to adapt your script to handled arbitrary point scaling as well, and its doing nothing :( Sorry...what am I missing?


try(destroyDialog testAlign)catch()
(
local tmRotSpace = undefined
local tmSpace = undefined
local objSpace = undefined

rollout testAlign "Test Rotation"
(
pickbutton pickPivot "Pick Pivot" autodisplay:true
Spinner rotX "X:" range:[-180,180,0]
Spinner rotScale "Scale:" range:[0, 1, 1]
on pickPivot picked obj do
(
tmRotSpace = selection[1].transform * inverse obj.transform
tmSpace = obj.transform * selection[1].transform
objSpace = obj
)
on rotX changed val do
if tmRotSpace != undefined do
selection[1].transform = tmRotSpace * ((eulerangles val 0 0) as matrix3) * objSpace.transform
)
on rotScale changed val do
if tmSpace != undefined do
selection[1].transform = tmSpace * (objSpace.transform * val)
createDialog testAlign
)

eek
07-07-2008, 11:52 PM
an example:



try(destroyDialog testAlign)catch()

rollout testAlign "testAlign"
(
local theObj = undefined
local theTarget = undefined
local theTm = undefined

pickButton pickObj "Pick Object" width:135 across:2
pickButton pickTarget "Pick Target" width:135
editText debug "Transform Stored: " align:#left
spinner scaleTrans "Scale Transform" range:[-100,100,1.0] type:#float width:100 align:#left


on pickObj picked obj do
(
theObj = obj
pickObj.text = obj.name
)

on pickTarget picked obj do
(
if theObj != undefined do
(
theTm = theObj.transform * inverse obj.transform
theTarget = obj
pickTarget.text = obj.name
debug.text = theTarget as string
)
)


on scaleTrans changed val do
(
theObj.pos = (theTm * theTarget.transform).pos * val + theTarget.pos
)


)

createDialog testAlign 300 100

lehthanis
07-08-2008, 05:09 AM
Ohhh...I see what thats doing...The rotate script is exactly what I'm looking for, but the scale one is only scaling the transform, its not scaling the geometry itself...

the actual geometry should also be shrinking, but relative to the targets pivot point...Its kinda hard to explain I guess. Its kinda like what happens when you create a sphere, and scale it on its own pivot, it shrinks in place...but if you go in and move the sphere's pivot point, and then scale it, its going to shrink the same amount but its going to shrink towards that pivot point as well. Know what I mean? I'm thinking at some point in this script, once a transform difference is determined, an actual geometry scaling is going to need to occur.

Here's what I'm doing to geometry.

tmesh = snapshotAsMesh allobj[i]

if ScaleConv.state == true then
(
scale tmesh [.0254,.0254,.0254]
)
if RotXNeg90.state == true then
(
rotate tmesh (eulerangles -90 0 0)
)


This works great because all my geometry has a pivot point of 0,0,0...but the manual pivots I'm placing also need to be scaled (and rotated) as if their pivots were 0,0,0...BUT their actual pivot point should go with them...so the final pivot point of the manual pivot helper should be its location after the scale and rotate around the 0,0,0...Confusing I know.

eek
07-08-2008, 06:10 AM
You'll then need to scale the verts positionally relative to the objects pivot relative to its space.

theObjVerts = #()

for v = 1 to theObj.verts.count do
(
append theObjVerts (theObj.verts[v].pos - theObj.transform.pos)
)

on scalTrans changed val do
(
for v = 1 to theObjVerts.count do
(
theObj.verts[v].pos = theObj.pos + (theObjVerts[v] * val)
)
)

something like this.

lehthanis
07-08-2008, 04:01 PM
Thanks much eek! I've gotten it to do what I need now ;) You're awesome!

CGTalk Moderation
07-08-2008, 04:01 PM
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.