PDA

View Full Version : Dynamic Parenting


DAVID:-D
06-01-2008, 06:20 AM
Does anyone try to solve this issue in XSI? I know I can use pose constrain and blend it between more parents, but the problem happen when u using it in animation. Offset blending do not work smooth and as I wish. I found one plug-in at highend3d (http://www.highend3d.com/maya/downloads/mel_scripts/animation/Parenting-for-Animators-5076.html).


Any Ideas how to do similar tool in XSI?
Is a MEL too much different from XSI scripts ? - so could be too hard get XSI version from this ?

kim aldis
06-01-2008, 10:13 AM
constraint blending is fine, you can do it without jumps or jerks. What kind of problems do you get?

DAVID:-D
06-01-2008, 11:50 AM
constraint blending is fine, you can do it without jumps or jerks. What kind of problems do you get?

Sorry yes u right, I had wrong setup.

pooby
06-02-2008, 03:57 AM
Has anyone invented a way of blending between parents but without moving the target item?

I achieve the effect manually each swap using Pose constraints with compensation, offsets, matching transforms to a dummy null to keep the item in the same spot etc , but there must be a way of setting it up so you can swap parents by just using a slider and keeping your constrained item static.

Anyone done this?

ximage
06-02-2008, 09:23 AM
hey pooby

iv been trying to figure something simular out, was trying to do it with contraints but could not figure it out at all.

but i just had a go with a bit of script(and im no scripter), not with sliders though, just a click. if you create your own toolbar and add your own bit of scipt on a button like.

ParentObj "cube1", "sphere"

second one is the child. you can parent them on the fly. but now thinking about it you wont be able to key these, but im sure it would not be too hard to put it on a slider with a scripted operator. so at value 1 its parented to "blah" and at 0 parented to "blah".

hope i understood you Q's right and havent gone off on one!!

ximage

pooby
06-02-2008, 09:53 AM
Thanks for looking into it.
I need to learn Scripted operators sometime, I'm a dunce when it comes to that.

I was just playing around, and I think that just having a (non offset) pose constraint to a null between the parent and the target which you can use as an offset and this seems to be about the most transparent way of handling this kind of thing ( that I can come up with).
Its not automatic and elegant, but at least its totally clear what's going on. If you want to animate the target, it just means animating the 'offset' null.
I guess for most shots you dont do this more than once or twice, so its not a big deal. It just wouldn't look very cool on a TD reel.

septopus
06-02-2008, 11:00 AM
you can use pose constrains. and turn on compensate
i dont see why that wouldnt work.

pooby
06-02-2008, 11:24 AM
That's ok if you do it once in the shot, and dont want to animate the target item once it's parented, but it's not a great solution, for, say having a hand come up and then move with the head, but then move down and rest on a leg.
Say you want the hand to come up and scratch the chin of a character, whilst the head is looking side to side - you want the hand to stay loosely parented to the head's space, but still be able to animate the hand independantly.
To use constrain compensation, you'll end up having to key the offset, which is a bit awkward and hidden to later adjust IMO. I think it's better to have a visible null that you can monitor in the shot.

septopus
06-02-2008, 11:52 AM
compensate works fine. just key them at the right time.
and dont make a null to parent the arm control object under, then constrain the null instead. this way you curve for the arm control stays clean.

pooby
06-02-2008, 12:06 PM
I know it works, it was my first 'solution'.
Its just not very good to manage when you want to go back and adjust things, as you can't 'match translation' on offsets as you can with a null, to eliminate jumps on the blend.

DAVID:-D
06-02-2008, 02:19 PM
It should work if u do a script what says in this order: get offset from "parent" - "child " what will be constrained, key the position and add key to constraint weight at 100.

It could be managed by adding the null under constrained "child" what will calculate the distance between the null and constrained "parent".

Its easy script yes? ...... but Im stupid man so if anyone has an idea how write it and implement it under custom parameter instead of script button, so it could be easier manage this once u animating.


But what about when u have several pose constraints? How this will know which weight get to "0" and so on?

mde
06-10-2008, 05:49 AM
There was similar discussion on xsi base, I'll repost my method here

What you need to do is - parent the object, store global transformations, cut it, re-parent to new parent, restore global transformations. Save keys on the way.

If you prefer using constrains, then instead of cutting/parenting, switch parent constrain (weights)

http://www.mdee.org/dyn_parent_xsi.avi

I am switching between head and world here.
You need camtasia codec.

This is rather brute force method but works for me. I'll not post my script, because it's very dependent on my namespaces, but it should be rather easy to recreate it.

septopus
06-10-2008, 03:07 PM
yes. this is the simplest way and effective way.
if you need to have more then 2 object to switch back and fourth to, say a finite amount of objects, you may need to do some vector math to get difference is positions and keep you parented object in place.
a tool i used in the past, was created in a way for me to parent just like xsi parenting, but i can have a finite amount of parents, and my parented object had a custom param that took integers, so for instance if i had it parented to 6 differnt objects, it took 7 integers, each integer represented a parent object, and i could animate easily by switching to "1" or "2" or "5" and 0 was world.
its not a hard thing to code. its much like coding an animatable pivot. look in the docs for more info.

3DMastermind
06-16-2008, 12:51 PM
Say you want the hand to come up and scratch the chin of a character, whilst the head is looking side to side - you want the hand to stay loosely parented to the head's space, but still be able to animate the hand independantly.
To use constrain compensation, you'll end up having to key the offset, which is a bit awkward and hidden to later adjust IMO. I think it's better to have a visible null that you can monitor in the shot.

If my char's arm is in FK on the side of the character to start, it must be switched to IK of course. This is what I would do.
1 Key the slider to the FK side .
Skip some frames forward and set it to the IK side (or else, you can't move the effector)
2 place effector near chin set and key up-vector
3 get a null, match transforms to the effector and parent the null to the head.
4 Add the constraint from the effector to the null
Press play.
If you want to animate the hand at the same time that it's constraint... you don't... you animate the null instead ;)
The beauty here is that even if the head is moving on the switch, the effector will track it.
All you have to do is animate the FK to IK blend.

Serguei
06-23-2008, 01:21 PM
After seeing the bi-directional constraints by Andrea Maiolo I tried to recreate something similar. Suffice to say I was unable to achieve stable results with any of my operators.

The way Andreas constrain work is it basically creates a switch board under the hood that can be sensitive to selections, key frames and other constrains and influences. This is achieved by checking which influence is dirty in the DAG. Unfortunately that is not exposed in XSI SDK and what bit of it is there doesn't work as expected. (Since I haven't had the time to look for this functionality in the API so it might be possible to do it there)

