Package com.jme3.scene

Examples of com.jme3.scene.Mesh


        geom.updateModelBound();
        return geom;
    }

    public static Mesh getDebugMesh(CollisionShape shape) {
        Mesh mesh = new Mesh();
        mesh = new Mesh();
        DebugMeshCallback callback = new DebugMeshCallback();
        getVertices(shape.getObjectId(), callback);
        mesh.setBuffer(Type.Position, 3, callback.getVertices());
        mesh.getFloatBuffer(Type.Position).clear();
        return mesh;
    }
View Full Code Here


    public Mesh createMesh(Vector3f scale, Vector2f tcScale, boolean center){
        FloatBuffer pb = writeVertexArray(null, scale, center);
        FloatBuffer tb = writeTexCoordArray(null, Vector2f.ZERO, tcScale);
        FloatBuffer nb = writeNormalArray(null, scale);
        IntBuffer ib = writeIndexArray(null);
        Mesh m = new Mesh();
        m.setBuffer(Type.Position, 3, pb);
        m.setBuffer(Type.Normal, 3, nb);
        m.setBuffer(Type.TexCoord, 2, tb);
        m.setBuffer(Type.Index, 3, ib);
        m.setStatic();
        m.updateBound();
        return m;
    }
View Full Code Here

            throw new IllegalArgumentException("LodControl can only be attached to Geometry!");
        }

        super.setSpatial(spatial);
        Geometry geom = (Geometry) spatial;
        Mesh mesh = geom.getMesh();
        numLevels = mesh.getNumLodLevels();
        numTris = new int[numLevels];
        for (int i = numLevels - 1; i >= 0; i--) {
            numTris[i] = mesh.getTriangleCount(i);
        }
    }
