package electrosphere.renderer.pipelines; import org.joml.Matrix4d; import org.joml.Quaterniond; import org.joml.Quaternionf; import org.joml.Vector3d; import org.joml.Vector3f; import org.lwjgl.opengl.GL40; import electrosphere.collision.collidable.Collidable; import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.hitbox.HitboxData; import electrosphere.entity.types.hitbox.HitboxUtils; import electrosphere.game.data.collidable.CollidableTemplate; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderingEngine; import electrosphere.renderer.model.Model; import electrosphere.server.pathfinding.navmesh.NavCube; import electrosphere.server.pathfinding.navmesh.NavMesh; import electrosphere.server.pathfinding.navmesh.NavShape; public class DebugContentPipeline implements RenderPipeline { @Override public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) { //bind screen fbo RenderingEngine.screenFramebuffer.bind(); openGLState.glDepthTest(true); openGLState.glDepthFunc(GL40.GL_LESS); GL40.glDepthMask(true); openGLState.glViewport(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); /// /// R E N D E R I N G S T U F F /// //Sets the background color. // // Set render pipeline state // renderPipelineState.setUseMeshShader(true); renderPipelineState.setBufferStandardUniforms(true); renderPipelineState.setBufferNonStandardUniforms(false); renderPipelineState.setUseMaterial(true); renderPipelineState.setUseShadowMap(true); renderPipelineState.setUseBones(true); renderPipelineState.setUseLight(true); Matrix4d modelTransformMatrix = new Matrix4d(); if(Globals.userSettings.graphicsDebugDrawCollisionSpheres()){ for(Entity currentHitbox : Globals.clientHitboxManager.getAllHitboxes()){ if((boolean)currentHitbox.getData(EntityDataStrings.DATA_STRING_DRAW)){ Model hitboxModel; HitboxData data = HitboxUtils.getHitboxData(currentHitbox); if(data.isActive()){ if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)){ if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere.fbx")) != null){ Vector3d position = EntityUtils.getPosition(currentHitbox); //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.translate(-0.25f, 0.0f, 0.5f); //center sphere modelTransformMatrix.scale(data.getRadius() * 2); hitboxModel.setModelMatrix(modelTransformMatrix); hitboxModel.draw(renderPipelineState,openGLState); } } else if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT)){ if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_1.fbx")) != null){ Vector3d position = EntityUtils.getPosition(currentHitbox); //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.translate(-0.25f, 0.0f, 0.5f); //center sphere modelTransformMatrix.scale(data.getRadius() * 2); hitboxModel.setModelMatrix(modelTransformMatrix); hitboxModel.draw(renderPipelineState,openGLState); } } } else { if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_grey.fbx")) != null){ Vector3d position = EntityUtils.getPosition(currentHitbox); modelTransformMatrix.identity(); modelTransformMatrix.translate(new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); // modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere modelTransformMatrix.scale(data.getRadius() * 2); hitboxModel.setModelMatrix(modelTransformMatrix); hitboxModel.draw(renderPipelineState,openGLState); } } } } } if(Globals.userSettings.graphicsDebugDrawPhysicsObjects()){ Model physicsGraphicsModel; for(Collidable collidable : Globals.clientSceneWrapper.getCollisionEngine().getCollidables()){ Entity physicsEntity = collidable.getParent(); 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/unitcylinder.fbx")) != null){ Vector3d position = EntityUtils.getPosition(physicsEntity); //calculate camera-modified vector3f Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); modelTransformMatrix.rotate(EntityUtils.getRotation(physicsEntity)); // modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere modelTransformMatrix.scale(template.getDimension1(),template.getDimension2() * 0.5,template.getDimension3()); physicsGraphicsModel.setModelMatrix(modelTransformMatrix); physicsGraphicsModel.draw(renderPipelineState,openGLState); } break; case "CUBE": if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcube.fbx")) != null){ 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).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); modelTransformMatrix.rotate(rotation); // modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere modelTransformMatrix.scale(template.getDimension1(),template.getDimension2(),template.getDimension3()); 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/unitplane.fbx")) != null){ 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.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere 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/unitcube.fbx")) != null){ 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.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere modelTransformMatrix.scale(new Vector3d(scale)); physicsGraphicsModel.setModelMatrix(modelTransformMatrix); physicsGraphicsModel.draw(renderPipelineState,openGLState); } } } } } if(Globals.userSettings.graphicsDebugDrawNavmesh()){ Model shapeGraphicsModel; for(NavMesh mesh : Globals.navMeshManager.getMeshes()){ for(NavShape shape : mesh.getNodes()){ if(shape instanceof NavCube){ if((shapeGraphicsModel = Globals.assetManager.fetchModel("Models/unitcube.fbx")) != 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); Quaternionf rotation = new Quaternionf(); //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.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere modelTransformMatrix.scale(new Vector3d(scale)); shapeGraphicsModel.setModelMatrix(modelTransformMatrix); shapeGraphicsModel.draw(renderPipelineState,openGLState); } } } } } } }