Search in sources :

Example 11 with PropertyModelClass

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;
}
Also used : Entity(net.drewke.tdme.engine.Entity) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity) FacesEntity(net.drewke.tdme.engine.model.FacesEntity) PropertyModelClass(net.drewke.tdme.tools.shared.model.PropertyModelClass) LevelEditorObject(net.drewke.tdme.tools.shared.model.LevelEditorObject)

Example 12 with PropertyModelClass

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());
}
Also used : Entity(net.drewke.tdme.engine.Entity) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity) FacesEntity(net.drewke.tdme.engine.model.FacesEntity) PropertyModelClass(net.drewke.tdme.tools.shared.model.PropertyModelClass) BoundingVolume(net.drewke.tdme.engine.primitives.BoundingVolume) Transformations(net.drewke.tdme.engine.Transformations) LevelEditorObject(net.drewke.tdme.tools.shared.model.LevelEditorObject) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity) Object3D(net.drewke.tdme.engine.Object3D)

Example 13 with PropertyModelClass

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);
    }
}
Also used : PropertyModelClass(net.drewke.tdme.tools.shared.model.PropertyModelClass) LevelEditorObject(net.drewke.tdme.tools.shared.model.LevelEditorObject)

Example 14 with PropertyModelClass

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);
    }
}
Also used : Entity(net.drewke.tdme.engine.Entity) PointsParticleSystemEntity(net.drewke.tdme.engine.PointsParticleSystemEntity) ObjectParticleSystemEntity(net.drewke.tdme.engine.ObjectParticleSystemEntity) PropertyModelClass(net.drewke.tdme.tools.shared.model.PropertyModelClass) LevelEditorObject(net.drewke.tdme.tools.shared.model.LevelEditorObject) Properties(net.drewke.tdme.tools.shared.model.Properties) Object3D(net.drewke.tdme.engine.Object3D)

Example 15 with PropertyModelClass

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();
    }
}
Also used : PropertyModelClass(net.drewke.tdme.tools.shared.model.PropertyModelClass) Vector3(net.drewke.tdme.math.Vector3)

Aggregations

PropertyModelClass (net.drewke.tdme.tools.shared.model.PropertyModelClass)23 LevelEditorObject (net.drewke.tdme.tools.shared.model.LevelEditorObject)9 LevelEditorEntity (net.drewke.tdme.tools.shared.model.LevelEditorEntity)7 Entity (net.drewke.tdme.engine.Entity)6 FacesEntity (net.drewke.tdme.engine.model.FacesEntity)5 Vector3 (net.drewke.tdme.math.Vector3)5 BoundingVolume (net.drewke.tdme.engine.primitives.BoundingVolume)3 GUIParentNode (net.drewke.tdme.gui.nodes.GUIParentNode)3 MutableString (net.drewke.tdme.utils.MutableString)3 File (java.io.File)2 IOException (java.io.IOException)2 Object3D (net.drewke.tdme.engine.Object3D)2 Transformations (net.drewke.tdme.engine.Transformations)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 ObjectParticleSystemEntity (net.drewke.tdme.engine.ObjectParticleSystemEntity)1 PointsParticleSystemEntity (net.drewke.tdme.engine.PointsParticleSystemEntity)1 Rotation (net.drewke.tdme.engine.Rotation)1