18
$\begingroup$

I am trying to create a Rubik's Cube using the Animation Nodes addon. The aim is to be able to make a specific sequence based on a custum group node system.

They could be a node for each individual action, like turn the top. (you are going to have the option to turn it left or right with a boolean option).

The main problem to solve is how do you know which cubes to move when you make an action? I solved this problem with no errors by making a custom group recognizing the layers depending on the positions of each cube.

Find Layers

This does work really well but the problem I currently have is I am not really used to use the an matrices. I tried to make a prototype in order to make the layer rotate around the center, but the problem is the animation seems to cumulate on each frame and you can't go back by returning to the first frame.

[matrix system[2]

If you could help me to find a solution for my non knowledge of the matrix system this would be really helpful.

Maybe the approach I am using to create this is not the most efficient one...


Edit

I tried my best to fix the matrix problem and found an other approach which is parenting every cube of a face / layer to the center cube of the layer (unlike the real Rubik's, there is still a center cube in order to control mid layers).

I created this custom node group, and when I animate the rotation of a center cube after linking the correct cubes to it, it works well!

But if I try to make it a group and then put two one after the other, the animations get cumulated, and you have both of the rotation occuring at once. Also this make the rotation of the linked cubes happen a strange way, and I didn't figure out why.

I provided some text help in the blend file to help you understand the project without going through each individual node because the project is a little bit complex now.

$\endgroup$
2

2 Answers 2

23
$\begingroup$

Here is my solution: enter image description here enter image description here enter image description here

(updated to v3.5)

How to Use:

-First, download and install Animation Nodes v1.6 from here.

-Open the file, DIY your own sramble and solution notation list in Text Editor.

-Tweak parameters on Settings node if needed, then play animation.

Advantages:

  1. Use standard move notations to control moves.
  2. Allow playback.
  3. Solvable (any move is pre-calculated).
  4. The whole cube is parented to a root object for additional transformation control.
  5. With a few more additional features for convenience.

Basic Idea:

First, generate a sequenced euler list by the notations read from textblock(s) for each move.

Second, generate bool list for each unit to decide whether it should be rotated according to the notation during each move (e.g. when notation is U, it means only the top layer will be moved, while the mid layer and bottom layer will keep still).

For the unit objects, a custom property called Position ID is implemented, which indicates the exact position of each unit right before next move starts. After moving(rotating), the Position ID will be overwritten by a new one according to the new position.

[TBC..]

$\endgroup$
6
  • $\begingroup$ @Leon_Cheung Thanks a lot for you blend file, I if you had the time to explain your work to the community (and me by the way) this would be awesome, but I will try to go into it anyway and figure out how you did this. $\endgroup$ Apr 17, 2017 at 17:35
  • $\begingroup$ Actually I tried to answer the similar question before. See here. The solution there got also got its own pros and cons, will try to explain more if needed. $\endgroup$ Apr 17, 2017 at 17:36
  • 1
    $\begingroup$ To be honest, it cost me a few days to solve that months ago. I'll find some time tomorrow to explain it (though I believe it would have to be a long one...). $\endgroup$ Apr 17, 2017 at 17:38
  • 1
    $\begingroup$ @PascalNardi Sorry for not yet explained the whole thing, I'm keep fixing things in the setup and discussing the issue with Jacques. I think v3.4 works pretty well now, I made it compatible with AN master version, try it out if interested. Will try to find time to explain it, tonight I hope. $\endgroup$ Apr 19, 2017 at 6:20
  • $\begingroup$ Hey, I haven't forgot my promise, just extremely busy in real life! I'll continue the explanation till I got enough time (within a week I hope). Patient pls. Thanks. :) $\endgroup$ Apr 30, 2017 at 1:50
8
$\begingroup$

enter image description here

The principle I used here is the following:

  • Filtering the cube list considering the frame range they need to move and the axis they correspond to
  • Rotating this filtered list around this axis

The input

enter image description here

All cubes belong to an object group.

This group is used as input for the string of nodes which define each rotation.

A rotation is itself defined by:

  • An axis: the axis is either (1,0,0), (0,1,0), (0,0,1) to indicate the corresponding positive faces, or (-1,0,0), (0,-1,0), (0,0,-1) for opposite faces
  • A rotation orientation
  • A frame which indicate the starting time for the rotation
  • A duration

!Don't overlap the nodes triggering frame!

(note that this node corresponds to a loop subprogram but is not used as a loop as the objects are given as a list input)

Animation

enter image description here

  • The animation begins with a filtering of the object list so that only the needed cubes are kept once the list is mask (it uses a 'mask list' node which is accessible with the search function)
  • Then the corresponding rotation matrix is calculated and given as input to a 'rotate' subprogram

The rotation is calculated this way:

  • We get either 90 or -90 degrees depending on the rotation orientation
  • Then divide by the amount of frames for the movement
  • This give a value "r" in degrees to be applied at each step/frame
  • This value is used to multiply the input rotation vector, so that we have an equivalent to an Euler rotation (considering that this vector have to be one of the six indicated above). So the result can only be (r, 0, 0), (0, r, 0), (0, 0, r) or (-r, 0, 0), (0, -r, 0), (0, 0, -r).
  • Once this calculation done, it is injected into a 'real' Euler rotation node

Filtering

enter image description here

  • The filter calculates if the current frame is inside the correct range (bottom part)
  • And calculates if the cubes are along the good axis (top part). This is done using a dot product which is positive if the wanted cubes locations are in the same side as the rotation axis
  • The result is a list of boolean values which is used above to filter the overall cubes list

About the dot product node:

  • This calculation assumes that the whole cube is centered and little cubes are separated at least by one unit

Rotation

enter image description here

The rotation itself is a simple matrix product.

Issues

The rotations are not always stable. Depending on the rotation speed, some cube may 'miss' (? I think) some rotation values.

I don't exactly know why: that may be some rounding issue (I don't really believe it) or other. I tried to avoid it using 'update object matrix' node (see above) but it is still not perfect... sometimes.

