com.jme3.scene.VertexBuffer Java Examples

The following examples show how to use com.jme3.scene.VertexBuffer. 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: GeometryBatchFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void printMesh(Mesh mesh) {
    for (int bufType = 0; bufType < Type.values().length; bufType++) {
        VertexBuffer outBuf = mesh.getBuffer(Type.values()[bufType]);
        if (outBuf == null) {
            continue;
        }

        System.out.println(outBuf.getBufferType() + ": ");
        for (int vert = 0; vert < outBuf.getNumElements(); vert++) {
            String str = "[";
            for (int comp = 0; comp < outBuf.getNumComponents(); comp++) {
                Object val = outBuf.getElementComponent(vert, comp);
                outBuf.setElementComponent(vert, comp, val);
                val = outBuf.getElementComponent(vert, comp);
                str += val;
                if (comp != outBuf.getNumComponents() - 1) {
                    str += ", ";
                }
            }
            str += "]";
            System.out.println(str);
        }
        System.out.println("------");
    }
}
 
Example #2
Source File: SkeletonInterBoneWire.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * The method updates the geometry according to the poitions of the bones.
 */
public void updateGeometry() {
    VertexBuffer vb = this.getBuffer(Type.Position);
    FloatBuffer posBuf = this.getFloatBuffer(Type.Position);
    posBuf.clear();
    for (int i = 0; i < skeleton.getBoneCount(); ++i) {
        Bone bone = skeleton.getBone(i);
        Vector3f parentTail = bone.getModelSpacePosition().add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i))));

        for (Bone child : bone.getChildren()) {
            Vector3f childHead = child.getModelSpacePosition();
            Vector3f v = childHead.subtract(parentTail);
            float pointDelta = v.length() / POINT_AMOUNT;
            v.normalizeLocal().multLocal(pointDelta);
            Vector3f pointPosition = parentTail.clone();
            for (int j = 0; j < POINT_AMOUNT; ++j) {
                posBuf.put(pointPosition.getX()).put(pointPosition.getY()).put(pointPosition.getZ());
                pointPosition.addLocal(v);
            }
        }
    }
    posBuf.flip();
    vb.updateData(posBuf);

    this.updateBound();
}
 
Example #3
Source File: SkeletonInterBoneWire.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates buffers for points. Each line has POINT_AMOUNT of points.
 * @param skeleton
 *            the skeleton that will be showed
 * @param boneLengths
 *            the lengths of the bones
 */
public SkeletonInterBoneWire(Skeleton skeleton, Map<Integer, Float> boneLengths) {
    this.skeleton = skeleton;

    for (Bone bone : skeleton.getRoots()) {
        this.countConnections(bone);
    }

    this.setMode(Mode.Points);
    this.boneLengths = boneLengths;

    VertexBuffer pb = new VertexBuffer(Type.Position);
    FloatBuffer fpb = BufferUtils.createFloatBuffer(POINT_AMOUNT * connectionsAmount * 3);
    pb.setupData(Usage.Stream, 3, Format.Float, fpb);
    this.setBuffer(pb);

    this.updateCounts();
}
 
Example #4
Source File: SkeletonPoints.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * The method updates the geometry according to the positions of the bones.
 */
public void updateGeometry() {
    VertexBuffer vb = this.getBuffer(Type.Position);
    FloatBuffer posBuf = this.getFloatBuffer(Type.Position);
    posBuf.clear();
    for (int i = 0; i < skeleton.getBoneCount(); ++i) {
        Bone bone = skeleton.getBone(i);
        Vector3f head = bone.getModelSpacePosition();

        posBuf.put(head.getX()).put(head.getY()).put(head.getZ());
        if (boneLengths != null) {
            Vector3f tail = head.add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i))));
            posBuf.put(tail.getX()).put(tail.getY()).put(tail.getZ());
        }
    }
    posBuf.flip();
    vb.updateData(posBuf);

    this.updateBound();
}
 
