Package com.jme3.scene

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


        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

        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

        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

    @Override
    public void write(JmeExporter ex) throws IOException {
        // the mesh is removed, and reloaded when read() is called
        // this reduces the save size to 10% by not saving the mesh
        Mesh temp = getMesh();
        mesh = null;
       
        super.write(ex);
        OutputCapsule oc = ex.getCapsule(this);
        oc.write(size, "size", 16);
View Full Code Here

        //lodCalculator.setTerrainPatch(this);
        //lodCalculatorFactory = (LodCalculatorFactory) ic.readSavable("lodCalculatorFactory", null);
        lodEntropy = ic.readFloatArray("lodEntropy", null);
        geomap = (LODGeomap) ic.readSavable("geomap", null);
       
        Mesh regen = geomap.createMesh(stepScale, new Vector2f(1,1), offset, offsetAmount, totalSize, false);
        setMesh(regen);
        //TangentBinormalGenerator.generate(this); // note that this will be removed
        ensurePositiveVolumeBBox();
    }
View Full Code Here

        //clone.lodCalculator = lodCalculator.clone();
        //clone.lodCalculator.setTerrainPatch(clone);
        //clone.setLodCalculator(lodCalculatorFactory.clone());
        clone.geomap = new LODGeomap(size, geomap.getHeightArray());
        clone.setLocalTranslation(getLocalTranslation().clone());
        Mesh m = clone.geomap.createMesh(clone.stepScale, Vector2f.UNIT_XY, clone.offset, clone.offsetAmount, clone.totalSize, false);
        clone.setMesh(m);
        clone.setMaterial(material.clone());
        return clone;
    }
View Full Code Here

 
 
  public static void mirrorAlong(int axis, Geometry geometry){

        int i = axis-1;
        Mesh oldMesh = geometry.getMesh().deepClone();

        FloatBuffer oldPoints = (FloatBuffer)oldMesh.getBuffer(Type.Position).getData();
        ShortBuffer oldIndexes = (ShortBuffer)oldMesh.getBuffer(Type.Index).getData();
        FloatBuffer oldNormals = (FloatBuffer)oldMesh.getBuffer(Type.Normal).getData();


        //Mirror along given axis, invert normals also
            while(i < oldPoints.capacity()){
          float oldPoint = oldPoints.get(i);
          float oldNormal = oldNormals.get(i);
          oldPoints.put(i, -oldPoint);
          oldNormals.put(i, -oldNormal);
          i+=3;
        }


        //Invert wise order
        i = 0;
        while(i < oldIndexes.capacity()){
          short oldValue = oldIndexes.get(i+2);
          oldIndexes.put(i+2, oldIndexes.get(i+1));
          oldIndexes.put(i+1, oldValue);
          i+=3;
        }


        oldMesh.setBuffer(Type.Position, 3, oldPoints);
        oldMesh.setBuffer(Type.Normal, 3, oldNormals);
        oldMesh.setBuffer(Type.Index, 1, oldIndexes);
        geometry.setMesh(oldMesh);
        geometry.updateModelBound();

      }