That could also be a bug because of the way I did it (a bug in my setting, I mean).

Using it easily

  • Assign the group named 'group.002' in the input node
  • AltA to trigger the animation
  • Esc to stop it
  • CtrlZ to come back to the initial state (and the group will come back to 'group.001' so that the cubes won't move on any change)

Note: the version of AN I'm using here is this one, which is not released yet. I've been reported that 'Mask list' node was not available in the last official release for now.

$\endgroup$
7
  • $\begingroup$ First thanks for your great answer! I suggest you to use the group subprogramm node if you are not looping through anything. Can you explain a little bit more why the vector dot product and vector scale are useful here and what they actually do? $\endgroup$ Apr 17, 2017 at 16:18
  • $\begingroup$ @PascalNardi, yes you are right about the 'group' node. Concerning the dot product, it uses the fact the input are either (1, 0, 0) or any permutation, or (-1, 0, 0) or any perm., so well placed cubes will give a positive dot product (example: (1,0,0).dot( cube location with positive x) > 1)). Scale is used to prepare the euler rotation: axis (eg. (1,0,0)) scaled by the rotation amount = (r, 0, 0). If still unclear, don't hesitate to ask. $\endgroup$
    – lemon
    Apr 17, 2017 at 16:31
  • $\begingroup$ @PascalNardi, a warning: I've exchanged with other people and it seems possible that the 'mask list' node is not available in all AN versions. The one I'm using is a testing (but very stable) version which can be found here graphicall.org/1202 $\endgroup$
    – lemon
    Apr 17, 2017 at 16:34
  • $\begingroup$ no problem i am using this build since I am also playing around with the new falloff nodes :) $\endgroup$ Apr 17, 2017 at 16:47
  • $\begingroup$ thanks for the warning (I am using this version anyway, and I ve got no stability problems yet so I confirm it's very stable). If I understand well, the node setup won't work if the individual cubes are separated by more than one blender unit, because the dot product will never be more than one... And the cube's center has to be at (0, 0, 0) (unless you make some vector sub math). Also for the scale Vector I don't think I've understood well, can you give an example where it would be useful? $\endgroup$ Apr 17, 2017 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .