Search in sources :

Example 1 with MeshManager

use of net.drewke.tdme.engine.subsystems.manager.MeshManager in project tdme by andreasdr.

the class Object3DBase method init.

/**
	 * Initiates this object3d 
	 */
public void init() {
    MeshManager meshManager = Engine.getInstance().getMeshManager();
    // init mesh
    for (int i = 0; i < object3dGroups.length; i++) {
        Object3DGroup object3DGroup = object3dGroups[i];
        // initiate mesh if not yet done, happens usually after disposing from engine and readding to engine
        if (object3DGroup.mesh == null) {
            if (usesMeshManager == true) {
                object3DGroup.mesh = meshManager.getMesh(object3DGroup.id);
                if (object3DGroup.mesh == null) {
                    object3DGroup.mesh = Object3DGroupMesh.createMesh(animationProcessingTarget, object3DGroup.group, object3DGroup.object.transformationsMatrices);
                    meshManager.addMesh(object3DGroup.id, object3DGroup.mesh);
                }
            } else {
                object3DGroup.mesh = Object3DGroupMesh.createMesh(animationProcessingTarget, object3DGroup.group, object3DGroup.object.transformationsMatrices);
            }
        }
    }
}
Also used : MeshManager(net.drewke.tdme.engine.subsystems.manager.MeshManager)

Example 2 with MeshManager

use of net.drewke.tdme.engine.subsystems.manager.MeshManager in project tdme by andreasdr.

the class Object3DGroup method createGroups.

/**
	 * Creates a object 3d groups recursively for given group and it sub groups
	 * @param object 3D base
	 * @param object 3D groups
	 * @param groups
	 * @param animated
	 * @param use mesh manager
	 */
private static void createGroups(Object3DBase object3D, ArrayList<Object3DGroup> object3DGroups, HashMap<String, Group> groups, boolean animated, boolean useMeshManager, Engine.AnimationProcessingTarget animationProcessingTarget) {
    for (Group group : groups.getValuesIterator()) {
        // skip on joints
        if (group.isJoint() == true) {
            continue;
        }
        // determine face count
        int faceCount = group.getFaceCount();
        // skip on groups without faces
        if (faceCount > 0) {
            // create group render data
            Object3DGroup object3DGroup = new Object3DGroup();
            // add it to group render data list
            object3DGroups.add(object3DGroup);
            // determine mesh id
            object3DGroup.id = group.getModel().getId() + ":" + group.getId() + ":" + animationProcessingTarget.toString().toLowerCase();
            if (animated == true && (animationProcessingTarget == AnimationProcessingTarget.CPU || animationProcessingTarget == AnimationProcessingTarget.CPU_NORENDERING)) {
                //
                object3DGroup.id += ":" + (counter++);
            }
            object3DGroup.object = object3D;
            object3DGroup.group = group;
            object3DGroup.animated = animated;
            if (useMeshManager == true) {
                MeshManager meshManager = Engine.getInstance().getMeshManager();
                object3DGroup.mesh = meshManager.getMesh(object3DGroup.id);
                if (object3DGroup.mesh == null) {
                    object3DGroup.mesh = Object3DGroupMesh.createMesh(animationProcessingTarget, group, object3D.transformationsMatrices);
                    meshManager.addMesh(object3DGroup.id, object3DGroup.mesh);
                }
            } else {
                object3DGroup.mesh = Object3DGroupMesh.createMesh(animationProcessingTarget, group, object3D.transformationsMatrices);
            }
            object3DGroup.materialDiffuseTextureIdsByEntities = new int[group.getFacesEntities().length];
            object3DGroup.dynamicDiffuseTextureIdsByEntities = new int[group.getFacesEntities().length];
            object3DGroup.materialSpecularTextureIdsByEntities = new int[group.getFacesEntities().length];
            object3DGroup.materialDisplacementTextureIdsByEntities = new int[group.getFacesEntities().length];
            object3DGroup.materialNormalTextureIdsByEntities = new int[group.getFacesEntities().length];
            for (int j = 0; j < group.getFacesEntities().length; j++) {
                object3DGroup.materialDiffuseTextureIdsByEntities[j] = GLTEXTUREID_NONE;
                object3DGroup.dynamicDiffuseTextureIdsByEntities[j] = GLTEXTUREID_NONE;
                object3DGroup.materialSpecularTextureIdsByEntities[j] = GLTEXTUREID_NONE;
                object3DGroup.materialDisplacementTextureIdsByEntities[j] = GLTEXTUREID_NONE;
                object3DGroup.materialNormalTextureIdsByEntities[j] = GLTEXTUREID_NONE;
            }
            // determine renderer
            object3DGroup.renderer = new Object3DGroupVBORenderer(object3DGroup);
            // skinning
            Skinning skinning = group.getSkinning();
            if (skinning != null) {
                object3DGroup.groupTransformationsMatricesVector = new ArrayList<Matrix4x4>();
                for (Joint joint : skinning.getJoints()) {
                    object3DGroup.groupTransformationsMatricesVector.add(object3D.transformationsMatrices.get(joint.getGroupId()));
                }
            } else {
                object3DGroup.groupTransformationsMatricesVector = null;
            }
            //
            object3DGroup.groupTransformationsMatrix = object3D.transformationsMatrices.get(group.getId());
        }
        // but still check sub groups
        createGroups(object3D, object3DGroups, group.getSubGroups(), animated, useMeshManager, animationProcessingTarget);
    }
}
Also used : Group(net.drewke.tdme.engine.model.Group) Skinning(net.drewke.tdme.engine.model.Skinning) Joint(net.drewke.tdme.engine.model.Joint) MeshManager(net.drewke.tdme.engine.subsystems.manager.MeshManager) Joint(net.drewke.tdme.engine.model.Joint) Matrix4x4(net.drewke.tdme.math.Matrix4x4)

