Search in sources :

Example 6 with Mode

use of com.jme3.scene.Mesh.Mode in project jmonkeyengine by jMonkeyEngine.

the class VRAppState method update.

@Override
public void update(float tpf) {
    // update VR pose & cameras
    if (environment.getVRViewManager() != null) {
        environment.getVRViewManager().update(tpf);
    } else if (environment.getObserver() != null) {
        environment.getCamera().setFrame(((Spatial) environment.getObserver()).getWorldTranslation(), ((Spatial) environment.getObserver()).getWorldRotation());
    }
    //FIXME: check if this code is necessary.
    // Updates scene and gui states.
    Iterator<Spatial> spatialIter = application.getViewPort().getScenes().iterator();
    Spatial spatial = null;
    while (spatialIter.hasNext()) {
        spatial = spatialIter.next();
        spatial.updateLogicalState(tpf);
        spatial.updateGeometricState();
    }
    if (environment.isInVR() == false || environment.getVRGUIManager().getPositioningMode() == VRGUIPositioningMode.MANUAL) {
        // only update geometric state here if GUI is in manual mode, or not in VR
        // it will get updated automatically in the viewmanager update otherwise
        spatialIter = application.getGuiViewPort().getScenes().iterator();
        spatial = null;
        while (spatialIter.hasNext()) {
            spatial = spatialIter.next();
            spatial.updateGeometricState();
        }
    }
    // use the analog control on the first tracked controller to push around the mouse
    environment.getVRMouseManager().updateAnalogAsMouse(0, null, null, null, tpf);
}
Also used : Spatial(com.jme3.scene.Spatial)

Example 7 with Mode

use of com.jme3.scene.Mesh.Mode in project jmonkeyengine by jMonkeyEngine.

the class BatchNode method mergeGeometries.

/**
     * Merges all geometries in the collection into
     * the output mesh. Does not take into account materials.
     *
     * @param geometries
     * @param outMesh
     */
