Search in sources :

Example 1 with Object3D

use of net.drewke.tdme.engine.Object3D in project tdme by andreasdr.

the class EntityBoundingVolumeView method updateModelBoundingVolume.

/**
	 * Update model bounding volume
	 * @param entity
	 * @param idx
	 */
private void updateModelBoundingVolume(LevelEditorEntity entity, int idx) {
    LevelEditorEntityBoundingVolume entityBoundingVolume = entity.getBoundingVolumeAt(idx);
    // remove old bv
    String id = EntityBoundingVolumeSubScreenController.MODEL_BOUNDINGVOLUME_IDS[idx];
    Entity modelBoundingVolumeObject = engine.getEntity(id);
    if (modelBoundingVolumeObject != null) {
        engine.removeEntity(id);
    }
    // add new bv
    if (entityBoundingVolume.getModel() == null)
        return;
    modelBoundingVolumeObject = new Object3D(id, entityBoundingVolume.getModel());
    modelBoundingVolumeObject.setEnabled(false);
    engine.addEntity(modelBoundingVolumeObject);
}
Also used : LevelEditorEntityBoundingVolume(net.drewke.tdme.tools.shared.model.LevelEditorEntityBoundingVolume) Entity(net.drewke.tdme.engine.Entity) LevelEditorEntity(net.drewke.tdme.tools.shared.model.LevelEditorEntity) Object3D(net.drewke.tdme.engine.Object3D)

Example 2 with Object3D

use of net.drewke.tdme.engine.Object3D in project tdme by andreasdr.

the class Object3DVBORenderer method render.

/**
	 * Renders all given objects
	 * @param objects
	 * @param render transparent faces
	 * @param depth buffer mode
	 * @param skinning shader  
	 */
public void render(ArrayList<Object3D> objects, boolean renderTransparentFaces, DepthBufferMode depthBufferMode, SkinningShader skinningShader) {
    // clear transparent render faces data
    transparentRenderFacesPool.reset();
    releaseTransparentFacesGroups();
    // sort objects by model
    for (int objectIdx = 0; objectIdx < objects.size(); objectIdx++) {
        Object3D object = objects.get(objectIdx);
        String modelId = object.getModel().getId();
        ArrayList<Object3D> visibleObjectsByModel = visibleObjectsByModels.get(modelId);
        if (visibleObjectsByModel == null) {
            visibleObjectsByModel = new ArrayList<Object3D>();
            visibleObjectsByModels.put(modelId, visibleObjectsByModel);
        }
        visibleObjectsByModel.add(object);
    }
    // render objects
    for (ArrayList<Object3D> objectsByModel : visibleObjectsByModels.getValuesIterator()) {
        if (objectsByModel.size() > 0) {
            renderObjectsOfSameType(objectsByModel, renderTransparentFaces, skinningShader);
            objectsByModel.clear();
        }
    }
    // render transparent render faces if any exist
    ArrayList<TransparentRenderFace> transparentRenderFaces = transparentRenderFacesPool.getTransparentRenderFaces();
    if (transparentRenderFaces.size() > 0) {
        // sort transparent render faces from far to near
        QuickSort.sort(transparentRenderFaces);
        // second render pass, draw color buffer for transparent objects
        // 	set up blending, but no culling and no depth buffer
        renderer.disableDepthBuffer();
        renderer.disableCulling();
        renderer.enableBlending();
        // actually this should not make any difference as culling is disabled
        // but having a fixed value is not a bad idea except that it is a GL call
        // TODO: confirm this
        renderer.setFrontFace(renderer.FRONTFACE_CCW);
        //
        for (TransparentRenderFace transparentRenderFace : transparentRenderFacesPool.getTransparentRenderFacesIterator()) {
            // do we have any faces yet?
            if (groupTransparentRenderFaces.size() == 0) {
                // nope, so add this one
                groupTransparentRenderFaces.add(transparentRenderFace);
            } else // do we have more than face already?
            if (groupTransparentRenderFaces.size() > 0) {
                // check if we have more of first type
                if (groupTransparentRenderFaces.get(0).object3DGroup == transparentRenderFace.object3DGroup) {
                    // yep, we can add this one
                    groupTransparentRenderFaces.add(transparentRenderFace);
                } else {
                    // no, render grouped faces
                    prepareTransparentFaces(groupTransparentRenderFaces);
                    // reset
                    groupTransparentRenderFaces.clear();
                    // add current face
                    groupTransparentRenderFaces.add(transparentRenderFace);
                }
            }
        }
        // 	check if there are any left overs
        if (groupTransparentRenderFaces.size() > 0) {
            prepareTransparentFaces(groupTransparentRenderFaces);
            groupTransparentRenderFaces.clear();
        }
        // render transparent faces groups
        renderTransparentFacesGroups(transparentRenderFacesGroups, depthBufferMode);
        //	no blending, but culling and depth buffer
        renderer.disableBlending();
        renderer.enableCulling();
        renderer.enableDepthBuffer();
    // done!
    }
}
Also used : Object3D(net.drewke.tdme.engine.Object3D)

