Adding the MeshContext that will help with mesh modifications in a future.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8251 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
2b8ec329ab
commit
ec4486d5eb
@ -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.FileBlockHeader;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
import com.jme3.scene.plugins.blender.materials.MaterialContext;
|
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;
|
import com.jme3.scene.plugins.blender.modifiers.Modifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,8 +90,8 @@ public class BlenderContext {
|
|||||||
protected Map<Long, List<Modifier>> modifiers = new HashMap<Long, List<Modifier>>();
|
protected Map<Long, List<Modifier>> modifiers = new HashMap<Long, List<Modifier>>();
|
||||||
/** A list of constraints for the specified object. */
|
/** A list of constraints for the specified object. */
|
||||||
protected Map<Long, List<Constraint>> constraints = new HashMap<Long, List<Constraint>>();
|
protected Map<Long, List<Constraint>> constraints = new HashMap<Long, List<Constraint>>();
|
||||||
/** Vertex data for a mesh specified by OMA. */
|
/** A map of mesh contexts. */
|
||||||
protected Map<Long, VertexData> vertexData = new HashMap<Long, VertexData>();
|
protected Map<Long, MeshContext> meshContexts = new HashMap<Long, MeshContext>();
|
||||||
/** A map of material contexts. */
|
/** A map of material contexts. */
|
||||||
protected Map<Material, MaterialContext> materialContexts = new HashMap<Material, MaterialContext>();
|
protected Map<Material, MaterialContext> materialContexts = new HashMap<Material, MaterialContext>();
|
||||||
/** A map og helpers that perform loading. */
|
/** A map og helpers that perform loading. */
|
||||||
@ -402,26 +402,26 @@ public class BlenderContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sets the vertex data for the specified mesh. Attention!!! If
|
* This method sets the mesh context for the given mesh old memory address.
|
||||||
* vertex data is already set it will be overwritten.
|
* If the context is already set it will be replaced.
|
||||||
* @param meshOMA
|
* @param meshOMA
|
||||||
* old memeory address of mesh
|
* the mesh's old memory address
|
||||||
* @param vertexData
|
* @param meshContext
|
||||||
* mesh's vertex data
|
* the mesh's context
|
||||||
*/
|
*/
|
||||||
public void setVertexData(Long meshOMA, VertexData vertexData) {
|
public void setMeshContext(Long meshOMA, MeshContext meshContext) {
|
||||||
this.vertexData.put(meshOMA, vertexData);
|
this.meshContexts.put(meshOMA, meshContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns vertex data for a mesh with the specified old memory
|
* This method returns the mesh context for the given mesh old memory address.
|
||||||
* address. If no data is registered then null is returned.
|
* If no context exists then <b>null</b> is returned.
|
||||||
* @param meshOMA
|
* @param meshOMA
|
||||||
* old memeory address of mesh
|
* the mesh's old memory address
|
||||||
* @return mesh's vertex data
|
* @return mesh's context
|
||||||
*/
|
*/
|
||||||
public VertexData getVertexData(Long meshOMA) {
|
public MeshContext getMeshContext(Long meshOMA) {
|
||||||
return vertexData.get(meshOMA);
|
return this.meshContexts.get(meshOMA);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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<Geometry> mesh;
|
||||||
|
/** Vertex list that is referenced by all the geometries. */
|
||||||
|
private List<Vector3f> vertexList;
|
||||||
|
/** The vertex reference map. */
|
||||||
|
private Map<Integer, List<Integer>> vertexReferenceMap;
|
||||||
|
/** The UV-coordinates for each of the geometries. */
|
||||||
|
private Map<Geometry, VertexBuffer> uvCoordinates = new HashMap<Geometry, VertexBuffer>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the referenced mesh.
|
||||||
|
*
|
||||||
|
* @return the referenced mesh
|
||||||
|
*/
|
||||||
|
public List<Geometry> getMesh() {
|
||||||
|
return mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the referenced mesh.
|
||||||
|
*
|
||||||
|
* @param mesh
|
||||||
|
* the referenced mesh
|
||||||
|
*/
|
||||||
|
public void setMesh(List<Geometry> mesh) {
|
||||||
|
this.mesh = mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the vertex list.
|
||||||
|
*
|
||||||
|
* @return the vertex list
|
||||||
|
*/
|
||||||
|
public List<Vector3f> getVertexList() {
|
||||||
|
return vertexList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the vertex list.
|
||||||
|
*
|
||||||
|
* @param vertexList
|
||||||
|
* the vertex list
|
||||||
|
*/
|
||||||
|
public void setVertexList(List<Vector3f> vertexList) {
|
||||||
|
this.vertexList = vertexList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the vertex reference map.
|
||||||
|
*
|
||||||
|
* @return the vertex reference map
|
||||||
|
*/
|
||||||
|
public Map<Integer, List<Integer>> getVertexReferenceMap() {
|
||||||
|
return vertexReferenceMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the vertex reference map.
|
||||||
|
*
|
||||||
|
* @param vertexReferenceMap
|
||||||
|
* the vertex reference map
|
||||||
|
*/
|
||||||
|
public void setVertexReferenceMap(
|
||||||
|
Map<Integer, List<Integer>> 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);
|
||||||
|
}
|
||||||
|
}
|
@ -108,6 +108,7 @@ public class MeshHelper extends AbstractBlenderHelper {
|
|||||||
|
|
||||||
// reading mesh data
|
// reading mesh data
|
||||||
String name = structure.getName();
|
String name = structure.getName();
|
||||||
|
MeshContext meshContext = new MeshContext();
|
||||||
|
|
||||||
// reading vertices
|
// reading vertices
|
||||||
Vector3f[] vertices = this.getVertices(structure, blenderContext);
|
Vector3f[] vertices = this.getVertices(structure, blenderContext);
|
||||||
@ -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()]);
|
Vector3f[] normals = normalList.toArray(new Vector3f[normalList.size()]);
|
||||||
|
|
||||||
@ -383,14 +385,19 @@ public class MeshHelper extends AbstractBlenderHelper {
|
|||||||
for(Entry<Material, List<Geometry>> entry : materialMap.entrySet()) {
|
for(Entry<Material, List<Geometry>> entry : materialMap.entrySet()) {
|
||||||
MaterialContext materialContext = blenderContext.getMaterialContext(entry.getKey());
|
MaterialContext materialContext = blenderContext.getMaterialContext(entry.getKey());
|
||||||
if(materialContext != null && materialContext.getTexturesCount()>0) {
|
if(materialContext != null && materialContext.getTexturesCount()>0) {
|
||||||
UVCoordinatesGenerator.generateUVCoordinates(materialContext.getUvCoordinatesType(),
|
VertexBuffer coords = UVCoordinatesGenerator.generateUVCoordinates(materialContext.getUvCoordinatesType(),
|
||||||
materialContext.getProjectionType(), materialContext.getTextureDimension(),
|
materialContext.getProjectionType(), materialContext.getTextureDimension(),
|
||||||
materialContext.getProjection(0), entry.getValue());
|
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.addLoadedFeatures(structure.getOldMemoryAddress(), structure.getName(), structure, geometries);
|
||||||
|
blenderContext.setMeshContext(structure.getOldMemoryAddress(), meshContext);
|
||||||
return geometries;
|
return geometries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,22 +506,4 @@ public class MeshHelper extends AbstractBlenderHelper {
|
|||||||
public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
|
public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class VertexData {
|
|
||||||
private List<Vector3f> vertexList;
|
|
||||||
private Map<Integer, List<Integer>> vertexReferenceMap;
|
|
||||||
|
|
||||||
public VertexData(List<Vector3f> vertexList, Map<Integer, List<Integer>> vertexReferenceMap) {
|
|
||||||
this.vertexList = vertexList;
|
|
||||||
this.vertexReferenceMap = vertexReferenceMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Vector3f> getVertexList() {
|
|
||||||
return vertexList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Integer, List<Integer>> getVertexReferenceMap() {
|
|
||||||
return vertexReferenceMap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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.FileBlockHeader;
|
||||||
import com.jme3.scene.plugins.blender.file.Pointer;
|
import com.jme3.scene.plugins.blender.file.Pointer;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
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.blender.objects.ObjectHelper;
|
||||||
import com.jme3.scene.plugins.ogre.AnimData;
|
import com.jme3.scene.plugins.ogre.AnimData;
|
||||||
import com.jme3.util.BufferUtils;
|
import com.jme3.util.BufferUtils;
|
||||||
@ -198,11 +198,10 @@ import com.jme3.util.BufferUtils;
|
|||||||
Map<Integer, Integer> groupToBoneIndexMap = armatureHelper.getGroupToBoneIndexMap(defBase, blenderContext);
|
Map<Integer, Integer> groupToBoneIndexMap = armatureHelper.getGroupToBoneIndexMap(defBase, blenderContext);
|
||||||
|
|
||||||
int[] bonesGroups = new int[] { 0 };
|
int[] bonesGroups = new int[] { 0 };
|
||||||
|
MeshContext meshContext = blenderContext.getMeshContext(meshStructure.getOldMemoryAddress());
|
||||||
|
|
||||||
VertexData vertexData = blenderContext.getVertexData(meshStructure.getOldMemoryAddress());
|
VertexBuffer[] boneWeightsAndIndex = this.getBoneWeightAndIndexBuffer(meshStructure, meshContext.getVertexList().size(), bonesGroups,
|
||||||
|
meshContext.getVertexReferenceMap(), groupToBoneIndexMap, blenderContext);
|
||||||
VertexBuffer[] boneWeightsAndIndex = this.getBoneWeightAndIndexBuffer(meshStructure, vertexData.getVertexList().size(), bonesGroups,
|
|
||||||
vertexData.getVertexReferenceMap(), groupToBoneIndexMap, blenderContext);
|
|
||||||
this.verticesWeights = boneWeightsAndIndex[0];
|
this.verticesWeights = boneWeightsAndIndex[0];
|
||||||
this.verticesWeightsIndices = boneWeightsAndIndex[1];
|
this.verticesWeightsIndices = boneWeightsAndIndex[1];
|
||||||
this.boneGroups = bonesGroups[0];
|
this.boneGroups = bonesGroups[0];
|
||||||
|
@ -19,6 +19,7 @@ public abstract class Modifier {
|
|||||||
public static final String ARMATURE_MODIFIER_DATA = "ArmatureModifierData";
|
public static final String ARMATURE_MODIFIER_DATA = "ArmatureModifierData";
|
||||||
public static final String PARTICLE_MODIFIER_DATA = "ParticleSystemModifierData";
|
public static final String PARTICLE_MODIFIER_DATA = "ParticleSystemModifierData";
|
||||||
public static final String MIRROR_MODIFIER_DATA = "MirrorModifierData";
|
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";
|
public static final String OBJECT_ANIMATION_MODIFIER_DATA = "ObjectAnimationModifierData";
|
||||||
|
|
||||||
/** This variable indicates if the modifier is invalid (<b>true</b>) or not (<b>false</b>). */
|
/** This variable indicates if the modifier is invalid (<b>true</b>) or not (<b>false</b>). */
|
||||||
|
@ -94,8 +94,9 @@ public class UVCoordinatesGenerator {
|
|||||||
* an array that tells how UV-coordinates need to be swapped
|
* an array that tells how UV-coordinates need to be swapped
|
||||||
* @param geometries
|
* @param geometries
|
||||||
* a list of geometries the UV coordinates will be applied to
|
* 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<Geometry> geometries) {
|
public static VertexBuffer generateUVCoordinates(int texco, int projection, int textureDimension, int[] coordinatesSwappingIndexes, List<Geometry> geometries) {
|
||||||
if (textureDimension != 2 && textureDimension != 3) {
|
if (textureDimension != 2 && textureDimension != 3) {
|
||||||
throw new IllegalStateException("Unsupported texture dimension: " + textureDimension);
|
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.clearBuffer(VertexBuffer.Type.TexCoord);// in case there are coordinates already set
|
||||||
mesh.setBuffer(result);
|
mesh.setBuffer(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user