Prechádzať zdrojové kódy

Merge branch 'master' of github.com:jMonkeyEngine/jmonkeyengine

Kirill Vainer 9 rokov pred
rodič
commit
f5c5d161d0

+ 15 - 6
jme3-blender/src/main/java/com/jme3/scene/plugins/blender/materials/MaterialContext.java

@@ -1,6 +1,7 @@
 package com.jme3.scene.plugins.blender.materials;
 
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -157,14 +158,14 @@ public final class MaterialContext implements Savable {
         }
 
         // applying textures
+        int textureIndex = 0;
         if (loadedTextures != null && loadedTextures.size() > 0) {
-            int textureIndex = 0;
             if (loadedTextures.size() > TextureHelper.TEXCOORD_TYPES.length) {
                 LOGGER.log(Level.WARNING, "The blender file has defined more than {0} different textures. JME supports only {0} UV mappings.", TextureHelper.TEXCOORD_TYPES.length);
             }
             for (CombinedTexture combinedTexture : loadedTextures) {
                 if (textureIndex < TextureHelper.TEXCOORD_TYPES.length) {
-                    combinedTexture.flatten(geometry, geometriesOMA, userDefinedUVCoordinates, blenderContext);
+                    String usedUserUVSet = combinedTexture.flatten(geometry, geometriesOMA, userDefinedUVCoordinates, blenderContext);
 
                     this.setTexture(material, combinedTexture.getMappingType(), combinedTexture.getResultTexture());
                     List<Vector2f> uvs = combinedTexture.getResultUVS();
@@ -173,13 +174,19 @@ public final class MaterialContext implements Savable {
                         uvCoordsBuffer.setupData(Usage.Static, 2, Format.Float, BufferUtils.createFloatBuffer(uvs.toArray(new Vector2f[uvs.size()])));
                         geometry.getMesh().setBuffer(uvCoordsBuffer);
                     }//uvs might be null if the user assigned non existing UV coordinates group name to the mesh (this should be fixed in blender file)
+                    
+                    if(usedUserUVSet != null) {
+                    	userDefinedUVCoordinates = new HashMap<>(userDefinedUVCoordinates);
+                    	userDefinedUVCoordinates.remove(usedUserUVSet);
+                    }
                 } else {
                     LOGGER.log(Level.WARNING, "The texture could not be applied because JME only supports up to {0} different UV's.", TextureHelper.TEXCOORD_TYPES.length);
                 }
             }
-        } else if (userDefinedUVCoordinates != null && userDefinedUVCoordinates.size() > 0) {
-            LOGGER.fine("No textures found for the mesh, but UV coordinates are applied.");
-            int textureIndex = 0;
+        }
+
+        if (userDefinedUVCoordinates != null && userDefinedUVCoordinates.size() > 0) {
+            LOGGER.fine("Storing unused, user defined UV coordinates sets.");
             if (userDefinedUVCoordinates.size() > TextureHelper.TEXCOORD_TYPES.length) {
                 LOGGER.log(Level.WARNING, "The blender file has defined more than {0} different UV coordinates for the mesh. JME supports only {0} UV coordinates buffers.", TextureHelper.TEXCOORD_TYPES.length);
             }
@@ -190,7 +197,9 @@ public final class MaterialContext implements Savable {
                     uvCoordsBuffer.setupData(Usage.Static, 2, Format.Float, BufferUtils.createFloatBuffer(uvs.toArray(new Vector2f[uvs.size()])));
                     geometry.getMesh().setBuffer(uvCoordsBuffer);
                 } else {
-                    LOGGER.log(Level.WARNING, "The texture could not be applied because JME only supports up to {0} different UV's.", TextureHelper.TEXCOORD_TYPES.length);
+                    LOGGER.log(Level.WARNING, "The user's UV set named: '{0}' could not be stored because JME only supports up to {1} different UV's.", new Object[] {
+                		entry.getKey(), TextureHelper.TEXCOORD_TYPES.length
+                    });
                 }
             }
         }

+ 21 - 16
jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/CombinedTexture.java

@@ -119,22 +119,24 @@ public class CombinedTexture {
         }
     }
 