Example 3 with Object3D

use of net.drewke.tdme.engine.Object3D in project tdme by andreasdr.

the class Object3DVBORenderer method renderObjectsOfSameType.

/**
	 * Renders multiple objects of same type(with same model)
	 * @param engine
	 * @param objects of same type/ with same models
	 * @param collect render faces
	 * @param skinning shader
	 */
protected void renderObjectsOfSameType(ArrayList<Object3D> objects, boolean collectTransparentFaces, SkinningShader skinningShader) {
    // do pre render steps
    for (int i = 0; i < objects.size(); i++) {
        Object3D object = objects.get(i);
        for (int j = 0; j < object.object3dGroups.length; j++) {
            Object3DGroup object3DGroup = object.object3dGroups[j];
            ((Object3DGroupVBORenderer) object3DGroup.renderer).preRender(this);
        }
    }
    //
    ShadowMapping shadowMapping = engine.getShadowMapping();
    modelViewMatrixBackup.set(renderer.getModelViewMatrix());
    // render faces entities
    int currentFrontFace = -1;
    Object3D firstObject = objects.get(0);
    // all objects share the same object 3d group structure, so we just take the first one
    int[] boundVBOBaseIds = null;
    int[] boundVBOTangentBitangentIds = null;
    int[] boundSkinningIds = null;
    for (int object3DGroupIdx = 0; object3DGroupIdx < firstObject.object3dGroups.length; object3DGroupIdx++) {
        Object3DGroup object3DGroup = firstObject.object3dGroups[object3DGroupIdx];
        // render each faces entity
        FacesEntity[] facesEntities = object3DGroup.group.getFacesEntities();
        int faceIdx = 0;
        int facesEntityIdxCount = facesEntities.length;
        for (int faceEntityIdx = 0; faceEntityIdx < facesEntityIdxCount; faceEntityIdx++) {
            FacesEntity facesEntity = facesEntities[faceEntityIdx];
            boolean isTextureCoordinatesAvailable = facesEntity.isTextureCoordinatesAvailable();
            int faces = facesEntity.getFaces().length;
            // material
            Material material = facesEntity.getMaterial();
            // determine if transparent
            boolean transparentFacesEntity = false;
            //	via material
            if (material != null) {
                if (material.hasTransparency() == true)
                    transparentFacesEntity = true;
            }
            // skip, if requested
            if (transparentFacesEntity == true) {
                // add to transparent render faces, if requested
                int objectCount = objects.size();
                for (int objectIdx = 0; objectIdx < objectCount; objectIdx++) {
                    Object3D object = objects.get(objectIdx);
                    Object3DGroup _object3DGroup = object.object3dGroups[object3DGroupIdx];
                    // set up textures
                    Object3DGroup.setupTextures(renderer, object3DGroup, faceEntityIdx);
                    // set up transparent render faces
                    if (collectTransparentFaces == true) {
                        transparentRenderFacesPool.createTransparentRenderFaces((_object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(_object3DGroup.groupTransformationsMatrix)).multiply(object.transformationsMatrix).multiply(modelViewMatrixBackup), object.object3dGroups[object3DGroupIdx], faceEntityIdx, faceIdx);
                    }
                }
                // keep track of rendered faces
                faceIdx += faces;
                // skip to next entity
                continue;
            }
            // optional texture coordinates
            if (isTextureCoordinatesAvailable == true) {
                // enable texturing client state if not yet done
                if (renderer.renderingTexturingClientState == false) {
                    renderer.enableClientState(renderer.CLIENTSTATE_TEXTURECOORD_ARRAY);
                    renderer.renderingTexturingClientState = true;
                }
            } else {
                // disable texturing client state if not yet done
                if (renderer.renderingTexturingClientState == true) {
                    renderer.disableClientState(renderer.CLIENTSTATE_TEXTURECOORD_ARRAY);
                    renderer.renderingTexturingClientState = false;
                }
            }
            // draw this faces entity for each object
            int objectCount = objects.size();
            for (int objectIdx = 0; objectIdx < objectCount; objectIdx++) {
                Object3D object = objects.get(objectIdx);
                Object3DGroup _object3DGroup = object.object3dGroups[object3DGroupIdx];
                // set up material on first object
                if (objectIdx == 0) {
                    // set up material
                    setupMaterial(_object3DGroup, faceEntityIdx);
                } else {
                    // only set up textures
                    Object3DGroup.setupTextures(renderer, _object3DGroup, faceEntityIdx);
                }
                //	check transparency via effect
                if (object.effectColorMul.getAlpha() < 1.0f - MathTools.EPSILON || object.effectColorAdd.getAlpha() < -MathTools.EPSILON) {
                    // add to transparent render faces, if requested
                    if (collectTransparentFaces == true) {
                        transparentRenderFacesPool.createTransparentRenderFaces((_object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(_object3DGroup.groupTransformationsMatrix)).multiply(object.transformationsMatrix).multiply(modelViewMatrixBackup), _object3DGroup, faceEntityIdx, faceIdx);
                    }
                    // skip to next object
                    continue;
                }
                // bind buffer base objects if not bound yet
                int[] currentVBOGlIds = ((Object3DGroupVBORenderer) _object3DGroup.renderer).vboBaseIds;
                if (boundVBOBaseIds != currentVBOGlIds) {
                    boundVBOBaseIds = currentVBOGlIds;
                    //	texture coordinates
                    if (isTextureCoordinatesAvailable == true) {
                        renderer.bindTextureCoordinatesBufferObject(currentVBOGlIds[3]);
                    }
                    // 	vertices
                    renderer.bindVerticesBufferObject(currentVBOGlIds[1]);
                    // 	normals
                    renderer.bindNormalsBufferObject(currentVBOGlIds[2]);
                    // indices
                    renderer.bindIndicesBufferObject(currentVBOGlIds[0]);
                }
                // bind tangent, bitangend buffers if not yet bound
                int[] currentVBOTangentBitangentIds = ((Object3DGroupVBORenderer) _object3DGroup.renderer).vboTangentBitangentIds;
                if (renderer.isNormalMappingAvailable() && currentVBOTangentBitangentIds != null && currentVBOTangentBitangentIds != boundVBOTangentBitangentIds) {
                    // tangent
                    renderer.bindTangentsBufferObject(currentVBOTangentBitangentIds[0]);
                    // bitangent
                    renderer.bindBitangentsBufferObject(currentVBOTangentBitangentIds[1]);
                }
                // set up GPU skinning, if required
                if (Engine.animationProcessingTarget == Engine.AnimationProcessingTarget.GPU && _object3DGroup.mesh.skinning == true && skinningShader != null) {
                    _object3DGroup.mesh.setupSkinningTransformationsMatrices(_object3DGroup.groupTransformationsMatricesVector);
                    skinningShader.initSkinning(renderer, _object3DGroup.mesh);
                    int[] currentSkinningIds = ((Object3DGroupVBORenderer) _object3DGroup.renderer).vboSkinningIds;
                    if (boundSkinningIds != currentSkinningIds) {
                        boundSkinningIds = currentSkinningIds;
                        renderer.bindSkinningVerticesJointsBufferObject(currentSkinningIds[0]);
                        renderer.bindSkinningVerticesVertexJointsIdxBufferObject(currentSkinningIds[1]);
                        renderer.bindSkinningVerticesVertexJointsWeightBufferObject(currentSkinningIds[2]);
                    }
                }
                // set up local -> world transformations matrix
                renderer.getModelViewMatrix().set((_object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(_object3DGroup.groupTransformationsMatrix)).multiply(object.transformationsMatrix).multiply(modelViewMatrixBackup));
                renderer.onUpdateModelViewMatrix();
                // set up front face
                int objectFrontFace = matrix4x4Negative.isNegative(renderer.getModelViewMatrix()) == false ? renderer.FRONTFACE_CCW : renderer.FRONTFACE_CW;
                if (objectFrontFace != currentFrontFace) {
                    renderer.setFrontFace(objectFrontFace);
                    currentFrontFace = objectFrontFace;
                }
                // set up effect color
                renderer.setEffectColorMul(object.effectColorMul.getArray());
                renderer.setEffectColorAdd(object.effectColorAdd.getArray());
                renderer.onUpdateEffect();
                // do transformation start to shadow mapping
                if (shadowMapping != null) {
                    shadowMapping.startObjectTransformations((_object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(_object3DGroup.groupTransformationsMatrix)).multiply(object.transformationsMatrix));
                }
                // draw
                renderer.drawIndexedTrianglesFromBufferObjects(faces, faceIdx);
                // do transformations end to shadow mapping
                if (shadowMapping != null) {
                    shadowMapping.endObjectTransformations();
                }
            }
            // done skinning
            if (skinningShader != null) {
                skinningShader.doneSkinning(renderer);
            }
            // keep track of rendered faces
            faceIdx += faces;
        }
    }
    // unbind buffers
    renderer.unbindBufferObjects();
    // restore model view matrix / view matrix
    renderer.getModelViewMatrix().set(modelViewMatrixBackup);
}
Also used : FacesEntity(net.drewke.tdme.engine.model.FacesEntity) ShadowMapping(net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMapping) Material(net.drewke.tdme.engine.model.Material) Object3D(net.drewke.tdme.engine.Object3D)

