Search in sources :

Example 11 with com.jme3.opencl

use of com.jme3.opencl in project jmonkeyengine by jMonkeyEngine.

the class RenderManager method renderViewPort.

/**
     * Renders the {@link ViewPort}.
     * <p>
     * If the ViewPort is {@link ViewPort#isEnabled() disabled}, this method
     * returns immediately. Otherwise, the ViewPort is rendered by 
     * the following process:<br>
     * <ul>
     * <li>All {@link SceneProcessor scene processors} that are attached
     * to the ViewPort are {@link SceneProcessor#initialize(com.jme3.renderer.RenderManager, com.jme3.renderer.ViewPort) initialized}.
     * </li>
     * <li>The SceneProcessors' {@link SceneProcessor#preFrame(float) } method 
     * is called.</li>
     * <li>The ViewPort's {@link ViewPort#getOutputFrameBuffer() output framebuffer}
     * is set on the Renderer</li>
     * <li>The camera is set on the renderer, including its view port parameters.
     * (see {@link #setCamera(com.jme3.renderer.Camera, boolean) })</li>
     * <li>Any buffers that the ViewPort requests to be cleared are cleared
     * and the {@link ViewPort#getBackgroundColor() background color} is set</li>
     * <li>Every scene that is attached to the ViewPort is flattened into 
     * the ViewPort's render queue 
     * (see {@link #renderViewPortQueues(com.jme3.renderer.ViewPort, boolean) })
     * </li>
     * <li>The SceneProcessors' {@link SceneProcessor#postQueue(com.jme3.renderer.queue.RenderQueue) }
     * method is called.</li>
     * <li>The render queue is sorted and then flushed, sending
     * rendering commands to the underlying Renderer implementation. 
     * (see {@link #flushQueue(com.jme3.renderer.ViewPort) })</li>
     * <li>The SceneProcessors' {@link SceneProcessor#postFrame(com.jme3.texture.FrameBuffer) }
     * method is called.</li>
     * <li>The translucent queue of the ViewPort is sorted and then flushed
     * (see {@link #renderTranslucentQueue(com.jme3.renderer.ViewPort) })</li>
     * <li>If any objects remained in the render queue, they are removed
     * from the queue. This is generally objects added to the 
     * {@link RenderQueue#renderShadowQueue(com.jme3.renderer.queue.RenderQueue.ShadowMode, com.jme3.renderer.RenderManager, com.jme3.renderer.Camera, boolean) 
     * shadow queue}
     * which were not rendered because of a missing shadow renderer.</li>
     * </ul>
     * 
     * @param vp View port to render
     * @param tpf Time per frame value
     */
public void renderViewPort(ViewPort vp, float tpf) {
    if (!vp.isEnabled()) {
        return;
    }
    if (prof != null)
        prof.vpStep(VpStep.BeginRender, vp, null);
    SafeArrayList<SceneProcessor> processors = vp.getProcessors();
    if (processors.isEmpty()) {
        processors = null;
    }
    if (processors != null) {
        if (prof != null)
            prof.vpStep(VpStep.PreFrame, vp, null);
        for (SceneProcessor proc : processors.getArray()) {
            if (!proc.isInitialized()) {
                proc.initialize(this, vp);
            }
            proc.setProfiler(this.prof);
            if (prof != null)
                prof.spStep(SpStep.ProcPreFrame, proc.getClass().getSimpleName());
            proc.preFrame(tpf);
        }
    }
    renderer.setFrameBuffer(vp.getOutputFrameBuffer());
    setCamera(vp.getCamera(), false);
    if (vp.isClearDepth() || vp.isClearColor() || vp.isClearStencil()) {
        if (vp.isClearColor()) {
            renderer.setBackgroundColor(vp.getBackgroundColor());
        }
        renderer.clearBuffers(vp.isClearColor(), vp.isClearDepth(), vp.isClearStencil());
    }
    if (prof != null)
        prof.vpStep(VpStep.RenderScene, vp, null);
    List<Spatial> scenes = vp.getScenes();
    for (int i = scenes.size() - 1; i >= 0; i--) {
        renderScene(scenes.get(i), vp);
    }
    if (processors != null) {
        if (prof != null)
            prof.vpStep(VpStep.PostQueue, vp, null);
        for (SceneProcessor proc : processors.getArray()) {
            if (prof != null)
                prof.spStep(SpStep.ProcPostQueue, proc.getClass().getSimpleName());
            proc.postQueue(vp.getQueue());
        }
    }
    if (prof != null)
        prof.vpStep(VpStep.FlushQueue, vp, null);
    flushQueue(vp);
    if (processors != null) {
        if (prof != null)
            prof.vpStep(VpStep.PostFrame, vp, null);
        for (SceneProcessor proc : processors.getArray()) {
            if (prof != null)
                prof.spStep(SpStep.ProcPostFrame, proc.getClass().getSimpleName());
            proc.postFrame(vp.getOutputFrameBuffer());
        }
        if (prof != null)
            prof.vpStep(VpStep.ProcEndRender, vp, null);
    }
    //renders the translucent objects queue after processors have been rendered
    renderTranslucentQueue(vp);
    // clear any remaining spatials that were not rendered.
    clearQueue(vp);
    if (prof != null)
        prof.vpStep(VpStep.EndRender, vp, null);
}
Also used : SceneProcessor(com.jme3.post.SceneProcessor)

