本文整理汇总了Java中com.jme3.scene.mesh.IndexBuffer.get方法的典型用法代码示例。如果您正苦于以下问题:Java IndexBuffer.get方法的具体用法?Java IndexBuffer.get怎么用?Java IndexBuffer.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.scene.mesh.IndexBuffer
的用法示例。
在下文中一共展示了IndexBuffer.get方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initTriList
import com.jme3.scene.mesh.IndexBuffer; //导入方法依赖的package包/类
private void initTriList(FloatBuffer vb, IndexBuffer ib) {
pointData = new float[numTris * 3 * 3];
int p = 0;
for (int i = 0; i < numTris * 3; i += 3) {
int vert = ib.get(i) * 3;
pointData[p++] = vb.get(vert++);
pointData[p++] = vb.get(vert++);
pointData[p++] = vb.get(vert);
vert = ib.get(i + 1) * 3;
pointData[p++] = vb.get(vert++);
pointData[p++] = vb.get(vert++);
pointData[p++] = vb.get(vert);
vert = ib.get(i + 2) * 3;
pointData[p++] = vb.get(vert++);
pointData[p++] = vb.get(vert++);
pointData[p++] = vb.get(vert);
}
triIndices = new int[numTris];
for (int i = 0; i < numTris; i++) {
triIndices[i] = i;
}
}
示例2: getTriangle
import com.jme3.scene.mesh.IndexBuffer; //导入方法依赖的package包/类
/**
* 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");
}
}
示例3: generateNormals
import com.jme3.scene.mesh.IndexBuffer; //导入方法依赖的package包/类
/**
* The method generates normal buffer for the created mesh of the curve.
*
* @param indexes
* the indexes of the mesh points
* @param points
* the mesh's points
* @param smooth
* the flag indicating if the result is to be smooth or solid
* @return normals buffer for the mesh
*/
private FloatBuffer generateNormals(IndexBuffer indexes, FloatBuffer points, boolean smooth) {
Map<Integer, Vector3f> normalMap = new TreeMap<Integer, Vector3f>();
Vector3f[] allVerts = BufferUtils.getVector3Array(points);
for (int i = 0; i < indexes.size(); i += 3) {
int index1 = indexes.get(i);
int index2 = indexes.get(i + 1);
int index3 = indexes.get(i + 2);
Vector3f n = FastMath.computeNormal(allVerts[index1], allVerts[index2], allVerts[index3]);
this.addNormal(n, normalMap, smooth, index1, index2, index3);
}
FloatBuffer normals = BufferUtils.createFloatBuffer(normalMap.size() * 3);
for (Entry<Integer, Vector3f> entry : normalMap.entrySet()) {
normals.put(entry.getValue().x);
normals.put(entry.getValue().y);
normals.put(entry.getValue().z);
}
return normals;
}
示例4: optimize
import com.jme3.scene.mesh.IndexBuffer; //导入方法依赖的package包/类
public Mesh optimize(Mesh mesh) {
nmgen = new NavmeshGenerator(cellSize, cellHeight, minTraversableHeight,
maxTraversableStep, maxTraversableSlope,
clipLedges, traversableAreaBorderSize,
smoothingThreshold, useConservativeExpansion,
minUnconnectedRegionSize, mergeRegionSize,
maxEdgeLength, edgeMaxDeviation, maxVertsPerPoly,
contourSampleDistance, contourMaxDeviation);
FloatBuffer pb = mesh.getFloatBuffer(Type.Position);
IndexBuffer ib = mesh.getIndexBuffer();
// copy positions to float array
float[] positions = new float[pb.capacity()];
pb.clear();
pb.get(positions);
// generate int array of indices
int[] indices = new int[ib.size()];
for (int i = 0; i < indices.length; i++) {
indices[i] = ib.get(i);
}
TriangleMesh triMesh = buildNavMesh(positions, indices, intermediateData);
if (triMesh == null) {
return null;
}
int[] indices2 = triMesh.indices;
float[] positions2 = triMesh.vertices;
Mesh mesh2 = new Mesh();
mesh2.setBuffer(Type.Position, 3, positions2);
mesh2.setBuffer(Type.Index, 3, indices2);
mesh2.updateBound();
mesh2.updateCounts();
return mesh2;
}
示例5: processTriangles
import com.jme3.scene.mesh.IndexBuffer; //导入方法依赖的package包/类
private static List<VertexData> processTriangles(Mesh mesh, int[] index, Vector3f[] v, Vector2f[] t, boolean splitMirrored) {
IndexBuffer indexBuffer = mesh.getIndexBuffer();
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
if (mesh.getBuffer(Type.TexCoord) == null) {
throw new IllegalArgumentException("Can only generate tangents for " + "meshes with texture coordinates");
}
FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();
List<VertexData> vertices = initVertexData(vertexBuffer.limit() / 3);
for (int i = 0; i < indexBuffer.size() / 3; i++) {
for (int j = 0; j < 3; j++) {
index[j] = indexBuffer.get(i * 3 + j);
populateFromBuffer(v[j], vertexBuffer, index[j]);
populateFromBuffer(t[j], textureBuffer, index[j]);
}
TriangleData triData = processTriangle(index, v, t);
if (splitMirrored) {
triData.setIndex(index);
triData.triangleOffset = i * 3;
}
if (triData != null) {
vertices.get(index[0]).triangles.add(triData);
vertices.get(index[1]).triangles.add(triData);
vertices.get(index[2]).triangles.add(triData);
}
}
return vertices;
}
示例6: loadFromMesh
import com.jme3.scene.mesh.IndexBuffer; //导入方法依赖的package包/类
public void loadFromMesh(Mesh mesh) {
clear();
Vector3f a = new Vector3f();
Vector3f b = new Vector3f();
Vector3f c = new Vector3f();
Plane up = new Plane();
up.setPlanePoints(Vector3f.UNIT_X, Vector3f.ZERO, Vector3f.UNIT_Z);
up.getNormal();
IndexBuffer ib = mesh.getIndexBuffer();
FloatBuffer pb = mesh.getFloatBuffer(Type.Position);
pb.clear();
for (int i = 0; i < mesh.getTriangleCount() * 3; i += 3) {
int i1 = ib.get(i + 0);
int i2 = ib.get(i + 1);
int i3 = ib.get(i + 2);
BufferUtils.populateFromBuffer(a, pb, i1);
BufferUtils.populateFromBuffer(b, pb, i2);
BufferUtils.populateFromBuffer(c, pb, i3);
Plane p = new Plane();
p.setPlanePoints(a, b, c);
if (up.pseudoDistance(p.getNormal()) <= 0.0f) {
System.out.println("Warning, normal of the plane faces downward!!!");
continue;
}
addFace(a, b, c);
}
linkCells();
}
示例7: processTriangles
import com.jme3.scene.mesh.IndexBuffer; //导入方法依赖的package包/类
private static VertexData[] processTriangles(Mesh mesh,
int[] index, Vector3f[] v, Vector2f[] t)
{
IndexBuffer indexBuffer = mesh.getIndexBuffer();
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
if (mesh.getBuffer(Type.TexCoord) == null)
throw new IllegalArgumentException("Can only generate tangents for "
+ "meshes with texture coordinates");
FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();
VertexData[] vertices = initVertexData(vertexBuffer.capacity() / 3);
for (int i = 0; i < indexBuffer.size() / 3; i++) {
for (int j = 0; j < 3; j++) {
index[j] = indexBuffer.get(i*3 + j);
populateFromBuffer(v[j], vertexBuffer, index[j]);
populateFromBuffer(t[j], textureBuffer, index[j]);
}
TriangleData triData = processTriangle(index, v, t);
if (triData != null) {
vertices[index[0]].triangles.add(triData);
vertices[index[1]].triangles.add(triData);
vertices[index[2]].triangles.add(triData);
}
}
return vertices;
}
示例8: getColor
import com.jme3.scene.mesh.IndexBuffer; //导入方法依赖的package包/类
public static ColorRGBA getColor( Geometry geom, Vector3f pt, int index, Tweed tweed ) {
MatParam param = geom.getMaterial().getParam( "DiffuseMap" );
ImageRaster ir = ImageRaster.create( tweed.getAssetManager().loadTexture( ((Texture2D)param.getValue()).getName() ).getImage() );
Mesh mesh = geom.getMesh();
// geom.getMaterial().getMaterialDef().
VertexBuffer pb = mesh.getBuffer(Type.Position);
VertexBuffer tb = mesh.getBuffer( Type.TexCoord );
IndexBuffer ib = mesh.getIndicesAsList();
Vector2f uva = new Vector2f(), uvb = new Vector2f(), uvc = new Vector2f();
Vector3f la = new Vector3f(), lb = new Vector3f(), lc = new Vector3f();
if (pb != null && pb.getFormat() == Format.Float && pb.getNumComponents() == 3) {
FloatBuffer fpb = (FloatBuffer) pb.getData();
FloatBuffer ftb = (FloatBuffer) tb.getData();
// aquire triangle's vertex indices
int vertIndex = index * 3;
int va = ib.get(vertIndex);
int vb = ib.get(vertIndex+1);
int vc = ib.get(vertIndex+2);
BufferUtils.populateFromBuffer( la, fpb, va );
BufferUtils.populateFromBuffer( lb, fpb, vb );
BufferUtils.populateFromBuffer( lc, fpb, vc );
BufferUtils.populateFromBuffer( uva, ftb, va );
BufferUtils.populateFromBuffer( uvb, ftb, vb );
BufferUtils.populateFromBuffer( uvc, ftb, vc );
// PaintThing.debug.put(1, new Line ( la.x, la.z, lb.x, lb.z) );
// PaintThing.debug.put(2, new Line ( lb.x, lb.z, lc.x, lc.z) );
// PaintThing.debug.put(3, new Line ( lc.x, lc.z, la.x, la.z) );
float[] bary = barycentric( pt, la, lb, lc );
int x = (int)( ( uva.x * bary[0] + uvb.x * bary[1] + uvc.x * bary[2] ) * ir.getWidth ()) ,
y = (int)( ( uva.y * bary[0] + uvb.y * bary[1] + uvc.y * bary[2] ) * ir.getHeight()) ;
ColorRGBA out = ir.getPixel( x, y );//ir.getHeight() - y -1 );
// for (Pair<Vector3f, Vector2f> pair : new Pair[]{ new Pair( la, uva), new Pair (lb, uvb), new Pair (lc, uvc)}) {
//
// int xx = (int)(pair.second().x * ir.getWidth () ),
// yy = (int)(pair.second().y * ir.getHeight() );
//
// System.out.println("xx "+xx+" yy "+ yy );
//
// ColorRGBA o = ir.getPixel(
// xx,
// yy );
//
// PaintThing.debug.put(1, new ColPt( pair.first().x, pair.first().z, o.r, o.g, o.b ));
// }
// System.out.println("<< "+ ((Texture2D)param.getValue()).getName());
// System.out.println( x + " " + y + " :: " + bary[ 0 ] + " " + bary[ 1 ] + " " + bary[ 2 ] +
// " --> " + out.r + "," + out.g + "," + out.b );
return out;
}else{
throw new UnsupportedOperationException("Position buffer not set or has incompatible format");
}
}
示例9: processTriangleStrip
import com.jme3.scene.mesh.IndexBuffer; //导入方法依赖的package包/类
private static List<VertexData> processTriangleStrip(Mesh mesh, int[] index, Vector3f[] v, Vector2f[] t) {
IndexBuffer indexBuffer = mesh.getIndexBuffer();
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();
List<VertexData> vertices = initVertexData(vertexBuffer.limit() / 3);
index[0] = indexBuffer.get(0);
index[1] = indexBuffer.get(1);
populateFromBuffer(v[0], vertexBuffer, index[0]);
populateFromBuffer(v[1], vertexBuffer, index[1]);
populateFromBuffer(t[0], textureBuffer, index[0]);
populateFromBuffer(t[1], textureBuffer, index[1]);
for (int i = 2; i < indexBuffer.size(); i++) {
index[2] = indexBuffer.get(i);
BufferUtils.populateFromBuffer(v[2], vertexBuffer, index[2]);
BufferUtils.populateFromBuffer(t[2], textureBuffer, index[2]);
boolean isDegenerate = isDegenerateTriangle(v[0], v[1], v[2]);
TriangleData triData = processTriangle(index, v, t);
if (triData != null && !isDegenerate) {
vertices.get(index[0]).triangles.add(triData);
vertices.get(index[1]).triangles.add(triData);
vertices.get(index[2]).triangles.add(triData);
}
Vector3f vTemp = v[0];
v[0] = v[1];
v[1] = v[2];
v[2] = vTemp;
Vector2f tTemp = t[0];
t[0] = t[1];
t[1] = t[2];
t[2] = tTemp;
index[0] = index[1];
index[1] = index[2];
}
return vertices;
}
示例10: processTriangleFan
import com.jme3.scene.mesh.IndexBuffer; //导入方法依赖的package包/类
private static List<VertexData> processTriangleFan(Mesh mesh, int[] index, Vector3f[] v, Vector2f[] t) {
IndexBuffer indexBuffer = mesh.getIndexBuffer();
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();
List<VertexData> vertices = initVertexData(vertexBuffer.limit() / 3);
index[0] = indexBuffer.get(0);
index[1] = indexBuffer.get(1);
populateFromBuffer(v[0], vertexBuffer, index[0]);
populateFromBuffer(v[1], vertexBuffer, index[1]);
populateFromBuffer(t[0], textureBuffer, index[0]);
populateFromBuffer(t[1], textureBuffer, index[1]);
for (int i = 2; i < vertexBuffer.limit() / 3; i++) {
index[2] = indexBuffer.get(i);
populateFromBuffer(v[2], vertexBuffer, index[2]);
populateFromBuffer(t[2], textureBuffer, index[2]);
TriangleData triData = processTriangle(index, v, t);
if (triData != null) {
vertices.get(index[0]).triangles.add(triData);
vertices.get(index[1]).triangles.add(triData);
vertices.get(index[2]).triangles.add(triData);
}
Vector3f vTemp = v[1];
v[1] = v[2];
v[2] = vTemp;
Vector2f tTemp = t[1];
t[1] = t[2];
t[2] = tTemp;
index[1] = index[2];
}
return vertices;
}
示例11: processTriangleStrip
import com.jme3.scene.mesh.IndexBuffer; //导入方法依赖的package包/类
private static VertexData[] processTriangleStrip(Mesh mesh,
int[] index, Vector3f[] v, Vector2f[] t)
{
IndexBuffer indexBuffer = mesh.getIndexBuffer();
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();
VertexData[] vertices = initVertexData(vertexBuffer.capacity() / 3);
index[0] = indexBuffer.get(0);
index[1] = indexBuffer.get(1);
populateFromBuffer(v[0], vertexBuffer, index[0]);
populateFromBuffer(v[1], vertexBuffer, index[1]);
populateFromBuffer(t[0], textureBuffer, index[0]);
populateFromBuffer(t[1], textureBuffer, index[1]);
for (int i = 2; i < indexBuffer.size(); i++) {
index[2] = indexBuffer.get(i);
BufferUtils.populateFromBuffer(v[2], vertexBuffer, index[2]);
BufferUtils.populateFromBuffer(t[2], textureBuffer, index[2]);
boolean isDegenerate = isDegenerateTriangle(v[0], v[1], v[2]);
TriangleData triData = processTriangle(index, v, t);
if (triData != null && !isDegenerate) {
vertices[index[0]].triangles.add(triData);
vertices[index[1]].triangles.add(triData);
vertices[index[2]].triangles.add(triData);
}
Vector3f vTemp = v[0];
v[0] = v[1];
v[1] = v[2];
v[2] = vTemp;
Vector2f tTemp = t[0];
t[0] = t[1];
t[1] = t[2];
t[2] = tTemp;
index[0] = index[1];
index[1] = index[2];
}
return vertices;
}
示例12: processTriangleFan
import com.jme3.scene.mesh.IndexBuffer; //导入方法依赖的package包/类
private static VertexData[] processTriangleFan(Mesh mesh,
int[] index, Vector3f[] v, Vector2f[] t)
{
IndexBuffer indexBuffer = mesh.getIndexBuffer();
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();
VertexData[] vertices = initVertexData(vertexBuffer.capacity() / 3);
index[0] = indexBuffer.get(0);
index[1] = indexBuffer.get(1);
populateFromBuffer(v[0], vertexBuffer, index[0]);
populateFromBuffer(v[1], vertexBuffer, index[1]);
populateFromBuffer(t[0], textureBuffer, index[0]);
populateFromBuffer(t[1], textureBuffer, index[1]);
for (int i = 2; i < vertexBuffer.capacity() / 3; i++) {
index[2] = indexBuffer.get(i);
populateFromBuffer(v[2], vertexBuffer, index[2]);
populateFromBuffer(t[2], textureBuffer, index[2]);
TriangleData triData = processTriangle(index, v, t);
if (triData != null) {
vertices[index[0]].triangles.add(triData);
vertices[index[1]].triangles.add(triData);
vertices[index[2]].triangles.add(triData);
}
Vector3f vTemp = v[1];
v[1] = v[2];
v[2] = vTemp;
Vector2f tTemp = t[1];
t[1] = t[2];
t[2] = tTemp;
index[1] = index[2];
}
return vertices;
}