use of net.drewke.tdme.engine.primitives.BoundingVolume in project tdme by andreasdr.
the class LevelEditorView method updateGUIElements.
/**
* Update GUI elements
* screen caption
* level size
* selected object
* object properties
* object 3d transformations
* object data
*/
private void updateGUIElements() {
levelEditorScreenController.setScreenCaption("Level Editor - " + level.getFileName());
levelEditorScreenController.setLevelSize(level.getDimension().getX(), level.getDimension().getZ(), level.getDimension().getY());
if (selectedObjects.size() == 1) {
Entity selectedObject = selectedObjects.get(0);
if (selectedObject != null && selectedObject.getId().startsWith("leveleditor.") == false) {
LevelEditorObject levelEditorObject = level.getObjectById(selectedObject.getId());
PropertyModelClass preset = levelEditorObject.getProperty("preset");
levelEditorScreenController.setObjectProperties(preset != null ? preset.getValue() : "", levelEditorObject.getProperties(), null);
levelEditorScreenController.setObject(selectedObject.getTranslation(), selectedObject.getScale(), selectedObject.getRotations().get(level.getRotationOrder().getAxisXIndex()).getAngle(), selectedObject.getRotations().get(level.getRotationOrder().getAxisYIndex()).getAngle(), selectedObject.getRotations().get(level.getRotationOrder().getAxisZIndex()).getAngle());
// determine center
Vector3 objectCenter = null;
if (levelEditorObject.getEntity().getModel() != null) {
BoundingVolume bv = levelEditorObject.getEntity().getModel().getBoundingBox().clone();
bv.fromBoundingVolumeWithTransformations(bv, levelEditorObject.getTransformations());
objectCenter = bv.getCenter();
} else {
// TODO: this is not the center, applies currently to particle systems
objectCenter = levelEditorObject.getTransformations().getTranslation();
}
//
levelEditorScreenController.setObjectData(levelEditorObject.getId(), levelEditorObject.getDescription(), levelEditorObject.getEntity().getName(), objectCenter);
} else {
levelEditorScreenController.unsetObjectData();
levelEditorScreenController.unsetObject();
levelEditorScreenController.unsetObjectProperties();
}
} else if (selectedObjects.size() > 1) {
levelEditorScreenController.unsetObjectData();
levelEditorScreenController.setObject(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 1f), 0f, 0f, 0f);
levelEditorScreenController.unsetObjectProperties();
} else if (selectedObjects.size() == 0) {
levelEditorScreenController.unsetObjectData();
levelEditorScreenController.unsetObject();
levelEditorScreenController.unsetObjectProperties();
}
// set up lights
for (int i = 0; i < 4; i++) {
levelEditorScreenController.setLight(i, level.getLightAt(i).getAmbient(), level.getLightAt(i).getDiffuse(), level.getLightAt(i).getSpecular(), level.getLightAt(i).getPosition(), level.getLightAt(i).getConstantAttenuation(), level.getLightAt(i).getLinearAttenuation(), level.getLightAt(i).getQuadraticAttenuation(), level.getLightAt(i).getSpotTo(), level.getLightAt(i).getSpotDirection(), level.getLightAt(i).getSpotExponent(), level.getLightAt(i).getSpotCutOff(), level.getLightAt(i).isEnabled());
}
}
use of net.drewke.tdme.engine.primitives.BoundingVolume in project tdme by andreasdr.
the class LevelEditorView method placeObject.
/**
* Places selected model on given object
*/
public void placeObject(Entity selectedObject) {
if (selectedEntity != null && selectedObject != null) {
// get selected level entity if it is one
LevelEditorObject selectedLevelEditorObject = level.getObjectById(selectedObject.getId());
// create level entity
Transformations levelEditorObjectTransformations = new Transformations();
// take translation of selected object as base
levelEditorObjectTransformations.getTranslation().set(selectedObject.getTranslation());
Vector3 centerSelectedObject = selectedObject.getBoundingBox().getMin().clone().add(selectedObject.getBoundingBox().getMax()).scale(0.5f);
// compute center of selected model
Vector3 centerNewObject = selectedEntity.getModel() != null ? selectedEntity.getModel().getBoundingBox().getCenter().clone() : new Vector3(0f, 0f, 0f);
// put new object on middle of selected object
levelEditorObjectTransformations.getTranslation().add(centerNewObject.clone().add(centerSelectedObject));
// set on selected object / y
if (selectedLevelEditorObject == null || selectedLevelEditorObject.getEntity().getType() == EntityType.PARTICLESYSTEM || selectedEntity.getType() == EntityType.PARTICLESYSTEM) {
levelEditorObjectTransformations.getTranslation().setY(gridY + (selectedEntity.getModel() != null ? -selectedEntity.getModel().getBoundingBox().getMin().getY() : 0f));
} else {
// create transformed level editor object bounding box
BoundingVolume bv = selectedLevelEditorObject.getEntity().getModel().getBoundingBox().clone();
bv.fromBoundingVolumeWithTransformations(selectedLevelEditorObject.getEntity().getModel().getBoundingBox(), selectedLevelEditorObject.getTransformations());
//
levelEditorObjectTransformations.getTranslation().setY(bv.computeDimensionOnAxis(new Vector3(0f, 1f, 0f)) / 2 + bv.getCenter().getY() + -selectedEntity.getModel().getBoundingBox().getMin().getY());
}
// standard scale
levelEditorObjectTransformations.getScale().set(new Vector3(1f, 1f, 1f));
// standard rotations
levelEditorObjectTransformations.getPivot().set(selectedEntity.getPivot());
levelEditorObjectTransformations.getRotations().add(new Rotation(0f, level.getRotationOrder().getAxis0()));
levelEditorObjectTransformations.getRotations().add(new Rotation(0f, level.getRotationOrder().getAxis1()));
levelEditorObjectTransformations.getRotations().add(new Rotation(0f, level.getRotationOrder().getAxis2()));
levelEditorObjectTransformations.update();
// check if entity already exists
for (int i = 0; i < level.getObjectCount(); i++) {
LevelEditorObject levelEditorObject = level.getObjectAt(i);
if (levelEditorObject.getEntity() == selectedEntity && 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(selectedEntity.getName() + "_" + level.allocateObjectId(), "", levelEditorObjectTransformations, selectedEntity);
// add to level
level.addObject(levelEditorObject);
// add model to 3d engine
if (levelEditorObject.getEntity().getModel() != null) {
Object3D object = new Object3D(levelEditorObject.getId(), levelEditorObject.getEntity().getModel());
object.fromTransformations(levelEditorObjectTransformations);
object.setPickable(true);
engine.addEntity(object);
}
// add particle system to 3d engine
if (levelEditorObject.getEntity().getType() == EntityType.PARTICLESYSTEM) {
Entity object = Level.createParticleSystem(levelEditorObject.getEntity().getParticleSystem(), levelEditorObject.getId(), false);
object.fromTransformations(levelEditorObjectTransformations);
object.setPickable(true);
engine.addEntity(object);
}
// add to objects listbox
levelEditorScreenController.setObjectListbox(level.getObjectIdsIterator());
}
}
Aggregations