Java Code Examples for java.nio.FloatBuffer#clear()

The following examples show how to use java.nio.FloatBuffer#clear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SkeletonControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void resetToBind() {
        for (int i = 0; i < targets.length; i++) {
            Mesh mesh = targets[i];
            if (targets[i].getBuffer(Type.BindPosePosition) != null) {
//                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();
            }
        }
    }
 
Example 2
Source File: Mesh.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public void scaleTextureCoordinates(Vector2f scaleFactor) {
	VertexBuffer tc = getBuffer(Type.TexCoord);
	if (tc == null) {
		throw new IllegalStateException("The mesh has no texture coordinates");
	}

	if (tc.getFormat() != VertexBuffer.Format.Float) {
		throw new UnsupportedOperationException("Only float texture coord format is supported");
	}

	if (tc.getNumComponents() != 2) {
		throw new UnsupportedOperationException("Only 2D texture coords are supported");
	}

	FloatBuffer fb = (FloatBuffer) tc.getData();
	fb.clear();
	for (int i = 0; i < fb.capacity() / 2; i++) {
		float x = fb.get();
		float y = fb.get();
		fb.position(fb.position() - 2);
		x *= scaleFactor.getX();
		y *= scaleFactor.getY();
		fb.put(x).put(y);
	}
	fb.clear();
}
 
Example 3
Source File: BufferUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Generates a Vector2f array from the given FloatBuffer.
 *
 * @param buff
 *            the FloatBuffer to read from
 * @return a newly generated array of Vector2f objects
 */
public static Vector2f[] getVector2Array(FloatBuffer buff) {
    buff.clear();
    Vector2f[] verts = new Vector2f[buff.limit() / 2];
    for (int x = 0; x < verts.length; x++) {
        Vector2f v = new Vector2f(buff.get(), buff.get());
        verts[x] = v;
    }
    return verts;
}
 
Example 4
Source File: BufferUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Generates a Vector2f array from the given FloatBuffer.
 *
 * @param buff
 *            the FloatBuffer to read from
 * @return a newly generated array of Vector2f objects
 */
public static Vector2f[] getVector2Array(FloatBuffer buff) {
    buff.clear();
    Vector2f[] verts = new Vector2f[buff.limit() / 2];
    for (int x = 0; x < verts.length; x++) {
        Vector2f v = new Vector2f(buff.get(), buff.get());
        verts[x] = v;
    }
    return verts;
}
 
Example 5
Source File: BufferUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Generates a Vector3f array from the given FloatBuffer.
 *
 * @param buff
 *            the FloatBuffer to read from
 * @return a newly generated array of Vector3f objects
 */
public static Vector3f[] getVector3Array(FloatBuffer buff) {
    buff.clear();
    Vector3f[] verts = new Vector3f[buff.limit() / 3];
    for (int x = 0; x < verts.length; x++) {
        Vector3f v = new Vector3f(buff.get(), buff.get(), buff.get());
        verts[x] = v;
    }
    return verts;
}
 
Example 6
Source File: BufferUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Generate a new FloatBuffer using the given array of float primitives.
 * @param data array of float primitives to place into a new FloatBuffer
 */
public static FloatBuffer createFloatBuffer(float... data) {
    if (data == null) {
        return null;
    }
    FloatBuffer buff = createFloatBuffer(data.length);
    buff.clear();
    buff.put(data);
    buff.flip();
    return buff;
}
 
Example 7
Source File: Converter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static IndexedMesh convert(Mesh mesh) {
    IndexedMesh jBulletIndexedMesh = new IndexedMesh();
    jBulletIndexedMesh.triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4);
    jBulletIndexedMesh.vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4);

    IndexBuffer indices = mesh.getIndicesAsList();
    
    FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
    vertices.rewind();

    int verticesLength = mesh.getVertexCount() * 3;
    jBulletIndexedMesh.numVertices = mesh.getVertexCount();
    jBulletIndexedMesh.vertexStride = 12; //3 verts * 4 bytes per.
    for (int i = 0; i < verticesLength; i++) {
        float tempFloat = vertices.get();
        jBulletIndexedMesh.vertexBase.putFloat(tempFloat);
    }

    int indicesLength = mesh.getTriangleCount() * 3;
    jBulletIndexedMesh.numTriangles = mesh.getTriangleCount();
    jBulletIndexedMesh.triangleIndexStride = 12; //3 index entries * 4 bytes each.
    for (int i = 0; i < indicesLength; i++) {
        jBulletIndexedMesh.triangleIndexBase.putInt(indices.get(i));
    }
    vertices.rewind();
    vertices.clear();

    return jBulletIndexedMesh;
}
 
