com.jme3.scene.Mesh.getIndicesAsList()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(14.8k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中com.jme3.scene.Mesh.getIndicesAsList()方法的一些代码示例,展示了Mesh.getIndicesAsList()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mesh.getIndicesAsList()方法的具体详情如下:
包路径:com.jme3.scene.Mesh
类名称:Mesh
方法名:getIndicesAsList

Mesh.getIndicesAsList介绍

[英]Acquires an index buffer that will read the vertices on the mesh as a list.
[中]获取索引缓冲区,该缓冲区将网格上的顶点作为列表读取。

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Gets the triangle vertex indices at the given triangle index
 * and stores them into the given int array.
 *
 * @param index The index of the triangle.
 * Should be between 0 and {@link #getTriangleCount()}.
 *
 * @param indices Indices of the triangle's vertices
 */
public void getTriangle(int index, int[] indices){
  IndexBuffer ib = getIndicesAsList();
  // acquire triangle's vertex indices
  int vertIndex = index * 3;
  indices[0] = ib.get(vertIndex);
  indices[1] = ib.get(vertIndex+1);
  indices[2] = ib.get(vertIndex+2);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public static synchronized IndexedMesh convert(Mesh mesh) {
  IndexedMesh jBulletIndexedMesh = new IndexedMesh();
  jBulletIndexedMesh.triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4);
  jBulletIndexedMesh.vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4);
  IndexBuffer indices = mesh.getIndicesAsList();
  
  FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
  vertices.rewind();
  int verticesLength = mesh.getVertexCount() * 3;
  jBulletIndexedMesh.numVertices = mesh.getVertexCount();
  jBulletIndexedMesh.vertexStride = 12; //3 verts * 4 bytes per.
  for (int i = 0; i < verticesLength; i++) {
    float tempFloat = vertices.get();
    jBulletIndexedMesh.vertexBase.putFloat(tempFloat);
  }
  int indicesLength = mesh.getTriangleCount() * 3;
  jBulletIndexedMesh.numTriangles = mesh.getTriangleCount();
  jBulletIndexedMesh.triangleIndexStride = 12; //3 index entries * 4 bytes each.
  for (int i = 0; i < indicesLength; i++) {
    jBulletIndexedMesh.triangleIndexBase.putInt(indices.get(i));
  }
  vertices.rewind();
  vertices.clear();
  return jBulletIndexedMesh;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private void createCollisionMesh(Mesh mesh) {
  this.triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4);
  this.vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4);
  this.numVertices = mesh.getVertexCount();
  this.vertexStride = 12; // 3 verts * 4 bytes per.
  this.numTriangles = mesh.getTriangleCount();
  this.triangleIndexStride = 12; // 3 index entries * 4 bytes each.
  IndexBuffer indices = mesh.getIndicesAsList();
  FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
  vertices.rewind();
  int verticesLength = mesh.getVertexCount() * 3;
  for (int i = 0; i < verticesLength; i++) {
    float tempFloat = vertices.get();
    vertexBase.putFloat(tempFloat);
  }
  int indicesLength = mesh.getTriangleCount() * 3;
  for (int i = 0; i < indicesLength; i++) {
    triangleIndexBase.putInt(indices.get(i));
  }
  vertices.rewind();
  vertices.clear();
  this.createShape(null);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private void createCollisionMesh(Mesh mesh) {
    triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4);
    vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4); 
//        triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4);
//        vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4);
    numVertices = mesh.getVertexCount();
    vertexStride = 12; //3 verts * 4 bytes per.
    numTriangles = mesh.getTriangleCount();
    triangleIndexStride = 12; //3 index entries * 4 bytes each.

    IndexBuffer indices = mesh.getIndicesAsList();
    FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
    vertices.rewind();

    int verticesLength = mesh.getVertexCount() * 3;
    for (int i = 0; i < verticesLength; i++) {
      float tempFloat = vertices.get();
      vertexBase.putFloat(tempFloat);
    }

    int indicesLength = mesh.getTriangleCount() * 3;
    for (int i = 0; i < indicesLength; i++) {
      triangleIndexBase.putInt(indices.get(i));
    }
    vertices.rewind();
    vertices.clear();

    createShape();
  }

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

