Scripting Advice for Rolling Box

7 views
Skip to first unread message

Jeffrey Dates

unread,
May 12, 2009, 11:13:59 AM5/12/09
to soft...@listproc.autodesk.com
Hello gang,

I don't do much scripting, so please bear with me, as I'm trying to learn.

I'm attempting to create a rig that allows me to simply translate a control, that rolls a cube on it sides.  ( the old rolling cube ).
However, it needs to roll in all axis, and cannot be dependent on a surface. 

I'm imagining it should need to be a scripted op, so that it can be live and apparent when the user drags the control. 

First, I'm looking for any examples, ( preferably in Python ), that might be useful in my initial endeavor. 

Also, any advice, or pointers from those of you who could script this in 20 minutes, would be also appreciated.

Thanks in advance.

Jeffrey








Sajjad Amjad

unread,
May 12, 2009, 11:24:07 AM5/12/09
to soft...@listproc.autodesk.com
Hi,
You don't really need a scop to do this. Run the following jscript in an empty scene:

CreatePrim("Cube", "MeshSurface", null, null);
GetPrim("Null", null, null, null);
SelectObj("cube", null, true);
InspectObj("cube.kine.local", "", null, "", null);
SelectObj("null", null, true);
InspectObj("null.kine.local", "", null, "", null);
SetExpr("cube.kine.local.pposx", "null.kine.local.posx", null);
SetExpr("cube.kine.local.pposy", "null.kine.local.posy", null);
SetExpr("cube.kine.local.pposz", "null.kine.local.posz", null);

The above makes a null the pivot of the cube. The following cycle applies:
1. Move the null to some corner/edge of the cube,
2. rotate/key cube
3 repeat 1

Hope this helps.



2009/5/12 Jeffrey Dates <jda...@kungfukoi.com>



--

-----
"Consistency is the last resort of the unimaginative" - O. Wilde

Kung FuKoi

unread,
May 12, 2009, 11:33:25 AM5/12/09
to soft...@listproc.autodesk.com
Thank you Sajjad,

Yeah, I appreciate your example.  However, this is what I would consider the traditional way to roll a cube.

What I'm actually looking to do, is automate this very process, so that all I do is grab a null that controls the cube.  When I drag that null in an arbitrary axis, the cube will do the flop/roll automatically. 

Thank you again,

Jeffrey

André Adam

unread,
May 12, 2009, 11:49:50 AM5/12/09
to soft...@listproc.autodesk.com
The fastest you can get:

1.: Execute Script:

CreatePrim("Grid", "MeshSurface", null, null);


CreatePrim("Cube", "MeshSurface", null, null);

SetValue("cube.cube.length", 1, null);
SetExpr("cube.kine.local.rotz", "cube.kine.local.posx*-90", null);
ApplyCns("BoundingPlane", "cube", "grid", null);

2.: Translate Cube in X

-André

> <mailto:jda...@kungfukoi.com>>

André Adam

unread,
May 12, 2009, 11:52:00 AM5/12/09
to soft...@listproc.autodesk.com
Oh, and of course I know that this is not exactly what you are after,
just couldn't resist... :)

Jeffrey Dates

unread,
May 12, 2009, 12:00:35 PM5/12/09
to soft...@listproc.autodesk.com
This is the desired control, for sure! ( only needed in all axis )

However, it is dependent on the Bounding Plane Constraint.. and in my situation unfortunately, there will be too many changing axis for this to be practical.

Thank you for your time.

I guess I wouldn't have posted the question if it was something as elementary as an expression and a constraint.  :-)

Jeffrey Dates

unread,
May 13, 2009, 10:47:30 AM5/13/09
to soft...@listproc.autodesk.com
So I've made some progress with the rolling cube rig. 

I'm using expressions driving rotation based on the translation..etc.

Two problems I'm looking at.

( assume the hierarchy is: Model->Translate_null->Rotate_null->geo_parent_null->mesh )


1) At some point the Y-up of a geo_parent_null gets rolled down off global Y and then from that point further the box now rolls incorrectly. 
            a) I'm looking at how to maintain a global Y-up on the geo_parent_null but also maintain the X and Z rots respectively for the mesh.

2) Also, getting the box to appear to rise up on the edge as it rolls is stumping me. 
right now I have the box rolling like a ball.  But I need the mesh to translate in global Y a small amount then translate back down so it appears to be in contact with a surface.

I have tried a sin wave but haven't successfully wired it yet.

Anyway..  Just an update.
It's a deceivingly simple problem, but turned out to be rather challenging for me.

