Embedding interactive 3D objects into PDF documents
Software used:
T E
X is
a language used to typeset documents, especially ones containing mathematics. The
term comes from the root of the Greek word τέχνη (art, technology). The
last letter in the name is a Greek capital Χ (chi, pronounced as in Scottish loch). It was designed to allow anybody to produce
high-quality books and to provide a system that would give exactly the same
results on all computers. The version number of T E X converges to π. The
current version is 3.1415926.
TEX
has both programming and mark-up features (like HTML language). A TEX document is a
plain text file (extension is tex) that contains both the text and its
formatting instructions.
For example, the well-known
quadratic formula would appear as:
$-b \pm \sqrt{b^2 - 4ac} \over 2a$
The T E X source file must then be compiled and turned in
the final document, typically a PDF (or PS – PostScript file), which obviously
contains only the formatted text.
Although it is still possible to
write in pure T E X, now
you are using languages that rely on it, as LATEX, that allow you
to automate, through macros, all the common tasks that involve the creation of
a document and makes it easier to produce
standard documents.
In our case we use the package movie15.sty, a
macro that
allows LATEX
to include multimedia files (sound, animation and 3D objects) and then will be
incorporated into the final PDF document.
Movie15.sty can be downloaded from CTAN (Comprehensive
TEX Archive Network), the
reference site for all TE X
materials.
http://www.ctan.org/tex-archive/macros/latex/contrib/movie15/
Now let’s prepare the TEX - LATEX
environment to use later.
After downloading the portable distribution MikTeX version 2.9 (one of the best and
most widely used distributions TEX
- LATEX for
Windows) from the site http://miktex.org/
, unpack it to a folder, eg c:\Miktex29\.
Now we must add the file movie15.sty.
Enter
unpacked MikTeX folder and click the folder 'tex' to open
and then open the folder 'latex'. Here
create a new folder and rename as 'movie15'
Copy the Movie15.sty file to the folder you just
created.
Now we have to update the system to recognize the new
package. Enter
the folder 'miktex/bin' and launch the file 'mo.exe' which opens the tab
'Options' of MikTeX
Click 'Refresh FNDB' button and close the tab by
clicking 'OK'.
Now let us deal with 3D file.
In a nutshell, a 3D file contains the coordinates (x,
y, z) of all points that detect the surface of the 3D object and, possibly, the
color and physical characteristics of its surfaces.
There is a very large number of 3D formats, but the only
ones that movie15 can embedd in PDF documents are U3D (Universal 3D) and
PRC (Product Representation Compact).
We will use the U3D format, viewable only with Adobe
Reader version 7.0 (or higher).
Since a 3D object looks
different depending on the perspective of the viewer, you must specify the
point of view, ideally replaced by a virtual camera.
There are a few options which
define how the 3D object is positioned within the view port of a virtual
camera, or conversely, how the virtual camera is positioned and oriented within
a coordinate system, called ‘The World’, which bears the 3D object at a fixed
position.
One of the problems we face is the object's position
with respect to the coordinate system (called "the world") and to the
virtual camera. If
the 3D object is placed too close or too far away or out of the virtual camera
view, the end result will be unusable. The coordinate
system bears the 3D object at a fixed position. When we
want to observe the object from different points of view, it will be room to
move the object.
In Movie15 there are a few
options which define how the 3D object is positioned contains the
following parameters that define the position and orientation of the virtual
camera relative to the reference 3D object.
We have to place the object
in the center of the orbit and determine an appropriate range for the size of
the object.
To do this we will use Accutrans
3D, a fully functional shareware that
still work at the end of the 30 day trial.
Accutrans 3D does not require installation. After
unpacking the zip file downloaded from http://www.micromouse.ca/downloads.html
is ready to work.
Using the menu command "File → Open (All
Known Formats) ..." open
knight.dxf, present as an example of 3D files in the folder 'Avatar Tutorial' of
Accutrans.
DXF (Drawing Exchange Format) is an AutoCAD 3D format.
At this point we can change the orientation of the 3D
object to fix the position as we like. We can do it manually by turning it while holding down
the left mouse button, or we can do it in a more precise way.
From the menu select the command "Tools → Adjust
Object". On
the right side of the window options and commands appear to modify the
coordinates of our 3D object.
In the 'Rotate" box click the "Y -90" button
in order to rotate the object 90 degrees counterclockwise around the Y axis, to
put it up.
Now click the "Z 90" so as to rotate the
object 90 degrees clockwise about the Z axis, to put it in front.
If we observe now the minimum and maximum coordinates
of the object in the top right
we can see that object is very far from the origin of
the axes (0,0,0).
To center the 3D object on the origin of the axes click
the button 'Center xyz'
Click 'Use Displayed Rotation' and then 'OK'
At this point we can save in the OBJ format
(Wavefront), a format which DAZ Studio 3D can import and convert into U3D
format. From
menu select 'File → Save as
..' and
from the window that appears, select Wavefront format.
In addition to knight.obj file will be generated
knight.mtl that contains information about the material of surfaces.
DAZ Studio 3D is a
freeware application, but requires registration at http://www.daz3d.com/ You will be emailled a serial number to use when you install the
program.
After you have installed and launched DAZ-3D, select
from menu item 'File → Import
..'
In the window that appears, select the file type
Wavefront Object and load the file knight.obj.
The object is too close to be fully displayed. Do not we
care. Set later the correct distance.
Select from menu 'File → Export ..' In window that appears, select the
file type Universal 3D and save the file as knight.u3d.
With VAZ3D we're done. We just need it to create U3D
files.
Also the
freeware MeshLab http://meshlab.sourceforge.net/ is
able to export U3D file format, but currently (version 1.2.3) is unable to save
the colors of the surfaces. However, it has the advantage that, with the U3D file also
generates a TEX file ready to be compiled and converted into a PDF with
embedded 3D object.
Let's now create the TEX file necessary to embed U3D
file in PDF
In the same folder where we saved the knight.u3d file
create a text file (with a right click will show a context menu from which
select 'New → Text
Document').
Open with a double-click the text file, paste (or
write) the following text and save.
\documentclass[a4paper]{article}
\usepackage[3D]{movie15}
\usepackage{hyperref}
\usepackage[english]{babel}
\begin{document}
\includemovie[
poster,
toolbar, %same as `controls'
label=knight.u3d,
text=(knight.u3d),
3Daac=60.000000, 3Droll=0,
3Dc2c=0.000000 -100.000000 0.000000, 3Droo=100.000000, 3Dcoo=0 0 0,
3Dlights=CAD
]{\linewidth}{\linewidth}{knight.u3d}
\movieref[3Dcalculate=60]{knight.u3d}{Calculate
Camera Distance}
\movieref[3Dgetview]{knight.u3d}{Capture
View!}
\end{document}
This is a TeX code.
The first four lines tell the compiler which TeX
packages are necessary for the compilation ( obviously movie15).
We then set the parameters of the virtual camera.
Instructions
\movieref[3Dcalculate=60]{knight.u3d}{Calculate
Camera Distance}
\movieref[3Dgetview]{knight.u3d}{Capture
View!}
are temporary and will create two links in the PDF
document.
The first (Calculate
camera distance) will help us to calculate the correct distance of the camera
(3Droo)
The second (Capture
View!) sets the parameters of the particular views of the 3D object that we
can later use in the final document.
Note: Links
will only work with Adobe Reader 8.0 (or later)
Rename the text file as 'knight.tex' so you can read
and compile with MikTeX.
Enter the folder where you have unpacked MikTeX and find
TexWorks.exe located in the subfolder /MiKTeX/bin
It is a TEX editor and compiler provided with the
MikTeX distribution.
Launch it with a double click. From the menu, select 'File → Open ..'
and load the file knight.tex.
The source text will appear in TEXworks. If you
want you can change it, but we simply compile by clicking the green button in
the upper left.
If the compiler finds no errors, will be created in
the same folder the file knight.pdf that will automatically be loaded
and displayed by TEXworks
in another window.
However TEXworks PDF viewer is not able to display the
3D object embedded.
We should therefore view it using Adobe Reader. At this
stage you must use at least Adobe Reader 8.0 (or higher). Earlier
versions can not properly handle links that we need to calculate the correct
distance of the object.
Loading knight.pdf file with Adobe Reader 8.0 embedded
3D object appears, but too close to the observer (so that all will be occupied
by a particular view of his green dress)
Click the link (Calculate Camera Distance) located in
the lower left, below the 3D image. We get the following dialog response while the 3D
object will be positioned at the correct distance.
The only information that interests us is the first,
which we round to 3Droo = 22542
Reopen the source file Knight.tex using the TEXworks editor
to correct line 11.
Replace with the following
3Daac=60,
3Droll=0, 3Dc2c=0 -22542 0,
3Droo=22542,
3Dcoo=0 0 0,
where the values of camera position and the radius of
the orbit that we had temporary set at -100 and 100 are replaced with the newly
calculated value (22,542).
From menu 'File → Save as ...'
save the modified TEX file as page3D.tex and recompile it to get the page3D.pdf
file.
Load the page3D.pdf file with Adobe Reader 8 where the
3D object is now correctly displayed. We can rotate it (by dragging it with the left mouse
button pressed), translate and zoom after selecting the corresponding command
from the menu that appears above the object.
Let's create some alternative 'view' to be selected
directly from the menu associated with the built-in 3D object.
In the same folder where we saved the file knight.u3d
create a text file (with a right click will show a context menu from which
select 'New → Text
Document'). Open with a double-click the text file, copy and paste (or write)
the following text and save.
VIEW={Front}
C2C=0 -1 0
ROO=22452
AAC=60
END
VIEW={Back}
C2C=0 1 0
ROO=22452
AAC=60
END
VIEW={Left}
C2C=1 0
0
ROO=22452
AAC=60
END
VIEW={Right}
C2C=-1 0 0
ROO=22452
AAC=60
END
VIEW={Top}
C2C=0 0 1
ROO=22452
AAC=60
END
These are standard views in which the object is
rotated 90 or 180 °. If we want to add a custom view, reopen
knight.pdf the file, rotate and zoom 3D object.
Once we have a shot that seems interesting click the link (Capture View). We'll get a dialog response of this type
Information are already selected. Simply right-click
over it to bring up the copy command. Click Copy and then paste informations to the text file
before (we round up the decimals). We will get
VIEW={Front}
C2C=0 -1 0
ROO=22452
AAC=60
END
VIEW={Back}
C2C=0 1 0
ROO=22452
AAC=60
END
VIEW={Left}
C2C=1 0 0
ROO=22452
AAC=60
END
VIEW={Right}
C2C=-1 0 0
ROO=22452
AAC=60
END
VIEW={Top}
C2C=0 0 1
ROO=22452
AAC=60
END
VIEW={Sword detail}
COO=168.254 2715.199 947.052
C2C=-0.9917 -0.01096 -0.12768
ROO=6229.0059
ROLL=1.9789
AAC=60
LIGHTS=CAD
RENDERMODE=Solid
END
Now save the new text file and rename it as 'views.vws'.
Load
page3D.tex file again with the TEXworks editor and modify it by deleting the
links and adding an instruction to load the file views.vws. The final
text will be
\documentclass[a4paper]{article}
\usepackage[3D]{movie15}
\usepackage{hyperref}
\usepackage[english]{babel}
\begin{document}
\includemovie[
poster,
toolbar,
%same as `controls'
label=knight.u3d,
text=(knight.u3d),
3Daac=60.000000,
3Droll=0, 3Dc2c=0.000000 -22452.000000 0.000000, 3Droo=22452.000000, 3Dcoo=0 0
0,
3Dlights=CAD,
3Dviews2=views.vws,
]{\linewidth}{\linewidth}{knight.u3d}
\end{document}
Recompile the TeX source (click the green button at
the top left of TEXworks) to get the final version of the page3D.pdf file.
Note. When TEXworks
compiles a source must generate a PDF file. If this file exists,
overwrites it, but if this file is already open (eg Adobe Reader), TEXworks
crashes and errors.
Now when we open the PDF file with Adobe Reader 7.0
(or higher), we can choose from the menu of the 3D object the preset views.
Possiamo modificare anche le dimensioni standard del
riquadro che occupa l'oggetto 3D. We
can also change the size of the standard box that 3D object takes.
If we want a box 70% smaller
{0.7\linewidth}{0.7\linewidth}{knight.u3d}
For a box 25% larger
{1.25\linewidth}{1.25\linewidth}{knight.u3d}
For a box
that has a width of 5 cm and a height of 10 cm
{5
cm}{10 cm}{knight.u3d}
Obviously, in this way we will incorporate a 3D object
on a white PDF page. If
we put it on a page that contains more text and graphics we have to compose the
entire page using TeX.
One way to put 3D objects in pages written with normal
wordprocessor.
OpenOffice (but
AbiWord too) does have the ability to export your documents in TeX format. Older
versions of OpenOffice (up to 2.0) had this feature by default. The latest
versions require that you install the extension writer2latex.oxt
downloadable from
http://extensions.services.openoffice.org/it/project/writer2latex
Once you've downloaded the extension, launch Writer
(OpenOffice word processing program). From menu select 'Tools → Extensions
Manager' and
in window that appears click 'Add ...'. Find the file writer2latex.oxt and
load it.
We can now export the document written in Writer to
TeX source, by selecting 'Export ..' from 'File' menu and
choosing TeX file type.
Once generated the TeX file, open it with TEXworks and
add to the preamble (the initial list of LaTeX packages that the compiler
should use) the line
\usepackage[3D]{movie15}
We should also add, in the position where we want it
to appear, the instruction for the inclusion of the 3D object
\includemovie[
poster,
toolbar,
%same as `controls'
label=knight.u3d,
text=(knight.u3d),
3Daac=60.000000,
3Droll=0, 3Dc2c=0.000000 -22452.000000 0.000000, 3Droo=22452.000000, 3Dcoo=0 0
0,
3Dlights=CAD,
3Dviews2=views.vws,
]{\linewidth}{\linewidth}{knight.u3d}
Finally
you have to compile the TEX file.
In
this way I have built this PDF document!!