package electrosphere.client.fluid.cells; import org.joml.Vector3d; import org.joml.Vector3i; import org.ode4j.ode.DBody; import electrosphere.client.fluid.cache.FluidChunkData; import electrosphere.collision.CollisionEngine; import electrosphere.engine.Globals; import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; import electrosphere.entity.types.fluid.FluidChunk; import electrosphere.renderer.shader.ShaderProgram; import electrosphere.renderer.texture.Texture; /** * * @author satellite */ public class FluidDrawCell { //the position of the draw cell in world coordinates Vector3i worldPos; FluidChunkData data; Entity modelEntity; ShaderProgram program; DBody physicsObject; static Texture groundTextureOne = new Texture("/Textures/Ground/Dirt1.png"); static Texture groundTextureTwo = new Texture("/Textures/Ground/Dirt1.png"); static Texture groundTextureThree = new Texture("/Textures/Ground/Dirt1.png"); static Texture groundTextureFour = new Texture("/Textures/Ground/Dirt1.png"); static { // groundTextureOne = new Texture("/Textures/Ground/GrassTileable.png"); // groundTextureTwo = new Texture("/Textures/Ground/Dirt1.png"); // groundTextureThree = new Texture("/Textures/Ground/Dirt1.png"); // groundTextureFour = new Texture("/Textures/Ground/Dirt1.png"); } FluidDrawCell(){ } /** * Constructs a drawcell object */ public static FluidDrawCell generateFluidCell( Vector3i worldPos, FluidChunkData data, ShaderProgram program ){ FluidDrawCell rVal = new FluidDrawCell(); rVal.worldPos = worldPos; rVal.program = program; rVal.data = data; return rVal; } /** * Generates a drawable entity based on this chunk */ public void generateDrawableEntity(){ if(modelEntity != null){ Globals.clientScene.deregisterEntity(modelEntity); } modelEntity = FluidChunk.clientCreateFluidChunkEntity(data.getVoxelWeight(), data.getVoxelType()); ClientEntityUtils.initiallyPositionEntity(modelEntity, getRealPos()); } protected Vector3d getRealPos(){ return new Vector3d( worldPos.x * FluidChunkData.CHUNK_SIZE, worldPos.y * FluidChunkData.CHUNK_SIZE, worldPos.z * FluidChunkData.CHUNK_SIZE ); } /** * Destroys a drawcell including its physics */ public void destroy(){ CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); collisionEngine.destroyEntityThatHasPhysics(modelEntity); EntityUtils.cleanUpEntity(modelEntity); } /** * Gets the current chunk data for this draw cell * @return The chunk data */ public FluidChunkData getData(){ return data; } }