Search in sources :

Example 11 with LevelEditorEntity

use of net.drewke.tdme.tools.shared.model.LevelEditorEntity in project tdme by andreasdr.

the class Tools method setupEntity.

/**
	 * Set up entity in given engine with look from rotations and scale
	 * @param entity
	 * @param engine
	 * @param look from rotations
	 * @param scale
	 */
public static void setupEntity(LevelEditorEntity entity, Engine engine, Transformations lookFromRotations, float scale) {
    if (entity == null)
        return;
    // entity bounding box
    BoundingBox entityBoundingBox = null;
    // add model to engine
    if (entity.getType() == EntityType.PARTICLESYSTEM) {
        entityBoundingBox = new BoundingBox(new Vector3(-0.5f, 0f, -0.5f), new Vector3(0.5f, 3f, 0.5f));
        Entity particleSystemObject = Level.createParticleSystem(entity.getParticleSystem(), "model", true);
        if (particleSystemObject != null) {
            engine.addEntity(particleSystemObject);
        }
    } else {
        entityBoundingBox = entity.getModel().getBoundingBox();
        Object3D modelObject = new Object3D("model", entity.getModel());
        modelObject.setDynamicShadowingEnabled(true);
        engine.addEntity(modelObject);
    }
    // create ground object
    Model ground = createGroundModel((entityBoundingBox.getMax().getX() - entityBoundingBox.getMin().getX()) * 1f, (entityBoundingBox.getMax().getZ() - entityBoundingBox.getMin().getZ()) * 1f, entityBoundingBox.getMin().getY() - MathTools.EPSILON);
    // add ground to engine
    Object3D groundObject = new Object3D("ground", ground);
    groundObject.setEnabled(false);
    engine.addEntity(groundObject);
    // add bounding volume if we have any
    for (int i = 0; i < entity.getBoundingVolumeCount(); i++) {
        LevelEditorEntityBoundingVolume boundingVolume = entity.getBoundingVolumeAt(i);
        if (boundingVolume.getModel() == null)
            continue;
        Object3D modelBoundingVolumeObject = new Object3D("model_bv." + i, boundingVolume.getModel());
        modelBoundingVolumeObject.setEnabled(false);
        engine.addEntity(modelBoundingVolumeObject);
    }
    // set up lights
    for (Light light : engine.getLights()) light.setEnabled(false);
    Light light0 = engine.getLightAt(0);
    light0.getAmbient().set(1.0f, 1.0f, 1.0f, 1.0f);
    light0.getDiffuse().set(0.5f, 0.5f, 0.5f, 1f);
    light0.getSpecular().set(1f, 1f, 1f, 1f);
    light0.getPosition().set(entityBoundingBox.getMin().getX() + ((entityBoundingBox.getMax().getX() - entityBoundingBox.getMin().getX()) / 2f), //modelBoundingBox.getMax().getY(),
    entityBoundingBox.getMin().getY() + ((entityBoundingBox.getMax().getY() - entityBoundingBox.getMin().getY()) / 2f), -entityBoundingBox.getMin().getZ() * 4f, 1f);
    light0.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light0.getPosition().getArray()));
    light0.setConstantAttenuation(0.5f);
    light0.setLinearAttenuation(0f);
    light0.setQuadraticAttenuation(0f);
    light0.setSpotExponent(0f);
    light0.setSpotCutOff(180f);
    light0.setEnabled(true);
    // model dimension
    Vector3 dimension = entityBoundingBox.getMax().clone().sub(entityBoundingBox.getMin());
    // determine max dimension on each axis
    float maxAxisDimension = computeMaxAxisDimension(entityBoundingBox);
    // set up cam
    Camera cam = engine.getCamera();
    cam.setZNear(maxAxisDimension / 5000f);
    cam.setZFar(maxAxisDimension);
    // look at
    Vector3 lookAt = entityBoundingBox.getMin().clone().add(dimension.clone().scale(0.5f));
    cam.getLookAt().set(lookAt);
    // look at -> look to vector
    Vector3 lookAtToFromVector = new Vector3(0f, 0f, +(maxAxisDimension * 1.2f));
    // apply look from rotations
    Vector3 lookAtToFromVectorTransformed = new Vector3();
    Vector3 lookAtToFromVectorScaled = new Vector3();
    Vector3 upVector = new Vector3();
    lookFromRotations.getTransformationsMatrix().multiply(lookAtToFromVector, lookAtToFromVectorTransformed);
    lookAtToFromVectorScaled.set(lookAtToFromVectorTransformed).scale(scale);
    lookFromRotations.getRotations().get(2).getQuaternion().multiply(new Vector3(0f, 1f, 0f), upVector);
    // look from with rotations
    Vector3 lookFrom = lookAt.clone().add(lookAtToFromVectorScaled);
    cam.getLookFrom().set(lookFrom);
    // up vector
    cam.getUpVector().set(upVector);
}
Also used : LevelEditorEntityBoundingVolume(net.drewke.tdme.tools.shared.model.LevelEditorEntityBoundingVolume) Entity(net.drewke.tdme.engine.Entity) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity) FacesEntity(net.drewke.tdme.engine.model.FacesEntity) Light(net.drewke.tdme.engine.Light) BoundingBox(net.drewke.tdme.engine.primitives.BoundingBox) Model(net.drewke.tdme.engine.model.Model) Vector3(net.drewke.tdme.math.Vector3) Camera(net.drewke.tdme.engine.Camera) Object3D(net.drewke.tdme.engine.Object3D)

Example 12 with LevelEditorEntity

use of net.drewke.tdme.tools.shared.model.LevelEditorEntity in project tdme by andreasdr.

the class ParticleSystemView method loadParticleSystem.

/**
	 * Load a particle system
	 */
