Examples of Mesh


Examples of com.jme3.scene.Mesh

    public Map<Integer, Mesh> buildMeshes() {
        LOGGER.fine("Building point mesh.");
        Map<Integer, Mesh> result = new HashMap<Integer, Mesh>(1);

        if (vertices.size() > 0) {
            Mesh mesh = new Mesh();
            mesh.setMode(Mode.Points);
            mesh.setPointSize(3);

            // the point mesh does not need index buffer, but some modifiers applied by importer need it
            // the 'alone point' situation should be quite rare so not too many resources are wasted here
            LOGGER.fine("Creating indices buffer.");
            if (vertices.size() <= Short.MAX_VALUE) {
                short[] indices = new short[vertices.size()];
                for (int i = 0; i < vertices.size(); ++i) {
                    indices[i] = (short) i;
                }
                mesh.setBuffer(Type.Index, 1, indices);
            } else {
                int[] indices = new int[vertices.size()];
                for (int i = 0; i < vertices.size(); ++i) {
                    indices[i] = i;
                }
                mesh.setBuffer(Type.Index, 1, indices);
            }

            LOGGER.fine("Creating vertices buffer.");
            VertexBuffer verticesBuffer = new VertexBuffer(Type.Position);
            verticesBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(vertices.toArray(new Vector3f[vertices.size()])));
            mesh.setBuffer(verticesBuffer);
           
            LOGGER.fine("Creating normals buffer (in case of points it is required if skeleton is applied).");
            VertexBuffer normalsBuffer = new VertexBuffer(Type.Normal);
            normalsBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(normals.toArray(new Vector3f[normals.size()])));
            mesh.setBuffer(normalsBuffer);

            result.put(-1, mesh);
        }
        return result;
    }
View Full Code Here

Examples of com.jme3.scene.Mesh

     */
    public Map<Integer, Mesh> buildMeshes() {
        LOGGER.fine("Building line mesh.");
        Map<Integer, Mesh> result = new HashMap<Integer, Mesh>(1);
        if (vertices.size() > 0) {
            Mesh mesh = new Mesh();
            mesh.setMode(Mode.Lines);

            LOGGER.fine("Creating indices buffer.");
            if (vertices.size() <= Short.MAX_VALUE) {
                short[] indices = new short[vertices.size()];
                for (int i = 0; i < vertices.size(); ++i) {
                    indices[i] = (short) i;
                }
                mesh.setBuffer(Type.Index, 1, indices);
            } else {
                int[] indices = new int[vertices.size()];
                for (int i = 0; i < vertices.size(); ++i) {
                    indices[i] = i;
                }
                mesh.setBuffer(Type.Index, 1, indices);
            }

            LOGGER.fine("Creating vertices buffer.");
            VertexBuffer verticesBuffer = new VertexBuffer(Type.Position);
            verticesBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(vertices.toArray(new Vector3f[vertices.size()])));
            mesh.setBuffer(verticesBuffer);

            LOGGER.fine("Creating normals buffer (in case of lines it is required if skeleton is applied).");
            VertexBuffer normalsBuffer = new VertexBuffer(Type.Normal);
            normalsBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(normals.toArray(new Vector3f[normals.size()])));
            mesh.setBuffer(normalsBuffer);
           
            result.put(-1, mesh);
        }
        return result;
    }
View Full Code Here

