Cogwheel gear via ICE

Discussions about SOFTIMAGEs© Interactive Creative Environment©
Pancho
Posts: 659
Joined: 19 Sep 2010, 09:28

Cogwheel gear via ICE

Post by Pancho » 27 Sep 2010, 22:28

Hi folks,

I try to find a way to position and animate several cogwheels which are connected to each other. Right now I managed to set everything up properly for the first three cogwheels. The second cogwheel also rotates like it is supposed to do. The third gets positioned correctly in its neutral pose, but doesn't move (movement is generated by keyframing cogwheel 1)

There's also a cyclebreak warning message popping up from time to time. So, if somebody could please tell me what's wrong with my approach.

Each cogwheel does have a small ICE tree which sets a "teeth" attribute for each wheel (amount of teeth for each wheel).

In the empty point cloud I intend to calculate all motion and positions based on the "root" cogwheel. Important for the position is always the amount of teeth which determins the diameter of each cogwheel and by this the distance to its "parent" wheel (although there is no parenting going on). To determin the position in relation to its "parent" wheel I just use an angle, like the watch hand pointing to a number (direction) . The distance between both wheels gets calculated by their diameters, the position of the wheel itself by using trigonometry and the angle. So far so good. The cogwheels all get placed in the correct spot, although sometimes one of the wheels disappears. Then I need to move the ICE tree up and down in the point cloud directory so that it gets updated.

My guess is that SI does get in trouble to calculate the third cogwheels position and rotation during animation as it depends on the rotation of the second wheel which gets calculated also. Some kind of interdependency trouble. Can this be the reason for the gear to not work as expected? I tried to bring in some "order" to the calculations and put the cogwheel 1-2 calculations in the first port and the cogwheel 2-3 rotations in the second port, hoping that the calculations will take place after the first port finished its business.

My cogwheel node simply asks for the "parents" global SRTs and then adds some rotation and the distance to these values. Then I set these values as the new global values of the "child" cogwheel.

Hope the download works. First time I uploaded to Megaupload.

Thanks in advance
Pancho

http://www.megaupload.com/?d=YRFI5TV9

grahamef
Posts: 281
Joined: 23 Jun 2009, 19:01

Re: Cogwheel gear via ICE

Post by grahamef » 27 Sep 2010, 23:27

Are you both setting and then getting the transformation on the second cog wheel? That's probably where the cycle is coming from.

Try calculating all the transformations in the tree on the pointcloud but then saving them as custom attributes. Then put another little ICE tree on each cogwheel to read the appropriate custom attribute from the pointcloud and then set its own kine.global.

Pancho
Posts: 659
Joined: 19 Sep 2010, 09:28

Re: Cogwheel gear via ICE

Post by Pancho » 28 Sep 2010, 06:11

Yes, first the second wheel gets calculated, then the third wheel, based on the just calculated position of the second. That's the way it needs to be done (at least in this kind of order). The last wheel will depend on its preceding wheel. It's like domino bricks in a row. The last one falling just falls as a consequence of the movement of the first one. So this would happen every frame, this chain reaction.

If I'd save the positon/rotation only as an attribute, which part/which ICE tree would actually set the position?

The interdependency wouldn't change also, just the area where things get set, or?

Did you take a look at the scene file?

I guess what I need to do is write the results of my calculations in an array first and after all calculations are through apply the results to the objects. Is there an example out there how to do this?

Cheers
Pancho

User avatar
Hirazi Blue
Administrator
Posts: 5113
Joined: 04 Jun 2009, 10:15

Re: Cogwheel gear via ICE

Post by Hirazi Blue » 28 Sep 2010, 08:48

I think I found a solution, but I'm new at this ICE Kine stuff also, so bear with me. In your current ICE Tree the calculated matrices get written directly into their respective kine.global. This way you create trouble when getting the data from the second wheel you've "just" set. Modifying your Compound and making two separate ones (one for the first and one for the next) to result in matrices and piping the matrix coming from the first into the "next" compound without setting anything seems to prevent most errors...

To illustrate:
cogtree.png
wheelone.jpg
wheelnext.jpg
PS This setup doesn't take the negative rotation (of the second wheel) into account.

Additional PS - As you're relatively new to our little forum I've added the URL tags in the above first post free of charge :D
Stay safe, sane & healthy!

Pancho
Posts: 659
Joined: 19 Sep 2010, 09:28

Re: Cogwheel gear via ICE

Post by Pancho » 28 Sep 2010, 09:07

Ha, ha, ha! Great! That's excactly what I came up with in the meantime. First I thought I would need to store the data in an array, but just transmitting the SRT matrix to the next node is pretty nice. To solve the rotation of the cogs I added a "Cogwheel number in chain" integer. Each Cogwheel SRT node increments this number and checks whether its even or odd. In one case I invert the rotation direction and voila, it works.

Right now I'm trying to find a way to check whether a node input is connected (Is there any nodal input?) and to pass the matrix, the name of the wheel and the wheel number in one go to the next node. Currently I need to connect three inputs/outputs. I tried to store everything in an array, but as the outputs are different in their category, the array refuses to hold all these different things. Would be just a bit more convinient to only need to connect one string between nodes.

