Search in sources :

Example 51 with Vector3

use of net.drewke.tdme.math.Vector3 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 52 with Vector3

use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.

the class EntityBoundingVolumeSubScreenController method onBoundingVolumeObbApply.

/**
	 * On bounding volume OBB apply
	 * @param entity
	 * @param idx
	 */
public void onBoundingVolumeObbApply(LevelEditorEntity entity, int idx) {
    try {
        // rotation axes by rotation angle for x,y,z
        Transformations rotations = new Transformations();
        rotations.getRotations().add(new Rotation(Tools.convertToFloat(boundingvolumeObbRotationZ[idx].getController().getValue().toString()), OrientedBoundingBox.AABB_AXIS_Z));
        rotations.getRotations().add(new Rotation(Tools.convertToFloat(boundingvolumeObbRotationY[idx].getController().getValue().toString()), OrientedBoundingBox.AABB_AXIS_Y));
        rotations.getRotations().add(new Rotation(Tools.convertToFloat(boundingvolumeObbRotationX[idx].getController().getValue().toString()), OrientedBoundingBox.AABB_AXIS_X));
        rotations.update();
        // extract axes from matrix
        Vector3 xAxis = new Vector3();
        Vector3 yAxis = new Vector3();
        Vector3 zAxis = new Vector3();
        rotations.getTransformationsMatrix().getAxes(xAxis, yAxis, zAxis);
        // delegate to view
        view.applyBoundingVolumeObb(entity, idx, Tools.convertToVector3(boundingvolumeObbCenter[idx].getController().getValue().toString()), xAxis, yAxis, zAxis, Tools.convertToVector3(boundingvolumeObbHalfextension[idx].getController().getValue().toString()));
    } catch (NumberFormatException nfe) {
        showErrorPopUp("Warning", "Invalid number entered");
    }
}
Also used : Transformations(net.drewke.tdme.engine.Transformations) Vector3(net.drewke.tdme.math.Vector3) Rotation(net.drewke.tdme.engine.Rotation)

Example 53 with Vector3

use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.

the class EntityBoundingVolumeSubScreenController method setupOrientedBoundingBox.

/**
	 * Setup oriented bounding box
	 * @param idx
	 * @param center
	 * @param axis 0
	 * @param axis 1
	 * @param axis 2
	 * @param half extension
	 */
public void setupOrientedBoundingBox(int idx, Vector3 center, Vector3 axis0, Vector3 axis1, Vector3 axis2, Vector3 halfExtension) {
    // set up rotation maxtrix
    Vector3 rotation = new Vector3();
    Matrix4x4 rotationMatrix = new Matrix4x4().identity();
    rotationMatrix.setAxes(axis0, axis1, axis2);
    rotationMatrix.computeEulerAngles(rotation);
    // set up obb in screen
    selectBoundingVolume(idx, BoundingVolumeType.ORIENTEDBOUNDINGBOX);
    boundingvolumeObbCenter[idx].getController().setValue(value.reset().append(Tools.formatFloat(center.getX())).append(", ").append(Tools.formatFloat(center.getY())).append(", ").append(Tools.formatFloat(center.getZ())));
    boundingvolumeObbHalfextension[idx].getController().setValue(value.reset().append(Tools.formatFloat(halfExtension.getX())).append(", ").append(Tools.formatFloat(halfExtension.getY())).append(", ").append(Tools.formatFloat(halfExtension.getZ())));
    boundingvolumeObbRotationX[idx].getController().setValue(value.set(Tools.formatFloat(rotation.getX())));
    boundingvolumeObbRotationY[idx].getController().setValue(value.set(Tools.formatFloat(rotation.getY())));
    boundingvolumeObbRotationZ[idx].getController().setValue(value.set(Tools.formatFloat(rotation.getZ())));
}
Also used : Vector3(net.drewke.tdme.math.Vector3) Matrix4x4(net.drewke.tdme.math.Matrix4x4)

Example 54 with Vector3

use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.

the class LevelEditorEntityLibrary method addModel.

/**
	 * Adds a model
	 * @param id
	 * @param name
	 * @param description
	 * @param path name
	 * @param file name
	 * @param pivot
	 * @return level editor entity
	 * @throws Exception
	 */
