protected void startMaterial(String name){ if (matName != null){ // material is already in cache, generate it createMaterial(); } // now, reset the params and set the name to start a new material resetMaterial(); matName = name; }
for (FbxCluster cluster : skinDeformer.getJmeObject()) { applyCluster(cluster); IrMesh irMesh = toIRMesh(); IrUtils.trimBoneWeights(irMesh); IrUtils.toTangentsWithParity(irMesh); IrUtils.triangulate(irMesh); IntMap<IrMesh> irMeshes = IrUtils.splitByMaterial(irMesh); Mesh jmeMesh = IrUtils.convertIrMeshToJmeMesh(irMeshEntry.getValue()); jmeMeshes.put(irMeshEntry.getKey(), jmeMesh);
if (cmd.startsWith("#")){ return nextStatement(); }else if (cmd.equals("v")){ verts.add(readVector3()); }else if (cmd.equals("vn")){ norms.add(readVector3()); }else if (cmd.equals("vt")){ texCoords.add(readVector2()); }else if (cmd.equals("f")){ readFace(); }else if (cmd.equals("usemtl")){ loadMtlLib(mtllib); }else if (cmd.equals("s") || cmd.equals("g")){ return nextStatement(); }else{ return nextStatement();
return skipLine(); }else if (cmd.equals("newmtl")){ String name = scan.next(); startMaterial(name); }else if (cmd.equals("ka")){ ambient.set(readColor()); }else if (cmd.equals("kd")){ diffuse.set(readColor()); }else if (cmd.equals("ks")){ specular.set(readColor()); }else if (cmd.equals("ns")){ float shiny = scan.nextFloat(); return skipLine(); }else if (cmd.equals("map_kd")){ String path = nextStatement(); diffuseMap = loadTexture(path); }else if (cmd.equals("map_bump") || cmd.equals("bump")){ if (normalMap == null){ String path = nextStatement(); normalMap = loadTexture(path); String path = nextStatement(); specularMap = loadTexture(path); if (specularMap != null){ alphaMap = loadTexture(path); transparent = true; }else if (cmd.equals("illum")){
@SuppressWarnings("empty-statement") public Object load(AssetInfo info) throws IOException{ reset(); scan.useLocale(Locale.US); while (readLine()); } finally { if (in != null){ createMaterial(); resetMaterial();
IrMesh newMesh = new IrMesh(); newMesh.polygons = new IrPolygon[polygons.length]; IrPolygon irPolygon = new IrPolygon(); irPolygon.vertices = new IrVertex[polygon.indices.length]; positionIndex = polygon.indices[j]; IrVertex irVertex = new IrVertex(); irVertex.pos = positions[positionIndex]; irVertex.norm = (Vector3f) layer0.getVertexData(FbxLayerElement.Type.Normal, i, polygonVertexIndex, positionIndex, 0); irVertex.tang = (Vector3f) layer0.getVertexData(FbxLayerElement.Type.Tangent, i, polygonVertexIndex, positionIndex, 0); irVertex.bitang = (Vector3f) layer0.getVertexData(FbxLayerElement.Type.Binormal, i, polygonVertexIndex, positionIndex, 0); irVertex.uv0 = (Vector2f) layer0.getVertexData(FbxLayerElement.Type.UV, i, polygonVertexIndex, positionIndex, 0); irVertex.color = (ColorRGBA) layer0.getVertexData(FbxLayerElement.Type.Color, i, polygonVertexIndex, positionIndex, 0); irVertex.material = (Integer) layer0.getVertexData(FbxLayerElement.Type.Material, i, polygonVertexIndex, positionIndex, 0); irVertex.smoothing = (Integer) layer0.getVertexData(FbxLayerElement.Type.Smoothing, i, polygonVertexIndex, positionIndex, 0); irVertex.uv1 = (Vector2f) layer1.getVertexData(FbxLayerElement.Type.UV, i, polygonVertexIndex, positionIndex, 0); ArrayList<Float> boneWeightsForVertex = boneWeights[positionIndex]; if (boneIndicesForVertex != null) { irVertex.boneWeightsIndices = toBoneWeightIndices(boneIndicesForVertex, boneWeightsForVertex);
public IrVertex deepClone() { IrVertex v = new IrVertex(); v.pos = pos != null ? pos.clone() : null; v.norm = norm != null ? norm.clone() : null; v.tang4d = tang4d != null ? tang4d.clone() : null; v.tang = tang != null ? tang.clone() : null; v.bitang = bitang != null ? bitang.clone() : null; v.uv0 = uv0 != null ? uv0.clone() : null; v.uv1 = uv1 != null ? uv1.clone() : null; v.color = color != null ? color.clone() : null; v.material = material; v.smoothing = smoothing; if (boneWeightsIndices != null) { v.boneWeightsIndices = new IrBoneWeightIndex[boneWeightsIndices.length]; for (int i = 0; i < boneWeightsIndices.length; i++) { v.boneWeightsIndices[i] = (IrBoneWeightIndex) boneWeightsIndices[i].clone(); } } return v; }
public void reset(){ scan = null; matList = null; // material = null; resetMaterial(); }
Mesh mesh = constructMesh(faceList);
private static IrBoneWeightIndex[] toBoneWeightIndices(List<Integer> boneIndices, List<Float> boneWeights) { IrBoneWeightIndex[] boneWeightIndices = new IrBoneWeightIndex[boneIndices.size()]; for (int i = 0; i < boneIndices.size(); i++) { boneWeightIndices[i] = new IrBoneWeightIndex(boneIndices.get(i), boneWeights.get(i)); } return boneWeightIndices; }
public static void toTangentsWithParity(IrMesh mesh) { for (IrPolygon polygon : mesh.polygons) { for (IrVertex vertex : polygon.vertices) { toTangentsWithParity(vertex); } } }
/** * Removes low bone weights from mesh, leaving only 4 bone weights at max. */ public static void trimBoneWeights(IrMesh mesh) { for (IrPolygon polygon : mesh.polygons) { for (IrVertex vertex : polygon.vertices) { trimBoneWeights(vertex); } } }
/** * Convert mesh from quads / triangles to triangles only. */ public static void triangulate(IrMesh mesh) { List<IrPolygon> newPolygons = new ArrayList<IrPolygon>(mesh.polygons.length); for (IrPolygon inputPoly : mesh.polygons) { if (inputPoly.vertices.length == 4) { IrPolygon[] tris = quadToTri(inputPoly); newPolygons.add(tris[0]); newPolygons.add(tris[1]); } else if (inputPoly.vertices.length == 3) { newPolygons.add(inputPoly); } else { // N-gon. We have to ignore it.. logger.log(Level.WARNING, "N-gon encountered, ignoring. " + "The mesh may not appear correctly. " + "Triangulate your model prior to export."); } } mesh.polygons = new IrPolygon[newPolygons.size()]; newPolygons.toArray(mesh.polygons); }
List<IrPolygon> polygons = entry.getValue(); if (polygons.size() > 0) { IrMesh newMesh = new IrMesh(); newMesh.polygons = new IrPolygon[polygons.size()]; polygons.toArray(newMesh.polygons);
for (int i = 0; i < boneWeightsIndices.length; i++) { IrBoneWeightIndex original = boneWeightsIndices[i]; boneWeightsIndices[i] = new IrBoneWeightIndex(original.boneIndex, original.boneWeight * sumToB);