Correct heightmap
This commit is contained in:
parent
8ba3c34262
commit
57c759c0f7
11
.project
11
.project
@ -14,4 +14,15 @@
|
|||||||
<natures>
|
<natures>
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
|
<filteredResources>
|
||||||
|
<filter>
|
||||||
|
<id>1646149232199</id>
|
||||||
|
<name></name>
|
||||||
|
<type>30</type>
|
||||||
|
<matcher>
|
||||||
|
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||||
|
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||||
|
</matcher>
|
||||||
|
</filter>
|
||||||
|
</filteredResources>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
@ -592,23 +592,12 @@ public class ResourceMesh extends ResourceStaticMesh {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void createViewBox( String _materialName,float _size=1.0){
|
protected void calculateNormaleFace(final String materialName) {
|
||||||
// this.normalMode = NormalMode.NONE;
|
|
||||||
// ege::viewBox::create(this.materials, this.listFaces, this.listVertex, this.listUV,
|
|
||||||
// _materialName, _size);
|
|
||||||
// calculateNormaleFace(_materialName);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void createIcoSphere( String _materialName,float _size=1.0, int _subdivision=3) {
|
|
||||||
// this.normalMode = NormalMode.NONE;
|
|
||||||
// ege::icoSphere::create(this.materials, this.listFaces, this.listVertex, this.listUV,
|
|
||||||
// _materialName, _size, _subdivision);
|
|
||||||
// calculateNormaleFace(_materialName);
|
|
||||||
// }
|
|
||||||
//private boolean loadOBJ( Uri _fileName);
|
|
||||||
//private boolean loadEMF( Uri _fileName);
|
|
||||||
private void calculateNormaleFace(final String _materialName) {
|
|
||||||
this.listFacesNormal.clear();
|
this.listFacesNormal.clear();
|
||||||
|
calculateNormaleFaceLocal(materialName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void calculateNormaleFaceLocal(final String _materialName) {
|
||||||
if (this.normalMode == NormalMode.FACE) {
|
if (this.normalMode == NormalMode.FACE) {
|
||||||
Log.verbose("calculateNormaleFace(" + _materialName + ")");
|
Log.verbose("calculateNormaleFace(" + _materialName + ")");
|
||||||
RenderMode tmpRenderMode = this.materials.get(_materialName).getRenderMode();
|
RenderMode tmpRenderMode = this.materials.get(_materialName).getRenderMode();
|
||||||
@ -617,7 +606,13 @@ public class ResourceMesh extends ResourceStaticMesh {
|
|||||||
this.normalMode = NormalMode.NONE;
|
this.normalMode = NormalMode.NONE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (Face it : this.listFaces.get(_materialName).face()) {
|
FaceIndexing faceList = null;
|
||||||
|
if (this.listFaces.containsKey(_materialName)) {
|
||||||
|
faceList = this.listFaces.get(_materialName);
|
||||||
|
} else if (this.listPaletteFaces.containsKey(_materialName)) {
|
||||||
|
faceList = this.listPaletteFaces.get(_materialName);
|
||||||
|
}
|
||||||
|
for (Face it : faceList.face()) {
|
||||||
// for all case, We use only the 3 vertex for quad element, in theory 3D modeler export element in triangle if it is not a real plane.
|
// for all case, We use only the 3 vertex for quad element, in theory 3D modeler export element in triangle if it is not a real plane.
|
||||||
Vector3f normal = (this.listVertex.get(it.vertex[0]).less(this.listVertex.get(it.vertex[1]))).cross(this.listVertex.get(it.vertex[1]).less(this.listVertex.get(it.vertex[2])));
|
Vector3f normal = (this.listVertex.get(it.vertex[0]).less(this.listVertex.get(it.vertex[1]))).cross(this.listVertex.get(it.vertex[1]).less(this.listVertex.get(it.vertex[2])));
|
||||||
//Log.info("normal: " + normal.normalized());
|
//Log.info("normal: " + normal.normalized());
|
||||||
@ -635,6 +630,30 @@ public class ResourceMesh extends ResourceStaticMesh {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public void createViewBox( String _materialName,float _size=1.0){
|
||||||
|
// this.normalMode = NormalMode.NONE;
|
||||||
|
// ege::viewBox::create(this.materials, this.listFaces, this.listVertex, this.listUV,
|
||||||
|
// _materialName, _size);
|
||||||
|
// calculateNormaleFace(_materialName);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void createIcoSphere( String _materialName,float _size=1.0, int _subdivision=3) {
|
||||||
|
// this.normalMode = NormalMode.NONE;
|
||||||
|
// ege::icoSphere::create(this.materials, this.listFaces, this.listVertex, this.listUV,
|
||||||
|
// _materialName, _size, _subdivision);
|
||||||
|
// calculateNormaleFace(_materialName);
|
||||||
|
// }
|
||||||
|
//private boolean loadOBJ( Uri _fileName);
|
||||||
|
//private boolean loadEMF( Uri _fileName);
|
||||||
|
|
||||||
|
protected void calculateNormaleFaces(final List<String> materialsNames) {
|
||||||
|
this.listFacesNormal.clear();
|
||||||
|
for (String name : materialsNames) {
|
||||||
|
Log.warning("generate normal for: '" + name + "'");
|
||||||
|
calculateNormaleFaceLocal(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void clean() {
|
void clean() {
|
||||||
//this.physics.clear();
|
//this.physics.clear();
|
||||||
this.materials.clear();
|
this.materials.clear();
|
||||||
@ -648,6 +667,17 @@ public class ResourceMesh extends ResourceStaticMesh {
|
|||||||
this.vao = ResourceVirtualArrayObject.createDynamic();
|
this.vao = ResourceVirtualArrayObject.createDynamic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cleanPartial() {
|
||||||
|
this.listFaces.clear();
|
||||||
|
this.listPaletteFaces.clear();
|
||||||
|
this.listColor.clear();
|
||||||
|
this.listVertexNormal.clear();
|
||||||
|
this.listFacesNormal.clear();
|
||||||
|
this.listUV.clear();
|
||||||
|
this.listVertex.clear();
|
||||||
|
this.vao = ResourceVirtualArrayObject.createDynamic();
|
||||||
|
}
|
||||||
|
|
||||||
protected int findColorInList(final Color _color) {
|
protected int findColorInList(final Color _color) {
|
||||||
for (int iii = 0; iii < this.listColor.size(); ++iii) {
|
for (int iii = 0; iii < this.listColor.size(); ++iii) {
|
||||||
if (this.listColor.get(iii) == _color) {
|
if (this.listColor.get(iii) == _color) {
|
||||||
@ -762,7 +792,7 @@ public class ResourceMesh extends ResourceStaticMesh {
|
|||||||
// calculate the normal of all faces if needed
|
// calculate the normal of all faces if needed
|
||||||
if (this.normalMode != NormalMode.NONE && this.listFacesNormal.size() == 0) {
|
if (this.normalMode != NormalMode.NONE && this.listFacesNormal.size() == 0) {
|
||||||
// when no normal detected == > auto generate Face normal ....
|
// when no normal detected == > auto generate Face normal ....
|
||||||
Log.error("No normal detected ???");
|
Log.error("No normal detected ??? ==> abort generation of the VBO");
|
||||||
// calculateNormaleFace(this.listFaces.getKeys()[0]);
|
// calculateNormaleFace(this.listFaces.getKeys()[0]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package org.atriasoft.loader3d.resources;
|
package org.atriasoft.loader3d.resources;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.atriasoft.etk.math.Vector3f;
|
import org.atriasoft.etk.math.Vector3f;
|
||||||
|
import org.atriasoft.gale.backend3d.OpenGL.RenderMode;
|
||||||
import org.atriasoft.loader3d.Face;
|
import org.atriasoft.loader3d.Face;
|
||||||
import org.atriasoft.loader3d.FaceIndexing;
|
import org.atriasoft.loader3d.FaceIndexing;
|
||||||
import org.atriasoft.loader3d.NormalMode;
|
import org.atriasoft.loader3d.NormalMode;
|
||||||
@ -23,6 +26,7 @@ public class ResourceMeshHeightMap extends ResourceMesh {
|
|||||||
*/
|
*/
|
||||||
public ResourceMeshHeightMap() {
|
public ResourceMeshHeightMap() {
|
||||||
this.normalMode = NormalMode.FACE;
|
this.normalMode = NormalMode.FACE;
|
||||||
|
this.vao.setName("[VBO] of heightmap");
|
||||||
}
|
}
|
||||||
|
|
||||||
void addPalette(String key, Material mat) {
|
void addPalette(String key, Material mat) {
|
||||||
@ -33,31 +37,131 @@ public class ResourceMeshHeightMap extends ResourceMesh {
|
|||||||
return this.palettes;
|
return this.palettes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void udateData(float[][] heightMap, String[][] colorMap, int width, int length) throws Exception {
|
public void udateData(float[][] heightMap, String[][] colorMap, int sizeX, int sizeY) throws Exception {
|
||||||
float ratio = 0.2f;
|
float ratio = 1;
|
||||||
for (int yyy = 0; yyy < length - 1; yyy++) {
|
setMode(RenderMode.TRIANGLE);
|
||||||
for (int xxx = 0; xxx < width - 1; xxx++) {
|
//cleanPartial();
|
||||||
Vector3f vertex1 = new Vector3f(ratio * xxx, ratio * yyy, ratio * heightMap[yyy][xxx]);
|
List<String> materialsNames = new ArrayList<>();
|
||||||
this.listVertex.add(vertex1);
|
for (int yyy = 0; yyy < sizeY - 1; yyy++) {
|
||||||
Vector3f vertex2 = new Vector3f(ratio * (xxx + 1), ratio * yyy, ratio * heightMap[yyy][xxx + 1]);
|
for (int xxx = 0; xxx < sizeX - 1; xxx++) {
|
||||||
this.listVertex.add(vertex2);
|
if (xxx % 2 == 0) {
|
||||||
Vector3f vertex3 = new Vector3f(ratio * xxx, ratio * (yyy + 1), ratio * heightMap[yyy + 1][xxx]);
|
float offsetA = 0.5f;
|
||||||
this.listVertex.add(vertex3);
|
{
|
||||||
FaceIndexing currentFaceIndexing = null;
|
int pos = this.listVertex.size();
|
||||||
String meshFaceMaterialID = colorMap[yyy][xxx * 2];
|
Vector3f vertex1 = new Vector3f(ratio * xxx, ratio * yyy, ratio * heightMap[yyy][xxx]);
|
||||||
if (this.listPaletteFaces.containsKey(meshFaceMaterialID) == false) {
|
this.listVertex.add(vertex1);
|
||||||
currentFaceIndexing = new FaceIndexing();
|
Vector3f vertex2 = new Vector3f(ratio * (xxx + 1), ratio * (yyy + offsetA), ratio * heightMap[yyy][xxx + 1]);
|
||||||
this.listPaletteFaces.put(meshFaceMaterialID, currentFaceIndexing);
|
this.listVertex.add(vertex2);
|
||||||
} else {
|
Vector3f vertex3 = new Vector3f(ratio * xxx, ratio * (yyy + 1.0f), ratio * heightMap[yyy + 1][xxx]);
|
||||||
currentFaceIndexing = this.listPaletteFaces.get(meshFaceMaterialID);
|
this.listVertex.add(vertex3);
|
||||||
}
|
FaceIndexing currentFaceIndexing = null;
|
||||||
Face face = new Face();
|
String meshFaceMaterialID = colorMap[yyy][xxx * 2];
|
||||||
int pos = this.listVertex.size() - 3;
|
if (!materialsNames.contains(meshFaceMaterialID)) {
|
||||||
face.setVertex(pos, pos + 1, pos + 2);
|
materialsNames.add(meshFaceMaterialID);
|
||||||
|
}
|
||||||
|
if (!this.listPaletteFaces.containsKey(meshFaceMaterialID)) {
|
||||||
|
currentFaceIndexing = new FaceIndexing();
|
||||||
|
this.listPaletteFaces.put(meshFaceMaterialID, currentFaceIndexing);
|
||||||
|
} else {
|
||||||
|
currentFaceIndexing = this.listPaletteFaces.get(meshFaceMaterialID);
|
||||||
|
}
|
||||||
|
Face face = new Face();
|
||||||
|
face.setVertex(pos, pos + 1, pos + 2);
|
||||||
|
|
||||||
currentFaceIndexing.face().add(face);
|
currentFaceIndexing.face().add(face);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int pos = this.listVertex.size();
|
||||||
|
Vector3f vertex1 = new Vector3f(ratio * (xxx + 1), ratio * (yyy + 1 + offsetA), ratio * heightMap[yyy + 1][xxx + 1]);
|
||||||
|
this.listVertex.add(vertex1);
|
||||||
|
Vector3f vertex2 = new Vector3f(ratio * (xxx + 1), ratio * (yyy + offsetA), 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 + 1];
|
||||||
|
if (!materialsNames.contains(meshFaceMaterialID)) {
|
||||||
|
materialsNames.add(meshFaceMaterialID);
|
||||||
|
}
|
||||||
|
if (!this.listPaletteFaces.containsKey(meshFaceMaterialID)) {
|
||||||
|
currentFaceIndexing = new FaceIndexing();
|
||||||
|
this.listPaletteFaces.put(meshFaceMaterialID, currentFaceIndexing);
|
||||||
|
} else {
|
||||||
|
currentFaceIndexing = this.listPaletteFaces.get(meshFaceMaterialID);
|
||||||
|
}
|
||||||
|
Face face = new Face();
|
||||||
|
face.setVertex(pos, pos + 1, pos + 2);
|
||||||
|
|
||||||
|
currentFaceIndexing.face().add(face);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
float offsetA = 0.5f;
|
||||||
|
{
|
||||||
|
int pos = this.listVertex.size();
|
||||||
|
Vector3f vertex1 = new Vector3f(ratio * xxx, ratio * (yyy + offsetA), 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 + 1), ratio * (yyy + 1.0f), ratio * heightMap[yyy + 1][xxx + 1]);
|
||||||
|
this.listVertex.add(vertex3);
|
||||||
|
FaceIndexing currentFaceIndexing = null;
|
||||||
|
String meshFaceMaterialID = colorMap[yyy][xxx * 2];
|
||||||
|
if (!materialsNames.contains(meshFaceMaterialID)) {
|
||||||
|
materialsNames.add(meshFaceMaterialID);
|
||||||
|
}
|
||||||
|
if (!this.listPaletteFaces.containsKey(meshFaceMaterialID)) {
|
||||||
|
currentFaceIndexing = new FaceIndexing();
|
||||||
|
this.listPaletteFaces.put(meshFaceMaterialID, currentFaceIndexing);
|
||||||
|
} else {
|
||||||
|
currentFaceIndexing = this.listPaletteFaces.get(meshFaceMaterialID);
|
||||||
|
}
|
||||||
|
Face face = new Face();
|
||||||
|
face.setVertex(pos, pos + 1, pos + 2);
|
||||||
|
|
||||||
|
currentFaceIndexing.face().add(face);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int pos = this.listVertex.size();
|
||||||
|
Vector3f vertex1 = new Vector3f(ratio * (xxx + 1), ratio * (yyy + 1), ratio * heightMap[yyy + 1][xxx + 1]);
|
||||||
|
this.listVertex.add(vertex1);
|
||||||
|
Vector3f vertex2 = new Vector3f(ratio * (xxx), ratio * (yyy + 1 + offsetA), ratio * heightMap[yyy + 1][xxx + 1]);
|
||||||
|
this.listVertex.add(vertex2);
|
||||||
|
Vector3f vertex3 = new Vector3f(ratio * xxx, ratio * (yyy + offsetA), ratio * heightMap[yyy][xxx]);
|
||||||
|
this.listVertex.add(vertex3);
|
||||||
|
FaceIndexing currentFaceIndexing = null;
|
||||||
|
String meshFaceMaterialID = colorMap[yyy][xxx * 2 + 1];
|
||||||
|
if (!materialsNames.contains(meshFaceMaterialID)) {
|
||||||
|
materialsNames.add(meshFaceMaterialID);
|
||||||
|
}
|
||||||
|
if (!this.listPaletteFaces.containsKey(meshFaceMaterialID)) {
|
||||||
|
currentFaceIndexing = new FaceIndexing();
|
||||||
|
this.listPaletteFaces.put(meshFaceMaterialID, currentFaceIndexing);
|
||||||
|
} else {
|
||||||
|
currentFaceIndexing = this.listPaletteFaces.get(meshFaceMaterialID);
|
||||||
|
}
|
||||||
|
Face face = new Face();
|
||||||
|
face.setVertex(pos, pos + 1, pos + 2);
|
||||||
|
|
||||||
|
currentFaceIndexing.face().add(face);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Log.warning("this.listVertex: " + this.listVertex.size());
|
||||||
|
//Log.warning("this.listFacesNormal: " + this.listFacesNormal.size());
|
||||||
|
calculateNormaleFaces(materialsNames);
|
||||||
|
//Log.warning("this.listVertex: " + this.listVertex.size());
|
||||||
|
//Log.warning("this.listFacesNormal: " + this.listFacesNormal.size());
|
||||||
|
// Log.verbose("New heightmap mesh : ");
|
||||||
|
// Log.verbose(" nb vertex: " + this.listVertex.size());
|
||||||
|
// Log.verbose(" nb UV: " + this.listUV.size());
|
||||||
|
// Log.verbose(" nb Colors: " + this.listColor.size());
|
||||||
|
// Log.verbose(" nb Normal face: " + this.listFacesNormal.size());
|
||||||
|
// Log.verbose(" nb Normal vertex: " + this.listVertexNormal.size());
|
||||||
|
// Log.verbose(" nb Faces: " + this.listFaces.size());
|
||||||
|
// Log.verbose(" nb Faces (palette): " + this.listPaletteFaces.get(0).face().size());
|
||||||
|
// Log.verbose(" nb material: " + this.materials.size());
|
||||||
|
// Log.verbose(" nb palettes: " + this.palettes.size());
|
||||||
generateVBO();
|
generateVBO();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user