Example #5
Source File: FbxSkin.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void generateSkinning() {
	for(FbxMesh fbxMesh : toSkin) {
		if(fbxMesh.geometries == null)
			continue;
		Mesh firstMesh = fbxMesh.geometries.get(0).getMesh();
		int maxWeightsPerVert = generateBoneData(firstMesh, fbxMesh);
		for(int i = 0; i < fbxMesh.geometries.size(); ++i) {
			Mesh mesh = fbxMesh.geometries.get(i).getMesh();
			if(mesh != firstMesh) {
				mesh.setBuffer(firstMesh.getBuffer(VertexBuffer.Type.BoneWeight));
				mesh.setBuffer(firstMesh.getBuffer(VertexBuffer.Type.BoneIndex));
				mesh.setBuffer(firstMesh.getBuffer(VertexBuffer.Type.HWBoneWeight));
				mesh.setBuffer(firstMesh.getBuffer(VertexBuffer.Type.HWBoneIndex));
			}
			mesh.setMaxNumWeights(maxWeightsPerVert);
			mesh.generateBindPose(true);
		}
	}
}
 
Example #6
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 #7
Source File: SkeletonPoints.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a points with bone lengths data. If the data is supplied then the points will show both head and tail of each bone.
 * @param skeleton
 *            the skeleton that will be shown
 * @param boneLengths
 *            a map between the bone's index and the bone's length
 */
public SkeletonPoints(Skeleton skeleton, Map<Integer, Float> boneLengths) {
    this.skeleton = skeleton;
    this.setMode(Mode.Points);
    int pointsCount = skeleton.getBoneCount();

    if (boneLengths != null) {
        this.boneLengths = boneLengths;
        pointsCount *= 2;
    }

    VertexBuffer pb = new VertexBuffer(Type.Position);
    FloatBuffer fpb = BufferUtils.createFloatBuffer(pointsCount * 3);
    pb.setupData(Usage.Stream, 3, Format.Float, fpb);
    this.setBuffer(pb);

    this.updateCounts();

}
 
Example #8
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
    public void renderMesh(Mesh mesh, int lod, int count, VertexBuffer[] instanceData) {
        if (mesh.getVertexCount() == 0 || mesh.getTriangleCount() == 0 || count == 0) {
            return;
        }

        if (count > 1 && !caps.contains(Caps.MeshInstancing)) {
            throw new RendererException("Mesh instancing is not supported by the video hardware");
        }

        if (mesh.getLineWidth() != 1f && context.lineWidth != mesh.getLineWidth()) {
            gl.glLineWidth(mesh.getLineWidth());
            context.lineWidth = mesh.getLineWidth();
        }

        if (gl4 != null && mesh.getMode().equals(Mode.Patch)) {
            gl4.glPatchParameter(mesh.getPatchVertexCount());
        }
        statistics.onMeshDrawn(mesh, lod, count);
//        if (ctxCaps.GL_ARB_vertex_array_object){
//            renderMeshVertexArray(mesh, lod, count);
//        }else{
        renderMeshDefault(mesh, lod, count, instanceData);
//        }
    }
 
Example #9
Source File: TerrainPatch.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void setHeight(List<LocationHeight> locationHeights, boolean overrideHeight) {

        final float[] heightArray = geomap.getHeightArray();
        final VertexBuffer vertexBuffer = mesh.getBuffer(Type.Position);
        final FloatBuffer floatBuffer = mesh.getFloatBuffer(Type.Position);

        for (LocationHeight lh : locationHeights) {

            if (lh.x < 0 || lh.z < 0 || lh.x >= size || lh.z >= size) {
                continue;
            }

            int idx = lh.z * size + lh.x;

            if (overrideHeight) {
                heightArray[idx] = lh.h;
            } else {
                float currentHeight = floatBuffer.get(idx * 3 + 1);
                heightArray[idx] = currentHeight + lh.h;
            }
        }

        floatBuffer.clear();
        geomap.writeVertexArray(floatBuffer, stepScale, false);
        vertexBuffer.setUpdateNeeded();
    }
 
Example #10
Source File: WireFrustum.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
}
 
