[newbie] Simulating a Rotating Cube in 2D

Want to share your Moho work? Post it here.

Moderators: Víctor Paredes, Belgarath, slowtiger

RASH
Posts: 126
Joined: Sat Mar 19, 2005 10:27 am
Location: Netherlands

[newbie] Simulating a Rotating Cube in 2D

Post by RASH »

Or: how to make things complicated ;)

The 3D layer manipulation tools are very handy, but "eat Kbytes" when exported to Shockwave Flash. I imagined there should be a way to suggest an animated 3D object, without actually using the 3D feature of Moho, thus rendering much smaller file. Of course, this is very labor-intensive, because every frame has to be drawn seperately.

I hoped this project would improve my drawing skill as a Moho animator. It may seem a bit mathematical to some of you, but the manipulations by Moho are even more complicated (I guess, I haven't looked into them). Luckily, users aren't aware of the complex calculations taking place inside Moho, that is until they stop using automated tools and are doing most things manually.

My goal in this project was to create a line drawing of a cube in a two dimensional plane and animate the resulting lines/surfaces so, that they give the impression of a rotating cube. To make things not too complicated I used rotation along the Z axis of the cube (running perpendicular to the front plane of the cube). This means the front plane is always in sight.

I started with a wireframe image of a cube. It was created by overlapping two equal squares and connecting the nearby corner points. I made sure all the lines were straight and all overlapping corner points were connected.

I decided I wanted an animation of 2 seconds at a frame rate of 24 frames per second (fps). This means a full circle of 360 degrees is made in 48 frames, which comes down to 7.5 degrees of rotation per frame. To keep track of the rotation state, I created a rotation aid. For a Z axis rotation this isn't really necessary, but for more complex rotations, it might be handy. So I made this aid for future projects.

Next I created a seperate group to help me put the corner points of the front of the cube in the right place during the animation. This group consists of a cross interconnecting opposing corner points on the front side of the cube, and a circle intersecting all of these corner points. The end points of the crosses correspond to the corner points of the front side. During rotation, these points move along the circle. The resulting Flash animation can be viewed here

Knowing how the corner points of the cube are moving, is knowing how the whole cube is moving. I already knew how four corner points were moving (on the front side of the cube), so all I had to do is figuring out how the corner points on the back side of the cube were moving. Adding a back group to help me with this tasks was easy. I just copied the front group and aligned it with the back of the wireframe cube (using the move layer tool). The result was an Flash animation of the front and back groups.

Now I knew where the corner points of the cube were during the animation (at the end points of the crosses), it was easy to move the individual points from frame to frame. The result was a rotating wireframe.

To create the illusion of a rotating cube, I had to remove the hidden lines. However, it is not possible to do this in Moho in this manner. While manipulating your points and lines, you can only move points and lines during animation, not remove them. However, in a cube only three planes are visible, from whichever angle in space it is viewed from. It should be possible to the draw a cube seen from one spacial angle, then rearrange the corner points so, that it appears the cube is shown from a different angle in space. If you use the wireframe cube as a template, the illusion should be perfect.

I used this "trick" to create an animation of three rotating planes. I marked two corner points with a dot and a star, respectively, to show you the rearrangement of these points and (hopefully also) the shapes of the individual "planes" during animation.

Now it was just simple a matter of copying this animation layer and cleaning it up. Here is the end result.

The result is a very small file (only 2.2 Kbytes after compression by Flash MX), in comparison with a real 3D cube rotating in 3D. However, there is a serious limitation: all the planes must be in the same color, otherwise the illusion is lost.

There are other ways to create a rotating cube in pure 2D, e.g. creating an animation of a rotating wireframe, make as many identical copies of this animation as there are frames, make them visible only only at a particular frame, and then make the hidden lines invisible in each layer, using the Hide Edge tool, and then coloring the sides.

I tried this method and found out that you'll need only 12 layers, and show each layer every 12th frame, with a different coloring of the sides for each appearance. This is very labor-intensive, but it can be done (view this example of only 2.7 Kbytes).

I needed about 7 - 8 hours to complete this exercise and write this article. The next thing I want to do is warping simple objects with similar techniques. Warping is one of the exercises mentioned in Drawing for Classical Animation, so I'm curious if I can pull this off in Moho as well.
Toontoonz
Posts: 763
Joined: Fri Mar 25, 2005 9:28 pm

Post by Toontoonz »

This is a test I was experimenting with the other day. Is it similar to what you are trying to do or ????.

http://img253.echo.cx/my.php?image=buildingroll5js.swf

24 fps
480 K bytes
User avatar
bupaje
Posts: 1175
Joined: Fri Nov 12, 2004 5:44 pm
Location: California
Contact:

Post by bupaje »

@Rash - thanks for the detailed explanation of your experiments. I found this very interesting -a tiny bit complex for the likes of me, but the step by step process helped strech the brain a little. Look forward to your other experiments. :)
RASH
Posts: 126
Joined: Sat Mar 19, 2005 10:27 am
Location: Netherlands

