本文整理汇总了Java中com.jme3.scene.Mesh.getBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java Mesh.getBuffer方法的具体用法?Java Mesh.getBuffer怎么用?Java Mesh.getBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.scene.Mesh
的用法示例。
在下文中一共展示了Mesh.getBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resetToBind
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
void resetToBind() {
for (Mesh mesh : targets){
if (isMeshAnimated(mesh)) {
VertexBuffer bi = mesh.getBuffer(Type.BoneIndex);
ByteBuffer bib = (ByteBuffer) bi.getData();
if (!bib.hasArray()) {
mesh.prepareForAnim(true); // prepare for software animation
}
VertexBuffer bindPos = mesh.getBuffer(Type.BindPosePosition);
VertexBuffer bindNorm = mesh.getBuffer(Type.BindPoseNormal);
VertexBuffer pos = mesh.getBuffer(Type.Position);
VertexBuffer norm = mesh.getBuffer(Type.Normal);
FloatBuffer pb = (FloatBuffer) pos.getData();
FloatBuffer nb = (FloatBuffer) norm.getData();
FloatBuffer bpb = (FloatBuffer) bindPos.getData();
FloatBuffer bnb = (FloatBuffer) bindNorm.getData();
pb.clear();
nb.clear();
bpb.clear();
bnb.clear();
pb.put(bpb).clear();
nb.put(bnb).clear();
}
}
}
示例2: generate
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public static void generate(Spatial scene, boolean splitMirrored) {
if (scene instanceof Node) {
Node node = (Node) scene;
for (Spatial child : node.getChildren()) {
generate(child, splitMirrored);
}
} else {
Geometry geom = (Geometry) scene;
Mesh mesh = geom.getMesh();
// Check to ensure mesh has texcoords and normals before generating
if (mesh.getBuffer(Type.TexCoord) != null && mesh.getBuffer(Type.Normal) != null) {
generate(geom.getMesh(), true, splitMirrored);
}
}
}
示例3: 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);
}
示例4: getHash
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
protected String getHash(Mesh m, VHACDParameters p) throws Exception {
ByteArrayOutputStream bao=new ByteArrayOutputStream();
VertexBuffer p_b=m.getBuffer(Type.Position);
VertexBuffer i_b=m.getBuffer(Type.Index);
p.toOutputStream(bao);
_EXPORTER.save(p_b,bao);
_EXPORTER.save(i_b,bao);
byte bytes[]=bao.toByteArray();
bao.close();
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(bytes);
byte[] digest = md.digest();
BigInteger bigInt = new BigInteger(1,digest);
String hash = bigInt.toString(16);
while(hash.length() < 32 )hash = "0"+hash;
return hash;
}
示例5: applyFrame
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
private void applyFrame(Mesh target, int frameIndex, float weight){
PoseFrame frame = frames[frameIndex];
VertexBuffer pb = target.getBuffer(Type.Position);
for (int i = 0; i < frame.poses.length; i++){
Pose pose = frame.poses[i];
float poseWeight = frame.weights[i] * weight;
pose.apply(poseWeight, (FloatBuffer) pb.getData());
}
// force to re-upload data to gpu
pb.updateData(pb.getData());
}
示例6: populateHdataFromMesh
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
/**
* Populate the height data from the supplied mesh.
* The mesh's dimensions should be the same as width and height
* of this geomap
*/
public void populateHdataFromMesh(Mesh mesh) {
hdata = BufferUtils.createFloatBuffer(width*height);
hdata.rewind();
VertexBuffer pb = mesh.getBuffer(Type.Position);
FloatBuffer fb = (FloatBuffer) pb.getData();
for (int r=0; r<height; r++) {
for (int c=0; c<width; c++) {
float f = fb.get( (width*r) + c + 1);
hdata.put( f );
}
}
}
示例7: updateVertexArray
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public void updateVertexArray(Mesh mesh) {
int id = mesh.getId();
if (id == -1) {
IntBuffer temp = intBuf1;
ARBVertexArrayObject.glGenVertexArrays(temp);
id = temp.get(0);
mesh.setId(id);
}
if (context.boundVertexArray != id) {
ARBVertexArrayObject.glBindVertexArray(id);
context.boundVertexArray = id;
}
VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
if (interleavedData != null && interleavedData.isUpdateNeeded()) {
updateBufferData(interleavedData);
}
IntMap<VertexBuffer> buffers = mesh.getBuffers();
for (Entry<VertexBuffer> entry : buffers) {
VertexBuffer vb = entry.getValue();
if (vb.getBufferType() == Type.InterleavedData
|| vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
|| vb.getBufferType() == Type.Index) {
continue;
}
if (vb.getStride() == 0) {
// not interleaved
setVertexAttrib(vb);
} else {
// interleaved
setVertexAttrib(vb, interleavedData);
}
}
}
示例8: renderMeshVertexArray
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
private void renderMeshVertexArray(Mesh mesh, int lod, int count) {
if (mesh.getId() == -1){
updateVertexArray(mesh);
}else{
// TODO: Check if it was updated
}
if (context.boundVertexArray != mesh.getId()) {
ARBVertexArrayObject.glBindVertexArray(mesh.getId());
context.boundVertexArray = mesh.getId();
}
// IntMap<VertexBuffer> buffers = mesh.getBuffers();
VertexBuffer indices = null;
if (mesh.getNumLodLevels() > 0) {
indices = mesh.getLodLevel(lod);
} else {
indices = mesh.getBuffer(Type.Index);
}
if (indices != null) {
drawTriangleList(indices, mesh, count);
} else {
drawTriangleArray(mesh.getMode(), count, mesh.getVertexCount());
}
clearVertexAttribs();
clearTextureUnits();
}
示例9: genTbnLines
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public static Mesh genTbnLines(Mesh mesh, float scale) {
if (mesh.getBuffer(Type.Tangent) == null) {
return genNormalLines(mesh, scale);
} else {
return genTangentLines(mesh, scale);
}
}
示例10: processTriangles
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
private static VertexData[] processTriangles(Mesh mesh,
int[] index, Vector3f[] v, Vector2f[] t)
{
IndexWrapper indexBuffer = getIndexWrapper(mesh.getBuffer(Type.Index).getData());
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;
}
示例11: optimize
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public static void optimize(Mesh mesh, boolean toFixed){
// update any data that need updating
mesh.updateBound();
mesh.updateCounts();
// set all buffers into STATIC_DRAW mode
mesh.setStatic();
if (mesh.getBuffer(Type.Index) != null){
// compress index buffer from UShort to UByte (if possible)
FloatToFixed.compressIndexBuffer(mesh);
// generate triangle strips stitched with degenerate tris
generateStrips(mesh, false, false, 16, 0);
}
IntMap<VertexBuffer> bufs = mesh.getBuffers();
for (Entry<VertexBuffer> entry : bufs){
VertexBuffer vb = entry.getValue();
if (vb == null || vb.getBufferType() == Type.Index)
continue;
if (vb.getFormat() == Format.Float){
if (vb.getBufferType() == Type.Color){
// convert the color buffer to UByte
vb = FloatToFixed.convertToUByte(vb);
vb.setNormalized(true);
}else if (toFixed){
// convert normals, positions, and texcoords
// to fixed-point (16.16)
vb = FloatToFixed.convertToFixed(vb);
// vb = FloatToFixed.convertToFloat(vb);
}
mesh.clearBuffer(vb.getBufferType());
mesh.setBuffer(vb);
}
}
mesh.setInterleaved();
}
示例12: 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));
}
}
示例13: getColor
import com.jme3.scene.Mesh; //导入方法依赖的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");
}
}
示例14: isMeshAnimated
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
private boolean isMeshAnimated(Mesh mesh){
return mesh.getBuffer(Type.BindPosePosition) != null;
}
示例15: renderMeshDefault
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
private void renderMeshDefault(Mesh mesh, int lod, int count) {
VertexBuffer indices = null;
VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
if (interleavedData != null && interleavedData.isUpdateNeeded()) {
updateBufferData(interleavedData);
}
//IntMap<VertexBuffer> buffers = mesh.getBuffers();
ArrayList<VertexBuffer> buffersList = mesh.getBufferList();
if (mesh.getNumLodLevels() > 0) {
indices = mesh.getLodLevel(lod);
} else {
indices = mesh.getBuffer(Type.Index);
}
//for (Entry<VertexBuffer> entry : buffers) {
// VertexBuffer vb = entry.getValue();
for (int i = 0; i < buffersList.size(); i++){
VertexBuffer vb = buffersList.get(i);
if (vb.getBufferType() == Type.InterleavedData
|| vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
|| vb.getBufferType() == Type.Index) {
continue;
}
if (vb.getStride() == 0) {
// not interleaved
setVertexAttrib(vb);
} else {
// interleaved
setVertexAttrib(vb, interleavedData);
}
}
if (indices != null) {
drawTriangleList(indices, mesh, count);
} else {
drawTriangleArray(mesh.getMode(), count, mesh.getVertexCount());
}
clearVertexAttribs();
clearTextureUnits();
}