physics debugging
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
b761299c29
commit
c706b855cd
@ -133,8 +133,8 @@
|
||||
"movementSystems" : [
|
||||
{
|
||||
"type" : "GROUND",
|
||||
"acceleration" : 5000.0,
|
||||
"maxVelocity" : 500.5,
|
||||
"acceleration" : 100.0,
|
||||
"maxVelocity" : 50.5,
|
||||
"strafeMultiplier" : 1.0,
|
||||
"backpedalMultiplier" : 0.5,
|
||||
"footstepFirstAudioOffset" : 0.2,
|
||||
@ -167,7 +167,7 @@
|
||||
{
|
||||
"type" : "JUMP",
|
||||
"jumpFrames" : 3,
|
||||
"jumpForce" : 700,
|
||||
"jumpForce" : 20,
|
||||
"animationJump" : {
|
||||
"nameThirdPerson" : "Jump",
|
||||
"nameFirstPerson" : "Jump",
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
],
|
||||
"collidable": {
|
||||
"type" : "CUBE",
|
||||
"mass": 10.0,
|
||||
"mass": 1.0,
|
||||
"rollingFriction": 100.0,
|
||||
"linearFriction": 100.0,
|
||||
"dimension1" : 2.0,
|
||||
@ -23,7 +23,7 @@
|
||||
"rotZ": 0,
|
||||
"rotW": 1,
|
||||
"offsetX" : 0,
|
||||
"offsetY" : 0.05,
|
||||
"offsetY" : 0,
|
||||
"offsetZ" : 0
|
||||
},
|
||||
"tokens": [
|
||||
|
||||
@ -747,6 +747,9 @@ Data cleanup
|
||||
Delete Structure entity type
|
||||
Physics work
|
||||
|
||||
(09/13/2024)
|
||||
Physics debugging
|
||||
|
||||
|
||||
# TODO
|
||||
|
||||
|
||||
@ -233,13 +233,9 @@ public class CollisionBodyCreation {
|
||||
public static DBody generateBodyFromTerrainData(CollisionEngine collisionEngine, TerrainChunkData data, long categoryBits){
|
||||
DBody body = null;
|
||||
|
||||
//create data
|
||||
int numberTriangles = data.getFaceElements().size() / 3;
|
||||
int numberVertices = data.getVertices().size() / 3;
|
||||
|
||||
float[] vertices = new float[numberVertices * 3];
|
||||
float[] vertices = new float[data.getVertices().size()];
|
||||
int vertexInserterPos = 0;
|
||||
int[] indices = new int[numberTriangles * 3];
|
||||
int[] indices = new int[data.getFaceElements().size()];
|
||||
int indexInserterPos = 0;
|
||||
|
||||
for(float vertexValue : data.getVertices()){
|
||||
@ -256,6 +252,8 @@ public class CollisionBodyCreation {
|
||||
if(vertices.length > 0){
|
||||
DTriMesh triMesh = collisionEngine.createTrimeshGeom(vertices,indices,categoryBits);
|
||||
body = collisionEngine.createDBody(triMesh);
|
||||
collisionEngine.setKinematic(body);
|
||||
collisionEngine.setGravityMode(body, false);
|
||||
}
|
||||
|
||||
return body;
|
||||
|
||||
@ -87,7 +87,7 @@ public class CollisionEngine {
|
||||
private static Semaphore spaceLock = new Semaphore(1);
|
||||
private DJointGroup contactgroup;
|
||||
|
||||
private static final int MAX_CONTACTS = 10; // maximum number of contact points per body
|
||||
private static final int MAX_CONTACTS = 64; // maximum number of contact points per body
|
||||
|
||||
//The list of dbodies ode should be tracking
|
||||
List<DBody> bodies = new ArrayList<DBody>();
|
||||
@ -116,11 +116,11 @@ public class CollisionEngine {
|
||||
public CollisionEngine(){
|
||||
world = OdeHelper.createWorld();
|
||||
space = OdeHelper.createBHVSpace(Collidable.TYPE_STATIC_BIT);
|
||||
world.setGravity(0,-GRAVITY_MAGNITUDE,0);
|
||||
world.setAutoDisableFlag(true);
|
||||
world.setGravity(0,-0.5,0);
|
||||
// world.setAutoDisableFlag(true);
|
||||
// world.setContactMaxCorrectingVel(0.1);
|
||||
world.setContactSurfaceLayer(0.001);
|
||||
world.setCFM(0.00000001);
|
||||
// world.setContactSurfaceLayer(0.001);
|
||||
world.setCFM(1e-5);
|
||||
|
||||
//base plane
|
||||
OdeHelper.createPlane(space, 0, 1, 0, 0);
|
||||
@ -262,6 +262,7 @@ public class CollisionEngine {
|
||||
public void simulatePhysics(float time){
|
||||
Globals.profiler.beginCpuSample("physics");
|
||||
spaceLock.acquireUninterruptibly();
|
||||
for(int i = 0; i < 5; i++){
|
||||
Globals.profiler.beginCpuSample("collide");
|
||||
OdeHelper.spaceCollide(space, 0, nearCallback);
|
||||
Globals.profiler.endCpuSample();
|
||||
@ -274,6 +275,7 @@ public class CollisionEngine {
|
||||
|
||||
// remove all contact joints
|
||||
contactgroup.empty();
|
||||
}
|
||||
spaceLock.release();
|
||||
Globals.profiler.endCpuSample();
|
||||
}
|
||||
@ -360,17 +362,18 @@ public class CollisionEngine {
|
||||
for (int i=0; i<numc; i++) {
|
||||
DContact contact = contacts.get(i);
|
||||
|
||||
//
|
||||
//add contact to contact group
|
||||
DJoint c = OdeHelper.createContactJoint(world,contactgroup,contact);
|
||||
c.attach(b1,b2);
|
||||
|
||||
//special code for ray casting
|
||||
if (o1 instanceof DRay || o2 instanceof DRay){
|
||||
DVector3 end = new DVector3();
|
||||
end.eqSum( contact.geom.pos, contact.geom.normal, contact.geom.depth );
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
//add contact to contact group
|
||||
DJoint c = OdeHelper.createContactJoint(world,contactgroup,contact);
|
||||
c.attach(b1,b2);
|
||||
|
||||
// Use the default collision resolution
|
||||
if(collisionResolutionCallback == null) {
|
||||
resolveCollision(
|
||||
@ -672,22 +675,6 @@ public class CollisionEngine {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Ode DSpace
|
||||
* @return The DSpace
|
||||
*/
|
||||
public DSpace getSpace(){
|
||||
return space;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the DWorld for this collision engine
|
||||
* @return The DWorld
|
||||
*/
|
||||
public DWorld getDWorld(){
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a trimesh from a given set of vertices and indices
|
||||
* @param verts The vertices
|
||||
@ -698,7 +685,14 @@ public class CollisionEngine {
|
||||
spaceLock.acquireUninterruptibly();
|
||||
DTriMeshData data = OdeHelper.createTriMeshData();
|
||||
data.build(verts, indices);
|
||||
DTriMesh rVal = OdeHelper.createTriMesh(getSpace(), data);
|
||||
final int preprocessFlags =
|
||||
(1 << DTriMeshData.dTRIDATAPREPROCESS_BUILD.CONCAVE_EDGES) |
|
||||
(1 << DTriMeshData.dTRIDATAPREPROCESS_BUILD.FACE_ANGLES) |
|
||||
(1 << DTriMeshData.dTRIDATAPREPROCESS_FACE_ANGLES_EXTRA__MAX)
|
||||
;
|
||||
data.preprocess2(preprocessFlags,null);
|
||||
DTriMesh rVal = OdeHelper.createTriMesh(space, data);
|
||||
rVal.setTrimeshData(data);
|
||||
rVal.setCategoryBits(categoryBits);
|
||||
spaceLock.release();
|
||||
return rVal;
|
||||
|
||||
@ -5,7 +5,6 @@ import org.joml.Quaterniond;
|
||||
import org.joml.Vector3d;
|
||||
import org.ode4j.ode.DBody;
|
||||
import org.ode4j.ode.DGeom;
|
||||
import org.ode4j.ode.DTriMesh;
|
||||
|
||||
import electrosphere.collision.collidable.Collidable;
|
||||
import electrosphere.engine.Globals;
|
||||
@ -416,82 +415,6 @@ public class PhysicsEntityUtils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* [CLIENT ONLY] Attaches a heightmap dbody to an entity
|
||||
* @param terrain The terrain entity
|
||||
* @param heightfield The heightfield values
|
||||
*
|
||||
* @return The DBody created
|
||||
*/
|
||||
public static DBody clientAttachTerrainRigidBody(Entity terrain, CollisionEngine collisionEngine, float[][] heightfield){
|
||||
int arrayLength = heightfield.length;
|
||||
int arrayWidth = heightfield[0].length;
|
||||
float collisionMargin = 0.08f;
|
||||
|
||||
/*
|
||||
Traditional buffer code not working for some reason
|
||||
the approach of
|
||||
https://stackoverflow.com/questions/40855945/lwjgl-mesh-to-jbullet-collider
|
||||
works much better
|
||||
IDK why
|
||||
*/
|
||||
|
||||
int numberTriangles = (arrayLength - 1) * (arrayWidth - 1) * 2;
|
||||
|
||||
int numberVertices = arrayLength * arrayWidth;
|
||||
|
||||
float[] vertices = new float[numberVertices * 3];
|
||||
int vertexInserterPos = 0;
|
||||
int[] indices = new int[numberTriangles * 3];
|
||||
int indexInserterPos = 0;
|
||||
|
||||
for(int x = 0; x < arrayLength; x++){
|
||||
for(int y = 0; y < arrayWidth; y++){
|
||||
vertices[vertexInserterPos] = x;
|
||||
vertexInserterPos++;
|
||||
vertices[vertexInserterPos] = heightfield[x][y] - collisionMargin;
|
||||
vertexInserterPos++;
|
||||
vertices[vertexInserterPos] = y;
|
||||
vertexInserterPos++;
|
||||
if(x < arrayLength - 1 && y < arrayWidth - 1){
|
||||
//if we should also add a triangle index
|
||||
/*
|
||||
as copied from ModelUtil's terrain mesh generation function
|
||||
faces.put((x / stride + 0) * actualHeight + (y / stride + 0));
|
||||
faces.put((x / stride + 0) * actualHeight + (y / stride + 1));
|
||||
faces.put((x / stride + 1) * actualHeight + (y / stride + 0));
|
||||
faces.put((x / stride + 1) * actualHeight + (y / stride + 0));
|
||||
faces.put((x / stride + 0) * actualHeight + (y / stride + 1));
|
||||
faces.put((x / stride + 1) * actualHeight + (y / stride + 1));
|
||||
*/
|
||||
indices[indexInserterPos] = (x + 0) * arrayWidth + (y + 0);
|
||||
indexInserterPos++;
|
||||
indices[indexInserterPos] = (x + 0) * arrayWidth + (y + 1);
|
||||
indexInserterPos++;
|
||||
indices[indexInserterPos] = (x + 1) * arrayWidth + (y + 0);
|
||||
indexInserterPos++;
|
||||
indices[indexInserterPos] = (x + 1) * arrayWidth + (y + 0);
|
||||
indexInserterPos++;
|
||||
indices[indexInserterPos] = (x + 0) * arrayWidth + (y + 1);
|
||||
indexInserterPos++;
|
||||
indices[indexInserterPos] = (x + 1) * arrayWidth + (y + 1);
|
||||
indexInserterPos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DTriMesh triMesh = collisionEngine.createTrimeshGeom(vertices,indices,Collidable.TYPE_STATIC_BIT);
|
||||
DBody body = collisionEngine.createDBody(triMesh);
|
||||
|
||||
Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(body, new Collidable(terrain,Collidable.TYPE_TERRAIN, false));
|
||||
PhysicsEntityUtils.setDBody(terrain,body);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [CLIENT ONLY] Given an entity and a terrain chunk description, create physics for the chunk and attach it to the entity
|
||||
* @param terrain The entity
|
||||
@ -500,8 +423,6 @@ public class PhysicsEntityUtils {
|
||||
*/
|
||||
public static DBody clientAttachTerrainChunkRigidBody(Entity terrain, TerrainChunkData data){
|
||||
DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(Globals.clientSceneWrapper.getCollisionEngine(), data,Collidable.TYPE_STATIC_BIT);
|
||||
CollisionBodyCreation.setKinematic(Globals.clientSceneWrapper.getCollisionEngine(), terrainBody);
|
||||
CollisionBodyCreation.setGravityMode(Globals.clientSceneWrapper.getCollisionEngine(), terrainBody, false);
|
||||
|
||||
|
||||
Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(terrainBody, new Collidable(terrain,Collidable.TYPE_TERRAIN, false));
|
||||
@ -520,8 +441,6 @@ public class PhysicsEntityUtils {
|
||||
public static DBody serverAttachTerrainChunkRigidBody(Entity terrain, TerrainChunkData data){
|
||||
Realm terrainRealm = Globals.realmManager.getEntityRealm(terrain);
|
||||
DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(terrainRealm.getCollisionEngine(),data,Collidable.TYPE_STATIC_BIT);
|
||||
CollisionBodyCreation.setKinematic(terrainRealm.getCollisionEngine(), terrainBody);
|
||||
CollisionBodyCreation.setGravityMode(terrainRealm.getCollisionEngine(), terrainBody, false);
|
||||
|
||||
terrainRealm.getCollisionEngine().registerCollisionObject(terrainBody, new Collidable(terrain,Collidable.TYPE_TERRAIN, false));
|
||||
PhysicsEntityUtils.setDBody(terrain,terrainBody);
|
||||
|
||||
@ -77,7 +77,7 @@ public class SurfaceParams {
|
||||
*/
|
||||
public SurfaceParams(){
|
||||
mode = OdeConstants.dContactApprox1 & OdeConstants.dContactRolling & OdeConstants.dContactBounce;
|
||||
mu = 10.0;
|
||||
mu = 0.01;
|
||||
rho = 10.0;
|
||||
rho2 = 10.0;
|
||||
rhoN = 10.0;
|
||||
|
||||
@ -608,6 +608,7 @@ public class Globals {
|
||||
//init models
|
||||
assetManager.registerModelToSpecificString(RenderUtils.createUnitsphere(), AssetDataStrings.UNITSPHERE);
|
||||
assetManager.registerModelToSpecificString(RenderUtils.createUnitCylinder(), AssetDataStrings.UNITCYLINDER);
|
||||
assetManager.registerModelToSpecificString(RenderUtils.createUnitCube(), AssetDataStrings.UNITCUBE);
|
||||
assetManager.addModelPathToQueue("Models/basic/geometry/SmallCube.fbx");
|
||||
assetManager.addModelPathToQueue("Models/basic/geometry/unitcapsule.glb");
|
||||
assetManager.addModelPathToQueue("Models/basic/geometry/unitplane.fbx");
|
||||
|
||||
@ -14,6 +14,7 @@ public class AssetDataStrings {
|
||||
*/
|
||||
public static final String UNITSPHERE = "unitSphere";
|
||||
public static final String UNITCYLINDER = "unitCylinder";
|
||||
public static final String UNITCUBE = "unitCube";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ public class Timekeeper {
|
||||
public static final int SIM_FRAME_HARDCAP = 3;
|
||||
|
||||
//step interval time size (for physics)
|
||||
public static final float ENGINE_STEP_SIZE = 0.01f;
|
||||
public static final float ENGINE_STEP_SIZE = 0.05f;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -390,6 +390,9 @@ public class RenderUtils {
|
||||
|
||||
//buffer coords
|
||||
ParShapesMesh data = ParShapes.par_shapes_create_cylinder(10, 2);
|
||||
ParShapes.par_shapes_rotate(data, (float)(Math.PI / 2.0), new float[]{-1,0,0});
|
||||
ParShapes.par_shapes_translate(data, 0, -0.5f, 0);
|
||||
ParShapes.par_shapes_scale(data, -1.0f, 2.0f, 1.0f);
|
||||
int numPoints = data.npoints();
|
||||
|
||||
//verts
|
||||
@ -398,7 +401,7 @@ public class RenderUtils {
|
||||
|
||||
//indices
|
||||
IntBuffer indices = data.triangles(data.ntriangles() * 3);
|
||||
sphereMesh.bufferFaces(indices, data.ntriangles());
|
||||
sphereMesh.bufferFaces(indices, data.ntriangles() * 3);
|
||||
|
||||
//texture coords
|
||||
FloatBuffer texCoords = data.tcoords(numPoints * 2);
|
||||
@ -416,6 +419,93 @@ public class RenderUtils {
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a unit cylinder model
|
||||
* @return The model
|
||||
*/
|
||||
public static Model createUnitCube(){
|
||||
Model model = new Model();
|
||||
Mesh sphereMesh = new Mesh("cube");
|
||||
sphereMesh.generateVAO();
|
||||
|
||||
//buffer coords
|
||||
int numTriangles = 12;
|
||||
|
||||
//verts
|
||||
BufferUtils.createFloatBuffer(3 * 8);
|
||||
FloatBuffer verts = BufferUtils.createFloatBuffer(3 * 8);
|
||||
verts.put(new float[]{
|
||||
-0.5f,-0.5f,-0.5f,
|
||||
0.5f,-0.5f,-0.5f,
|
||||
-0.5f, 0.5f,-0.5f,
|
||||
0.5f, 0.5f,-0.5f,
|
||||
|
||||
-0.5f,-0.5f, 0.5f,
|
||||
0.5f,-0.5f, 0.5f,
|
||||
-0.5f, 0.5f, 0.5f,
|
||||
0.5f, 0.5f, 0.5f,
|
||||
});
|
||||
verts.flip();
|
||||
sphereMesh.bufferVertices(verts, 3);
|
||||
|
||||
//indices
|
||||
IntBuffer indices = BufferUtils.createIntBuffer(3*12);
|
||||
indices.put(new int[]{
|
||||
//Top
|
||||
2, 6, 7,
|
||||
2, 3, 7,
|
||||
|
||||
//Bottom
|
||||
0, 4, 5,
|
||||
0, 1, 5,
|
||||
|
||||
//Left
|
||||
0, 2, 6,
|
||||
0, 4, 6,
|
||||
|
||||
//Right
|
||||
1, 3, 7,
|
||||
1, 5, 7,
|
||||
|
||||
//Front
|
||||
0, 2, 3,
|
||||
0, 1, 3,
|
||||
|
||||
//Back
|
||||
4, 6, 7,
|
||||
4, 5, 7
|
||||
});
|
||||
indices.flip();
|
||||
sphereMesh.bufferFaces(indices, numTriangles * 3);
|
||||
|
||||
//texture coords
|
||||
FloatBuffer texCoords = BufferUtils.createFloatBuffer(2*8);
|
||||
texCoords.put(new float[]{
|
||||
0,0,
|
||||
1,0,
|
||||
0,1,
|
||||
1,1,
|
||||
|
||||
0,0,
|
||||
0,1,
|
||||
1,0,
|
||||
1,1,
|
||||
});
|
||||
texCoords.flip();
|
||||
sphereMesh.bufferTextureCoords(texCoords, 2);
|
||||
|
||||
//setup extra structures
|
||||
Material mat = new Material();
|
||||
mat.set_diffuse("Textures/color/transparent_teal.png");
|
||||
sphereMesh.setMaterial(mat);
|
||||
sphereMesh.setShader(ShaderProgram.smart_assemble_shader(false, true));
|
||||
GL40.glBindVertexArray(0);
|
||||
sphereMesh.setParent(model);
|
||||
model.getMeshes().add(sphereMesh);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static Model createBitmapDisplay(){
|
||||
@ -1470,173 +1560,6 @@ public class RenderUtils {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
public static Model createUnitCube(){
|
||||
Model rVal = new Model();
|
||||
Mesh m = new Mesh("cube");
|
||||
|
||||
// System.out.println(actualWidth + " " + actualHeight);
|
||||
|
||||
// System.out.println((actualWidth - 1) * (actualHeight - 1));
|
||||
|
||||
FloatBuffer vertices = BufferUtils.createFloatBuffer(8 * 3);
|
||||
FloatBuffer normals = BufferUtils.createFloatBuffer(8 * 3);
|
||||
IntBuffer faces = BufferUtils.createIntBuffer(6 * 2 * 3);
|
||||
FloatBuffer texture_coords = BufferUtils.createFloatBuffer(8 * 2);
|
||||
|
||||
//vertices
|
||||
//0,0,0
|
||||
vertices.put(0);
|
||||
vertices.put(0);
|
||||
vertices.put(0);
|
||||
//1,0,0
|
||||
vertices.put(1);
|
||||
vertices.put(0);
|
||||
vertices.put(0);
|
||||
//0,1,0
|
||||
vertices.put(0);
|
||||
vertices.put(1);
|
||||
vertices.put(0);
|
||||
//1,1,0
|
||||
vertices.put(1);
|
||||
vertices.put(1);
|
||||
vertices.put(0);
|
||||
//0,0,1
|
||||
vertices.put(0);
|
||||
vertices.put(0);
|
||||
vertices.put(1);
|
||||
//1,0,1
|
||||
vertices.put(1);
|
||||
vertices.put(0);
|
||||
vertices.put(1);
|
||||
//0,1,1
|
||||
vertices.put(0);
|
||||
vertices.put(1);
|
||||
vertices.put(1);
|
||||
//1,1,1
|
||||
vertices.put(1);
|
||||
vertices.put(1);
|
||||
vertices.put(1);
|
||||
|
||||
//normals
|
||||
//-1,-1,-1
|
||||
normals.put(-1);
|
||||
normals.put(-1);
|
||||
normals.put(-1);
|
||||
// 1,-1,-1
|
||||
normals.put( 1);
|
||||
normals.put(-1);
|
||||
normals.put(-1);
|
||||
//-1, 1,-1
|
||||
normals.put(-1);
|
||||
normals.put( 1);
|
||||
normals.put(-1);
|
||||
// 1, 1,-1
|
||||
normals.put( 1);
|
||||
normals.put( 1);
|
||||
normals.put(-1);
|
||||
//-1,-1, 1
|
||||
normals.put(-1);
|
||||
normals.put(-1);
|
||||
normals.put( 1);
|
||||
// 1,-1, 1
|
||||
normals.put( 1);
|
||||
normals.put(-1);
|
||||
normals.put( 1);
|
||||
//-1, 1, 1
|
||||
normals.put(-1);
|
||||
normals.put( 1);
|
||||
normals.put( 1);
|
||||
// 1, 1, 1
|
||||
normals.put( 1);
|
||||
normals.put( 1);
|
||||
normals.put( 1);
|
||||
|
||||
//faces
|
||||
//0,1,2
|
||||
faces.put(0);
|
||||
faces.put(1);
|
||||
faces.put(2);
|
||||
//1,2,3
|
||||
faces.put(1);
|
||||
faces.put(2);
|
||||
faces.put(3);
|
||||
//1,3,5
|
||||
faces.put(1);
|
||||
faces.put(3);
|
||||
faces.put(5);
|
||||
//3,5,7
|
||||
faces.put(3);
|
||||
faces.put(5);
|
||||
faces.put(7);
|
||||
//0,1,4
|
||||
faces.put(0);
|
||||
faces.put(1);
|
||||
faces.put(4);
|
||||
//1,4,5
|
||||
faces.put(1);
|
||||
faces.put(4);
|
||||
faces.put(5);
|
||||
//0,2,4
|
||||
faces.put(0);
|
||||
faces.put(2);
|
||||
faces.put(4);
|
||||
//2,4,6
|
||||
faces.put(2);
|
||||
faces.put(4);
|
||||
faces.put(6);
|
||||
//2,3,6
|
||||
faces.put(2);
|
||||
faces.put(3);
|
||||
faces.put(6);
|
||||
//3,6,7
|
||||
faces.put(3);
|
||||
faces.put(6);
|
||||
faces.put(7);
|
||||
//4,5,6
|
||||
faces.put(4);
|
||||
faces.put(5);
|
||||
faces.put(6);
|
||||
//5,6,7
|
||||
faces.put(5);
|
||||
faces.put(6);
|
||||
faces.put(7);
|
||||
|
||||
//texture
|
||||
for(int i = 0; i < 8 * 2; i++){
|
||||
texture_coords.put(0);
|
||||
}
|
||||
|
||||
|
||||
vertices.flip();
|
||||
normals.flip();
|
||||
faces.flip();
|
||||
texture_coords.flip();
|
||||
|
||||
m.generateVAO();
|
||||
//buffer vertices
|
||||
m.bufferVertices(vertices, 3);
|
||||
//buffer normals
|
||||
m.bufferNormals(normals, 3);
|
||||
//buffer faces
|
||||
m.bufferFaces(faces,12);
|
||||
//buffer texture coords
|
||||
m.bufferTextureCoords(texture_coords, 2);
|
||||
m.setShader(ShaderProgram.smart_assemble_shader(false,true));
|
||||
GL40.glBindVertexArray(0);
|
||||
m.setParent(rVal);
|
||||
|
||||
Material groundMat = new Material();
|
||||
Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png");
|
||||
groundMat.set_diffuse("/Textures/Ground/Dirt1.png");
|
||||
groundMat.set_specular("/Textures/Ground/Dirt1.png");
|
||||
m.setMaterial(groundMat);
|
||||
|
||||
rVal.getMeshes().add(m);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
public static ActorTextureMask generateVolumetricTextureMask(String meshName){
|
||||
List<Texture> textureList = new LinkedList<Texture>();
|
||||
textureList.add(Globals.renderingEngine.getVolumeFrontfaceTexture());
|
||||
|
||||
@ -187,8 +187,8 @@ public class DebugContentPipeline implements RenderPipeline {
|
||||
if((boolean)physicsEntity.getData(EntityDataStrings.DATA_STRING_DRAW) && physicsEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE) != null){
|
||||
CollidableTemplate template = (CollidableTemplate)physicsEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE);
|
||||
switch(template.getType()){
|
||||
case "CYLINDER":
|
||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/basic/geometry/unitcylinder.glb")) != null){
|
||||
case "CYLINDER": {
|
||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel(AssetDataStrings.UNITCYLINDER)) != null){
|
||||
//set color based on collision status, type, etc
|
||||
Texture texture = Globals.assetManager.fetchTexture("Textures/transparent_blue.png");
|
||||
if(texture != null){
|
||||
@ -204,9 +204,9 @@ public class DebugContentPipeline implements RenderPipeline {
|
||||
physicsGraphicsModel.setModelMatrix(modelTransformMatrix);
|
||||
physicsGraphicsModel.draw(renderPipelineState,openGLState);
|
||||
}
|
||||
break;
|
||||
case "CUBE":
|
||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/basic/geometry/unitcube.fbx")) != null){
|
||||
} break;
|
||||
case "CUBE": {
|
||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel(AssetDataStrings.UNITCUBE)) != null){
|
||||
//set color based on collision status, type, etc
|
||||
Texture texture = Globals.assetManager.fetchTexture("Textures/transparent_blue.png");
|
||||
if(texture != null){
|
||||
@ -224,51 +224,7 @@ public class DebugContentPipeline implements RenderPipeline {
|
||||
physicsGraphicsModel.setModelMatrix(modelTransformMatrix);
|
||||
physicsGraphicsModel.draw(renderPipelineState,openGLState);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(Collidable collidable : Globals.clientSceneWrapper.getCollisionEngine().getCollidables()){
|
||||
Entity physicsEntity = collidable.getParent();
|
||||
if((boolean)physicsEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){
|
||||
if(physicsEntity.containsKey(EntityDataStrings.COLLISION_ENTITY_TYPE_PLANE)){
|
||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/basic/geometry/unitplane.fbx")) != null){
|
||||
//set color based on collision status, type, etc
|
||||
Texture texture = Globals.assetManager.fetchTexture("Textures/transparent_blue.png");
|
||||
if(texture != null){
|
||||
texture.bind(openGLState);
|
||||
}
|
||||
Vector3d position = EntityUtils.getPosition(physicsEntity);
|
||||
Vector3f scale = EntityUtils.getScale(physicsEntity);
|
||||
Quaterniond rotation = EntityUtils.getRotation(physicsEntity);
|
||||
//calculate camera-modified vector3f
|
||||
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
||||
modelTransformMatrix.identity();
|
||||
modelTransformMatrix.translate(cameraModifiedPosition);
|
||||
modelTransformMatrix.rotate(rotation);
|
||||
modelTransformMatrix.scale(new Vector3d(scale));
|
||||
physicsGraphicsModel.setModelMatrix(modelTransformMatrix);
|
||||
physicsGraphicsModel.draw(renderPipelineState,openGLState);
|
||||
}
|
||||
} else if(physicsEntity.containsKey(EntityDataStrings.COLLISION_ENTITY_TYPE_CUBE)){
|
||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/basic/geometry/unitcube.fbx")) != null){
|
||||
//set color based on collision status, type, etc
|
||||
Texture texture = Globals.assetManager.fetchTexture("Textures/transparent_blue.png");
|
||||
if(texture != null){
|
||||
texture.bind(openGLState);
|
||||
}
|
||||
Vector3d position = EntityUtils.getPosition(physicsEntity);
|
||||
Vector3f scale = EntityUtils.getScale(physicsEntity);
|
||||
Quaterniond rotation = EntityUtils.getRotation(physicsEntity);
|
||||
//calculate camera-modified vector3f
|
||||
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
||||
modelTransformMatrix.identity();
|
||||
modelTransformMatrix.translate(cameraModifiedPosition);
|
||||
modelTransformMatrix.rotate(rotation);
|
||||
modelTransformMatrix.scale(new Vector3d(scale));
|
||||
physicsGraphicsModel.setModelMatrix(modelTransformMatrix);
|
||||
physicsGraphicsModel.draw(renderPipelineState,openGLState);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -282,7 +238,7 @@ public class DebugContentPipeline implements RenderPipeline {
|
||||
for(NavMesh mesh : Globals.navMeshManager.getMeshes()){
|
||||
for(NavShape shape : mesh.getNodes()){
|
||||
if(shape instanceof NavCube){
|
||||
if((shapeGraphicsModel = Globals.assetManager.fetchModel("Models/unitcube.fbx")) != null){
|
||||
if((shapeGraphicsModel = Globals.assetManager.fetchModel(AssetDataStrings.UNITCUBE)) != null){
|
||||
NavCube cube = (NavCube)shape;
|
||||
Vector3d position = new Vector3d(cube.getMinPoint()).add(cube.getMaxPoint()).mul(0.5);
|
||||
Vector3f scale = new Vector3f((float)(cube.getMaxPoint().x-cube.getMinPoint().x)/2,(float)(cube.getMaxPoint().y-cube.getMinPoint().y)/2,(float)(cube.getMaxPoint().z-cube.getMinPoint().z)/2);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user