本文整理汇总了Java中com.jme3.scene.VertexBuffer.getFormat方法的典型用法代码示例。如果您正苦于以下问题:Java VertexBuffer.getFormat方法的具体用法?Java VertexBuffer.getFormat怎么用?Java VertexBuffer.getFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.scene.VertexBuffer
的用法示例。
在下文中一共展示了VertexBuffer.getFormat方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: optimize
import com.jme3.scene.VertexBuffer; //导入方法依赖的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();
}
示例2: compressIndexBuffer
import com.jme3.scene.VertexBuffer; //导入方法依赖的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));
}
}
示例3: convertToFixed
import com.jme3.scene.VertexBuffer; //导入方法依赖的package包/类
public static VertexBuffer convertToFixed(VertexBuffer vb){
if (vb.getFormat() == Format.Int)
return vb;
FloatBuffer fb = (FloatBuffer) vb.getData();
IntBuffer ib = BufferUtils.createIntBuffer(fb.capacity());
convertToFixed(fb, ib);
VertexBuffer newVb = new VertexBuffer(vb.getBufferType());
newVb.setupData(vb.getUsage(),
vb.getNumComponents(),
Format.Int,
ib);
return newVb;
}
示例4: convertToFloat
import com.jme3.scene.VertexBuffer; //导入方法依赖的package包/类
public static VertexBuffer convertToFloat(VertexBuffer vb){
if (vb.getFormat() == Format.Float)
return vb;
IntBuffer ib = (IntBuffer) vb.getData();
FloatBuffer fb = BufferUtils.createFloatBuffer(ib.capacity());
convertToFloat(ib, fb);
VertexBuffer newVb = new VertexBuffer(vb.getBufferType());
newVb.setupData(vb.getUsage(),
vb.getNumComponents(),
Format.Float,
fb);
return newVb;
}
示例5: SharedBuffer
import com.jme3.scene.VertexBuffer; //导入方法依赖的package包/类
/**
* Creates a shared buffer from the specified vertex buffer
* @param vertexBuffer the vertex buffer to use
*/
public SharedBuffer(VertexBuffer vertexBuffer) {
this.jmeBuffer = vertexBuffer;
this.format = vertexBuffer.getFormat();
this.type = vertexBuffer.getBufferType();
this.components = vertexBuffer.getNumComponents();
this.size = vertexBuffer.getNumElements();
}
示例6: getColor
import com.jme3.scene.VertexBuffer; //导入方法依赖的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");
}
}