Blender Loader

* Enable mipmaps for packed and generated textures
 * Better handling of material flags for 2.58
 * Allow loading of meshes with no vertices instead of crashing

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8005 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 13 years ago
parent d87e69d97f
commit 17b949fea2
  1. 42
      engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialHelper.java
  2. 11
      engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java
  3. 8
      engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java
  4. 4
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureHelper.java

@ -190,32 +190,40 @@ public class MaterialHelper extends AbstractBlenderHelper {
int mode = ((Number) structure.getFieldValue("mode")).intValue();
boolean shadeless = (mode & 0x4) != 0;
boolean vertexColor = (mode & 0x16) != 0;
boolean transparent = (mode & 0x64) != 0;
boolean vertexColor = (mode & 0x80) != 0;
boolean transparent = (mode & 0x10000) != 0;
boolean vtangent = (mode & 0x4000000) != 0; // NOTE: Requires tangents
if (shadeless) {
result = new Material(dataRepository.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
} else {
result = new Material(dataRepository.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
}
//System.out.println("Mode: \n" +
// "Shadeless: " + shadeless + "\n" +
// "VColor: " + vertexColor + "\n" +
// "ZTrans: " + transparent + "\n" +
// "VTangent: " + vtangent);
result.getAdditionalRenderState().setFaceCullMode(faceCullMode);
if (transparent) {
result.setTransparent(true);
result.setTransparent(true);
result.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
}
}
String name = structure.getName();
LOGGER.log(Level.INFO, "Material's name: {0}", name);
if (vertexColor) {
result.setBoolean(shadeless ? "VertexColor" : "UseVertexColor", true);
}
MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class);
ColorRGBA diffuseColor = null;
if (shadeless) {
// color of shadeless? doesn't seem to work in blender ..
diffuseColor = ColorRGBA.White.clone();
} else {
result.setBoolean("UseMaterialColors", Boolean.TRUE);
@ -223,6 +231,9 @@ public class MaterialHelper extends AbstractBlenderHelper {
DiffuseShader diffuseShader = materialHelper.getDiffuseShader(structure);
result.setBoolean("Minnaert", diffuseShader == DiffuseShader.MINNAERT);
diffuseColor = materialHelper.getDiffuseColor(structure, diffuseShader);
if (!transparent){
diffuseColor.a = 1;
}
result.setColor("Diffuse", diffuseColor);
SpecularShader specularShader = materialHelper.getSpecularShader(structure);
@ -231,6 +242,8 @@ public class MaterialHelper extends AbstractBlenderHelper {
result.setColor("Ambient", materialHelper.getAmbientColor(structure));
result.setFloat("Shininess", materialHelper.getShininess(structure));
}
// texture
@ -262,40 +275,43 @@ public class MaterialHelper extends AbstractBlenderHelper {
if ((mapto & 0x01) != 0) {// Col
// Map to COLOR channel or DIFFUSE
// Set diffuse to white so it doesn't get multiplied by texture
result.setColor("Diffuse", ColorRGBA.White);
diffuseColor.r = diffuseColor.g = diffuseColor.b = 1.0f;
result.setColor(shadeless ? "Color" : "Diffuse", diffuseColor);
//result.setBoolean("UseMaterialColors", Boolean.FALSE);
// blending the texture with material color and texture's defined color
int blendType = ((Number) textureLink.getFieldValue("blendtype")).intValue();
float[] color = new float[] { ((Number) textureLink.getFieldValue("r")).floatValue(), ((Number) textureLink.getFieldValue("g")).floatValue(), ((Number) textureLink.getFieldValue("b")).floatValue() };
float colfac = ((Number) textureLink.getFieldValue("colfac")).floatValue();
texture = textureHelper.blendTexture(diffuseColor.getColorArray(), texture, color, colfac, blendType, negateTexture, dataRepository);
texture.setWrap(WrapMode.Repeat);
texture.setMinFilter(MinFilter.Trilinear);
texture.setWrap(WrapMode.Repeat);
if (shadeless) {
result.setTexture(TEXTURE_TYPE_COLOR, texture);
} else {
result.setTexture(TEXTURE_TYPE_DIFFUSE, texture);
}
}
if ((mapto & 0x02) != 0) {// Nor
if ((mapto & 0x02) != 0 && !shadeless) {// Nor
Texture normalMapTexture;
if(texture.getKey() instanceof GeneratedTextureKey) {
normalMapTexture = textureHelper.convertToNormalMapTexture(texture, ((Number)textureLink.getFieldValue("norfac")).floatValue());
} else {
normalMapTexture.setMinFilter(MinFilter.Trilinear);
} else {
normalMapTexture = texture;
}
result.setTexture(TEXTURE_TYPE_NORMAL, normalMapTexture);
result.setTexture(TEXTURE_TYPE_NORMAL, normalMapTexture);
if (vertexColor) {
result.setBoolean(shadeless ? "VertexColor" : "UseVertexColor", false);
}
}
if ((mapto & 0x04) != 0) {// Spec
if ((mapto & 0x04) != 0 && !shadeless) {// Spec
// Map to SPECULAR
result.setTexture(TEXTURE_TYPE_SPECULAR, texture);
}
if ((mapto & 0x40) != 0) {// Emit
result.setTexture(TEXTURE_TYPE_GLOW, texture);
}
if ((mapto & 0x80) != 0) {// Alpha
if ((mapto & 0x80) != 0 && !shadeless) {// Alpha
result.setTexture(TEXTURE_TYPE_ALPHA, texture);
}
} else {

@ -127,7 +127,10 @@ public class MeshHelper extends AbstractBlenderHelper {
// the following map sorts faces by material number (because in jme Mesh can have only one material)
Map<Integer, List<Integer>> meshesMap = new HashMap<Integer, List<Integer>>();
Pointer pMFace = (Pointer) structure.getFieldValue("mface");
List<Structure> mFaces = pMFace.fetchData(dataRepository.getInputStream());
List<Structure> mFaces = null;
if (pMFace.isNotNull()){
mFaces = pMFace.fetchData(dataRepository.getInputStream());
}
Pointer pMTFace = (Pointer) structure.getFieldValue("mtface");
List<Vector2f> uvCoordinates = null;
@ -153,6 +156,9 @@ public class MeshHelper extends AbstractBlenderHelper {
// positions (it simply tells which vertex is referenced where in the result list)
Map<Integer, List<Integer>> vertexReferenceMap = new HashMap<Integer, List<Integer>>(verticesAmount);
int vertexColorIndex = 0;
if (mFaces == null){
return null;
}
for (int i = 0; i < mFaces.size(); ++i) {
Structure mFace = mFaces.get(i);
boolean smooth = (((Number) mFace.getFieldValue("flag")).byteValue() & 0x01) != 0x00;
@ -544,6 +550,9 @@ public class MeshHelper extends AbstractBlenderHelper {
public Vector3f[] getVertices(Structure meshStructure, DataRepository dataRepository) throws BlenderFileException {
int verticesAmount = ((Number) meshStructure.getFieldValue("totvert")).intValue();
Vector3f[] vertices = new Vector3f[verticesAmount];
if (verticesAmount == 0)
return vertices;
Pointer pMVert = (Pointer) meshStructure.getFieldValue("mvert");
List<Structure> mVerts = pMVert.fetchData(dataRepository.getInputStream());
for (int i = 0; i < verticesAmount; ++i) {

@ -184,9 +184,11 @@ public class ObjectHelper extends AbstractBlenderHelper {
Pointer pMesh = (Pointer)objectStructure.getFieldValue("data");
List<Structure> meshesArray = pMesh.fetchData(dataRepository.getInputStream());
List<Geometry> geometries = meshHelper.toMesh(meshesArray.get(0), dataRepository);
for(Geometry geometry : geometries) {
node.attachChild(geometry);
}
if (geometries != null){
for(Geometry geometry : geometries) {
node.attachChild(geometry);
}
}
node.setLocalTransform(t);
//reading and applying all modifiers

@ -935,12 +935,12 @@ public class TextureHelper extends AbstractBlenderHelper {
name = name.substring(1);
}
TextureKey texKey = new TextureKey(name, false);
TextureKey texKey = new TextureKey(name, true);
try {
Texture tex = dataRepository.getAssetManager().loadTexture(texKey);
image = tex.getImage();
} catch (AssetNotFoundException e) {
LOGGER.warning("Asset not found: " + e.getLocalizedMessage());
LOGGER.log(Level.WARNING, "Asset not found: {0}", e.getLocalizedMessage());
}
}

Loading…
Cancel
Save