当前位置: 首页>>代码示例>>Java>>正文


Java BufferUtils类代码示例

本文整理汇总了Java中com.jme3.util.BufferUtils的典型用法代码示例。如果您正苦于以下问题:Java BufferUtils类的具体用法?Java BufferUtils怎么用?Java BufferUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BufferUtils类属于com.jme3.util包,在下文中一共展示了BufferUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startChange

import com.jme3.util.BufferUtils; //导入依赖的package包/类
/**
 * Start making changes.
 */
private void startChange() {

    final Array<ColorPoint> colorPoints = getColorPoints();
    colorPoints.clear();

    final Texture alphaTexture = notNull(getAlphaTexture());
    final Image image = alphaTexture.getImage();
    final ByteBuffer data = image.getData(0);

    if (prevBuffer == null) {
        prevBuffer = BufferUtils.createByteBuffer(data.capacity());
    } else if (prevBuffer.capacity() < data.capacity()) {
        BufferUtils.destroyDirectBuffer(prevBuffer);
        prevBuffer = BufferUtils.createByteBuffer(data.capacity());
    }

    final int position = data.position();
    data.position(0);
    prevBuffer.clear();
    prevBuffer.put(data);
    prevBuffer.flip();
    data.position(position);
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:27,代码来源:PaintTerrainToolControl.java

示例2: processMesh

import com.jme3.util.BufferUtils; //导入依赖的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()])));
}
 
开发者ID:quadracoatl,项目名称:quadracoatl,代码行数:18,代码来源:MeshBuilder.java

示例3: Sector

import com.jme3.util.BufferUtils; //导入依赖的package包/类
/**
 * Create a sector using the points from a specified arc.
 *
 * @param arc Arc to pull points from
 */