Example 12 with com.jme3.opencl

use of com.jme3.opencl in project jmonkeyengine by jMonkeyEngine.

the class Mesh method createCollisionData.

/**
     * Generates a collision tree for the mesh.
     * Called automatically by {@link #collideWith(com.jme3.collision.Collidable,
     * com.jme3.math.Matrix4f,
     * com.jme3.bounding.BoundingVolume,
     * com.jme3.collision.CollisionResults) }.
     */
public void createCollisionData() {
    BIHTree tree = new BIHTree(this);
    tree.construct();
    collisionTree = tree;
}
Also used : BIHTree(com.jme3.collision.bih.BIHTree)

Example 13 with com.jme3.opencl

use of com.jme3.opencl in project jmonkeyengine by jMonkeyEngine.

the class Spatial method lookAt.

/**
     * <code>lookAt</code> is a convenience method for auto-setting the local
     * rotation based on a position in world space and an up vector. It computes the rotation
     * to transform the z-axis to point onto 'position' and the y-axis to 'up'.
     * Unlike {@link Quaternion#lookAt(com.jme3.math.Vector3f, com.jme3.math.Vector3f) }
     * this method takes a world position to look at and not a relative direction.
     *
     * Note : 28/01/2013 this method has been fixed as it was not taking into account the parent rotation.
     * This was resulting in improper rotation when the spatial had rotated parent nodes.
     * This method is intended to work in world space, so no matter what parent graph the
     * spatial has, it will look at the given position in world space.
     *
     * @param position
     *            where to look at in terms of world coordinates
     * @param upVector
     *            a vector indicating the (local) up direction. (typically {0,
     *            1, 0} in jME.)
     */
public void lookAt(Vector3f position, Vector3f upVector) {
    Vector3f worldTranslation = getWorldTranslation();
    TempVars vars = TempVars.get();
    Vector3f compVecA = vars.vect4;
    compVecA.set(position).subtractLocal(worldTranslation);
    getLocalRotation().lookAt(compVecA, upVector);
    if (getParent() != null) {
        Quaternion rot = vars.quat1;
        rot = rot.set(parent.getWorldRotation()).inverseLocal().multLocal(getLocalRotation());
        rot.normalizeLocal();
        setLocalRotation(rot);
    }
    vars.release();
    setTransformRefresh();
}
Also used : TempVars(com.jme3.util.TempVars)

Example 14 with com.jme3.opencl

use of com.jme3.opencl in project jmonkeyengine by jMonkeyEngine.

the class FbxImage method createImage.

