Java Code Examples for com.jme3.scene.VertexBuffer#Type

The following examples show how to use com.jme3.scene.VertexBuffer#Type . 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: RagUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Copy Vector3f data for the indexed vertex from the specified vertex
 * buffer.
 * <p>
 * A software skin update is required BEFORE reading vertex
 * positions/normals/tangents from an animated mesh
 *
 * @param mesh subject mesh (not null)
 * @param bufferType which buffer to read (5 legal values)
 * @param vertexIndex index into the mesh's vertices (&ge;0)
 * @param storeResult (modified if not null)
 * @return the data vector (either storeResult or a new instance)
 */
private static Vector3f vertexVector3f(Mesh mesh,
        VertexBuffer.Type bufferType, int vertexIndex,
        Vector3f storeResult) {
    assert bufferType == VertexBuffer.Type.BindPoseNormal
            || bufferType == VertexBuffer.Type.BindPosePosition
            || bufferType == VertexBuffer.Type.Binormal
            || bufferType == VertexBuffer.Type.Normal
            || bufferType == VertexBuffer.Type.Position : bufferType;
    if (storeResult == null) {
        storeResult = new Vector3f();
    }

    VertexBuffer vertexBuffer = mesh.getBuffer(bufferType);
    FloatBuffer floatBuffer = (FloatBuffer) vertexBuffer.getDataReadOnly();
    floatBuffer.position(3 * vertexIndex);
    storeResult.x = floatBuffer.get();
    storeResult.y = floatBuffer.get();
    storeResult.z = floatBuffer.get();

    return storeResult;
}
 
Example 2
Source File: TestIssue1004.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    String sinbadPath = "Models/Sinbad/SinbadOldAnim.j3o";
    Node sinbad = (Node) assetManager.loadModel(sinbadPath);

    Geometry geometry = (Geometry) sinbad.getChild(0);
    Mesh mesh = geometry.getMesh();
    VertexBuffer.Type bufferType = VertexBuffer.Type.BoneIndex;
    VertexBuffer vertexBuffer = mesh.getBuffer(bufferType);

    // Remove the existing bone-index buffer.
    mesh.getBufferList().remove(vertexBuffer);
    mesh.getBuffers().remove(bufferType.ordinal());

    // Copy the 8-bit bone indices to 16-bit indices.
    ByteBuffer oldBuffer = (ByteBuffer) vertexBuffer.getDataReadOnly();
    int numComponents = oldBuffer.limit();
    oldBuffer.rewind();
    short[] shortArray = new short[numComponents];
    for (int index = 0; oldBuffer.hasRemaining(); ++index) {
        shortArray[index] = oldBuffer.get();
    }

    // Add the 16-bit bone indices to the mesh.
    mesh.setBuffer(bufferType, 4, shortArray);

    KinematicRagdollControl ragdoll = new KinematicRagdollControl(0.5f);
    sinbad.addControl(ragdoll);

    stop();
}
 
Example 3
Source File: Shader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Attribute getAttribute(VertexBuffer.Type attribType){
    int ordinal = attribType.ordinal();
    Attribute attrib = attribs.get(ordinal);
    if (attrib == null){
        attrib = new Attribute();
        attrib.name = attribType.name();
        attribs.put(ordinal, attrib);
    }
    return attrib;
}
 
Example 4
Source File: MorphTarget.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void write(JmeExporter ex) throws IOException {
    OutputCapsule oc = ex.getCapsule(this);
    for (Map.Entry<VertexBuffer.Type, FloatBuffer> entry : buffers.entrySet()) {
        Buffer roData = entry.getValue().asReadOnlyBuffer();
        oc.write((FloatBuffer) roData, entry.getKey().name(),null);
    }
    oc.write(name, "morphName", null);
}
 
Example 5
Source File: MorphTarget.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void read(JmeImporter im) throws IOException {
    InputCapsule ic = im.getCapsule(this);
    for (VertexBuffer.Type type : VertexBuffer.Type.values()) {
        FloatBuffer b = ic.readFloatBuffer(type.name(), null);
        if(b!= null){
            setBuffer(type, b);
        }
    }
    name = ic.readString("morphName", null);
}
 
Example 6
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int convertArrayType(VertexBuffer.Type type) {
    switch (type) {
        case Position:
            return gl.GL_VERTEX_ARRAY;
        case Normal:
            return gl.GL_NORMAL_ARRAY;
        case TexCoord:
            return gl.GL_TEXTURE_COORD_ARRAY;
        case Color:
            return gl.GL_COLOR_ARRAY;
        default:
            return -1; // unsupported
    }
}
 
Example 7
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected int convertArrayType(VertexBuffer.Type type) {
    switch (type) {
        case Position:
            return GLPointerFunc.GL_VERTEX_ARRAY;
        case Normal:
            return GLPointerFunc.GL_NORMAL_ARRAY;
        case TexCoord:
            return GLPointerFunc.GL_TEXTURE_COORD_ARRAY;
        case Color:
            return GLPointerFunc.GL_COLOR_ARRAY;
        default:
            return -1; // unsupported
    }
}
 
Example 8
Source File: Shader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Attribute getAttribute(VertexBuffer.Type attribType){
    int ordinal = attribType.ordinal();
    Attribute attrib = attribs.get(ordinal);
    if (attrib == null){
        attrib = new Attribute();
        attrib.name = attribType.name();
        attribs.put(ordinal, attrib);
    }
    return attrib;
}
 
Example 9
Source File: MorphTarget.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setBuffer(VertexBuffer.Type type, FloatBuffer buffer) {
    buffers.put(type, buffer);
}
 
Example 10
Source File: MorphTarget.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public FloatBuffer getBuffer(VertexBuffer.Type type) {
    return buffers.get(type);
}
 
Example 11
Source File: MorphTarget.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public EnumMap<VertexBuffer.Type, FloatBuffer> getBuffers() {
    return buffers;
}
 
Example 12
Source File: AbstractRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License votes vote down vote up
protected abstract int convertArrayType(VertexBuffer.Type type);