Thanks everyone.

Jeffrey Dates


Morten Bartholdy

unread,
May 13, 2009, 11:37:40 AM5/13/09
to soft...@listproc.autodesk.com
Now I wouldn't begin to speculate on how to script this, but have a
suggestion that might help - it sounds like what you need is the difference
in distance between the surface of a sphere that just fits inside the cube
and the surface of the cube, and then apply that to the global y-position of
the cube. Not simple but sounds doable.

Morten Bartholdy
3D & VFX Supervisor

Bradley Gabe

unread,
May 13, 2009, 12:00:42 PM5/13/09
to soft...@listproc.autodesk.com
I'm not sure that would work either. The pivot point of the cube rotation is not at the center of the cube, but rather at whichever corner or edge is in contact with the surface at a given point in time.

adrian wyer

unread,
May 13, 2009, 12:09:18 PM5/13/09
to soft...@listproc.autodesk.com

Jeffrey Dates

unread,
May 13, 2009, 12:30:39 PM5/13/09
to soft...@listproc.autodesk.com
thanks adrian.

But this is the 'traditional way' to roll a cube.  Animating the pivot by hand. 

Jeffrey Dates

unread,
May 13, 2009, 3:14:58 PM5/13/09
to soft...@listproc.autodesk.com
So, I've seem to got everything working pretty good except for one aspect.

I'm looking at how to keep a global axis so that I can have a consistent Y-up. 

I'm unclear on why setting an expression on global.rotation acts as if it's local? 

The biggest problem I'm encountering is the Y-axis rolls off Y-up as soon as the Z-axis is rolled.  

how has this been addressed in the past!?

thanks.

Bradley Gabe

unread,
May 13, 2009, 3:23:25 PM5/13/09
to soft...@listproc.autodesk.com
I don't think it matters if you are working in global or local rotation space. If you are using Euler rotations you are going to have issues with gimbal lock.

Come to think of it, you might be better off working in local rotation space and using a different rotation order like zxy.

Julian Johnson

unread,
May 14, 2009, 3:27:55 PM5/14/09
to soft...@listproc.autodesk.com
Jeffrey Dates wrote:
> So, I've seem to got everything working pretty good except for one aspect.
>
> I'm looking at how to keep a global axis so that I can have a
> consistent Y-up.

Hi Jeffrey,

I'm sure you're nearly done with this now but just in case you wanted
another approach, I've got an ICE compound that'll roll a cube:

http://vimeo.com/4647214

Let me know if you'd like a copy and I'll email it on to you.
Cheers,
Julian

Eric Thivierge / XSI Database

unread,
May 14, 2009, 3:35:12 PM5/14/09
to soft...@listproc.autodesk.com
Hey Julian,

I'd be interested in seeing the ICE tree to pull it apart if you
wouldn't mind. No worries if you want to keep it private though.

Later,

--------------------------------------------
Eric Thivierge
Technical Director
Speakeasy FX

jimmy

unread,
May 14, 2009, 3:39:09 PM5/14/09
to soft...@listproc.autodesk.com
That is pretty cool.

Jeffrey Dates

unread,
May 14, 2009, 3:39:21 PM5/14/09
to soft...@listproc.autodesk.com
Say Julian that's really nice!

It's funny that you accomplished it in ICE, as that is where I've ended up after trying expressions and Scripted ops.  :-)

I'd love to see the compound as well. 

Thanks in advance!!

Jeff.

On Thu, May 14, 2009 at 3:27 PM, Julian Johnson <jul...@exch.demon.co.uk> wrote:

Sajjad Amjad

unread,
May 15, 2009, 12:12:37 PM5/15/09
to soft...@listproc.autodesk.com
Was browsing Julian's Vimeo page and came across this:
http://www.vimeo.com/4662525

