Search in sources :

Example 1 with Capsule

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

the class ModelMetaDataFileExport method exportToJSON.

/**
	 * Export model meta data file to JSON node
	 * @param entity
	 */
public static JSONObject exportToJSON(LevelEditorEntity entity) throws Exception {
    JSONObject jEntityRoot = new JSONObject();
    // re-convert to tm if having a model file
    if (entity.getType() == EntityType.MODEL && entity.getFileName() != null) {
        String modelPathName = Tools.getPath(entity.getFileName());
        String modelFileName = Tools.getFileName(entity.getFileName()) + (entity.getFileName().endsWith(".tm") == false ? ".tm" : "");
        TMWriter.write(entity.getModel(), modelPathName, modelFileName);
        jEntityRoot.put("file", modelPathName + "/" + modelFileName);
        // try to copy thumbnail
        try {
            String thumbnail = modelFileName + ".png";
            jEntityRoot.put("thumbnail", thumbnail);
            copyFile(new File("./tmp", entity.getThumbnail()), new File(Tools.getPath(entity.getFileName()), thumbnail));
        } catch (IOException ioe) {
            System.out.println("ModelMetaDataFileExport::export(): Could not copy thumbnail for '" + entity.getFileName() + "'");
        }
    }
    // general data
    jEntityRoot.put("version", "0.99");
    jEntityRoot.put("type", entity.getType());
    jEntityRoot.put("name", entity.getName());
    jEntityRoot.put("descr", entity.getDescription());
    jEntityRoot.put("px", entity.getPivot().getX());
    jEntityRoot.put("py", entity.getPivot().getY());
    jEntityRoot.put("pz", entity.getPivot().getZ());
    // export particle system
    if (entity.getType() == EntityType.PARTICLESYSTEM) {
        LevelEditorEntityParticleSystem particleSystem = entity.getParticleSystem();
        JSONObject jParticleSystem = new JSONObject();
        // type
        jParticleSystem.put("t", particleSystem.getType().toString());
        switch(particleSystem.getType()) {
            case NONE:
                {
                    break;
                }
            case OBJECT_PARTICLE_SYSTEM:
                {
                    JSONObject jObjectParticleSystem = new JSONObject();
                    // do we have a model file name?
                    if (particleSystem.getObjectParticleSystem().getModelFile() != null && particleSystem.getObjectParticleSystem().getModelFile().length() > 0) {
                        // yep, convert to .tm
                        String modelPathName = Tools.getPath(particleSystem.getObjectParticleSystem().getModelFile());
                        String modelFileName = Tools.getFileName(particleSystem.getObjectParticleSystem().getModelFile() + (particleSystem.getObjectParticleSystem().getModelFile().endsWith(".tm") == false ? ".tm" : ""));
                        TMWriter.write(particleSystem.getObjectParticleSystem().getModel(), modelPathName, modelFileName);
                        // and store to file
                        particleSystem.getObjectParticleSystem().setModelFile(modelPathName + "/" + modelFileName);
                    }
                    jObjectParticleSystem.put("mc", particleSystem.getObjectParticleSystem().getMaxCount());
                    jObjectParticleSystem.put("sx", particleSystem.getObjectParticleSystem().getScale().getX());
                    jObjectParticleSystem.put("sy", particleSystem.getObjectParticleSystem().getScale().getY());
                    jObjectParticleSystem.put("sz", particleSystem.getObjectParticleSystem().getScale().getZ());
                    jObjectParticleSystem.put("mf", particleSystem.getObjectParticleSystem().getModelFile());
                    jObjectParticleSystem.put("ae", particleSystem.getObjectParticleSystem().isAutoEmit());
                    jParticleSystem.put("ops", jObjectParticleSystem);
                    break;
                }
            case POINT_PARTICLE_SYSTEM:
                {
                    JSONObject jPointParticleSystem = new JSONObject();
                    jPointParticleSystem.put("mp", particleSystem.getPointParticleSystem().getMaxPoints());
                    jPointParticleSystem.put("ae", particleSystem.getPointParticleSystem().isAutoEmit());
                    jParticleSystem.put("pps", jPointParticleSystem);
                    break;
                }
            default:
                {
                    System.out.println("ModelMetaDataFileExport::export(): unknown particle system type '" + particleSystem.getType() + "'");
                    break;
                }
        }
        // emitter
        jParticleSystem.put("e", particleSystem.getEmitter().toString());
        switch(particleSystem.getEmitter()) {
            case NONE:
                {
                    break;
                }
            case POINT_PARTICLE_EMITTER:
                {
                    JSONObject jPointParticleEmitter = new JSONObject();
                    PointParticleEmitter emitter = particleSystem.getPointParticleEmitter();
                    jPointParticleEmitter.put("c", emitter.getCount());
                    jPointParticleEmitter.put("lt", emitter.getLifeTime());
                    jPointParticleEmitter.put("ltrnd", emitter.getLifeTimeRnd());
                    jPointParticleEmitter.put("m", emitter.getMass());
                    jPointParticleEmitter.put("mrnd", emitter.getMassRnd());
                    jPointParticleEmitter.put("px", emitter.getPosition().getX());
                    jPointParticleEmitter.put("py", emitter.getPosition().getY());
                    jPointParticleEmitter.put("pz", emitter.getPosition().getZ());
                    jPointParticleEmitter.put("vx", emitter.getVelocity().getX());
                    jPointParticleEmitter.put("vy", emitter.getVelocity().getY());
                    jPointParticleEmitter.put("vz", emitter.getVelocity().getZ());
                    jPointParticleEmitter.put("vrndx", emitter.getVelocityRnd().getX());
                    jPointParticleEmitter.put("vrndy", emitter.getVelocityRnd().getY());
                    jPointParticleEmitter.put("vrndz", emitter.getVelocityRnd().getZ());
                    jPointParticleEmitter.put("csr", emitter.getColorStart().getRed());
                    jPointParticleEmitter.put("csg", emitter.getColorStart().getGreen());
                    jPointParticleEmitter.put("csb", emitter.getColorStart().getBlue());
                    jPointParticleEmitter.put("csa", emitter.getColorStart().getAlpha());
                    jPointParticleEmitter.put("cer", emitter.getColorEnd().getRed());
                    jPointParticleEmitter.put("ceg", emitter.getColorEnd().getGreen());
                    jPointParticleEmitter.put("ceb", emitter.getColorEnd().getBlue());
                    jPointParticleEmitter.put("cea", emitter.getColorEnd().getAlpha());
                    jParticleSystem.put("ppe", jPointParticleEmitter);
                    break;
                }
            case BOUNDINGBOX_PARTICLE_EMITTER:
                {
                    JSONObject jBoundingBoxParticleEmitter = new JSONObject();
                    BoundingBoxParticleEmitter emitter = particleSystem.getBoundingBoxParticleEmitters();
                    jBoundingBoxParticleEmitter.put("c", emitter.getCount());
                    jBoundingBoxParticleEmitter.put("lt", emitter.getLifeTime());
                    jBoundingBoxParticleEmitter.put("ltrnd", emitter.getLifeTimeRnd());
                    jBoundingBoxParticleEmitter.put("m", emitter.getMass());
                    jBoundingBoxParticleEmitter.put("mrnd", emitter.getMassRnd());
                    jBoundingBoxParticleEmitter.put("vx", emitter.getVelocity().getX());
                    jBoundingBoxParticleEmitter.put("vy", emitter.getVelocity().getY());
                    jBoundingBoxParticleEmitter.put("vz", emitter.getVelocity().getZ());
                    jBoundingBoxParticleEmitter.put("vrndx", emitter.getVelocityRnd().getX());
                    jBoundingBoxParticleEmitter.put("vrndy", emitter.getVelocityRnd().getY());
                    jBoundingBoxParticleEmitter.put("vrndz", emitter.getVelocityRnd().getZ());
                    jBoundingBoxParticleEmitter.put("csr", emitter.getColorStart().getRed());
                    jBoundingBoxParticleEmitter.put("csg", emitter.getColorStart().getGreen());
                    jBoundingBoxParticleEmitter.put("csb", emitter.getColorStart().getBlue());
                    jBoundingBoxParticleEmitter.put("csa", emitter.getColorStart().getAlpha());
                    jBoundingBoxParticleEmitter.put("cer", emitter.getColorEnd().getRed());
                    jBoundingBoxParticleEmitter.put("ceg", emitter.getColorEnd().getGreen());
                    jBoundingBoxParticleEmitter.put("ceb", emitter.getColorEnd().getBlue());
                    jBoundingBoxParticleEmitter.put("cea", emitter.getColorEnd().getAlpha());
                    jBoundingBoxParticleEmitter.put("ocx", emitter.getObbCenter().getX());
                    jBoundingBoxParticleEmitter.put("ocy", emitter.getObbCenter().getY());
                    jBoundingBoxParticleEmitter.put("ocz", emitter.getObbCenter().getZ());
                    jBoundingBoxParticleEmitter.put("ohex", emitter.getObbHalfextension().getX());
                    jBoundingBoxParticleEmitter.put("ohey", emitter.getObbHalfextension().getY());
                    jBoundingBoxParticleEmitter.put("ohez", emitter.getObbHalfextension().getZ());
                    jBoundingBoxParticleEmitter.put("oa0x", emitter.getObbAxis0().getX());
                    jBoundingBoxParticleEmitter.put("oa0y", emitter.getObbAxis0().getY());
                    jBoundingBoxParticleEmitter.put("oa0z", emitter.getObbAxis0().getZ());
                    jBoundingBoxParticleEmitter.put("oa1x", emitter.getObbAxis1().getX());
                    jBoundingBoxParticleEmitter.put("oa1y", emitter.getObbAxis1().getY());
                    jBoundingBoxParticleEmitter.put("oa1z", emitter.getObbAxis1().getZ());
                    jBoundingBoxParticleEmitter.put("oa2x", emitter.getObbAxis2().getX());
                    jBoundingBoxParticleEmitter.put("oa2y", emitter.getObbAxis2().getY());
                    jBoundingBoxParticleEmitter.put("oa2z", emitter.getObbAxis2().getZ());
                    jParticleSystem.put("bbpe", jBoundingBoxParticleEmitter);
                    break;
                }
            case CIRCLE_PARTICLE_EMITTER:
                {
                    JSONObject jCircleParticleEmitter = new JSONObject();
                    CircleParticleEmitter emitter = particleSystem.getCircleParticleEmitter();
                    jCircleParticleEmitter.put("c", emitter.getCount());
                    jCircleParticleEmitter.put("lt", emitter.getLifeTime());
                    jCircleParticleEmitter.put("ltrnd", emitter.getLifeTimeRnd());
                    jCircleParticleEmitter.put("m", emitter.getMass());
                    jCircleParticleEmitter.put("mrnd", emitter.getMassRnd());
                    jCircleParticleEmitter.put("vx", emitter.getVelocity().getX());
                    jCircleParticleEmitter.put("vy", emitter.getVelocity().getY());
                    jCircleParticleEmitter.put("vz", emitter.getVelocity().getZ());
                    jCircleParticleEmitter.put("vrndx", emitter.getVelocityRnd().getX());
                    jCircleParticleEmitter.put("vrndy", emitter.getVelocityRnd().getY());
                    jCircleParticleEmitter.put("vrndz", emitter.getVelocityRnd().getZ());
                    jCircleParticleEmitter.put("csr", emitter.getColorStart().getRed());
                    jCircleParticleEmitter.put("csg", emitter.getColorStart().getGreen());
                    jCircleParticleEmitter.put("csb", emitter.getColorStart().getBlue());
                    jCircleParticleEmitter.put("csa", emitter.getColorStart().getAlpha());
                    jCircleParticleEmitter.put("cer", emitter.getColorEnd().getRed());
                    jCircleParticleEmitter.put("ceg", emitter.getColorEnd().getGreen());
                    jCircleParticleEmitter.put("ceb", emitter.getColorEnd().getBlue());
                    jCircleParticleEmitter.put("cea", emitter.getColorEnd().getAlpha());
                    jCircleParticleEmitter.put("cx", emitter.getCenter().getX());
                    jCircleParticleEmitter.put("cy", emitter.getCenter().getY());
                    jCircleParticleEmitter.put("cz", emitter.getCenter().getZ());
                    jCircleParticleEmitter.put("r", emitter.getRadius());
                    jCircleParticleEmitter.put("a0x", emitter.getAxis0().getX());
                    jCircleParticleEmitter.put("a0y", emitter.getAxis0().getY());
                    jCircleParticleEmitter.put("a0z", emitter.getAxis0().getZ());
                    jCircleParticleEmitter.put("a1x", emitter.getAxis1().getX());
                    jCircleParticleEmitter.put("a1y", emitter.getAxis1().getY());
                    jCircleParticleEmitter.put("a1z", emitter.getAxis1().getZ());
                    jParticleSystem.put("cpe", jCircleParticleEmitter);
                    break;
                }
            case CIRCLE_PARTICLE_EMITTER_PLANE_VELOCITY:
                {
                    JSONObject jCircleParticleEmitterPlaneVelocity = new JSONObject();
                    CircleParticleEmitterPlaneVelocity emitter = particleSystem.getCircleParticleEmitterPlaneVelocity();
                    jCircleParticleEmitterPlaneVelocity.put("c", emitter.getCount());
                    jCircleParticleEmitterPlaneVelocity.put("lt", emitter.getLifeTime());
                    jCircleParticleEmitterPlaneVelocity.put("ltrnd", emitter.getLifeTimeRnd());
                    jCircleParticleEmitterPlaneVelocity.put("m", emitter.getMass());
                    jCircleParticleEmitterPlaneVelocity.put("mrnd", emitter.getMassRnd());
                    jCircleParticleEmitterPlaneVelocity.put("v", emitter.getVelocity());
                    jCircleParticleEmitterPlaneVelocity.put("vrnd", emitter.getVelocityRnd());
                    jCircleParticleEmitterPlaneVelocity.put("csr", emitter.getColorStart().getRed());
                    jCircleParticleEmitterPlaneVelocity.put("csg", emitter.getColorStart().getGreen());
                    jCircleParticleEmitterPlaneVelocity.put("csb", emitter.getColorStart().getBlue());
                    jCircleParticleEmitterPlaneVelocity.put("csa", emitter.getColorStart().getAlpha());
                    jCircleParticleEmitterPlaneVelocity.put("cer", emitter.getColorEnd().getRed());
                    jCircleParticleEmitterPlaneVelocity.put("ceg", emitter.getColorEnd().getGreen());
                    jCircleParticleEmitterPlaneVelocity.put("ceb", emitter.getColorEnd().getBlue());
                    jCircleParticleEmitterPlaneVelocity.put("cea", emitter.getColorEnd().getAlpha());
                    jCircleParticleEmitterPlaneVelocity.put("cx", emitter.getCenter().getX());
                    jCircleParticleEmitterPlaneVelocity.put("cy", emitter.getCenter().getY());
                    jCircleParticleEmitterPlaneVelocity.put("cz", emitter.getCenter().getZ());
                    jCircleParticleEmitterPlaneVelocity.put("r", emitter.getRadius());
                    jCircleParticleEmitterPlaneVelocity.put("a0x", emitter.getAxis0().getX());
                    jCircleParticleEmitterPlaneVelocity.put("a0y", emitter.getAxis0().getY());
                    jCircleParticleEmitterPlaneVelocity.put("a0z", emitter.getAxis0().getZ());
                    jCircleParticleEmitterPlaneVelocity.put("a1x", emitter.getAxis1().getX());
                    jCircleParticleEmitterPlaneVelocity.put("a1y", emitter.getAxis1().getY());
                    jCircleParticleEmitterPlaneVelocity.put("a1z", emitter.getAxis1().getZ());
                    jParticleSystem.put("cpeev", jCircleParticleEmitterPlaneVelocity);
                    break;
                }
            case SPHERE_PARTICLE_EMITTER:
                {
                    JSONObject jSphereParticleEmitter = new JSONObject();
                    SphereParticleEmitter emitter = particleSystem.getSphereParticleEmitter();
                    jSphereParticleEmitter.put("c", emitter.getCount());
                    jSphereParticleEmitter.put("lt", emitter.getLifeTime());
                    jSphereParticleEmitter.put("ltrnd", emitter.getLifeTimeRnd());
                    jSphereParticleEmitter.put("m", emitter.getMass());
                    jSphereParticleEmitter.put("mrnd", emitter.getMassRnd());
                    jSphereParticleEmitter.put("vx", emitter.getVelocity().getX());
                    jSphereParticleEmitter.put("vy", emitter.getVelocity().getY());
                    jSphereParticleEmitter.put("vz", emitter.getVelocity().getZ());
                    jSphereParticleEmitter.put("vrndx", emitter.getVelocityRnd().getX());
                    jSphereParticleEmitter.put("vrndy", emitter.getVelocityRnd().getY());
                    jSphereParticleEmitter.put("vrndz", emitter.getVelocityRnd().getZ());
                    jSphereParticleEmitter.put("csr", emitter.getColorStart().getRed());
                    jSphereParticleEmitter.put("csg", emitter.getColorStart().getGreen());
                    jSphereParticleEmitter.put("csb", emitter.getColorStart().getBlue());
                    jSphereParticleEmitter.put("csa", emitter.getColorStart().getAlpha());
                    jSphereParticleEmitter.put("cer", emitter.getColorEnd().getRed());
                    jSphereParticleEmitter.put("ceg", emitter.getColorEnd().getGreen());
                    jSphereParticleEmitter.put("ceb", emitter.getColorEnd().getBlue());
                    jSphereParticleEmitter.put("cea", emitter.getColorEnd().getAlpha());
                    jSphereParticleEmitter.put("cx", emitter.getCenter().getX());
                    jSphereParticleEmitter.put("cy", emitter.getCenter().getY());
                    jSphereParticleEmitter.put("cz", emitter.getCenter().getZ());
                    jSphereParticleEmitter.put("r", emitter.getRadius());
                    jParticleSystem.put("spe", jSphereParticleEmitter);
                    break;
                }
            default:
                System.out.println("ModelMetaDataFileExport::export(): unknown particle system emitter '" + particleSystem.getEmitter() + "'");
        }
        // add to file
        jEntityRoot.put("ps", jParticleSystem);
    }
    // bounding volume
    JSONArray jBoundingVolumes = new JSONArray();
    for (int i = 0; i < entity.getBoundingVolumeCount(); i++) {
        LevelEditorEntityBoundingVolume entityBoundingVolume = entity.getBoundingVolumeAt(i);
        BoundingVolume bv = entityBoundingVolume.getBoundingVolume();
        if (bv == null)
            continue;
        JSONObject jBoundingVolume = new JSONObject();
        if (bv == null) {
            jBoundingVolume.put("type", "none");
            jBoundingVolumes.put(jBoundingVolume);
        } else if (bv instanceof Sphere) {
            Sphere sphere = (Sphere) bv;
            jBoundingVolume.put("type", "sphere");
            jBoundingVolume.put("cx", sphere.getCenter().getX());
            jBoundingVolume.put("cy", sphere.getCenter().getY());
            jBoundingVolume.put("cz", sphere.getCenter().getZ());
            jBoundingVolume.put("r", sphere.getRadius());
            jBoundingVolumes.put(jBoundingVolume);
        } else if (bv instanceof Capsule) {
            Capsule capsule = (Capsule) bv;
            jBoundingVolume.put("type", "capsule");
            jBoundingVolume.put("ax", capsule.getA().getX());
            jBoundingVolume.put("ay", capsule.getA().getY());
            jBoundingVolume.put("az", capsule.getA().getZ());
            jBoundingVolume.put("bx", capsule.getB().getX());
            jBoundingVolume.put("by", capsule.getB().getY());
            jBoundingVolume.put("bz", capsule.getB().getZ());
            jBoundingVolume.put("r", capsule.getRadius());
            jBoundingVolumes.put(jBoundingVolume);
        } else if (bv instanceof BoundingBox) {
            BoundingBox aabb = (BoundingBox) bv;
            jBoundingVolume.put("type", "aabb");
            jBoundingVolume.put("mix", aabb.getMin().getX());
            jBoundingVolume.put("miy", aabb.getMin().getY());
            jBoundingVolume.put("miz", aabb.getMin().getZ());
            jBoundingVolume.put("max", aabb.getMax().getX());
            jBoundingVolume.put("may", aabb.getMax().getY());
            jBoundingVolume.put("maz", aabb.getMax().getZ());
            jBoundingVolumes.put(jBoundingVolume);
        } else if (bv instanceof OrientedBoundingBox) {
            OrientedBoundingBox obb = (OrientedBoundingBox) bv;
            jBoundingVolume.put("type", "obb");
            jBoundingVolume.put("cx", obb.getCenter().getX());
            jBoundingVolume.put("cy", obb.getCenter().getY());
            jBoundingVolume.put("cz", obb.getCenter().getZ());
            jBoundingVolume.put("a0x", obb.getAxes()[0].getX());
            jBoundingVolume.put("a0y", obb.getAxes()[0].getY());
            jBoundingVolume.put("a0z", obb.getAxes()[0].getZ());
            jBoundingVolume.put("a1x", obb.getAxes()[1].getX());
            jBoundingVolume.put("a1y", obb.getAxes()[1].getY());
            jBoundingVolume.put("a1z", obb.getAxes()[1].getZ());
            jBoundingVolume.put("a2x", obb.getAxes()[2].getX());
            jBoundingVolume.put("a2y", obb.getAxes()[2].getY());
            jBoundingVolume.put("a2z", obb.getAxes()[2].getZ());
            jBoundingVolume.put("hex", obb.getHalfExtension().getX());
            jBoundingVolume.put("hey", obb.getHalfExtension().getY());
            jBoundingVolume.put("hez", obb.getHalfExtension().getZ());
            jBoundingVolumes.put(jBoundingVolume);
        } else if (bv instanceof ConvexMesh) {
            ConvexMesh mesh = (ConvexMesh) bv;
            jBoundingVolume.put("type", "convexmesh");
            jBoundingVolume.put("file", entityBoundingVolume.getModelMeshFile());
            JSONArray jMeshTriangles = new JSONArray();
            int triangleIdx = 0;
            for (Triangle triangle : mesh.getTriangles()) {
                JSONArray jMeshTriangleVertices = new JSONArray();
                int vertexIdx = 0;
                for (Vector3 vertex : triangle.getVertices()) {
                    JSONArray jMeshTriangleVertex = new JSONArray();
                    for (int vcIdx = 0; vcIdx < 3; vcIdx++) {
                        jMeshTriangleVertex.put(vcIdx, vertex.getArray()[vcIdx]);
                    }
                    jMeshTriangleVertices.put(vertexIdx++, jMeshTriangleVertex);
                }
                jMeshTriangles.put(triangleIdx++, jMeshTriangleVertices);
            }
            jBoundingVolume.put("t", jMeshTriangles);
            jBoundingVolumes.put(jBoundingVolume);
        }
    }
    jEntityRoot.put("bvs", jBoundingVolumes);
    // model properties
    JSONArray jModelProperties = new JSONArray();
    for (PropertyModelClass modelProperty : entity.getProperties()) {
        JSONObject jObjectProperty = new JSONObject();
        jObjectProperty.put("name", modelProperty.getName());
        jObjectProperty.put("value", modelProperty.getValue());
        jModelProperties.put(jObjectProperty);
    }
    jEntityRoot.put("properties", jModelProperties);
    //
    return jEntityRoot;
}
Also used : LevelEditorEntityBoundingVolume(net.drewke.tdme.tools.shared.model.LevelEditorEntityBoundingVolume) PropertyModelClass(net.drewke.tdme.tools.shared.model.PropertyModelClass) CircleParticleEmitterPlaneVelocity(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitterPlaneVelocity) JSONArray(org.json.JSONArray) Triangle(net.drewke.tdme.engine.primitives.Triangle) CircleParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitter) Capsule(net.drewke.tdme.engine.primitives.Capsule) ConvexMesh(net.drewke.tdme.engine.primitives.ConvexMesh) Vector3(net.drewke.tdme.math.Vector3) IOException(java.io.IOException) LevelEditorEntityParticleSystem(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem) Sphere(net.drewke.tdme.engine.primitives.Sphere) OrientedBoundingBox(net.drewke.tdme.engine.primitives.OrientedBoundingBox) JSONObject(org.json.JSONObject) BoundingBox(net.drewke.tdme.engine.primitives.BoundingBox) OrientedBoundingBox(net.drewke.tdme.engine.primitives.OrientedBoundingBox) LevelEditorEntityBoundingVolume(net.drewke.tdme.tools.shared.model.LevelEditorEntityBoundingVolume) BoundingVolume(net.drewke.tdme.engine.primitives.BoundingVolume) BoundingBoxParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.BoundingBoxParticleEmitter) File(java.io.File) SphereParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.SphereParticleEmitter) PointParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.PointParticleEmitter)