private void loadParticleSystem() {
    //
    System.out.println("Particle system file: " + particleSystemFile);
    // scene
    try {
        LevelEditorEntity oldEntity = entity;
        // add entity to library
        entity = loadParticleSystem(particleSystemFile.getName(), "", particleSystemFile.getParentFile().getAbsolutePath(), particleSystemFile.getName());
        onLoadParticleSystem(oldEntity, entity);
    } catch (Exception exception) {
        exception.printStackTrace();
        popUps.getInfoDialogScreenController().show("Warning", exception.getMessage());
    }
}
Also used : LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity) IOException(java.io.IOException)

Example 13 with LevelEditorEntity

use of net.drewke.tdme.tools.shared.model.LevelEditorEntity in project tdme by andreasdr.

the class ParticleSystemView method loadParticleSystem.

/**
	 * Load particle system
	 * @param name
	 * @param description
	 * @param path name
	 * @param file name
	 * @return level editor entity
	 * @throws Exception
	 */
protected LevelEditorEntity loadParticleSystem(String name, String description, String pathName, String fileName) throws Exception {
    if (fileName.toLowerCase().endsWith(".tps")) {
        LevelEditorEntity levelEditorEntity = ModelMetaDataFileImport.doImport(LevelEditorEntity.ID_NONE, pathName, fileName);
        levelEditorEntity.setDefaultBoundingVolumes();
        return levelEditorEntity;
    }
    return null;
}
Also used : LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity)

Example 14 with LevelEditorEntity

use of net.drewke.tdme.tools.shared.model.LevelEditorEntity in project tdme by andreasdr.

the class ModelViewerView method loadModel.

/**
	 * Load a model
	 */
private void loadModel() {
    //
    System.out.println("Model file: " + modelFile);
    // scene
    try {
        LevelEditorEntity oldModel = entity;
        // add entity to library
        entity = loadModel(modelFile.getName(), "", modelFile.getParentFile().getAbsolutePath(), modelFile.getName(), new Vector3());
        onLoadModel(oldModel, entity);
    } catch (Exception exception) {
        popUps.getInfoDialogScreenController().show("Warning", exception.getMessage());
    }
}
Also used : Vector3(net.drewke.tdme.math.Vector3) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity) IOException(java.io.IOException)

Example 15 with LevelEditorEntity

use of net.drewke.tdme.tools.shared.model.LevelEditorEntity in project tdme by andreasdr.

the class ModelViewerView method loadModel.

/**
	 * Load model
	 * @param name
	 * @param description
	 * @param path name
	 * @param file name
	 * @param pivot
	 * @return level editor entity
	 * @throws Exception
	 */
protected LevelEditorEntity loadModel(String name, String description, String pathName, String fileName, Vector3 pivot) throws Exception {
    if (fileName.toLowerCase().endsWith(".dae")) {
        Model model = DAEReader.read(modelFile.getParentFile().getCanonicalPath(), modelFile.getName());
        LevelEditorEntity levelEditorEntity = new LevelEditorEntity(LevelEditorEntity.ID_NONE, LevelEditorEntity.EntityType.MODEL, name, description, null, pathName + File.separator + fileName, model.getId().replace("\\", "_").replace("/", "_").replace(":", "_") + ".png", model, pivot);
        levelEditorEntity.setDefaultBoundingVolumes();
        return levelEditorEntity;
    } else if (fileName.toLowerCase().endsWith(".tm")) {
        Model model = TMReader.read(modelFile.getParentFile().getCanonicalPath(), modelFile.getName());
        LevelEditorEntity levelEditorEntity = new LevelEditorEntity(LevelEditorEntity.ID_NONE, LevelEditorEntity.EntityType.MODEL, name, description, null, pathName + File.separator + fileName, model.getId().replace("\\", "_").replace("/", "_").replace(":", "_") + ".png", model, pivot);
        levelEditorEntity.setDefaultBoundingVolumes();
        return levelEditorEntity;
    } else if (fileName.toLowerCase().endsWith(".tmm")) {
        LevelEditorEntity levelEditorEntity = ModelMetaDataFileImport.doImport(LevelEditorEntity.ID_NONE, pathName, fileName);
        levelEditorEntity.setDefaultBoundingVolumes();
        return levelEditorEntity;
    }
    return null;
}
Also used : Model(net.drewke.tdme.engine.model.Model) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity)

Aggregations

LevelEditorEntity (net.drewke.tdme.tools.shared.model.LevelEditorEntity)20 Vector3 (net.drewke.tdme.math.Vector3)7 IOException (java.io.IOException)6 File (java.io.File)4 Entity (net.drewke.tdme.engine.Entity)4 Transformations (net.drewke.tdme.engine.Transformations)4 Model (net.drewke.tdme.engine.model.Model)4 Object3D (net.drewke.tdme.engine.Object3D)3 Rotation (net.drewke.tdme.engine.Rotation)3 EmptyView (net.drewke.tdme.tools.leveleditor.views.EmptyView)3 ModelViewerView (net.drewke.tdme.tools.leveleditor.views.ModelViewerView)3 ParticleSystemView (net.drewke.tdme.tools.leveleditor.views.ParticleSystemView)3 TriggerView (net.drewke.tdme.tools.leveleditor.views.TriggerView)3 LevelEditorEntityLibrary (net.drewke.tdme.tools.shared.model.LevelEditorEntityLibrary)3 LevelEditorObject (net.drewke.tdme.tools.shared.model.LevelEditorObject)3 PropertyModelClass (net.drewke.tdme.tools.shared.model.PropertyModelClass)3 JSONObject (org.json.JSONObject)3 InputStream (java.io.InputStream)2 FacesEntity (net.drewke.tdme.engine.model.FacesEntity)2 Action (net.drewke.tdme.gui.events.Action)2