use of net.drewke.tdme.tools.shared.model.LevelEditorObject 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.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class LevelEditorView method objectScaleApply.
/**
* Apply object scale
* @param x
* @param y
* @param z
*/
public void objectScaleApply(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().getScale().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().getScale().scale(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();
}
use of net.drewke.tdme.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class LevelEditorView method objectRotationsApply.
/**
* Apply object rotations
* @param x
* @param y
* @param z
*/
public void objectRotationsApply(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().getRotations().get(level.getRotationOrder().getAxisXIndex()).setAngle(x);
currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisYIndex()).setAngle(y);
currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisZIndex()).setAngle(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().getRotations().get(level.getRotationOrder().getAxisXIndex()).setAngle(currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisXIndex()).getAngle() + x);
currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisYIndex()).setAngle(currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisYIndex()).getAngle() + y);
currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisZIndex()).setAngle(currentEntity.getTransformations().getRotations().get(level.getRotationOrder().getAxisZIndex()).getAngle() + 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();
}
use of net.drewke.tdme.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class LevelEditorView method objectPropertySave.
/**
* Save a model property
* @param old name
* @param name
* @param value
* @return success
*/
public boolean objectPropertySave(String oldName, String name, String value) {
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 update property
if (levelEditorObject.updateProperty(oldName, name, value) == true) {
// reload model properties
levelEditorScreenController.setObjectProperties(null, levelEditorObject.getProperties(), name);
//
return true;
}
//
return false;
}
use of net.drewke.tdme.tools.shared.model.LevelEditorObject in project tdme by andreasdr.
the class LevelEditorScreenController method onObjectPropertiesSelectionChanged.
/**
* Event callback for object properties selection
* @param id
* @param event
*/
public void onObjectPropertiesSelectionChanged() {
//
objectPropertyName.getController().setDisabled(true);
objectPropertyName.getController().setValue(TEXT_EMPTY);
objectPropertyValue.getController().setDisabled(true);
objectPropertyValue.getController().setValue(TEXT_EMPTY);
btnObjectPropertySave.getController().setDisabled(true);
btnObjectPropertyRemove.getController().setDisabled(true);
// get selected level editor object
LevelEditorObject levelEditorObject = view.getSelectedObject();
if (levelEditorObject == null)
return;
// get model property
PropertyModelClass modelProperty = levelEditorObject.getProperty(objectPropertiesListBox.getController().getValue().toString());
if (modelProperty != null) {
objectPropertyName.getController().setValue(value.set(modelProperty.getName()));
objectPropertyValue.getController().setValue(value.set(modelProperty.getValue()));
objectPropertyName.getController().setDisabled(false);
objectPropertyValue.getController().setDisabled(false);
btnObjectPropertySave.getController().setDisabled(false);
btnObjectPropertyRemove.getController().setDisabled(false);
}
}
Aggregations