Example 2 with Capsule

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

the class EntityBoundingVolumeView method setBoundingVolumes.

/**
	 * Set bounding volumes
	 * @param entity
	 */
public void setBoundingVolumes(LevelEditorEntity entity) {
    // set up default bounding volumes
    for (int i = 0; i < EntityBoundingVolumeSubScreenController.MODEL_BOUNDINGVOLUME_COUNT; i++) {
        resetBoundingVolume(entity, i);
    }
    // set up existing bounding volumes
    for (int i = 0; i < entity.getBoundingVolumeCount(); i++) {
        LevelEditorEntityBoundingVolume bv = entity.getBoundingVolumeAt(i);
        if (bv == null) {
            modelViewerScreenController.selectBoundingVolume(i, EntityBoundingVolumeSubScreenController.BoundingVolumeType.NONE);
            continue;
        } else if (bv.getBoundingVolume() instanceof Sphere) {
            Sphere sphere = (Sphere) bv.getBoundingVolume();
            modelViewerScreenController.setupSphere(i, sphere.getCenter(), sphere.getRadius());
            modelViewerScreenController.selectBoundingVolume(i, EntityBoundingVolumeSubScreenController.BoundingVolumeType.SPHERE);
        } else if (bv.getBoundingVolume() instanceof Capsule) {
            Capsule capsule = (Capsule) bv.getBoundingVolume();
            modelViewerScreenController.setupCapsule(i, capsule.getA(), capsule.getB(), capsule.getRadius());
            modelViewerScreenController.selectBoundingVolume(i, EntityBoundingVolumeSubScreenController.BoundingVolumeType.CAPSULE);
        } else if (bv.getBoundingVolume() instanceof BoundingBox) {
            BoundingBox aabb = (BoundingBox) bv.getBoundingVolume();
            modelViewerScreenController.setupBoundingBox(i, aabb.getMin(), aabb.getMax());
            modelViewerScreenController.selectBoundingVolume(i, EntityBoundingVolumeSubScreenController.BoundingVolumeType.BOUNDINGBOX);
        } else if (bv.getBoundingVolume() instanceof OrientedBoundingBox) {
            OrientedBoundingBox obb = (OrientedBoundingBox) bv.getBoundingVolume();
            modelViewerScreenController.setupOrientedBoundingBox(i, obb.getCenter(), obb.getAxes()[0], obb.getAxes()[1], obb.getAxes()[2], obb.getHalfExtension());
            modelViewerScreenController.selectBoundingVolume(i, EntityBoundingVolumeSubScreenController.BoundingVolumeType.ORIENTEDBOUNDINGBOX);
        } else if (bv.getBoundingVolume() instanceof ConvexMesh) {
            modelViewerScreenController.setupConvexMesh(i, bv.getModelMeshFile());
            modelViewerScreenController.selectBoundingVolume(i, EntityBoundingVolumeSubScreenController.BoundingVolumeType.CONVEXMESH);
        }
        // enable bounding volume and set type in GUI
        modelViewerScreenController.enableBoundingVolume(i);
        modelViewerScreenController.setupModelBoundingVolumeType(entity, i);
    }
}
Also used : LevelEditorEntityBoundingVolume(net.drewke.tdme.tools.shared.model.LevelEditorEntityBoundingVolume) Sphere(net.drewke.tdme.engine.primitives.Sphere) OrientedBoundingBox(net.drewke.tdme.engine.primitives.OrientedBoundingBox) OrientedBoundingBox(net.drewke.tdme.engine.primitives.OrientedBoundingBox) BoundingBox(net.drewke.tdme.engine.primitives.BoundingBox) Capsule(net.drewke.tdme.engine.primitives.Capsule) ConvexMesh(net.drewke.tdme.engine.primitives.ConvexMesh)