Examples of com.jme3.scene.Mesh

            int inGeomIndex = entry.getKey().intValue();
            int outOffset = entry.getValue().start;
            int outLength = entry.getValue().length;

            Geometry inGeom = inGeoms[inGeomIndex];
            Mesh in = inGeom.getMesh();
            Mesh out = new Mesh();

            int outElementCount = outLength * 3;
            ShortBuffer ib = BufferUtils.createShortBuffer(outElementCount);
            out.setBuffer(Type.Index, 3, ib);

            // generate output buffers based on input buffers
            IntMap<VertexBuffer> bufs = in.getBuffers();
            for (Entry<VertexBuffer> ent : bufs){
                VertexBuffer vb = ent.getValue();
                if (vb.getBufferType() == Type.Index)
                    continue;

                // NOTE: we are not actually sure
                // how many elements will be in this buffer.
                // It will be compacted later.
                Buffer b = VertexBuffer.createBuffer(vb.getFormat(),
                                                     vb.getNumComponents(),
                                                     outElementCount);

                VertexBuffer outVb = new VertexBuffer(vb.getBufferType());
                outVb.setNormalized(vb.isNormalized());
                outVb.setupData(vb.getUsage(), vb.getNumComponents(), vb.getFormat(), b);
                out.setBuffer(outVb);
            }

            int currentVertex = 0;
            for (int i = outOffset; i < outOffset + outLength; i++){
                OCTTriangle t = tris.get(i);

                // find vertex indices for triangle t
                in.getTriangle(t.getTriangleIndex(), vertIndicies);

                // find indices in new buf
                Integer i0 = indexCache.get(vertIndicies[0]);
                Integer i1 = indexCache.get(vertIndicies[1]);
                Integer i2 = indexCache.get(vertIndicies[2]);

                // check which ones were not created
                // if not created in new IB, create them
                if (i0 == null){
                    vertexCreated[0] = true;
                    newIndices[0] = currentVertex++;
                    indexCache.put(vertIndicies[0], newIndices[0]);
                }else{
                    newIndices[0] = i0.intValue();
                    vertexCreated[0] = false;
                }
                if (i1 == null){
                    vertexCreated[1] = true;
                    newIndices[1] = currentVertex++;
                    indexCache.put(vertIndicies[1], newIndices[1]);
                }else{
                    newIndices[1] = i1.intValue();
                    vertexCreated[1] = false;
                }
                if (i2 == null){
                    vertexCreated[2] = true;
                    newIndices[2] = currentVertex++;
                    indexCache.put(vertIndicies[2], newIndices[2]);
                }else{
                    newIndices[2] = i2.intValue();
                    vertexCreated[2] = false;
                }

                // if any verticies were created for this triangle
                // copy them to the output mesh
                IntMap<VertexBuffer> inbufs = in.getBuffers();
                for (Entry<VertexBuffer> ent : inbufs){
                    VertexBuffer vb = ent.getValue();
                    if (vb.getBufferType() == Type.Index)
                        continue;
                   
                    VertexBuffer outVb = out.getBuffer(vb.getBufferType());
                    // copy verticies that were created for this triangle
                    for (int v = 0; v < 3; v++){
                        if (!vertexCreated[v])
                            continue;

                        // copy triangle's attribute from one
                        // buffer to another
                        vb.copyElement(vertIndicies[v], outVb, newIndices[v]);
                    }
                }

                // write the indices onto the output index buffer
                ib.put((short)newIndices[0])
                  .put((short)newIndices[1])
                  .put((short)newIndices[2]);
            }
            ib.clear();
            indexCache.clear();

            // since some verticies were cached, it means there's
            // extra data in some buffers
            IntMap<VertexBuffer> outbufs = out.getBuffers();
            for (Entry<VertexBuffer> ent : outbufs){
                VertexBuffer vb = ent.getValue();
                if (vb.getBufferType() == Type.Index)
                    continue;

                vb.compact(currentVertex);
            }

            out.updateBound();
            out.updateCounts();
            out.setStatic();
            //out.setInterleaved();
            Geometry outGeom = new Geometry("Geom"+entry.getKey(), out);
            outGeom.setLocalTransform(inGeom.getWorldTransform());
            outGeom.setMaterial(inGeom.getMaterial());
            for (Light light : inGeom.getWorldLightList()){
View Full Code Here

Examples of com.jme3.scene.Mesh

     * @param blenderContext
     *            the blender context
     */
    @SuppressWarnings("unchecked")
    public void flatten(Geometry geometry, Long geometriesOMA, LinkedHashMap<String, List<Vector2f>> userDefinedUVCoordinates, BlenderContext blenderContext) {
        Mesh mesh = geometry.getMesh();
        Texture previousTexture = null;
        UVCoordinatesType masterUVCoordinatesType = null;
        String masterUserUVSetName = null;
        for (TextureData textureData : textureDatas) {
            // decompress compressed textures (all will be merged into one texture anyway)
View Full Code Here

Examples of com.jme3.scene.Mesh

    public void read(JmeImporter im) throws IOException {
        super.read(im);
        InputCapsule capsule = im.getCapsule(this);

        // for backwards compatability
        Mesh mesh = (Mesh) capsule.readSavable("hullMesh", null);
        if (mesh != null) {
            this.points = getPoints(mesh);
        } else {
            this.points = capsule.readFloatArray("points", null);
View Full Code Here

Examples of com.jme3.scene.Mesh

        for (Entry<Integer, List<Integer>> meshEntry : indexMap.entrySet()) {
            int materialIndex = meshEntry.getKey();
            // key is the material index
            // value is a list of vertex indices
            Mesh mesh = new Mesh();

            // creating vertices indices for this mesh
            List<Integer> indexList = meshEntry.getValue();
            if (this.getVerticesAmount(materialIndex) <= Short.MAX_VALUE) {
                short[] indices = new short[indexList.size()];
                for (int i = 0; i < indexList.size(); ++i) {
                    indices[i] = indexList.get(i).shortValue();
                }
                mesh.setBuffer(Type.Index, 1, indices);
            } else {
                int[] indices = new int[indexList.size()];
                for (int i = 0; i < indexList.size(); ++i) {
                    indices[i] = indexList.get(i).intValue();
                }
                mesh.setBuffer(Type.Index, 1, indices);
            }

            LOGGER.fine("Creating vertices buffer.");
            VertexBuffer verticesBuffer = new VertexBuffer(Type.Position);
            verticesBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(this.getVertices(materialIndex)));
            mesh.setBuffer(verticesBuffer);

            LOGGER.fine("Creating normals buffer.");
            VertexBuffer normalsBuffer = new VertexBuffer(Type.Normal);
            normalsBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(this.getNormals(materialIndex)));
            mesh.setBuffer(normalsBuffer);

            if (verticesColors != null) {
                LOGGER.fine("Setting vertices colors.");
                mesh.setBuffer(Type.Color, 4, this.getVertexColorsBuffer(materialIndex));
                mesh.getBuffer(Type.Color).setNormalized(true);
            }

            result.put(materialIndex, mesh);
        }
View Full Code Here

Examples of com.jme3.scene.Mesh

        else
            ib = (ShortBuffer)idxB.getBuffer();
        FloatBuffer bb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3);
        FloatBuffer tanb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3);
        writeTangentArray(nb, tanb, bb, texb, scale);
        Mesh m = new Mesh();
        m.setMode(Mode.TriangleStrip);
        m.setBuffer(Type.Position, 3, pb);
        m.setBuffer(Type.Normal, 3, nb);
        m.setBuffer(Type.Tangent, 3, tanb);
        m.setBuffer(Type.Binormal, 3, bb);
        m.setBuffer(Type.TexCoord, 2, texb);
        if (ib instanceof IntBuffer)
            m.setBuffer(Type.Index, 3, (IntBuffer)ib);
        else if (ib instanceof ShortBuffer)
            m.setBuffer(Type.Index, 3, (ShortBuffer)ib);
        m.setStatic();
        m.updateBound();
        return m;
    }