Thanks man!

Pancho
Posts: 659
Joined: 19 Sep 2010, 09:28

Re: Cogwheel gear via ICE

Post by Pancho » 28 Sep 2010, 12:35

Mmmh! One problem remains. Although in my scene cogwheel 1 rotates up to 400°, the "rotation to axis and angle" nodes starts to count downwards as soon as 180° are reached. Is that a problem with this node or because I use kine.global?

As long as this problem remains cogwheel 1 turns correctly, but the 2nd wheel will start to rotate backwards from 180° on.

Cheers
Thomas

User avatar
Hirazi Blue
Administrator
Posts: 5113
Joined: 04 Jun 2009, 10:15

Re: Cogwheel gear via ICE

Post by Hirazi Blue » 28 Sep 2010, 14:43

Hmm, I knew I should have given the wheels the chance to turn some more... b-(
Seems like something that should be relatively easy to fix / workaround...
If you haven't solved it by then, I will have a look at it some more tonight!
Stay safe, sane & healthy!

Pancho
Posts: 659
Joined: 19 Sep 2010, 09:28

Re: Cogwheel gear via ICE

Post by Pancho » 28 Sep 2010, 14:54

Thanks! I've dropped the SRT matrix in a way and just use their position values. I directly get the local Euler z rotation and use this angle for the calculations. Wonder whether that's "correct", but it works.

Is there a way to transmit about 4-5 different value types via one connection? Would make everything so much cleaner and faster to set up.

User avatar
Hirazi Blue
Administrator
Posts: 5113
Joined: 04 Jun 2009, 10:15

Re: Cogwheel gear via ICE

Post by Hirazi Blue » 28 Sep 2010, 15:02

If I understand your last question correctly, then no I don't think that that's possible.
I consider your other problem solved, so I can enjoy a quiet evening... i-)
(if it works, it works...)

Please post some of your work on this tree when you're done...
I really want to see what you're doing and how you are doing it.
Learning by example... :-?
Stay safe, sane & healthy!

Pancho
Posts: 659
Joined: 19 Sep 2010, 09:28

Re: Cogwheel gear via ICE

Post by Pancho » 28 Sep 2010, 17:57

I thought I would be able to pass all the data forward in a mixed array? Well, apart from this the node is almost finished. I just want to implement an offset function in case you want to reposition one of the wheels without moving the others (e.g., to rotate a pattern or some letters which might be attached to the wheel). I did run into some difficulties with the rotation and found a solution by trial and error. No idea why it works this way, but it does so far. One thing I didn't try so far are cogwheels with an odd amount of teeth. That would be something to try out next. But for my purposes it works. If everything works out great here job wise I'll upload the scene file with the nodes in the next few days.

grahamef
Posts: 281
Joined: 23 Jun 2009, 19:01

Re: Cogwheel gear via ICE

Post by grahamef » 28 Sep 2010, 20:11

You can store all the transforms in an array based on "cogwheel number in chain", and have each cogwheel look up its transform from the array based on that value.

Pancho
Posts: 659
Joined: 19 Sep 2010, 09:28

Re: Cogwheel gear via ICE

Post by Pancho » 29 Sep 2010, 15:18

Thanks, Graham!

I'm not quite sure whether I understand you correctly. Are you talking about storing all the transforms in the array (in the empty point cloud where all calculations take place) and then access this array and its data from an ice tree attached to each cogwheel? I guess that might not be possible with ice to have something like a global array. So I guess the only solution you have in mind is to do all this in one ice tree in the pointcloud.

What I would consider interesting is to use one "Cogwheel SRT" in a loop? I would store all the names of the cogwheels in two arrays (one with the name of the parent wheel, one with the name of the wheel to be positioned) and run them through this one node, writing the transforms into another array. Is this possible? Because right now I use one "Cogwheel SRT" node for each wheel in my scene. So the node tree get big, fat and ugly the more wheels are placed.

Cheers
Pancho

grahamef
Posts: 281
Joined: 23 Jun 2009, 19:01

Re: Cogwheel gear via ICE

Post by grahamef » 30 Sep 2010, 23:34

Right, I'm suggesting something similar but you can't put references to the names of objects in an array so you need to approach it slightly differently. It's actually very similar to the approach used in the rabbit rig sample ICE kine scene.

You put all your cog wheels into a group. The important thing is that you select and add the cog wheels to the group in the correct order 0 to N. In addition, each cog wheel needs a custom parameter that specifies its number in the group. When setting up the rabbit rig, this part was automated with a script.

In the ICE tree, you get the group's kine.global value. This gives an array of transforms in the same order as the group. You can now loop on the array using the value of i to update i+1, and then save that array of transforms as a custom attribute on the rig object.

Finally each cog wheel has an ICE tree that looks up its custom property, gets the corresponding value from the array on the rig object, and sets its own kine.global. Again, this was set up using a script in the case of the rabbit rig.

So now you don't need to add more nodes to the tree if you want more wheels. All you need to do is add the new wheel to the group, apply and set its custom parameter, and apply the same ICE tree used by all the other wheels.