Example 3 with MeshManager

use of net.drewke.tdme.engine.subsystems.manager.MeshManager in project tdme by andreasdr.

the class Object3DBase method dispose.

/**
	 * Disposes this object3d 
	 */
public void dispose() {
    MeshManager meshManager = Engine.getInstance().getMeshManager();
    // dispose mesh
    for (int i = 0; i < object3dGroups.length; i++) {
        Object3DGroup object3DGroup = object3dGroups[i];
        // dispose mesh
        meshManager.removeMesh(object3DGroup.id);
        object3DGroup.mesh = null;
    }
}
Also used : MeshManager(net.drewke.tdme.engine.subsystems.manager.MeshManager)

Example 4 with MeshManager

use of net.drewke.tdme.engine.subsystems.manager.MeshManager in project tdme by andreasdr.

the class Engine method init.

/**
	 * Initialize render engine
	 * @param drawable
	 * @param debug
	 */
public void init(GLAutoDrawable drawable, boolean debug) {
    // exit if already initialized like a offscreen engine instance
    if (initialized == true)
        return;
    //
    GLContext glContext = drawable.getGL().getContext();
    if (drawable.getGL().isGL3()) {
        GL3 gl = (GL3) drawable.getGL().getGL3();
        if (debug == true) {
            drawable.setGL(new DebugGL3(gl));
        }
        // use gl3 renderer
        renderer = new GL3Renderer() {

            public final void onUpdateProjectionMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateCameraMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateModelViewMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onBindTexture(int textureId) {
                if (lightingShader != null)
                    lightingShader.bindTexture(this, textureId);
                if (guiShader != null)
                    guiShader.bindTexture(this, textureId);
            }

            public final void onUpdateTextureMatrix() {
            // no op
            }

            public final void onUpdateEffect() {
                if (lightingShader != null)
                    lightingShader.updateEffect(this);
                if (particlesShader != null)
                    particlesShader.updateEffect(this);
                if (guiShader != null)
                    guiShader.updateEffect(this);
            }

            public final void onUpdateLight(int lightId) {
                if (lightingShader != null)
                    lightingShader.updateLight(this, lightId);
            }

            public final void onUpdateMaterial() {
                if (lightingShader != null)
                    lightingShader.updateMaterial(this);
            }
        };
        // notify gl context to renderer
        renderer.setGL(gl);
        // print gl version, extensions
        System.out.println("TDME::Using GL3");
        System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
        // engine defaults
        shadowMappingEnabled = true;
        animationProcessingTarget = AnimationProcessingTarget.CPU;
        ShadowMapping.setShadowMapSize(2048, 2048);
    } else if (drawable.getGL().isGL2()) {
        GL2 gl = (GL2) drawable.getGL().getGL2();
        if (debug == true) {
            drawable.setGL(new DebugGL2(gl));
        }
        // use gl2 renderer
        renderer = new GL2Renderer() {

            public final void onUpdateProjectionMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateCameraMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateModelViewMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onBindTexture(int textureId) {
                if (lightingShader != null)
                    lightingShader.bindTexture(this, textureId);
                if (guiShader != null)
                    guiShader.bindTexture(this, textureId);
            }

            public final void onUpdateTextureMatrix() {
            // no op
            }

            public final void onUpdateEffect() {
                if (lightingShader != null)
                    lightingShader.updateEffect(this);
                if (particlesShader != null)
                    particlesShader.updateEffect(this);
                if (guiShader != null)
                    guiShader.updateEffect(this);
            }

            public final void onUpdateLight(int lightId) {
                if (lightingShader != null)
                    lightingShader.updateLight(this, lightId);
            }

            public final void onUpdateMaterial() {
                if (lightingShader != null)
                    lightingShader.updateMaterial(this);
            }
        };
        // notify gl context to renderer
        renderer.setGL(gl);
        // print gl version, extensions
        System.out.println("TDME::Using GL2");
        System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
        // engine defaults
        shadowMappingEnabled = true;
        animationProcessingTarget = AnimationProcessingTarget.CPU;
        ShadowMapping.setShadowMapSize(2048, 2048);
    } else if (drawable.getGL().isGLES2()) {
        GLES2 gl = (GLES2) drawable.getGL().getGLES2();
        if (debug == true) {
            drawable.setGL(new DebugGLES2(gl));
        }
        // use gl es 2 renderer
        renderer = new GLES2Renderer() {

            public final void onUpdateProjectionMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateCameraMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onUpdateModelViewMatrix() {
                if (lightingShader != null)
                    lightingShader.updateMatrices(this);
                if (particlesShader != null)
                    particlesShader.updateMatrices(this);
                if (shadowMapping != null)
                    shadowMapping.updateMVPMatrices(this);
            }

            public final void onBindTexture(int textureId) {
                if (lightingShader != null)
                    lightingShader.bindTexture(this, textureId);
                if (guiShader != null)
                    guiShader.bindTexture(this, textureId);
            }

            public final void onUpdateTextureMatrix() {
            // no op
            }

            public final void onUpdateEffect() {
                if (lightingShader != null)
                    lightingShader.updateEffect(this);
                if (particlesShader != null)
                    particlesShader.updateEffect(this);
                if (guiShader != null)
                    guiShader.updateEffect(this);
            }

            public final void onUpdateLight(int lightId) {
                if (lightingShader != null)
                    lightingShader.updateLight(this, lightId);
            }

            public final void onUpdateMaterial() {
                if (lightingShader != null)
                    lightingShader.updateMaterial(this);
            }
        };
        // notify gl context to renderer
        renderer.setGL(gl);
        // print gl version, extensions
        System.out.println("TDME::Using GLES2");
        System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
        // is shadow mapping available?
        if (renderer.isBufferObjectsAvailable() == true && renderer.isDepthTextureAvailable() == true) {
            // yep, nice
            shadowMappingEnabled = true;
            animationProcessingTarget = AnimationProcessingTarget.CPU;
            ShadowMapping.setShadowMapSize(512, 512);
        } else {
            // nope, renderer skinning on GPU to speed up things and do not shadow mapping
            shadowMappingEnabled = false;
            animationProcessingTarget = AnimationProcessingTarget.GPU;
        }
    } else {
        System.out.println("Engine::init(): unsupported GL!");
        return;
    }
    // init
    initialized = true;
    renderer.init();
    renderer.renderingTexturingClientState = false;
    // create manager
    textureManager = new TextureManager(renderer);
    vboManager = new VBOManager(renderer);
    meshManager = new MeshManager();
    // create object 3d vbo renderer
    object3DVBORenderer = new Object3DVBORenderer(this, renderer);
    object3DVBORenderer.init();
    // create GUI
    guiRenderer = new GUIRenderer(renderer);
    guiRenderer.init();
    gui = new GUI(this, guiRenderer);
    gui.init();
    // create camera
    camera = new Camera(renderer);
    partition = new PartitionQuadTree();
    // create lights
    for (int i = 0; i < lights.length; i++) lights[i] = new Light(renderer, i);
    // create lighting shader
    lightingShader = new LightingShader(renderer);
    lightingShader.init();
    // create particles shader
    particlesShader = new ParticlesShader(this, renderer);
    particlesShader.init();
    // create GUI shader
    guiShader = new GUIShader(renderer);
    guiShader.init();
    // check if VBOs are available
    if (renderer.isBufferObjectsAvailable()) {
        System.out.println("TDME::VBOs are available.");
    } else {
        System.out.println("TDME::VBOs are not available! Engine will not work!");
        initialized = false;
    }
    // check FBO support
    if (glContext.hasBasicFBOSupport() == false) {
        System.out.println("TDME::Basic FBOs are not available!");
        shadowMappingEnabled = false;
    } else {
        System.out.println("TDME::Basic FBOs are available.");
    }
    // initialize shadow mapping
    if (shadowMappingEnabled == true) {
        System.out.println("TDME::Using shadow mapping");
        shadowMappingShaderPre = new ShadowMappingShaderPre(renderer);
        shadowMappingShaderPre.init();
        shadowMappingShaderRender = new ShadowMappingShaderRender(renderer);
        shadowMappingShaderRender.init();
        shadowMapping = new ShadowMapping(this, renderer, object3DVBORenderer);
    } else {
        System.out.println("TDME::Not using shadow mapping");
    }
    // print out animation processing target
    System.out.println("TDME: animation processing target: " + animationProcessingTarget);
    // determine initialized from sub systems
    initialized &= shadowMappingShaderPre == null ? true : shadowMappingShaderPre.isInitialized();
    initialized &= shadowMappingShaderRender == null ? true : shadowMappingShaderRender.isInitialized();
    initialized &= lightingShader.isInitialized();
    initialized &= particlesShader.isInitialized();
    initialized &= guiShader.isInitialized();
    //
    System.out.println("TDME::initialized & ready: " + initialized);
}
Also used : ParticlesShader(net.drewke.tdme.engine.subsystems.particlesystem.ParticlesShader) ShadowMappingShaderRender(net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMappingShaderRender) ShadowMappingShaderPre(net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMappingShaderPre) VBOManager(net.drewke.tdme.engine.subsystems.manager.VBOManager) GLContext(com.jogamp.opengl.GLContext) LightingShader(net.drewke.tdme.engine.subsystems.lighting.LightingShader) GUIShader(net.drewke.tdme.gui.renderer.GUIShader) DebugGLES2(com.jogamp.opengl.DebugGLES2) GUIRenderer(net.drewke.tdme.gui.renderer.GUIRenderer) ShadowMapping(net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMapping) Object3DVBORenderer(net.drewke.tdme.engine.subsystems.object.Object3DVBORenderer) DebugGL2(com.jogamp.opengl.DebugGL2) GUI(net.drewke.tdme.gui.GUI) DebugGL3(com.jogamp.opengl.DebugGL3) MeshManager(net.drewke.tdme.engine.subsystems.manager.MeshManager) GLES2Renderer(net.drewke.tdme.engine.subsystems.renderer.GLES2Renderer) GL2Renderer(net.drewke.tdme.engine.subsystems.renderer.GL2Renderer) GL3Renderer(net.drewke.tdme.engine.subsystems.renderer.GL3Renderer) GL2(com.jogamp.opengl.GL2) DebugGL2(com.jogamp.opengl.DebugGL2) GL3(com.jogamp.opengl.GL3) DebugGL3(com.jogamp.opengl.DebugGL3) TextureManager(net.drewke.tdme.engine.subsystems.manager.TextureManager) DebugGLES2(com.jogamp.opengl.DebugGLES2) GLES2(com.jogamp.opengl.GLES2)

