package electrosphere.client.terrain.cells; import org.joml.Vector3d; import org.joml.Vector3i; import org.ode4j.ode.DBody; import electrosphere.client.terrain.cache.ChunkData; import electrosphere.collision.CollisionEngine; import electrosphere.engine.Globals; import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; import electrosphere.entity.types.terrain.TerrainChunk; import electrosphere.renderer.ShaderProgram; import electrosphere.renderer.texture.Texture; import electrosphere.server.datacell.Realm; /** * * @author satellite */ public class DrawCell { //the position of the draw cell in world coordinates Vector3i worldPos; ChunkData 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"); } DrawCell(){ } /** * Constructs a drawcell object */ public static DrawCell generateTerrainCell( Vector3i worldPos, ChunkData data, ShaderProgram program ){ DrawCell rVal = new DrawCell(); rVal.worldPos = worldPos; rVal.program = program; rVal.data = data; System.out.println("Create cell"); return rVal; } /** * Generates a drawable entity based on this chunk */ public void generateDrawableEntity(){ if(modelEntity != null){ Globals.clientScene.deregisterEntity(modelEntity); } modelEntity = TerrainChunk.clientCreateTerrainChunkEntity(data.getVoxelWeight(), data.getVoxelType(), 0); // TerrainChunk.createTerrainChunkEntity(); // Model terrainModel = RenderUtils.createMinimizedTerrainModelPrecomputedShader(heightmap, texturemap, program, stride); // Mesh terrainMesh = terrainModel.meshes.get(0); // List textureList = new LinkedList(); // textureList.add(groundTextureOne); // textureList.add(groundTextureTwo); // textureList.add(groundTextureThree); // textureList.add(groundTextureFour); // List uniformList = new LinkedList(); // uniformList.add("groundTextures[0]"); // uniformList.add("groundTextures[1]"); // uniformList.add("groundTextures[2]"); // uniformList.add("groundTextures[3]"); // String terrainModelPath = Globals.assetManager.registerModel(terrainModel); // modelEntity = EntityCreationUtils.createClientSpatialEntity(); // EntityCreationUtils.makeEntityDrawable(modelEntity, terrainModelPath); // EntityUtils.getActor(modelEntity).addTextureMask(new ActorTextureMask("terrain",textureList,uniformList)); // modelEntity.putData(EntityDataStrings.TERRAIN_IS_TERRAIN, true); // modelEntity.putData(EntityDataStrings.DRAW_CAST_SHADOW, true); // LoggerInterface.loggerRenderer.INFO("New cell @ " + cellX * dynamicInterpolationRatio + "," + cellY * dynamicInterpolationRatio); // EntityUtils.getPosition(modelEntity).set(getRealPos()); for(Vector3i position : data.getModifiedPositions()){ Globals.clientFoliageManager.invalidateCell(worldPos, position); } data.resetModifiedPositions(); ClientEntityUtils.initiallyPositionEntity(modelEntity, getRealPos()); } protected Vector3d getRealPos(){ return new Vector3d( worldPos.x * ChunkData.CHUNK_SIZE, worldPos.y * ChunkData.CHUNK_SIZE, worldPos.z * ChunkData.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 ChunkData getData(){ return data; } }