Post by RASH »

I realized that there is a much easier way to create the illusion of 3D animation in 2D space. Just as with imported bitmap artwork, you can outline a real 3D animation in a seperate layer/layers and works from that.

Here is an example Flash animation I created in under an hour. Much faster than with the complex constuction. And it works for all kinds of 3D objects. You might notice some closing errors at the edges of the cube. I was just too lazy/tired to corrrect those. I've done enough for today!
RASH
Posts: 126
Joined: Sat Mar 19, 2005 10:27 am
Location: Netherlands

Post by RASH »

Toontoonz wrote:This is a test I was experimenting with the other day. Is it similar to what you are trying to do or ????.

http://img253.echo.cx/my.php?image=buildingroll5js.swf

24 fps
480 K bytes
Judging by the file size your experiment is something totally different. I guess you rotated the building in 3D, while I was merely moving lines in 2D. Nevertheless, nice animation, Toontoonz!

BTW I managed to reduce the file size of your animation from 505241 to 138205 bytes (73 % file size reduction) by using the Windows program Flash Optimizer. I have put the optimized file here. I know the quality has gone down, because I used the highest compression setting. I haven't registered Flash Optimizer, so the program returns gray scales only.

If you are using Windows, you might opt for this neat little program to reduce the file size of 3D animations.
Toontoonz
Posts: 763
Joined: Fri Mar 25, 2005 9:28 pm

Post by Toontoonz »

On your method of rotating the cube, could you add text or a design and it would appear in correctly as it rotated?
For example, if you were to put text on all planes in your cube that was parallel to the bottom or side of each plane (if one was looking straight on to the plane) and would it look correct as it rotated? (And then how big does this bump up the size of the file?)

My building example was just for flat planes rotating through 3D space.
RASH
Posts: 126
Joined: Sat Mar 19, 2005 10:27 am
Location: Netherlands

Post by RASH »

Toontoonz wrote:On your method of rotating the cube, could you add text or a design and it would appear in correctly as it rotated?
For example, if you were to put text on all planes in your cube that was parallel to the bottom or side of each plane (if one was looking straight on to the plane) and would it look correct as it rotated? (And then how big does this bump up the size of the file?)
As I wrote earlier in this thread, there is a much better method for creating simulated 3D animation. Just create a full blown 3D animation and then outline this in a layer or a group of layers, just as you would with imported bitmap images. Of course, how convincing the result is, depends on your drawing skills and how well you understand the 3-dimensional world.

Remember Moho is a character animation program, typically for cartoon animation. I think this kind of experimenting is good, but there are much more efficient programs to tackle 3D animation (e.g. Blender).

I surely don't want to use Moho for complex technical animation, because it is too limited for that area of animation.

My next experiment will be transfering self-drawn classical animation into Moho, without scanning the images (just be looking at the images). Twisting a block of rubber would do nicely.
Toontoonz
Posts: 763
Joined: Fri Mar 25, 2005 9:28 pm

Post by Toontoonz »

RASH wrote: My next experiment will be transfering self-drawn classical animation into Moho, without scanning the images (just be looking at the images). Twisting a block of rubber would do nicely.
I look forward to seeing that. :D
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post by 7feet »

I'm pretty sure that building was built from 2D layers moved around in 3D space in Moho (which I do a lot of). One of the reasons for that building seems expensive in flash is because of all the windows. If you do much of anything to a vector layer in Moho besides 2D layer translation or scaling, Moho has to export each shape in each frame as a new object to flash. So every frame has a duplicate of every visible point and curve in the project. So those windows add up to a lot of shapes. Because of this, if the walls were blank, e.g. it's just a plain ol' cube, built from 6 squares on six layers rotated and translated in 3D in Moho, you don't really end up with any more overhead for flash export than hand drawing it. You're essentially creating the same number of shapes, and it sure is easier to flexibly manipulate in Moho. Cool experiment, though.
Toontoonz
Posts: 763
Joined: Fri Mar 25, 2005 9:28 pm

Post by Toontoonz »