Example 4 with Object3D

use of net.drewke.tdme.engine.Object3D in project tdme by andreasdr.

the class Object3DVBORenderer method prepareTransparentFaces.

/**
	 * Renders transparent faces
	 * 	TODO:	guess this should be optimized regarding GL commands
	 * 			skinned mesh is not supported when using GPU
	 * @param transparent render faces
	 */
protected void prepareTransparentFaces(ArrayList<TransparentRenderFace> transparentRenderFaces) {
    // all those faces should share the object and object 3d group, ...
    Object3DGroup object3DGroup = transparentRenderFaces.get(0).object3DGroup;
    Object3D object3D = (Object3D) object3DGroup.object;
    // model view matrix to be used with given transparent render faces
    modelViewMatrix = (object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(object3DGroup.groupTransformationsMatrix)).multiply(object3D.transformationsMatrix).multiply(renderer.getModelViewMatrix());
    //
    Model model = ((Object3D) object3DGroup.object).getModel();
    FacesEntity[] facesEntities = object3DGroup.group.getFacesEntities();
    FacesEntity facesEntity = null;
    // attributes we collect for a transparent render face group
    boolean depthBuffer = false;
    Color4 effectColorAdd = ((Object3D) object3D).getEffectColorAdd();
    Color4 effectColorMul = ((Object3D) object3D).getEffectColorMul();
    Material material = null;
    boolean textureCoordinates = false;
    // render transparent faces
    Key transparentRenderFacesGroupKey = keyPool.allocate();
    for (int i = 0; i < transparentRenderFaces.size(); i++) {
        TransparentRenderFace transparentRenderFace = transparentRenderFaces.get(i);
        int facesEntityIdx = transparentRenderFace.facesEntityIdx;
        // check if to use depth buffer
        depthBuffer = ((Object3D) transparentRenderFace.object3DGroup.object).isPickable();
        // determine if faces entity and so material did switch between last face and current face
        if (facesEntity != facesEntities[facesEntityIdx]) {
            facesEntity = facesEntities[facesEntityIdx];
            material = facesEntity.getMaterial();
        }
        textureCoordinates = facesEntity.isTextureCoordinatesAvailable();
        // create group key
        TransparentRenderFacesGroup.createKey(transparentRenderFacesGroupKey, model, object3DGroup, facesEntityIdx, effectColorAdd, effectColorMul, depthBuffer, material, textureCoordinates);
        // get group
        TransparentRenderFacesGroup trfGroup = transparentRenderFacesGroups.get(transparentRenderFacesGroupKey);
        if (trfGroup == null) {
            // we do not have the group, create group
            trfGroup = transparentRenderFacesGroupPool.allocate();
            trfGroup.set(this, model, object3DGroup, facesEntityIdx, effectColorAdd, effectColorMul, depthBuffer, material, textureCoordinates);
            Key hashtableKey = keyPool.allocate();
            transparentRenderFacesGroupKey.cloneInto(hashtableKey);
            if (transparentRenderFacesGroups.put(hashtableKey, trfGroup) != null) {
                System.out.println("Object3DVBORenderer::prepareTransparentFaces::key already exists");
                System.out.println("-->" + transparentRenderFacesGroupKey);
                System.out.println("-->" + hashtableKey);
            }
        }
        // add face vertices
        for (int vertexIdx = 0; vertexIdx < 3; vertexIdx++) {
            short arrayIdx = transparentRenderFace.object3DGroup.mesh.indices[transparentRenderFace.faceIdx * 3 + vertexIdx];
            trfGroup.addVertex(modelViewMatrix.multiply(transparentRenderFace.object3DGroup.mesh.transformedVertices[arrayIdx], transformedVertex), modelViewMatrix.multiplyNoTranslation(transparentRenderFace.object3DGroup.mesh.transformedNormals[arrayIdx], transformedNormal), transparentRenderFace.object3DGroup.mesh.textureCoordinates != null ? transparentRenderFace.object3DGroup.mesh.textureCoordinates[arrayIdx] : null);
        }
    }
    keyPool.release(transparentRenderFacesGroupKey);
}
Also used : FacesEntity(net.drewke.tdme.engine.model.FacesEntity) Material(net.drewke.tdme.engine.model.Material) Object3D(net.drewke.tdme.engine.Object3D) Color4(net.drewke.tdme.engine.model.Color4) Model(net.drewke.tdme.engine.model.Model) Key(net.drewke.tdme.utils.Key)

