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