Search in sources :

Example 11 with BoundingVolume

use of net.drewke.tdme.engine.primitives.BoundingVolume 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 12 with BoundingVolume

use of net.drewke.tdme.engine.primitives.BoundingVolume in project tdme by andreasdr.

the class LevelEditorView method placeObject.

/**
	 * Places selected model on given object
	 */
public void placeObject(Entity selectedObject) {
    if (selectedEntity != null && selectedObject != null) {
        // get selected level entity if it is one
        LevelEditorObject selectedLevelEditorObject = level.getObjectById(selectedObject.getId());
        // create level entity
        Transformations levelEditorObjectTransformations = new Transformations();
        // take translation of selected object as base
        levelEditorObjectTransformations.getTranslation().set(selectedObject.getTranslation());
        Vector3 centerSelectedObject = selectedObject.getBoundingBox().getMin().clone().add(selectedObject.getBoundingBox().getMax()).scale(0.5f);
        // compute center of selected model
        Vector3 centerNewObject = selectedEntity.getModel() != null ? selectedEntity.getModel().getBoundingBox().getCenter().clone() : new Vector3(0f, 0f, 0f);
        // put new object on middle of selected object
        levelEditorObjectTransformations.getTranslation().add(centerNewObject.clone().add(centerSelectedObject));
        // set on selected object / y
        if (selectedLevelEditorObject == null || selectedLevelEditorObject.getEntity().getType() == EntityType.PARTICLESYSTEM || selectedEntity.getType() == EntityType.PARTICLESYSTEM) {
            levelEditorObjectTransformations.getTranslation().setY(gridY + (selectedEntity.getModel() != null ? -selectedEntity.getModel().getBoundingBox().getMin().getY() : 0f));
        } else {
            // create transformed level editor object bounding box
            BoundingVolume bv = selectedLevelEditorObject.getEntity().getModel().getBoundingBox().clone();
            bv.fromBoundingVolumeWithTransformations(selectedLevelEditorObject.getEntity().getModel().getBoundingBox(), selectedLevelEditorObject.getTransformations());
            //
            levelEditorObjectTransformations.getTranslation().setY(bv.computeDimensionOnAxis(new Vector3(0f, 1f, 0f)) / 2 + bv.getCenter().getY() + -selectedEntity.getModel().getBoundingBox().getMin().getY());
        }
        // standard scale
        levelEditorObjectTransformations.getScale().set(new Vector3(1f, 1f, 1f));
        // standard rotations
        levelEditorObjectTransformations.getPivot().set(selectedEntity.getPivot());
        levelEditorObjectTransformations.getRotations().add(new Rotation(0f, level.getRotationOrder().getAxis0()));
        levelEditorObjectTransformations.getRotations().add(new Rotation(0f, level.getRotationOrder().getAxis1()));
        levelEditorObjectTransformations.getRotations().add(new Rotation(0f, level.getRotationOrder().getAxis2()));
        levelEditorObjectTransformations.update();
        // check if entity already exists
        for (int i = 0; i < level.getObjectCount(); i++) {
            LevelEditorObject levelEditorObject = level.getObjectAt(i);
            if (levelEditorObject.getEntity() == selectedEntity && 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(selectedEntity.getName() + "_" + level.allocateObjectId(), "", levelEditorObjectTransformations, selectedEntity);
        //	add to level
        level.addObject(levelEditorObject);
        // add model to 3d engine
        if (levelEditorObject.getEntity().getModel() != null) {
            Object3D object = new Object3D(levelEditorObject.getId(), levelEditorObject.getEntity().getModel());
            object.fromTransformations(levelEditorObjectTransformations);
            object.setPickable(true);
            engine.addEntity(object);
        }
        // add particle system to 3d engine
        if (levelEditorObject.getEntity().getType() == EntityType.PARTICLESYSTEM) {
            Entity object = Level.createParticleSystem(levelEditorObject.getEntity().getParticleSystem(), levelEditorObject.getId(), false);
            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) BoundingVolume(net.drewke.tdme.engine.primitives.BoundingVolume) Transformations(net.drewke.tdme.engine.Transformations) Vector3(net.drewke.tdme.math.Vector3) LevelEditorObject(net.drewke.tdme.tools.shared.model.LevelEditorObject) Rotation(net.drewke.tdme.engine.Rotation) Object3D(net.drewke.tdme.engine.Object3D)

Aggregations

BoundingVolume (net.drewke.tdme.engine.primitives.BoundingVolume)12 Vector3 (net.drewke.tdme.math.Vector3)10 Object3D (net.drewke.tdme.engine.Object3D)4 Entity (net.drewke.tdme.engine.Entity)3 Rotation (net.drewke.tdme.engine.Rotation)3 Transformations (net.drewke.tdme.engine.Transformations)3 FacesEntity (net.drewke.tdme.engine.model.FacesEntity)3 BoundingBox (net.drewke.tdme.engine.primitives.BoundingBox)3 OrientedBoundingBox (net.drewke.tdme.engine.primitives.OrientedBoundingBox)3 LevelEditorEntity (net.drewke.tdme.tools.shared.model.LevelEditorEntity)3 LevelEditorObject (net.drewke.tdme.tools.shared.model.LevelEditorObject)3 PropertyModelClass (net.drewke.tdme.tools.shared.model.PropertyModelClass)3 IOException (java.io.IOException)2 ConvexMesh (net.drewke.tdme.engine.primitives.ConvexMesh)2 Sphere (net.drewke.tdme.engine.primitives.Sphere)2 LevelEditorEntityBoundingVolume (net.drewke.tdme.tools.shared.model.LevelEditorEntityBoundingVolume)2 File (java.io.File)1 Camera (net.drewke.tdme.engine.Camera)1 Light (net.drewke.tdme.engine.Light)1 Object3DModel (net.drewke.tdme.engine.Object3DModel)1