Example 8
Source File: BufferUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Generate a new FloatBuffer using the given array of float primitives.
 *
 * @param data
 *            array of float primitives to place into a new FloatBuffer
 * @return a new direct, flipped FloatBuffer, or null if data was null
 */
public static FloatBuffer createFloatBuffer(float... data) {
    if (data == null) {
        return null;
    }
    FloatBuffer buff = createFloatBuffer(data.length);
    buff.clear();
    buff.put(data);
    buff.flip();
    return buff;
}
 
Example 9
Source File: BufferUtils.java    From Ultraino with MIT License 5 votes vote down vote up
/**
 * Generates a Vector2f array from the given FloatBuffer.
 *
 * @param buff
 *            the FloatBuffer to read from
 * @return a newly generated array of Vector2f objects
 */
public static Vector2f[] getVector2Array(FloatBuffer buff) {
    buff.clear();
    Vector2f[] verts = new Vector2f[buff.limit() / 2];
    for (int x = 0; x < verts.length; x++) {
        Vector2f v = new Vector2f(buff.get(), buff.get());
        verts[x] = v;
    }
    return verts;
}
 
Example 10
Source File: SkeletonPoints.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void updateGeometry(){
    VertexBuffer vb = getBuffer(Type.Position);
    FloatBuffer posBuf = getFloatBuffer(Type.Position);
    posBuf.clear();
    for (int i = 0; i < skeleton.getBoneCount(); i++){
        Bone bone = skeleton.getBone(i);
        Vector3f bonePos = bone.getModelSpacePosition();

        posBuf.put(bonePos.getX()).put(bonePos.getY()).put(bonePos.getZ());
    }
    posBuf.flip();
    vb.updateData(posBuf);

    updateBound();
}
 
Example 11
Source File: FloatToFixed.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void convertToFloat(IntBuffer input, FloatBuffer output){
    if (output.capacity() < input.capacity())
        throw new RuntimeException("Output must be at least as large as input!");

    input.clear();
    output.clear();
    for (int i = 0; i < input.capacity(); i++){
        output.put( ((float)input.get() / (float)(1<<16)) );
    }
    output.flip();
}
 
Example 12
Source File: Converter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static synchronized IndexedMesh convert(Mesh mesh) {
    IndexedMesh jBulletIndexedMesh = new IndexedMesh();
    jBulletIndexedMesh.triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4);
    jBulletIndexedMesh.vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4);

    IndexBuffer indices = mesh.getIndicesAsList();
    
    FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
    vertices.rewind();

    int verticesLength = mesh.getVertexCount() * 3;
    jBulletIndexedMesh.numVertices = mesh.getVertexCount();
    jBulletIndexedMesh.vertexStride = 12; //3 verts * 4 bytes per.
    for (int i = 0; i < verticesLength; i++) {
        float tempFloat = vertices.get();
        jBulletIndexedMesh.vertexBase.putFloat(tempFloat);
    }

    int indicesLength = mesh.getTriangleCount() * 3;
    jBulletIndexedMesh.numTriangles = mesh.getTriangleCount();
    jBulletIndexedMesh.triangleIndexStride = 12; //3 index entries * 4 bytes each.
    for (int i = 0; i < indicesLength; i++) {
        jBulletIndexedMesh.triangleIndexBase.putInt(indices.get(i));
    }
    vertices.rewind();
    vertices.clear();

    return jBulletIndexedMesh;
}
 
Example 13
Source File: BufferUtils.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new float[] array and populate it with the given FloatBuffer's contents.
 *
 * @param buff
 *            the FloatBuffer to read from
 * @return a new float array populated from the FloatBuffer
 */
public static float[] getFloatArray(FloatBuffer buff) {
	if (buff == null) {
		return null;
	}
	buff.clear();
	float[] inds = new float[buff.limit()];
	for (int x = 0; x < inds.length; x++) {
		inds[x] = buff.get();
	}
	return inds;
}
 
Example 14
Source File: BufferUtils.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a Vector3f array from the given FloatBuffer.
 *
 * @param buff
 *            the FloatBuffer to read from
 * @return a newly generated array of Vector3f objects
 */
public static Vector3f[] getVector3Array(FloatBuffer buff) {
	buff.clear();
	Vector3f[] verts = new Vector3f[buff.limit() / 3];
	for (int x = 0; x < verts.length; x++) {
		Vector3f v = new Vector3f(buff.get(), buff.get(), buff.get());
		verts[x] = v;
	}
	return verts;
}
 
