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" : [
|
"movementSystems" : [
|
||||||
{
|
{
|
||||||
"type" : "GROUND",
|
"type" : "GROUND",
|
||||||
"acceleration" : 5000.0,
|
"acceleration" : 100.0,
|
||||||
"maxVelocity" : 500.5,
|
"maxVelocity" : 50.5,
|
||||||
"strafeMultiplier" : 1.0,
|
"strafeMultiplier" : 1.0,
|
||||||
"backpedalMultiplier" : 0.5,
|
"backpedalMultiplier" : 0.5,
|
||||||
"footstepFirstAudioOffset" : 0.2,
|
"footstepFirstAudioOffset" : 0.2,
|
||||||
@ -167,7 +167,7 @@
|
|||||||
{
|
{
|
||||||
"type" : "JUMP",
|
"type" : "JUMP",
|
||||||
"jumpFrames" : 3,
|
"jumpFrames" : 3,
|
||||||
"jumpForce" : 700,
|
"jumpForce" : 20,
|
||||||
"animationJump" : {
|
"animationJump" : {
|
||||||
"nameThirdPerson" : "Jump",
|
"nameThirdPerson" : "Jump",
|
||||||
"nameFirstPerson" : "Jump",
|
"nameFirstPerson" : "Jump",
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
],
|
],
|
||||||
"collidable": {
|
"collidable": {
|
||||||
"type" : "CUBE",
|
"type" : "CUBE",
|
||||||
"mass": 10.0,
|
"mass": 1.0,
|
||||||
"rollingFriction": 100.0,
|
"rollingFriction": 100.0,
|
||||||
"linearFriction": 100.0,
|
"linearFriction": 100.0,
|
||||||
"dimension1" : 2.0,
|
"dimension1" : 2.0,
|
||||||
@ -23,7 +23,7 @@
|
|||||||
"rotZ": 0,
|
"rotZ": 0,
|
||||||
"rotW": 1,
|
"rotW": 1,
|
||||||
"offsetX" : 0,
|
"offsetX" : 0,
|
||||||
"offsetY" : 0.05,
|
"offsetY" : 0,
|
||||||
"offsetZ" : 0
|
"offsetZ" : 0
|
||||||
},
|
},
|
||||||
"tokens": [
|
"tokens": [
|
||||||
|
|||||||
@ -747,6 +747,9 @@ Data cleanup
|
|||||||
Delete Structure entity type
|
Delete Structure entity type
|
||||||
Physics work
|
Physics work
|
||||||
|
|
||||||
|
(09/13/2024)
|
||||||
|
Physics debugging
|
||||||
|
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
|
|||||||
@ -233,13 +233,9 @@ public class CollisionBodyCreation {
|
|||||||
public static DBody generateBodyFromTerrainData(CollisionEngine collisionEngine, TerrainChunkData data, long categoryBits){
|
public static DBody generateBodyFromTerrainData(CollisionEngine collisionEngine, TerrainChunkData data, long categoryBits){
|
||||||
DBody body = null;
|
DBody body = null;
|
||||||
|
|
||||||
//create data
|
float[] vertices = new float[data.getVertices().size()];
|
||||||
int numberTriangles = data.getFaceElements().size() / 3;
|
|
||||||
int numberVertices = data.getVertices().size() / 3;
|
|
||||||
|
|
||||||
float[] vertices = new float[numberVertices * 3];
|
|
||||||
int vertexInserterPos = 0;
|
int vertexInserterPos = 0;
|
||||||
int[] indices = new int[numberTriangles * 3];
|
int[] indices = new int[data.getFaceElements().size()];
|
||||||
int indexInserterPos = 0;
|
int indexInserterPos = 0;
|
||||||
|
|
||||||
for(float vertexValue : data.getVertices()){
|
for(float vertexValue : data.getVertices()){
|
||||||
@ -251,11 +247,13 @@ public class CollisionBodyCreation {
|
|||||||
indices[indexInserterPos] = element;
|
indices[indexInserterPos] = element;
|
||||||
indexInserterPos++;
|
indexInserterPos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//create trimesh
|
//create trimesh
|
||||||
if(vertices.length > 0){
|
if(vertices.length > 0){
|
||||||
DTriMesh triMesh = collisionEngine.createTrimeshGeom(vertices,indices,categoryBits);
|
DTriMesh triMesh = collisionEngine.createTrimeshGeom(vertices,indices,categoryBits);
|
||||||
body = collisionEngine.createDBody(triMesh);
|
body = collisionEngine.createDBody(triMesh);
|
||||||
|
collisionEngine.setKinematic(body);
|
||||||
|
collisionEngine.setGravityMode(body, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return body;
|
return body;
|
||||||
|
|||||||
@ -87,7 +87,7 @@ public class CollisionEngine {
|
|||||||
private static Semaphore spaceLock = new Semaphore(1);
|
private static Semaphore spaceLock = new Semaphore(1);
|
||||||
private DJointGroup contactgroup;
|
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
|
//The list of dbodies ode should be tracking
|
||||||
List<DBody> bodies = new ArrayList<DBody>();
|
List<DBody> bodies = new ArrayList<DBody>();
|
||||||
@ -116,11 +116,11 @@ public class CollisionEngine {
|
|||||||
public CollisionEngine(){
|
public CollisionEngine(){
|
||||||
world = OdeHelper.createWorld();
|
world = OdeHelper.createWorld();
|
||||||
space = OdeHelper.createBHVSpace(Collidable.TYPE_STATIC_BIT);
|
space = OdeHelper.createBHVSpace(Collidable.TYPE_STATIC_BIT);
|
||||||
world.setGravity(0,-GRAVITY_MAGNITUDE,0);
|
world.setGravity(0,-0.5,0);
|
||||||
world.setAutoDisableFlag(true);
|
// world.setAutoDisableFlag(true);
|
||||||
// world.setContactMaxCorrectingVel(0.1);
|
// world.setContactMaxCorrectingVel(0.1);
|
||||||
world.setContactSurfaceLayer(0.001);
|
// world.setContactSurfaceLayer(0.001);
|
||||||
world.setCFM(0.00000001);
|
world.setCFM(1e-5);
|
||||||
|
|
||||||
//base plane
|
//base plane
|
||||||
OdeHelper.createPlane(space, 0, 1, 0, 0);
|
OdeHelper.createPlane(space, 0, 1, 0, 0);
|
||||||
@ -262,18 +262,20 @@ public class CollisionEngine {
|
|||||||
public void simulatePhysics(float time){
|
public void simulatePhysics(float time){
|
||||||
Globals.profiler.beginCpuSample("physics");
|
Globals.profiler.beginCpuSample("physics");
|
||||||
spaceLock.acquireUninterruptibly();
|
spaceLock.acquireUninterruptibly();
|
||||||
Globals.profiler.beginCpuSample("collide");
|
for(int i = 0; i < 5; i++){
|
||||||
OdeHelper.spaceCollide(space, 0, nearCallback);
|
Globals.profiler.beginCpuSample("collide");
|
||||||
Globals.profiler.endCpuSample();
|
OdeHelper.spaceCollide(space, 0, nearCallback);
|
||||||
// space.collide2(space, collisionWorldData, nearCallback);
|
Globals.profiler.endCpuSample();
|
||||||
|
// space.collide2(space, collisionWorldData, nearCallback);
|
||||||
|
|
||||||
//simulate physics
|
//simulate physics
|
||||||
Globals.profiler.beginCpuSample("step physics");
|
Globals.profiler.beginCpuSample("step physics");
|
||||||
world.quickStep(Timekeeper.ENGINE_STEP_SIZE);
|
world.quickStep(Timekeeper.ENGINE_STEP_SIZE);
|
||||||
Globals.profiler.endCpuSample();
|
Globals.profiler.endCpuSample();
|
||||||
|
|
||||||
// remove all contact joints
|
// remove all contact joints
|
||||||
contactgroup.empty();
|
contactgroup.empty();
|
||||||
|
}
|
||||||
spaceLock.release();
|
spaceLock.release();
|
||||||
Globals.profiler.endCpuSample();
|
Globals.profiler.endCpuSample();
|
||||||
}
|
}
|
||||||
@ -360,17 +362,18 @@ public class CollisionEngine {
|
|||||||
for (int i=0; i<numc; i++) {
|
for (int i=0; i<numc; i++) {
|
||||||
DContact contact = contacts.get(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
|
//special code for ray casting
|
||||||
if (o1 instanceof DRay || o2 instanceof DRay){
|
if (o1 instanceof DRay || o2 instanceof DRay){
|
||||||
DVector3 end = new DVector3();
|
DVector3 end = new DVector3();
|
||||||
end.eqSum( contact.geom.pos, contact.geom.normal, contact.geom.depth );
|
end.eqSum( contact.geom.pos, contact.geom.normal, contact.geom.depth );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//add contact to contact group
|
||||||
|
DJoint c = OdeHelper.createContactJoint(world,contactgroup,contact);
|
||||||
|
c.attach(b1,b2);
|
||||||
|
|
||||||
// Use the default collision resolution
|
// Use the default collision resolution
|
||||||
if(collisionResolutionCallback == null) {
|
if(collisionResolutionCallback == null) {
|
||||||
resolveCollision(
|
resolveCollision(
|
||||||
@ -671,22 +674,6 @@ public class CollisionEngine {
|
|||||||
ServerPhysicsSyncTree.detachTree(e, ServerPhysicsSyncTree.getTree(e));
|
ServerPhysicsSyncTree.detachTree(e, ServerPhysicsSyncTree.getTree(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
* Creates a trimesh from a given set of vertices and indices
|
||||||
@ -698,7 +685,14 @@ public class CollisionEngine {
|
|||||||
spaceLock.acquireUninterruptibly();
|
spaceLock.acquireUninterruptibly();
|
||||||
DTriMeshData data = OdeHelper.createTriMeshData();
|
DTriMeshData data = OdeHelper.createTriMeshData();
|
||||||
data.build(verts, indices);
|
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);
|
rVal.setCategoryBits(categoryBits);
|
||||||
spaceLock.release();
|
spaceLock.release();
|
||||||
return rVal;
|
return rVal;
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import org.joml.Quaterniond;
|
|||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
import org.ode4j.ode.DBody;
|
import org.ode4j.ode.DBody;
|
||||||
import org.ode4j.ode.DGeom;
|
import org.ode4j.ode.DGeom;
|
||||||
import org.ode4j.ode.DTriMesh;
|
|
||||||
|
|
||||||
import electrosphere.collision.collidable.Collidable;
|
import electrosphere.collision.collidable.Collidable;
|
||||||
import electrosphere.engine.Globals;
|
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
|
* [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
|
* @param terrain The entity
|
||||||
@ -500,8 +423,6 @@ public class PhysicsEntityUtils {
|
|||||||
*/
|
*/
|
||||||
public static DBody clientAttachTerrainChunkRigidBody(Entity terrain, TerrainChunkData data){
|
public static DBody clientAttachTerrainChunkRigidBody(Entity terrain, TerrainChunkData data){
|
||||||
DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(Globals.clientSceneWrapper.getCollisionEngine(), data,Collidable.TYPE_STATIC_BIT);
|
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));
|
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){
|
public static DBody serverAttachTerrainChunkRigidBody(Entity terrain, TerrainChunkData data){
|
||||||
Realm terrainRealm = Globals.realmManager.getEntityRealm(terrain);
|
Realm terrainRealm = Globals.realmManager.getEntityRealm(terrain);
|
||||||
DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(terrainRealm.getCollisionEngine(),data,Collidable.TYPE_STATIC_BIT);
|
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));
|
terrainRealm.getCollisionEngine().registerCollisionObject(terrainBody, new Collidable(terrain,Collidable.TYPE_TERRAIN, false));
|
||||||
PhysicsEntityUtils.setDBody(terrain,terrainBody);
|
PhysicsEntityUtils.setDBody(terrain,terrainBody);
|
||||||
|
|||||||
@ -77,7 +77,7 @@ public class SurfaceParams {
|
|||||||
*/
|
*/
|
||||||
public SurfaceParams(){
|
public SurfaceParams(){
|
||||||
mode = OdeConstants.dContactApprox1 & OdeConstants.dContactRolling & OdeConstants.dContactBounce;
|
mode = OdeConstants.dContactApprox1 & OdeConstants.dContactRolling & OdeConstants.dContactBounce;
|
||||||
mu = 10.0;
|
mu = 0.01;
|
||||||
rho = 10.0;
|
rho = 10.0;
|
||||||
rho2 = 10.0;
|
rho2 = 10.0;
|
||||||
rhoN = 10.0;
|
rhoN = 10.0;
|
||||||
|
|||||||
@ -608,6 +608,7 @@ public class Globals {
|
|||||||
//init models
|
//init models
|
||||||
assetManager.registerModelToSpecificString(RenderUtils.createUnitsphere(), AssetDataStrings.UNITSPHERE);
|
assetManager.registerModelToSpecificString(RenderUtils.createUnitsphere(), AssetDataStrings.UNITSPHERE);
|
||||||
assetManager.registerModelToSpecificString(RenderUtils.createUnitCylinder(), AssetDataStrings.UNITCYLINDER);
|
assetManager.registerModelToSpecificString(RenderUtils.createUnitCylinder(), AssetDataStrings.UNITCYLINDER);
|
||||||
|
assetManager.registerModelToSpecificString(RenderUtils.createUnitCube(), AssetDataStrings.UNITCUBE);
|
||||||
assetManager.addModelPathToQueue("Models/basic/geometry/SmallCube.fbx");
|
assetManager.addModelPathToQueue("Models/basic/geometry/SmallCube.fbx");
|
||||||
assetManager.addModelPathToQueue("Models/basic/geometry/unitcapsule.glb");
|
assetManager.addModelPathToQueue("Models/basic/geometry/unitcapsule.glb");
|
||||||
assetManager.addModelPathToQueue("Models/basic/geometry/unitplane.fbx");
|
assetManager.addModelPathToQueue("Models/basic/geometry/unitplane.fbx");
|
||||||
|
|||||||
@ -14,6 +14,7 @@ public class AssetDataStrings {
|
|||||||
*/
|
*/
|
||||||
public static final String UNITSPHERE = "unitSphere";
|
public static final String UNITSPHERE = "unitSphere";
|
||||||
public static final String UNITCYLINDER = "unitCylinder";
|
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;
|
public static final int SIM_FRAME_HARDCAP = 3;
|
||||||
|
|
||||||
//step interval time size (for physics)
|
//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
|
//buffer coords
|
||||||
ParShapesMesh data = ParShapes.par_shapes_create_cylinder(10, 2);
|
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();
|
int numPoints = data.npoints();
|
||||||
|
|
||||||
//verts
|
//verts
|
||||||
@ -398,7 +401,7 @@ public class RenderUtils {
|
|||||||
|
|
||||||
//indices
|
//indices
|
||||||
IntBuffer indices = data.triangles(data.ntriangles() * 3);
|
IntBuffer indices = data.triangles(data.ntriangles() * 3);
|
||||||
sphereMesh.bufferFaces(indices, data.ntriangles());
|
sphereMesh.bufferFaces(indices, data.ntriangles() * 3);
|
||||||
|
|
||||||
//texture coords
|
//texture coords
|
||||||
FloatBuffer texCoords = data.tcoords(numPoints * 2);
|
FloatBuffer texCoords = data.tcoords(numPoints * 2);
|
||||||
@ -416,6 +419,93 @@ public class RenderUtils {
|
|||||||
return model;
|
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
|
@Deprecated
|
||||||
public static Model createBitmapDisplay(){
|
public static Model createBitmapDisplay(){
|
||||||
@ -1469,173 +1559,6 @@ public class RenderUtils {
|
|||||||
}
|
}
|
||||||
return rVal;
|
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){
|
public static ActorTextureMask generateVolumetricTextureMask(String meshName){
|
||||||
List<Texture> textureList = new LinkedList<Texture>();
|
List<Texture> textureList = new LinkedList<Texture>();
|
||||||
|
|||||||
@ -187,8 +187,8 @@ public class DebugContentPipeline implements RenderPipeline {
|
|||||||
if((boolean)physicsEntity.getData(EntityDataStrings.DATA_STRING_DRAW) && physicsEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE) != null){
|
if((boolean)physicsEntity.getData(EntityDataStrings.DATA_STRING_DRAW) && physicsEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE) != null){
|
||||||
CollidableTemplate template = (CollidableTemplate)physicsEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE);
|
CollidableTemplate template = (CollidableTemplate)physicsEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE);
|
||||||
switch(template.getType()){
|
switch(template.getType()){
|
||||||
case "CYLINDER":
|
case "CYLINDER": {
|
||||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/basic/geometry/unitcylinder.glb")) != null){
|
if((physicsGraphicsModel = Globals.assetManager.fetchModel(AssetDataStrings.UNITCYLINDER)) != null){
|
||||||
//set color based on collision status, type, etc
|
//set color based on collision status, type, etc
|
||||||
Texture texture = Globals.assetManager.fetchTexture("Textures/transparent_blue.png");
|
Texture texture = Globals.assetManager.fetchTexture("Textures/transparent_blue.png");
|
||||||
if(texture != null){
|
if(texture != null){
|
||||||
@ -204,9 +204,9 @@ public class DebugContentPipeline implements RenderPipeline {
|
|||||||
physicsGraphicsModel.setModelMatrix(modelTransformMatrix);
|
physicsGraphicsModel.setModelMatrix(modelTransformMatrix);
|
||||||
physicsGraphicsModel.draw(renderPipelineState,openGLState);
|
physicsGraphicsModel.draw(renderPipelineState,openGLState);
|
||||||
}
|
}
|
||||||
break;
|
} break;
|
||||||
case "CUBE":
|
case "CUBE": {
|
||||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/basic/geometry/unitcube.fbx")) != null){
|
if((physicsGraphicsModel = Globals.assetManager.fetchModel(AssetDataStrings.UNITCUBE)) != null){
|
||||||
//set color based on collision status, type, etc
|
//set color based on collision status, type, etc
|
||||||
Texture texture = Globals.assetManager.fetchTexture("Textures/transparent_blue.png");
|
Texture texture = Globals.assetManager.fetchTexture("Textures/transparent_blue.png");
|
||||||
if(texture != null){
|
if(texture != null){
|
||||||
@ -224,51 +224,7 @@ public class DebugContentPipeline implements RenderPipeline {
|
|||||||
physicsGraphicsModel.setModelMatrix(modelTransformMatrix);
|
physicsGraphicsModel.setModelMatrix(modelTransformMatrix);
|
||||||
physicsGraphicsModel.draw(renderPipelineState,openGLState);
|
physicsGraphicsModel.draw(renderPipelineState,openGLState);
|
||||||
}
|
}
|
||||||
break;
|
} 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,7 +238,7 @@ public class DebugContentPipeline implements RenderPipeline {
|
|||||||
for(NavMesh mesh : Globals.navMeshManager.getMeshes()){
|
for(NavMesh mesh : Globals.navMeshManager.getMeshes()){
|
||||||
for(NavShape shape : mesh.getNodes()){
|
for(NavShape shape : mesh.getNodes()){
|
||||||
if(shape instanceof NavCube){
|
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;
|
NavCube cube = (NavCube)shape;
|
||||||
Vector3d position = new Vector3d(cube.getMinPoint()).add(cube.getMaxPoint()).mul(0.5);
|
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);
|
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