Example #11
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void updateBufferData(VertexBuffer vb) {
    int bufId = vb.getId();
    if (bufId == -1) {
        // create buffer
        gl.glGenBuffers(1, ib1);
        bufId = ib1.get(0);
        vb.setId(bufId);
        objManager.registerForCleanup(vb);
    }

    int target;
    if (vb.getBufferType() == VertexBuffer.Type.Index) {
        target = gl.GL_ELEMENT_ARRAY_BUFFER;
        if (context.boundElementArrayVBO != bufId) {
            gl.glBindBuffer(target, bufId);
            context.boundElementArrayVBO = bufId;
        }
    } else {
        target = gl.GL_ARRAY_BUFFER;
        if (context.boundArrayVBO != bufId) {
            gl.glBindBuffer(target, bufId);
            context.boundArrayVBO = bufId;
        }
    }

    int usage = convertUsage(vb.getUsage());
    Buffer data = vb.getData();
    data.rewind();

    gl.glBufferData(target,
            data.capacity() * vb.getFormat().getComponentSize(),
            data,
            usage);

    vb.clearUpdateNeeded();
}
 
Example #12
Source File: RenderManager.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Preloads a scene for rendering.
 * <p>
 * After invocation of this method, the underlying
 * renderer would have uploaded any textures, shaders and meshes
 * used by the given scene to the video driver. 
 * Using this method is useful when wishing to avoid the initial pause
 * when rendering a scene for the first time. Note that it is not 
 * guaranteed that the underlying renderer will actually choose to upload
 * the data to the GPU so some pause is still to be expected.
 * 
 * @param scene The scene to preload
 */
public void preloadScene(Spatial scene) {
    if (scene instanceof Node) {
        // recurse for all children
        Node n = (Node) scene;
        List<Spatial> children = n.getChildren();
        for (int i = 0; i < children.size(); i++) {
            preloadScene(children.get(i));
        }
    } else if (scene instanceof Geometry) {
        // add to the render queue
        Geometry gm = (Geometry) scene;
        if (gm.getMaterial() == null) {
            throw new IllegalStateException("No material is set for Geometry: " + gm.getName());
        }

        gm.getMaterial().preload(this);
        Mesh mesh = gm.getMesh();
        if (mesh != null) {
            for (Entry<VertexBuffer> entry : mesh.getBuffers()) {
                VertexBuffer buf = entry.getValue();
                if (buf.getData() != null) {
                    renderer.updateBufferData(buf);
                }
            }
        }
    }
}
 
Example #13
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void deleteBuffer(VertexBuffer vb) {
    int bufId = vb.getId();
    if (bufId != -1) {
        // delete buffer
        intBuf1.put(0, bufId);
        intBuf1.position(0).limit(1);
        if (verboseLogging) {
            logger.info("GLES20.glDeleteBuffers(1, buffer)");
        }

        GLES20.glDeleteBuffers(1, intBuf1);
        vb.resetObject();
    }
}
 
Example #14
Source File: RenderDeviceJme.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public RenderDeviceJme(NiftyJmeDisplay display){
    this.display = display;

    quadColor = new VertexBuffer(Type.Color);
    quadColor.setNormalized(true);
    ByteBuffer bb = BufferUtils.createByteBuffer(4 * 4);
    quadColor.setupData(Usage.Stream, 4, Format.UnsignedByte, bb);
    quad.setBuffer(quadColor);

    quadModTC.setUsage(Usage.Stream);

    niftyMat = new Material(display.getAssetManager(), "Common/MatDefs/Nifty/Nifty.j3md");
    niftyMat.getAdditionalRenderState().setDepthTest(false);
}
 
Example #15
Source File: PoseTrack.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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());
}
 
Example #16
Source File: AbstractRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void clearVertexAttribs() {
    for (int i = 0; i < 16; i++) {
        VertexBuffer vb = context.boundAttribs[i];
        if (vb != null) {
            int arrayType = convertArrayType(vb.getBufferType());               
            disableClientState(arrayType);
            context.boundAttribs[vb.getBufferType().ordinal()] = null;
        }
    }
}
 
Example #17
Source File: AbstractRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void deleteBuffer(VertexBuffer vb) {
    int bufId = vb.getId();
    if (bufId != -1) {
        // delete buffer
        intBuf1.put(0, bufId);
        intBuf1.position(0).limit(1);
        deleteBuffer();
        vb.resetObject();
    }
}
 
