use of net.drewke.tdme.tools.shared.model.PropertyModelClass in project tdme by andreasdr.
the class LevelEditorView method objectPropertyRemove.
/**
* Remove a object property from object properties
* @param name
* @return success
*/
public boolean objectPropertyRemove(String name) {
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 remove property
int idx = levelEditorObject.getPropertyIndex(name);
if (idx != -1 && levelEditorObject.removeProperty(name) == true) {
// get property first at index that was removed
PropertyModelClass property = levelEditorObject.getPropertyByIndex(idx);
if (property == null) {
// if current index does not work, take current one -1
property = levelEditorObject.getPropertyByIndex(idx - 1);
}
// reload model properties
levelEditorScreenController.setObjectProperties(null, levelEditorObject.getProperties(), property == null ? null : property.getName());
//
return true;
}
//
return false;
}
use of net.drewke.tdme.tools.shared.model.PropertyModelClass 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.PropertyModelClass 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);
}
}
use of net.drewke.tdme.tools.shared.model.PropertyModelClass in project tdme by andreasdr.
the class Level method addLevel.
/**
* Add level to engine
* @param engine
* @param level
* @param add empties
* @param add trigger
* @param dynamic shadowing
* @param pickable
* @param translation
*/
public static void addLevel(Engine engine, LevelEditorLevel level, boolean addEmpties, boolean addTrigger, boolean dynamicShadowing, boolean pickable, Vector3 translation) {
// load level objects
for (int i = 0; i < level.getObjectCount(); i++) {
LevelEditorObject object = level.getObjectAt(i);
Properties properties = object.getTotalProperties();
// skip on empties or trigger
if (addEmpties == false && object.getEntity().getType() == EntityType.EMPTY)
continue;
if (addTrigger == false && object.getEntity().getType() == EntityType.TRIGGER)
continue;
// add to 3d engine
Entity entity = null;
if (object.getEntity().getModel() != null) {
entity = new Object3D(object.getId(), object.getEntity().getModel());
} else if (object.getEntity().getType() == EntityType.PARTICLESYSTEM) {
entity = createParticleSystem(object.getEntity().getParticleSystem(), object.getId(), false);
}
// skip if we have no entity
if (entity == null)
continue;
// apply transformations
entity.fromTransformations(object.getTransformations());
// apply translation
if (translation != null) {
entity.getTranslation().add(translation);
}
// pickable
entity.setPickable(pickable);
// dynamic shadowing
PropertyModelClass shadowingProperty = properties.getProperty("shadowing");
boolean omitShadowing = shadowingProperty != null && shadowingProperty.getValue().equalsIgnoreCase("false");
entity.setDynamicShadowingEnabled(omitShadowing == true ? false : dynamicShadowing);
// do not scale empties
if (object.getEntity().getType() == EntityType.EMPTY) {
entity.getScale().set(MathTools.sign(entity.getScale().getX()), MathTools.sign(entity.getScale().getY()), MathTools.sign(entity.getScale().getZ()));
}
// update
entity.update();
// add
engine.addEntity(entity);
}
}
use of net.drewke.tdme.tools.shared.model.PropertyModelClass in project tdme by andreasdr.
the class EmptyView method updateGUIElements.
/**
* Init GUI elements
*/
public void updateGUIElements() {
if (entity != null) {
emptyScreenController.setScreenCaption("Empty - " + entity.getName());
PropertyModelClass preset = entity.getProperty("preset");
emptyScreenController.setEntityProperties(preset != null ? preset.getValue() : null, entity.getProperties(), null);
emptyScreenController.setEntityData(entity.getName(), entity.getDescription());
// trigger
Vector3 dimension = new Vector3();
dimension.set(entity.getModel().getBoundingBox().getMax());
dimension.sub(entity.getModel().getBoundingBox().getMin());
} else {
emptyScreenController.setScreenCaption("Empty - no trigger loaded");
emptyScreenController.unsetEntityProperties();
emptyScreenController.unsetEntityData();
}
}
Aggregations