本文整理了Java中com.jme3.scene.Mesh.getFloatBuffer()
方法的一些代码示例,展示了Mesh.getFloatBuffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mesh.getFloatBuffer()
方法的具体详情如下:
包路径:com.jme3.scene.Mesh
类名称:Mesh
方法名:getFloatBuffer
[英]Get the VertexBuffer data stored on this mesh in float format.
[中]获取以浮点格式存储在此网格上的VertexBuffer数据。
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public float getHeightmapHeight(float x, float z) {
if (x < 0 || z < 0 || x >= size || z >= size)
return 0;
int idx = (int) (z * size + x);
return getMesh().getFloatBuffer(Type.Position).get(idx*3+1); // 3 floats per entry (x,y,z), the +1 is to get the Y
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
protected float[] getPoints(Mesh mesh) {
FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
vertices.rewind();
int components = mesh.getVertexCount() * 3;
float[] pointsArray = new float[components];
for (int i = 0; i < components; i += 3) {
pointsArray[i] = vertices.get();
pointsArray[i + 1] = vertices.get();
pointsArray[i + 2] = vertices.get();
}
return pointsArray;
}
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public Vector2f getTex(float x, float z, Vector2f store) {
if (x < 0 || z < 0 || x >= size || z >= size) {
store.set(Vector2f.ZERO);
return store;
}
int idx = (int) (z * size + x);
return store.set(getMesh().getFloatBuffer(Type.TexCoord).get(idx*2),
getMesh().getFloatBuffer(Type.TexCoord).get(idx*2+1) );
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* Copy the vertex positions from a JME mesh.
*
* @param mesh the mesh to read (not null)
* @return a new array (not null, length a multiple of 3)
*/
protected float[] getPoints(Mesh mesh) {
FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
vertices.rewind();
int components = mesh.getVertexCount() * 3;
float[] pointsArray = new float[components];
for (int i = 0; i < components; i += 3) {
pointsArray[i] = vertices.get();
pointsArray[i + 1] = vertices.get();
pointsArray[i + 2] = vertices.get();
}
return pointsArray;
}
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
@Override
public void setMeshes(List<Mesh> meshes) {
this.vertices = new ArrayList<List<Vector3f>>(meshes.size());
this.normals = new ArrayList<List<Vector3f>>(meshes.size());
for (Mesh mesh : meshes) {
Vector3f[] vertexTable = BufferUtils.getVector3Array(mesh.getFloatBuffer(Type.Position));
int[] indices = new int[3];
List<Vector3f> vertices = new ArrayList<Vector3f>(mesh.getTriangleCount() * 3);
List<Vector3f> normals = new ArrayList<Vector3f>(mesh.getTriangleCount());
for (int i = 0; i < mesh.getTriangleCount(); ++i) {
mesh.getTriangle(i, indices);
vertices.add(vertexTable[indices[0]]);
vertices.add(vertexTable[indices[1]]);
vertices.add(vertexTable[indices[2]]);
normals.add(FastMath.computeNormal(vertexTable[indices[0]], vertexTable[indices[1]], vertexTable[indices[2]]));
}
this.vertices.add(vertices);
this.normals.add(normals);
}
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
for (Mesh mesh : meshes) {
float[] vertexTable = BufferUtils.getFloatArray(mesh.getFloatBuffer(Type.Position));
float[] normalTable = BufferUtils.getFloatArray(mesh.getFloatBuffer(Type.Normal));
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private static Map<Integer, List<Float>> buildPointMapForMesh(Mesh mesh, Map<Integer, List<Float>> map) {
FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
ByteBuffer boneIndices = (ByteBuffer) mesh.getBuffer(Type.BoneIndex).getData();
FloatBuffer boneWeight = (FloatBuffer) mesh.getBuffer(Type.BoneWeight).getData();
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private static Map<Integer, List<Float>> buildPointMapForMesh(Mesh mesh, Map<Integer, List<Float>> map) {
FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
ByteBuffer boneIndices = (ByteBuffer) mesh.getBuffer(Type.BoneIndex).getData();
FloatBuffer boneWeight = (FloatBuffer) mesh.getBuffer(Type.BoneWeight).getData();
代码示例来源: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
protected void setHeight(List<LocationHeight> locationHeights, boolean overrideHeight) {
final float[] heightArray = geomap.getHeightArray();
final VertexBuffer vertexBuffer = mesh.getBuffer(Type.Position);
final FloatBuffer floatBuffer = mesh.getFloatBuffer(Type.Position);
for (LocationHeight lh : locationHeights) {
if (lh.x < 0 || lh.z < 0 || lh.x >= size || lh.z >= size) {
continue;
}
int idx = lh.z * size + lh.x;
if (overrideHeight) {
heightArray[idx] = lh.h;
} else {
float currentHeight = floatBuffer.get(idx * 3 + 1);
heightArray[idx] = currentHeight + lh.h;
}
}
floatBuffer.clear();
geomap.writeVertexArray(floatBuffer, stepScale, false);
vertexBuffer.setUpdateNeeded();
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private static ArrayList<VertexInfo> linkVertices(Mesh mesh, boolean splitMirrored) {
ArrayList<VertexInfo> vertexMap = new ArrayList<VertexInfo>();
FloatBuffer vertexBuffer = mesh.getFloatBuffer(Type.Position);
FloatBuffer normalBuffer = mesh.getFloatBuffer(Type.Normal);
FloatBuffer texcoordBuffer = mesh.getFloatBuffer(Type.TexCoord);
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private void build() {
BoundingSphere bs = new BoundingSphere();
bs.computeFromPoints(mesh.getFloatBuffer(VertexBuffer.Type.Position));
meshBoundingSphereRadius = bs.getRadius();
List<Vertex> vertexLookup = new ArrayList<Vertex>();
initialize();
gatherVertexData(mesh, vertexLookup);
gatherIndexData(mesh, vertexLookup);
computeCosts();
// assert (assertValidMesh());
}
代码示例来源: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
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
&& mesh.getFloatBuffer(Type.Normal) == null){
logger.log(Level.WARNING, "OBJ mesh {0} doesn't contain normals! "
+ "It might not display correctly", geom.getName());
代码示例来源: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 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
FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
vertices.rewind();
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
FloatBuffer positions = terrainBlock.getFloatBuffer(Type.Position);
内容来源于网络,如有侵权,请联系作者删除!