bounding sphere work
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-30 14:56:57 -04:00
parent d4858f7d90
commit cc40718f42
12 changed files with 50 additions and 42 deletions

View File

@ -2078,6 +2078,7 @@ Town constructs nav graph of road nodes
Render pathing nodes (still needs some work)
Pathing construction between town buildings and road nodes
Pathing construction for farm plots
Bounding sphere work

View File

@ -37,9 +37,7 @@ public class RenderUtils {
*/
public static Model wrapMeshInModel(Mesh mesh){
Model model = new Model();
//setup extra structures
mesh.setParent(model);
model.getMeshes().add(mesh);
model.addMesh(mesh);
return model;
}

View File

@ -599,8 +599,7 @@ public class BlockMeshgen {
m.setShader(Globals.blockShader);
m.setParent(rVal);
rVal.getMeshes().add(m);
rVal.setBoundingSphere(m.getBoundingSphere());
rVal.addMesh(m);
return rVal;
}

View File

@ -189,7 +189,7 @@ public class EngineMeshgen {
particleMesh.setParent(particleModel);
particleModel.getMeshes().add(particleMesh);
particleModel.addMesh(particleMesh);
return particleModel;
@ -279,7 +279,7 @@ public class EngineMeshgen {
m.setMaterial(uiMat);
rVal.getMaterials().add(uiMat);
rVal.getMeshes().add(m);
rVal.addMesh(m);
return rVal;
}
@ -368,9 +368,8 @@ public class EngineMeshgen {
openGLState.glBindVertexArray(0);
m.setParent(rVal);
rVal.getMeshes().add(m);
rVal.addMesh(m);
return rVal;
}
@ -453,9 +452,8 @@ public class EngineMeshgen {
openGLState.glBindVertexArray(0);
m.setParent(rVal);
rVal.getMeshes().add(m);
rVal.addMesh(m);
return rVal;
}

View File

@ -795,10 +795,8 @@ public class FluidChunkModelGeneration {
m.setMaterial(groundMat);
m.setShader(FluidChunkModelGeneration.fluidChunkShaderProgram);
m.setParent(rVal);
rVal.getMeshes().add(m);
rVal.setBoundingSphere(m.getBoundingSphere());
rVal.addMesh(m);
return rVal;
}

View File

@ -458,6 +458,18 @@ public class GeometryMeshGen {
ex.printStackTrace();
}
//
// Calculate bounding sphere
//
double maxDist = 0;
for(int i = 0; i < points.length; i++){
double dist = points[i].distance(centerpoint);
if(dist > maxDist){
maxDist = dist;
}
}
mesh.updateBoundingSphere(centerpoint.x, centerpoint.y, centerpoint.z, maxDist + height);
return mesh;
}

View File

@ -112,8 +112,7 @@ public class GeometryModelGen {
planeMesh.setShader(VisualShader.loadSpecificShader(vertexShader,fragmentShader));
openGLState.glBindVertexArray(0);
planeMesh.setParent(rVal);
rVal.getMeshes().add(planeMesh);
rVal.addMesh(planeMesh);
return rVal;
}
@ -164,8 +163,7 @@ public class GeometryModelGen {
sphereMesh.setMaterial(mat);
sphereMesh.setShader(VisualShader.smartAssembleShader());
openGLState.glBindVertexArray(0);
sphereMesh.setParent(model);
model.getMeshes().add(sphereMesh);
model.addMesh(sphereMesh);
return model;
}
@ -219,8 +217,7 @@ public class GeometryModelGen {
sphereMesh.setMaterial(mat);
sphereMesh.setShader(VisualShader.smartAssembleShader());
openGLState.glBindVertexArray(0);
sphereMesh.setParent(model);
model.getMeshes().add(sphereMesh);
model.addMesh(sphereMesh);
return model;
}
@ -306,8 +303,7 @@ public class GeometryModelGen {
sphereMesh.setMaterial(mat);
sphereMesh.setShader(VisualShader.smartAssembleShader());
openGLState.glBindVertexArray(0);
sphereMesh.setParent(model);
model.getMeshes().add(sphereMesh);
model.addMesh(sphereMesh);
return model;
}
@ -393,8 +389,7 @@ public class GeometryModelGen {
cubeMesh.setMaterial(mat);
cubeMesh.setShader(VisualShader.loadSpecificShader(AssetDataStrings.SHADER_BLOCK_SINGLE_VERT, AssetDataStrings.SHADER_BLOCK_SINGLE_FRAG));
openGLState.glBindVertexArray(0);
cubeMesh.setParent(model);
model.getMeshes().add(cubeMesh);
model.addMesh(cubeMesh);
return model;
}

View File

@ -177,12 +177,11 @@ public class HeightmapMeshgen {
m.bufferCustomFloatAttribArray(textureIndices, 4, 5);
m.setShader(program);
openGLState.glBindVertexArray(0);
m.setParent(rVal);
Material groundMat = Material.create("/Textures/Ground/Dirt1.png");
m.setMaterial(groundMat);
rVal.getMeshes().add(m);
rVal.addMesh(m);
return rVal;
}
@ -731,12 +730,11 @@ public class HeightmapMeshgen {
m.bufferCustomFloatAttribArray(textureIndices, 4, 5);
m.setShader(program);
openGLState.glBindVertexArray(0);
m.setParent(rVal);
Material groundMat = Material.create("/Textures/Ground/Dirt1.png");
m.setMaterial(groundMat);
rVal.getMeshes().add(m);
rVal.addMesh(m);
return rVal;
}

View File

@ -894,10 +894,8 @@ public class TerrainChunkModelGeneration {
//shader logic
m.setShader(Globals.terrainShaderProgram);
m.setParent(rVal);
rVal.getMeshes().add(m);
rVal.setBoundingSphere(m.getBoundingSphere());
rVal.addMesh(m);
return rVal;
}

View File

@ -2304,10 +2304,8 @@ public class TransvoxelModelGeneration {
//shader logic
m.setShader(Globals.terrainShaderProgram);
m.setParent(rVal);
rVal.getMeshes().add(m);
rVal.setBoundingSphere(m.getBoundingSphere());
rVal.addMesh(m);
return rVal;
}

View File

@ -666,7 +666,7 @@ public class Mesh {
* @param z
* @param r
*/
public void updateBoundingSphere(float x, float y, float z, float r){
public void updateBoundingSphere(double x, double y, double z, double r){
this.boundingSphere.x = x;
this.boundingSphere.y = y;
this.boundingSphere.z = z;

View File

@ -15,6 +15,7 @@ import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.joml.Matrix4d;
@ -163,12 +164,7 @@ public class Model {
meshMetadata = modelMetadata.getMesh(aiMesh.mName().dataString());
}
Mesh currentMesh = MeshLoader.createMeshFromAIScene(aiMesh, meshMetadata);
rVal.meshes.add(currentMesh);
currentMesh.setParent(rVal);
//update model bounding sphere
if(currentMesh.getBoundingSphere().r > rVal.boundingSphere.r){
rVal.boundingSphere.r = currentMesh.getBoundingSphere().r;
}
rVal.addMesh(currentMesh);
//conditionally add material
int materialIndex = aiMesh.mMaterialIndex();
@ -549,7 +545,24 @@ public class Model {
* @return the list of meshes
*/
public List<Mesh> getMeshes(){
return meshes;
return Collections.unmodifiableList(meshes);
}
/**
* Adds a mesh to the model
* @param mesh The mesh
*/
public void addMesh(Mesh mesh){
this.meshes.add(mesh);
mesh.setParent(this);
if(this.meshes.size() == 1){
this.boundingSphere.r = mesh.getBoundingSphere().r;
this.boundingSphere.x = mesh.getBoundingSphere().x;
this.boundingSphere.y = mesh.getBoundingSphere().y;
this.boundingSphere.z = mesh.getBoundingSphere().z;
} else if(mesh.getBoundingSphere().r > this.boundingSphere.r){
this.boundingSphere.r = mesh.getBoundingSphere().r;
}
}
/**