Example 5 with Object3D

use of net.drewke.tdme.engine.Object3D in project tdme by andreasdr.

the class EngineTest method init.

/*
	 * (non-Javadoc)
	 * @see com.jogamp.opengl.GLEventListener#init(com.jogamp.opengl.GLAutoDrawable)
	 */
public void init(GLAutoDrawable drawable) {
    engine.init(drawable);
    if (osEngine == null) {
        osEngine = Engine.createOffScreenInstance(drawable, 512, 512);
        //
        Light osLight0 = osEngine.getLightAt(0);
        osLight0.getAmbient().set(1.0f, 1.0f, 1.0f, 1.0f);
        osLight0.getDiffuse().set(1.0f, 1.0f, 1.0f, 1.0f);
        osLight0.getPosition().set(0.0f, -4f, -4f, 1.0f);
        osLight0.getSpotDirection().set(new Vector3(osLight0.getPosition().getArray())).sub(new Vector3(0f, 0f, 0f));
        osLight0.setEnabled(true);
        // cam
        Camera osCam = osEngine.getCamera();
        osCam.setZNear(0.10f);
        osCam.setZFar(50.00f);
        osCam.getLookFrom().set(0f, 4f, -4f);
        osCam.getLookAt().set(0f, 0.50f, 0f);
        osCam.computeUpVector(osCam.getLookFrom(), osCam.getLookAt(), osCam.getUpVector());
        // scene color
        osEngine.getSceneColor().set(0.5f, 0.0f, 0.0f, 1.0f);
    }
    // cam
    Camera cam = engine.getCamera();
    cam.setZNear(0.10f);
    cam.setZFar(50.00f);
    cam.getLookFrom().set(0f, 3f, -8f);
    cam.getLookAt().set(0f, 0.50f, 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);
    Light light1 = engine.getLightAt(1);
    light1.getDiffuse().set(1.0f, 0.0f, 0.0f, 1.0f);
    light1.getPosition().set(-4.0f, 5.0f, -5.0f, 1.0f);
    light1.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light1.getPosition().getArray()));
    light1.setEnabled(true);
    Light light2 = engine.getLightAt(2);
    light2.getDiffuse().set(0.0f, 1.0f, 0.0f, 1.0f);
    light2.getPosition().set(+4.0f, 5.0f, 0.0f, 1.0f);
    light2.getSpotDirection().set(0f, 0f, 0f).sub(new Vector3(light2.getPosition().getArray()));
    light2.setEnabled(true);
    // scene
    players = new ArrayList<Object3D>();
    playersBoundingVolumeModel = new ArrayList<Object3D>();
    playerBoundingVolumesTransformed = new ArrayList<BoundingVolume>();
    try {
        Model _barrel = DAEReader.read("resources/tests/models/barrel", "barrel.dae");
        Object3D barrel = new Object3D("barrel", _barrel);
        barrelBoundingVolume = new ConvexMesh(new Object3DModel(_barrel));
        barrel.getTranslation().set(1.5f, 0.35f, -2f);
        barrel.setDynamicShadowingEnabled(true);
        barrel.setEnabled(true);
        barrel.update();
        barrelBoundingVolumeTransformed = barrelBoundingVolume.clone();
        barrelBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(barrelBoundingVolume, barrel);
        engine.addEntity(barrel);
        // wall
        Model _farPlane = createWallModel();
        Object3D farPlane = new Object3D("wall", _farPlane);
        farPlane.bindDiffuseTexture("wall", "wall", osEngine.getFrameBuffer());
        engine.addEntity(farPlane);
        //
        Model _grass = DAEReader.read("resources/tests/models/grass", "grass.dae");
        Object3D grass = new Object3D("ground", _grass);
        grass.setEnabled(true);
        grass.getScale().set(8f, 1f, 8f);
        grass.update();
        engine.addEntity(grass);
        // players
        Model _player = DAEReader.read("resources/tests/models/dummy", "testDummy_textured.DAE");
        _player.addAnimationSetup("still", 3, 3, true);
        _player.addAnimationSetup("walk", 0, 18, true);
        // player bounding volume
        // playerBoundingVolume = Sphere.createBoundingVolume(new Vector3(0,90f/130f,0), 90f/130f);
        playerBoundingVolume = Capsule.createBoundingVolume(new Vector3(0, 30f / 130f, 0), new Vector3(0, 230f / 130f, 0), 25 / 130f);
        // playerBoundingVolume = BoundingBox.createBoundingVolume(new Vector3(-25f/130f, 0, -25f/130f), new Vector3(+25f/130f, 180f/130f, +25f/130f));
        /*
			playerBoundingVolume = OrientedBoundingBox.createBoundingVolume(
				new Vector3(0f, 90f/130f, 0f),
				new Vector3(1f, 0f, 0f),
				new Vector3(0f, 1f, 0f),
				new Vector3(0f, 0f, 1f),
				new Vector3(25f/130f, 90f/130f, 25f/130f)
			);
			*/
        playerBoundingVolumeModel = PrimitiveModel.createModel(playerBoundingVolume, "player_bv");
        // add player 1
        //	player
        Object3D player1 = new Object3D("player1", _player);
        player1.getTranslation().add(new Vector3(-1.50f, 0f, 0f));
        player1.setAnimation("still");
        player1.getRotations().add(new Rotation(0f, new Vector3(0f, 1f, 0f)));
        player1.update();
        player1.setEnabled(true);
        player1.setPickable(true);
        player1.setDynamicShadowingEnabled(true);
        engine.addEntity(player1);
        //	bounding volume transformed
        BoundingVolume player1BoundingVolumeTransformed = playerBoundingVolume.clone();
        player1BoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player1);
        playerBoundingVolumesTransformed.add(player1BoundingVolumeTransformed);
        //	add to engine
        players.add(player1);
        //	bounding volume
        Object3D player1BoundingVolume = new Object3D("player1_bv", playerBoundingVolumeModel);
        player1BoundingVolume.fromTransformations(player1);
        player1BoundingVolume.setEnabled(true);
        playersBoundingVolumeModel.add(player1BoundingVolume);
        // engine.addEntity(player1BoundingVolume);
        // add player 2
        //	player
        Object3D player2 = new Object3D("player2", _player);
        player2.getTranslation().add(new Vector3(1.50f, 0f, 0f));
        player2.setAnimation("still");
        player2.getRotations().add(new Rotation(0f, new Vector3(0f, 1f, 0f)));
        player2.update();
        player2.setEnabled(true);
        player2.setPickable(true);
        player2.setDynamicShadowingEnabled(true);
        players.add(player2);
        //	bounding volume transformed
        BoundingVolume player2BoundingVolumeTransformed = playerBoundingVolume.clone();
        player2BoundingVolumeTransformed.fromBoundingVolumeWithTransformations(playerBoundingVolume, player2);
        playerBoundingVolumesTransformed.add(player2BoundingVolumeTransformed);
        //	add to engine
        engine.addEntity(player2);
        //	bounding volume
        Object3D player2BoundingVolume = new Object3D("player2_bv", playerBoundingVolumeModel);
        player2BoundingVolume.fromTransformations(player2);
        player2BoundingVolume.setEnabled(true);
        playersBoundingVolumeModel.add(player2BoundingVolume);
        // engine.addEntity(player2BoundingVolume);
        // add cube
        Model _cube = DAEReader.read("resources/tests/models/test", "cube.dae");
        cube = new Object3D("cube", _cube);
        cube.getTranslation().add(new Vector3(0f, 0f, 0f));
        cube.getScale().set(2f, 2f, 2f);
        cube.update();
        cube.setPickable(true);
        cube.setDynamicShadowingEnabled(true);
        cube.setEnabled(true);
        cubeBoundingVolume = cube.getBoundingBox();
        cubeBoundingVolumeTransformed = cubeBoundingVolume.clone();
        cubeBoundingVolumeTransformed.fromBoundingVolumeWithTransformations(cubeBoundingVolume, cube);
        engine.addEntity(cube);
        //
        cubeBoundingVolumeModel = PrimitiveModel.createModel(cubeBoundingVolume, "cube_bv");
        //	bounding volume
        Object3D cubeBoundingVolumeObject3D = new Object3D("cube_bv", cubeBoundingVolumeModel);
        cubeBoundingVolumeObject3D.fromTransformations(cube);
        cubeBoundingVolumeObject3D.setEnabled(true);
        engine.addEntity(cubeBoundingVolumeObject3D);
        // wall
        Model _wall = DAEReader.read("resources/tests/models/wall", "wall.dae");
        Object3D wall0 = new Object3D("wall0", _wall);
        wall0.getTranslation().add(new Vector3(-1.00f, 0f, 3.00f));
        wall0.update();
        wall0.setPickable(true);
        wall0.setEnabled(true);
        engine.addEntity(wall0);
        Object3D wall1 = new Object3D("wall1", _wall);
        wall1.getTranslation().add(new Vector3(0f, 0f, 3.00f));
        wall1.update();
        wall1.setPickable(true);
        wall1.setEnabled(true);
        engine.addEntity(wall1);
        // os engine test
        Object3D osCube = new Object3D("cube", _cube);
        osCube.getTranslation().add(new Vector3(0f, 0f, 0f));
        osCube.getScale().set(2f, 2f, 2f);
        osCube.update();
        osEngine.addEntity(osCube);
        //
        circleTransformations = new Transformations();
        engine.addEntity(new PointsParticleSystemEntity("circle", false, new CircleParticleEmitter(3000, 50, 50, new Vector3(1f, 0f, 0f), new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 0f), 0.4f, 0f, 0f, new Vector3(0f, 0.2f, 0f), new Vector3(0f, 0.2f, 0f), new Color4(1f, 1f, 1f, 0.3f), new Color4(1f, 1f, 1f, 0.3f)), 1000, true));
        engine.getEntity("circle").setEnabled(true);
        engine.addEntity(new PointsParticleSystemEntity("water", true, new SphereParticleEmitter(4000, 1000, 0, 0.1f, 0.0f, new Sphere(new Vector3(-1f, 1f, 0f), 0.05f), new Vector3(-4f, 0f, 1f), new Vector3(-1f, 0f, 0f), new Color4(0.8f, 0.8f, 1f, 0.25f), new Color4(0.8f, 0.8f, 1f, 0.25f)), 4000, true));
        engine.getEntity("water").setEnabled(true);
        engine.addEntity(new PointsParticleSystemEntity("snow", false, new BoundingBoxParticleEmitter(15, 15000, 1000, 0, 0, new OrientedBoundingBox(new Vector3(0f, 4f, 0f), new Vector3(1f, 0f, 0f), new Vector3(0f, 1f, 0f), new Vector3(0f, 0f, 1f), new Vector3(4f, 0f, 4f)), new Vector3(0f, -0.5f, 0f), new Vector3(0f, -0.1f, 0f), new Color4(0.8f, 0.8f, 1f, 0.5f), new Color4(0.8f, 0.8f, 1f, 0.5f)), 1024, true));
        engine.getEntity("snow").setEnabled(true);
        engine.addEntity(new PointsParticleSystemEntity("firebase", false, new SphereParticleEmitter(2048, 1024, 2048, 0, 0, new Sphere(new Vector3(2.5f, 0.2f, 0f), 0.2f), new Vector3(0f, 0.1f, 0f), new Vector3(0f, 0.1f, 0f), new Color4(0.0f, 0f, 0f, 0.5f), new Color4(0.4f, 0f, 0f, 0.5f)), 2048, true));
        engine.getEntity("firebase").setEnabled(true);
        //
        engine.addEntity(new PointsParticleSystemEntity("firetop", false, new SphereParticleEmitter(2048, 1024, 2048, 0, 0, new Sphere(new Vector3(2.5f, 0.7f, 0f), 0.1f), new Vector3(0f, 0.06f, 0f), new Vector3(0f, 0.12f, 0f), new Color4(0.75f, 0.0f, 0f, 0.5f), new Color4(1f, 1f, 0f, 0.5f)), 2048, true));
        engine.getEntity("firetop").setEnabled(true);
        //
        engine.addEntity(new PointsParticleSystemEntity("firesmoke", false, new SphereParticleEmitter(2048, 1024, 2048, 0, 0, new Sphere(new Vector3(2.5f, 0.7f, 0f), 0.1f), new Vector3(0f, 0.2f, 0f), new Vector3(0f, 0.4f, 0f), new Color4(0.8f, 0.8f, 0.8f, 0.1f), new Color4(0.8f, 0.8f, 0.8f, 0.1f)), 2048, true));
        engine.getEntity("firesmoke").setEnabled(true);
        ((ParticleSystemEntity) engine.getEntity("circle")).setPickable(false);
        ((ParticleSystemEntity) engine.getEntity("snow")).setPickable(false);
        ((ParticleSystemEntity) engine.getEntity("firebase")).setPickable(true);
        ((ParticleSystemEntity) engine.getEntity("firetop")).setPickable(true);
        ((ParticleSystemEntity) engine.getEntity("firesmoke")).setPickable(true);
    } catch (Exception exception) {
        exception.printStackTrace();
        System.out.println("Could not load object: " + exception.getMessage());
    }
}
Also used : CircleParticleEmitter(net.drewke.tdme.engine.subsystems.particlesystem.CircleParticleEmitter) Vector3(net.drewke.tdme.math.Vector3) ConvexMesh(net.drewke.tdme.engine.primitives.ConvexMesh) Object3DModel(net.drewke.tdme.engine.Object3DModel) PointsParticleSystemEntity(net.drewke.tdme.engine.PointsParticleSystemEntity) PointsParticleSystemEntity(net.drewke.tdme.engine.PointsParticleSystemEntity) ParticleSystemEntity(net.drewke.tdme.engine.subsystems.particlesystem.ParticleSystemEntity) Rotation(net.drewke.tdme.engine.Rotation) Object3D(net.drewke.tdme.engine.Object3D) Sphere(net.drewke.tdme.engine.primitives.Sphere) Color4(net.drewke.tdme.engine.model.Color4) OrientedBoundingBox(net.drewke.tdme.engine.primitives.OrientedBoundingBox) Light(net.drewke.tdme.engine.Light) Model(net.drewke.tdme.engine.model.Model) Object3DModel(net.drewke.tdme.engine.Object3DModel) PrimitiveModel(net.drewke.tdme.engine.primitives.PrimitiveModel) BoundingVolume(net.drewke.tdme.engine.primitives.BoundingVolume) Transformations(net.drewke.tdme.engine.Transformations) BoundingBoxParticleEmitter(net.drewke.tdme.engine.subsystems.particlesystem.BoundingBoxParticleEmitter) Camera(net.drewke.tdme.engine.Camera) SphereParticleEmitter(net.drewke.tdme.engine.subsystems.particlesystem.SphereParticleEmitter)

