Hi *,
it would be nice to patch the flow code into the jme base. maybe you can comment if this methode works fine in your opinion.
# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and n newlines.
# Above lines and this line are ignored by the patching process.
Index: src/com/jmex/model/ogrexml/MaterialLoader.java
--- src/com/jmex/model/ogrexml/MaterialLoader.java Base (BASE)
+++ src/com/jmex/model/ogrexml/MaterialLoader.java Locally Modified (Based On LOCAL)
@@ -51,6 +51,7 @@
import com.jme.image.Texture.MinificationFilter;
import com.jme.image.Texture.WrapMode;
import com.jme.renderer.ColorRGBA;
+import com.jme.scene.Skybox;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.CullState;
import com.jme.scene.state.GLSLShaderObjectsState;
@@ -66,6 +67,7 @@
import com.jme.util.resource.RelativeResourceLocator;
import com.jme.util.resource.ResourceLocator;
import com.jme.util.resource.ResourceLocatorTool;
+import java.util.ArrayList;
/**
* Reads OGRE3D material files<br/>
@@ -228,6 +230,8 @@
// ??
}
logger.fine("FILTERING: "+mode);
+ } else if (stat_name.equals("cubic_texture")) {
+ readCubicTextureUnit(tex, unit);
}else{
logger.fine("UNIT STAT: "+stat_name);
}
@@ -236,6 +240,97 @@
reader.nextToken();
}
+ /**
+ * Methode readCubicTextureUnit:
+ * Sets the images (texture) used in a cubic texture, i.e. one made up of 6
+ * individual images making up the faces of a cube. These kinds of
+ * textures are used for reflection maps (if hardware supports cubic
+ * reflection maps) or skyboxes. There are 2 formats, a brief format
+ * expecting image names of a particular format and a more flexible but
+ * longer format for arbitrarily named textures.
+ * Format1 (short): cubic_texture <base_name> <combinedUVW|separateUV>
+ * The base_name in this format is something like 'skybox.jpg', and the
+ * system will expect you to provide skybox_fr.jpg, skybox_bk.jpg,
+ * skybox_up.jpg, skybox_dn.jpg, skybox_lf.jpg, and skybox_rt.jpg for
+ * the individual faces.
+ * Format2 (long): cubic_texture <front> <back> <left> <right> <up>
+ * <down> separateUV
+ * In this case each face is specified explicitly, incase you don't
+ * want to conform to the image naming standards above. You can only
+ * use this for the separateUV version since the combinedUVW version
+ * requires a single texture name to be assigned to the combined 3D
+ * texture (see below).
+ * In both cases the final parameter means the following:
+ * combinedUVW
+ * The 6 textures are combined into a single 'cubic' texture map which
+ * is then addressed using 3D texture coordinates with U, V and W
+ * components. Necessary for reflection maps since you never know which
+ * face of the box you are going to need. Note that not all cards
+ * support cubic environment mapping.
+ * separateUV The 6 textures are kept separate but are all referenced
+ * by this single texture layer. One texture at a time is active
+ * (they are actually stored as 6 frames), and they are addressed
+ * using standard 2D UV coordinates. This type is good for skyboxes
+ * since only one face is rendered at one time and this has more
+ * guaranteed hardware support on older cards.
+ *
+ * @param tex
+ * @param unit
+ * @throws IOException
+ */
+ public void readCubicTextureUnit(TextureState tex, int unit) throws IOException {
+
+ reader.nextToken();
+ String texName = nextStatement();
+ reader.nextToken();
+ String mode = nextStatement();
+ // cubic_texture <base_name> <combinedUVW|separateUV>
+ if (mode.equals("separateUV") || mode.equals("combinedUVW")) {
+ String surffix = texName.substring(texName.indexOf("."), texName.length());
+ String baseName = texName.substring(0, texName.indexOf("."));
+ // Skybox representation of <front> <back> <left> <right> <up> <down>
+ String skyboxOder[] = {Skybox.Face.Up.name(), Skybox.Face.Down.name(), Skybox.Face.East.name(), Skybox.Face.West.name(), Skybox.Face.South.name(), Skybox.Face.North.name()};
+ for (String skyboxName : skyboxOder) {
+ String materialFile = baseName + "_" + skyboxName;
+ URL texURL = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, materialFile);
+ if (texURL != null) {
+ Texture t = TextureManager.loadTexture(texURL,
+ MinificationFilter.Trilinear,
+ MagnificationFilter.Bilinear, 0.0f, false);
+ t.setWrap(WrapMode.Repeat);
+ tex.setTexture(t, unit);
+ unit += 1;
+ }
+ }
+ } else {
+ // Format 2: cubic_texture <front> <back> <left> <right> <up> <down> separateUV
+ ArrayList<String> imageNameList = new ArrayList();
+ imageNameList.add(texName);
+ imageNameList.add(mode);
+ while (!texName.equals("separateUV")) {
+ reader.nextToken();
+ texName = nextStatement();
+ if (!texName.equals("separateUV")) {
+ imageNameList.add(texName);
+ }
+ }
+ if (imageNameList.size() == 6) {
+ for (String fileName : imageNameList) {
+ URL texURL = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, fileName);
+ if (texURL != null) {
+ Texture t = TextureManager.loadTexture(texURL,
+ MinificationFilter.Trilinear,
+ MagnificationFilter.Bilinear, 0.0f, false);
+ t.setWrap(WrapMode.Repeat);
+ tex.setTexture(t, unit);
+ unit += 1;
+ }
+
+ }
+ }
+ }
+ }
+
public void readTextureUnit(Material material) throws IOException{
// skip 'texture_unit'
nextStatement();