85 lines
3.7 KiB
Java

package org.atriaSoft.gameEngine.map;
import java.util.ArrayList;
import java.util.List;
import org.atriaSoft.etk.Uri;
import org.atriaSoft.etk.math.Transform3D;
import org.atriaSoft.etk.math.Vector3i;
import org.atriaSoft.etk.math.Vector3f;
import org.atriaSoft.gameEngine.Entity;
import org.atriaSoft.gameEngine.Environement;
import org.atriaSoft.gameEngine.Light;
import org.atriaSoft.gameEngine.Material;
import org.atriaSoft.gameEngine.components.ComponentLight;
import org.atriaSoft.gameEngine.components.ComponentLightSun;
import org.atriaSoft.gameEngine.components.ComponentMaterials;
import org.atriaSoft.gameEngine.components.ComponentPhysics;
import org.atriaSoft.gameEngine.components.ComponentPosition;
import org.atriaSoft.gameEngine.components.ComponentRenderTexturedMaterialsDynamicMeshs;
import org.atriaSoft.gameEngine.components.ComponentRenderTexturedMaterialsStaticMeshs;
import org.atriaSoft.gameEngine.components.ComponentRenderTexturedStaticMesh;
import org.atriaSoft.gameEngine.components.ComponentStaticMesh;
import org.atriaSoft.gameEngine.components.ComponentStaticMeshs;
import org.atriaSoft.gameEngine.components.ComponentTexture;
import org.atriaSoft.gameEngine.components.ComponentTextures;
import org.atriaSoft.gameEngine.engines.EngineLight;
import org.atriaSoft.gameEngine.engines.EngineMap;
import org.atriaSoft.gameEngine.physics.PhysicBox;
import org.atriaSoft.gameEngine.physics.PhysicMapVoxel;
public class MapVoxel extends EngineMap {
//List<VoxelChunk> listOfChunks = new ArrayList<VoxelChunk>();
ComponentTextures textures;
public MapVoxel(Environement env){
super(env);
// for basic test ... after generate dynamic ...
textures = new ComponentTextures();
}
public void init() {
textures.setTexture("stone", new Uri("DATA", "blocks/stone.png"));
textures.setTexture("grass", new Uri("DATA", "blocks/dirt_podzol_top.png"));
textures.setTexture("dirt", new Uri("DATA", "blocks/dirt.png"));
textures.setTexture("watter", new Uri("DATA", "blocks/water_static.png"));
textures.setTexture("unbreakable", new Uri("DATA", "blocks/stone_diorite.png"));
// addNewChunk(new Vector3i(-1,-1, 0));
// addNewChunk(new Vector3i(-1, 0, 0));
// addNewChunk(new Vector3i(-1, 1, 0));
// addNewChunk(new Vector3i( 0,-1, 0));
addNewChunk(new Vector3i( 0, 0, 0));
// addNewChunk(new Vector3i( 0, 1, 0));
// addNewChunk(new Vector3i( 1,-1, 0));
// addNewChunk(new Vector3i( 1, 0, 0));
// addNewChunk(new Vector3i( 1, 1, 0));
}
private void addNewChunk(Vector3i position) {
// simple sun to have a global light ...
Entity tmpEntity = new Entity(this.env);
tmpEntity.addComponent(new ComponentPosition(new Transform3D(new Vector3f(position.x,position.y,0))));
VoxelChunk tmpVoxelChunk = new VoxelChunk(this, position);
tmpEntity.addComponent(tmpVoxelChunk);
ComponentDynamicMeshsVoxelMap mesh = new ComponentDynamicMeshsVoxelMap(tmpVoxelChunk);
tmpEntity.addComponent(mesh);
tmpEntity.addComponent(textures);
ComponentMaterials materials = new ComponentMaterials();
materials.setMaterial("stone", new Material());
materials.setMaterial("grass", new Material());
materials.setMaterial("dirt", new Material());
materials.setMaterial("watter", new Material());
materials.setMaterial("unbreakable", new Material());
tmpEntity.addComponent(materials);
tmpEntity.addComponent(new ComponentRenderTexturedMaterialsDynamicMeshs(
new Uri("DATA", "basicMaterial.vert"),
new Uri("DATA", "basicMaterial.frag"),
(EngineLight)env.getEngine(EngineLight.ENGINE_NAME)));
ComponentPhysics physics = new ComponentPhysics(false);
PhysicMapVoxel box = new PhysicMapVoxel(tmpVoxelChunk);
physics.addShape(box);
tmpEntity.addComponent(physics);
this.env.addEntity(tmpEntity);
}
}