Overview: This document discusses how to apply UV texture mapping, including textures with transparency, to Blender models and export those models so that load correctly into a JME scene graph.
References: Blender Modeler: An open-source 3D modeler for computer graphics. http://www.blender.org/download
OgreXML Exporter (A python Blender to Ogre format exporter plug-in) version 0.6.0: http://code.google.com/p/blender2ogre/downloads/list
Ogre v1.8 Manual (particularly the section on Scripts …. Material Scripts): http://www.ogre3d.org/docs/manual/index.html
Java Monkey Engine and SDK: Download JME SDK 3.0beta. Use TestSceneLoading as basis for test application http://hub.jmonkeyengine.org/downloads
Ogre Mesh Tools: The Ogre mesh tools provides a viewer (OrgeMeshy). The tools can be found on the S: drive (S:\Dept\EG\Computer Science\CS4710\OgreTools
Setup: Before beginning, ensure you have installed Blender and JME SDK 3.0 Stable. Then, to complete the setup, take the actions in step (1) and (2) below.
This step prepares Blender for exporting in the Ogre format. To do this:
Download the exporter (e.g., blender2ogre-0.6.0.zip) from the second reference above. .
Under the File ... User Preferences choose the Addons tab. Click the Install from File button that appears at the bottom of the user preferences window. Enter the directory where you saved blender2ogre-0.6.0.zip and enter blender2ogre-0.6.0.zip as the filename. Click the Install from File … button to the right of the directory name.
Back in the Addons tab, click the checkbox on the far right for the Import-Export: Ogre Exporter …
Click the Save User Settings button at the bottom of the Addons window. Then close the window.
Verify that Blender is now set up to export in the Ogre format by verifying that File ... Export ... Ogre3D (.scene and .mesh)is a valid export option. Note: Blender needs to be in object mode (not edit mode) for the option to be selectable.
This step builds a sample JME application for viewing the model which you will build and texture using the General Workflow instructions on the next page. To create that JME application, do the following:
Within the JME SDK choose File ... New Project (CTRL-SHIFT-N). Category should be JME3 and Project should be BasicGame. Select Next. Choose a project name, select a folder location for the project and click Finish.
Expand the file hierarchy on the left by left-clicking on the “+” symbol. Expand your project, then the Source Packages folder, then the mygame folder to reveal the file Main.java.
To the file Main.java add imports to com.jme3.light.AmbientLight, com.jme3.light.DirectionalLight, and com.jme3.scene.Spatial.
Replace the body of the method simpleInitApp() with the code below
After making the code changes above, but before running the program you will create your model with transparent textures using the workflow below. Once your model is created and exported to the ./Project Assets/Models folder of your game, replace the italicized text YourModelName with the actual name of your exported model.
General Workflow: The following is a brief synopsis of the general workflow for creating and exporting Blender models with transparent texture into an XML format that is usable by JME. This workflow assumes the reader already has a texture with a transparency layer (such as would occur in the .png file type) and is generally familiar with the Blender interface.
Create a new model in Blender without materials. For simplicity, you could just use the default cube model appearing in a new Blender file. Although, if you prefer, you could use any other polygonal mesh model.
Divide the 3D View in two by clicking and dragging to the left from the “cross-hatched” area in the upper right of the window.
Change the right-most window type to UV/Image Editor.
In the left-most 3D View window, enter edit mode (Tab).
In edit mode, select all the faces (A) and unwrap (U) the object (using Smart UV Project). Note: while not required, to get your best unwrapping, you may prefer to make certain seams on your model before unwrapping. That process is not part of this workflow. Information on UV unwrapping can be found belowi.
While still in the 3D View, bring up the right tool shelf by clicking the small “+” on the upper right or typing the hot key (N). In the Display sub-panel of the tool shelf, set Shading to GLSL.
Set the 3D View shading (e.g., viewport shading can be one of wireframe, solid, etc.) to Texture.
Select the Materials context in the properties window on the middle left of the blender interface.
Set the following Material properties:
Click the check-box in the Transparency sub-panel and ensure Z Transparency is selected.
Select the Texture context in the properties window on the middle left of the blender interface.
Remember to replace YourModelName in Main.java with the base name of the model you just exported in step (16).
Open the YourModelName.material file in your project’s Models folder in your favorite text editor (like Notepad++).
Find the text “cull_hardware” and replace the attribute which follows it (it should be “clockwise”) with “none”, so that the line reads “cull_hardware none”
Find the text “scene_blend” and replace the following two attributes with “alpha_blend” so that the final result is “scene_blend alpha_blend”, be careful that you do NOT change the “scene_blend_op” line.
Save your changes to the .material file.
Ensure your .material file has the same base name as your .mesh.xml file. For example, if your .mesh.xml file is named YourModelName.mesh.xml, then your .material file should be named YourModelName.material.ii
Execute your Main.java program within the JME SDK. In the middle of your render window you should see your model with the texture and transparency applied as you specified in Blender.
ii In the presence of multiple materials, the Ogre exporter creates multiple .material files. These materials will need to be combined into one .material file with the same base name as the .mesh.xml file.
iii Note: If your model appears as a red object, it may be that you have not named your material with the same base name as the mesh, or the material file does not include all of the appropriate material definitions.