public Sector( PointArc arc ) {
    this.arc = arc;

    // calculate convenience numbers
    int numTriangles = arc.getNumVertices() - 1;
    int numEdgeVertices = numTriangles + 1;
    int numVertices = numEdgeVertices + 1; // +1 for origin

    positionBuffer = BufferUtils.createFloatBuffer( numVertices * 3 );
    ShortBuffer indexBuffer = BufferUtils.createShortBuffer( numVertices );

    setPositions();

    // our shape is easy to make with the TriangleFan mode
    for ( int i = 0; i < numVertices; i++ ) {
        indexBuffer.put( (short) i );
    }

    this.setMode( Mode.TriangleFan );
    this.setBuffer( VertexBuffer.Type.Position, 3, positionBuffer );
    this.setBuffer( VertexBuffer.Type.Index, 3, indexBuffer );
    this.updateBound();
    this.updateCounts();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:30,代码来源:Sector.java

示例4: PointArc

import com.jme3.util.BufferUtils; //导入依赖的package包/类
/**
 * Creates an Arc
 *
 * @param startDir        Unit vector for one end of the arc
 * @param endDir          Unit vector for the other end of the arc
 * @param radius          How far from the origin should the arc be? (Radius of the circle that the arc is part of)
 * @param numSegments     How many line segments should the arc be approximated by
 * @param lastMidpointDir The direction that the arc will point out in if it is determined to be too close to 180 degrees
 */
public PointArc( Vector3f startDir, Vector3f endDir, float radius, int numSegments, Vector3f lastMidpointDir ) {
    this.radius = radius;
    numVertices = numSegments + 1;
    numFloats = numVertices * 3;
    int numIndices = numSegments + 1;

    positionBuffer = BufferUtils.createFloatBuffer( numFloats );
    ShortBuffer indexBuffer = BufferUtils.createShortBuffer( numIndices );

    setPositions( startDir, endDir, lastMidpointDir );

    for ( short i = 0; i < numIndices; i++ ) {
        indexBuffer.put( i );
    }

    this.setMode( Mode.LineStrip );
    this.setBuffer( VertexBuffer.Type.Position, 3, positionBuffer );
    this.setBuffer( VertexBuffer.Type.Index, 2, indexBuffer );
    this.updateBound();
    this.updateCounts();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:31,代码来源:PointArc.java

示例5: apply

import com.jme3.util.BufferUtils; //导入依赖的package包/类
/**
 * Applies the offsets of this pose to the vertex buffer given by the blend factor.
 *
 * @param blend Blend factor, 0 = no change to vert buf, 1 = apply full offsets
 * @param vertbuf Vertex buffer to apply this pose to
 */
public void apply(float blend, FloatBuffer vertbuf){
    for (int i = 0; i < indices.length; i++){
        Vector3f offset = offsets[i];
        int vertIndex   = indices[i];

        tempVec.set(offset).multLocal(blend);

        // aquire vert
        BufferUtils.populateFromBuffer(tempVec2, vertbuf, vertIndex);

        // add offset multiplied by factor
        tempVec2.addLocal(tempVec);

        // write modified vert
        BufferUtils.setInBuffer(tempVec2, vertbuf, vertIndex);
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:24,代码来源:Pose.java

示例6: writeIndexArray

import com.jme3.util.BufferUtils; //导入依赖的package包/类
public IntBuffer writeIndexArray(IntBuffer store){
    int faceN = (getWidth()-1)*(getHeight()-1)*2;

    if (store!=null){
        if (store.remaining() < faceN*3)
            throw new BufferUnderflowException();
    }else{
        store = BufferUtils.createIntBuffer(faceN*3);
    }

    int i = 0;
    for (int z = 0; z < getHeight()-1; z++){
        for (int x = 0; x < getWidth()-1; x++){
            store.put(i).put(i+getWidth()).put(i+getWidth()+1);
            store.put(i+getWidth()+1).put(i+1).put(i);
            i++;

            // TODO: There's probably a better way to do this..
            if (x==getWidth()-2) i++;
        }
    }
    store.flip();

    return store;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:26,代码来源:AbstractGeomap.java

示例7: getFrameBufferSamplePositions

import com.jme3.util.BufferUtils; //导入依赖的package包/类
public Vector2f[] getFrameBufferSamplePositions(FrameBuffer fb) {
    if (fb.getSamples() <= 1) {
        throw new IllegalArgumentException("Framebuffer must be multisampled");
    }

    setFrameBuffer(fb);

    Vector2f[] samplePositions = new Vector2f[fb.getSamples()];
    FloatBuffer samplePos = BufferUtils.createFloatBuffer(2);
    for (int i = 0; i < samplePositions.length; i++) {
        glGetMultisample(GL_SAMPLE_POSITION, i, samplePos);
        samplePos.clear();
        samplePositions[i] = new Vector2f(samplePos.get(0) - 0.5f,
                samplePos.get(1) - 0.5f);
    }
    return samplePositions;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:18,代码来源:LwjglRenderer.java

示例8: WireFrustum

import com.jme3.util.BufferUtils; //导入依赖的package包/类
public WireFrustum(Vector3f[] points){
    if (points != null)
        setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(points));

    setBuffer(Type.Index, 2,
            new short[]{
                 0, 1,
                 1, 2,
                 2, 3,
                 3, 0,

                 4, 5,
                 5, 6,
                 6, 7,
                 7, 4,

                 0, 4,
                 1, 5,
                 2, 6,
                 3, 7,
            }
    );
    setMode(Mode.Lines);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:25,代码来源:WireFrustum.java

示例9: update

import com.jme3.util.BufferUtils; //导入依赖的package包/类
public void update(Vector3f[] points){
    VertexBuffer vb = getBuffer(Type.Position);
    if (vb == null){
        setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(points));
        return;
    }

    FloatBuffer b = BufferUtils.createFloatBuffer(points);
    FloatBuffer a = (FloatBuffer) vb.getData();
    b.rewind();
    a.rewind();
    a.put(b);
    a.rewind();

    vb.updateData(a);
    
    updateBound();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:WireFrustum.java

示例10: WireSphere

import com.jme3.util.BufferUtils; //导入依赖的package包/类
public WireSphere(float radius) {
        updatePositions(radius);
        ShortBuffer ib = BufferUtils.createShortBuffer(samples * 2 * 2 + zSamples * samples * 2 /*+ 3 * 2*/);
        setBuffer(Type.Index, 2, ib);

//        ib.put(new byte[]{
//            (byte) 0, (byte) 1,
//            (byte) 2, (byte) 3,
//            (byte) 4, (byte) 5,
//        });

//        int curNum = 3 * 2;
        int curNum = 0;
        for (int j = 0; j < 2 + zSamples; j++) {
            for (int i = curNum; i < curNum + samples - 1; i++) {
                ib.put((short) i).put((short) (i + 1));
            }
            ib.put((short) (curNum + samples - 1)).put((short) curNum);
            curNum += samples;
        }

        setMode(Mode.Lines);

        updateBound();
        updateCounts();
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:27,代码来源:WireSphere.java

示例11: clone

import com.jme3.util.BufferUtils; //导入依赖的package包/类
/**
 * Creates a deep clone of this VertexBuffer but overrides the
 * {@link Type}.
 * 
 * @param overrideType The type of the cloned VertexBuffer
 * @return A deep clone of the buffer
 */
public VertexBuffer clone(Type overrideType){
    VertexBuffer vb = new VertexBuffer(overrideType);
    vb.components = components;
    vb.componentsLength = componentsLength;
    vb.data = BufferUtils.clone(data);
    vb.format = format;
    vb.handleRef = new Object();
    vb.id = -1;
    vb.normalized = normalized;
    vb.offset = offset;
    vb.stride = stride;
    vb.updateNeeded = true;
    vb.usage = usage;
    return vb;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:23,代码来源:VertexBuffer.java

示例12: duUpdateGeometryNormals

import com.jme3.util.BufferUtils; //导入依赖的package包/类
protected void duUpdateGeometryNormals() {
    if (getBuffer(Type.Normal) == null){
        float[] normals = new float[8 * 3];
        
        Vector3f[] vert = computeVertices();
        Vector3f norm = new Vector3f();
        
        for (int i = 0; i < 8; i++) {
            norm.set(vert[i]).normalizeLocal();
            
            normals[i * 3 + 0] = norm.x;
            normals[i * 3 + 1] = norm.x;
            normals[i * 3 + 2] = norm.x;
        }
        
        setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:StripBox.java

示例13: duUpdateGeometryVertices

import com.jme3.util.BufferUtils; //导入依赖的package包/类
protected void duUpdateGeometryVertices() {
    FloatBuffer fpb = BufferUtils.createVector3Buffer(8 * 3);
    Vector3f[] v = computeVertices();
    fpb.put(new float[] {
            v[0].x, v[0].y, v[0].z, 
            v[1].x, v[1].y, v[1].z, 
            v[2].x, v[2].y, v[2].z, 
            v[3].x, v[3].y, v[3].z,
            v[4].x, v[4].y, v[4].z, 
            v[5].x, v[5].y, v[5].z, 
            v[6].x, v[6].y, v[6].z, 
            v[7].x, v[7].y, v[7].z, 
    });
    setBuffer(Type.Position, 3, fpb);
    setMode(Mode.TriangleStrip);
    updateBound();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:18,代码来源:StripBox.java

示例14: getTriangle

import com.jme3.util.BufferUtils; //导入依赖的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");
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:32,代码来源:Mesh.java

示例15: startFaces

import com.jme3.util.BufferUtils; //导入依赖的package包/类
private void startFaces(String count) throws SAXException {
    int numFaces = parseInt(count);
    int numIndices;

    if (mesh.getMode() == Mesh.Mode.Triangles) {
        numIndices = numFaces * 3;
    } else {
        throw new SAXException("Triangle strip or fan not supported!");
    }

    vb = new VertexBuffer(VertexBuffer.Type.Index);
    if (!usesBigIndices) {
        sb = BufferUtils.createShortBuffer(numIndices);
        ib = null;
        vb.setupData(Usage.Static, 3, Format.UnsignedShort, sb);
    } else {
        ib = BufferUtils.createIntBuffer(numIndices);
        sb = null;
        vb.setupData(Usage.Static, 3, Format.UnsignedInt, ib);
    }
    mesh.setBuffer(vb);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:23,代码来源:MeshLoader.java


注:本文中的com.jme3.util.BufferUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。