private Image createImage() {
    AssetManager assetManager = scene.assetManager;
    Image image = null;
    if (filename != null) {
        // Try load by absolute path
        File file = new File(filename);
        if (file.exists() && file.isFile()) {
            File dir = new File(file.getParent());
            String locatorPath = dir.getAbsolutePath();
            Texture tex = null;
            try {
                assetManager.registerLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
                tex = assetManager.loadTexture(file.getName());
            } catch (Exception e) {
            } finally {
                assetManager.unregisterLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
            }
            if (tex != null)
                image = tex.getImage();
        }
    }
    if (image == null && relativeFilename != null) {
        // Try load by relative path
        File dir = new File(scene.sceneFolderName);
        String locatorPath = dir.getAbsolutePath();
        Texture tex = null;
        try {
            assetManager.registerLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
            tex = assetManager.loadTexture(relativeFilename);
        } catch (Exception e) {
        } finally {
            assetManager.unregisterLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
        }
        if (tex != null)
            image = tex.getImage();
    }
    if (image == null && content != null) {
        // Try load from content
        String filename = null;
        if (this.filename != null)
            filename = new File(this.filename).getName();
        if (filename != null && this.relativeFilename != null)
            filename = this.relativeFilename;
        // Filename is required to aquire asset loader by extension
        if (filename != null) {
            String locatorPath = scene.sceneFilename;
            // Unique path
            filename = scene.sceneFilename + File.separatorChar + filename;
            Texture tex = null;
            try {
                assetManager.registerLocator(locatorPath, ContentTextureLocator.class);
                tex = assetManager.loadTexture(new ContentTextureKey(filename, content));
            } catch (Exception e) {
            } finally {
                assetManager.unregisterLocator(locatorPath, ContentTextureLocator.class);
            }
            if (tex != null)
                image = tex.getImage();
        }
    }
    if (image == null) {
        // Try to load from files near
        if (relativeFilename != null) {
            String[] split = relativeFilename.split("[\\\\/]");
            String filename = split[split.length - 1];
            Texture tex = null;
            try {
                tex = assetManager.loadTexture(new ContentTextureKey(scene.currentAssetInfo.getKey().getFolder() + filename, content));
            } catch (Exception e) {
            }
            if (tex != null)
                image = tex.getImage();
        }
    }
    if (image == null)
        return new Image(Image.Format.RGB8, 1, 1, BufferUtils.createByteBuffer((int) ((long) 1 * (long) 1 * (long) Image.Format.RGB8.getBitsPerPixel() / 8L)), ColorSpace.Linear);
    return image;
}
Also used : AssetManager(com.jme3.asset.AssetManager) ContentTextureKey(com.jme3.scene.plugins.fbx.ContentTextureKey) Image(com.jme3.texture.Image) File(java.io.File) Texture(com.jme3.texture.Texture)

Example 15 with com.jme3.opencl

use of com.jme3.opencl in project jmonkeyengine by jMonkeyEngine.

