use of net.drewke.tdme.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class LevelEditorView method copyObjects.
/**
* Copy current selected objects
*/
private void copyObjects() {
pasteObjects.clear();
for (Entity selectedObject : selectedObjects) {
if (selectedObject != null && selectedObject.getId().startsWith("leveleditor.") == false) {
LevelEditorObject levelEditorObject = level.getObjectById(selectedObject.getId());
if (levelEditorObject == null)
continue;
pasteObjects.add(levelEditorObject);
}
}
}
use of net.drewke.tdme.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class LevelEditorView method objectDataApply.
/**
* On object data apply
* @param name
* @param description
*/
public boolean objectDataApply(String name, String description) {
if (selectedObjects.size() != 1)
return false;
// we only accept a single selection
Entity selectedObject = selectedObjects.get(0);
// skip if level editor internal object
if (selectedObject.getId().startsWith("leveleditor."))
return false;
// check if not a internal leveleditor object
LevelEditorObject levelEditorObject = level.getObjectById(selectedObject.getId());
// we need a associated object in level
if (levelEditorObject == null)
return false;
// we always can safely set the description
levelEditorObject.setDescription(description);
// did id changed
if (levelEditorObject.getId().equals(name) == false) {
// yep, check if name is already in use
if (engine.getEntity(name) != null) {
return false;
}
// remove from engine, level and selection
String oldId = levelEditorObject.getId();
level.removeObject(levelEditorObject.getId());
engine.removeEntity(levelEditorObject.getId());
selectedObjectsById.clear();
selectedObjects.clear();
// set up id
levelEditorObject.setId(name);
// add to level, 3d engine
level.addObject(levelEditorObject);
Object3D object = new Object3D(levelEditorObject.getId(), levelEditorObject.getEntity().getModel());
object.fromTransformations(levelEditorObject.getTransformations());
object.setPickable(true);
setStandardObjectColorEffect(object);
setHighlightObjectColorEffect(object);
engine.addEntity(object);
// add to selected objects
selectedObjects.add(object);
selectedObjectsById.put(object.getId(), object);
// update in objects listbox
levelEditorScreenController.setObjectListbox(level.getObjectIdsIterator());
}
// set description
levelEditorObject.setDescription(description);
//
return true;
}
use of net.drewke.tdme.tools.shared.model.LevelEditorObject 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.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class LevelEditorView method objectPropertyAdd.
/**
* Add a model property
* @return success
*/
public boolean objectPropertyAdd() {
if (selectedObjects.size() != 1)
return false;
// handle single object
Entity selectedObject = selectedObjects.get(0);
LevelEditorObject levelEditorObject = level.getObjectById(selectedObject.getId());
if (levelEditorObject == null)
return false;
// try to add property
if (levelEditorObject.addProperty("new.property", "new.value")) {
// reload model properties
levelEditorScreenController.setObjectProperties(null, levelEditorObject.getProperties(), "new.property");
//
return true;
}
//
return false;
}
use of net.drewke.tdme.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class LevelEditorView method objectTranslationApply.
/**
* Apply object translation
* @param x
* @param y
* @param z
*/
public void objectTranslationApply(float x, float y, float z) {
if (selectedObjects.size() == 0)
return;
// handle single object
if (selectedObjects.size() == 1) {
Entity selectedObject = selectedObjects.get(0);
LevelEditorObject currentEntity = level.getObjectById(selectedObject.getId());
if (currentEntity == null)
return;
currentEntity.getTransformations().getTranslation().set(x, y, z);
currentEntity.getTransformations().update();
selectedObject.fromTransformations(currentEntity.getTransformations());
} else if (selectedObjects.size() > 1) {
// multiple objects
for (Entity selectedObject : selectedObjects) {
LevelEditorObject currentEntity = level.getObjectById(selectedObject.getId());
if (currentEntity == null)
continue;
currentEntity.getTransformations().getTranslation().add(new Vector3(x, y, z));
currentEntity.getTransformations().update();
selectedObject.fromTransformations(currentEntity.getTransformations());
}
// reset controller object properties
levelEditorScreenController.setObject(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 1f), 0f, 0f, 0f);
}
level.computeDimension();
updateGUIElements();
}
Aggregations