View Full Code Here

                        ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
                        Node curveObject = (Node) objectHelper.toObject(curveStructure, blenderContext);
                        Set<Number> referencesToCurveLengths = new HashSet<Number>(curveObject.getChildren().size());
                        for (Spatial spatial : curveObject.getChildren()) {
                            if (spatial instanceof Geometry) {
                                Mesh mesh = ((Geometry) spatial).getMesh();
                                if (mesh instanceof Curve) {
                                    length += ((Curve) mesh).getLength();
                                } else {
                                    // if bevel object has several parts then each mesh will have the same reference
                                    // to length value (and we should use only one)
View Full Code Here

        bbox.setYExtent(extent);
        bbox.setZExtent(extent);

        Triangle t = new Triangle();
        for (int g = 0; g < geoms.length; g++){
            Mesh m = geoms[g].getMesh();
            for (int i = 0; i < m.getTriangleCount(); i++){
                m.getTriangle(i, t);
                OCTTriangle ot = new OCTTriangle(t.get1(), t.get2(), t.get3(), i, g);
                allTris.add(ot);
                // convert triangle to world space
//                geom.getWorldTransform().transformVector(t.get1(), t.get1());
//                geom.getWorldTransform().transformVector(t.get2(), t.get2());
View Full Code Here

                        mirrorPlaneNormal.set(0, 0, 0).set(mirrorIndex, Math.signum(mirrorPlaneCenter.get(mirrorIndex)));
                    }

                    for (Spatial spatial : node.getChildren()) {
                        if (spatial instanceof Geometry) {
                            Mesh mesh = ((Geometry) spatial).getMesh();
                            Mesh clone = mesh.deepClone();

                            LOGGER.log(Level.FINEST, "Fetching buffers of cloned spatial: {0}", spatial.getName());
                            FloatBuffer position = mesh.getFloatBuffer(Type.Position);
                            FloatBuffer bindPosePosition = mesh.getFloatBuffer(Type.BindPosePosition);

                            FloatBuffer clonePosition = clone.getFloatBuffer(Type.Position);
                            FloatBuffer cloneBindPosePosition = clone.getFloatBuffer(Type.BindPosePosition);
                            FloatBuffer cloneNormals = clone.getFloatBuffer(Type.Normal);
                            FloatBuffer cloneBindPoseNormals = clone.getFloatBuffer(Type.BindPoseNormal);
                            Buffer cloneIndexes = clone.getBuffer(Type.Index).getData();

                            for (int i = 0; i < cloneIndexes.limit(); ++i) {
                                int index = cloneIndexes instanceof ShortBuffer ? ((ShortBuffer) cloneIndexes).get(i) : ((IntBuffer) cloneIndexes).get(i);
                                if (!modifiedIndexes.contains(index)) {
                                    modifiedIndexes.add(index);

                                    this.get(clonePosition, index, point);
                                    if (mirrorAtPoint0) {
                                        d = Math.abs(point.get(mirrorIndex));
                                        shiftVector.set(0, 0, 0).set(mirrorIndex, -point.get(mirrorIndex));
                                    } else {
                                        d = this.computeDistanceFromPlane(point, mirrorPlaneCenter, mirrorPlaneNormal);
                                        mirrorPlaneNormal.mult(d, shiftVector);
                                    }

                                    if (merge && d <= tolerance) {
                                        point.addLocal(shiftVector);

                                        this.set(index, point, clonePosition, cloneBindPosePosition, position, bindPosePosition);
                                        if (cloneNormals != null) {
                                            this.get(cloneNormals, index, normal);
                                            normal.set(mirrorIndex, 0);
                                            this.set(index, normal, cloneNormals, cloneBindPoseNormals);
                                        }
                                    } else {
                                        point.addLocal(shiftVector.multLocal(2));

                                        this.set(index, point, clonePosition, cloneBindPosePosition);
                                        if (cloneNormals != null) {
                                            this.get(cloneNormals, index, normal);
                                            normal.set(mirrorIndex, -normal.get(mirrorIndex));
                                            this.set(index, normal, cloneNormals, cloneBindPoseNormals);
                                        }
                                    }
                                }
                            }
                            modifiedIndexes.clear();

                            LOGGER.finer("Flipping index order.");
                            switch (mesh.getMode()) {
                                case Points:
                                    cloneIndexes.flip();
                                    break;
                                case Lines:
                                    for (int i = 0; i < cloneIndexes.limit(); i += 2) {
                                        if (cloneIndexes instanceof ShortBuffer) {
                                            short index = ((ShortBuffer) cloneIndexes).get(i + 1);
                                            ((ShortBuffer) cloneIndexes).put(i + 1, ((ShortBuffer) cloneIndexes).get(i));
                                            ((ShortBuffer) cloneIndexes).put(i, index);
                                        } else {
                                            int index = ((IntBuffer) cloneIndexes).get(i + 1);
                                            ((IntBuffer) cloneIndexes).put(i + 1, ((IntBuffer) cloneIndexes).get(i));
                                            ((IntBuffer) cloneIndexes).put(i, index);
                                        }
                                    }
                                    break;
                                case Triangles:
                                    for (int i = 0; i < cloneIndexes.limit(); i += 3) {
                                        if (cloneIndexes instanceof ShortBuffer) {
                                            short index = ((ShortBuffer) cloneIndexes).get(i + 2);
                                            ((ShortBuffer) cloneIndexes).put(i + 2, ((ShortBuffer) cloneIndexes).get(i + 1));
                                            ((ShortBuffer) cloneIndexes).put(i + 1, index);
                                        } else {
                                            int index = ((IntBuffer) cloneIndexes).get(i + 2);
                                            ((IntBuffer) cloneIndexes).put(i + 2, ((IntBuffer) cloneIndexes).get(i + 1));
                                            ((IntBuffer) cloneIndexes).put(i + 1, index);
                                        }
                                    }
                                    break;
                                default:
                                    throw new IllegalStateException("Invalid mesh mode: " + mesh.getMode());
                            }

                            if (mirrorU && clone.getBuffer(Type.TexCoord) != null) {
                                LOGGER.finer("Mirroring U coordinates.");
                                FloatBuffer cloneUVs = (FloatBuffer) clone.getBuffer(Type.TexCoord).getData();
                                for (int i = 0; i < cloneUVs.limit(); i += 2) {
                                    cloneUVs.put(i, 1.0f - cloneUVs.get(i));
                                }
                            }
                            if (mirrorV && clone.getBuffer(Type.TexCoord) != null) {
                                LOGGER.finer("Mirroring V coordinates.");
                                FloatBuffer cloneUVs = (FloatBuffer) clone.getBuffer(Type.TexCoord).getData();
                                for (int i = 1; i < cloneUVs.limit(); i += 2) {
                                    cloneUVs.put(i, 1.0f - cloneUVs.get(i));
                                }
                            }
View Full Code Here

            // 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

            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

    @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

    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

TOP

Related Classes of com.jme3.scene.Mesh

Copyright © 2018 www.massapicom. 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.