Search in sources :

Example 1 with CircleParticleEmitterPlaneVelocity

use of net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitterPlaneVelocity 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 CircleParticleEmitterPlaneVelocity

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

the class ModelMetaDataFileImport method doImportFromJSON.

/**
	 * Imports a model meta data file from JSON object
	 * @param id or LevelEditorEntity.ID_NONE
	 * @param path name or null
	 * @param JSON entity root
	 */
public static LevelEditorEntity doImportFromJSON(int id, String pathName, JSONObject jEntityRoot) throws Exception {
    LevelEditorEntity levelEditorEntity;
    // check for version
    float version = Float.parseFloat(jEntityRoot.getString("version"));
    // pivot
    Vector3 pivot = new Vector3((float) jEntityRoot.getDouble("px"), (float) jEntityRoot.getDouble("py"), (float) jEntityRoot.getDouble("pz"));
    // String thumbnail = jRoot.getString("thumbnail");
    EntityType modelType = LevelEditorEntity.EntityType.valueOf(jEntityRoot.getString("type"));
    String modelFile = jEntityRoot.has("file") == true ? new File(jEntityRoot.getString("file")).getCanonicalPath() : null;
    String modelThumbnail = jEntityRoot.has("thumbnail") == true ? jEntityRoot.getString("thumbnail") : null;
    String name = jEntityRoot.getString("name");
    String description = jEntityRoot.getString("descr");
    // load model
    Model model = null;
    // having a model file?
    String gameRoot = Tools.getGameRootPath(pathName);
    String modelRelativeFileName = null;
    if (modelFile != null) {
        // yep, load it
        modelRelativeFileName = Tools.getRelativeResourcesFileName(gameRoot, modelFile);
        String modelPath = (gameRoot.length() > 0 ? gameRoot + "/" : "") + Tools.getPath(modelRelativeFileName);
        if (modelFile.toLowerCase().endsWith(".dae")) {
            model = DAEReader.read(modelPath, Tools.getFileName(modelRelativeFileName));
        } else if (modelFile.toLowerCase().endsWith(".tm")) {
            model = TMReader.read(modelPath, Tools.getFileName(modelRelativeFileName));
        } else {
            throw new Exception("Unsupported mode file: " + modelFile);
        }
    } else //	TODO: only load if required e.g. for LevelEditor
    if (modelType == EntityType.EMPTY) {
        model = DAEReader.read("resources/tools/leveleditor/models", "arrow.dae");
    }
    // load level editor model
    levelEditorEntity = new LevelEditorEntity(id, modelType, name, description, null, modelFile != null ? new File(gameRoot, modelRelativeFileName).getCanonicalPath() : null, modelThumbnail, model, pivot);
    // parse properties
    JSONArray jProperties = jEntityRoot.getJSONArray("properties");
    for (int i = 0; i < jProperties.length(); i++) {
        JSONObject jProperty = jProperties.getJSONObject(i);
        levelEditorEntity.addProperty(jProperty.getString("name"), jProperty.getString("value"));
    }
    // old: optional bounding volume
    if (jEntityRoot.has("bv") == true) {
        levelEditorEntity.addBoundingVolume(0, parseBoundingVolume(0, levelEditorEntity, jEntityRoot.getJSONObject("bv")));
    } else // new: optional bounding volumeS
    if (jEntityRoot.has("bvs") == true) {
        JSONArray jBoundingVolumes = jEntityRoot.getJSONArray("bvs");
        for (int i = 0; i < jBoundingVolumes.length(); i++) {
            JSONObject jBv = jBoundingVolumes.getJSONObject(i);
            levelEditorEntity.addBoundingVolume(i, parseBoundingVolume(i, levelEditorEntity, jBv));
        }
    }
    // parse particle system 
    if (modelType == EntityType.PARTICLESYSTEM) {
        LevelEditorEntityParticleSystem particleSystem = levelEditorEntity.getParticleSystem();
        JSONObject jParticleSystem = jEntityRoot.getJSONObject("ps");
        // type
        particleSystem.setType(Type.valueOf(jParticleSystem.getString("t")));
        switch(particleSystem.getType()) {
            case NONE:
                {
                    break;
                }
            case OBJECT_PARTICLE_SYSTEM:
                {
                    JSONObject jObjectParticleSystem = jParticleSystem.getJSONObject("ops");
                    ObjectParticleSystem objectParticleSystem = particleSystem.getObjectParticleSystem();
                    objectParticleSystem.setMaxCount(jObjectParticleSystem.getInt("mc"));
                    objectParticleSystem.getScale().setX((float) jObjectParticleSystem.getDouble("sx"));
                    objectParticleSystem.getScale().setY((float) jObjectParticleSystem.getDouble("sy"));
                    objectParticleSystem.getScale().setZ((float) jObjectParticleSystem.getDouble("sz"));
                    objectParticleSystem.setAutoEmit(jObjectParticleSystem.getBoolean("ae"));
                    try {
                        String particleModelFile = jObjectParticleSystem.getString("mf");
                        String particleModelRelativeFileName = Tools.getRelativeResourcesFileName(gameRoot, particleModelFile);
                        String particleModelPath = (gameRoot.length() > 0 ? gameRoot + "/" : "") + Tools.getPath(particleModelRelativeFileName);
                        objectParticleSystem.setModelFile(particleModelPath + "/" + Tools.getFileName(particleModelRelativeFileName));
                    } catch (Exception exception) {
                        exception.printStackTrace();
                        System.out.println("ModelMetaDataFileImport::doImport(): Failed to set model file: " + exception.getMessage());
                    }
                    break;
                }
            case POINT_PARTICLE_SYSTEM:
                {
                    JSONObject jPointParticleSystem = jParticleSystem.getJSONObject("pps");
                    particleSystem.getPointParticleSystem().setMaxPoints(jPointParticleSystem.getInt("mp"));
                    particleSystem.getPointParticleSystem().setAutoEmit(jPointParticleSystem.getBoolean("ae"));
                    break;
                }
            default:
                {
                    System.out.println("ModelMetaDataFileExport::export(): unknown particle system type '" + particleSystem.getType() + "'");
                    break;
                }
        }
        // emitter
        particleSystem.setEmitter(Emitter.valueOf(jParticleSystem.getString("e")));
        switch(particleSystem.getEmitter()) {
            case NONE:
                {
                    break;
                }
            case POINT_PARTICLE_EMITTER:
                {
                    JSONObject jPointParticleEmitter = jParticleSystem.getJSONObject("ppe");
                    PointParticleEmitter emitter = particleSystem.getPointParticleEmitter();
                    emitter.setCount(jPointParticleEmitter.getInt("c"));
                    emitter.setLifeTime(jPointParticleEmitter.getLong("lt"));
                    emitter.setLifeTimeRnd(jPointParticleEmitter.getLong("ltrnd"));
                    emitter.setMass((float) jPointParticleEmitter.getDouble("m"));
                    emitter.setMassRnd((float) jPointParticleEmitter.getDouble("mrnd"));
                    emitter.getPosition().setX((float) jPointParticleEmitter.getDouble("px"));
                    emitter.getPosition().setY((float) jPointParticleEmitter.getDouble("py"));
                    emitter.getPosition().setZ((float) jPointParticleEmitter.getDouble("pz"));
                    emitter.getVelocity().setX((float) jPointParticleEmitter.getDouble("vx"));
                    emitter.getVelocity().setY((float) jPointParticleEmitter.getDouble("vy"));
                    emitter.getVelocity().setZ((float) jPointParticleEmitter.getDouble("vz"));
                    emitter.getVelocityRnd().setX((float) jPointParticleEmitter.getDouble("vrndx"));
                    emitter.getVelocityRnd().setY((float) jPointParticleEmitter.getDouble("vrndy"));
                    emitter.getVelocityRnd().setZ((float) jPointParticleEmitter.getDouble("vrndz"));
                    emitter.getColorStart().setRed((float) jPointParticleEmitter.getDouble("csr"));
                    emitter.getColorStart().setGreen((float) jPointParticleEmitter.getDouble("csg"));
                    emitter.getColorStart().setBlue((float) jPointParticleEmitter.getDouble("csb"));
                    emitter.getColorStart().setAlpha((float) jPointParticleEmitter.getDouble("csa"));
                    emitter.getColorEnd().setRed((float) jPointParticleEmitter.getDouble("cer"));
                    emitter.getColorEnd().setGreen((float) jPointParticleEmitter.getDouble("ceg"));
                    emitter.getColorEnd().setBlue((float) jPointParticleEmitter.getDouble("ceb"));
                    emitter.getColorEnd().setAlpha((float) jPointParticleEmitter.getDouble("cea"));
                    break;
                }
            case BOUNDINGBOX_PARTICLE_EMITTER:
                {
                    JSONObject jBoundingBoxParticleEmitter = jParticleSystem.getJSONObject("bbpe");
                    BoundingBoxParticleEmitter emitter = particleSystem.getBoundingBoxParticleEmitters();
                    emitter.setCount(jBoundingBoxParticleEmitter.getInt("c"));
                    emitter.setLifeTime(jBoundingBoxParticleEmitter.getLong("lt"));
                    emitter.setLifeTimeRnd(jBoundingBoxParticleEmitter.getLong("ltrnd"));
                    emitter.setMass((float) jBoundingBoxParticleEmitter.getDouble("m"));
                    emitter.setMassRnd((float) jBoundingBoxParticleEmitter.getDouble("mrnd"));
                    emitter.getVelocity().setX((float) jBoundingBoxParticleEmitter.getDouble("vx"));
                    emitter.getVelocity().setY((float) jBoundingBoxParticleEmitter.getDouble("vy"));
                    emitter.getVelocity().setZ((float) jBoundingBoxParticleEmitter.getDouble("vz"));
                    emitter.getVelocityRnd().setX((float) jBoundingBoxParticleEmitter.getDouble("vrndx"));
                    emitter.getVelocityRnd().setY((float) jBoundingBoxParticleEmitter.getDouble("vrndy"));
                    emitter.getVelocityRnd().setZ((float) jBoundingBoxParticleEmitter.getDouble("vrndz"));
                    emitter.getColorStart().setRed((float) jBoundingBoxParticleEmitter.getDouble("csr"));
                    emitter.getColorStart().setGreen((float) jBoundingBoxParticleEmitter.getDouble("csg"));
                    emitter.getColorStart().setBlue((float) jBoundingBoxParticleEmitter.getDouble("csb"));
                    emitter.getColorStart().setAlpha((float) jBoundingBoxParticleEmitter.getDouble("csa"));
                    emitter.getColorEnd().setRed((float) jBoundingBoxParticleEmitter.getDouble("cer"));
                    emitter.getColorEnd().setGreen((float) jBoundingBoxParticleEmitter.getDouble("ceg"));
                    emitter.getColorEnd().setBlue((float) jBoundingBoxParticleEmitter.getDouble("ceb"));
                    emitter.getColorEnd().setAlpha((float) jBoundingBoxParticleEmitter.getDouble("cea"));
                    emitter.getObbCenter().setX((float) jBoundingBoxParticleEmitter.getDouble("ocx"));
                    emitter.getObbCenter().setY((float) jBoundingBoxParticleEmitter.getDouble("ocy"));
                    emitter.getObbCenter().setZ((float) jBoundingBoxParticleEmitter.getDouble("ocz"));
                    emitter.getObbHalfextension().setX((float) jBoundingBoxParticleEmitter.getDouble("ohex"));
                    emitter.getObbHalfextension().setY((float) jBoundingBoxParticleEmitter.getDouble("ohey"));
                    emitter.getObbHalfextension().setZ((float) jBoundingBoxParticleEmitter.getDouble("ohez"));
                    emitter.getObbAxis0().setX((float) jBoundingBoxParticleEmitter.getDouble("oa0x"));
                    emitter.getObbAxis0().setY((float) jBoundingBoxParticleEmitter.getDouble("oa0y"));
                    emitter.getObbAxis0().setZ((float) jBoundingBoxParticleEmitter.getDouble("oa0z"));
                    emitter.getObbAxis1().setX((float) jBoundingBoxParticleEmitter.getDouble("oa1x"));
                    emitter.getObbAxis1().setY((float) jBoundingBoxParticleEmitter.getDouble("oa1y"));
                    emitter.getObbAxis1().setZ((float) jBoundingBoxParticleEmitter.getDouble("oa1z"));
                    emitter.getObbAxis2().setX((float) jBoundingBoxParticleEmitter.getDouble("oa2x"));
                    emitter.getObbAxis2().setY((float) jBoundingBoxParticleEmitter.getDouble("oa2y"));
                    emitter.getObbAxis2().setZ((float) jBoundingBoxParticleEmitter.getDouble("oa2z"));
                    break;
                }
            case CIRCLE_PARTICLE_EMITTER:
                {
                    JSONObject jCircleParticleEmitter = jParticleSystem.getJSONObject("cpe");
                    CircleParticleEmitter emitter = particleSystem.getCircleParticleEmitter();
                    emitter.setCount(jCircleParticleEmitter.getInt("c"));
                    emitter.setLifeTime(jCircleParticleEmitter.getLong("lt"));
                    emitter.setLifeTimeRnd(jCircleParticleEmitter.getLong("ltrnd"));
                    emitter.setMass((float) jCircleParticleEmitter.getDouble("m"));
                    emitter.setMassRnd((float) jCircleParticleEmitter.getDouble("mrnd"));
                    emitter.getVelocity().setX((float) jCircleParticleEmitter.getDouble("vx"));
                    emitter.getVelocity().setY((float) jCircleParticleEmitter.getDouble("vy"));
                    emitter.getVelocity().setZ((float) jCircleParticleEmitter.getDouble("vz"));
                    emitter.getVelocityRnd().setX((float) jCircleParticleEmitter.getDouble("vrndx"));
                    emitter.getVelocityRnd().setY((float) jCircleParticleEmitter.getDouble("vrndy"));
                    emitter.getVelocityRnd().setZ((float) jCircleParticleEmitter.getDouble("vrndz"));
                    emitter.getColorStart().setRed((float) jCircleParticleEmitter.getDouble("csr"));
                    emitter.getColorStart().setGreen((float) jCircleParticleEmitter.getDouble("csg"));
                    emitter.getColorStart().setBlue((float) jCircleParticleEmitter.getDouble("csb"));
                    emitter.getColorStart().setAlpha((float) jCircleParticleEmitter.getDouble("csa"));
                    emitter.getColorEnd().setRed((float) jCircleParticleEmitter.getDouble("cer"));
                    emitter.getColorEnd().setGreen((float) jCircleParticleEmitter.getDouble("ceg"));
                    emitter.getColorEnd().setBlue((float) jCircleParticleEmitter.getDouble("ceb"));
                    emitter.getColorEnd().setAlpha((float) jCircleParticleEmitter.getDouble("cea"));
                    emitter.getCenter().setX((float) jCircleParticleEmitter.getDouble("cx"));
                    emitter.getCenter().setY((float) jCircleParticleEmitter.getDouble("cy"));
                    emitter.getCenter().setZ((float) jCircleParticleEmitter.getDouble("cz"));
                    emitter.setRadius((float) jCircleParticleEmitter.getDouble("r"));
                    emitter.getAxis0().setX((float) jCircleParticleEmitter.getDouble("a0x"));
                    emitter.getAxis0().setY((float) jCircleParticleEmitter.getDouble("a0y"));
                    emitter.getAxis0().setZ((float) jCircleParticleEmitter.getDouble("a0z"));
                    emitter.getAxis1().setX((float) jCircleParticleEmitter.getDouble("a1x"));
                    emitter.getAxis1().setY((float) jCircleParticleEmitter.getDouble("a1y"));
                    emitter.getAxis1().setZ((float) jCircleParticleEmitter.getDouble("a1z"));
                    break;
                }
            case CIRCLE_PARTICLE_EMITTER_PLANE_VELOCITY:
                {
                    JSONObject jCircleParticleEmitterPlaneVelocity = jParticleSystem.getJSONObject("cpeev");
                    CircleParticleEmitterPlaneVelocity emitter = particleSystem.getCircleParticleEmitterPlaneVelocity();
                    emitter.setCount(jCircleParticleEmitterPlaneVelocity.getInt("c"));
                    emitter.setLifeTime(jCircleParticleEmitterPlaneVelocity.getLong("lt"));
                    emitter.setLifeTimeRnd(jCircleParticleEmitterPlaneVelocity.getLong("ltrnd"));
                    emitter.setMass((float) jCircleParticleEmitterPlaneVelocity.getDouble("m"));
                    emitter.setMassRnd((float) jCircleParticleEmitterPlaneVelocity.getDouble("mrnd"));
                    emitter.setVelocity((float) jCircleParticleEmitterPlaneVelocity.getDouble("v"));
                    emitter.setVelocityRnd((float) jCircleParticleEmitterPlaneVelocity.getDouble("vrnd"));
                    emitter.getColorStart().setRed((float) jCircleParticleEmitterPlaneVelocity.getDouble("csr"));
                    emitter.getColorStart().setGreen((float) jCircleParticleEmitterPlaneVelocity.getDouble("csg"));
                    emitter.getColorStart().setBlue((float) jCircleParticleEmitterPlaneVelocity.getDouble("csb"));
                    emitter.getColorStart().setAlpha((float) jCircleParticleEmitterPlaneVelocity.getDouble("csa"));
                    emitter.getColorEnd().setRed((float) jCircleParticleEmitterPlaneVelocity.getDouble("cer"));
                    emitter.getColorEnd().setGreen((float) jCircleParticleEmitterPlaneVelocity.getDouble("ceg"));
                    emitter.getColorEnd().setBlue((float) jCircleParticleEmitterPlaneVelocity.getDouble("ceb"));
                    emitter.getColorEnd().setAlpha((float) jCircleParticleEmitterPlaneVelocity.getDouble("cea"));
                    emitter.getCenter().setX((float) jCircleParticleEmitterPlaneVelocity.getDouble("cx"));
                    emitter.getCenter().setY((float) jCircleParticleEmitterPlaneVelocity.getDouble("cy"));
                    emitter.getCenter().setZ((float) jCircleParticleEmitterPlaneVelocity.getDouble("cz"));
                    emitter.setRadius((float) jCircleParticleEmitterPlaneVelocity.getDouble("r"));
                    emitter.getAxis0().setX((float) jCircleParticleEmitterPlaneVelocity.getDouble("a0x"));
                    emitter.getAxis0().setY((float) jCircleParticleEmitterPlaneVelocity.getDouble("a0y"));
                    emitter.getAxis0().setZ((float) jCircleParticleEmitterPlaneVelocity.getDouble("a0z"));
                    emitter.getAxis1().setX((float) jCircleParticleEmitterPlaneVelocity.getDouble("a1x"));
                    emitter.getAxis1().setY((float) jCircleParticleEmitterPlaneVelocity.getDouble("a1y"));
                    emitter.getAxis1().setZ((float) jCircleParticleEmitterPlaneVelocity.getDouble("a1z"));
                    break;
                }
            case SPHERE_PARTICLE_EMITTER:
                {
                    JSONObject jSphereParticleEmitter = jParticleSystem.getJSONObject("spe");
                    SphereParticleEmitter emitter = particleSystem.getSphereParticleEmitter();
                    emitter.setCount(jSphereParticleEmitter.getInt("c"));
                    emitter.setLifeTime(jSphereParticleEmitter.getLong("lt"));
                    emitter.setLifeTimeRnd(jSphereParticleEmitter.getLong("ltrnd"));
                    emitter.setMass((float) jSphereParticleEmitter.getDouble("m"));
                    emitter.setMassRnd((float) jSphereParticleEmitter.getDouble("mrnd"));
                    emitter.getVelocity().setX((float) jSphereParticleEmitter.getDouble("vx"));
                    emitter.getVelocity().setY((float) jSphereParticleEmitter.getDouble("vy"));
                    emitter.getVelocity().setZ((float) jSphereParticleEmitter.getDouble("vz"));
                    emitter.getVelocityRnd().setX((float) jSphereParticleEmitter.getDouble("vrndx"));
                    emitter.getVelocityRnd().setY((float) jSphereParticleEmitter.getDouble("vrndy"));
                    emitter.getVelocityRnd().setZ((float) jSphereParticleEmitter.getDouble("vrndz"));
                    emitter.getColorStart().setRed((float) jSphereParticleEmitter.getDouble("csr"));
                    emitter.getColorStart().setGreen((float) jSphereParticleEmitter.getDouble("csg"));
                    emitter.getColorStart().setBlue((float) jSphereParticleEmitter.getDouble("csb"));
                    emitter.getColorStart().setAlpha((float) jSphereParticleEmitter.getDouble("csa"));
                    emitter.getColorEnd().setRed((float) jSphereParticleEmitter.getDouble("cer"));
                    emitter.getColorEnd().setGreen((float) jSphereParticleEmitter.getDouble("ceg"));
                    emitter.getColorEnd().setBlue((float) jSphereParticleEmitter.getDouble("ceb"));
                    emitter.getColorEnd().setAlpha((float) jSphereParticleEmitter.getDouble("cea"));
                    emitter.getCenter().setX((float) jSphereParticleEmitter.getDouble("cx"));
                    emitter.getCenter().setY((float) jSphereParticleEmitter.getDouble("cy"));
                    emitter.getCenter().setZ((float) jSphereParticleEmitter.getDouble("cz"));
                    emitter.setRadius((float) jSphereParticleEmitter.getDouble("r"));
                    break;
                }
            default:
                System.out.println("ModelMetaDataFileExport::export(): unknown particle system emitter '" + particleSystem.getEmitter() + "'");
        }
    }
    // done
    return levelEditorEntity;
}
Also used : CircleParticleEmitterPlaneVelocity(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitterPlaneVelocity) JSONArray(org.json.JSONArray) CircleParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitter) Vector3(net.drewke.tdme.math.Vector3) JSONException(org.json.JSONException) IOException(java.io.IOException) LevelEditorEntityParticleSystem(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem) EntityType(net.drewke.tdme.tools.shared.model.LevelEditorEntity.EntityType) JSONObject(org.json.JSONObject) Model(net.drewke.tdme.engine.model.Model) PrimitiveModel(net.drewke.tdme.engine.primitives.PrimitiveModel) BoundingBoxParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.BoundingBoxParticleEmitter) ObjectParticleSystem(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.ObjectParticleSystem) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity) File(java.io.File) SphereParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.SphereParticleEmitter) PointParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.PointParticleEmitter)

