update basic ground

This commit is contained in:
Edouard DUPIN 2022-03-09 00:22:21 +01:00
parent 4d73d8ac48
commit 8d2e6305da
6 changed files with 67 additions and 10 deletions

View File

@ -20,4 +20,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1646149232188</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>

View File

@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1646149232189</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>

View File

@ -27,6 +27,15 @@
},
"grass_1":{
"Kd":"0.057805 1.0 0.013702"
},
"grass_2":{
"Kd":"1.0 0.0 0.013702"
},
"grass_3":{
"Kd":"1.0 1.0 0.013702"
},
"grass_4":{
"Kd":"0.0 0.0 1.0"
}
}
}

View File

@ -32,6 +32,7 @@ public class ApplScene extends EgeScene {
groundEntity
.addComponent(new ComponentRenderMeshPalette(new Uri("DATA", "basicPalette.vert"), new Uri("DATA", "basicPalette.frag"), (EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
this.env.addEntity(groundEntity);
this.ground.updateMesh();
}
}

View File

@ -54,7 +54,7 @@ public class EgeScene extends Widget {
final Camera mainView = new Camera();
this.env.addCamera("default", mainView);
mainView.setPitch((float) Math.PI * -0.25f);
mainView.setPosition(new Vector3f(0, -5, 5));
mainView.setPosition(new Vector3f(4, -5, 5));
}

View File

@ -5,17 +5,27 @@ import org.atriasoft.loader3d.model.Material;
import org.atriasoft.loader3d.resources.ResourceMeshHeightMap;
public class Ground {
int width = 512;
int length = 512;
float[][] heightMap = new float[512][512];
String[][] colorMap = new String[512][512 * 2];
int sizeX = 16;
int sizeY = 16;
float[][] heightMap = new float[this.sizeY][this.sizeX];
String[][] colorMap = new String[this.sizeY][this.sizeX * 2];
ResourceMeshHeightMap mesh = new ResourceMeshHeightMap();
String baseNamePalette = "palette:grass_1";
String baseNamePalette2 = "palette:grass_2";
String baseNamePalette3 = "palette:grass_3";
String baseNamePalette4 = "palette:grass_4";
public Ground() {
for (int yyy = 0; yyy < this.length; yyy++) {
for (int xxx = 0; xxx < this.width; xxx++) {
for (int yyy = 0; yyy < this.sizeY; yyy++) {
for (int xxx = 0; xxx < this.sizeX; xxx++) {
this.heightMap[yyy][xxx] = 0.0f;
this.colorMap[yyy][xxx] = "grass_1";
if (xxx % 2 == 0) {
this.colorMap[yyy][xxx * 2] = this.baseNamePalette;
this.colorMap[yyy][xxx * 2 + 1] = this.baseNamePalette2;
} else {
this.colorMap[yyy][xxx * 2] = this.baseNamePalette3;
this.colorMap[yyy][xxx * 2 + 1] = this.baseNamePalette4;
}
}
}
}
@ -26,8 +36,23 @@ public class Ground {
public void updateMesh() {
Material mat = new Material();
this.mesh.addMaterial("grass_1", mat);
mat.setAmbientFactor(new Vector4f(1.0f, 0, 0, 1.0f));
this.mesh.addMaterial(this.baseNamePalette, mat);
mat.setAmbientFactor(new Vector4f(1, 0, 0, 1.0f));
mat = new Material();
this.mesh.addMaterial(this.baseNamePalette2, mat);
mat.setAmbientFactor(new Vector4f(0, 1, 0, 1.0f));
mat = new Material();
this.mesh.addMaterial(this.baseNamePalette3, mat);
mat.setAmbientFactor(new Vector4f(0, 0, 1, 1.0f));
mat = new Material();
this.mesh.addMaterial(this.baseNamePalette4, mat);
mat.setAmbientFactor(new Vector4f(1, 1, 0, 1.0f));
try {
this.mesh.udateData(this.heightMap, this.colorMap, this.sizeX, this.sizeY);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}