-    /**
-     * This method flattens the texture and creates a single result of Texture2D
-     * type.
-     * 
-     * @param geometry
-     *            the geometry the texture is created for
-     * @param geometriesOMA
-     *            the old memory address of the geometries list that the given
-     *            geometry belongs to (needed for bounding box creation)
-     * @param userDefinedUVCoordinates
-     *            the UV's defined by user (null or zero length table if none
-     *            were defined)
-     * @param blenderContext
-     *            the blender context
-     */
-    public void flatten(Geometry geometry, Long geometriesOMA, Map<String, List<Vector2f>> userDefinedUVCoordinates, BlenderContext blenderContext) {
+	/**
+	 * This method flattens the texture and creates a single result of Texture2D
+	 * type.
+	 * 
+	 * @param geometry
+	 *            the geometry the texture is created for
+	 * @param geometriesOMA
+	 *            the old memory address of the geometries list that the given
+	 *            geometry belongs to (needed for bounding box creation)
+	 * @param userDefinedUVCoordinates
+	 *            the UV's defined by user (null or zero length table if none
+	 *            were defined)
+	 * @param blenderContext
+	 *            the blender context
+	 * @return the name of the user UV coordinates used (null if the UV's were
+	 *         generated)
+	 */
+    public String flatten(Geometry geometry, Long geometriesOMA, Map<String, List<Vector2f>> userDefinedUVCoordinates, BlenderContext blenderContext) {
         Mesh mesh = geometry.getMesh();
         Texture previousTexture = null;
         UVCoordinatesType masterUVCoordinatesType = null;
@@ -226,6 +228,7 @@ public class CombinedTexture {
             }
             resultUVS = ((TriangulatedTexture) resultTexture).getResultUVS();
             resultTexture = ((TriangulatedTexture) resultTexture).getResultTexture();
+            masterUserUVSetName = null;
         }
 
         // setting additional data
@@ -234,6 +237,8 @@ public class CombinedTexture {
         // otherwise ugly lines appear between the mesh faces
         resultTexture.setMagFilter(MagFilter.Nearest);
         resultTexture.setMinFilter(MinFilter.NearestNoMipMaps);
+        
+        return masterUserUVSetName;
     }
 
     /**

+ 17 - 1
jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java

@@ -409,7 +409,23 @@ public class SkeletonControl extends AbstractControl implements Cloneable, JmeCl
         // Not automatic set cloning yet
         Set<Material> newMaterials = new HashSet<Material>();
         for( Material m : this.materials ) {
-            newMaterials.add(cloner.clone(m));
+            Material mClone = cloner.clone(m);
+            newMaterials.add(mClone);
+            if( mClone != m ) {
+                // Material was really cloned so clear the bone matrices in case
+                // this is hardware skinned.  This allows a local version to be
+                // used and will be reset on the material.  Really this just avoids
+                // the 'safety' check in controlRenderHardware().  Right now material
+                // doesn't clone itself with the cloner (and doesn't clone its parameters)
+                // else this would be unnecessary.
+                MatParam boneMatrices = mClone.getParam("BoneMatrices");
+                
+                // ...because for some strange reason you can't clear a non-existant 
+                // parameter.
+                if( boneMatrices != null ) {                    
+                    mClone.clearParam("BoneMatrices");
+                }
+            }
         }
         this.materials = newMaterials;
     }

+ 2 - 2
jme3-core/src/main/java/com/jme3/util/clone/Cloner.java

@@ -207,10 +207,10 @@ public class Cloner {
 
         // Check the index to see if we already have it
         Object clone = index.get(object);
-        if( clone != null ) {
+        if( clone != null || index.containsKey(object) ) {
             if( log.isLoggable(Level.FINER) ) {
                 log.finer("cloned:" + object.getClass() + "@" + System.identityHashCode(object)
-                            + " as cached:" + clone.getClass() + "@" + System.identityHashCode(clone));
+                            + " as cached:" + (clone == null ? "null" : (clone.getClass() + "@" + System.identityHashCode(clone))));
             }
             return type.cast(clone);
         }