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

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

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

Mesh.setBuffer介绍

[英]Creates a VertexBuffer for the mesh or modifies the existing one per the parameters given.
[中]为网格创建顶点缓冲区,或根据给定的参数修改现有的顶点缓冲区。

代码示例

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

public void setBuffer(Type type, int components, ByteBuffer buf) {
  setBuffer(type, components, Format.UnsignedByte, buf);
}

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

public void setBuffer(Type type, int components, ShortBuffer buf) {
  setBuffer(type, components, Format.UnsignedShort, buf);
}

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

/**
 * Set a floating point {@link VertexBuffer} on the mesh.
 *
 * @param type The type of {@link VertexBuffer},
 * e.g. {@link Type#Position}, {@link Type#Normal}, etc.
 *
 * @param components Number of components on the vertex buffer, should
 * be between 1 and 4.
 *
 * @param buf The floating point data to contain
 */
public void setBuffer(Type type, int components, FloatBuffer buf) {
  setBuffer(type, components, Format.Float, buf);
}

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

public void setBuffer(Type type, int components, IntBuffer buf) {
  setBuffer(type, components, Format.UnsignedInt, buf);
}

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

public void setBuffer(Type type, int components, float[] buf){
  setBuffer(type, components, BufferUtils.createFloatBuffer(buf));
}

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

public void setBuffer(Type type, int components, byte[] buf){
  setBuffer(type, components, BufferUtils.createByteBuffer(buf));
}

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

public void setBuffer(Type type, int components, short[] buf){
  setBuffer(type, components, BufferUtils.createShortBuffer(buf));
}

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

public void setBuffer(Type type, int components, int[] buf){
  setBuffer(type, components, BufferUtils.createIntBuffer(buf));
}

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

protected void updateMesh() {
  FloatBuffer pb = (FloatBuffer)mesh.getBuffer(Type.Position).getData();
  pb.rewind();
  float scale = 1 / 1000000f; // scaled to ms as pixels
  for( int i = 0; i < size; i++ ) {
    float t1 = frames[i * 2] * scale;
    float t2 = frames[i * 2 + 1] * scale;
    
    pb.put(i).put(0).put(0);
    pb.put(i).put(t1).put(0);
    pb.put(i).put(t1).put(0);
    pb.put(i).put(t2).put(0);
  }
  mesh.setBuffer(Type.Position, 3, pb);
}

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

private static void writeColorBuffer(List<VertexData> vertices, ColorRGBA[] cols, Mesh mesh) {
  FloatBuffer colors = BufferUtils.createFloatBuffer(vertices.size() * 4);
  colors.rewind();
  for (ColorRGBA color : cols) {
    colors.put(color.r);
    colors.put(color.g);
    colors.put(color.b);
    colors.put(color.a);
  }
  mesh.clearBuffer(Type.Color);
  mesh.setBuffer(Type.Color, 4, colors);
}

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

protected final void createMesh() {
  if( mesh == null ) {
    mesh = new Mesh();
    mesh.setMode(Mesh.Mode.Lines);
  }
  
  mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(size * 4 * 3));
  
  FloatBuffer cb = BufferUtils.createFloatBuffer(size * 4 * 4);
  for( int i = 0; i < size; i++ ) {
    // For each index we add 4 colors, one for each line
    // endpoint for two layers.
    cb.put(0.5f).put(0.5f).put(0).put(1);
    cb.put(1).put(1).put(0).put(1);
    cb.put(0).put(0.5f).put(0.5f).put(1);
    cb.put(0).put(1).put(1).put(1);
  }         
  mesh.setBuffer(Type.Color, 4, cb);
}

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

private void activateBuffer(Mesh mesh, int idx, int start, FloatBuffer b) {
  VertexBuffer.Type t = bufferTypes[start + idx];
  VertexBuffer vb = mesh.getBuffer(t);
  // only set the buffer if it's different
  if (vb == null || vb.getData() != b) {
    mesh.setBuffer(t, 3, b);
  }
}

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

public Mesh createMesh(Vector3f scale, Vector2f tcScale, boolean center){
  FloatBuffer pb = writeVertexArray(null, scale, center);
  FloatBuffer tb = writeTexCoordArray(null, Vector2f.ZERO, tcScale);
  FloatBuffer nb = writeNormalArray(null, scale);
  IntBuffer ib = writeIndexArray(null);
  Mesh m = new Mesh();
  m.setBuffer(Type.Position, 3, pb);
  m.setBuffer(Type.Normal, 3, nb);
  m.setBuffer(Type.TexCoord, 2, tb);
  m.setBuffer(Type.Index, 3, ib);
  m.setStatic();
  m.updateBound();
  return m;
}

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

