Blender Loader : implemented fixUpAxis for meshes

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8265 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent c011a29529
commit bf70599185
  1. 27
      engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java

@ -72,6 +72,7 @@ import com.jme3.util.BufferUtils;
* @author Marcin Roguski (Kaelthas) * @author Marcin Roguski (Kaelthas)
*/ */
public class MeshHelper extends AbstractBlenderHelper { public class MeshHelper extends AbstractBlenderHelper {
/** /**
* This constructor parses the given blender version and stores the result. Some functionalities may differ in different blender * This constructor parses the given blender version and stores the result. Some functionalities may differ in different blender
* versions. * versions.
@ -122,9 +123,9 @@ public class MeshHelper extends AbstractBlenderHelper {
Map<Integer, List<Integer>> meshesMap = new HashMap<Integer, List<Integer>>(); Map<Integer, List<Integer>> meshesMap = new HashMap<Integer, List<Integer>>();
Pointer pMFace = (Pointer) structure.getFieldValue("mface"); Pointer pMFace = (Pointer) structure.getFieldValue("mface");
List<Structure> mFaces = null; List<Structure> mFaces = null;
if (pMFace.isNotNull()){ if (pMFace.isNotNull()) {
mFaces = pMFace.fetchData(blenderContext.getInputStream()); mFaces = pMFace.fetchData(blenderContext.getInputStream());
if(mFaces==null || mFaces.size()==0) { if (mFaces == null || mFaces.size() == 0) {
return new ArrayList<Geometry>(0); return new ArrayList<Geometry>(0);
} }
} }
@ -353,13 +354,13 @@ public class MeshHelper extends AbstractBlenderHelper {
material = nonTexturedMaterials[materialNumber]; material = nonTexturedMaterials[materialNumber];
} }
geometry.setMaterial(material); geometry.setMaterial(material);
if (material.isTransparent()){ if (material.isTransparent()) {
geometry.setQueueBucket(Bucket.Transparent); geometry.setQueueBucket(Bucket.Transparent);
} }
} else { } else {
geometry.setMaterial(blenderContext.getDefaultMaterial()); geometry.setMaterial(blenderContext.getDefaultMaterial());
} }
if(properties != null && properties.getValue() != null) { if (properties != null && properties.getValue() != null) {
geometry.setUserData("properties", properties); geometry.setUserData("properties", properties);
} }
geometries.add(geometry); geometries.add(geometry);
@ -367,29 +368,29 @@ public class MeshHelper extends AbstractBlenderHelper {
//applying uvCoordinates for all the meshes //applying uvCoordinates for all the meshes
if (uvCoordsBuffer != null) { if (uvCoordsBuffer != null) {
for(Geometry geom : geometries) { for (Geometry geom : geometries) {
geom.getMesh().setBuffer(uvCoordsBuffer); geom.getMesh().setBuffer(uvCoordsBuffer);
} }
} else { } else {
Map<Material, List<Geometry>> materialMap = new HashMap<Material, List<Geometry>>(); Map<Material, List<Geometry>> materialMap = new HashMap<Material, List<Geometry>>();
for(Geometry geom : geometries) { for (Geometry geom : geometries) {
Material material = geom.getMaterial(); Material material = geom.getMaterial();
List<Geometry> geomsWithCommonMaterial = materialMap.get(material); List<Geometry> geomsWithCommonMaterial = materialMap.get(material);
if(geomsWithCommonMaterial==null) { if (geomsWithCommonMaterial == null) {
geomsWithCommonMaterial = new ArrayList<Geometry>(); geomsWithCommonMaterial = new ArrayList<Geometry>();
materialMap.put(material, geomsWithCommonMaterial); materialMap.put(material, geomsWithCommonMaterial);
} }
geomsWithCommonMaterial.add(geom); geomsWithCommonMaterial.add(geom);
} }
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) {
VertexBuffer coords = 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 //setting the coordinates inside the mesh context
for(Geometry geometry : entry.getValue()) { for (Geometry geometry : entry.getValue()) {
meshContext.addUVCoordinates(geometry, coords); meshContext.addUVCoordinates(geometry, coords);
} }
} }
@ -468,7 +469,7 @@ public class MeshHelper extends AbstractBlenderHelper {
float g = ((Number) color.getFieldValue("g")).byteValue() / 256.0f; float g = ((Number) color.getFieldValue("g")).byteValue() / 256.0f;
float b = ((Number) color.getFieldValue("b")).byteValue() / 256.0f; float b = ((Number) color.getFieldValue("b")).byteValue() / 256.0f;
float a = ((Number) color.getFieldValue("a")).byteValue() / 256.0f; float a = ((Number) color.getFieldValue("a")).byteValue() / 256.0f;
verticesColors.add(new float[] { b, g, r, a }); verticesColors.add(new float[]{b, g, r, a});
} }
} }
return verticesColors; return verticesColors;
@ -497,8 +498,12 @@ public class MeshHelper extends AbstractBlenderHelper {
List<Structure> mVerts = pMVert.fetchData(blenderContext.getInputStream()); List<Structure> mVerts = pMVert.fetchData(blenderContext.getInputStream());
for (int i = 0; i < verticesAmount; ++i) { for (int i = 0; i < verticesAmount; ++i) {
DynamicArray<Number> coordinates = (DynamicArray<Number>) mVerts.get(i).getFieldValue("co"); DynamicArray<Number> coordinates = (DynamicArray<Number>) mVerts.get(i).getFieldValue("co");
if (blenderContext.getBlenderKey().isFixUpAxis()) {
vertices[i] = new Vector3f(coordinates.get(0).floatValue(), coordinates.get(2).floatValue(), -coordinates.get(1).floatValue());
} else {
vertices[i] = new Vector3f(coordinates.get(0).floatValue(), coordinates.get(1).floatValue(), coordinates.get(2).floatValue()); vertices[i] = new Vector3f(coordinates.get(0).floatValue(), coordinates.get(1).floatValue(), coordinates.get(2).floatValue());
} }
}
return vertices; return vertices;
} }

Loading…
Cancel
Save