int triangleIndexStride = 12; //3 index entries * 4 bytes each
IndexBuffer indices = mesh.getIndicesAsList();
FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
vertices.rewind();

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Gets the triangle vertex positions at the given triangle index
 * and stores them into the v1, v2, v3 arguments.
 *
 * @param index The index of the triangle.
 * Should be between 0 and {@link #getTriangleCount()}.
 *
 * @param v1 Vector to contain first vertex position
 * @param v2 Vector to contain second vertex position
 * @param v3 Vector to contain third vertex position
 */
public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3){
  VertexBuffer pb = getBuffer(Type.Position);
  IndexBuffer ib = getIndicesAsList();
  if (pb != null && pb.getFormat() == Format.Float && pb.getNumComponents() == 3){
    FloatBuffer fpb = (FloatBuffer) pb.getData();
    // aquire triangle's vertex indices
    int vertIndex = index * 3;
    int vert1 = ib.get(vertIndex);
    int vert2 = ib.get(vertIndex+1);
    int vert3 = ib.get(vertIndex+2);
    BufferUtils.populateFromBuffer(v1, fpb, vert1);
    BufferUtils.populateFromBuffer(v2, fpb, vert2);
    BufferUtils.populateFromBuffer(v3, fpb, vert3);
  }else{
    throw new UnsupportedOperationException("Position buffer not set or "
                       + " has incompatible format");
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public static void convertToList(Mesh mesh){
  IndexBuffer inBuf = mesh.getIndicesAsList();
  IndexBuffer outBuf = IndexBuffer.createIndexBuffer(mesh.getVertexCount(),
                            inBuf.size());
  for (int i = 0; i < inBuf.size(); i++){
    outBuf.put(i, inBuf.get(i));
  }
  mesh.clearBuffer(Type.Index);
  switch (mesh.getMode()){
    case LineLoop:
    case LineStrip:
      mesh.setMode(Mode.Lines);
      break;
    case TriangleStrip:
    case TriangleFan:
      mesh.setMode(Mode.Triangles);
      break;
    default:
      break;
  }
  if (outBuf instanceof IndexIntBuffer){
    mesh.setBuffer(Type.Index, 3, (IntBuffer)outBuf.getBuffer());
  }else{
    mesh.setBuffer(Type.Index, 3, (ShortBuffer)outBuf.getBuffer());
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

int components = compsForBuf[bufType];
IndexBuffer inIdx = inMesh.getIndicesAsList();
IndexBuffer outIdx = outMesh.getIndexBuffer();

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

int components = compsForBuf[bufType];
IndexBuffer inIdx = inMesh.getIndicesAsList();
IndexBuffer outIdx = outMesh.getIndexBuffer();

代码示例来源:origin: org.jmonkeyengine/jme3-core

/**
 * Gets the triangle vertex indices at the given triangle index
 * and stores them into the given int array.
 *
 * @param index The index of the triangle.
 * Should be between 0 and {@link #getTriangleCount()}.
 *
 * @param indices Indices of the triangle's vertices
 */
public void getTriangle(int index, int[] indices){
  IndexBuffer ib = getIndicesAsList();
  // acquire triangle's vertex indices
  int vertIndex = index * 3;
  indices[0] = ib.get(vertIndex);
  indices[1] = ib.get(vertIndex+1);
  indices[2] = ib.get(vertIndex+2);
}

代码示例来源:origin: info.projectkyoto/mms-engine

/**
 * Gets the triangle vertex indices at the given triangle index 
 * and stores them into the given int array.
 * 
 * @param index The index of the triangle. 
 * Should be between 0 and {@link #getTriangleCount()}.
 * 
 * @param indices Indices of the triangle's vertices
 */
public void getTriangle(int index, int[] indices){
  IndexBuffer ib = getIndicesAsList();
  // acquire triangle's vertex indices
  int vertIndex = index * 3;
  indices[0] = ib.get(vertIndex);
  indices[1] = ib.get(vertIndex+1);
  indices[2] = ib.get(vertIndex+2);
}

代码示例来源:origin: org.jmonkeyengine/jme3-jbullet

public static synchronized IndexedMesh convert(Mesh mesh) {
  IndexedMesh jBulletIndexedMesh = new IndexedMesh();
  jBulletIndexedMesh.triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4);
  jBulletIndexedMesh.vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4);
  IndexBuffer indices = mesh.getIndicesAsList();
  
  FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
  vertices.rewind();
  int verticesLength = mesh.getVertexCount() * 3;
  jBulletIndexedMesh.numVertices = mesh.getVertexCount();
  jBulletIndexedMesh.vertexStride = 12; //3 verts * 4 bytes per.
  for (int i = 0; i < verticesLength; i++) {
    float tempFloat = vertices.get();
    jBulletIndexedMesh.vertexBase.putFloat(tempFloat);
  }
  int indicesLength = mesh.getTriangleCount() * 3;
  jBulletIndexedMesh.numTriangles = mesh.getTriangleCount();
  jBulletIndexedMesh.triangleIndexStride = 12; //3 index entries * 4 bytes each.
  for (int i = 0; i < indicesLength; i++) {
    jBulletIndexedMesh.triangleIndexBase.putInt(indices.get(i));
  }
  vertices.rewind();
  vertices.clear();
  return jBulletIndexedMesh;
}

代码示例来源:origin: info.projectkyoto/mms-engine

public static long getTriangleIndexVertexArray(Mesh mesh){
  ByteBuffer triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4);
  ByteBuffer vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4);
  int numVertices = mesh.getVertexCount();
  int vertexStride = 12; //3 verts * 4 bytes per.
  int numTriangles = mesh.getTriangleCount();
  int triangleIndexStride = 12; //3 index entries * 4 bytes each.
  IndexBuffer indices = mesh.getIndicesAsList();
  FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
  vertices.rewind();
  int verticesLength = mesh.getVertexCount() * 3;
  for (int i = 0; i < verticesLength; i++) {
    float tempFloat = vertices.get();
    vertexBase.putFloat(tempFloat);
  }
  int indicesLength = mesh.getTriangleCount() * 3;
  for (int i = 0; i < indicesLength; i++) {
    triangleIndexBase.putInt(indices.get(i));
  }
  vertices.rewind();
  vertices.clear();
  return createTriangleIndexVertexArray(triangleIndexBase, vertexBase, numTriangles, numVertices, vertexStride, triangleIndexStride);
}