View Full Code Here

Examples of com.jme3.scene.Mesh

        this.offset = offset;

        setLocalTranslation(origin);

        geomap = new LODGeomap(size, heightMap);
        Mesh m = geomap.createMesh(stepScale, new Vector2f(1,1), offset, offsetAmount, totalSize, false);
        setMesh(m);

    }
View Full Code Here

Examples of com.puzzletimer.graphics.Mesh

    Plane planeD = new Plane(new Vector3(0, -0.166, 0), new Vector3(0, -1, 0));
    Plane planeU = new Plane(new Vector3(0, 0.166, 0), new Vector3(0, 1, 0));
    Plane planeF = new Plane(new Vector3(0, 0, -0.166), new Vector3(0, 0, -1));
    Plane planeB = new Plane(new Vector3(0, 0, 0.166), new Vector3(0, 0, 1));

    Mesh mesh = Mesh.cube(new Color[] { //
      colorScheme.getLeftColor(), // LEFT
        colorScheme.getBackColor(), // BACK
        colorScheme.getDownColor(), // DOWN
        colorScheme.getRightColor(), // RIGHT
        colorScheme.getFrontColor(), // FRONT
        colorScheme.getUpColor(), // UP
      });

    mesh = mesh //
      .cut(planeL, 0) //
      .cut(planeR, 0) //
      .cut(planeD, 0) //
      .cut(planeU, 0) //
      .cut(planeF, 0) //
      .cut(planeB, 0) //
      .shortenFaces(0.03) //
      .softenFaces(0.015) //
      .softenFaces(0.005);

    HashMap<String, Twist> twists = new HashMap<String, Twist>();
    twists.put("L", new Twist(planeL, Math.PI / 2));
    twists.put("L2", new Twist(planeL, Math.PI));
    twists.put("L'", new Twist(planeL, -Math.PI / 2));
    twists.put("R", new Twist(planeR, Math.PI / 2));
    twists.put("R2", new Twist(planeR, Math.PI));
    twists.put("R'", new Twist(planeR, -Math.PI / 2));
    twists.put("D", new Twist(planeD, Math.PI / 2));
    twists.put("D2", new Twist(planeD, Math.PI));
    twists.put("D'", new Twist(planeD, -Math.PI / 2));
    twists.put("U", new Twist(planeU, Math.PI / 2));
    twists.put("U2", new Twist(planeU, Math.PI));
    twists.put("U'", new Twist(planeU, -Math.PI / 2));
    twists.put("F", new Twist(planeF, Math.PI / 2));
    twists.put("F2", new Twist(planeF, Math.PI));
    twists.put("F'", new Twist(planeF, -Math.PI / 2));
    twists.put("B", new Twist(planeB, Math.PI / 2));
    twists.put("B2", new Twist(planeB, Math.PI));
    twists.put("B'", new Twist(planeB, -Math.PI / 2));

    // Apply PLL
    for (String move : algo.getAlgoMoves()) {
      Twist t = twists.get(move);
      if (t != null) {
        mesh = mesh.rotateHalfspace(t.getPlane(), t.getAngle());
      } else {
        System.out.println("WARNING: Cannot apply algo move <" + move + "> -> Skip it...");
      }
    }

    // custom perspective view
    mesh = mesh.transform(Matrix44.rotationY(-Math.PI / 5)).transform(Matrix44.rotationX(Math.PI / 7));

    return mesh;
  }
View Full Code Here

Examples of de.ailis.jollada.model.Mesh

    @Test
    public void testDefaultConstructor()
    {
        final Vertices vertices = new Vertices("ID");
        final Mesh mesh = new Mesh(vertices);
        final Geometry geometry = new Geometry(mesh);
        assertNull(geometry.getId());
        assertNull(geometry.getAsset());
        assertNull(geometry.getName());
        assertSame(mesh, geometry.getGeometric());
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.