PDA

View Full Version : absolute object position


Matze4d
04-05-2005, 06:02 PM
HI,

i not very firm in scripting so pls excuse if this is maybe a dumb question.
When i assign node to a variable the script listener give sthe absolute position of the node in the scene. How can i access this point3 info? when i retrieve positional info from the the respective node (its linked) i got only the relative position to its parent.

And another prob i have, how can i set the weights for a position list controller?
e.g.
when i script the following
p=node.position.controller
p[1]
p[2]
p[3]
p[4]

it puts out sth. like
Position list controller
Bezier subanim
Bezier subanim
available
subanim weights

but if i try to assign the weights via
p[4]=100,0
i got an error message "no put function..yadadayada"

thanks for your help

Bobo
04-05-2005, 06:33 PM
Using the .pos property, you should always get the world position, unless you specify a different coordinate system:

$.pos --returns abs. world position
in coordsys parent $.pos --returns local position in parent's coordinate space

You would get the relative offset to the parent if you are accessing the sub-anim track, because animation keys store the offset in parent space and not in world space.

So

$[3][1].value --returns local position in parent space!


As for the weights, the .weight property expects (and returns) an ARRAY of values, one for each sub-controller. So you can both get that array and set either the whole array of its elements.

For example

$.position.controller.weight --get the weights at current time
#(100.0, 100.0)

$.position.controller.weight[1] --get the weight of the first sub-controller at current time
100.0

$.position.controller.weight[1] = 50.0 --set the weight of the first sub-controller at current time
50.0

$.position.controller.weight = #(50.0, 50.0) --set the weights of both sub-controller at current time
#(50.0, 50.0)


Since the weights are animatable, the arrays you are getting/setting will reflect the current time.

So you could say

with animate on --enable keyframing
(
at time 0 $.position.controller.weight=#(100.0, 0.0) --enable first controller at frame 0
at time 50 $.position.controller.weight=#(10.0, 90.0) --set other weights on frame 50
at time 100 $.position.controller.weight=#(0.0, 100.0) --override first sub-controller with the second on frame 100
)

Thanks for asking!
I will add these examples to the next update of the MAXScript Reference!

Cheers,
Bobo

Matze4d
04-05-2005, 09:54 PM
:)
thanks a lot Bobo..

just checked it and it works perfect.

Always when i try to script something its like i dont see the forest because of the trees (thats what we say in german, hope it makes sense to you at least it meets my feelings best)

i hope i dont get a plague but maybe you can tell me from your experience whether its better to write a script controller than an expression controller regarding the performance. Obviously the expression controller slows down things a lot, like he's evaluating the entire history of a calculation before coming up with a result.
What i have is an expression controller which calculates the distance between 2 linked pivots. Since it cant see the world space i'd to use 2 helpers with position constraints from which it actually calcs the distance. This expression controls the push value of a mesh, and yeah if i turn this push expression off the playback rate increases significantly. Thats why i consider writing a script controller.

thank you!

Bobo
04-06-2005, 12:17 AM
:)
Always when i try to script something its like i dont see the forest because of the trees (thats what we say in german, hope it makes sense to you at least it meets my feelings best)

Den Wald vor lauter Baeume nicht sehen? Ich kann es gut verstehen :)


i hope i dont get a plague but maybe you can tell me from your experience whether its better to write a script controller than an expression controller regarding the performance. Obviously the expression controller slows down things a lot, like he's evaluating the entire history of a calculation before coming up with a result.
What i have is an expression controller which calculates the distance between 2 linked pivots. Since it cant see the world space i'd to use 2 helpers with position constraints from which it actually calcs the distance. This expression controls the push value of a mesh, and yeah if i turn this push expression off the playback rate increases significantly. Thats why i consider writing a script controller.


Ok. Here is the deal.
First, expressions controllers are FAST.
Second, you CAN get absolute position in expression controllers. Instead of picking the position track (which returns the local position), pick the NODE track (the top track of the object). This will return the absolute world position. It is somewhat hidden and only people with pre-scripting MAX experience (read: Max 1.0) seem to remember it ;)

Scripted controllers have become much faster lately (Max 7) and are much more flexible. But if you want to do simple things very often, Expression controllers seem to be the faster option...

mfG,
Bobo

Matze4d
04-06-2005, 01:04 AM
Bobo,

thanks a lot.
From other threads in the forum i know that you are probably the one w. most experience and with the most inview into max issues. I don't know whether you are from Autodesk maybe? :eek: Nevertheless im glad you care bout my issues. Im using 3D Studio since R2 for DOS and i did some scripting even then, but the mess is that the knowledge gets lost so fast. Everytime i try another script i feel like a complete beginner again :cry:

Thank you for the tip with the absolute world coordinates, i didnt know that but im shure this will be a great help in future. :bounce:

Since im at it theres another issue im struggling with.
I try to create a dialog where the buttons (or any other UI items e.g. checkboxes) should be generated on the fly from an array of modifier names. Unfortunately i didnt find a way to assign a string variable to the <name> property of the checkbox. It seems it only accepts explicitly written "strings". Is it just me?

thats approx. what i did:

mynode.modifiers.count
for i=1 to mynode.modifiers.count
do join mods#(mynode.modifiers[i].name)

rollout test "test"
(
for i=1 to mods.count
do checkbox i mods[i]
)
rof=newrolloutfloater "tester" 300 300
addrollout test rof

what i get is an error saying he wants to have a 'name' afaik.

thank you

Bobo
04-06-2005, 11:47 PM
I don't work at Discreet/Autodesk, but for them (as external contactor), have been editing the MAXScript Reference since 2003.

Take a look at the topic "How To ... Enhance the Morpher Modifier With Floating Controls" in the MAXScript Reference. It shows how to generate UIs on the fly.
Also, take a look at the "RolloutCreator Functions" - these provide an alternative way for building rollouts on the fly.

Cheers,
Bobo

CGTalk Moderation
04-06-2005, 11:47 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.