Friday, May 13, 2011

Interactively rotate and move figures in 3D space

Although GEF3D provides full 3D capabilities for placing and rotating figures, it was not possible to interactively place figures everywhere in 3D space. GEF3D adapts moving and resizing of figures as provided by GEF, by enabling moving and resizing of figures on so called virtual planes (which are unbounded surfaces). Since surfaces are always 2D planes, this is similar to moving figures in a 2D editor (in which the surface is always the screen surface). As of revision 576 (we are still working on a nightly build system, until then you have to get GEF3D from the code repository), it is possible to interactively move figures in 3D space. In the movie below, you will see how some planes are interactively moved and placed in 3D space. The editor is part of the GEF3D examples. It consists of simple (2D GEF) editors for graphs, that is labeled nodes connected with edges. Several graphs, each one drawn on its own diagram surface, are combined into a GEF3D multi editor. You will find this example called "Multiple Graphs in Dia2D Mode Sample" in the example package (org.eclipse.gef3d.examples.graph).

This closes bug 300321 and it also demonstrates a lot of nice features of GEF3D which are not that obvious. In the following, I will highlight some interesting aspects, using some snapshots taken from the movie.

Fig. 1: Virtual Plane
Figure 1 shows how 2D figures can be moved around just like moving figures with GEF. GEF3D provides a concept called "virtual planes", that is, a figure is moved parallel to a (virtually extended) surface of a 3D figure, which usually is the surface of the diagram. This always worked for 2D  figures. (For people not that much involved in GEF3D: a 2D figure actually is an original GEF or Draw2D figure! It's code is not modified at all!)

Fig. 2: 2D breaks free!
As shown in Figure 2, 2D figures are not necessarily bound to the actual surface of a 3D figure. Instead, 2D figures are rendered as real 3D content, which does improve quality and performance (Kristian is a real 3D wizard making this possible), but also removes restrictions on how 2D content is drawn in 3D.

Fig. 3: Move 3D figure on virtual plane
Now, 3D figures can be moved like that as well. A 3D figure, which is not placed onto a figure with a surface, such as the digram figure itself, can then simply be moved parallel to its own surface. This is illustrated in Figure 3.

Fig. 4: Interactively rotate 3D figure
One of the most interesting features of GEF3D is the full support of rotation. In the current version, 3D figures can be interactively rotated by holding down a modifier key (command key for on OS X, alt key for Windows and Linux). Instead of moving the figure, it is then rotated around its own x- and y axis. Figure 4 shows the feedback figure, which exactly shows the rotation.
Fig. 5: Connection anchors are placed correctly
One of the trickiest things with rotations is the correct handling of connection and connection anchors. Figure 5 shows that the connection between an element of the one diagram is still correctly connected with an element of another diagram, although the first diagram is rotated. This works with all arbitrarily rotated figures. Since 2D content is rendered using OpenGL as well, we also have no problems with image quality or whatever. So, if you need fully supported rotation capabilities for a 2D editor (in which the figures are to be rotated around the z-axis), GEF3D may be interesting for you as well (all you need to do is to restrict the camera in order to emulate a 2D editor).

Fig. 6: Move along normal vector
Holding down the modifier and shift will cause the figure to be moved orthogonally to the virtual plane, that is along its own z-axis (or normal vector). This is shown in Figure 6.

Fig. 7: Resize 3D figure
This enables one to arbitrarily place 3D figures in the 3D space. It is also possible to resize 3D figures, however at the moment I only have implemented the resizing itself. Thus, only resizing along the x- and y-axis are supported (as shown in Figure 7), because only handles for x- and y-resizing are provided yet.

While modifier keys may work in some cases, it is only a temporary hack. In the long run, we have planned to add 3D handles. We are thinking about adding handles for x-, y-, and z-axis rotation, z-axis movement, and resizing the depth of a figure. This will also remove conflicts with applications using the modifier keys for different kind of actions.


No comments:

Post a Comment