Blender to jme textures and Transparency

Download 21.51 Kb.
Size21.51 Kb.
Blender to JME

Textures and Transparency

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.

OgreXML Exporter (A python Blender to Ogre format exporter plug-in) version 0.6.0:

Ogre v1.8 Manual (particularly the section on Scripts …. Material Scripts):

Java Monkey Engine and SDK: Download JME SDK 3.0beta. Use TestSceneLoading as basis for test application

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.

  1. This step prepares Blender for exporting in the Ogre format. To do this:

  1. Download the exporter (e.g., from the second reference above. .

  2. Start Blender.

  3. 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 and enter as the filename. Click the Install from File … button to the right of the directory name.

  4. Back in the Addons tab, click the checkbox on the far right for the Import-Export: Ogre Exporter …

  5. Click the Save User Settings button at the bottom of the Addons window. Then close the window.

  6. 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.

  1. 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:

    1. 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.

    2. 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

    3. To the file add imports to com.jme3.light.AmbientLight, com.jme3.light.DirectionalLight, and com.jme3.scene.Spatial.

    4. Replace the body of the method simpleInitApp() with the code below

cam.setLocation(new Vector3f(5.0f, 5.0f, 5.0f));

cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);

Spatial node1 = assetManager.loadModel


AmbientLight al = new AmbientLight();


DirectionalLight sun1 = new DirectionalLight();


Vector3f( 0.69077975f, -0.6277887f,




DirectionalLight sun2 = new DirectionalLight();


Vector3f(-0.69077975f, 0.6277887f,





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.

  1. 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.

  2. 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.

  3. Change the right-most window type to UV/Image Editor.

  4. In the left-most 3D View window, enter edit mode (Tab).

  5. 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.

  6. 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.

  7. Set the 3D View shading (e.g., viewport shading can be one of wireframe, solid, etc.) to Texture.

  8. Select the Materials context in the properties window on the middle left of the blender interface.

  9. Set the following Material properties:

    1. Click the check-box in the Transparency sub-panel and ensure Z Transparency is selected.

  10. Select the Texture context in the properties window on the middle left of the blender interface.

  11. Set the following Texture properties:

    1. For the texture type, choose Image or Movie.

    2. In the Preview sub-panel, check Show Alpha.

    3. In the Image sub-panel, click Open and use the file dialog that appears to find and open your texture (image) file. Remember, the texture file much have an transparency (i.e., alpha) layer.

    4. In the Image sub-panel, directly below the ‘S’ in the word “Source” is an icon that looks like an empty inbox. Clicking on this icon “packs” the image. Click on this icon to pack the image.

    5. In the Mapping sub-panel

      1. Use UV for Coordinate.

      2. Use Flat for Projection.

    6. In the Influence sub-panel

      1. Check Alpha in the Diffuse section.

      2. Use Multiply for Blend.

  12. In the UV/Image Editor window which you opened in step (3), click the icon to the left of the New button and choose the file name of the texture you opened in step (11c).

  13. (Optional) Relocate the faces of the object in the UV/Image Editor as desired to texture map the object.

  14. Select all the faces of your object (A)

  15. Return to object mode (TAB). Your object to export should be highlighted, if it is not select it to highlight it.

  16. Export the object to the Models folder of your JME project created in the setup on page one using File ... Export ... Ogre 3D (.scene and .mesh). Use the following export options:

    1. Copy shader programs

    2. Swap Axis: xz-y

    3. Export Selected Only

    4. Export Meshes

    5. Export Meshes (overwrite)

    6. Optimize Arrays

    7. Export Materials

    8. You can leave the remainder as their defaults.

  17. Remember to replace YourModelName in with the base name of the model you just exported in step (16).

  18. Open the YourModelName.material file in your project’s Models folder in your favorite text editor (like Notepad++).

  19. 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”

  20. 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.

  21. Save your changes to the .material file.

  22. 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

  23. Execute your 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.

  24. Good job!iii


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.

Download 21.51 Kb.

Share with your friends:

The database is protected by copyright © 2024
send message

    Main page