use of net.drewke.tdme.engine.Transformations in project tdme by andreasdr.
the class LevelFileExport method export.
/**
* Exports a level to a TDME level file
* @param file name
*/
public static void export(String fileName, LevelEditorLevel level) throws Exception {
FileOutputStream fos = null;
PrintStream fops = null;
level.setFileName(new File(fileName).getName());
try {
// generate json
LevelEditorEntityLibrary entityLibrary = level.getEntityLibrary();
JSONObject jRoot = new JSONObject();
jRoot.put("version", "0.99");
jRoot.put("ro", level.getRotationOrder().toString());
JSONArray jLights = new JSONArray();
for (int i = 0; i < level.getLightCount(); i++) {
LevelEditorLight light = level.getLightAt(i);
JSONObject jLight = new JSONObject();
jLight.put("id", i);
jLight.put("ar", light.getAmbient().getRed());
jLight.put("ag", light.getAmbient().getGreen());
jLight.put("ab", light.getAmbient().getBlue());
jLight.put("aa", light.getAmbient().getAlpha());
jLight.put("dr", light.getDiffuse().getRed());
jLight.put("dg", light.getDiffuse().getGreen());
jLight.put("db", light.getDiffuse().getBlue());
jLight.put("da", light.getDiffuse().getAlpha());
jLight.put("sr", light.getSpecular().getRed());
jLight.put("sg", light.getSpecular().getGreen());
jLight.put("sb", light.getSpecular().getBlue());
jLight.put("sa", light.getSpecular().getAlpha());
jLight.put("px", light.getPosition().getX());
jLight.put("py", light.getPosition().getY());
jLight.put("pz", light.getPosition().getZ());
jLight.put("pw", light.getPosition().getW());
jLight.put("stx", light.getSpotTo().getX());
jLight.put("sty", light.getSpotTo().getY());
jLight.put("stz", light.getSpotTo().getZ());
jLight.put("sdx", light.getSpotDirection().getX());
jLight.put("sdy", light.getSpotDirection().getY());
jLight.put("sdz", light.getSpotDirection().getZ());
jLight.put("se", light.getSpotExponent());
jLight.put("sco", light.getSpotCutOff());
jLight.put("ca", light.getConstantAttenuation());
jLight.put("la", light.getLinearAttenuation());
jLight.put("qa", light.getQuadraticAttenuation());
jLight.put("e", light.isEnabled());
jLights.put(jLight);
}
jRoot.put("lights", jLights);
JSONArray jEntityLibrary = new JSONArray();
for (int i = 0; i < entityLibrary.getEntityCount(); i++) {
LevelEditorEntity entity = entityLibrary.getEntityAt(i);
JSONObject jModel = new JSONObject();
jModel.put("id", entity.getId());
jModel.put("type", entity.getType());
jModel.put("name", entity.getName());
jModel.put("descr", entity.getDescription());
jModel.put("entity", ModelMetaDataFileExport.exportToJSON(entity));
jEntityLibrary.put(jModel);
}
JSONArray jMapProperties = new JSONArray();
for (PropertyModelClass mapProperty : level.getProperties()) {
JSONObject jMapProperty = new JSONObject();
jMapProperty.put("name", mapProperty.getName());
jMapProperty.put("value", mapProperty.getValue());
jMapProperties.put(jMapProperty);
}
jRoot.put("properties", jMapProperties);
jRoot.put("models", jEntityLibrary);
JSONArray jObjects = new JSONArray();
for (int i = 0; i < level.getObjectCount(); i++) {
LevelEditorObject levelEditorObject = level.getObjectAt(i);
JSONObject jObject = new JSONObject();
Transformations transformations = levelEditorObject.getTransformations();
Vector3 translation = transformations.getTranslation();
Vector3 scale = transformations.getScale();
Rotation rotationAroundXAxis = transformations.getRotations().get(level.getRotationOrder().getAxisXIndex());
Rotation rotationAroundYAxis = transformations.getRotations().get(level.getRotationOrder().getAxisYIndex());
Rotation rotationAroundZAxis = transformations.getRotations().get(level.getRotationOrder().getAxisZIndex());
jObject.put("id", levelEditorObject.getId());
jObject.put("descr", levelEditorObject.getDescription());
jObject.put("mid", levelEditorObject.getEntity().getId());
jObject.put("tx", translation.getX());
jObject.put("ty", translation.getY());
jObject.put("tz", translation.getZ());
jObject.put("sx", scale.getX());
jObject.put("sy", scale.getY());
jObject.put("sz", scale.getZ());
jObject.put("rx", rotationAroundXAxis.getAngle());
jObject.put("ry", rotationAroundYAxis.getAngle());
jObject.put("rz", rotationAroundZAxis.getAngle());
JSONArray jObjectProperties = new JSONArray();
for (PropertyModelClass objectProperty : levelEditorObject.getProperties()) {
JSONObject jObjectProperty = new JSONObject();
jObjectProperty.put("name", objectProperty.getName());
jObjectProperty.put("value", objectProperty.getValue());
jObjectProperties.put(jObjectProperty);
}
jObject.put("properties", jObjectProperties);
jObjects.put(jObject);
}
jRoot.put("objects", jObjects);
jRoot.put("objects_eidx", level.getObjectIdx());
// save to file
fos = new FileOutputStream(new File(fileName));
fops = new PrintStream(fos);
fops.print(jRoot.toString(2));
} catch (JSONException je) {
je.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (fops != null)
fops.close();
if (fos != null)
try {
fos.close();
} catch (IOException ioe) {
}
}
}
use of net.drewke.tdme.engine.Transformations in project tdme by andreasdr.
the class LevelFileImport method doImport.
/**
* Imports a level from a TDME level file to Level Editor
* @param path name
* @param file name
* @param level
* @param object id prefix
*/
public static void doImport(String pathName, String fileName, LevelEditorLevel level, String objectIdPrefix) throws Exception {
pathName = pathName.replace(File.separatorChar == '/' ? '\\' : '/', File.separatorChar);
fileName = fileName.replace(File.separatorChar == '/' ? '\\' : '/', File.separatorChar);
JSONObject jRoot = null;
InputStream is = null;
try {
jRoot = new JSONObject(new JSONTokener(FileSystem.getInstance().getContent(pathName, fileName)));
} catch (IOException ioe) {
throw ioe;
} finally {
if (is != null)
try {
is.close();
} catch (IOException ioei) {
}
}
// game root path
level.setGameRoot(Tools.getGameRootPath(pathName));
// check for version
float version = Float.parseFloat(jRoot.getString("version"));
// new: rotation order
level.setRotationOrder(jRoot.has("ro") == true ? RotationOrder.valueOf(jRoot.getString("ro")) : RotationOrder.XYZ);
// map properties
level.clearProperties();
// parse properties
JSONArray jMapProperties = jRoot.getJSONArray("properties");
for (int i = 0; i < jMapProperties.length(); i++) {
JSONObject jMapProperty = jMapProperties.getJSONObject(i);
level.addProperty(jMapProperty.getString("name"), jMapProperty.getString("value"));
}
// lights
if (jRoot.has("lights") == true) {
JSONArray jLights = jRoot.getJSONArray("lights");
for (int i = 0; i < jLights.length(); i++) {
JSONObject jLight = jLights.getJSONObject(i);
LevelEditorLight light = level.getLightAt(jLight.has("id") ? jLight.getInt("id") : i);
// set up light in level
light.getAmbient().set((float) jLight.getDouble("ar"), (float) jLight.getDouble("ag"), (float) jLight.getDouble("ab"), (float) jLight.getDouble("aa"));
light.getDiffuse().set((float) jLight.getDouble("dr"), (float) jLight.getDouble("dg"), (float) jLight.getDouble("db"), (float) jLight.getDouble("da"));
light.getSpecular().set((float) jLight.getDouble("sr"), (float) jLight.getDouble("sg"), (float) jLight.getDouble("sb"), (float) jLight.getDouble("sa"));
light.getPosition().set((float) jLight.getDouble("px"), (float) jLight.getDouble("py"), (float) jLight.getDouble("pz"), (float) jLight.getDouble("pw"));
light.setConstantAttenuation((float) jLight.getDouble("ca"));
light.setLinearAttenuation((float) jLight.getDouble("la"));
light.setQuadraticAttenuation((float) jLight.getDouble("qa"));
light.getSpotTo().set((float) jLight.getDouble("stx"), (float) jLight.getDouble("sty"), (float) jLight.getDouble("stz"));
light.getSpotDirection().set((float) jLight.getDouble("sdx"), (float) jLight.getDouble("sdy"), (float) jLight.getDouble("sdz"));
light.setSpotExponent((float) jLight.getDouble("se"));
light.setSpotCutOff((float) jLight.getDouble("sco"));
light.setEnabled(jLight.getBoolean("e"));
}
}
// entities
level.getEntityLibrary().clear();
JSONArray jModels = jRoot.getJSONArray("models");
for (int i = 0; i < jModels.length(); i++) {
JSONObject jModel = jModels.getJSONObject(i);
// add model to library
LevelEditorEntity levelEditorEntity = ModelMetaDataFileImport.doImportFromJSON(jModel.getInt("id"), new File(pathName).getCanonicalPath(), jModel.getJSONObject("entity"));
// do we have a valid entity?
if (levelEditorEntity == null) {
throw new Exception("Invalid entity");
}
// add entity
level.getEntityLibrary().addEntity(levelEditorEntity);
// parse optional model properties
if (jModel.has("properties")) {
JSONArray jModelProperties = jModel.getJSONArray("properties");
for (int j = 0; j < jModelProperties.length(); j++) {
JSONObject jModelProperty = jModelProperties.getJSONObject(j);
levelEditorEntity.addProperty(jModelProperty.getString("name"), jModelProperty.getString("value"));
}
}
}
// objects
level.clearObjects();
JSONArray jObjects = jRoot.getJSONArray("objects");
for (int i = 0; i < jObjects.length(); i++) {
JSONObject jObject = jObjects.getJSONObject(i);
LevelEditorEntity model = level.getEntityLibrary().getEntity(jObject.getInt("mid"));
Transformations transformations = new Transformations();
transformations.getPivot().set(model.getPivot());
transformations.getTranslation().set((float) jObject.getDouble("tx"), (float) jObject.getDouble("ty"), (float) jObject.getDouble("tz"));
transformations.getScale().set((float) jObject.getDouble("sx"), (float) jObject.getDouble("sy"), (float) jObject.getDouble("sz"));
Vector3 rotation = new Vector3((float) jObject.getDouble("rx"), (float) jObject.getDouble("ry"), (float) jObject.getDouble("rz"));
transformations.getRotations().add(new Rotation(rotation.getArray()[level.getRotationOrder().getAxis0VectorIndex()], level.getRotationOrder().getAxis0()));
transformations.getRotations().add(new Rotation(rotation.getArray()[level.getRotationOrder().getAxis1VectorIndex()], level.getRotationOrder().getAxis1()));
transformations.getRotations().add(new Rotation(rotation.getArray()[level.getRotationOrder().getAxis2VectorIndex()], level.getRotationOrder().getAxis2()));
transformations.update();
LevelEditorObject levelEditorObject = new LevelEditorObject(objectIdPrefix != null ? objectIdPrefix + jObject.getString("id") : jObject.getString("id"), jObject.has("descr") ? jObject.getString("descr") : "", transformations, model);
levelEditorObject.clearProperties();
// parse optional object properties, new in LE 0.3a
if (jObject.has("properties")) {
JSONArray jObjectProperties = jObject.getJSONArray("properties");
for (int j = 0; j < jObjectProperties.length(); j++) {
JSONObject jObjectProperty = jObjectProperties.getJSONObject(j);
levelEditorObject.addProperty(jObjectProperty.getString("name"), jObjectProperty.getString("value"));
}
}
// check if entity already exists
// small workaround for a bug that would allow to place to objects at same place with same model
/*
boolean skipObject = false;
for (int j = 0; j < level.getObjectCount(); j++) {
LevelEditorObject _levelEditorObject = level.getObjectAt(j);
if (_levelEditorObject.getModel() == levelEditorObject.getModel() &&
_levelEditorObject.getTransformations().getTranslation().equals(levelEditorObject.getTransformations().getTranslation())) {
System.out.println("Skipping '" + levelEditorObject + "' as we already have a object with this model and translation.");
// we already have a object with selected model on this translation
skipObject = true;
break;
}
}
// skip on object if requested
if (skipObject == true) continue;
*/
// otherwise add
level.addObject(levelEditorObject);
}
level.setObjectIdx(jRoot.getInt("objects_eidx"));
level.setPathName(pathName);
level.setFileName(fileName);
level.computeDimension();
}
use of net.drewke.tdme.engine.Transformations in project tdme by andreasdr.
the class EngineTest method init.
/*
* (non-Javadoc)
* @see com.jogamp.opengl.GLEventListener#init(com.jogamp.opengl.GLAutoDrawable)
*/
public void init(GLAutoDrawable drawable) {
engine.init(drawable);
if (osEngine == null) {
osEngine = Engine.createOffScreenInstance(drawable, 512, 512);
//
Light osLight0 = osEngine.getLightAt(0);
osLight0.getAmbient().set(1.0f, 1.0f, 1.0f, 1.0f);
osLight0.getDiffuse().set(1.0f, 1.0f, 1.0f, 1.0f);
osLight0.getPosition().set(0.0f, -4f, -4f, 1.0f);
osLight0.getSpotDirection().set(new Vector3(osLight0.getPosition().getArray())).sub(new Vector3(0f, 0f, 0f));
osLight0.setEnabled(true);
// cam
Camera osCam = osEngine.getCamera();
osCam.setZNear(0.10f);
osCam.setZFar(50.00f);
osCam.getLookFrom().set(0f, 4f, -4f);
osCam.getLookAt().set(0f, 0.50f, 0f);
osCam.computeUpVector(osCam.getLookFrom(), osCam.getLookAt(), osCam.getUpVector());
// scene color
osEngine.getSceneColor().set(0.5f, 0.0f, 0.0f, 1.0f);
}
// cam
Camera cam = engine.getCamera();
cam.setZNear(0.10f);
cam.setZFar(50.00f);
cam.getLookFrom().set(0f, 3f, -8f);
cam.getLookAt().set(0f, 0.50f, 0f);
cam.computeUpVector(cam.getLookFrom(), cam.getLookAt(), cam.getUpVector());
// lights
Light light0 = engine.getLightAt(0);
light0.getAmbient().set(1.0f, 1.0f, 1.0f, 1.0f);
light0.getDiffuse().set(0.5f, 0.5f, 0.5f, 1f);
light0.getSpecular().set(1f, 1f, 1f, 1f);
light0.getPosition().set(0f, 20000f, 0f, 1f);
light0.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light0.getPosition().getArray()));
light0.setConstantAttenuation(0.5f);
light0.setLinearAttenuation(0f);
light0.setQuadraticAttenuation(0f);
light0.setSpotExponent(0f);
light0.setSpotCutOff(180f);
light0.setEnabled(true);
Light light1 = engine.getLightAt(1);
light1.getDiffuse().set(1.0f, 0.0f, 0.0f, 1.0f);
light1.getPosition().set(-4.0f, 5.0f, -5.0f, 1.0f);
light1.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light1.getPosition().getArray()));
light1.setEnabled(true);
Light light2 = engine.getLightAt(2);
light2.getDiffuse().set(0.0f, 1.0f, 0.0f, 1.0f);
light2.getPosition().set(+4.0f, 5.0f, 0.0f, 1.0f);
light2.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light2.getPosition().getArray()));
light2.setEnabled(true);
// scene
players = new ArrayList<Object3D>();
playersBoundingVolumeModel = new ArrayList<Object3D>();
playerBoundingVolumesTransformed = new ArrayList<BoundingVolume>();
try {
Model _barrel = DAEReader.read("resources/tests/models/barrel", "barrel.dae");
Object3D barrel = new Object3D("barrel", _barrel);
barrelBoundingVolume = new ConvexMesh(new Object3DModel(_barrel));
barrel.getTranslation().set(1.5f, 0.35f, -2f);
barrel.setDynamicShadowingEnabled(true);
barrel.setEnabled(true);
barrel.update();
barrelBoundingVolumeTransformed = barrelBoundingVolume.clone();
barrelBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(barrelBoundingVolume, barrel);
engine.addEntity(barrel);
// wall
Model _farPlane = createWallModel();
Object3D farPlane = new Object3D("wall", _farPlane);
farPlane.bindDiffuseTexture("wall", "wall", osEngine.getFrameBuffer());
engine.addEntity(farPlane);
//
Model _grass = DAEReader.read("resources/tests/models/grass", "grass.dae");
Object3D grass = new Object3D("ground", _grass);
grass.setEnabled(true);
grass.getScale().set(8f, 1f, 8f);
grass.update();
engine.addEntity(grass);
// players
Model _player = DAEReader.read("resources/tests/models/dummy", "testDummy_textured.DAE");
_player.addAnimationSetup("still", 3, 3, true);
_player.addAnimationSetup("walk", 0, 18, true);
// player bounding volume
// playerBoundingVolume = Sphere.createBoundingVolume(new Vector3(0,90f/130f,0), 90f/130f);
playerBoundingVolume = Capsule.createBoundingVolume(new Vector3(0, 30f / 130f, 0), new Vector3(0, 230f / 130f, 0), 25 / 130f);
// playerBoundingVolume = BoundingBox.createBoundingVolume(new Vector3(-25f/130f, 0, -25f/130f), new Vector3(+25f/130f, 180f/130f, +25f/130f));
/*
playerBoundingVolume = OrientedBoundingBox.createBoundingVolume(
new Vector3(0f, 90f/130f, 0f),
new Vector3(1f, 0f, 0f),
new Vector3(0f, 1f, 0f),
new Vector3(0f, 0f, 1f),
new Vector3(25f/130f, 90f/130f, 25f/130f)
);
*/
playerBoundingVolumeModel = PrimitiveModel.createModel(playerBoundingVolume, "player_bv");
// add player 1
// player
Object3D player1 = new Object3D("player1", _player);
player1.getTranslation().add(new Vector3(-1.50f, 0f, 0f));
player1.setAnimation("still");
player1.getRotations().add(new Rotation(0f, new Vector3(0f, 1f, 0f)));
player1.update();
player1.setEnabled(true);
player1.setPickable(true);
player1.setDynamicShadowingEnabled(true);
engine.addEntity(player1);
// bounding volume transformed
BoundingVolume player1BoundingVolumeTransformed = playerBoundingVolume.clone();
player1BoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player1);
playerBoundingVolumesTransformed.add(player1BoundingVolumeTransformed);
// add to engine
players.add(player1);
// bounding volume
Object3D player1BoundingVolume = new Object3D("player1_bv", playerBoundingVolumeModel);
player1BoundingVolume.fromTransformations(player1);
player1BoundingVolume.setEnabled(true);
playersBoundingVolumeModel.add(player1BoundingVolume);
// engine.addEntity(player1BoundingVolume);
// add player 2
// player
Object3D player2 = new Object3D("player2", _player);
player2.getTranslation().add(new Vector3(1.50f, 0f, 0f));
player2.setAnimation("still");
player2.getRotations().add(new Rotation(0f, new Vector3(0f, 1f, 0f)));
player2.update();
player2.setEnabled(true);
player2.setPickable(true);
player2.setDynamicShadowingEnabled(true);
players.add(player2);
// bounding volume transformed
BoundingVolume player2BoundingVolumeTransformed = playerBoundingVolume.clone();
player2BoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player2);
playerBoundingVolumesTransformed.add(player2BoundingVolumeTransformed);
// add to engine
engine.addEntity(player2);
// bounding volume
Object3D player2BoundingVolume = new Object3D("player2_bv", playerBoundingVolumeModel);
player2BoundingVolume.fromTransformations(player2);
player2BoundingVolume.setEnabled(true);
playersBoundingVolumeModel.add(player2BoundingVolume);
// engine.addEntity(player2BoundingVolume);
// add cube
Model _cube = DAEReader.read("resources/tests/models/test", "cube.dae");
cube = new Object3D("cube", _cube);
cube.getTranslation().add(new Vector3(0f, 0f, 0f));
cube.getScale().set(2f, 2f, 2f);
cube.update();
cube.setPickable(true);
cube.setDynamicShadowingEnabled(true);
cube.setEnabled(true);
cubeBoundingVolume = cube.getBoundingBox();
cubeBoundingVolumeTransformed = cubeBoundingVolume.clone();
cubeBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(cubeBoundingVolume, cube);
engine.addEntity(cube);
//
cubeBoundingVolumeModel = PrimitiveModel.createModel(cubeBoundingVolume, "cube_bv");
// bounding volume
Object3D cubeBoundingVolumeObject3D = new Object3D("cube_bv", cubeBoundingVolumeModel);
cubeBoundingVolumeObject3D.fromTransformations(cube);
cubeBoundingVolumeObject3D.setEnabled(true);
engine.addEntity(cubeBoundingVolumeObject3D);
// wall
Model _wall = DAEReader.read("resources/tests/models/wall", "wall.dae");
Object3D wall0 = new Object3D("wall0", _wall);
wall0.getTranslation().add(new Vector3(-1.00f, 0f, 3.00f));
wall0.update();
wall0.setPickable(true);
wall0.setEnabled(true);
engine.addEntity(wall0);
Object3D wall1 = new Object3D("wall1", _wall);
wall1.getTranslation().add(new Vector3(0f, 0f, 3.00f));
wall1.update();
wall1.setPickable(true);
wall1.setEnabled(true);
engine.addEntity(wall1);
// os engine test
Object3D osCube = new Object3D("cube", _cube);
osCube.getTranslation().add(new Vector3(0f, 0f, 0f));
osCube.getScale().set(2f, 2f, 2f);
osCube.update();
osEngine.addEntity(osCube);
//
circleTransformations = new Transformations();
engine.addEntity(new PointsParticleSystemEntity("circle", false, new CircleParticleEmitter(3000, 50, 50, new Vector3(1f, 0f, 0f), new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 0f), 0.4f, 0f, 0f, new Vector3(0f, 0.2f, 0f), new Vector3(0f, 0.2f, 0f), new Color4(1f, 1f, 1f, 0.3f), new Color4(1f, 1f, 1f, 0.3f)), 1000, true));
engine.getEntity("circle").setEnabled(true);
engine.addEntity(new PointsParticleSystemEntity("water", true, new SphereParticleEmitter(4000, 1000, 0, 0.1f, 0.0f, new Sphere(new Vector3(-1f, 1f, 0f), 0.05f), new Vector3(-4f, 0f, 1f), new Vector3(-1f, 0f, 0f), new Color4(0.8f, 0.8f, 1f, 0.25f), new Color4(0.8f, 0.8f, 1f, 0.25f)), 4000, true));
engine.getEntity("water").setEnabled(true);
engine.addEntity(new PointsParticleSystemEntity("snow", false, new BoundingBoxParticleEmitter(15, 15000, 1000, 0, 0, new OrientedBoundingBox(new Vector3(0f, 4f, 0f), new Vector3(1f, 0f, 0f), new Vector3(0f, 1f, 0f), new Vector3(0f, 0f, 1f), new Vector3(4f, 0f, 4f)), new Vector3(0f, -0.5f, 0f), new Vector3(0f, -0.1f, 0f), new Color4(0.8f, 0.8f, 1f, 0.5f), new Color4(0.8f, 0.8f, 1f, 0.5f)), 1024, true));
engine.getEntity("snow").setEnabled(true);
engine.addEntity(new PointsParticleSystemEntity("firebase", false, new SphereParticleEmitter(2048, 1024, 2048, 0, 0, new Sphere(new Vector3(2.5f, 0.2f, 0f), 0.2f), new Vector3(0f, 0.1f, 0f), new Vector3(0f, 0.1f, 0f), new Color4(0.0f, 0f, 0f, 0.5f), new Color4(0.4f, 0f, 0f, 0.5f)), 2048, true));
engine.getEntity("firebase").setEnabled(true);
//
engine.addEntity(new PointsParticleSystemEntity("firetop", false, new SphereParticleEmitter(2048, 1024, 2048, 0, 0, new Sphere(new Vector3(2.5f, 0.7f, 0f), 0.1f), new Vector3(0f, 0.06f, 0f), new Vector3(0f, 0.12f, 0f), new Color4(0.75f, 0.0f, 0f, 0.5f), new Color4(1f, 1f, 0f, 0.5f)), 2048, true));
engine.getEntity("firetop").setEnabled(true);
//
engine.addEntity(new PointsParticleSystemEntity("firesmoke", false, new SphereParticleEmitter(2048, 1024, 2048, 0, 0, new Sphere(new Vector3(2.5f, 0.7f, 0f), 0.1f), new Vector3(0f, 0.2f, 0f), new Vector3(0f, 0.4f, 0f), new Color4(0.8f, 0.8f, 0.8f, 0.1f), new Color4(0.8f, 0.8f, 0.8f, 0.1f)), 2048, true));
engine.getEntity("firesmoke").setEnabled(true);
((ParticleSystemEntity) engine.getEntity("circle")).setPickable(false);
((ParticleSystemEntity) engine.getEntity("snow")).setPickable(false);
((ParticleSystemEntity) engine.getEntity("firebase")).setPickable(true);
((ParticleSystemEntity) engine.getEntity("firetop")).setPickable(true);
((ParticleSystemEntity) engine.getEntity("firesmoke")).setPickable(true);
} catch (Exception exception) {
exception.printStackTrace();
System.out.println("Could not load object: " + exception.getMessage());
}
}
use of net.drewke.tdme.engine.Transformations in project tdme by andreasdr.
the class LevelEditorView method pasteObjects.
/**
* Paste objects
*/
private void pasteObjects() {
// determine top left of paste objects
float pasteObjectsMinX = Float.MAX_VALUE;
float pasteObjectsMinZ = Float.MAX_VALUE;
float pasteObjectsMinY = Float.MIN_VALUE;
for (LevelEditorObject object : pasteObjects) {
BoundingVolume obv = object.getEntity().getModel().getBoundingBox();
BoundingVolume cbv = obv.clone();
cbv.fromBoundingVolumeWithTransformations(obv, object.getTransformations());
float[] objectBBMinXYZ = ((BoundingBox) cbv).getMin().getArray();
if (objectBBMinXYZ[0] < pasteObjectsMinX)
pasteObjectsMinX = objectBBMinXYZ[0];
if (objectBBMinXYZ[1] < pasteObjectsMinY)
pasteObjectsMinY = objectBBMinXYZ[1];
if (objectBBMinXYZ[2] < pasteObjectsMinZ)
pasteObjectsMinZ = objectBBMinXYZ[2];
}
// determine top left of selected objects
float selectedObjectsMinX = Float.MAX_VALUE;
float selectedObjectsMinZ = Float.MAX_VALUE;
float selectedObjectsMaxY = Float.MIN_VALUE;
for (Entity object : selectedObjects) {
LevelEditorObject levelEditorObject = level.getObjectById(object.getId());
if (levelEditorObject == null)
continue;
BoundingVolume obv = levelEditorObject.getEntity().getModel().getBoundingBox();
BoundingVolume cbv = obv.clone();
cbv.fromBoundingVolumeWithTransformations(obv, levelEditorObject.getTransformations());
float[] objectBBMinXYZ = ((BoundingBox) cbv).getMin().getArray();
float[] objectBBMaxXYZ = ((BoundingBox) cbv).getMax().getArray();
if (objectBBMinXYZ[0] < selectedObjectsMinX)
selectedObjectsMinX = objectBBMinXYZ[0];
if (objectBBMaxXYZ[1] > selectedObjectsMaxY)
selectedObjectsMaxY = objectBBMaxXYZ[1];
if (objectBBMinXYZ[2] < selectedObjectsMinZ)
selectedObjectsMinZ = objectBBMinXYZ[2];
}
// paste objects
for (LevelEditorObject pasteObject : pasteObjects) {
// get selected level entity if it is one
LevelEditorEntity pasteModel = pasteObject.getEntity();
// create level entity, copy transformations from original
Transformations levelEditorObjectTransformations = new Transformations();
levelEditorObjectTransformations.fromTransformations(pasteObject.getTransformations());
// compute new translation
float objectDiffX = pasteObject.getTransformations().getTranslation().getX() - pasteObjectsMinX;
float objectDiffY = pasteObject.getTransformations().getTranslation().getY() - pasteObjectsMinY;
float objectDiffZ = pasteObject.getTransformations().getTranslation().getZ() - pasteObjectsMinZ;
levelEditorObjectTransformations.getTranslation().setX(selectedObjectsMinX + objectDiffX);
levelEditorObjectTransformations.getTranslation().setY(selectedObjectsMaxY + objectDiffY);
levelEditorObjectTransformations.getTranslation().setZ(selectedObjectsMinZ + objectDiffZ);
levelEditorObjectTransformations.update();
// check if entity already exists
for (int i = 0; i < level.getObjectCount(); i++) {
LevelEditorObject levelEditorObject = level.getObjectAt(i);
if (levelEditorObject.getEntity() == pasteModel && levelEditorObject.getTransformations().getTranslation().equals(levelEditorObjectTransformations.getTranslation())) {
// we already have a object with selected model on this translation
return;
}
}
// create new level editor object
LevelEditorObject levelEditorObject = new LevelEditorObject(pasteModel.getName() + "_" + level.allocateObjectId(), "", levelEditorObjectTransformations, pasteModel);
// copy properties
for (PropertyModelClass property : pasteObject.getProperties()) {
levelEditorObject.addProperty(property.getName(), property.getValue());
}
// add to level
level.addObject(levelEditorObject);
// add to 3d engine
Object3D object = new Object3D(levelEditorObject.getId(), levelEditorObject.getEntity().getModel());
object.fromTransformations(levelEditorObjectTransformations);
object.setPickable(true);
engine.addEntity(object);
}
// add to objects listbox
levelEditorScreenController.setObjectListbox(level.getObjectIdsIterator());
}
use of net.drewke.tdme.engine.Transformations in project tdme by andreasdr.
the class Level method addLevel.
/**
* Add level to physics world
* @param world
* @param level
* @param rigid bodies (will be filled by logic)
* @param translation
*/
public static void addLevel(World world, LevelEditorLevel level, ArrayList<RigidBody> rigidBodies, Vector3 translation) {
// load level objects
for (int i = 0; i < level.getObjectCount(); i++) {
LevelEditorObject object = level.getObjectAt(i);
// skip on empties or trigger
if (object.getEntity().getType() == EntityType.EMPTY)
continue;
if (object.getEntity().getType() == EntityType.TRIGGER)
continue;
if (object.getEntity().getType() == EntityType.PARTICLESYSTEM)
continue;
//
for (int j = 0; j < object.getEntity().getBoundingVolumeCount(); j++) {
LevelEditorEntityBoundingVolume entityBv = object.getEntity().getBoundingVolumeAt(j);
// keep track of world ids
String worldId = object.getId() + ".bv." + j;
// TODO: apply transformations
Transformations transformations = new Transformations();
// apply transformations
transformations.fromTransformations(object.getTransformations());
// apply translation
if (translation != null) {
transformations.getTranslation().add(translation);
transformations.update();
}
// add to physics world
RigidBody rigidBody = world.addStaticRigidBody(worldId, true, RIGIDBODY_TYPEID_STATIC, transformations, entityBv.getBoundingVolume(), 1.0f);
rigidBody.setCollisionTypeIds(RIGIDBODY_TYPEID_STATIC | RIGIDBODY_TYPEID_PLAYER);
// add to rigid bodies
rigidBodies.add(rigidBody);
}
}
}
Aggregations