So being unable to do the check under the hood I tried to implement a toggle that would be controlled "manually" in some way like with an FK/IK blend. This method worked well on Nulls but it was not stable on bone chains. Because you are inherently creating a cycle with a bi-directional setup the IK solver just doesn't like it.

So yeah that’s where I basically left off with that, hoping to get back to it once again sometime in the future.

Daysgone
08-11-2008, 09:29 PM
I posted this as well on xsibase

import win32com.client
from win32com.client import constants
from win32com.client.dynamic import Dispatch
import math
xsi = Dispatch( 'XSI.Application' ).Application
XSIMath = Dispatch( 'XSI.Math' )

LOG = xsi.LogMessage

null = None
false = 0
true = 1
import math

#find scene objects
root = xsi.ActiveSceneRoot
pose = xsi.Selection(0)
test = root.FindChild('test')

#set transforms
objTrans = XSIMath.CreateTransform()
poseTrans = XSIMath.CreateTransform()
mathTrans = XSIMath.CreateTransform()

#create Matrices
objMatrix = XSIMath.CreateMatrix4()
poseMatrix = XSIMath.Creatematrix4()
mathMatrix = XSIMath.CreateMatrix4()

#set Transforms
objTrans = test.Kinematics.Global.Transform
poseTrans = pose.Kinematics.Global.Transform

#set Matrices
objTrans.GetMatrix4(objMatrix)
poseTrans.GetMatrix4(poseMatrix)

#invert parent matrix
poseMatrix.InvertInPlace()
mathMatrix.Mul( objMatrix, poseMatrix)# gives cords liek its parented

mathTrans.SetMatrix4( mathMatrix )

#see what object is the parent
if pose.Name == 'null':
cons = 0
elif pose.Name == 'null1':
cons = 1
else: LOG('Please select one of the 2 objects your null is constrained to')
LOG(cons)

#set ofset values
xsi.SetValue("test.kine.posecns["+ str(cons) + "].posx", mathTrans.PosX, "")
xsi.SetValue("test.kine.posecns["+ str(cons) + "].posy", mathTrans.PosY, "")
xsi.SetValue("test.kine.posecns["+ str(cons) + "].posz", mathTrans.PosZ, "")
xsi.SetValue("test.kine.posecns["+ str(cons) + "].rotx", mathTrans.RotX, "")
xsi.SetValue("test.kine.posecns["+ str(cons) + "].roty", mathTrans.RotY, "")
xsi.SetValue("test.kine.posecns["+ str(cons) + "].rotz", mathTrans.RotZ, "")

#switch blending to correct constraint
xsi.SetValue("test.kine.posecns["+ str(cons) + "].blendweight", 1, "")
xsi.SetValue("test.kine.posecns["+ str(1 - cons) + "].blendweight", 0, "")

Please let me know if somethign doesnt work, I am learning this stuff myself

septopus
08-11-2008, 10:05 PM
i get errors.

# ERROR : Traceback (most recent call last):
# File "<Script Block >", line 31, in <module>
# objTrans = test.Kinematics.Global.Transform
# AttributeError: 'NoneType' object has no attribute 'Kinematics'
# - [line 31]

Daysgone
08-12-2008, 09:39 AM
The script doesnt create any of the objects you need in the scene, so you currently dont have an object in your scene called test, look for this line and change the name to whatever you want your object to be called

[CODE]
test = root.FindChild('test')
/CODE]