Example 3 with CircleParticleEmitterPlaneVelocity

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

the class ParticleSystemScreenController method setParticleSystemEmitter.

/**
	 * Set particle system emitter
	 */
public void setParticleSystemEmitter() {
    particleSystemEmitter.getActiveConditions().removeAll();
    LevelEditorEntityParticleSystem particleSystem = view.getEntity().getParticleSystem();
    switch(particleSystem.getEmitter()) {
        case NONE:
            {
                particleSystemEmitters.getController().setValue(value.set(EMITTER_NONE));
                particleSystemEmitter.getActiveConditions().add(EMITTER_NONE);
                break;
            }
        case POINT_PARTICLE_EMITTER:
            {
                particleSystemEmitters.getController().setValue(value.set(EMITTER_POINTPARTICLEEMITTER));
                particleSystemEmitter.getActiveConditions().add(EMITTER_POINTPARTICLEEMITTER);
                PointParticleEmitter emitter = particleSystem.getPointParticleEmitter();
                ppeCount.getController().setValue(value.set(emitter.getCount()));
                ppeLifeTime.getController().setValue(value.set((int) emitter.getLifeTime()));
                ppeLifeTimeRnd.getController().setValue(value.set((int) emitter.getLifeTimeRnd()));
                ppeMass.getController().setValue(value.set(emitter.getMass(), 4));
                ppeMassRnd.getController().setValue(value.set(emitter.getMassRnd(), 4));
                ppePosition.getController().setValue(value.set(Tools.formatVector3(emitter.getPosition())));
                ppeVelocity.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocity())));
                ppeVelocityRnd.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocityRnd())));
                ppeColorStart.getController().setValue(value.set(Tools.formatColor4(emitter.getColorStart())));
                ppeColorEnd.getController().setValue(value.set(Tools.formatColor4(emitter.getColorEnd())));
                break;
            }
        case BOUNDINGBOX_PARTICLE_EMITTER:
            {
                particleSystemEmitters.getController().setValue(value.set(EMITTER_BOUNDINGBOXPARTICLEEMITTER));
                particleSystemEmitter.getActiveConditions().add(EMITTER_BOUNDINGBOXPARTICLEEMITTER);
                BoundingBoxParticleEmitter emitter = particleSystem.getBoundingBoxParticleEmitters();
                bbpeCount.getController().setValue(value.set(emitter.getCount()));
                bbpeLifeTime.getController().setValue(value.set((int) emitter.getLifeTime()));
                bbpeLifeTimeRnd.getController().setValue(value.set((int) emitter.getLifeTimeRnd()));
                bbpeMass.getController().setValue(value.set(emitter.getMass(), 4));
                bbpeMassRnd.getController().setValue(value.set(emitter.getMassRnd(), 4));
                bbpeVelocity.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocity())));
                bbpeVelocityRnd.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocityRnd())));
                bbpeColorStart.getController().setValue(value.set(Tools.formatColor4(emitter.getColorStart())));
                bbpeColorEnd.getController().setValue(value.set(Tools.formatColor4(emitter.getColorEnd())));
                bbpeObbCenter.getController().setValue(value.set(Tools.formatVector3(emitter.getObbCenter())));
                bbpeObbHalfextension.getController().setValue(value.set(Tools.formatVector3(emitter.getObbHalfextension())));
                // set up rotation matrix to extract euler angles
                Vector3 rotation = new Vector3();
                Matrix4x4 rotationMatrix = new Matrix4x4().identity();
                rotationMatrix.setAxes(emitter.getObbAxis0(), emitter.getObbAxis1(), emitter.getObbAxis2());
                rotationMatrix.computeEulerAngles(rotation);
                // set up rotation
                bbpeObbRotationX.getController().setValue(value.set(Tools.formatFloat(rotation.getX())));
                bbpeObbRotationY.getController().setValue(value.set(Tools.formatFloat(rotation.getY())));
                bbpeObbRotationZ.getController().setValue(value.set(Tools.formatFloat(rotation.getZ())));
                break;
            }
        case CIRCLE_PARTICLE_EMITTER:
            {
                particleSystemEmitters.getController().setValue(value.set(EMITTER_CIRCLEPARTICLEEMITTER));
                particleSystemEmitter.getActiveConditions().add(EMITTER_CIRCLEPARTICLEEMITTER);
                CircleParticleEmitter emitter = particleSystem.getCircleParticleEmitter();
                cpeCount.getController().setValue(value.set(emitter.getCount()));
                cpeLifeTime.getController().setValue(value.set((int) emitter.getLifeTime()));
                cpeLifeTimeRnd.getController().setValue(value.set((int) emitter.getLifeTimeRnd()));
                cpeMass.getController().setValue(value.set(emitter.getMass(), 4));
                cpeMassRnd.getController().setValue(value.set(emitter.getMassRnd(), 4));
                cpeVelocity.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocity())));
                cpeVelocityRnd.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocityRnd())));
                cpeColorStart.getController().setValue(value.set(Tools.formatColor4(emitter.getColorStart())));
                cpeColorEnd.getController().setValue(value.set(Tools.formatColor4(emitter.getColorEnd())));
                cpeCenter.getController().setValue(value.set(Tools.formatVector3(emitter.getCenter())));
                cpeRadius.getController().setValue(value.set(emitter.getRadius(), 4));
                // set up rotation matrix to extract euler angles
                Vector3 rotation = new Vector3();
                Matrix4x4 rotationMatrix = new Matrix4x4().identity();
                rotationMatrix.setAxes(emitter.getAxis0(), Vector3.computeCrossProduct(emitter.getAxis0(), emitter.getAxis1()), emitter.getAxis1());
                rotationMatrix.computeEulerAngles(rotation);
                // set up rotation
                cpeRotationX.getController().setValue(value.set(Tools.formatFloat(rotation.getX())));
                cpeRotationY.getController().setValue(value.set(Tools.formatFloat(rotation.getY())));
                cpeRotationZ.getController().setValue(value.set(Tools.formatFloat(rotation.getZ())));
                break;
            }
        case CIRCLE_PARTICLE_EMITTER_PLANE_VELOCITY:
            {
                particleSystemEmitters.getController().setValue(value.set(EMITTER_CIRCLEPARTICLEEMITTERPLANEVELOCITY));
                particleSystemEmitter.getActiveConditions().add(EMITTER_CIRCLEPARTICLEEMITTERPLANEVELOCITY);
                CircleParticleEmitterPlaneVelocity emitter = particleSystem.getCircleParticleEmitterPlaneVelocity();
                cpepvCount.getController().setValue(value.set(emitter.getCount()));
                cpepvLifeTime.getController().setValue(value.set((int) emitter.getLifeTime()));
                cpepvLifeTimeRnd.getController().setValue(value.set((int) emitter.getLifeTimeRnd()));
                cpepvMass.getController().setValue(value.set(emitter.getMass(), 4));
                cpepvMassRnd.getController().setValue(value.set(emitter.getMassRnd(), 4));
                cpepvVelocity.getController().setValue(value.set(emitter.getVelocity(), 4));
                cpepvVelocityRnd.getController().setValue(value.set(emitter.getVelocityRnd(), 4));
                cpepvColorStart.getController().setValue(value.set(Tools.formatColor4(emitter.getColorStart())));
                cpepvColorEnd.getController().setValue(value.set(Tools.formatColor4(emitter.getColorEnd())));
                cpepvCenter.getController().setValue(value.set(Tools.formatVector3(emitter.getCenter())));
                cpepvRadius.getController().setValue(value.set(emitter.getRadius(), 4));
                // set up rotation matrix to extract euler angles
                Vector3 rotation = new Vector3();
                Matrix4x4 rotationMatrix = new Matrix4x4().identity();
                rotationMatrix.setAxes(emitter.getAxis0(), Vector3.computeCrossProduct(emitter.getAxis0(), emitter.getAxis1()), emitter.getAxis1());
                rotationMatrix.computeEulerAngles(rotation);
                // set up rotation
                cpepvRotationX.getController().setValue(value.set(Tools.formatFloat(rotation.getX())));
                cpepvRotationY.getController().setValue(value.set(Tools.formatFloat(rotation.getY())));
                cpepvRotationZ.getController().setValue(value.set(Tools.formatFloat(rotation.getZ())));
                break;
            }
        case SPHERE_PARTICLE_EMITTER:
            {
                particleSystemEmitters.getController().setValue(value.set(EMITTER_SPHEREPARTICLEEMITTER));
                particleSystemEmitter.getActiveConditions().add(EMITTER_SPHEREPARTICLEEMITTER);
                SphereParticleEmitter emitter = particleSystem.getSphereParticleEmitter();
                speCount.getController().setValue(value.set(emitter.getCount()));
                speLifeTime.getController().setValue(value.set((int) emitter.getLifeTime()));
                speLifeTimeRnd.getController().setValue(value.set((int) emitter.getLifeTimeRnd()));
                speMass.getController().setValue(value.set(emitter.getMass(), 4));
                speMassRnd.getController().setValue(value.set(emitter.getMassRnd(), 4));
                speVelocity.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocity())));
                speVelocityRnd.getController().setValue(value.set(Tools.formatVector3(emitter.getVelocityRnd())));
                speColorStart.getController().setValue(value.set(Tools.formatColor4(emitter.getColorStart())));
                speColorEnd.getController().setValue(value.set(Tools.formatColor4(emitter.getColorEnd())));
                speCenter.getController().setValue(value.set(Tools.formatVector3(emitter.getCenter())));
                speRadius.getController().setValue(value.set(emitter.getRadius(), 4));
                break;
            }
        default:
            System.out.println("ParticleSystemScreenController::onParticleSystemEmitterApply(): unknown particle system emitter '" + particleSystem.getEmitter() + "'");
    }
    // re init entity in view
    view.initParticleSystem();
}
Also used : CircleParticleEmitterPlaneVelocity(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitterPlaneVelocity) CircleParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitter) BoundingBoxParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.BoundingBoxParticleEmitter) Vector3(net.drewke.tdme.math.Vector3) LevelEditorEntityParticleSystem(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem) Matrix4x4(net.drewke.tdme.math.Matrix4x4) SphereParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.SphereParticleEmitter) PointParticleEmitter(net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.PointParticleEmitter)

