Search in sources :

Example 16 with LevelEditorObject

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

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

Example 18 with LevelEditorObject

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

Example 19 with LevelEditorObject

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

Example 20 with LevelEditorObject

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

Aggregations

LevelEditorObject (net.drewke.tdme.tools.shared.model.LevelEditorObject)24 Entity (net.drewke.tdme.engine.Entity)17 LevelEditorEntity (net.drewke.tdme.tools.shared.model.LevelEditorEntity)17 FacesEntity (net.drewke.tdme.engine.model.FacesEntity)14 PropertyModelClass (net.drewke.tdme.tools.shared.model.PropertyModelClass)9 Vector3 (net.drewke.tdme.math.Vector3)8 Transformations (net.drewke.tdme.engine.Transformations)6 Object3D (net.drewke.tdme.engine.Object3D)4 Rotation (net.drewke.tdme.engine.Rotation)4 File (java.io.File)3 ObjectParticleSystemEntity (net.drewke.tdme.engine.ObjectParticleSystemEntity)3 PointsParticleSystemEntity (net.drewke.tdme.engine.PointsParticleSystemEntity)3 BoundingVolume (net.drewke.tdme.engine.primitives.BoundingVolume)3 IOException (java.io.IOException)2 RigidBody (net.drewke.tdme.engine.physics.RigidBody)2 LevelEditorEntityLibrary (net.drewke.tdme.tools.shared.model.LevelEditorEntityLibrary)2 LevelEditorLight (net.drewke.tdme.tools.shared.model.LevelEditorLight)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 FileOutputStream (java.io.FileOutputStream)1