Yes, my 2D walls in the building example had lots of shapes on them. I recreated a smaller box, with plain walls and the file was only about 4.6 Kilobytes.

Too me that´s the way to make 3D things in Moho (as long as they are not round, anyway). The hardest thing is lining up the sides of the boxes or rectangles in the 3D space.
Anyway to write a script to automate that? If anyone can, it is you!
I have been working on a 2D - 3D (as I refer to it: 2D objects to make 3D world things) desk...in fact, a whole street of 2D-3D buildings. Trying to line the planes ofeverything up perfectly (and add a roof at an angle) and then so they look correctly (no edges or walls sneaking through at certain viewing angles) is a real brain twister for me.
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post by 7feet »

I was trying to think up a way to "fold" up a drawing. For pretty boxy stuff, it might not be too hard. Basically, draw each side of your obect, each shape on a diffent layer as if it were an unfolded, unassembled cardboard box. And then have the script match up edges and rotate and translate the edges to fold up the shape. If everything was based on 90 degree angles, it might not be too painful. I'm going to look at that. I was also going to whip out a version of my 3D shading script to work on 2D-3D objects in Moho. That might save a few minutes.
Toontoonz
Posts: 763
Joined: Fri Mar 25, 2005 9:28 pm

Post by Toontoonz »

7feet wrote:I was trying to think up a way to "fold" up a drawing. For pretty boxy stuff, it might not be too hard. Basically, draw each side of your obect, each shape on a diffent layer as if it were an unfolded, unassembled cardboard box.
That is exactly how I have been drawing my 2D/3D objects in Illustrator. Everything drawn on one plane at first - top, sides, bottom, etc. Makes it a lot easier to get everything in the object the right dimensions. I even created a house with a roof that pitched at a 30 degree angle. The hardest part was assembling it in Moho - I was trying to figure out how I could put it together simpler in Moho knowing all the dimensions and angles - but that is beyond my brainpower.
Plus this method of making all the sides a 2D vector for the finished 3D object, I can design the building or object in the drawing style I want, not having to add image maps or use 3D object type files.
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post by 7feet »

Plus this method of making all the sides a 2D vector for the finished 3D object, I can design the building or object in the drawing style I want, not having to add image maps or use 3D object type files.
Sometimes images can end up rendering faster is some cases (like if you have a million points). One thing I've done in the past, to keep a consistent look, is to draw the piece (another building, in this case), render it out, cut up the walls into separate images and import them as separate layers. Then assemble your shape. I did this in particular because I wanted a pretty fine brick texture as the surface, and it was soooo many points that Moho slowed to a crawl. Kind of a special case, though. And you need to render at pretty high res or you can't get too close. There's always tradeoffs.

Also, if you haven't, you should check out the Universal Layer Tool I made a while ago http://www.lostmarble.com/forum/viewtopic.php?t=512. Since it puts all the layer rotation, translation and scaling bits in one tool it can make it a lot less hassle to put together these sort of objects. I have a new version that's almost done, but as I think about it I really should put in a control for orbiting the workspace. That shouldn't be too hard...
RASH
Posts: 126
Joined: Sat Mar 19, 2005 10:27 am
Location: Netherlands

Post by RASH »

7feet wrote:... if the walls were blank, e.g. it's just a plain ol' cube, built from 6 squares on six layers rotated and translated in 3D in Moho, you don't really end up with any more overhead for flash export than hand drawing it. You're essentially creating the same number of shapes, and it sure is easier to flexibly manipulate in Moho.
My experiment in Moho shows something else. The original cube rotating in 3D was 2328 bytes exported and compressed as SWF, while the engineered flat version was only 1427 bytes. That is 39 percent less.

It seems if file size is important, it may pay to redraw 3D animations in two dimensions. Of course, it is so much work, that it should be the last step in your animation. Just doing a rotating cube took me 4-5 minutes per frame.

I will repeat the experiment on a more complicated 3D object animated in 3D to see if the same applies to larger files.
RASH
Posts: 126
Joined: Sat Mar 19, 2005 10:27 am
Location: Netherlands

Post by RASH »

7feet wrote:Also, if you haven't, you should check out the Universal Layer Tool I made a while ago http://www.lostmarble.com/forum/viewtopic.php?t=512.
I love you for that. It makes constructing 3D objects in Moho so much easier!
7feet wrote:I did this in particular because I wanted a pretty fine brick texture as the surface, and it was soooo many points that Moho slowed to a crawl.
Wasn't it possible to import a completed brick textured cut-out as a transparent PNG bitmap and manipulate this bitmap in 3D?
Post Reply