Aggregations

Vector3 (net.drewke.tdme.math.Vector3)3 LevelEditorEntityParticleSystem (net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem)3 BoundingBoxParticleEmitter (net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.BoundingBoxParticleEmitter)3 CircleParticleEmitter (net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitter)3 CircleParticleEmitterPlaneVelocity (net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.CircleParticleEmitterPlaneVelocity)3 PointParticleEmitter (net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.PointParticleEmitter)3 SphereParticleEmitter (net.drewke.tdme.tools.shared.model.LevelEditorEntityParticleSystem.SphereParticleEmitter)3 File (java.io.File)2 IOException (java.io.IOException)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 Model (net.drewke.tdme.engine.model.Model)1 BoundingBox (net.drewke.tdme.engine.primitives.BoundingBox)1 BoundingVolume (net.drewke.tdme.engine.primitives.BoundingVolume)1 Capsule (net.drewke.tdme.engine.primitives.Capsule)1 ConvexMesh (net.drewke.tdme.engine.primitives.ConvexMesh)1 OrientedBoundingBox (net.drewke.tdme.engine.primitives.OrientedBoundingBox)1 PrimitiveModel (net.drewke.tdme.engine.primitives.PrimitiveModel)1 Sphere (net.drewke.tdme.engine.primitives.Sphere)1 Triangle (net.drewke.tdme.engine.primitives.Triangle)1