dcdcdc
This commit is contained in:
parent
1679d62300
commit
8ba3c34262
@ -1,90 +1,6 @@
|
|||||||
package org.atriasoft.loader3d;
|
package org.atriasoft.loader3d;
|
||||||
|
|
||||||
public class Face {
|
public class Face {
|
||||||
public byte nbElement;
|
|
||||||
public final int[] vertex = new int[3];
|
|
||||||
public final int[] uv = new int[3];
|
|
||||||
public final int[] normal = new int[3];
|
|
||||||
public final int[] color = new int[3];
|
|
||||||
public Face() {
|
|
||||||
this.nbElement = 1;
|
|
||||||
this.vertex[0] = -1;
|
|
||||||
this.vertex[1] = -1;
|
|
||||||
this.vertex[2] = -1;
|
|
||||||
this.uv[0] = -1;
|
|
||||||
this.uv[1] = -1;
|
|
||||||
this.uv[2] = -1;
|
|
||||||
this.normal[0] = -1;
|
|
||||||
this.normal[1] = -1;
|
|
||||||
this.normal[2] = -1;
|
|
||||||
this.color[0] = -1;
|
|
||||||
this.color[1] = -1;
|
|
||||||
this.color[2] = -1;
|
|
||||||
}
|
|
||||||
public Face(int _v1, int _t1,
|
|
||||||
int _v2, int _t2,
|
|
||||||
int _v3, int _t3) {
|
|
||||||
this.nbElement = 3;
|
|
||||||
this.vertex[0] = _v1;
|
|
||||||
this.vertex[1] = _v2;
|
|
||||||
this.vertex[2] = _v3;
|
|
||||||
this.uv[0] = _t1;
|
|
||||||
this.uv[1] = _t2;
|
|
||||||
this.uv[2] = _t3;
|
|
||||||
this.normal[0] = -1;
|
|
||||||
this.normal[1] = -1;
|
|
||||||
this.normal[2] = -1;
|
|
||||||
this.color[0] = -1;
|
|
||||||
this.color[1] = -1;
|
|
||||||
this.color[2] = -1;
|
|
||||||
}
|
|
||||||
public Face(int _v1, int _t1, int _n1,
|
|
||||||
int _v2, int _t2, int _n2,
|
|
||||||
int _v3, int _t3, int _n3) {
|
|
||||||
this.nbElement = 3;
|
|
||||||
this.vertex[0] = _v1;
|
|
||||||
this.vertex[1] = _v2;
|
|
||||||
this.vertex[2] = _v3;
|
|
||||||
this.uv[0] = _t1;
|
|
||||||
this.uv[1] = _t2;
|
|
||||||
this.uv[2] = _t3;
|
|
||||||
this.normal[0] = _n1;
|
|
||||||
this.normal[1] = _n2;
|
|
||||||
this.normal[2] = _n3;
|
|
||||||
this.color[0] = -1;
|
|
||||||
this.color[1] = -1;
|
|
||||||
this.color[2] = -1;
|
|
||||||
}
|
|
||||||
public void setVertex(int _v1) {
|
|
||||||
this.nbElement = 1;
|
|
||||||
this.vertex[0] = _v1;
|
|
||||||
}
|
|
||||||
public void setVertex(int _v1, int _v2) {
|
|
||||||
this.nbElement = 2;
|
|
||||||
this.vertex[0] = _v1;
|
|
||||||
this.vertex[1] = _v2;
|
|
||||||
}
|
|
||||||
public void setVertex(int _v1, int _v2, int _v3) {
|
|
||||||
this.nbElement = 3;
|
|
||||||
this.vertex[0] = _v1;
|
|
||||||
this.vertex[1] = _v2;
|
|
||||||
this.vertex[2] = _v3;
|
|
||||||
}
|
|
||||||
public void setTexture(int _t1, int _t2, int _t3) {
|
|
||||||
this.uv[0] = _t1;
|
|
||||||
this.uv[1] = _t2;
|
|
||||||
this.uv[2] = _t3;
|
|
||||||
}
|
|
||||||
public void setNormal(int _n1, int _n2, int _n3) {
|
|
||||||
this.normal[0] = _n1;
|
|
||||||
this.normal[1] = _n2;
|
|
||||||
this.normal[2] = _n3;
|
|
||||||
}
|
|
||||||
public void setColor(int _c1, int _c2, int _c3) {
|
|
||||||
this.color[0] = _c1;
|
|
||||||
this.color[1] = _c2;
|
|
||||||
this.color[2] = _c3;
|
|
||||||
}
|
|
||||||
public static Face valueOf(String data, int offsetVertex, int offsetUV, int offsetNormal) {
|
public static Face valueOf(String data, int offsetVertex, int offsetUV, int offsetNormal) {
|
||||||
while (data.length() >= 1 && data.charAt(0) == ' ') {
|
while (data.length() >= 1 && data.charAt(0) == ' ') {
|
||||||
data = data.substring(1);
|
data = data.substring(1);
|
||||||
@ -114,4 +30,100 @@ public class Face {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte nbElement;
|
||||||
|
public final int[] vertex = new int[3];
|
||||||
|
public final int[] uv = new int[3];
|
||||||
|
public final int[] normal = new int[3];
|
||||||
|
public final int[] color = new int[3];
|
||||||
|
|
||||||
|
public Face() {
|
||||||
|
this.nbElement = 1;
|
||||||
|
this.vertex[0] = -1;
|
||||||
|
this.vertex[1] = -1;
|
||||||
|
this.vertex[2] = -1;
|
||||||
|
this.uv[0] = -1;
|
||||||
|
this.uv[1] = -1;
|
||||||
|
this.uv[2] = -1;
|
||||||
|
this.normal[0] = -1;
|
||||||
|
this.normal[1] = -1;
|
||||||
|
this.normal[2] = -1;
|
||||||
|
this.color[0] = -1;
|
||||||
|
this.color[1] = -1;
|
||||||
|
this.color[2] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Face(int _v1, int _t1, int _v2, int _t2, int _v3, int _t3) {
|
||||||
|
this.nbElement = 3;
|
||||||
|
this.vertex[0] = _v1;
|
||||||
|
this.vertex[1] = _v2;
|
||||||
|
this.vertex[2] = _v3;
|
||||||
|
this.uv[0] = _t1;
|
||||||
|
this.uv[1] = _t2;
|
||||||
|
this.uv[2] = _t3;
|
||||||
|
this.normal[0] = -1;
|
||||||
|
this.normal[1] = -1;
|
||||||
|
this.normal[2] = -1;
|
||||||
|
this.color[0] = -1;
|
||||||
|
this.color[1] = -1;
|
||||||
|
this.color[2] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Face(int _v1, int _t1, int _n1, int _v2, int _t2, int _n2, int _v3, int _t3, int _n3) {
|
||||||
|
this.nbElement = 3;
|
||||||
|
this.vertex[0] = _v1;
|
||||||
|
this.vertex[1] = _v2;
|
||||||
|
this.vertex[2] = _v3;
|
||||||
|
this.uv[0] = _t1;
|
||||||
|
this.uv[1] = _t2;
|
||||||
|
this.uv[2] = _t3;
|
||||||
|
this.normal[0] = _n1;
|
||||||
|
this.normal[1] = _n2;
|
||||||
|
this.normal[2] = _n3;
|
||||||
|
this.color[0] = -1;
|
||||||
|
this.color[1] = -1;
|
||||||
|
this.color[2] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(int _c1, int _c2, int _c3) {
|
||||||
|
this.color[0] = _c1;
|
||||||
|
this.color[1] = _c2;
|
||||||
|
this.color[2] = _c3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNormal(int _n) {
|
||||||
|
this.normal[0] = _n;
|
||||||
|
this.normal[1] = _n;
|
||||||
|
this.normal[2] = _n;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNormal(int _n1, int _n2, int _n3) {
|
||||||
|
this.normal[0] = _n1;
|
||||||
|
this.normal[1] = _n2;
|
||||||
|
this.normal[2] = _n3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTexture(int _t1, int _t2, int _t3) {
|
||||||
|
this.uv[0] = _t1;
|
||||||
|
this.uv[1] = _t2;
|
||||||
|
this.uv[2] = _t3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVertex(int _v1) {
|
||||||
|
this.nbElement = 1;
|
||||||
|
this.vertex[0] = _v1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVertex(int _v1, int _v2) {
|
||||||
|
this.nbElement = 2;
|
||||||
|
this.vertex[0] = _v1;
|
||||||
|
this.vertex[1] = _v2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVertex(int _v1, int _v2, int _v3) {
|
||||||
|
this.nbElement = 3;
|
||||||
|
this.vertex[0] = _v1;
|
||||||
|
this.vertex[1] = _v2;
|
||||||
|
this.vertex[2] = _v3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,8 @@ import java.io.BufferedReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.atriasoft.etk.Uri;
|
import org.atriasoft.etk.Uri;
|
||||||
import org.atriasoft.etk.math.Vector2f;
|
import org.atriasoft.etk.math.Vector2f;
|
||||||
@ -20,47 +22,56 @@ import org.atriasoft.loader3d.model.PhysicShape;
|
|||||||
|
|
||||||
public class ResourceMeshEmf extends ResourceMesh {
|
public class ResourceMeshEmf extends ResourceMesh {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum emfModuleMode {
|
enum emfModuleMode {
|
||||||
EMFModuleNone(0),
|
EMFModuleSkip(-1), //!< skip the current module ==> filtered...
|
||||||
EMFModuleMesh(1),
|
EMFModuleNone(0), //!< Nothing in parsing
|
||||||
EMFModuleMeshVertex(2),
|
EMFModuleMesh(1), //!<
|
||||||
EMFModuleMeshUVMapping(3),
|
EMFModuleMeshVertex(2), //!<
|
||||||
EMFModuleMeshNormalVertex(4),
|
EMFModuleMeshUVMapping(3), //!<
|
||||||
EMFModuleMeshNormalFace(5),
|
EMFModuleMeshNormalVertex(4), //!<
|
||||||
EMFModuleMeshFace(6),
|
EMFModuleMeshNormalFace(5), //!<
|
||||||
EMFModuleMeshFaceMaterial(7),
|
EMFModuleMeshFace(6), //!<
|
||||||
EMFModuleMeshPhysics(8),
|
EMFModuleMeshFaceMaterial(7), //!<
|
||||||
EMFModuleMeshPhysicsNamed(9),
|
EMFModuleMeshPhysics(8), //!<
|
||||||
EMFModuleMesh_END(100),
|
EMFModuleMeshPhysicsNamed(9), //!<
|
||||||
EMFModuleMaterial(101),
|
EMFModuleMesh_END(100), //!<
|
||||||
EMFModuleMaterial_END(200),
|
EMFModuleMaterial(101), //!<
|
||||||
EMFModulePalette(201),
|
EMFModuleMaterial_END(200), //!<
|
||||||
EMFModulePalette_END(300),
|
EMFModulePalette(201), //!<
|
||||||
EMFModulePhysics(301),
|
EMFModulePalette_END(300), //!<
|
||||||
EMFModulePhysicsNamed(302),
|
EMFModulePhysics(301), //!<
|
||||||
EMFModulePhysics_END(400);
|
EMFModulePhysicsNamed(302), //!<
|
||||||
|
EMFModulePhysics_END(400); //!<
|
||||||
|
|
||||||
private final int value;
|
private final int value;
|
||||||
|
|
||||||
emfModuleMode(int value) {
|
emfModuleMode(int value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getValue() {
|
int getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO : rework with string line extractor
|
// TODO : rework with string line extractor
|
||||||
public ResourceMeshEmf(Uri _fileName) {
|
/**
|
||||||
super(_fileName);
|
* Create a mesh from Ewol Mesh File.
|
||||||
mode = RenderMode.TRIANGLE;
|
* @param fileName generic URI if parameter filter is set the mesh is partially loaded applying the filter
|
||||||
|
* @throws Exception pb in parsing the file maybe no vertices inside...
|
||||||
|
*/
|
||||||
|
public ResourceMeshEmf(Uri fileName) throws Exception {
|
||||||
|
super(fileName);
|
||||||
|
Pattern filterPattern = null;
|
||||||
|
if (fileName.hasProperty("filter")) {
|
||||||
|
filterPattern = Pattern.compile(fileName.getProperty("filter"));
|
||||||
|
}
|
||||||
|
this.mode = RenderMode.TRIANGLE;
|
||||||
this.checkNormal = true;
|
this.checkNormal = true;
|
||||||
this.normalMode = NormalMode.NONE;
|
this.normalMode = NormalMode.NONE;
|
||||||
InputStream fileIOStream = Uri.getStream(_fileName);
|
InputStream fileIOStream = Uri.getStream(fileName);
|
||||||
if (fileIOStream == null) {
|
if (fileIOStream == null) {
|
||||||
Log.error("CAn not get the file named='" + _fileName + "'");
|
Log.error("CAn not get the file named='" + fileName + "'");
|
||||||
return; // TODO false;
|
return; // TODO false;
|
||||||
}
|
}
|
||||||
BufferedReader fileIO = new BufferedReader(new InputStreamReader(fileIOStream));
|
BufferedReader fileIO = new BufferedReader(new InputStreamReader(fileIOStream));
|
||||||
@ -69,7 +80,7 @@ public ResourceMeshEmf(Uri _fileName) {
|
|||||||
//int size = fileIO.size();
|
//int size = fileIO.size();
|
||||||
|
|
||||||
String inputDataLine;
|
String inputDataLine;
|
||||||
Dynamic<Integer> levelIO = new Dynamic<Integer>(0);
|
Dynamic<Integer> levelIO = new Dynamic<>(0);
|
||||||
// load the first line :
|
// load the first line :
|
||||||
inputDataLine = readLine(fileIO, levelIO);
|
inputDataLine = readLine(fileIO, levelIO);
|
||||||
if (inputDataLine.startsWith("EMF(STRING)") == true) {
|
if (inputDataLine.startsWith("EMF(STRING)") == true) {
|
||||||
@ -82,7 +93,7 @@ public ResourceMeshEmf(Uri _fileName) {
|
|||||||
return; // TODO false;
|
return; // TODO false;
|
||||||
}
|
}
|
||||||
emfModuleMode currentMode = emfModuleMode.EMFModuleNone;
|
emfModuleMode currentMode = emfModuleMode.EMFModuleNone;
|
||||||
Log.verbose("Start parsing Mesh file : " + _fileName);
|
Log.verbose("Start parsing Mesh file : " + fileName);
|
||||||
// mesh global param :
|
// mesh global param :
|
||||||
String currentMeshName = "";
|
String currentMeshName = "";
|
||||||
FaceIndexing currentFaceIndexing = null;
|
FaceIndexing currentFaceIndexing = null;
|
||||||
@ -108,7 +119,17 @@ public ResourceMeshEmf(Uri _fileName) {
|
|||||||
if (inputDataLine.startsWith("Mesh:") == true) {
|
if (inputDataLine.startsWith("Mesh:") == true) {
|
||||||
currentMode = emfModuleMode.EMFModuleMesh;
|
currentMode = emfModuleMode.EMFModuleMesh;
|
||||||
currentMeshName = inputDataLine.substring(5);
|
currentMeshName = inputDataLine.substring(5);
|
||||||
|
if (filterPattern != null) {
|
||||||
|
Matcher m = filterPattern.matcher(currentMeshName);
|
||||||
|
if (!m.matches()) {
|
||||||
|
currentMode = emfModuleMode.EMFModuleSkip;
|
||||||
|
Log.verbose("Parse Mesh(SKIP): " + currentMeshName);
|
||||||
|
} else {
|
||||||
Log.verbose("Parse Mesh: " + currentMeshName);
|
Log.verbose("Parse Mesh: " + currentMeshName);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.verbose("Parse Mesh: " + currentMeshName);
|
||||||
|
}
|
||||||
offsetVertexId = this.listVertex.size();
|
offsetVertexId = this.listVertex.size();
|
||||||
offsetUV = this.listUV.size();
|
offsetUV = this.listUV.size();
|
||||||
offsetFaceNormal = this.listFacesNormal.size();
|
offsetFaceNormal = this.listFacesNormal.size();
|
||||||
@ -116,8 +137,7 @@ public ResourceMeshEmf(Uri _fileName) {
|
|||||||
//Log.error("new offset: " + offsetVertexId + " " + offsetUV + " " + offsetFaceNormal + " " + offsetVertexNormal);
|
//Log.error("new offset: " + offsetVertexId + " " + offsetUV + " " + offsetFaceNormal + " " + offsetVertexNormal);
|
||||||
} else if (inputDataLine.startsWith("Materials:")) {
|
} else if (inputDataLine.startsWith("Materials:")) {
|
||||||
// add previous material:
|
// add previous material:
|
||||||
if( materialName != ""
|
if (materialName != "" && material != null) {
|
||||||
&& material != null) {
|
|
||||||
if (currentMode == emfModuleMode.EMFModulePalette) {
|
if (currentMode == emfModuleMode.EMFModulePalette) {
|
||||||
this.palettes.put(materialName, material);
|
this.palettes.put(materialName, material);
|
||||||
// TODO Remove this later ...
|
// TODO Remove this later ...
|
||||||
@ -134,8 +154,7 @@ public ResourceMeshEmf(Uri _fileName) {
|
|||||||
Log.verbose("Parse Material: " + materialName);
|
Log.verbose("Parse Material: " + materialName);
|
||||||
} else if (inputDataLine.startsWith("Palettes:")) {
|
} else if (inputDataLine.startsWith("Palettes:")) {
|
||||||
// add previous material:
|
// add previous material:
|
||||||
if( materialName != ""
|
if (materialName != "" && material != null) {
|
||||||
&& material != null) {
|
|
||||||
if (currentMode == emfModuleMode.EMFModulePalette) {
|
if (currentMode == emfModuleMode.EMFModulePalette) {
|
||||||
this.palettes.put(materialName, material);
|
this.palettes.put(materialName, material);
|
||||||
// TODO Remove this later ...
|
// TODO Remove this later ...
|
||||||
@ -156,9 +175,13 @@ public ResourceMeshEmf(Uri _fileName) {
|
|||||||
} else {
|
} else {
|
||||||
currentMode = emfModuleMode.EMFModuleNone;
|
currentMode = emfModuleMode.EMFModuleNone;
|
||||||
}
|
}
|
||||||
} else {
|
continue;
|
||||||
if ( currentMode.getValue() >= emfModuleMode.EMFModuleMesh.getValue()
|
}
|
||||||
&& currentMode.getValue() <= emfModuleMode.EMFModuleMesh_END.getValue()) {
|
if (currentMode == emfModuleMode.EMFModuleSkip) {
|
||||||
|
// skip the content...
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (currentMode.getValue() >= emfModuleMode.EMFModuleMesh.getValue() && currentMode.getValue() <= emfModuleMode.EMFModuleMesh_END.getValue()) {
|
||||||
if (level == 1) {
|
if (level == 1) {
|
||||||
if (inputDataLine.startsWith("Vertex:") == true) {
|
if (inputDataLine.startsWith("Vertex:") == true) {
|
||||||
currentMode = emfModuleMode.EMFModuleMeshVertex;
|
currentMode = emfModuleMode.EMFModuleMeshVertex;
|
||||||
@ -292,10 +315,9 @@ public ResourceMeshEmf(Uri _fileName) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else if ( ( currentMode.getValue() >= emfModuleMode.EMFModuleMaterial.getValue()
|
}
|
||||||
&& currentMode.getValue() <= emfModuleMode.EMFModuleMaterial_END.getValue())
|
if ((currentMode.getValue() >= emfModuleMode.EMFModuleMaterial.getValue() && currentMode.getValue() <= emfModuleMode.EMFModuleMaterial_END.getValue())
|
||||||
|| ( currentMode.getValue() >= emfModuleMode.EMFModulePalette.getValue()
|
|| (currentMode.getValue() >= emfModuleMode.EMFModulePalette.getValue() && currentMode.getValue() <= emfModuleMode.EMFModulePalette_END.getValue())) {
|
||||||
&& currentMode.getValue() <= emfModuleMode.EMFModulePalette_END.getValue())) {
|
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
Log.error("material allocation error");
|
Log.error("material allocation error");
|
||||||
continue;
|
continue;
|
||||||
@ -332,7 +354,7 @@ public ResourceMeshEmf(Uri _fileName) {
|
|||||||
// TODO : ...
|
// TODO : ...
|
||||||
Log.verbose(" illum " + tmpVal);
|
Log.verbose(" illum " + tmpVal);
|
||||||
} else if (inputDataLine.startsWith("map_Kd ") == true) {
|
} else if (inputDataLine.startsWith("map_Kd ") == true) {
|
||||||
Uri tmpTexture = _fileName.getParent();
|
Uri tmpTexture = fileName.getParent();
|
||||||
tmpTexture = tmpTexture.pathAdd(inputDataLine.substring(7));
|
tmpTexture = tmpTexture.pathAdd(inputDataLine.substring(7));
|
||||||
material.setTexture0(tmpTexture);
|
material.setTexture0(tmpTexture);
|
||||||
Log.verbose(" Texture " + tmpTexture);
|
Log.verbose(" Texture " + tmpTexture);
|
||||||
@ -340,12 +362,13 @@ public ResourceMeshEmf(Uri _fileName) {
|
|||||||
//RenderMode mode;
|
//RenderMode mode;
|
||||||
//frothis.string(mode, &inputDataLine[11]);
|
//frothis.string(mode, &inputDataLine[11]);
|
||||||
//material.setRenderMode(mode);
|
//material.setRenderMode(mode);
|
||||||
Log.verbose(" Texture " + mode);
|
Log.verbose(" Texture " + this.mode);
|
||||||
} else {
|
} else {
|
||||||
Log.error("unknow material property ... : '" + inputDataLine + "'");
|
Log.error("unknow material property ... : '" + inputDataLine + "'");
|
||||||
}
|
}
|
||||||
} else if ( currentMode.getValue() >= emfModuleMode.EMFModulePhysics.getValue()
|
continue;
|
||||||
&& currentMode.getValue() <= emfModuleMode.EMFModulePhysics_END.getValue()) {
|
}
|
||||||
|
if (currentMode.getValue() >= emfModuleMode.EMFModulePhysics.getValue() && currentMode.getValue() <= emfModuleMode.EMFModulePhysics_END.getValue()) {
|
||||||
if (level == 1) {
|
if (level == 1) {
|
||||||
Log.error("Load shape : " + inputDataLine);
|
Log.error("Load shape : " + inputDataLine);
|
||||||
// physics = ege::physics::Shape::create(inputDataLine);
|
// physics = ege::physics::Shape::create(inputDataLine);
|
||||||
@ -365,15 +388,13 @@ public ResourceMeshEmf(Uri _fileName) {
|
|||||||
// Log.error("ERROR when parsing :'" + inputDataLine + "' in physical shape ...");
|
// Log.error("ERROR when parsing :'" + inputDataLine + "' in physical shape ...");
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
} else {
|
continue;
|
||||||
// unknow ...
|
|
||||||
Log.warning("Unknow type of line == > jump end of line ... " + inputDataLine);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// unknown ...
|
||||||
|
Log.warning("Unknown type of line == > jump end of line ... " + inputDataLine);
|
||||||
}
|
}
|
||||||
// add last material ...
|
// add last material ...
|
||||||
if( materialName != ""
|
if (materialName != "" && material != null) {
|
||||||
&& material != null) {
|
|
||||||
if (currentMode == emfModuleMode.EMFModulePalette) {
|
if (currentMode == emfModuleMode.EMFModulePalette) {
|
||||||
this.palettes.put(materialName, material);
|
this.palettes.put(materialName, material);
|
||||||
// TODO Remove this later ...
|
// TODO Remove this later ...
|
||||||
@ -405,10 +426,12 @@ public ResourceMeshEmf(Uri _fileName) {
|
|||||||
Log.verbose(" nb material: " + this.materials.size());
|
Log.verbose(" nb material: " + this.materials.size());
|
||||||
Log.verbose(" nb palettes: " + this.palettes.size());
|
Log.verbose(" nb palettes: " + this.palettes.size());
|
||||||
//Log.verbose(" nb physic: " + this.physics.size());
|
//Log.verbose(" nb physic: " + this.physics.size());
|
||||||
|
if (this.listVertex.size() == 0) {
|
||||||
|
throw new Exception("unable to load the mesh file: " + fileName + " ==> no vertex available.");
|
||||||
|
}
|
||||||
generateVBO();
|
generateVBO();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//private String loadNextData(int _maxData,
|
//private String loadNextData(int _maxData,
|
||||||
// BufferedReader _file) {
|
// BufferedReader _file) {
|
||||||
// return loadNextData(_maxData, _file, false, false, true);
|
// return loadNextData(_maxData, _file, false, false, true);
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
package org.atriasoft.loader3d.resources;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.atriasoft.etk.math.Vector3f;
|
||||||
|
import org.atriasoft.loader3d.Face;
|
||||||
|
import org.atriasoft.loader3d.FaceIndexing;
|
||||||
|
import org.atriasoft.loader3d.NormalMode;
|
||||||
|
import org.atriasoft.loader3d.model.Material;
|
||||||
|
|
||||||
|
public class ResourceMeshHeightMap extends ResourceMesh {
|
||||||
|
/*
|
||||||
|
* 0 1 2 3
|
||||||
|
* 0 *-------*-------*-------*
|
||||||
|
* \ OO / \ 02 / \ 04 / \
|
||||||
|
* \ / \ / \ / \
|
||||||
|
* \ / 01 \ / 03 \ / 05 \
|
||||||
|
* *-------*-------*-------*
|
||||||
|
* / \ / \ / \ /
|
||||||
|
* / \ / \ / \ /
|
||||||
|
* / \ / \ / \ /
|
||||||
|
* *-------*-------*-------*
|
||||||
|
*/
|
||||||
|
public ResourceMeshHeightMap() {
|
||||||
|
this.normalMode = NormalMode.FACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addPalette(String key, Material mat) {
|
||||||
|
this.palettes.put(key, mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Material> getPalette() {
|
||||||
|
return this.palettes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void udateData(float[][] heightMap, String[][] colorMap, int width, int length) throws Exception {
|
||||||
|
float ratio = 0.2f;
|
||||||
|
for (int yyy = 0; yyy < length - 1; yyy++) {
|
||||||
|
for (int xxx = 0; xxx < width - 1; xxx++) {
|
||||||
|
Vector3f vertex1 = new Vector3f(ratio * xxx, ratio * yyy, ratio * heightMap[yyy][xxx]);
|
||||||
|
this.listVertex.add(vertex1);
|
||||||
|
Vector3f vertex2 = new Vector3f(ratio * (xxx + 1), ratio * yyy, ratio * heightMap[yyy][xxx + 1]);
|
||||||
|
this.listVertex.add(vertex2);
|
||||||
|
Vector3f vertex3 = new Vector3f(ratio * xxx, ratio * (yyy + 1), ratio * heightMap[yyy + 1][xxx]);
|
||||||
|
this.listVertex.add(vertex3);
|
||||||
|
FaceIndexing currentFaceIndexing = null;
|
||||||
|
String meshFaceMaterialID = colorMap[yyy][xxx * 2];
|
||||||
|
if (this.listPaletteFaces.containsKey(meshFaceMaterialID) == false) {
|
||||||
|
currentFaceIndexing = new FaceIndexing();
|
||||||
|
this.listPaletteFaces.put(meshFaceMaterialID, currentFaceIndexing);
|
||||||
|
} else {
|
||||||
|
currentFaceIndexing = this.listPaletteFaces.get(meshFaceMaterialID);
|
||||||
|
}
|
||||||
|
Face face = new Face();
|
||||||
|
int pos = this.listVertex.size() - 3;
|
||||||
|
face.setVertex(pos, pos + 1, pos + 2);
|
||||||
|
|
||||||
|
currentFaceIndexing.face().add(face);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
generateVBO();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -5,10 +5,10 @@ import org.atriasoft.gale.resource.Resource;
|
|||||||
import org.atriasoft.gale.resource.ResourceVirtualArrayObject;
|
import org.atriasoft.gale.resource.ResourceVirtualArrayObject;
|
||||||
import org.atriasoft.loader3d.internal.Log;
|
import org.atriasoft.loader3d.internal.Log;
|
||||||
|
|
||||||
public class ResourceStaticMeshObjBynamic extends ResourceStaticMeshObj {
|
public class ResourceStaticMeshObjDynamic extends ResourceStaticMeshObj {
|
||||||
|
|
||||||
public static ResourceStaticMeshObjBynamic create(final Uri uriObj) {
|
public static ResourceStaticMeshObjDynamic create(final Uri uriObj) {
|
||||||
ResourceStaticMeshObjBynamic resource;
|
ResourceStaticMeshObjDynamic resource;
|
||||||
Resource resource2;
|
Resource resource2;
|
||||||
final String name = uriObj.getValue();
|
final String name = uriObj.getValue();
|
||||||
if (name.isEmpty() || name.equals("---")) {
|
if (name.isEmpty() || name.equals("---")) {
|
||||||
@ -17,19 +17,19 @@ public class ResourceStaticMeshObjBynamic extends ResourceStaticMeshObj {
|
|||||||
}
|
}
|
||||||
resource2 = Resource.getManager().localKeep(name);
|
resource2 = Resource.getManager().localKeep(name);
|
||||||
if (resource2 != null) {
|
if (resource2 != null) {
|
||||||
if (resource2 instanceof ResourceStaticMeshObjBynamic tmpp) {
|
if (resource2 instanceof ResourceStaticMeshObjDynamic tmpp) {
|
||||||
resource2.keep();
|
resource2.keep();
|
||||||
return tmpp;
|
return tmpp;
|
||||||
}
|
}
|
||||||
Log.critical("Request resource file : '" + name + "' With the wrong type (dynamic cast error)");
|
Log.critical("Request resource file : '" + name + "' With the wrong type (dynamic cast error)");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
resource = new ResourceStaticMeshObjBynamic(uriObj);
|
resource = new ResourceStaticMeshObjDynamic(uriObj);
|
||||||
Resource.getManager().localAdd(resource);
|
Resource.getManager().localAdd(resource);
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ResourceStaticMeshObjBynamic(final Uri uriFile) {
|
protected ResourceStaticMeshObjDynamic(final Uri uriFile) {
|
||||||
super(uriFile);
|
super(uriFile);
|
||||||
}
|
}
|
||||||
|
|
@ -13,7 +13,7 @@ import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
|||||||
import org.atriasoft.etk.Uri;
|
import org.atriasoft.etk.Uri;
|
||||||
import org.atriasoft.gale.Gale;
|
import org.atriasoft.gale.Gale;
|
||||||
import org.atriasoft.gale.context.GaleContextTest;
|
import org.atriasoft.gale.context.GaleContextTest;
|
||||||
import org.atriasoft.loader3d.resources.ResourceMeshEmf;
|
import org.atriasoft.loader3d.resources.ResourceMeshHeightMap;
|
||||||
import org.junit.jupiter.api.Order;
|
import org.junit.jupiter.api.Order;
|
||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
|
|
||||||
@ -27,10 +27,10 @@ public class TestBasicLog {
|
|||||||
GaleContextTest tmpContext = new GaleContextTest();
|
GaleContextTest tmpContext = new GaleContextTest();
|
||||||
Uri.setGroup("EMF", "emf");
|
Uri.setGroup("EMF", "emf");
|
||||||
Uri.setApplication(TestBasicLog.class, "");
|
Uri.setApplication(TestBasicLog.class, "");
|
||||||
Uri.addLibrary("test", ResourceMeshEmf.class, "/resources");
|
Uri.addLibrary("test", ResourceMeshHeightMap.class, "/resources");
|
||||||
|
|
||||||
//ResourceMeshEmf tmp = new ResourceMeshEmf(new Uri("EMF", "tree1.emf", "test"));
|
//ResourceMeshEmf tmp = new ResourceMeshEmf(new Uri("EMF", "tree1.emf", "test"));
|
||||||
ResourceMeshEmf tmp = new ResourceMeshEmf(new Uri("FILE", "/home/heero/dev/workspace-game/atriasoft/loader3d/out/eclipse/classes/resources/emf/tree1.emf"));
|
ResourceMeshHeightMap tmp = new ResourceMeshHeightMap(new Uri("FILE", "/home/heero/dev/workspace-game/atriasoft/loader3d/out/eclipse/classes/resources/emf/tree1.emf"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user