Rolling with a twist. (Apologies for being a bit vague, don't want to spoil it)

2009/5/14 Jeffrey Dates <kung...@gmail.com>

Jeffrey Dates

unread,
May 15, 2009, 12:15:53 PM5/15/09
to soft...@listproc.autodesk.com
Yeah that's great isn't it!?   He posted that yesterday in response to this thread.

His compound is pretty deep.. I'm still dissecting it and learning from it.
Great stuffs!!

/me buries his head back in his math book...

Sajjad Amjad

unread,
May 15, 2009, 12:32:39 PM5/15/09
to soft...@listproc.autodesk.com
Yesterday he posted the rolling cube, this is a new one.

2009/5/15 Jeffrey Dates <kung...@gmail.com>

Jeffrey Dates

unread,
May 15, 2009, 12:35:21 PM5/15/09
to soft...@listproc.autodesk.com
Oh, look at that! 

Wow, Julian, that's great!




On Fri, May 15, 2009 at 12:12 PM, Sajjad Amjad <sajjad...@gmail.com> wrote:

Andy Moorer

unread,
May 15, 2009, 4:07:00 PM5/15/09
to soft...@listproc.autodesk.com
Julian drinks for free next time he visits LA....

Sam Cuttriss

unread,
May 15, 2009, 9:08:53 PM5/15/09
to soft...@listproc.autodesk.com
and san rafael,


Andy Moorer wrote:
> Julian drinks for free next time he visits LA....
>
> On Fri, May 15, 2009 at 9:35 AM, Jeffrey Dates <kung...@gmail.com
> <mailto:kung...@gmail.com>> wrote:
>
> Oh, look at that!
>
> Wow, Julian, that's great!
>
>
>
>
> On Fri, May 15, 2009 at 12:12 PM, Sajjad Amjad
> <sajjad...@gmail.com <mailto:sajjad...@gmail.com>> wrote:
>
> Was browsing Julian's Vimeo page and came across this:
> http://www.vimeo.com/4662525
>
> Rolling with a twist. (Apologies for being a bit vague, don't
> want to spoil it)
>
> 2009/5/14 Jeffrey Dates <kung...@gmail.com

> <mailto:kung...@gmail.com>>


>
> Say Julian that's really nice!
>
> It's funny that you accomplished it in ICE, as that is
> where I've ended up after trying expressions and Scripted
> ops. :-)
>
> I'd love to see the compound as well.
>
> Thanks in advance!!
>
> Jeff.
>
> On Thu, May 14, 2009 at 3:27 PM, Julian Johnson

> <jul...@exch.demon.co.uk <mailto:jul...@exch.demon.co.uk>>

Fabricio Chamon

unread,
May 18, 2009, 10:50:35 AM5/18/09
to soft...@listproc.autodesk.com
Hi Julian,

I know it could get annoying, as you already said you're finishing
some things before posting the compound. but I'm really (I mean,
REALLY!) interested in learning from your ice tree.
And I cannot stop wondering the many possibilities this compound can achieve.
So, if you don't mind showing it before you upload to the community
I'd like to have a look at it too.
Thanks!

Fabricio

Ciaran Moloney

unread,
May 18, 2009, 11:13:49 AM5/18/09
to soft...@listproc.autodesk.com
I had a go at this myself. It's a pretty fun exercise to learn from, thanks for inspiring!
Did you intend to add any collision detection/evasion? I'm just testing for intersecting bounding boxes, it works pretty well, but would be interested in a more reliable approach.

Julian Johnson

unread,
May 18, 2009, 11:34:42 AM5/18/09
to soft...@listproc.autodesk.com
Ciaran Moloney wrote:
> I had a go at this myself. It's a pretty fun exercise to learn from,
> thanks for inspiring!
> Did you intend to add any collision detection/evasion? I'm just
> testing for intersecting bounding boxes, it works pretty well, but
> would be interested in a more reliable approach.
Hi Ciaran,

That sounds cool. I'm way behind that :-) At the moment I'm just trying
to find the most performant way to do the basic roll i.e. weighing up
the fastest way to locate the 'candidate' pivots at any given frame
especially with really heavy point sets. Removing geometry queries and
using a combination of filter and min/max in set to find the relevant
points seems much quicker so far......I haven't even considered
collision detection!

Julian

Ciaran Moloney

unread,
May 18, 2009, 4:39:43 PM5/18/09
to soft...@listproc.autodesk.com
Yeah, that seemed best to me too. If possible, avoid 'find in array' if you're working with big sets.

On Mon, May 18, 2009 at 11:34 AM, Julian Johnson <jul...@exch.demon.co.uk> wrote:

Removing geometry queries and using a combination of filter and min/max in set to find the relevant points seems much quicker so far.....

Julian

Julian Johnson

unread,
May 19, 2009, 8:13:34 AM5/19/09
to soft...@listproc.autodesk.com
A 'cleaned up' compound and sample scene is here:

http://julianjohnsonsblog.blogspot.com/2009/05/roll-object-compound-and-sample-scene.html

Hopefully better than the original! :-)

Joe Williamsen

unread,
May 19, 2009, 9:29:48 AM5/19/09
to soft...@listproc.autodesk.com
Thanks, Julian!
Reply all
Reply to author
Forward
0 new messages