Example 3 with Capsule

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

the class PhysicsTest1 method init.

/*
	 * (non-Javadoc)
	 * @see com.jogamp.opengl.GLEventListener#init(com.jogamp.opengl.GLAutoDrawable)
	 */
public void init(GLAutoDrawable drawable) {
    drawable.getGL().setSwapInterval(0);
    engine.init(drawable);
    Object3D entity;
    // cam
    Camera cam = engine.getCamera();
    cam.setZNear(0.10f);
    cam.setZFar(50.00f);
    cam.getLookFrom().set(0f, 4f * 2.5f, -6f * 2.5f);
    cam.getLookAt().set(0f, 0.0f, 0f);
    cam.computeUpVector(cam.getLookFrom(), cam.getLookAt(), cam.getUpVector());
    // lights
    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(0f, 20000f, 0f, 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);
    // ground
    OrientedBoundingBox ground = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(8f, 1f, 8f));
    Model groundModel = PrimitiveModel.createModel(ground, "ground_model");
    groundModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.8f, 0.8f, 1f);
    groundModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 1f, 1f, 1f);
    entity = new Object3D("ground", groundModel);
    // entity.getRotations().add(new Rotation(10f, OrientedBoundingBox.AABB_AXIS_Z.clone()));
    entity.update();
    engine.addEntity(entity);
    world.addStaticRigidBody("ground", true, RIGID_TYPEID_STANDARD, entity, ground, 0.5f);
    // side
    OrientedBoundingBox side = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(1f, 16f, 8f));
    Model sideModel = PrimitiveModel.createModel(side, "side_model");
    sideModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.8f, 0.8f, 1f);
    sideModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 1f, 1f, 1f);
    // far
    OrientedBoundingBox nearFar = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(8f, 16f, 1f));
    Model nearFarModel = PrimitiveModel.createModel(nearFar, "far_model");
    nearFarModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.8f, 0.8f, 1f);
    nearFarModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 1f, 1f, 1f);
    // far
    entity = new Object3D("far", nearFarModel);
    entity.getTranslation().addZ(+9f);
    entity.update();
    engine.addEntity(entity);
    world.addStaticRigidBody("far", true, RIGID_TYPEID_STANDARD, entity, nearFar, 0.5f);
    // near
    entity = new Object3D("near", nearFarModel);
    entity.getTranslation().addZ(-9f);
    entity.getEffectColorMul().set(1f, 1f, 1f, 0f);
    entity.update();
    engine.addEntity(entity);
    world.addStaticRigidBody("near", true, RIGID_TYPEID_STANDARD, entity, nearFar, 0.5f);
    // side left
    entity = new Object3D("sideright", sideModel);
    entity.getTranslation().addX(-9f);
    entity.update();
    engine.addEntity(entity);
    world.addStaticRigidBody("sideright", true, RIGID_TYPEID_STANDARD, entity, side, 0.5f);
    // side right
    entity = new Object3D("sideleft", sideModel);
    entity.getTranslation().addX(9f);
    entity.update();
    engine.addEntity(entity);
    world.addStaticRigidBody("sideleft", true, RIGID_TYPEID_STANDARD, entity, side, 0.5f);
    // box
    OrientedBoundingBox box = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(0.6f, 0.6f, 0.6f));
    Model boxModel = PrimitiveModel.createModel(box, "box_model");
    boxModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.5f, 0.5f, 1f);
    boxModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 0f, 0f, 1f);
    // boxes
    for (int i = 0; i < BOX_COUNT; i++) {
        entity = new Object3D("box" + i, boxModel);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(10f + i * 3.0f);
        entity.getTranslation().addX(-2f + i * 0.1f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("box" + i, true, RIGID_TYPEID_STANDARD, entity, box, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(box, 100f, 1f, 1f, 1f));
    }
    // stack
    for (int i = 0; i < BOXSTACK_COUNT; i++) {
        entity = new Object3D("box" + (BOX_COUNT + i), boxModel);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(1.6f + (i * 1.2f));
        entity.getTranslation().addX(+3f);
        entity.getTranslation().addZ(-5f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("box" + (BOX_COUNT + i), true, RIGID_TYPEID_STANDARD, entity, box, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(box, 100f, 1f, 1f, 1f));
    }
    // sphere
    Sphere sphere = new Sphere(new Vector3(0f, 0f, 0f), 0.4f);
    Model sphereModel = PrimitiveModel.createModel(sphere, "sphere_model");
    sphereModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.5f, 0.8f, 0.8f, 1f);
    sphereModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(0f, 1f, 1f, 1f);
    // spheres
    for (int i = 0; i < SPHERE_COUNT; i++) {
        entity = new Object3D("sphere" + i, sphereModel);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(12f + (i * 1f));
        entity.getTranslation().addX(0.45f * i - 3f);
        entity.getTranslation().addZ(0.1f * i - 3f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("sphere" + i, true, RIGID_TYPEID_STANDARD, entity, sphere, 0.75f, 0.4f, 10f, RigidBody.computeInertiaMatrix(sphere, 10f, 1f, 1f, 1f));
    }
    // sphere
    Capsule capsule = new Capsule(new Vector3(0f, 0.5f, 0f), new Vector3(0f, -0.5f, 0f), 0.25f);
    Model capsuleModel = PrimitiveModel.createModel(capsule, "capsule_model");
    capsuleModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.0f, 0.8f, 1f);
    capsuleModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 0f, 1f, 1f);
    //
    for (int i = 0; i < CAPSULE_COUNT; i++) {
        entity = new Object3D("capsule" + i, capsuleModel);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(14f + (i * 2f));
        entity.getTranslation().addX((i * 0.5f));
        // entity.getPivot().set(capsule.getCenter());
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("capsule" + i, true, RIGID_TYPEID_STANDARD, entity, capsule, 0.0f, 0.4f, 3f, RigidBody.computeInertiaMatrix(capsule, 3f, 1f, 1f, 1f));
    }
    // sphere
    //Capsule capsuleBig = new Capsule(
    //	new Vector3(0f,+1f,0f),
    //	new Vector3(0f,-1f,0f),
    //	0.5f
    //);
    OrientedBoundingBox capsuleBig = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(0.5f, 1f, 0.5f));
    Model capsuleBigModel = PrimitiveModel.createModel(capsuleBig, "capsulebig_model");
    capsuleBigModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(1f, 0.8f, 0.8f, 1f);
    capsuleBigModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 0f, 0f, 1f);
    System.out.println(capsuleBig.getCenter());
    //
    entity = new Object3D("capsulebig1", capsuleBigModel);
    entity.setDynamicShadowingEnabled(true);
    entity.getTranslation().addY(5f);
    entity.getTranslation().addX(-2f);
    entity.update();
    engine.addEntity(entity);
    world.addRigidBody("capsulebig1", true, RIGID_TYPEID_STANDARD, entity, capsuleBig, 0f, 1f, 80f, RigidBody.getNoRotationInertiaMatrix());
    //
    entity = new Object3D("capsulebig2", capsuleBigModel);
    entity.setDynamicShadowingEnabled(true);
    entity.getTranslation().addY(5f);
    entity.getTranslation().addX(+2f);
    entity.update();
    engine.addEntity(entity);
    world.addRigidBody("capsulebig2", true, RIGID_TYPEID_STANDARD, entity, capsuleBig, 0f, 1f, 100f, RigidBody.getNoRotationInertiaMatrix());
    try {
        // load barrel, set up bounding volume
        Model _barrel = DAEReader.read("resources/tests/models/barrel", "barrel.dae");
        // _barrel.getImportTransformationsMatrix().scale(2f);
        ConvexMesh barrelBoundingVolume = new ConvexMesh(new Object3DModel(_barrel));
        // set up barrel 1 in 3d engine
        entity = new Object3D("barrel1", _barrel);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(5f);
        entity.getTranslation().addX(+4f);
        entity.getScale().set(2f, 2f, 2f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("barrel1", true, RIGID_TYPEID_STANDARD, entity, barrelBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(barrelBoundingVolume, 100f, 1f, 1f, 1f));
        // set up barrel 2 in 3d engine
        entity = new Object3D("barrel2", _barrel);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(5f);
        entity.getTranslation().addX(+6f);
        entity.getScale().set(2f, 2f, 2f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("barrel2", true, RIGID_TYPEID_STANDARD, entity, barrelBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(barrelBoundingVolume, 100f, 1f, 1f, 1f));
        // load cone, set up bounding volume
        Model _cone = DAEReader.read("resources/tests/models/cone", "cone.dae");
        // _barrel.getImportTransformationsMatrix().scale(2f);
        ConvexMesh coneBoundingVolume = new ConvexMesh(new Object3DModel(_cone));
        // set up cone 1 in 3d engine
        entity = new Object3D("cone1", _cone);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(5f);
        entity.getTranslation().addX(-4f);
        entity.getScale().set(3f, 3f, 3f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("cone1", true, RIGID_TYPEID_STANDARD, entity, coneBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(coneBoundingVolume, 100f, 1f, 1f, 1f));
        // set up cone 1 in 3d engine
        entity = new Object3D("cone2", _cone);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(5f);
        entity.getTranslation().addX(-5f);
        entity.getScale().set(3f, 3f, 3f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("cone2", true, RIGID_TYPEID_STANDARD, entity, coneBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(coneBoundingVolume, 100f, 1f, 1f, 1f));
        // load cone, set up bounding volume
        Model _tire = DAEReader.read("resources/tests/models/tire", "tire.dae");
        // _barrel.getImportTransformationsMatrix().scale(2f);
        ConvexMesh tireBoundingVolume = new ConvexMesh(new Object3DModel(_tire));
        // set up tire 1 in 3d engine
        entity = new Object3D("tire1", _tire);
        entity.setDynamicShadowingEnabled(true);
        entity.getRotations().add(new Rotation(90f, new Vector3(1f, 0f, 0f)));
        entity.getTranslation().addY(5f);
        entity.getTranslation().addX(-4f);
        entity.getTranslation().addZ(-2f);
        entity.getScale().set(2f, 2f, 2f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("tire1", true, RIGID_TYPEID_STANDARD, entity, tireBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(tireBoundingVolume, 100f, 1f, 1f, 1f));
        // set up tire 1 in 3d engine
        entity = new Object3D("tire2", _tire);
        entity.setDynamicShadowingEnabled(true);
        entity.getRotations().add(new Rotation(90f, new Vector3(1f, 0f, 0f)));
        entity.getTranslation().addY(5f);
        entity.getTranslation().addX(-6f);
        entity.getTranslation().addZ(-2f);
        entity.getScale().set(2f, 2f, 2f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("tire2", true, RIGID_TYPEID_STANDARD, entity, tireBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(tireBoundingVolume, 100f, 1f, 1f, 1f));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Vector3(net.drewke.tdme.math.Vector3) Capsule(net.drewke.tdme.engine.primitives.Capsule) ConvexMesh(net.drewke.tdme.engine.primitives.ConvexMesh) Object3DModel(net.drewke.tdme.engine.Object3DModel) Rotation(net.drewke.tdme.engine.Rotation) Object3D(net.drewke.tdme.engine.Object3D) Sphere(net.drewke.tdme.engine.primitives.Sphere) OrientedBoundingBox(net.drewke.tdme.engine.primitives.OrientedBoundingBox) Light(net.drewke.tdme.engine.Light) Model(net.drewke.tdme.engine.model.Model) PrimitiveModel(net.drewke.tdme.engine.primitives.PrimitiveModel) Object3DModel(net.drewke.tdme.engine.Object3DModel) Camera(net.drewke.tdme.engine.Camera)

Example 4 with Capsule

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

the class LevelEditorEntityBoundingVolume method setupCapsule.

/**
	 * Setup bounding volume capsule
	 * @param a
	 * @param b
	 * @param radius
	 */
public void setupCapsule(Vector3 a, Vector3 b, float radius) {
    boundingVolume = new Capsule(a, b, radius);
    model = PrimitiveModel.createModel(boundingVolume, (levelEditorEntity.getModel() != null ? levelEditorEntity.getModel().getId() : levelEditorEntity.getId()) + "_model_bv." + id + "." + (staticIdx++));
    modelMeshFile = null;
    updateLevelEditorEntity();
}
Also used : Capsule(net.drewke.tdme.engine.primitives.Capsule)

Example 5 with Capsule

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

the class PhysicsTest3 method init.

/*
	 * (non-Javadoc)
	 * @see com.jogamp.opengl.GLEventListener#init(com.jogamp.opengl.GLAutoDrawable)
	 */
public void init(GLAutoDrawable drawable) {
    drawable.getGL().setSwapInterval(0);
    engine.init(drawable);
    Object3D entity;
    // cam
    Camera cam = engine.getCamera();
    cam.setZNear(0.10f);
    cam.setZFar(50.00f);
    cam.getLookFrom().set(0f, 4f * 2.5f, -6f * 2.5f);
    cam.getLookAt().set(0f, 0.0f, 0f);
    cam.computeUpVector(cam.getLookFrom(), cam.getLookAt(), cam.getUpVector());
    // lights
    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(0f, 20000f, 0f, 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);
    // side
    OrientedBoundingBox side = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(1f, 16f, 8f));
    Model sideModel = PrimitiveModel.createModel(side, "side_model");
    sideModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.8f, 0.8f, 1f);
    sideModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 1f, 1f, 1f);
    // far
    OrientedBoundingBox nearFar = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(8f, 16f, 1f));
    Model nearFarModel = PrimitiveModel.createModel(nearFar, "far_model");
    nearFarModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.8f, 0.8f, 1f);
    nearFarModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 1f, 1f, 1f);
    // far
    entity = new Object3D("far", nearFarModel);
    entity.getTranslation().addZ(+9f);
    entity.update();
    engine.addEntity(entity);
    world.addStaticRigidBody("far", true, RIGID_TYPEID_STANDARD, entity, nearFar, 0.5f);
    // near
    entity = new Object3D("near", nearFarModel);
    entity.getTranslation().addZ(-9f);
    entity.getEffectColorMul().set(1f, 1f, 1f, 0f);
    entity.update();
    engine.addEntity(entity);
    world.addStaticRigidBody("near", true, RIGID_TYPEID_STANDARD, entity, nearFar, 0.5f);
    // side left
    entity = new Object3D("sideright", sideModel);
    entity.getTranslation().addX(-9f);
    entity.update();
    engine.addEntity(entity);
    world.addStaticRigidBody("sideright", true, RIGID_TYPEID_STANDARD, entity, side, 0.5f);
    // side right
    entity = new Object3D("sideleft", sideModel);
    entity.getTranslation().addX(9f);
    entity.update();
    engine.addEntity(entity);
    world.addStaticRigidBody("sideleft", true, RIGID_TYPEID_STANDARD, entity, side, 0.5f);
    // box
    OrientedBoundingBox box = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(0.6f, 0.6f, 0.6f));
    Model boxModel = PrimitiveModel.createModel(box, "box_model");
    boxModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.5f, 0.5f, 1f);
    boxModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 0f, 0f, 1f);
    // boxes
    for (int i = 0; i < BOX_COUNT; i++) {
        entity = new Object3D("box" + i, boxModel);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(10f + i * 3.0f);
        entity.getTranslation().addX(-2f + i * 0.1f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("box" + i, true, RIGID_TYPEID_STANDARD, entity, box, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(box, 100f, 1f, 1f, 1f));
    }
    // stack
    for (int i = 0; i < BOXSTACK_COUNT; i++) {
        entity = new Object3D("box" + (BOX_COUNT + i), boxModel);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(1.6f + (i * 1.2f));
        entity.getTranslation().addX(+3f);
        entity.getTranslation().addZ(-5f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("box" + (BOX_COUNT + i), true, RIGID_TYPEID_STANDARD, entity, box, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(box, 100f, 1f, 1f, 1f));
    }
    // sphere
    Sphere sphere = new Sphere(new Vector3(0f, 0f, 0f), 0.4f);
    Model sphereModel = PrimitiveModel.createModel(sphere, "sphere_model");
    sphereModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.5f, 0.8f, 0.8f, 1f);
    sphereModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(0f, 1f, 1f, 1f);
    // spheres
    for (int i = 0; i < SPHERE_COUNT; i++) {
        entity = new Object3D("sphere" + i, sphereModel);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(12f + (i * 1f));
        entity.getTranslation().addX(0.45f * i - 3f);
        entity.getTranslation().addZ(0.1f * i - 3f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("sphere" + i, true, RIGID_TYPEID_STANDARD, entity, sphere, 0.75f, 0.4f, 10f, RigidBody.computeInertiaMatrix(sphere, 10f, 1f, 1f, 1f));
    }
    // sphere
    Capsule capsule = new Capsule(new Vector3(0f, 0.5f, 0f), new Vector3(0f, -0.5f, 0f), 0.25f);
    Model capsuleModel = PrimitiveModel.createModel(capsule, "capsule_model");
    capsuleModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(0.8f, 0.0f, 0.8f, 1f);
    capsuleModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 0f, 1f, 1f);
    //
    for (int i = 0; i < CAPSULE_COUNT; i++) {
        entity = new Object3D("capsule" + i, capsuleModel);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(14f + (i * 2f));
        entity.getTranslation().addX((i * 0.5f));
        // entity.getPivot().set(capsule.getCenter());
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("capsule" + i, true, RIGID_TYPEID_STANDARD, entity, capsule, 0.0f, 0.4f, 3f, RigidBody.computeInertiaMatrix(capsule, 3f, 1f, 1f, 1f));
    }
    // sphere
    //Capsule capsuleBig = new Capsule(
    //	new Vector3(0f,+1f,0f),
    //	new Vector3(0f,-1f,0f),
    //	0.5f
    //);
    OrientedBoundingBox capsuleBig = new OrientedBoundingBox(new Vector3(0f, 0f, 0f), OrientedBoundingBox.AABB_AXIS_X.clone(), OrientedBoundingBox.AABB_AXIS_Y.clone(), OrientedBoundingBox.AABB_AXIS_Z.clone(), new Vector3(0.5f, 1f, 0.5f));
    Model capsuleBigModel = PrimitiveModel.createModel(capsuleBig, "capsulebig_model");
    capsuleBigModel.getMaterials().get("tdme.primitive.material").getAmbientColor().set(1f, 0.8f, 0.8f, 1f);
    capsuleBigModel.getMaterials().get("tdme.primitive.material").getDiffuseColor().set(1f, 0f, 0f, 1f);
    System.out.println(capsuleBig.getCenter());
    //
    entity = new Object3D("capsulebig1", capsuleBigModel);
    entity.setDynamicShadowingEnabled(true);
    entity.getTranslation().addY(5f);
    entity.getTranslation().addX(-2f);
    entity.update();
    engine.addEntity(entity);
    world.addRigidBody("capsulebig1", true, RIGID_TYPEID_STANDARD, entity, capsuleBig, 0f, 1f, 80f, RigidBody.getNoRotationInertiaMatrix());
    //
    entity = new Object3D("capsulebig2", capsuleBigModel);
    entity.setDynamicShadowingEnabled(true);
    entity.getTranslation().addY(5f);
    entity.getTranslation().addX(+2f);
    entity.update();
    engine.addEntity(entity);
    world.addRigidBody("capsulebig2", true, RIGID_TYPEID_STANDARD, entity, capsuleBig, 0f, 1f, 100f, RigidBody.getNoRotationInertiaMatrix());
    //
    try {
        Model _terrainModel = DAEReader.read("resources/tests/environment/terrain_test", "terrain_test.dae");
        _terrainModel.getImportTransformationsMatrix().scale(1.5f);
        entity = new Object3D("terrain", _terrainModel);
        entity.getTranslation().setY(-4f);
        entity.update();
        engine.addEntity(entity);
        ArrayList<ConvexMesh> groundConvexMeshes = new ArrayList<ConvexMesh>();
        ConvexMesh.createTerrainConvexMeshes(new Object3DModel(_terrainModel), groundConvexMeshes);
        for (int i = 0; i < groundConvexMeshes.size(); i++) {
            world.addStaticRigidBody("ground" + i, true, RIGID_TYPEID_STANDARD, entity, groundConvexMeshes.get(i), 0.5f);
        }
        // load barrel, set up bounding volume
        Model _barrel = DAEReader.read("resources/tests/models/barrel", "barrel.dae");
        // _barrel.getImportTransformationsMatrix().scale(2f);
        ConvexMesh barrelBoundingVolume = new ConvexMesh(new Object3DModel(_barrel));
        // set up barrel 1 in 3d engine
        entity = new Object3D("barrel1", _barrel);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(5f);
        entity.getTranslation().addX(+4f);
        entity.getScale().set(2f, 2f, 2f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("barrel1", true, RIGID_TYPEID_STANDARD, entity, barrelBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(barrelBoundingVolume, 100f, 1f, 1f, 1f));
        // set up barrel 2 in 3d engine
        entity = new Object3D("barrel2", _barrel);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(5f);
        entity.getTranslation().addX(+6f);
        entity.getScale().set(2f, 2f, 2f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("barrel2", true, RIGID_TYPEID_STANDARD, entity, barrelBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(barrelBoundingVolume, 100f, 1f, 1f, 1f));
        // load cone, set up bounding volume
        Model _cone = DAEReader.read("resources/tests/models/cone", "cone.dae");
        // _barrel.getImportTransformationsMatrix().scale(2f);
        ConvexMesh coneBoundingVolume = new ConvexMesh(new Object3DModel(_cone));
        // set up cone 1 in 3d engine
        entity = new Object3D("cone1", _cone);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(5f);
        entity.getTranslation().addX(-4f);
        entity.getScale().set(3f, 3f, 3f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("cone1", true, RIGID_TYPEID_STANDARD, entity, coneBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(coneBoundingVolume, 100f, 1f, 1f, 1f));
        // set up cone 1 in 3d engine
        entity = new Object3D("cone2", _cone);
        entity.setDynamicShadowingEnabled(true);
        entity.getTranslation().addY(5f);
        entity.getTranslation().addX(-5f);
        entity.getScale().set(3f, 3f, 3f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("cone2", true, RIGID_TYPEID_STANDARD, entity, coneBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(coneBoundingVolume, 100f, 1f, 1f, 1f));
        // load cone, set up bounding volume
        Model _tire = DAEReader.read("resources/tests/models/tire", "tire.dae");
        // _barrel.getImportTransformationsMatrix().scale(2f);
        ConvexMesh tireBoundingVolume = new ConvexMesh(new Object3DModel(_tire));
        // set up tire 1 in 3d engine
        entity = new Object3D("tire1", _tire);
        entity.setDynamicShadowingEnabled(true);
        entity.getRotations().add(new Rotation(90f, new Vector3(1f, 0f, 0f)));
        entity.getTranslation().addY(5f);
        entity.getTranslation().addX(-4f);
        entity.getTranslation().addZ(-2f);
        entity.getScale().set(2f, 2f, 2f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("tire1", true, RIGID_TYPEID_STANDARD, entity, tireBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(tireBoundingVolume, 100f, 1f, 1f, 1f));
        // set up tire 1 in 3d engine
        entity = new Object3D("tire2", _tire);
        entity.setDynamicShadowingEnabled(true);
        entity.getRotations().add(new Rotation(90f, new Vector3(1f, 0f, 0f)));
        entity.getTranslation().addY(5f);
        entity.getTranslation().addX(-6f);
        entity.getTranslation().addZ(-2f);
        entity.getScale().set(2f, 2f, 2f);
        entity.update();
        engine.addEntity(entity);
        world.addRigidBody("tire2", true, RIGID_TYPEID_STANDARD, entity, tireBoundingVolume, 0f, 1f, 100f, RigidBody.computeInertiaMatrix(tireBoundingVolume, 100f, 1f, 1f, 1f));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) Vector3(net.drewke.tdme.math.Vector3) Capsule(net.drewke.tdme.engine.primitives.Capsule) ConvexMesh(net.drewke.tdme.engine.primitives.ConvexMesh) Object3DModel(net.drewke.tdme.engine.Object3DModel) Rotation(net.drewke.tdme.engine.Rotation) Object3D(net.drewke.tdme.engine.Object3D) Sphere(net.drewke.tdme.engine.primitives.Sphere) OrientedBoundingBox(net.drewke.tdme.engine.primitives.OrientedBoundingBox) Light(net.drewke.tdme.engine.Light) Model(net.drewke.tdme.engine.model.Model) PrimitiveModel(net.drewke.tdme.engine.primitives.PrimitiveModel) Object3DModel(net.drewke.tdme.engine.Object3DModel) Camera(net.drewke.tdme.engine.Camera)

Aggregations

Capsule (net.drewke.tdme.engine.primitives.Capsule)5 ConvexMesh (net.drewke.tdme.engine.primitives.ConvexMesh)4 OrientedBoundingBox (net.drewke.tdme.engine.primitives.OrientedBoundingBox)4 Sphere (net.drewke.tdme.engine.primitives.Sphere)4 Vector3 (net.drewke.tdme.math.Vector3)3 Camera (net.drewke.tdme.engine.Camera)2 Light (net.drewke.tdme.engine.Light)2 Object3D (net.drewke.tdme.engine.Object3D)2 Object3DModel (net.drewke.tdme.engine.Object3DModel)2 Rotation (net.drewke.tdme.engine.Rotation)2 Model (net.drewke.tdme.engine.model.Model)2 BoundingBox (net.drewke.tdme.engine.primitives.BoundingBox)2 PrimitiveModel (net.drewke.tdme.engine.primitives.PrimitiveModel)2 LevelEditorEntityBoundingVolume (net.drewke.tdme.tools.shared.model.LevelEditorEntityBoundingVolume)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 BoundingVolume (net.drewke.tdme.engine.primitives.BoundingVolume)1 Triangle (net.drewke.tdme.engine.primitives.Triangle)1 LevelEditorEntityParticleSystem (net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem)1