tech notes

advertisement
Blender to JME
Exporting Animated Blender Objects for JME Import
Overview: This document discusses how to install the necessary Ogre tools to export Ogre meshes from
Blender, test the validity of the exported meshes, and import the Ogre meshes into JME3.
References: OgreXML Exporter (A python Blender to Ogre format exporter plug-in) version 0.6.0:
http://code.google.com/p/blender2ogre/downloads/list
Ogre Command-line tools: S: drive
(S:\Dept\EG\ComputerScience\CS4710\OgreTools)
Sample java JME3 application (Main.java) for loading an Ogre .mesh.xml file and its
corresponding .skeleton.xml file (for animation) into a JME3 scene graph:
S:\Dept\EG\ComputerScience\CS4710\Animation. Also included in this folder is the
Shark.blend file to which the animation can be added by these instructions.
Setup: There are two setup tasks that you need to complete before you can export your Blender models. All
files or installers referenced below for this setup process can be found at the two folders listed in the references
above.
(1) Blender needs to be set up to with the Ogre exporter. For instructions in installing the exporter
follow the first setup step referenced in Blender To JME: Textures and Transparency.
(2) Install the Ogre Command Line Tools: These tools can be found at
S:\Dept\EG\ComputerScience\CS4710\OgreTools\OgreCommandLineTools.
Install the tools by following the task specific instructions—bullet (4)—on the next page.
(3) (Optional) OgreMeshy needs be installed to view the .mesh (i.e., binary Ogre file) files. This is
sometimes useful to get a preview of what the exported file will look like in JME. To install
OgreMeshy, use the installer OgreMeshy-1.4-Win32.exe in
S:\Dept\EG\ComputerScience\CS4710\OgreTools as described in bullet (5) on the
next page.
Specific instructions for each of these setup tasks appear next. Once the setup tasks are completed,
the general workflow for exporting the Blender object for import into a JME3 application will be
addressed.
(4) To allow automatic conversion of the .mesh.xml files exported by Blender to be viewed in
OgreMeshy do the following:
1. Copy the folder OgreCommandLineTools and the files it contains to C:\. The Ogre
exporter uses these tools to convert the .mesh.xml file into a .mesh file for viewing in
OgreMeshy.
(5) To install OgreMeshy do the following:
1. Run the OgreMeshy installer, OgreMeshy-1.4-Win32.exe.
2. Edit the file C:\Program Files (x86)\OgreMeshy\Plugins.cfg by
commenting out the line “ Plugin=RenderSystem_Direct3D9” (put a ‘#’ in the
first line to comment out this line) .
3. Start OgreMeshy (Start … All Programs … OgreMeshy … Ogre Meshy) and configure it for
your first use. I chose “No” for full-screen mode and 800x600 for video mode, but you
may choose something else to suit your preferences.
General Workflow: To test the general workflow, I have provided the file Shark.blend in the folder
S:\Dept\EG\Computer Science\CS4710\Animation. You can use this as your first test case. If you
are successful with this file, then you should then test with your own models.
(1) Create a new model in Blender (for the purposes of this document, the “Shark” object (or mesh) is that
model, which we will begin with by opening the Shark.blend file). Initially, the Shark mesh has no
bone structure. In this tutorial, we will be adding and animating a bone structure for export into JME.
(2) Ensure you are in Object mode.
(3) Press NUMPAD-1 to get into front view. Hit NUMPAD-5, if necessary to ensure you are in Ortho view.
(4) Press the Z key to move to wireframe mode, adjust your view to zoom up on the tail section of the
shark, and place you 3D cursor in the mid-part of the tail section of the shark. It should appear as
follows:
(5) Press SHIFT-A to add an armature bone. It will appear as follows:
(6) With the armature still highlighted, rotate the bone to align with the shark’s spine using R, then Y, then
type -90 (i.e., Rotate on the Y axis -90 degrees). Now TAB to edit mode and ensure the tip of the bone is
selected (the tip of the bone is the narrower side on the left) and press G, then X, then move the tip to
the narrowest part of the shark’s body, as shown.
(7) With the first bone’s tip still selected, press E (for extrude), X and place the tip of the new bone at the
end of the shark’s body, as shown below:
(8) While still in edit mode, choose the bone icon in the properties panel and with the smaller bone
selected, rename this bone FinBone. The select the larger bone and rename it TailBone. Then, click on
the object data icon (it looks like a little person) in the properties panel, find the “Display” sub-panel and
check the Names and X-Ray check boxes. TAB into object mode. Press Z to move into solid shading
mode. The situation should now look like this.
(9) Unselect all objects with A. Then select the shark mesh, and then the armature (if you selected the
object in the right order the shark should be outlined in orange and the armature in yellow). Now press
CTRL-P and choose “With Automatic Weights.” Unselect everything with A. If the parenting (i.e., CTRLP) was done in the proper order the object hierarchy should appear as below. Note, that the shark mesh
is now a child (a sub branch) of the armature. Note also, that two new vertex groups, FinBone and
TailBone, have also been added to the shark mesh.
(10)Press NUMPAD-7 to move to the top view. We are now ready to start animating the bone structure.
(Optional) You may want to save your blender file to a new name to save your progress up to this point.
(11)Up to this point, we’ve been in the default blender view. However, animation is more easily
accomplished in the “Animation” view. So click the list box chooser on the menu bar next to the word
“Default” and choose “Animation.” If necessary, restore the 3D view to a top view and zoom up on the
tail section of the shark.
(12)To animate the tail section, we will create four keyframes, one each at frames 1, 13, 37, and 49. The
process of creating a keyframe is as follows:
a. Choose the frame number
b. Modify the object’s transformations as you would like them to appear in this frame
c. Press the I Key to insert a keyframe.
(13)Select the armature object. Enter pose mode. Ensure the FinBone is selected. Open the object tool
shelf (with the N key).
(14) Keyframe 1:
a. Ensure you are in the first frame. The text (1) will appear next to the selected object at the
bottom of the 3D View window, if you are in keyframe 1.
b. In the transform sub-panel of the tool shelf, set the x rotation value to 0.00.
c. Press the I key and choose Rotation to insert a keyframe at frame 1.
The situation should appear as:
(15)To set the remainder of the key frames use the following values:
a. Frame 13: set frame to 13, set x rotation 0.15, set rotation keyframe with I key
b. Frame 37: set frame to 37, set x rotation -0.15, set rotation keyframe with I key
c. Frame 49: set frame to 49, set x rotation 0.00, set rotation keyframe with I key
(16)As each keyframe is set, that keyfame appears in two places: in the DopeSheet (the upper left of your
blender interface) and the F-Curve Editor (the lower left of your blender interface). Once all four
keyframes have been inserted, your F-Curve Editor should appear as follows:
If your F-Curve Editor appears differently, try clicking on the eye before the W-, Y-, and Z- Quaternion
Rotation to hide these (we do not need to see the effects on these, since we are only performing X
rotations). Then choose View … View All from the F-Curve Editor’s menu to see the curve on the X
rotations clearly. To read the F-Curve Editor, note that the frame number is on the horizontal axis and
the rotation value is on the vertical axis. Thus, we see that the X rotation goes from 0.00 at from 1 to
0.15 at frame 13, then to -0.15 at frame 37, and finally to 0.00 again at frame 49.
By default, the F-Curve Editor uses Bezier curves to give a smooth transition between keyframe values.
For us, a linear interpolation will suffice. So with the mouse in the F-Curve Editor window, press V and
then Vector. This will change the curve from a smooth Bezier curve to a straight-line curve, as shown:
(17)To view the animation results, set the end frame in the timeline window to 48 and press the play button.
The shark’s tail should now move from one side to the other in a cyclic fashion.
(18)Pause the animation by hitting the pause button and return the view to frame 1. Press the NUMPAD-1
key to move to front view. Ensure you are in object mode and select the shark object. Now select
weight paint mode (see the image below for how to choose this mode).
With weight paint mode selected, you should see something similar to the following:
The colors indicate how much the bone movement influences the surrounding mesh. A bright red
indicates that the bone movement has complete influence. The dark blue color indicates not influence.
The colors in between these are assigned varying degrees of influence (e.g., orange: strong influence,
yellow: some influence, green: little influence). The tail section is already colored, because in step (9)
we parented the armature to the shark using automatically assigned weights. If we wish to have
different weights assigned, we can repaint the tail in this mode. Since we are satisfied with the
automatic weights, we have no further actions for this step.
(19)Return to object mode and deselect the shark and select the armature. Note in the tool shelf that the
armature has its original -90 Y rotation and a small translation (i.e., non-zero location values) applied.
These transformations need to be zeroed for the armature to work correctly once exported. We zero
the transformations, by pressing CTRL-A and choosing Location and then pressing CTRL-A again and
choosing Rotation. Once the transformation values for location and rotation in the tool shelf are all
zero, we are ready to export. You may want to save the file at this time as a completed example.
(20)With the shark selected, Choose File … Export … Ogre3D (.scene and .mesh).
a. In the Export Ogre properties panel on the left ensure Export Selected Only,
Export Meshes, Export Meshes (Overwrite), Armature Animation, and
Export Materials are checked. Everything else should be unchecked. The swap axis
choice button should be set to xz-y.
b. Check to make sure the filename, e.g., Shark.scene, has the same name “Shark” as the
object’s mesh name that you are exporting.
c. Click the Export Ogre button next to the file path name. After a few seconds you should see
the files Shark.material, Shark.mesh, Shark.mesh.xml, Shark.skeleton,
and Shark.skeleton.xml. Shark.mesh and Shark.skeleton are the Ogre binary
format and Shark.skeleton.xml and Shark.mesh.xml are the corresponding ASCII
text-readable XML files. JME can import the XML files. The Shark.material file is a textreadable file containing colors or textures for the given mesh.
d. NOTE: When the export is complete a pop-up window appears in Blender summarizing the
results of the export. Note, you can see a more detailed report in the Blender System Console.
(21)(Optional) Check the validity of your exported model using OgreMeshy. Within OgreMeshy, select File
… Load … and then use the file dialog that appears to select the newly exported .mesh file. If the
.mesh file does not load, you can debug errors by turning on the OgreMeshy log (e.g., View … Show
Log File). Within OgreMeshy you can rotate and zoom your model. You can also view the bone
structure and play the animations.
(22)Test whether or not you can load your .mesh.xml file into JME3 by
a. Starting the jMonkeyPlatform and selecting File … New Project … JME3 …
BasicGame … Next and then filling in the project name and clicking Finish.
b. Your new project will have three folders: Project Assets, Source Packages, and Libraries. Place
your newly created .mesh.xml and related files (.material, .skeleton.xml, and any
texture maps) into the Project Assets/Models folder.
c. Replace the source in Source Packages/mygame/main.java with the source example
Main.java in S:\Dept\EG\Computer Science\CS4710\Animation.
d. Right-click on your main source file and choose Run File.
e. The shark now appears with its tail moving side to side. You are ready to test your own models.
Creating Multiple Animations in the Blender File:
The previous workflow created a single animation for export. If multiple animations are desired. Follow these
additional steps.
(1) To turn the animation completed above into a track that can be exported independent of any other
animations that may be subsequently added to the blender file, first enter the NLA Editor as shown
below. The NLA Editor is the window appearing on the right:
(2) To turn the keyframes into an animation track that can be named independently of other animations,
click on the “snowflake” icon to the right of the word “ArmatureAction.” Note: in the newest version of
Blender, the “snowflake” now appears as a
shown:
. This will create a new track containing the animation as
(3) Press the N Key in the NLA Editor window to bring up the tool shelf, so you may rename the track and
the action. Rename the track SmallSwimTrack and the action SmallSwim. Once renamed, the Ogre
exported will use the action name as the animation name in the .skeleton.xml file.
(4) To add additional animations, simply repeat the steps above, beginning with step (12) in the previous
section, i.e., you will set new pose positions at various keyframes and save the rotation positions for
those keyframes using the I KEY. Once all keyframes are set, return to the NLA Editor and follow steps
(1) through (3) in this section to create and rename a new animation track.
(5) Note, if you would like the animations to play independently, then the tracks should not overlap in the
NLA Editor. You can sequence the track along the frame timeline using the G KEY (i.e., select the track
and GRAB it to move it left or right).
Download