Example #18
Source File: Arrow.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
     * Sets the arrow's extent.
     * This will modify the buffers on the mesh.
     * 
     * @param extent the arrow's extent.
     */
    public void setArrowExtent(Vector3f extent) {
        float len = extent.length();
//        Vector3f dir = extent.normalize();

        tempQuat.lookAt(extent, Vector3f.UNIT_Y);
        tempQuat.normalizeLocal();

        VertexBuffer pvb = getBuffer(Type.Position);
        FloatBuffer buffer = (FloatBuffer)pvb.getData(); 
        buffer.rewind();
        for (int i = 0; i < positions.length; i += 3) {
            Vector3f vec = tempVec.set(positions[i],
                    positions[i + 1],
                    positions[i + 2]);
            vec.multLocal(len);
            tempQuat.mult(vec, vec);

            buffer.put(vec.x);
            buffer.put(vec.y);
            buffer.put(vec.z);
        }
        
        pvb.updateData(buffer);

        updateBound();
        updateCounts();
    }
 
Example #19
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 #20
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 #21
Source File: FloatToFixed.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #22
Source File: Arrow.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
     * Sets the arrow's extent.
     * This will modify the buffers on the mesh.
     * 
     * @param extent the arrow's extent.
     */
    public void setArrowExtent(Vector3f extent) {
        float len = extent.length();
//        Vector3f dir = extent.normalize();

        tempQuat.lookAt(extent, Vector3f.UNIT_Y);
        tempQuat.normalizeLocal();

        VertexBuffer pvb = getBuffer(Type.Position);
        FloatBuffer buffer = (FloatBuffer)pvb.getData(); 
        buffer.rewind();
        for (int i = 0; i < positions.length; i += 3) {
            Vector3f vec = tempVec.set(positions[i],
                    positions[i + 1],
                    positions[i + 2]);
            vec.multLocal(len);
            tempQuat.mult(vec, vec);

            buffer.put(vec.x);
            buffer.put(vec.y);
            buffer.put(vec.z);
        }
        
        pvb.updateData(buffer);

        updateBound();
        updateCounts();
    }
 
Example #23
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void renderMesh(Mesh mesh, int lod, int count) {
    GL gl = GLContext.getCurrentGL();
    if (context.pointSize != mesh.getPointSize()) {
        gl.getGL2().glPointSize(mesh.getPointSize());
        context.pointSize = mesh.getPointSize();
    }
    if (context.lineWidth != mesh.getLineWidth()) {
        gl.glLineWidth(mesh.getLineWidth());
        context.lineWidth = mesh.getLineWidth();
    }

    checkTexturingUsed();

    if (vbo) {
        renderMeshVBO(mesh, lod, count);
    }
    else {
        boolean dynamic = false;
        if (mesh.getNumLodLevels() == 0) {
            IntMap<VertexBuffer> bufs = mesh.getBuffers();
            for (Entry<VertexBuffer> entry : bufs) {
                if (entry.getValue().getUsage() != VertexBuffer.Usage.Static) {
                    dynamic = true;
                    break;
                }
            }
        }
        else {
            dynamic = true;
        }

        if (!dynamic) {
            // dealing with a static object, generate display list
            renderMeshDisplayList(mesh);
        }
        else {
            renderMeshDefault(mesh, lod, count);
        }
    }
}
 
Example #24
Source File: SilentTangentBinormalGenerator.java    From OpenRTS with MIT License 5 votes vote down vote up
private static void bulkPut(VertexBuffer.Format format, Buffer buf1, Buffer buf2) {
	switch (format) {
		case Byte:
		case Half:
		case UnsignedByte:
			((ByteBuffer) buf1).put((ByteBuffer) buf2);
			break;
		case Short:
		case UnsignedShort:

			((ShortBuffer) buf1).put((ShortBuffer) buf2);
			break;

		case Int:
		case UnsignedInt:
			((IntBuffer) buf1).put((IntBuffer) buf2);
			break;
		case Float:

			((FloatBuffer) buf1).put((FloatBuffer) buf2);
			break;
		case Double:
			((DoubleBuffer) buf1).put((DoubleBuffer) buf2);
			break;

		default:
			throw new UnsupportedOperationException("Unrecoginized buffer format: " + format);
	}
}
 