代码示例来源:origin: org.jmonkeyengine/jme3-bullet

private void createCollisionMesh(Mesh mesh) {
  this.triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4);
  this.vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4);
  this.numVertices = mesh.getVertexCount();
  this.vertexStride = 12; // 3 verts * 4 bytes per.
  this.numTriangles = mesh.getTriangleCount();
  this.triangleIndexStride = 12; // 3 index entries * 4 bytes each.
  IndexBuffer indices = mesh.getIndicesAsList();
  FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
  vertices.rewind();
  int verticesLength = mesh.getVertexCount() * 3;
  for (int i = 0; i < verticesLength; i++) {
    float tempFloat = vertices.get();
    vertexBase.putFloat(tempFloat);
  }
  int indicesLength = mesh.getTriangleCount() * 3;
  for (int i = 0; i < indicesLength; i++) {
    triangleIndexBase.putInt(indices.get(i));
  }
  vertices.rewind();
  vertices.clear();
  this.createShape(null);
}

代码示例来源:origin: org.jmonkeyengine/jme3-bullet

public static long getTriangleIndexVertexArray(Mesh mesh){
  ByteBuffer triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4);
  ByteBuffer vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4);
  int numVertices = mesh.getVertexCount();
  int vertexStride = 12; //3 verts * 4 bytes per.
  int numTriangles = mesh.getTriangleCount();
  int triangleIndexStride = 12; //3 index entries * 4 bytes each.
  IndexBuffer indices = mesh.getIndicesAsList();
  FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
  vertices.rewind();
  int verticesLength = mesh.getVertexCount() * 3;
  for (int i = 0; i < verticesLength; i++) {
    float tempFloat = vertices.get();
    vertexBase.putFloat(tempFloat);
  }
  int indicesLength = mesh.getTriangleCount() * 3;
  for (int i = 0; i < indicesLength; i++) {
    triangleIndexBase.putInt(indices.get(i));
  }
  vertices.rewind();
  vertices.clear();
  return createTriangleIndexVertexArray(triangleIndexBase, vertexBase, numTriangles, numVertices, vertexStride, triangleIndexStride);
}

代码示例来源:origin: org.jmonkeyengine/jme3-bullet

private void createCollisionMesh(Mesh mesh) {
    triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4);
    vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4); 
//        triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4);
//        vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4);
    numVertices = mesh.getVertexCount();
    vertexStride = 12; //3 verts * 4 bytes per.
    numTriangles = mesh.getTriangleCount();
    triangleIndexStride = 12; //3 index entries * 4 bytes each.

    IndexBuffer indices = mesh.getIndicesAsList();
    FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
    vertices.rewind();

    int verticesLength = mesh.getVertexCount() * 3;
    for (int i = 0; i < verticesLength; i++) {
      float tempFloat = vertices.get();
      vertexBase.putFloat(tempFloat);
    }

    int indicesLength = mesh.getTriangleCount() * 3;
    for (int i = 0; i < indicesLength; i++) {
      triangleIndexBase.putInt(indices.get(i));
    }
    vertices.rewind();
    vertices.clear();

    createShape();
  }

代码示例来源:origin: org.jmonkeyengine/jme3-core