Example 15
Source File: BufferUtils.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generate a new FloatBuffer using the given array of float primitives.
 *
 * @param data
 *            array of float primitives to place into a new FloatBuffer
 */
public static FloatBuffer createFloatBuffer(float... data) {
	if (data == null) {
		return null;
	}
	FloatBuffer buff = createFloatBuffer(data.length);
	buff.clear();
	buff.put(data);
	buff.flip();
	return buff;
}
 
Example 16
Source File: GImpactCollisionShape.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void createCollisionMesh(Mesh mesh) {
        triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4);
        vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4); 
//        triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4);
//        vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4);
        numVertices = mesh.getVertexCount();
        vertexStride = 12; //3 verts * 4 bytes per.
        numTriangles = mesh.getTriangleCount();
        triangleIndexStride = 12; //3 index entries * 4 bytes each.

        IndexBuffer indices = mesh.getIndexBuffer();
        FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
        vertices.rewind();

        int verticesLength = mesh.getVertexCount() * 3;
        for (int i = 0; i < verticesLength; i++) {
            float tempFloat = vertices.get();
            vertexBase.putFloat(tempFloat);
        }

        int indicesLength = mesh.getTriangleCount() * 3;
        for (int i = 0; i < indicesLength; i++) {
            triangleIndexBase.putInt(indices.get(i));
        }
        vertices.rewind();
        vertices.clear();

        createShape();
    }
 
Example 17
Source File: RouteLocationIndicator.java    From open with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void render(GLViewport v) {
    GLState.useProgram(shader);
    GLState.blend(true);
    GLState.test(false, false);

    GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);

    FloatBuffer mVertices;
    final float[] mVerticesData = {
            -0.4f, 0.0f, 0.0f,
            -0.9f, 0.7f, 0.0f,
            1.0f, 0.0f, 0.0f,
            -0.9f, -0.7f, 0.0f,
    };

    mVertices = ByteBuffer.allocateDirect(mVerticesData.length * 4)
            .order(ByteOrder.nativeOrder()).asFloatBuffer();

    mVertices.clear();
    mVertices.put(mVerticesData);
    mVertices.flip();

    GL.glVertexAttribPointer(vertexPosition, 3, GL20.GL_FLOAT, false, 0, mVertices);

    GLState.enableVertexArrays(vertexPosition, -1);
    GL.glUniform1f(rotation, degrees);

    float scaleValue = SCALE_FACTOR * v.pos.getZoomLevel();
    if (scaleValue > MAX_SCALE) {
        scaleValue = MAX_SCALE;
    } else if (scaleValue < MIN_SCALE) {
        scaleValue = MIN_SCALE;
    }

    GL.glUniform1f(scale, scaleValue);

    double x = indicatorPosition.x - v.pos.x;
    double y = indicatorPosition.y - v.pos.y;
    double tileScale = Tile.SIZE * v.pos.scale;

    v.mvp.setTransScale((float) (x * tileScale), (float) (y * tileScale), 1);
    v.mvp.multiplyMM(v.viewproj, v.mvp);
    v.mvp.setAsUniform(matrixPosition);

    if (visible > 1) {
        GL.glDrawArrays(GL20.GL_TRIANGLE_FAN, 0, 4);
    }
}
 
Example 18
Source File: BufferUtils.java    From Ultraino with MIT License 3 votes vote down vote up
/**
 * Create a new FloatBuffer of the specified size.
 *
 * @param size
 *            required number of floats to store.
 * @return the new FloatBuffer
 */
public static FloatBuffer createFloatBuffer(int size) {
    FloatBuffer buf = allocator.allocate(4 * size).order(ByteOrder.nativeOrder()).asFloatBuffer();
    buf.clear();
    onBufferAllocated(buf);
    return buf;
}
 
Example 19
Source File: BufferUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Create a new FloatBuffer of the specified size.
 *
 * @param size
 *            required number of floats to store.
 * @return the new FloatBuffer
 */
public static FloatBuffer createFloatBuffer(int size) {
    FloatBuffer buf = allocator.allocate(4 * size).order(ByteOrder.nativeOrder()).asFloatBuffer();
    buf.clear();
    onBufferAllocated(buf);
    return buf;
}
 
Example 20
Source File: BufferUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Create a new FloatBuffer of the specified size.
 *
 * @param size
 *            required number of floats to store.
 * @return the new FloatBuffer
 */
public static FloatBuffer createFloatBuffer(int size) {
    FloatBuffer buf = ByteBuffer.allocateDirect(4 * size).order(ByteOrder.nativeOrder()).asFloatBuffer();
    buf.clear();
    onBufferAllocated(buf);
    return buf;
}