Example #25
Source File: ParticleTriMesh.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setImagesXY(int imagesX, int imagesY) {
    this.imagesX = imagesX;
    this.imagesY = imagesY;
    if (imagesX != 1 || imagesY != 1){
        uniqueTexCoords = true;
        getBuffer(VertexBuffer.Type.TexCoord).setUsage(Usage.Stream);
    }
}
 
Example #26
Source File: PMDLoaderGLSLSkinning2.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
PMDSkinMesh createSkinMesh(PMDMaterial pmdMaterial) {
        boolean textureFlag = true;
        if (pmdMaterial.getTextureFileName().length() == 0) {
            textureFlag = false;
        }
        PMDSkinMesh mesh = new PMDSkinMesh();
        mesh.setMode(Mesh.Mode.Triangles);
        mesh.setBuffer(skinvb);
        mesh.setSkinvb2(skinvb2);
        mesh.setBuffer(skinnb);
//        mesh.setSkinnb2(skinnb2);
        if (textureFlag) {
            mesh.setBuffer(skintb);
        }
        mesh.setBuffer(skinbib);
        mesh.setBuffer(skinwb);
        VertexBuffer ib = new VertexBuffer(VertexBuffer.Type.Index);
        ShortBuffer isb = meshConverter.getSkinMeshData().indexShortBufferMap.get(pmdMaterial);
        ib.setupData(VertexBuffer.Usage.Static, 1, VertexBuffer.Format.UnsignedShort, isb);
        mesh.setBuffer(ib);
        mesh.setBoneIndexArray(skinIndexArray);
        ShortBuffer boneIndexBuffer = BufferUtils.createShortBuffer(skinIndexArray.length);
        for(int i=0;i<skinIndexArray.length;i++) {
            boneIndexBuffer.put((short)skinIndexArray[i]);
        }
        mesh.setBoneIndexBuffer(boneIndexBuffer);
        mesh.setBoneMatrixArray(new Matrix4f[skinIndexArray.length]);
        for (int i = 0; i < mesh.getBoneMatrixArray().length; i++) {
            mesh.getBoneMatrixArray()[i] = new Matrix4f();
            mesh.getBoneMatrixArray()[i].loadIdentity();
        }
        FloatBuffer boneMatrixBuffer = BufferUtils.createFloatBuffer(skinIndexArray.length * 16);
        mesh.setBoneMatrixBuffer(boneMatrixBuffer);
        return mesh;
    }
 
Example #27
Source File: MikkTSpaceImpl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void getPosition(float[] posOut, int face, int vert) {
    int vertIndex = getIndex(face, vert);
    VertexBuffer position = mesh.getBuffer(VertexBuffer.Type.Position);
    FloatBuffer pos = (FloatBuffer) position.getData();
    pos.position(vertIndex * 3);
    posOut[0] = pos.get();
    posOut[1] = pos.get();
    posOut[2] = pos.get();
}
 
Example #28
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void deleteBuffer(VertexBuffer vb) {
    int bufId = vb.getId();
    if (bufId != -1) {
        // delete buffer
        intBuf1.put(0, bufId);
        intBuf1.position(0).limit(1);
        glDeleteBuffers(intBuf1);
        vb.resetObject();
        
        //statistics.onDeleteVertexBuffer();
    }
}
 
Example #29
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 #30
Source File: LodGenerator.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void build() {
    BoundingSphere bs = new BoundingSphere();
    bs.computeFromPoints(mesh.getFloatBuffer(VertexBuffer.Type.Position));
    meshBoundingSphereRadius = bs.getRadius();
    List<Vertex> vertexLookup = new ArrayList<Vertex>();
    initialize();
    
    gatherVertexData(mesh, vertexLookup);
    gatherIndexData(mesh, vertexLookup);
    computeCosts();
   // assert (assertValidMesh());
    
}