the class SceneLoader method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attribs) throws SAXException {
    if (qName.equals("scene")) {
        if (elementStack.size() != 0) {
            throw new SAXException("dotScene parse error: 'scene' element must be the root XML element");
        }
        String version = attribs.getValue("formatVersion");
        if (version == null || (!version.equals("1.0.0") && !version.equals("1.0.1"))) {
            logger.log(Level.WARNING, "Unrecognized version number" + " in dotScene file: {0}", version);
        }
    } else if (qName.equals("nodes")) {
        if (root != null) {
            throw new SAXException("dotScene parse error: nodes element was specified twice");
        }
        if (sceneName == null) {
            root = new com.jme3.scene.Node("OgreDotScene" + (++sceneIdx));
        } else {
            root = new com.jme3.scene.Node(sceneName + "-scene_node");
        }
        node = root;
    } else if (qName.equals("externals")) {
        checkTopNode("scene");
    } else if (qName.equals("item")) {
        checkTopNode("externals");
    } else if (qName.equals("file")) {
        checkTopNode("item");
    // NOTE: This part of the file is ignored, it is parsed
    // by SceneMaterialLoader in the first pass.
    } else if (qName.equals("node")) {
        String curElement = elementStack.peek();
        if (!curElement.equals("node") && !curElement.equals("nodes")) {
            throw new SAXException("dotScene parse error: " + "node element can only appear under 'node' or 'nodes'");
        }
        parseNode(attribs);
    } else if (qName.equals("property")) {
        if (node != null) {
            String type = attribs.getValue("type");
            String name = attribs.getValue("name");
            String data = attribs.getValue("data");
            if (type.equals("BOOL")) {
                node.setUserData(name, Boolean.parseBoolean(data) || data.equals("1"));
            } else if (type.equals("FLOAT")) {
                node.setUserData(name, Float.parseFloat(data));
            } else if (type.equals("STRING")) {
                node.setUserData(name, data);
            } else if (type.equals("INT")) {
                node.setUserData(name, Integer.parseInt(data));
            }
        }
    } else if (qName.equals("entity")) {
        checkTopNode("node");
        parseEntity(attribs);
    } else if (qName.equals("camera")) {
        checkTopNode("node");
        parseCamera(attribs);
    } else if (qName.equals("clipping")) {
        checkTopNode("camera");
        parseCameraClipping(attribs);
    } else if (qName.equals("position")) {
        if (elementStack.peek().equals("node")) {
            node.setLocalTranslation(SAXUtil.parseVector3(attribs));
        } else if (elementStack.peek().equals("camera")) {
            cameraNode.setLocalTranslation(SAXUtil.parseVector3(attribs));
        }
    } else if (qName.equals("quaternion") || qName.equals("rotation")) {
        node.setLocalRotation(parseQuat(attribs));
    } else if (qName.equals("scale")) {
        node.setLocalScale(SAXUtil.parseVector3(attribs));
    } else if (qName.equals("light")) {
        parseLight(attribs);
    } else if (qName.equals("colourDiffuse") || qName.equals("colorDiffuse")) {
        if (elementStack.peek().equals("light")) {
            if (light != null) {
                light.setColor(parseColor(attribs));
            }
        } else {
            checkTopNode("environment");
        }
    } else if (qName.equals("colourAmbient") || qName.equals("colorAmbient")) {
        if (elementStack.peek().equals("environment")) {
            ColorRGBA color = parseColor(attribs);
            if (!color.equals(ColorRGBA.Black) && !color.equals(ColorRGBA.BlackNoAlpha)) {
                // Lets add an ambient light to the scene.
                AmbientLight al = new AmbientLight();
                al.setColor(color);
                root.addLight(al);
            }
        }
    } else if (qName.equals("normal") || qName.equals("direction")) {
        checkTopNode("light");
        parseLightNormal(attribs);
    } else if (qName.equals("lightAttenuation")) {
        parseLightAttenuation(attribs);
    } else if (qName.equals("spotLightRange") || qName.equals("lightRange")) {
        parseLightSpotLightRange(attribs);
    }
    elementStack.push(qName);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) LightNode(com.jme3.scene.LightNode) CameraNode(com.jme3.scene.CameraNode) AmbientLight(com.jme3.light.AmbientLight) SAXException(org.xml.sax.SAXException)

Aggregations

ByteBuffer (java.nio.ByteBuffer)8 Vector3f (com.jme3.math.Vector3f)7 ColorRGBA (com.jme3.math.ColorRGBA)6 Material (com.jme3.material.Material)5 com.jme3.opencl (com.jme3.opencl)5 Geometry (com.jme3.scene.Geometry)5 BitmapText (com.jme3.font.BitmapText)4 RendererException (com.jme3.renderer.RendererException)4 Texture (com.jme3.texture.Texture)4 ArrayList (java.util.ArrayList)4 BitmapFont (com.jme3.font.BitmapFont)3 Matrix4f (com.jme3.math.Matrix4f)3 DefaultPlatformChooser (com.jme3.opencl.DefaultPlatformChooser)3 Device (com.jme3.opencl.Device)3 PlatformChooser (com.jme3.opencl.PlatformChooser)3 AppSettings (com.jme3.system.AppSettings)3 Image (com.jme3.texture.Image)3 TextureCubeMap (com.jme3.texture.TextureCubeMap)3 CubeMapWrapper (com.jme3.environment.util.CubeMapWrapper)2 AmbientLight (com.jme3.light.AmbientLight)2