private void mergeGeometries(Mesh outMesh, List<Geometry> geometries) {
    int[] compsForBuf = new int[VertexBuffer.Type.values().length];
    VertexBuffer.Format[] formatForBuf = new VertexBuffer.Format[compsForBuf.length];
    boolean[] normForBuf = new boolean[VertexBuffer.Type.values().length];
    int totalVerts = 0;
    int totalTris = 0;
    int totalLodLevels = 0;
    int maxWeights = -1;
    Mesh.Mode mode = null;
    float lineWidth = 1f;
    for (Geometry geom : geometries) {
        totalVerts += geom.getVertexCount();
        totalTris += geom.getTriangleCount();
        totalLodLevels = Math.min(totalLodLevels, geom.getMesh().getNumLodLevels());
        if (maxVertCount < geom.getVertexCount()) {
            maxVertCount = geom.getVertexCount();
        }
        Mesh.Mode listMode;
        //float listLineWidth = 1f;
        int components;
        switch(geom.getMesh().getMode()) {
            case Points:
                listMode = Mesh.Mode.Points;
                components = 1;
                break;
            case LineLoop:
            case LineStrip:
            case Lines:
                listMode = Mesh.Mode.Lines;
                //listLineWidth = geom.getMesh().getLineWidth();
                components = 2;
                break;
            case TriangleFan:
            case TriangleStrip:
            case Triangles:
                listMode = Mesh.Mode.Triangles;
                components = 3;
                break;
            default:
                throw new UnsupportedOperationException();
        }
        for (VertexBuffer vb : geom.getMesh().getBufferList().getArray()) {
            int currentCompsForBuf = compsForBuf[vb.getBufferType().ordinal()];
            if (vb.getBufferType() != VertexBuffer.Type.Index && currentCompsForBuf != 0 && currentCompsForBuf != vb.getNumComponents()) {
                throw new UnsupportedOperationException("The geometry " + geom + " buffer " + vb.getBufferType() + " has different number of components than the rest of the meshes " + "(this: " + vb.getNumComponents() + ", expected: " + currentCompsForBuf + ")");
            }
            compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents();
            formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat();
            normForBuf[vb.getBufferType().ordinal()] = vb.isNormalized();
        }
        maxWeights = Math.max(maxWeights, geom.getMesh().getMaxNumWeights());
        if (mode != null && mode != listMode) {
            throw new UnsupportedOperationException("Cannot combine different" + " primitive types: " + mode + " != " + listMode);
        }
        mode = listMode;
        //Not needed anymore as lineWidth is now in RenderState and will be taken into account when merging according to the material
        //            if (mode == Mesh.Mode.Lines) {
        //                if (lineWidth != 1f && listLineWidth != lineWidth) {
        //                    throw new UnsupportedOperationException("When using Mesh Line mode, cannot combine meshes with different line width "
        //                            + lineWidth + " != " + listLineWidth);
        //                }
        //                lineWidth = listLineWidth;
        //            }
        compsForBuf[VertexBuffer.Type.Index.ordinal()] = components;
    }
    outMesh.setMaxNumWeights(maxWeights);
    outMesh.setMode(mode);
    //outMesh.setLineWidth(lineWidth);
    if (totalVerts >= 65536) {
        // make sure we create an UnsignedInt buffer so we can fit all of the meshes
        formatForBuf[VertexBuffer.Type.Index.ordinal()] = VertexBuffer.Format.UnsignedInt;
    } else {
        formatForBuf[VertexBuffer.Type.Index.ordinal()] = VertexBuffer.Format.UnsignedShort;
    }
    // generate output buffers based on retrieved info
    for (int i = 0; i < compsForBuf.length; i++) {
        if (compsForBuf[i] == 0) {
            continue;
        }
        Buffer data;
        if (i == VertexBuffer.Type.Index.ordinal()) {
            data = VertexBuffer.createBuffer(formatForBuf[i], compsForBuf[i], totalTris);
        } else {
            data = VertexBuffer.createBuffer(formatForBuf[i], compsForBuf[i], totalVerts);
        }
        VertexBuffer vb = new VertexBuffer(VertexBuffer.Type.values()[i]);
        vb.setupData(VertexBuffer.Usage.Dynamic, compsForBuf[i], formatForBuf[i], data);
        vb.setNormalized(normForBuf[i]);
        outMesh.setBuffer(vb);
    }
    int globalVertIndex = 0;
    int globalTriIndex = 0;
    for (Geometry geom : geometries) {
        Mesh inMesh = geom.getMesh();
        if (!isBatch(geom)) {
            geom.associateWithGroupNode(this, globalVertIndex);
        }
        int geomVertCount = inMesh.getVertexCount();
        int geomTriCount = inMesh.getTriangleCount();
        for (int bufType = 0; bufType < compsForBuf.length; bufType++) {
            VertexBuffer inBuf = inMesh.getBuffer(VertexBuffer.Type.values()[bufType]);
            VertexBuffer outBuf = outMesh.getBuffer(VertexBuffer.Type.values()[bufType]);
            if (outBuf == null) {
                continue;
            }
            if (VertexBuffer.Type.Index.ordinal() == bufType) {
                int components = compsForBuf[bufType];
                IndexBuffer inIdx = inMesh.getIndicesAsList();
                IndexBuffer outIdx = outMesh.getIndexBuffer();
                for (int tri = 0; tri < geomTriCount; tri++) {
                    for (int comp = 0; comp < components; comp++) {
                        int idx = inIdx.get(tri * components + comp) + globalVertIndex;
                        outIdx.put((globalTriIndex + tri) * components + comp, idx);
                    }
                }
            } else if (VertexBuffer.Type.Position.ordinal() == bufType) {
                FloatBuffer inPos = (FloatBuffer) inBuf.getData();
                FloatBuffer outPos = (FloatBuffer) outBuf.getData();
                doCopyBuffer(inPos, globalVertIndex, outPos, 3);
            } else if (VertexBuffer.Type.Normal.ordinal() == bufType || VertexBuffer.Type.Tangent.ordinal() == bufType) {
                FloatBuffer inPos = (FloatBuffer) inBuf.getData();
                FloatBuffer outPos = (FloatBuffer) outBuf.getData();
                doCopyBuffer(inPos, globalVertIndex, outPos, compsForBuf[bufType]);
                if (VertexBuffer.Type.Tangent.ordinal() == bufType) {
                    useTangents = true;
                }
            } else {
                if (inBuf == null) {
                    throw new IllegalArgumentException("Geometry " + geom.getName() + " has no " + outBuf.getBufferType() + " buffer whereas other geoms have. all geometries should have the same types of buffers.\n Try to use GeometryBatchFactory.alignBuffer() on the BatchNode before batching");
                } else if (outBuf == null) {
                    throw new IllegalArgumentException("Geometry " + geom.getName() + " has a " + outBuf.getBufferType() + " buffer whereas other geoms don't. all geometries should have the same types of buffers.\n Try to use GeometryBatchFactory.alignBuffer() on the BatchNode before batching");
                } else {
                    inBuf.copyElements(0, outBuf, globalVertIndex, geomVertCount);
                }
            }
        }
        globalVertIndex += geomVertCount;
        globalTriIndex += geomTriCount;
    }
}
Also used : FloatBuffer(java.nio.FloatBuffer) IndexBuffer(com.jme3.scene.mesh.IndexBuffer) Buffer(java.nio.Buffer) FloatBuffer(java.nio.FloatBuffer) IndexBuffer(com.jme3.scene.mesh.IndexBuffer)

Example 8 with Mode

