Examples of Mesh


Examples of com.jme3.scene.Mesh

            // applying emitter shape
            EmitterShape emitterShape = emitter.getShape();
            List<Mesh> meshes = new ArrayList<Mesh>();
            for (Spatial spatial : node.getChildren()) {
                if (spatial instanceof Geometry) {
                    Mesh mesh = ((Geometry) spatial).getMesh();
                    if (mesh != null) {
                        meshes.add(mesh);
                        Material material = materialHelper.getParticlesMaterial(((Geometry) spatial).getMaterial(), alphaFunction, blenderContext);
                        emitter.setMaterial(material);// TODO: divide into several pieces
                    }
View Full Code Here

Examples of com.jme3.scene.Mesh

            List<Geometry> geomList = (List<Geometry>) blenderContext.getLoadedFeature(meshOMA, LoadedFeatureDataType.LOADED_FEATURE);
            MeshContext meshContext = blenderContext.getMeshContext(meshOMA);
            int[] bonesGroups = new int[] { 0 };
            for (Geometry geom : geomList) {
                int materialIndex = meshContext.getMaterialIndex(geom);
                Mesh mesh = geom.getMesh();

                try {
                    VertexBuffer[] buffers = this.readVerticesWeightsData(objectStructure, meshStructure, skeleton, materialIndex, bonesGroups, blenderContext);
                    if (buffers != null) {
                        mesh.setMaxNumWeights(bonesGroups[0]);
                        mesh.setBuffer(buffers[0]);
                        mesh.setBuffer(buffers[1]);

                        LOGGER.fine("Generating bind pose and normal buffers.");
                        mesh.generateBindPose(true);

                        // change the usage type of vertex and normal buffers from
                        // Static to Stream
                        mesh.getBuffer(Type.Position).setUsage(Usage.Stream);
                        mesh.getBuffer(Type.Normal).setUsage(Usage.Stream);

                        // creating empty buffers for HW skinning
                        // the buffers will be setup if ever used.
                        VertexBuffer verticesWeightsHW = new VertexBuffer(Type.HWBoneWeight);
                        VertexBuffer verticesWeightsIndicesHW = new VertexBuffer(Type.HWBoneIndex);
                        mesh.setBuffer(verticesWeightsHW);
                        mesh.setBuffer(verticesWeightsIndicesHW);
                    }
                } catch (BlenderFileException e) {
                    LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
                    invalid = true;
                }
View Full Code Here

Examples of com.jme3.scene.Mesh

    @Deprecated
    public static void convertToFixed(Geometry geom, Format posFmt, Format nmFmt, Format tcFmt){
        geom.updateModelBound();
        BoundingBox bbox = (BoundingBox) geom.getModelBound();
        Mesh mesh = geom.getMesh();

        VertexBuffer positions = mesh.getBuffer(Type.Position);
        VertexBuffer normals   = mesh.getBuffer(Type.Normal);
        VertexBuffer texcoords = mesh.getBuffer(Type.TexCoord);
        VertexBuffer indices   = mesh.getBuffer(Type.Index);

        // positions
        FloatBuffer fb = (FloatBuffer) positions.getData();
        if (posFmt != Format.Float){
            Buffer newBuf = VertexBuffer.createBuffer(posFmt, positions.getNumComponents(),
                                                      mesh.getVertexCount());
            Transform t = convertPositions(fb, bbox, newBuf);
            t.combineWithParent(geom.getLocalTransform());
            geom.setLocalTransform(t);

            VertexBuffer newPosVb = new VertexBuffer(Type.Position);
            newPosVb.setupData(positions.getUsage(),
                               positions.getNumComponents(),
                               posFmt,
                               newBuf);
            mesh.clearBuffer(Type.Position);
            mesh.setBuffer(newPosVb);
        }

        // normals, automatically convert to signed byte
        fb = (FloatBuffer) normals.getData();

        ByteBuffer bb = BufferUtils.createByteBuffer(fb.capacity());
        convertNormals(fb, bb);

        normals = new VertexBuffer(Type.Normal);
        normals.setupData(Usage.Static, 3, Format.Byte, bb);
        normals.setNormalized(true);
        mesh.clearBuffer(Type.Normal);
        mesh.setBuffer(normals);

        // texcoords
        fb = (FloatBuffer) texcoords.getData();
        if (tcFmt != Format.Float){
            Buffer newBuf = VertexBuffer.createBuffer(tcFmt,
                                                      texcoords.getNumComponents(),
                                                      mesh.getVertexCount());
            convertTexCoords2D(fb, newBuf);

            VertexBuffer newTcVb = new VertexBuffer(Type.TexCoord);
            newTcVb.setupData(texcoords.getUsage(),
                              texcoords.getNumComponents(),
                              tcFmt,
                              newBuf);
            mesh.clearBuffer(Type.TexCoord);
            mesh.setBuffer(newTcVb);
        }
    }
View Full Code Here

Examples of com.jme3.scene.Mesh

    private final int page;
    private final Texture2D texture;
    private final LinkedList<LetterQuad> pageQuads = new LinkedList<LetterQuad>();

    BitmapTextPage(BitmapFont font, boolean arrayBased, int page) {
        super("BitmapFont", new Mesh());
        setBatchHint(BatchHint.Never);
        if (font == null) {
            throw new IllegalArgumentException("font cannot be null.");
        }

        this.page = page;

        Material mat = font.getPage(page);
        if (mat == null) {
            throw new IllegalStateException("The font's texture was not found!");
        }

        setMaterial(mat);
        this.texture = (Texture2D) mat.getTextureParam("ColorMap").getTextureValue();

        // initialize buffers
        Mesh m = getMesh();
        m.setBuffer(Type.Position, 3, new float[0]);
        m.setBuffer(Type.TexCoord, 2, new float[0]);
        m.setBuffer(Type.Color, 4, new byte[0]);
        m.setBuffer(Type.Index, 3, new short[0]);

        // scale colors from 0 - 255 range into 0 - 1
        m.getBuffer(Type.Color).setNormalized(true);

        arrayBased = true;

        /*
         * TODO: Since this is forced to true, should we just lose the conditional?
View Full Code Here

Examples of com.jme3.scene.Mesh

                    pageQuads.add(quads.getQuad());
                }
            }
        }

        Mesh m = getMesh();
        int vertCount = pageQuads.size() * 4;
        int triCount = pageQuads.size() * 2;

        VertexBuffer pb = m.getBuffer(Type.Position);
        VertexBuffer tb = m.getBuffer(Type.TexCoord);
        VertexBuffer ib = m.getBuffer(Type.Index);
        VertexBuffer cb = m.getBuffer(Type.Color);

        FloatBuffer fpb = (FloatBuffer) pb.getData();
        FloatBuffer ftb = (FloatBuffer) tb.getData();
        ShortBuffer sib = (ShortBuffer) ib.getData();
        ByteBuffer bcb = (ByteBuffer) cb.getData();

        // increase capacity of buffers as needed
        fpb.rewind();
        fpb = BufferUtils.ensureLargeEnough(fpb, vertCount * 3);
        fpb.limit(vertCount * 3);
        pb.updateData(fpb);

        ftb.rewind();
        ftb = BufferUtils.ensureLargeEnough(ftb, vertCount * 2);
        ftb.limit(vertCount * 2);
        tb.updateData(ftb);

        bcb.rewind();
        bcb = BufferUtils.ensureLargeEnough(bcb, vertCount * 4);
        bcb.limit(vertCount * 4);
        cb.updateData(bcb);

        sib.rewind();
        sib = BufferUtils.ensureLargeEnough(sib, triCount * 3);
        sib.limit(triCount * 3);
        ib.updateData(sib);

        m.updateCounts();

        // go for each quad and append it to the buffers
        if (pos != null) {
            for (int i = 0; i < pageQuads.size(); i++) {
                LetterQuad fq = pageQuads.get(i);
View Full Code Here

Examples of com.jme3.scene.Mesh

    public Triangle getTriangle(Triangle store){
        if (store == null)
            store = new Triangle();

        Mesh m = geometry.getMesh();
        m.getTriangle(triangleIndex, store);
        store.calculateCenter();
        store.calculateNormal();
        return store;
    }
View Full Code Here

Examples of com.jme3.scene.Mesh

        FloatBuffer[] vertexBuffers = new FloatBuffer[bevelObject.size()];
        FloatBuffer[] normalBuffers = new FloatBuffer[bevelObject.size()];
        IndexBuffer[] indexBuffers = new IndexBuffer[bevelObject.size()];
        for (int geomIndex = 0; geomIndex < bevelObject.size(); ++geomIndex) {
            Mesh mesh = bevelObject.get(geomIndex).getMesh();
            Vector3f[] positions = BufferUtils.getVector3Array(mesh.getFloatBuffer(Type.Position));
            Vector3f[] bevelPoints = this.transformToFirstLineOfBevelPoints(positions, curvePoints[0], curvePoints[1]);

            List<Vector3f[]> bevels = new ArrayList<Vector3f[]>(curvePoints.length);
            bevels.add(bevelPoints);

            vertexBuffers[geomIndex] = BufferUtils.createFloatBuffer(bevelPoints.length * 3 * curvePoints.length * (smooth ? 1 : 6));
            for (int i = 1; i < curvePoints.length - 1; ++i) {
                bevelPoints = this.transformBevel(bevelPoints, curvePoints[i - 1], curvePoints[i], curvePoints[i + 1]);
                bevels.add(bevelPoints);
            }
            bevelPoints = this.transformBevel(bevelPoints, curvePoints[curvePoints.length - 2], curvePoints[curvePoints.length - 1], null);
            bevels.add(bevelPoints);

            if (bevels.size() > 2) {
                // changing the first and last bevel so that they are parallel to their neighbours (blender works this way)
                // notice this implicates that the distances of every corresponding point in th two bevels must be identical and
                // equal to the distance between the points on curve that define the bevel position
                // so instead doing complicated rotations on each point we will simply properly translate each of them

                int[][] pointIndexes = new int[][] { { 0, 1 }, { curvePoints.length - 1, curvePoints.length - 2 } };
                for (int[] indexes : pointIndexes) {
                    float distance = curvePoints[indexes[1]].subtract(curvePoints[indexes[0]], subtractResult).length();
                    Vector3f[] bevel = bevels.get(indexes[0]);
                    Vector3f[] nextBevel = bevels.get(indexes[1]);
                    for (int i = 0; i < bevel.length; ++i) {
                        float d = bevel[i].subtract(nextBevel[i], subtractResult).length();
                        subtractResult.normalizeLocal().multLocal(distance - d);
                        bevel[i].addLocal(subtractResult);
                    }
                }
            }

            // apply scales to the bevels
            float lengthAlongCurve = 0;
            for (int i = 0; i < curvePoints.length; ++i) {
                if (i > 0) {
                    lengthAlongCurve += curvePoints[i].subtract(curvePoints[i - 1], subtractResult).length();
                }
                float taperScale = this.getTaperScale(taperObject, i == 0 ? 0 : lengthAlongCurve / curveLength);
                this.applyScale(bevels.get(i), curvePoints[i], taperScale);
            }

            if (smooth) {// add everything to the buffer
                for (Vector3f[] bevel : bevels) {
                    for (Vector3f d : bevel) {
                        vertexBuffers[geomIndex].put(d.x);
                        vertexBuffers[geomIndex].put(d.y);
                        vertexBuffers[geomIndex].put(d.z);
                    }
                }
            } else {// add vertices to the buffer duplicating them so that every vertex belongs only to a single triangle
                for (int i = 0; i < curvePoints.length - 1; ++i) {
                    for (int j = 0; j < bevelPoints.length - 1; ++j) {
                        // first triangle
                        vertexBuffers[geomIndex].put(bevels.get(i)[j].x);
                        vertexBuffers[geomIndex].put(bevels.get(i)[j].y);
                        vertexBuffers[geomIndex].put(bevels.get(i)[j].z);
                        vertexBuffers[geomIndex].put(bevels.get(i)[j + 1].x);
                        vertexBuffers[geomIndex].put(bevels.get(i)[j + 1].y);
                        vertexBuffers[geomIndex].put(bevels.get(i)[j + 1].z);
                        vertexBuffers[geomIndex].put(bevels.get(i + 1)[j].x);
                        vertexBuffers[geomIndex].put(bevels.get(i + 1)[j].y);
                        vertexBuffers[geomIndex].put(bevels.get(i + 1)[j].z);

                        // second triangle
                        vertexBuffers[geomIndex].put(bevels.get(i)[j + 1].x);
                        vertexBuffers[geomIndex].put(bevels.get(i)[j + 1].y);
                        vertexBuffers[geomIndex].put(bevels.get(i)[j + 1].z);
                        vertexBuffers[geomIndex].put(bevels.get(i + 1)[j + 1].x);
                        vertexBuffers[geomIndex].put(bevels.get(i + 1)[j + 1].y);
                        vertexBuffers[geomIndex].put(bevels.get(i + 1)[j + 1].z);
                        vertexBuffers[geomIndex].put(bevels.get(i + 1)[j].x);
                        vertexBuffers[geomIndex].put(bevels.get(i + 1)[j].y);
                        vertexBuffers[geomIndex].put(bevels.get(i + 1)[j].z);
                    }
                }
            }

            indexBuffers[geomIndex] = this.generateIndexes(bevelPoints.length, curvePoints.length, smooth);
            normalBuffers[geomIndex] = this.generateNormals(indexBuffers[geomIndex], vertexBuffers[geomIndex], smooth);
        }

        // creating and returning the result
        List<Geometry> result = new ArrayList<Geometry>(vertexBuffers.length);
        Float oneReferenceToCurveLength = new Float(curveLength);// its important for array modifier to use one reference here
        for (int i = 0; i < vertexBuffers.length; ++i) {
            Mesh mesh = new Mesh();
            mesh.setBuffer(Type.Position, 3, vertexBuffers[i]);
            if (indexBuffers[i].getBuffer() instanceof IntBuffer) {
                mesh.setBuffer(Type.Index, 3, (IntBuffer) indexBuffers[i].getBuffer());
            } else {
                mesh.setBuffer(Type.Index, 3, (ShortBuffer) indexBuffers[i].getBuffer());
            }
            mesh.setBuffer(Type.Normal, 3, normalBuffers[i]);
            Geometry g = new Geometry("g" + i, mesh);
            g.setUserData("curveLength", oneReferenceToCurveLength);
            g.updateModelBound();
            result.add(g);
        }
View Full Code Here

Examples of com.jme3.scene.Mesh

     * @param offset Target buffer offset.
     * @param outMesh The mesh to set the coords in (can be same as input).
     * @return true if texture has been found and coords have been changed, false otherwise.
     */
    public boolean applyCoords(Geometry geom, int offset, Mesh outMesh) {
        Mesh inMesh = geom.getMesh();
        geom.computeWorldMatrix();

        VertexBuffer inBuf = inMesh.getBuffer(Type.TexCoord);
        VertexBuffer outBuf = outMesh.getBuffer(Type.TexCoord);

        if (inBuf == null || outBuf == null) {
            throw new IllegalStateException("Geometry mesh has no texture coordinate buffer.");
        }
View Full Code Here

Examples of com.jme3.scene.Mesh

        TextureAtlas atlas = createAtlas(spat, atlasSize);
        if (atlas == null) {
            return null;
        }
        Geometry geom = new Geometry();
        Mesh mesh = new Mesh();
        GeometryBatchFactory.mergeGeometries(geometries, mesh);
        applyAtlasCoords(geometries, mesh, atlas);
        mesh.updateCounts();
        mesh.updateBound();
        geom.setMesh(mesh);

        Material mat = new Material(mgr, "Common/MatDefs/Light/Lighting.j3md");
        mat.getAdditionalRenderState().setAlphaTest(true);
        Texture diffuseMap = atlas.getAtlasTexture("DiffuseMap");
View Full Code Here

Examples of com.jme3.scene.Mesh

    private static void applyAtlasCoords(List<Geometry> geometries, Mesh outMesh, TextureAtlas atlas) {
        int globalVertIndex = 0;

        for (Geometry geom : geometries) {
            Mesh inMesh = geom.getMesh();
            geom.computeWorldMatrix();

            int geomVertCount = inMesh.getVertexCount();

            VertexBuffer inBuf = inMesh.getBuffer(Type.TexCoord);
            VertexBuffer outBuf = outMesh.getBuffer(Type.TexCoord);

            if (inBuf == null || outBuf == null) {
                continue;
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.