Aggregations

Object3D (net.drewke.tdme.engine.Object3D)18 Entity (net.drewke.tdme.engine.Entity)8 Vector3 (net.drewke.tdme.math.Vector3)8 FacesEntity (net.drewke.tdme.engine.model.FacesEntity)7 Camera (net.drewke.tdme.engine.Camera)6 Rotation (net.drewke.tdme.engine.Rotation)6 Model (net.drewke.tdme.engine.model.Model)6 LevelEditorEntity (net.drewke.tdme.tools.shared.model.LevelEditorEntity)6 Light (net.drewke.tdme.engine.Light)5 BoundingVolume (net.drewke.tdme.engine.primitives.BoundingVolume)4 OrientedBoundingBox (net.drewke.tdme.engine.primitives.OrientedBoundingBox)4 PrimitiveModel (net.drewke.tdme.engine.primitives.PrimitiveModel)4 LevelEditorObject (net.drewke.tdme.tools.shared.model.LevelEditorObject)4 Object3DModel (net.drewke.tdme.engine.Object3DModel)3 Transformations (net.drewke.tdme.engine.Transformations)3 ConvexMesh (net.drewke.tdme.engine.primitives.ConvexMesh)3 Sphere (net.drewke.tdme.engine.primitives.Sphere)3 ObjectParticleSystemEntity (net.drewke.tdme.engine.ObjectParticleSystemEntity)2 PointsParticleSystemEntity (net.drewke.tdme.engine.PointsParticleSystemEntity)2 Color4 (net.drewke.tdme.engine.model.Color4)2