/**
 * Gets the triangle vertex positions at the given triangle index
 * and stores them into the v1, v2, v3 arguments.
 *
 * @param index The index of the triangle.
 * Should be between 0 and {@link #getTriangleCount()}.
 *
 * @param v1 Vector to contain first vertex position
 * @param v2 Vector to contain second vertex position
 * @param v3 Vector to contain third vertex position
 */
public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3){
  VertexBuffer pb = getBuffer(Type.Position);
  IndexBuffer ib = getIndicesAsList();
  if (pb != null && pb.getFormat() == Format.Float && pb.getNumComponents() == 3){
    FloatBuffer fpb = (FloatBuffer) pb.getData();
    // aquire triangle's vertex indices
    int vertIndex = index * 3;
    int vert1 = ib.get(vertIndex);
    int vert2 = ib.get(vertIndex+1);
    int vert3 = ib.get(vertIndex+2);
    BufferUtils.populateFromBuffer(v1, fpb, vert1);
    BufferUtils.populateFromBuffer(v2, fpb, vert2);
    BufferUtils.populateFromBuffer(v3, fpb, vert3);
  }else{
    throw new UnsupportedOperationException("Position buffer not set or "
                       + " has incompatible format");
  }
}

代码示例来源:origin: info.projectkyoto/mms-engine

/**
 * Gets the triangle vertex positions at the given triangle index 
 * and stores them into the v1, v2, v3 arguments.
 * 
 * @param index The index of the triangle. 
 * Should be between 0 and {@link #getTriangleCount()}.
 * 
 * @param v1 Vector to contain first vertex position
 * @param v2 Vector to contain second vertex position
 * @param v3 Vector to contain third vertex position
 */
public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3){
  VertexBuffer pb = getBuffer(Type.Position);
  IndexBuffer ib = getIndicesAsList();
  if (pb != null && pb.getFormat() == Format.Float && pb.getNumComponents() == 3){
    FloatBuffer fpb = (FloatBuffer) pb.getData();
    // aquire triangle's vertex indices
    int vertIndex = index * 3;
    int vert1 = ib.get(vertIndex);
    int vert2 = ib.get(vertIndex+1);
    int vert3 = ib.get(vertIndex+2);
    BufferUtils.populateFromBuffer(v1, fpb, vert1);
    BufferUtils.populateFromBuffer(v2, fpb, vert2);
    BufferUtils.populateFromBuffer(v3, fpb, vert3);
  }else{
    throw new UnsupportedOperationException("Position buffer not set or "
                       + " has incompatible format");
  }
}

代码示例来源:origin: info.projectkyoto/mms-engine

public static void convertToList(Mesh mesh){
  IndexBuffer inBuf = mesh.getIndicesAsList();
  IndexBuffer outBuf = IndexBuffer.createIndexBuffer(mesh.getVertexCount(),
                            inBuf.size());
  for (int i = 0; i < inBuf.size(); i++){
    outBuf.put(i, inBuf.get(i));
  }
  mesh.clearBuffer(Type.Index);
  switch (mesh.getMode()){
    case LineLoop:
    case LineStrip:
      mesh.setMode(Mode.Lines);
      break;
    case TriangleStrip:
    case TriangleFan:
      mesh.setMode(Mode.Triangles);
      break;
    default:
      break;
  }
  if (outBuf instanceof IndexIntBuffer){
    mesh.setBuffer(Type.Index, 3, (IntBuffer)outBuf.getBuffer());
  }else{
    mesh.setBuffer(Type.Index, 3, (ShortBuffer)outBuf.getBuffer());
  }
}

代码示例来源:origin: org.jmonkeyengine/jme3-core

public static void convertToList(Mesh mesh){
  IndexBuffer inBuf = mesh.getIndicesAsList();
  IndexBuffer outBuf = IndexBuffer.createIndexBuffer(mesh.getVertexCount(),
                            inBuf.size());
  for (int i = 0; i < inBuf.size(); i++){
    outBuf.put(i, inBuf.get(i));
  }
  mesh.clearBuffer(Type.Index);
  switch (mesh.getMode()){
    case LineLoop:
    case LineStrip:
      mesh.setMode(Mode.Lines);
      break;
    case TriangleStrip:
    case TriangleFan:
      mesh.setMode(Mode.Triangles);
      break;
    default:
      break;
  }
  if (outBuf instanceof IndexIntBuffer){
    mesh.setBuffer(Type.Index, 3, (IntBuffer)outBuf.getBuffer());
  }else{
    mesh.setBuffer(Type.Index, 3, (ShortBuffer)outBuf.getBuffer());
  }
}

相关文章