Aggregations

MeshManager (net.drewke.tdme.engine.subsystems.manager.MeshManager)4 DebugGL2 (com.jogamp.opengl.DebugGL2)1 DebugGL3 (com.jogamp.opengl.DebugGL3)1 DebugGLES2 (com.jogamp.opengl.DebugGLES2)1 GL2 (com.jogamp.opengl.GL2)1 GL3 (com.jogamp.opengl.GL3)1 GLContext (com.jogamp.opengl.GLContext)1 GLES2 (com.jogamp.opengl.GLES2)1 Group (net.drewke.tdme.engine.model.Group)1 Joint (net.drewke.tdme.engine.model.Joint)1 Skinning (net.drewke.tdme.engine.model.Skinning)1 LightingShader (net.drewke.tdme.engine.subsystems.lighting.LightingShader)1 TextureManager (net.drewke.tdme.engine.subsystems.manager.TextureManager)1 VBOManager (net.drewke.tdme.engine.subsystems.manager.VBOManager)1 Object3DVBORenderer (net.drewke.tdme.engine.subsystems.object.Object3DVBORenderer)1 ParticlesShader (net.drewke.tdme.engine.subsystems.particlesystem.ParticlesShader)1 GL2Renderer (net.drewke.tdme.engine.subsystems.renderer.GL2Renderer)1 GL3Renderer (net.drewke.tdme.engine.subsystems.renderer.GL3Renderer)1 GLES2Renderer (net.drewke.tdme.engine.subsystems.renderer.GLES2Renderer)1 ShadowMapping (net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMapping)1