diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java index 027c4b5ef..424201af3 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java @@ -49,7 +49,7 @@ import com.jme3.scene.plugins.blender.file.DnaBlockData; import com.jme3.scene.plugins.blender.file.FileBlockHeader; import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.materials.MaterialContext; -import com.jme3.scene.plugins.blender.meshes.MeshHelper.VertexData; +import com.jme3.scene.plugins.blender.meshes.MeshContext; import com.jme3.scene.plugins.blender.modifiers.Modifier; /** @@ -90,8 +90,8 @@ public class BlenderContext { protected Map> modifiers = new HashMap>(); /** A list of constraints for the specified object. */ protected Map> constraints = new HashMap>(); - /** Vertex data for a mesh specified by OMA. */ - protected Map vertexData = new HashMap(); + /** A map of mesh contexts. */ + protected Map meshContexts = new HashMap(); /** A map of material contexts. */ protected Map materialContexts = new HashMap(); /** A map og helpers that perform loading. */ @@ -401,27 +401,27 @@ public class BlenderContext { return constraints.get(objectOMA); } - /** - * This method sets the vertex data for the specified mesh. Attention!!! If - * vertex data is already set it will be overwritten. + /** + * This method sets the mesh context for the given mesh old memory address. + * If the context is already set it will be replaced. * @param meshOMA - * old memeory address of mesh - * @param vertexData - * mesh's vertex data + * the mesh's old memory address + * @param meshContext + * the mesh's context */ - public void setVertexData(Long meshOMA, VertexData vertexData) { - this.vertexData.put(meshOMA, vertexData); + public void setMeshContext(Long meshOMA, MeshContext meshContext) { + this.meshContexts.put(meshOMA, meshContext); } - /** - * This method returns vertex data for a mesh with the specified old memory - * address. If no data is registered then null is returned. + /** + * This method returns the mesh context for the given mesh old memory address. + * If no context exists then null is returned. * @param meshOMA - * old memeory address of mesh - * @return mesh's vertex data + * the mesh's old memory address + * @return mesh's context */ - public VertexData getVertexData(Long meshOMA) { - return vertexData.get(meshOMA); + public MeshContext getMeshContext(Long meshOMA) { + return this.meshContexts.get(meshOMA); } /** diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java new file mode 100644 index 000000000..859617e1a --- /dev/null +++ b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java @@ -0,0 +1,106 @@ +package com.jme3.scene.plugins.blender.meshes; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.VertexBuffer; + +/** + * Class that holds information about the mesh. + * + * @author Marcin Roguski (Kaelthas) + */ +public class MeshContext { + /** The mesh stored here as a list of geometries. */ + private List mesh; + /** Vertex list that is referenced by all the geometries. */ + private List vertexList; + /** The vertex reference map. */ + private Map> vertexReferenceMap; + /** The UV-coordinates for each of the geometries. */ + private Map uvCoordinates = new HashMap(); + + /** + * This method returns the referenced mesh. + * + * @return the referenced mesh + */ + public List getMesh() { + return mesh; + } + + /** + * This method sets the referenced mesh. + * + * @param mesh + * the referenced mesh + */ + public void setMesh(List mesh) { + this.mesh = mesh; + } + + /** + * This method returns the vertex list. + * + * @return the vertex list + */ + public List getVertexList() { + return vertexList; + } + + /** + * This method sets the vertex list. + * + * @param vertexList + * the vertex list + */ + public void setVertexList(List vertexList) { + this.vertexList = vertexList; + } + + /** + * This method returns the vertex reference map. + * + * @return the vertex reference map + */ + public Map> getVertexReferenceMap() { + return vertexReferenceMap; + } + + /** + * This method sets the vertex reference map. + * + * @param vertexReferenceMap + * the vertex reference map + */ + public void setVertexReferenceMap( + Map> vertexReferenceMap) { + this.vertexReferenceMap = vertexReferenceMap; + } + + /** + * This method adds the mesh's UV-coordinates. + * + * @param geometry + * the mesh that has the UV-coordinates + * @param vertexBuffer + * the mesh's UV-coordinates + */ + public void addUVCoordinates(Geometry geometry, VertexBuffer vertexBuffer) { + uvCoordinates.put(geometry, vertexBuffer); + } + + /** + * This method returns the mesh's UV-coordinates. + * + * @param geometry + * the mesh + * @return the mesh's UV-coordinates + */ + public VertexBuffer getUVCoordinates(Geometry geometry) { + return uvCoordinates.get(geometry); + } +} diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java index 56bc1c89a..360a9654f 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java @@ -108,7 +108,8 @@ public class MeshHelper extends AbstractBlenderHelper { // reading mesh data String name = structure.getName(); - + MeshContext meshContext = new MeshContext(); + // reading vertices Vector3f[] vertices = this.getVertices(structure, blenderContext); int verticesAmount = vertices.length; @@ -243,7 +244,8 @@ public class MeshHelper extends AbstractBlenderHelper { } } } - blenderContext.setVertexData(structure.getOldMemoryAddress(), new VertexData(vertexList, vertexReferenceMap)); + meshContext.setVertexList(vertexList); + meshContext.setVertexReferenceMap(vertexReferenceMap); Vector3f[] normals = normalList.toArray(new Vector3f[normalList.size()]); @@ -383,14 +385,19 @@ public class MeshHelper extends AbstractBlenderHelper { for(Entry> entry : materialMap.entrySet()) { MaterialContext materialContext = blenderContext.getMaterialContext(entry.getKey()); if(materialContext != null && materialContext.getTexturesCount()>0) { - UVCoordinatesGenerator.generateUVCoordinates(materialContext.getUvCoordinatesType(), + VertexBuffer coords = UVCoordinatesGenerator.generateUVCoordinates(materialContext.getUvCoordinatesType(), materialContext.getProjectionType(), materialContext.getTextureDimension(), materialContext.getProjection(0), entry.getValue()); + //setting the coordinates inside the mesh context + for(Geometry geometry : entry.getValue()) { + meshContext.addUVCoordinates(geometry, coords); + } } } } blenderContext.addLoadedFeatures(structure.getOldMemoryAddress(), structure.getName(), structure, geometries); + blenderContext.setMeshContext(structure.getOldMemoryAddress(), meshContext); return geometries; } @@ -499,22 +506,4 @@ public class MeshHelper extends AbstractBlenderHelper { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) { return true; } - - public static class VertexData { - private List vertexList; - private Map> vertexReferenceMap; - - public VertexData(List vertexList, Map> vertexReferenceMap) { - this.vertexList = vertexList; - this.vertexReferenceMap = vertexReferenceMap; - } - - public List getVertexList() { - return vertexList; - } - - public Map> getVertexReferenceMap() { - return vertexReferenceMap; - } - } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java index 1ba90063a..399c93553 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java @@ -33,7 +33,7 @@ import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.file.FileBlockHeader; import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Structure; -import com.jme3.scene.plugins.blender.meshes.MeshHelper.VertexData; +import com.jme3.scene.plugins.blender.meshes.MeshContext; import com.jme3.scene.plugins.blender.objects.ObjectHelper; import com.jme3.scene.plugins.ogre.AnimData; import com.jme3.util.BufferUtils; @@ -198,11 +198,10 @@ import com.jme3.util.BufferUtils; Map groupToBoneIndexMap = armatureHelper.getGroupToBoneIndexMap(defBase, blenderContext); int[] bonesGroups = new int[] { 0 }; + MeshContext meshContext = blenderContext.getMeshContext(meshStructure.getOldMemoryAddress()); - VertexData vertexData = blenderContext.getVertexData(meshStructure.getOldMemoryAddress()); - - VertexBuffer[] boneWeightsAndIndex = this.getBoneWeightAndIndexBuffer(meshStructure, vertexData.getVertexList().size(), bonesGroups, - vertexData.getVertexReferenceMap(), groupToBoneIndexMap, blenderContext); + VertexBuffer[] boneWeightsAndIndex = this.getBoneWeightAndIndexBuffer(meshStructure, meshContext.getVertexList().size(), bonesGroups, + meshContext.getVertexReferenceMap(), groupToBoneIndexMap, blenderContext); this.verticesWeights = boneWeightsAndIndex[0]; this.verticesWeightsIndices = boneWeightsAndIndex[1]; this.boneGroups = bonesGroups[0]; diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java index f1190f630..12d9ed4ac 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java @@ -19,6 +19,7 @@ public abstract class Modifier { public static final String ARMATURE_MODIFIER_DATA = "ArmatureModifierData"; public static final String PARTICLE_MODIFIER_DATA = "ParticleSystemModifierData"; public static final String MIRROR_MODIFIER_DATA = "MirrorModifierData"; + public static final String SUBSURF_MODIFIER_DATA = "SubsurfModifierData"; public static final String OBJECT_ANIMATION_MODIFIER_DATA = "ObjectAnimationModifierData"; /** This variable indicates if the modifier is invalid (true) or not (false). */ diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/UVCoordinatesGenerator.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/UVCoordinatesGenerator.java index 114932b58..9db50e431 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/UVCoordinatesGenerator.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/UVCoordinatesGenerator.java @@ -94,8 +94,9 @@ public class UVCoordinatesGenerator { * an array that tells how UV-coordinates need to be swapped * @param geometries * a list of geometries the UV coordinates will be applied to + * @return created UV-coordinates buffer */ - public static void generateUVCoordinates(int texco, int projection, int textureDimension, int[] coordinatesSwappingIndexes, List geometries) { + public static VertexBuffer generateUVCoordinates(int texco, int projection, int textureDimension, int[] coordinatesSwappingIndexes, List geometries) { if (textureDimension != 2 && textureDimension != 3) { throw new IllegalStateException("Unsupported texture dimension: " + textureDimension); } @@ -189,6 +190,8 @@ public class UVCoordinatesGenerator { mesh.clearBuffer(VertexBuffer.Type.TexCoord);// in case there are coordinates already set mesh.setBuffer(result); } + + return result; } /**