Wednesday, August 20, 2014

The last LibreOffice release came with 3D model support in Impress. Now you can insert 3D models onto your slides in the open formats of glTF,COLLADA and KMZ. To do that go to Insert->Object->3D Model... in the menu hierarchy and after you selected a file you can see the model on your slide:

Animated models

The inserted 3D models also can define some animations. In this case after insertion you can control the animation using the media toolbar's play/pause/stop buttons. During implementation we lean on the existing movie player feature, that's why 3D animations behave the same as movies. This similarity also exists inside the slideshow which means animations are also started as soon as the actual slide appears and the same custom animations are available to trigger play/pause/stop events.

Hidden features of the model viewer window

This 3D model feature was implemented a bit late in the releasing process that can explain why some features of the viewer window does not appear noticeable on the UI. Hopefully the situation will be better on the next release, but until then let's see what are these features are.

First you should know that the viewer window is active only when the 3D model is "played" (push play button on the media toolbar or start the slideshow), even if the model actually doesn't have any animation to play. While the 3D model object is in stopped state, only a screen shot of the scene is displayed, which makes resizing and positioning easier in edit mode.

Changing camera position

So when the viewer window is active we can change the camera position to have a look at the model from different points of view. By default we are in walkthrough mode where we can handle the camera from a first-person perspective. We can move forward ('W'), backward ('S'), left ('A') and right ('D') using the keyboard and we can turn by click and drag.

You can see some pictures bellow about the walkthrough mode. However you can enter into the maze, but inside the maze navigation becomes hard. The perfect would be if we could walk in the maze like packman does but camera handling still needs some improvements.

Next to the walkthrough mode there is an other one called orbit mode. Use 'M' key to switch between the two modes. In orbit mode the camera is moved on an orbit around the model, always looking at the model. Using the keyboard we can move the camera on this orbit northward ('W'), southward ('S'), westward ('A') and eastward ('D'), and we also can change the distance between the orbit and the center of the model ('E' and 'Q' keys). Click and drag event also moves the camera on this orbit, but from the user points of view this looks rather like the model is rotated around it's center.

On the next pictures you can see the different views after the model was rotated horizontally by mouse (in other words, camera was moved around the model horizontally):

Duck model, full face

Duck model, profile

Duck model, from behind

FPS rendering

We added an FPS (frame per second) rendering possibility to the viewer window, so the rendering performance can be measured easily. By default this feature is disabled. To enable it you can press 'F' key and you will see FPS number at the right-bottom corner of the viewer window.

Monster model with FPS

About the file formats

The main format is COLLADA, the other ones are closely related to it.

First KMZ is a zipped file format which can contain 3D models in COLLADA format. So not all KMZ files can be loaded by LibreOffice, it's assumed that the given KMZ format contains only one 3D model. The main advantage of supporting KMZ format is the huge source of free 3D models on the 3D warehouse site. On this site almost all models are available in KMZ format.

The glTF format is a really new format, actually it has only a draft specification. The main purpose of the format is the better performance. It is designed to make loading and rendering of the models faster, with using such structures which are closer to the OpenGL language. It's not an independent file format but rather a runtime form of COLLADA. So in general glTF models are generated from COLLADA files and creating/editing of the 3D models is done in COLLADA format.

Since glTF is desgined to be faster, LibreOffice stores all 3D models in this form both in runtime and in the ODP file. When a KMZ or a COLLADA file is inserted into Impress, the file is converted to glTF and rendering comes just after that.

Some limitations you should aware of

First of all it's good to know that Impress uses OpenGL 3.0 for rendering of these 3D models. If your graphic card doesn't support it then only a question mark will be displayed on the screen, but the model is there, so if you save your presentation and move it to a capable computer then it will appear.

Other limitations come from that glTF is a draft format and collada2gltf tool (used for COLLADA->glTF conversion) is also unstable. So don't surprise if some of the KMZ files downloaded from Warehouse are not rendered well.
By now this feature is available only for Windows and Linux.

Who stands behind the feature

3D model support came alive as a result of the cooperation of Collabora, AMD and MCW.
First of all AMD founded our work and was coming up with new ideas about the feature.

Secondly a developer group from MCW was working on the parser/rendering code of
the glTF format. To make our cooperation with MCW more misunderstanding
tolerant we set up a wall between LibreOffice code and glTF parser code
with defining an API. Later, from that separation born an open source glTF
rendering library called libglTF. By now libglTF is still developed closely to LibreOffice.

Last but not least we at Collabora have done the integration into LibreOffice. First Markus Mohrard was working on LibreOffice OpenGL code in general, made it better/more fresh and generalized it allowing to use the same code for all OpenGL based features: OpenGL transitions, OpenGL charts and glTF models. Jan Holesovsky (Kendy) was the manager of the project, making plans, participating in brain storming and having great ideas. Matus Kukan helped us with integrating COLLADA related libraries into LibreOffice (for COLLADA->glTF conversion).

Finally I implemented embedding of glTF models into Impress by setting together the pieces (plans from Kendy, generic OpenGL pieces from Markus, COLLADA conversion from Matus and glTF rendering from MCW).