public static void setSkinBuffers(Mesh mesh, short[] jointsArray, float[] weightsArray, int componentSize) {
  if (componentSize == 1) {
    mesh.setBuffer(VertexBuffer.Type.BoneIndex, 4, BufferUtils.createByteBuffer(toByteArray(jointsArray)));
  } else {
    mesh.setBuffer(VertexBuffer.Type.BoneIndex, 4, BufferUtils.createShortBuffer(jointsArray));
  }
  mesh.setBuffer(VertexBuffer.Type.BoneWeight, 4, BufferUtils.createFloatBuffer(weightsArray));
  mesh.getBuffer(VertexBuffer.Type.BoneIndex).setUsage(VertexBuffer.Usage.CpuOnly);
  mesh.getBuffer(VertexBuffer.Type.BoneWeight).setUsage(VertexBuffer.Usage.CpuOnly);
}

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

public MikkTSpaceImpl(Mesh mesh) {
  this.mesh = mesh;
  //replacing any existing tangent buffer, if you came here you want them new.
  mesh.clearBuffer(VertexBuffer.Type.Tangent);
  FloatBuffer fb = BufferUtils.createFloatBuffer(mesh.getVertexCount() * 4);
  mesh.setBuffer(VertexBuffer.Type.Tangent, 4, fb);
}

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

public static Mesh convert(IndexedMesh mesh) {
  Mesh jmeMesh = new Mesh();
  jmeMesh.setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(mesh.numTriangles * 3));
  jmeMesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(mesh.numVertices * 3));
  IndexBuffer indicess = jmeMesh.getIndexBuffer();
  FloatBuffer vertices = jmeMesh.getFloatBuffer(Type.Position);
  for (int i = 0; i < mesh.numTriangles * 3; i++) {
    indicess.put(i, mesh.triangleIndexBase.getInt(i * 4));
  }
  for (int i = 0; i < mesh.numVertices * 3; i++) {
    vertices.put(i, mesh.vertexBase.getFloat(i * 4));
  }
  jmeMesh.updateCounts();
  jmeMesh.updateBound();
  jmeMesh.getFloatBuffer(Type.Position).clear();
  return jmeMesh;
}

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

public void updateAll() {
  updatedPatch.setLod(newLod);
  updatedPatch.setLodRight(rightLod);
  updatedPatch.setLodTop(topLod);
  updatedPatch.setLodLeft(leftLod);
  updatedPatch.setLodBottom(bottomLod);
  if (newIndexBuffer != null && isReIndexNeeded()) {
    updatedPatch.setPreviousLod(previousLod);
    updatedPatch.getMesh().clearBuffer(Type.Index);
    if (newIndexBuffer instanceof IntBuffer)
      updatedPatch.getMesh().setBuffer(Type.Index, 3, (IntBuffer)newIndexBuffer);
    else if (newIndexBuffer instanceof ShortBuffer)
      updatedPatch.getMesh().setBuffer(Type.Index, 3, (ShortBuffer)newIndexBuffer);
  }
}

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

public static Mesh getDebugMesh(CollisionShape shape) {
  Mesh mesh = null;
  if (shape.getCShape() instanceof ConvexShape) {
    mesh = new Mesh();
    mesh.setBuffer(Type.Position, 3, getVertices((ConvexShape) shape.getCShape()));
    mesh.getFloatBuffer(Type.Position).clear();
  } else if (shape.getCShape() instanceof ConcaveShape) {
    mesh = new Mesh();
    mesh.setBuffer(Type.Position, 3, getVertices((ConcaveShape) shape.getCShape()));
    mesh.getFloatBuffer(Type.Position).clear();
  }
  return mesh;
}

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

/**
 * Create a mesh for visualizing the specified shape.
 *
 * @param shape (not null, unaffected)
 * @return a new mesh (not null)
 */
public static Mesh getDebugMesh(CollisionShape shape) {
  Mesh mesh = new Mesh();
  DebugMeshCallback callback = new DebugMeshCallback();
  long id = shape.getObjectId();
  getVertices(id, callback);
  mesh.setBuffer(Type.Position, 3, callback.getVertices());
  mesh.getFloatBuffer(Type.Position).clear();
  return mesh;
}

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

private void setColor(Geometry g, ColorRGBA color) {
  float[] colors = new float[g.getMesh().getVertexCount() * 4];
  for (int i = 0; i < g.getMesh().getVertexCount() * 4; i += 4) {
    colors[i] = color.r;
    colors[i + 1] = color.g;
    colors[i + 2] = color.b;
    colors[i + 3] = color.a;
  }
  VertexBuffer colorBuff = g.getMesh().getBuffer(VertexBuffer.Type.Color);
  if (colorBuff == null) {
    g.getMesh().setBuffer(VertexBuffer.Type.Color, 4, colors);
  } else {
    FloatBuffer cBuff = (FloatBuffer) colorBuff.getData();
    cBuff.rewind();
    cBuff.put(colors);
    colorBuff.updateData(cBuff);
  }
}

相关文章