本文整理汇总了Java中com.jme3.scene.Mesh.setBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java Mesh.setBuffer方法的具体用法?Java Mesh.setBuffer怎么用?Java Mesh.setBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.scene.Mesh
的用法示例。
在下文中一共展示了Mesh.setBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processMesh
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
protected void processMesh(Mesh mesh) {
int[] indexes = new int[faces.size()];
for (int index = 0; index < faces.size(); index++) {
indexes[index] = faces.get(index).intValue();
}
mesh.setBuffer(Type.Position, 3,
BufferUtils.createFloatBuffer(vertices.toArray(new Vector3f[vertices.size()])));
mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indexes));
mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals.toArray(new Vector3f[normals.size()])));
mesh.setBuffer(Type.TexCoord, 2,
BufferUtils.createFloatBuffer(textureCoordinates.toArray(new Vector2f[textureCoordinates.size()])));
mesh.setBuffer(Type.TexCoord2, 4,
BufferUtils.createFloatBuffer(
textureTileCoordinates.toArray(new Vector4f[textureTileCoordinates.size()])));
}
示例2: convert
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
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;
}
示例3: main
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public static void main(String[] args) {
Mesh mesh = new Mesh();
mesh.setBuffer(Type.Position, 3, new float[]{
0, 0, 0,
1, 0, 0,
1, 1, 0,
0, 1, 0
});
mesh.setBuffer(Type.Index, 2, new short[]{
0, 1,
1, 2,
2, 3,
3, 0
});
Geometry g1 = new Geometry("g1", mesh);
ArrayList<Geometry> geoms = new ArrayList<Geometry>();
geoms.add(g1);
Mesh outMesh = new Mesh();
mergeGeometries(geoms, outMesh);
printMesh(outMesh);
}
示例4: BNode
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public BNode(int size) {
mesh = new Mesh();
quads = new BGeometry[size];
slotBusy = new boolean[size];
indexes = new int[6 * size];
posData = BufferUtils.createFloatBuffer(new Vector3f[4 * size]);
msPosData = BufferUtils.createFloatBuffer(new float[4 * size]);
alphaData = BufferUtils.createFloatBuffer(new float[4 * size]);
texData = BufferUtils.createFloatBuffer(new Vector2f[4 * size]);
idxData = BufferUtils.createIntBuffer(indexes);
mesh.setBuffer(Position, 3, posData);
mesh.setBuffer(TexCoord, 2, texData);
mesh.setBuffer(TexCoord2, 1, msPosData);
mesh.setBuffer(TexCoord3, 1, alphaData);
mesh.setBuffer(Index, 3, idxData);
posBuffer = mesh.getBuffer(Position);
texBuffer = mesh.getBuffer(TexCoord);
msPosBuffer = mesh.getBuffer(TexCoord2);
alphaBuffer = mesh.getBuffer(TexCoord3);
idxBuffer = mesh.getBuffer(Index);
}
示例5: calculate
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
@Override
public void calculate() {
for (Spatial s : gNode.getChildren())
s.removeFromParent();
Mesh mesh = new Mesh();
mesh.setMode( Mode.Points );
Vector3f[] verts = new Vector3f[cubes.size()];
for (int i = 0; i < cubes.size(); i++) {
verts[ i ] = new com.jme3.math.Vector3f( (float)cubes.get( i ).x, (float)cubes.get( i ).y, (float)cubes.get( i ).z );
}
mesh.setBuffer( VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer( verts ) );
Material mat1 = new Material( tweed.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md" );
mat1.setBoolean( "VertexColor", true );
Geometry depth = new Geometry( "depth", mesh );
depth.setMaterial( mat1 );
depth.updateModelBound();
depth.updateGeometricState();
gNode.attachChild(depth);
super.calculate();
}
示例6: generateMesh
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public void generateMesh(){
try{
System.out.println("Starting chunk generation: " + chunk.getChunkCoordinates());
long startAt = System.currentTimeMillis();
int cx, cy, cz;
for(cy=0;cy<Chunk.CHUNK_HEIGHT;++cy){
for(cx=0;cx<Chunk.CHUNK_SIZE;++cx){
for(cz=0;cz<Chunk.CHUNK_SIZE;++cz){
generateBlock(cx, cy, cz);
}
}
}
Vector3f[] verticesArray = vertices.toArray(new Vector3f[vertices.size()]);
Vector2f[] texCoordsArray = texCoords.toArray(new Vector2f[texCoords.size()]);
int[] indicesArray = new int[indices.size()];
for(int x=0;x<indicesArray.length;++x){
indicesArray[x] = indices.get(x);
}
mesh = new Mesh();
mesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(verticesArray));
mesh.setBuffer(VertexBuffer.Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoordsArray));
mesh.setBuffer(VertexBuffer.Type.Index, 3, BufferUtils.createIntBuffer(indicesArray));
mesh.updateBound();
System.out.println("Finished chunk generation: " + chunk.getChunkCoordinates() + " in " + (System.currentTimeMillis() - startAt) + "ms");
}catch(Throwable t){
t.printStackTrace();
}
}
示例7: processMesh
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
@Override
protected void processMesh(Mesh mesh) {
super.processMesh(mesh);
mesh.setBuffer(Type.TexCoord3, 2,
BufferUtils.createFloatBuffer(quadSizes.toArray(new Vector2f[quadSizes.size()])));
}
示例8: optimize
import com.jme3.scene.Mesh; //导入方法依赖的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;
}
示例9: createTriangleStripMesh
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
private Mesh createTriangleStripMesh() {
Mesh strip = new Mesh();
strip.setMode(Mode.TriangleStrip);
FloatBuffer vb = BufferUtils.createFloatBuffer(3*3*3); // 3 rows * 3 columns * 3 floats
vb.rewind();
vb.put(new float[]{0,2,0}); vb.put(new float[]{1,2,0}); vb.put(new float[]{2,2,0});
vb.put(new float[]{0,1,0}); vb.put(new float[]{1,1,0}); vb.put(new float[]{2,1,0});
vb.put(new float[]{0,0,0}); vb.put(new float[]{1,0,0}); vb.put(new float[]{2,0,0});
FloatBuffer nb = BufferUtils.createFloatBuffer(3*3*3);
nb.rewind();
nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1});
nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1});
nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1});
FloatBuffer tb = BufferUtils.createFloatBuffer(3*3*2);
tb.rewind();
tb.put(new float[]{0,0}); tb.put(new float[]{0.5f,0}); tb.put(new float[]{1,0});
tb.put(new float[]{0,0.5f}); tb.put(new float[]{0.5f,0.5f}); tb.put(new float[]{1,0.5f});
tb.put(new float[]{0,1}); tb.put(new float[]{0.5f,1}); tb.put(new float[]{1,1});
int[] indexes = new int[]{0,3,1,4,2,5, 5,3, 3,6,4,7,5,8};
IntBuffer ib = BufferUtils.createIntBuffer(indexes.length);
ib.put(indexes);
strip.setBuffer(Type.Position, 3, vb);
strip.setBuffer(Type.Normal, 3, nb);
strip.setBuffer(Type.TexCoord, 2, tb);
strip.setBuffer(Type.Index, 3, ib);
strip.updateBound();
return strip;
}
示例10: createMesh
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public Mesh createMesh(Vector3f scale, Vector2f tcScale, Vector2f tcOffset, float offsetAmount, int totalSize, boolean center, int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod) {
FloatBuffer pb = writeVertexArray(null, scale, center);
FloatBuffer tb = writeTexCoordArray(null, tcOffset, tcScale, offsetAmount, totalSize);
FloatBuffer nb = writeNormalArray(null, scale);
IntBuffer ib = writeIndexArrayLodDiff(null, lod, rightLod, topLod, leftLod, bottomLod);
Mesh m = new Mesh();
m.setMode(Mode.TriangleStrip);
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;
}
示例11: convertToList
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
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());
}
}
示例12: startSubMesh
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
private void startSubMesh(String matName, String usesharedvertices, String use32bitIndices, String opType) throws SAXException {
mesh = new Mesh();
if (opType == null || opType.equals("triangle_list")) {
mesh.setMode(Mesh.Mode.Triangles);
} else if (opType.equals("triangle_strip")) {
mesh.setMode(Mesh.Mode.TriangleStrip);
} else if (opType.equals("triangle_fan")) {
mesh.setMode(Mesh.Mode.TriangleFan);
}
usesBigIndices = parseBool(use32bitIndices, false);
usesSharedVerts = parseBool(usesharedvertices, false);
if (usesSharedVerts) {
// import vertexbuffers from shared geom
IntMap<VertexBuffer> sharedBufs = sharedMesh.getBuffers();
for (Entry<VertexBuffer> entry : sharedBufs) {
mesh.setBuffer(entry.getValue());
}
}
if (meshName == null) {
geom = new Geometry("OgreSubmesh-" + (++meshIndex), mesh);
} else {
geom = new Geometry(meshName + "-geom-" + (++meshIndex), mesh);
}
if (usesSharedVerts){
// this mesh is shared!
geom.setUserData(UserData.JME_SHAREDMESH, sharedMesh);
}
applyMaterial(geom, matName);
geoms.add(geom);
}
示例13: genNormalLines
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public static Mesh genNormalLines(Mesh mesh, float scale) {
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
FloatBuffer normalBuffer = (FloatBuffer) mesh.getBuffer(Type.Normal).getData();
ColorRGBA originColor = ColorRGBA.White;
ColorRGBA normalColor = ColorRGBA.Blue;
Mesh lineMesh = new Mesh();
lineMesh.setMode(Mesh.Mode.Lines);
Vector3f origin = new Vector3f();
Vector3f point = new Vector3f();
FloatBuffer lineVertex = BufferUtils.createFloatBuffer(vertexBuffer.capacity() * 2);
FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.capacity() / 3 * 4 * 2);
for (int i = 0; i < vertexBuffer.capacity() / 3; i++) {
populateFromBuffer(origin, vertexBuffer, i);
populateFromBuffer(point, normalBuffer, i);
int index = i * 2;
setInBuffer(origin, lineVertex, index);
setInBuffer(originColor, lineColor, index);
point.multLocal(scale);
point.addLocal(origin);
setInBuffer(point, lineVertex, index + 1);
setInBuffer(normalColor, lineColor, index + 1);
}
lineMesh.setBuffer(Type.Position, 3, lineVertex);
lineMesh.setBuffer(Type.Color, 4, lineColor);
lineMesh.setStatic();
lineMesh.setInterleaved();
return lineMesh;
}
示例14: compressIndexBuffer
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public static void compressIndexBuffer(Mesh mesh){
int vertCount = mesh.getVertexCount();
VertexBuffer vb = mesh.getBuffer(Type.Index);
Format targetFmt;
if (vb.getFormat() == Format.UnsignedInt && vertCount <= 0xffff){
if (vertCount <= 256)
targetFmt = Format.UnsignedByte;
else
targetFmt = Format.UnsignedShort;
}else if (vb.getFormat() == Format.UnsignedShort && vertCount <= 0xff){
targetFmt = Format.UnsignedByte;
}else{
return;
}
IndexBuffer src = mesh.getIndexBuffer();
Buffer newBuf = VertexBuffer.createBuffer(targetFmt, vb.getNumComponents(), src.size());
VertexBuffer newVb = new VertexBuffer(Type.Index);
newVb.setupData(vb.getUsage(), vb.getNumComponents(), targetFmt, newBuf);
mesh.clearBuffer(Type.Index);
mesh.setBuffer(newVb);
IndexBuffer dst = mesh.getIndexBuffer();
for (int i = 0; i < src.size(); i++){
dst.put(i, src.get(i));
}
}
示例15: init
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
private void init(TransferFunctionEditor tfe, Node node) {
this.tfe = tfe;
buffer = new VertexBuffer(VertexBuffer.Type.Position);
buffer.setupData(VertexBuffer.Usage.Dynamic, 4, VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(4 * points.size()));
this.node = new Node(name);
node.attachChild(this.node);
Mesh mesh1 = new Mesh();
mesh1.setMode(Mesh.Mode.LineStrip);
mesh1.setBuffer(buffer);
Material mat1 = new Material(tfe.app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", color);
mat1.getAdditionalRenderState().setLineWidth(LINE_WIDTHS[0]);
Geometry geom1 = new Geometry(name, mesh1);
geom1.setMaterial(mat1);
geom1.setLocalScale(1, Y_SIZE, 1);
this.node.attachChild(geom1);
meshes[0] = mesh1;
geoms[0] = geom1;
Mesh mesh2 = new Mesh();
mesh2.setMode(Mesh.Mode.Points);
mesh2.setBuffer(buffer);
Material mat2 = new Material(tfe.app.getAssetManager(), "org/shaman/jmecl/utils/UnshadedPoint.j3md");
mat2.getAdditionalRenderState().setPointSprite(true);
mat2.setColor("Color", color);
Geometry geom2 = new Geometry(name+"_p", mesh2);
geom2.setMaterial(mat2);
geom2.setLocalScale(1, Y_SIZE, 1);
this.node.attachChild(geom2);
meshes[1] = mesh2;
geoms[1] = geom2;
}