Esempio n. 1
0
 private void endpart() {
   if (part != null) {
     part.indexOffset = istart;
     part.numVertices = indices.size - istart;
     istart = indices.size;
     part = null;
   }
 }
Esempio n. 2
0
  /** Starts a new MeshPart. The mesh part is not usable until end() is called */
  public MeshPart part(final String id, int primitiveType) {
    if (this.attributes == null) throw new RuntimeException("Call begin() first");
    endpart();

    part = new MeshPart();
    part.id = id;
    this.primitiveType = part.primitiveType = primitiveType;
    parts.add(part);

    setColor(null);

    return part;
  }
Esempio n. 3
0
  protected void convertMesh(ModelMesh modelMesh) {
    int numIndices = 0;
    for (ModelMeshPart part : modelMesh.parts) {
      numIndices += part.indices.length;
    }
    VertexAttributes attributes = new VertexAttributes(modelMesh.attributes);
    int numVertices = modelMesh.vertices.length / (attributes.vertexSize / 4);

    Mesh mesh = new Mesh(true, numVertices, numIndices, attributes);
    meshes.add(mesh);
    disposables.add(mesh);

    BufferUtils.copy(modelMesh.vertices, mesh.getVerticesBuffer(), modelMesh.vertices.length, 0);
    int offset = 0;
    mesh.getIndicesBuffer().clear();
    for (ModelMeshPart part : modelMesh.parts) {
      MeshPart meshPart = new MeshPart();
      meshPart.id = part.id;
      meshPart.primitiveType = part.primitiveType;
      meshPart.offset = offset;
      meshPart.size = part.indices.length;
      meshPart.mesh = mesh;
      mesh.getIndicesBuffer().put(part.indices);
      offset += meshPart.size;
      meshParts.add(meshPart);
    }
    mesh.getIndicesBuffer().position(0);
    for (MeshPart part : meshParts) part.update();
  }
Esempio n. 4
0
  /** End building the mesh and returns the mesh */
  public Mesh end() {
    if (this.attributes == null) throw new RuntimeException("Call begin() first");
    endpart();

    final Mesh mesh = new Mesh(true, vertices.size, indices.size, attributes);
    mesh.setVertices(vertices.items, 0, vertices.size);
    mesh.setIndices(indices.items, 0, indices.size);

    for (MeshPart p : parts) p.mesh = mesh;
    parts.clear();

    attributes = null;
    vertices.clear();
    indices.clear();

    return mesh;
  }
Esempio n. 5
0
  private void convertMesh(ModelMesh modelMesh) {
    int numIndices = 0;
    for (ModelMeshPart part : modelMesh.parts) {
      numIndices += part.indices.length;
    }
    VertexAttributes attributes = new VertexAttributes(modelMesh.attributes);
    int numVertices = modelMesh.vertices.length / (attributes.vertexSize / 4);

    Mesh mesh = new Mesh(true, numVertices, numIndices, attributes);
    meshes.add(mesh);
    disposables.add(mesh);

    BufferUtils.copy(modelMesh.vertices, mesh.getVerticesBuffer(), modelMesh.vertices.length, 0);
    int offset = 0;
    mesh.getIndicesBuffer().clear();
    for (ModelMeshPart part : modelMesh.parts) {
      MeshPart meshPart = new MeshPart();
      meshPart.id = part.id; // FIXME not storing the mesh name, part ids may collide!
      meshPart.primitiveType = part.primitiveType;
      meshPart.indexOffset = offset;
      meshPart.numVertices = part.indices.length;
      meshPart.mesh = mesh;
      mesh.getIndicesBuffer().put(part.indices);
      offset += meshPart.numVertices;
      meshParts.add(meshPart);
    }
    mesh.getIndicesBuffer().position(0);
  }
Esempio n. 6
0
  @Deprecated
  public static Model createFromMesh(
      final Mesh mesh,
      int indexOffset,
      int vertexCount,
      int primitiveType,
      final Material material) {
    Model result = new Model();
    MeshPart meshPart = new MeshPart();
    meshPart.id = "part1";
    meshPart.indexOffset = indexOffset;
    meshPart.numVertices = vertexCount;
    meshPart.primitiveType = primitiveType;
    meshPart.mesh = mesh;

    NodePart partMaterial = new NodePart();
    partMaterial.material = material;
    partMaterial.meshPart = meshPart;
    Node node = new Node();
    node.id = "node1";
    node.parts.add(partMaterial);

    result.meshes.add(mesh);
    result.materials.add(material);
    result.nodes.add(node);
    result.meshParts.add(meshPart);
    result.manageDisposable(mesh);
    return result;
  }
Esempio n. 7
0
 /**
  * Adds the specified mesh part to the current node. The Mesh will be managed by the model and
  * disposed when the model is disposed. The resources the Material might contain are not managed,
  * use {@link #manage(Disposable)} to add those to the model.
  *
  * @return The added MeshPart.
  */
 public MeshPart part(
     final String id,
     final Mesh mesh,
     int primitiveType,
     int offset,
     int size,
     final Material material) {
   final MeshPart meshPart = new MeshPart();
   meshPart.id = id;
   meshPart.primitiveType = primitiveType;
   meshPart.mesh = mesh;
   meshPart.indexOffset = offset;
   meshPart.numVertices = size;
   part(meshPart, material);
   return meshPart;
 }