Notifications
Clear all

[Closed] Simulating links between objects?

probably you have to make some GUI to help a user to switch between modes. It’s like IK/FK switching. The user presses only one button and the system does do everything else

how about using ‘When Constructs’



box001OffsetTm = $box001.transform * inverse $box002.transform
box002OffsetTm = $box002.transform * inverse $box001.transform

HFollowMe1 = when transform $box001 changes do (
 if not $box002.isselected do $box002.transform = box002OffsetTm * $box001.transform
)
HFollowMe2 = when transform $box002 changes do (
 if not $box001.isselected do $box001.transform = box001OffsetTm * $box002.transform
)
/*
deleteChangeHandler HFollowMe1
deleteChangeHandler HFollowMe2
*/


1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

when construct is not for the making animation…

Denis: I still don’t understand what I am supposed to do with the commented code. Where do I put it?

Huijun: The only problem with this is that the offset between the objects has to be able to change within the context of the animation.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

the commented part just illustrates how the setup works… run the code first. and one by one execute commented blocks. execute first and try to move/rotate the boxes. execute the next. try … see the difference.
if i have a half hour tomorrow i will make a simple GUI to switch modes.

I guess I’ll wait and see if you get the chance to do that or not, I’m sure it would make much more sense if I could actually see it (and I do appreciate you going to all this trouble to help me out!)

A thought: instead of commenting and uncommenting, would it make sense to set to set the script up as a case expression with each of the blocks based on the current selection?

Also, are there problems I’m not aware of where it comes to the solution Tz proposed? I’ve been messing around with my version of it and it really seems like it’s working smoothly…

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

you case is a rig setup. TzMtN showed the way how to bake an animation. any baked animation is hard to edit. usually to change the baked animation you have to redo/re-bake it over. if you do a dynamic/editable animation you have to avoid the baking solution, and try to find any controller based one.
maybe i’m over-complicating the problem. try to explain better what you want to get finally.

by the way it’s very interesting problem. it is a subject of matter how to fool the dependency loop test.

I’ve fixed a small issue in the code I’ve posted earlier. So I’ll post it just in case anyone in the distant future finds it slightly helpful

fn equals m1 m2 thresh:0.001 =
(
	local test = true
	for i = 1 to 4 where distance m1[i] m2[i] > thresh do
		exit with test = false
	test
)

if this.offset.count != 0 and a.isSelected and not b.isSelected then (
	local m = (execute this.offset) * a.transform
	if not (equals b.transform m) then
		b.transform = m
)

this.offset = (b.transform * inverse a.transform) as string

0

this should replace the code inside the script controller in my explanation in the previous post.

It ties back to the IK/FK rig setup I’m working on. Basically a matter of using different helper objects at different times, and having them move along with the rig when they aren’t the ones driving it.

I haven’t tried fully incorporating the technique I’m currently using into the actual rig yet. It will be interesting to see if it works when combined with everything else…

And Tz: I’ll take a look at the new version when I wake up.

Tz: with the new version you posted, it doesn’t create keys on every frame initially, but if I scrub back over the frames again, a bunch of new frames get created. I appreciate the help anyway though, and my version seems to be working (at least for now).

look at new rig that i made… it’s based on Link_Constraints. i really like it and it looks more promising than the previous one:


  delete objects
  b1 = box name:"bro1" width:10 length:10 height:10 wirecolor:green
  b2 = box name:"bro2" width:10 length:10 height:10 wirecolor:orange
  centerPivot #(b1,b2)
  
  p1 = point name:"pro1" constantscreensize:off centermarker:off axistripod:off box:on cross:off size:30 wirecolor:(color 100 255 100)
  p2 = point name:"pro2" constantscreensize:off centermarker:off axistripod:off box:on cross:off size:30 wirecolor:(color 255 255 100)
  
  b1.pos = p1.pos = [0,0,0]
  b2.pos = p2.pos = [0,0,20]
  
  c = b1.controller = Link_Constraint key_mode:0
  c.addtarget p2 0  
  c = b2.controller = Link_Constraint key_mode:0
  c.addtarget p2 0 
  
  fn makeStepKey controller time = 
  (
  	for k=1 to controller.numsubs do
  	(
  		if (i = getkeyindex controller[k].controller time) != 0 do (getkey controller[k].controller i).inTangentType = #step
  	)
  )
  fn addLinkTarget nodes target time = 
  (
  	tms = for k=1 to nodes.count collect nodes[k].transform
  	for node in nodes do node.controller.addtarget target time
  	for k=1 to nodes.count do nodes[k].transform = tms[k]
  )
  
  step = 5
  for k=0 to 3 do
  (
  	t = step*(2*k + 1)
  	at time t
  	(
  		animate on 
  		(
  			rotate p2 (eulerangles 0 180 0)
  			p1.transform = b1.transform
  			makeStepKey p1.position.controller t
  			makeStepKey p1.rotation.controller t
  		)
  		animate off addLinkTarget #(b1,b2) p1 t
  	)
  	t += step 
  	at time t
  	(
  		animate on 
  		(
  			rotate p1 (eulerangles 0 -180 0)
  			p2.transform = b2.transform
  			makeStepKey p2.position.controller t
  			makeStepKey p2.rotation.controller t
  		)
  		animate off addLinkTarget #(b1,b2) p2 t
  	)
  )
  
  

Hm… it seems to work well, but I’m trying to create a rig that can be used quickly and intuitively, and with the link constraints setup, adding/deleting/moving frames becomes a much slower and more complicated process.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

i would prefer slower but right. my animators also like to know what they do. for example they like manually switch animation modes instead of any automatic way.
well… anyway it would be very interesting to see what you will finally make.

Page 2 / 3