public LevelEditorEntity addModel(int id, String name, String description, String pathName, String fileName, Vector3 pivot) throws Exception {
    File modelFile = new File(pathName + File.separator + fileName);
    LevelEditorEntity levelEditorEntity = null;
    // parse models
    if (modelFile.getName().toLowerCase().endsWith(".dae")) {
        Model model = DAEReader.read(modelFile.getParentFile().getCanonicalPath(), modelFile.getName());
        levelEditorEntity = new LevelEditorEntity(id == ID_ALLOCATE ? allocateEntityId() : id, LevelEditorEntity.EntityType.MODEL, name, description, null, pathName + File.separator + fileName, model.getId().replace("\\", "_").replace("/", "_").replace(":", "_") + ".png", model, new Vector3(0f, 0f, 0f));
    } else if (modelFile.getName().toLowerCase().endsWith(".tm")) {
        Model model = TMReader.read(modelFile.getParentFile().getCanonicalPath(), modelFile.getName());
        levelEditorEntity = new LevelEditorEntity(id == ID_ALLOCATE ? allocateEntityId() : id, LevelEditorEntity.EntityType.MODEL, name, description, null, pathName + File.separator + fileName, model.getId().replace("\\", "_").replace("/", "_").replace(":", "_") + ".png", model, new Vector3(0f, 0f, 0f));
    } else if (modelFile.getName().toLowerCase().endsWith(".tmm")) {
        levelEditorEntity = ModelMetaDataFileImport.doImport(id == ID_ALLOCATE ? allocateEntityId() : id, pathName, fileName);
    } else {
        throw new Exception(pathName + "/" + fileName + ": Unknown model file format");
    }
    // add model
    addEntity(levelEditorEntity);
    //
    return levelEditorEntity;
}
Also used : Model(net.drewke.tdme.engine.model.Model) PrimitiveModel(net.drewke.tdme.engine.primitives.PrimitiveModel) Vector3(net.drewke.tdme.math.Vector3) File(java.io.File)

Example 55 with Vector3

use of net.drewke.tdme.math.Vector3 in project tdme by andreasdr.

the class LevelEditorEntityLibrary method addParticleSystem.

/**
	 * Add a empty
	 * @param name
	 * @param description
	 * @return level editor entity
	 * @throws Exception
	 */
public LevelEditorEntity addParticleSystem(int id, String name, String description) throws Exception {
    // create entity
    LevelEditorEntity levelEditorEntity = new LevelEditorEntity(id == ID_ALLOCATE ? allocateEntityId() : id, EntityType.PARTICLESYSTEM, name, description, null, null, null, null, new Vector3());
    // add particle system
    addEntity(levelEditorEntity);
    //
    return levelEditorEntity;
}
Also used : Vector3(net.drewke.tdme.math.Vector3)

Aggregations

Vector3 (net.drewke.tdme.math.Vector3)75 FacesEntity (net.drewke.tdme.engine.model.FacesEntity)20 Model (net.drewke.tdme.engine.model.Model)20 LevelEditorEntity (net.drewke.tdme.tools.shared.model.LevelEditorEntity)14 ArrayList (java.util.ArrayList)13 Rotation (net.drewke.tdme.engine.Rotation)12 Face (net.drewke.tdme.engine.model.Face)12 BoundingBox (net.drewke.tdme.engine.primitives.BoundingBox)11 Material (net.drewke.tdme.engine.model.Material)10 BoundingVolume (net.drewke.tdme.engine.primitives.BoundingVolume)10 Group (net.drewke.tdme.engine.model.Group)9 PrimitiveModel (net.drewke.tdme.engine.primitives.PrimitiveModel)9 Entity (net.drewke.tdme.engine.Entity)8 Object3D (net.drewke.tdme.engine.Object3D)8 LevelEditorObject (net.drewke.tdme.tools.shared.model.LevelEditorObject)8 File (java.io.File)7 IOException (java.io.IOException)7 Transformations (net.drewke.tdme.engine.Transformations)7 OrientedBoundingBox (net.drewke.tdme.engine.primitives.OrientedBoundingBox)7 Camera (net.drewke.tdme.engine.Camera)6