Example #1
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);
  }
Example #2
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;
  }
Example #3
0
 private void endpart() {
   if (part != null) {
     part.indexOffset = istart;
     part.numVertices = indices.size - istart;
     istart = indices.size;
     part = null;
   }
 }
Example #4
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;
 }