use of com.jme3.scene.Mesh.Mode in project jmonkeyengine by jMonkeyEngine.

the class HDRRenderer method createDisplayQuad.

public Picture createDisplayQuad() /*int mode, Texture tex*/
{
    if (scene64 == null)
        return null;
    Material mat = new Material(manager, "Common/MatDefs/Hdr/LogLum.j3md");
    //        if (mode == LUMMODE_ENCODE_LUM)
    //            mat.setBoolean("EncodeLum", true);
    //        else if (mode == LUMMODE_DECODE_LUM)
    mat.setBoolean("DecodeLum", true);
    mat.setTexture("Texture", scene64);
    //        mat.setTexture("Texture", tex);
    Picture dispQuad = new Picture("Luminance Display");
    dispQuad.setMaterial(mat);
    return dispQuad;
}
Also used : Picture(com.jme3.ui.Picture) Material(com.jme3.material.Material)

Example 9 with Mode

use of com.jme3.scene.Mesh.Mode in project jmonkeyengine by jMonkeyEngine.

the class LandscapeHelper method toFog.

/**
     * The method loads fog for the scene.
     * NOTICE! Remember to manually set the distance and density of the fog.
     * Unfortunately blender's fog parameters in no way fit to the JME.
     * @param worldStructure
     *            the world's structure
     * @return fog filter or null if scene does not define it
     */
public FogFilter toFog(Structure worldStructure) {
    FogFilter result = null;
    int mode = ((Number) worldStructure.getFieldValue("mode")).intValue();
    if ((mode & MODE_MIST) != 0) {
        LOGGER.fine("Loading fog.");
        result = new FogFilter();
        result.setName("FIfog");
        result.setFogColor(this.toBackgroundColor(worldStructure));
    }
    return result;
}
Also used : FogFilter(com.jme3.post.filters.FogFilter)

Example 10 with Mode

use of com.jme3.scene.Mesh.Mode in project jmonkeyengine by jMonkeyEngine.

the class BlenderKey method read.

@Override
public void read(JmeImporter e) throws IOException {
    super.read(e);
    InputCapsule ic = e.getCapsule(this);
    fps = ic.readInt("fps", DEFAULT_FPS);
    featuresToLoad = ic.readInt("features-to-load", FeaturesToLoad.ALL);
    loadUnlinkedAssets = ic.readBoolean("load-unlinked-assets", false);
    assetRootPath = ic.readString("asset-root-path", null);
    fixUpAxis = ic.readBoolean("fix-up-axis", true);
    generatedTexturePPU = ic.readInt("generated-texture-ppu", 128);
    usedWorld = ic.readString("used-world", null);
    defaultMaterial = (Material) ic.readSavable("default-material", null);
    faceCullMode = ic.readEnum("face-cull-mode", FaceCullMode.class, FaceCullMode.Off);
    layersToLoad = ic.readInt("layers-to=load", -1);
    mipmapGenerationMethod = ic.readEnum("mipmap-generation-method", MipmapGenerationMethod.class, MipmapGenerationMethod.GENERATE_WHEN_NEEDED);
    skyGeneratedTextureSize = ic.readInt("sky-generated-texture-size", 1000);
    skyGeneratedTextureRadius = ic.readFloat("sky-generated-texture-radius", 1f);
    skyGeneratedTextureShape = ic.readEnum("sky-generated-texture-shape", SkyGeneratedTextureShape.class, SkyGeneratedTextureShape.SPHERE);
    optimiseTextures = ic.readBoolean("optimise-textures", false);
    animationMatchMethod = ic.readEnum("animation-match-method", AnimationMatchMethod.class, AnimationMatchMethod.AT_LEAST_ONE_NAME_MATCH);
    pointsSize = ic.readFloat("points-size", 1);
    linesWidth = ic.readFloat("lines-width", 1);
}
Also used : InputCapsule(com.jme3.export.InputCapsule) FaceCullMode(com.jme3.material.RenderState.FaceCullMode)

Aggregations

Vector3f (com.jme3.math.Vector3f)6 Texture2D (com.jme3.texture.Texture2D)6 Bone (com.jme3.animation.Bone)5 Quaternion (com.jme3.math.Quaternion)4 AppSettings (com.jme3.system.AppSettings)3 AnimControl (com.jme3.animation.AnimControl)2 InputCapsule (com.jme3.export.InputCapsule)2 OutputCapsule (com.jme3.export.OutputCapsule)2 Material (com.jme3.material.Material)2 Spatial (com.jme3.scene.Spatial)2 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)2 Texture (com.jme3.texture.Texture)2 TempVars (com.jme3.util.TempVars)2 GraphicsDevice (java.awt.GraphicsDevice)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 Buffer (java.nio.Buffer)2 FloatBuffer (java.nio.FloatBuffer)2