View Full Code Here

    if (planes < 2)
      planes = DEFAULT_PLANES;
    if (radialSamples < 3)
      radialSamples = DEFAULT_RADIAL_SAMPLES;

    Mesh m = new Mesh();
    float[] azimuth = new float[radialSamples + 1];
    float[] elevation = new float[planes];
    int numPolygons, numVertices, i_index, v_index;
    int[] indexes;
    Vector2f[] texCoord;
    Vector3f temp_normal;
    Vector3f[] vertices, normals;

    // Determine the angles (in radians) that we need.
    for (int i = 0; i < (azimuth.length - 1); i++) {
      azimuth[i] = FastMath.TWO_PI * ((float)i / radialSamples);
    }
    for (int i = 0; i < (elevation.length - 1); i++) {
      elevation[i] = FastMath.HALF_PI * ((float)i / (planes - 1));
    }

    // Determine the number of polygons, vertices, and indexes we need.
    numPolygons = ((radialSamples * 2) * (planes - 2)) + radialSamples;
    numVertices = ((radialSamples * 4) * (planes - 2)) + (radialSamples * 3);
    indexes = new int[numPolygons * 3];
    texCoord = new Vector2f[numVertices];
    vertices = new Vector3f[numVertices];
    normals = new Vector3f[numVertices];

    // Calculate vertices and determine indexes for all but the top tier.
    i_index = 0;
    v_index = 0;
    for (int i = 0; i < (planes - 2); i++) {
      for (int j = 0; j < radialSamples; j++) {
        vertices[v_index] = World.toCartesian(azimuth[j], elevation[i], radius);
        vertices[v_index + 1] = World.toCartesian(azimuth[j], elevation[i + 1], radius);
        vertices[v_index + 2] = World.toCartesian(azimuth[j + 1], elevation[i + 1], radius);
        vertices[v_index + 3] = World.toCartesian(azimuth[j + 1], elevation[i], radius);

        temp_normal = vertices[v_index].subtract(vertices[v_index + 1]).cross(vertices[v_index + 1].subtract(vertices[v_index + 2])).normalize();
        if (outsideView)
          temp_normal = temp_normal.negate();
        normals[v_index] = normals[v_index + 1] = normals[v_index + 2] = normals[v_index + 3] = temp_normal;

        texCoord[v_index] = new Vector2f(0, 0);
        texCoord[v_index + 1] = new Vector2f(0, 1);
        texCoord[v_index + 2] = new Vector2f(1, 1);
        texCoord[v_index + 3] = new Vector2f(1, 0);

        if (outsideView) {
          indexes[i_index] = v_index;
          indexes[i_index + 1] = v_index + 3;
          indexes[i_index + 2] = v_index + 1;
          indexes[i_index + 3] = v_index + 1;
          indexes[i_index + 4] = v_index + 3;
          indexes[i_index + 5] = v_index + 2;
        }
        else {
          indexes[i_index] = v_index;
          indexes[i_index + 1] = v_index + 1;
          indexes[i_index + 2] = v_index + 2;
          indexes[i_index + 3] = v_index + 2;
          indexes[i_index + 4] = v_index + 3;
          indexes[i_index + 5] = v_index;
        }

        i_index += 6;
        v_index += 4;
      }
    }

    // Calculate vertices and determine indexes for the top tier.
    for (int i = 0; i < radialSamples; i++) {
      vertices[v_index] = World.toCartesian(azimuth[i], elevation[elevation.length - 2], radius);
      vertices[v_index + 1] = new Vector3f(0, radius, 0);
      vertices[v_index + 2] = World.toCartesian(azimuth[i + 1], elevation[elevation.length - 2], radius);

      temp_normal = vertices[v_index].subtract(vertices[v_index + 1]).cross(vertices[v_index + 1].subtract(vertices[v_index + 2])).normalize();
      if (outsideView)
        temp_normal = temp_normal.negate();
      normals[v_index] = normals[v_index + 1] = normals[v_index + 2] = temp_normal;

      texCoord[v_index] = new Vector2f(0, 0);
      texCoord[v_index] = new Vector2f(0.5f, 1);
      texCoord[v_index] = new Vector2f(1, 0);

      if (outsideView) {
        indexes[i_index] = v_index;
        indexes[i_index + 1] = v_index + 2;
        indexes[i_index + 2] = v_index + 1;
      }
      else {
        indexes[i_index] = v_index;
        indexes[i_index + 1] = v_index + 1;
        indexes[i_index + 2] = v_index + 2;
      }

      i_index += 3;
      v_index += 3;
    }

    // Assign the indexes and vertices to the mesh.
    m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
    m.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));
    m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
    m.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes));
    m.updateBound();

    return m;
  }
View Full Code Here

        vertList.clear();
        normList.clear();
        indexList.clear();
        components.clear();

        Mesh m = new Mesh();
        m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
        m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoords));
        m.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));
        m.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes));
        m.updateCounts();
        m.updateBound();

        return new Geometry("Terrain", m);
    }
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.