com.jme3.util.BufferUtils Java Examples

The following examples show how to use com.jme3.util.BufferUtils. 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: PMDSkinData.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public PMDSkinData(DataInputStreamLittleEndian is) throws IOException {
//        PMDSkinVertData skinVertData[];
        skinName = is.readString(20);
//        System.out.println("skinName = "+skinName);
        skinVertCount = is.readInt();
        skinType = is.readByte();
//        System.out.println("skinVertCount = "+skinVertCount);
//        skinVertData = new PMDSkinVertData[skinVertCount];
//        for(int i=0;i<skinVertCount;i++) {
//            skinVertData[i] = new PMDSkinVertData(is);
//        }
        indexBuf = BufferUtils.createShortBuffer(skinVertCount);
        skinBuf = BufferUtils.createFloatBuffer(skinVertCount * 3);
        for(int i=0;i<skinVertCount;i++) {
            indexBuf.put((short)is.readInt());
            skinBuf.put(is.readFloat());
            skinBuf.put(is.readFloat());
            skinBuf.put(-is.readFloat());
        }
    }
 
Example #2
Source File: JmeBatchRenderBackend.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Batch() {
    // setup mesh
    vertexPos.setupData(Usage.Stream, 2, VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(BATCH_MAX_VERTICES * 2));
    vertexPosBuffer = (FloatBuffer) vertexPos.getData();
    mesh.setBuffer(vertexPos);

    vertexTexCoord.setupData(Usage.Stream, 2, VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(BATCH_MAX_VERTICES * 2));
    vertexTexCoordBuffer = (FloatBuffer) vertexTexCoord.getData();
    mesh.setBuffer(vertexTexCoord);

    vertexColor.setupData(Usage.Stream, 4, VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(BATCH_MAX_VERTICES * 4));
    vertexColorBuffer = (FloatBuffer) vertexColor.getData();
    mesh.setBuffer(vertexColor);

    indexBuffer.setupData(Usage.Stream, 3, VertexBuffer.Format.UnsignedShort, BufferUtils.createShortBuffer(BATCH_MAX_QUADS * 2 * 3));
    indexBufferBuffer = (ShortBuffer) indexBuffer.getData();
    mesh.setBuffer(indexBuffer);

    material = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    material.setBoolean("VertexColor", true);

    renderState.setDepthTest(false);
    renderState.setDepthWrite(false);
}
 
Example #3
Source File: Pose.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Applies the offsets of this pose to the vertex buffer given by the blend factor.
 *
 * @param blend Blend factor, 0 = no change to vertex buffer, 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);

        // acquire vertex
        BufferUtils.populateFromBuffer(tempVec2, vertbuf, vertIndex);

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

        // write modified vertex
        BufferUtils.setInBuffer(tempVec2, vertbuf, vertIndex);
    }
}
 
Example #4
Source File: Circle.java    From OpenRTS with MIT License 6 votes vote down vote up
protected void updateGeometry() {
	FloatBuffer positions = BufferUtils.createFloatBuffer(samples * 3);
	FloatBuffer normals = BufferUtils.createFloatBuffer(samples * 3);
	short[] indices = new short[samples * 2];

	float rate = FastMath.TWO_PI / samples;
	float angle = 0;
	for (int i = 0; i < samples; i++) {
		float x = FastMath.cos(angle) + center.x;
		float y = FastMath.sin(angle) + center.y;
		positions.put(x * radius).put(y * radius).put(center.z);
		normals.put(new float[] { 0, 1, 0 });
		indices[i * 2] = (short) i;
		indices[i * 2 + 1] = (short) ((i + 1) % samples);
		angle += rate;
	}

	setBuffer(Type.Position, 3, positions);
	setBuffer(Type.Normal, 3, normals);
	setBuffer(Type.Index, 2, indices);

	setBuffer(Type.TexCoord, 2, new float[] { 0, 0, 1, 1 });

	updateBound();
}
 
Example #5
Source File: EmitterMeshFaceShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void setMeshes(List<Mesh> meshes) {
    this.vertices = new ArrayList<List<Vector3f>>(meshes.size());
    this.normals = new ArrayList<List<Vector3f>>(meshes.size());
    for (Mesh mesh : meshes) {
        Vector3f[] vertexTable = BufferUtils.getVector3Array(mesh.getFloatBuffer(Type.Position));
        int[] indices = new int[3];
        List<Vector3f> vertices = new ArrayList<Vector3f>(mesh.getTriangleCount() * 3);
        List<Vector3f> normals = new ArrayList<Vector3f>(mesh.getTriangleCount());
        for (int i = 0; i < mesh.getTriangleCount(); ++i) {
            mesh.getTriangle(i, indices);
            vertices.add(vertexTable[indices[0]]);
            vertices.add(vertexTable[indices[1]]);
            vertices.add(vertexTable[indices[2]]);
            normals.add(FastMath.computeNormal(vertexTable[indices[0]], vertexTable[indices[1]], vertexTable[indices[2]]));
        }
        this.vertices.add(vertices);
        this.normals.add(normals);
    }
}
 
Example #6
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 #7
Source File: EmitterMeshFaceShape.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void setMeshes(List<Mesh> meshes) {
    this.vertices = new ArrayList<List<Vector3f>>(meshes.size());
    this.normals = new ArrayList<List<Vector3f>>(meshes.size());
    for (Mesh mesh : meshes) {
        Vector3f[] vertexTable = BufferUtils.getVector3Array(mesh.getFloatBuffer(Type.Position));
        int[] indices = new int[3];
        List<Vector3f> vertices = new ArrayList<Vector3f>(mesh.getTriangleCount() * 3);
        List<Vector3f> normals = new ArrayList<Vector3f>(mesh.getTriangleCount());
        for (int i = 0; i < mesh.getTriangleCount(); ++i) {
            mesh.getTriangle(i, indices);
            vertices.add(vertexTable[indices[0]]);
            vertices.add(vertexTable[indices[1]]);
            vertices.add(vertexTable[indices[2]]);
            normals.add(FastMath.computeNormal(vertexTable[indices[0]], vertexTable[indices[1]], vertexTable[indices[2]]));
        }
        this.vertices.add(vertices);
        this.normals.add(normals);
    }
}
 
Example #8
Source File: HullCollisionShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
     * Instantiate the configured shape in Bullet.
     */
    protected void createShape() {
//        ObjectArrayList<Vector3f> pointList = new ObjectArrayList<Vector3f>();
//        for (int i = 0; i < points.length; i += 3) {
//            pointList.add(new Vector3f(points[i], points[i + 1], points[i + 2]));
//        }
//        objectId = new ConvexHullShape(pointList);
//        objectId.setLocalScaling(Converter.convert(getScale()));
//        objectId.setMargin(margin);
        ByteBuffer bbuf=BufferUtils.createByteBuffer(points.length * 4); 
//        fbuf = bbuf.asFloatBuffer();
//        fbuf.rewind();
//        fbuf.put(points);
        for (int i = 0; i < points.length; i++) {
            float f = points[i];
            bbuf.putFloat(f);
        }
        bbuf.rewind();
        objectId = createShape(bbuf);
        Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId));
        setScale(scale);
        setMargin(margin);
    }
 
Example #9
Source File: MeshBuilder.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * @param materialNumber
 *            the material index
 * @return the vertices colors buffer or null if no vertex colors is set
 */
public ByteBuffer getVertexColorsBuffer(int materialNumber) {
    ByteBuffer result = null;
    if (verticesColors != null && vertexColorsMap.get(materialNumber) != null) {
        List<byte[]> data = vertexColorsMap.get(materialNumber);
        result = BufferUtils.createByteBuffer(4 * data.size());
        for (byte[] v : data) {
            if (v != null) {
                result.put(v[0]).put(v[1]).put(v[2]).put(v[3]);
            } else {
                result.put((byte) 0).put((byte) 0).put((byte) 0).put((byte) 0);
            }
        }
        result.flip();
    }
    return result;
}
 
Example #10
Source File: PaintTerrainToolControl.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Start making changes.
 */
@JmeThread
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);
}
 
Example #11
Source File: DebugShapeFactory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 *  Retrieves the vertices from the Triangle buffer.
 */
public FloatBuffer getVertices() {
    // There are 3 floats needed for each vertex (x,y,z)
    final int numberOfFloats = vertices.size() * 3;
    FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(numberOfFloats); 

    // Force the limit, set the cap - most number of floats we will use the buffer for
    verticesBuffer.limit(numberOfFloats);

    // Copy the values from the list to the direct float buffer
    for (Vector3f v : vertices) {
        verticesBuffer.put(v.x).put(v.y).put(v.z);
    }

    vertices.clear();
    return verticesBuffer;
}
 
Example #12
Source File: OpenRTSApplication.java    From OpenRTS with MIT License 6 votes vote down vote up
@Override
public void onAction(String name, boolean value, float tpf) {
	if (!value) {
		return;
	}

	if (name.equals("SIMPLEAPP_Exit")) {
		stop();
	} else if (name.equals("SIMPLEAPP_CameraPos")) {
		if (cam != null) {
			Vector3f loc = cam.getLocation();
			Quaternion rot = cam.getRotation();
			System.out.println("Camera Position: (" + loc.x + ", " + loc.y + ", " + loc.z + ")");
			System.out.println("Camera Rotation: " + rot);
			System.out.println("Camera Direction: " + cam.getDirection());
		}
	} else if (name.equals("SIMPLEAPP_Memory")) {
		BufferUtils.printCurrentDirectMemory(null);
	}
}
 
Example #13
Source File: Pose.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Applies the offsets of this pose to the vertex buffer given by the blend factor.
 *
 * @param blend Blend factor, 0 = no change to vertex buffer, 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);

        // acquire vertex
        BufferUtils.populateFromBuffer(tempVec2, vertbuf, vertIndex);

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

        // write modified vertex
        BufferUtils.setInBuffer(tempVec2, vertbuf, vertIndex);
    }
}
 
Example #14
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 #15
Source File: WireFrustum.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" 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 #16
Source File: CubeMapWrapper.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Inits the mip maps of a cube map with the given number of mip maps
 * @param nbMipMaps the number of mip maps to initialize
 */
public void initMipMaps(int nbMipMaps) {
    int maxMipMap = (int) (Math.log(image.getWidth()) / Math.log(2) + 1);
    if (nbMipMaps > maxMipMap) {
        throw new IllegalArgumentException("Max mip map number for a " + image.getWidth() + "x" + image.getHeight() + " cube map is " + maxMipMap);
    }

    sizes = new int[nbMipMaps];

    int totalSize = 0;
    for (int i = 0; i < nbMipMaps; i++) {
        int size = (int) pow(2, maxMipMap - 1 - i);
        sizes[i] = size * size * image.getFormat().getBitsPerPixel() / 8;
        totalSize += sizes[i];
    }
    
    image.setMipMapSizes(sizes);        
    image.getData().clear();
    for (int i = 0; i < 6; i++) {
        image.addData(BufferUtils.createByteBuffer(totalSize));
    }
    mipMapRaster = new MipMapImageRaster(image, 0);        
}
 
Example #17
Source File: WireSphere.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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();
    }
 
Example #18
Source File: FloatToFixed.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static void convertNormals(FloatBuffer input, ByteBuffer output){
    if (output.capacity() < input.capacity())
        throw new RuntimeException("Output must be at least as large as input!");

    input.clear();
    output.clear();
    Vector3f temp = new Vector3f();
    int vertexCount = input.capacity() / 3;
    for (int i = 0; i < vertexCount; i++){
        BufferUtils.populateFromBuffer(temp, input, i);

        // offset and scale vector into -128 ... 127
        temp.multLocal(127).addLocal(0.5f, 0.5f, 0.5f);

        // quantize
        byte v1 = (byte) temp.getX();
        byte v2 = (byte) temp.getY();
        byte v3 = (byte) temp.getZ();

        // store
        output.put(v1).put(v2).put(v3);
    }
}
 
Example #19
Source File: TextureAtlas.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a new atlas texture for the given map name.
 * @param mapName
 * @return the atlas texture
 */
public Texture getAtlasTexture(String mapName) {
    if (images == null) {
        return null;
    }
    byte[] image = images.get(mapName);
    if (image != null) {
        //TODO check if color space shouldn't be sRGB
        Texture2D tex = new Texture2D(new Image(format, atlasWidth, atlasHeight, BufferUtils.createByteBuffer(image), null, ColorSpace.Linear));
        tex.setMagFilter(Texture.MagFilter.Bilinear);
        tex.setMinFilter(Texture.MinFilter.BilinearNearestMipMap);
        tex.setWrap(Texture.WrapMode.EdgeClamp);
        return tex;
    }
    return null;
}
 
Example #20
Source File: MeshCollisionShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * De-serialize this shape, for example when loading from a J3O file.
 *
 * @param im importer (not null)
 * @throws IOException from importer
 */
@Override
public void read(final JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule capsule = im.getCapsule(this);
    this.numVertices = capsule.readInt(MeshCollisionShape.NUM_VERTICES, 0);
    this.numTriangles = capsule.readInt(MeshCollisionShape.NUM_TRIANGLES, 0);
    this.vertexStride = capsule.readInt(MeshCollisionShape.VERTEX_STRIDE, 0);
    this.triangleIndexStride = capsule.readInt(MeshCollisionShape.TRIANGLE_INDEX_STRIDE, 0);

    this.triangleIndexBase = BufferUtils.createByteBuffer(capsule.readByteArray(MeshCollisionShape.TRIANGLE_INDEX_BASE, null));
    this.vertexBase = BufferUtils.createByteBuffer(capsule.readByteArray(MeshCollisionShape.VERTEX_BASE, null));

    byte[] nativeBvh = capsule.readByteArray(MeshCollisionShape.NATIVE_BVH, null);
    memoryOptimized=nativeBvh != null;
    createShape(nativeBvh);
}
 
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: RenderDeviceJme.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" 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);

    // Load the 3 material types separately to avoid
    // reloading the shader when the defines change.

    // Material with a single color (no texture or vertex color)
    colorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");

    // Material with a texture and a color (no vertex color)
    textureColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");

    // Material with vertex color, used for gradients (no texture)
    vertexColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    vertexColorMaterial.setBoolean("VertexColor", true);

    // Shared render state for all materials
    renderState.setDepthTest(false);
    renderState.setDepthWrite(false);
}
 
Example #23
Source File: OculusViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void render() {

    // Calculate the render pose (translation/rotation) for each eye.
    // LibOVR takes the difference between this and the real position of each eye at display time
    // to apply AZW (timewarp).

    OVRPosef.Buffer hmdToEyeOffsets = OVRPosef.calloc(2);
    hmdToEyeOffsets.put(0, hardware.getEyePose(ovrEye_Left));
    hmdToEyeOffsets.put(1, hardware.getEyePose(ovrEye_Right));

    //calculate eye poses
    OVRUtil.ovr_CalcEyePoses(hardware.getHeadPose(), hmdToEyeOffsets, hardware.getLayer0().RenderPose());
    hmdToEyeOffsets.free();

    for (int eye = 0; eye < 2; eye++) {
        IntBuffer currentIndexB = BufferUtils.createIntBuffer(1);
        ovr_GetTextureSwapChainCurrentIndex(session(), hardware.getChain(eye), currentIndexB);
        int index = currentIndexB.get();

        // Constantly (each frame) rotating through a series of
        // frame buffers, so make sure we write into the correct one.
        (eye == ovrEye_Left ? leftViewPort : rightViewPort).setOutputFrameBuffer(hardware.getFramebuffers(eye)[index]);
    }

    // Now the game will render into the buffers given to us by LibOVR
}
 
Example #24
Source File: FloatToFixed.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static VertexBuffer convertToUByte(VertexBuffer vb){
    FloatBuffer fb = (FloatBuffer) vb.getData();
    ByteBuffer bb = BufferUtils.createByteBuffer(fb.capacity());
    convertToUByte(fb, bb);

    VertexBuffer newVb = new VertexBuffer(vb.getBufferType());
    newVb.setupData(vb.getUsage(),
                    vb.getNumComponents(),
                    Format.UnsignedByte,
                    bb);
    newVb.setNormalized(true);
    return newVb;
}
 
Example #25
Source File: GlfwMouseInputVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private long createGlfwCursor(JmeCursor jmeCursor) {
    GLFWImage glfwImage = new GLFWImage(BufferUtils.createByteBuffer(GLFWImage.SIZEOF));

    // TODO: currently animated cursors are not supported
    IntBuffer imageData = jmeCursor.getImagesData();
    ByteBuffer buf = BufferUtils.createByteBuffer(imageData.capacity() * 4);
    buf.asIntBuffer().put(imageData);

    glfwImage.set(jmeCursor.getWidth(), jmeCursor.getHeight(), buf);

    return glfwCreateCursor(glfwImage, jmeCursor.getXHotSpot(), jmeCursor.getYHotSpot());
}
 
Example #26
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 #27
Source File: MeshLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void startFaces(String count) throws SAXException {
    int numFaces = parseInt(count);
    int indicesPerFace = 0;

    switch (mesh.getMode()) {
        case Triangles:
            indicesPerFace = 3;
            break;
        case Lines:
            indicesPerFace = 2;
            break;
        case Points:
            indicesPerFace = 1;
            break;
        default:
            throw new SAXException("Strips or fans not supported!");
    }

    int numIndices = indicesPerFace * numFaces;

    vb = new VertexBuffer(VertexBuffer.Type.Index);
    if (!usesBigIndices) {
        sb = BufferUtils.createShortBuffer(numIndices);
        ib = null;
        vb.setupData(Usage.Static, indicesPerFace, Format.UnsignedShort, sb);
    } else {
        ib = BufferUtils.createIntBuffer(numIndices);
        sb = null;
        vb.setupData(Usage.Static, indicesPerFace, Format.UnsignedInt, ib);
    }
    mesh.setBuffer(vb);
}
 
Example #28
Source File: SkinMeshData.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void read(DataInputStream is, byte[] buf) throws IOException {
    skinvfbb = BufferUtil.read(is, buf);
    skinvfb = skinvfbb.asFloatBuffer();
    skinnfbb = BufferUtil.read(is, buf);
    skinnfb = skinnfbb.asFloatBuffer();
    if (is.readBoolean()) {
        skintfbb = BufferUtil.read(is, buf);
        skintfb = skintfbb.asFloatBuffer();
    }
    wfbb = BufferUtil.read(is, buf);
    wfb = wfbb.asFloatBuffer();
    skinbisbb = BufferUtil.read(is, buf);
    skinbisb = skinbisbb.asShortBuffer();
    int length = is.readInt();
    skinIndexArray = new int[length];
    for (int i = 0; i < length; i++) {
        skinIndexArray[i] = is.readInt();
    }
    int size = is.readInt();
    indexShortBufferMap = new HashMap<PMDMaterial, ShortBuffer>();
    for(int i=0;i<size;i++) {
        PMDMaterial mat = model.getMaterial()[is.readInt()];
        ShortBuffer sb = BufferUtil.read(is, buf).asShortBuffer();
        indexShortBufferMap.put(mat, sb);
    }
    skinvfb2 = BufferUtils.createFloatBuffer(skinvfb.capacity());
    skinvfb.position(0);
    skinvfb2.put(skinvfb);
}
 
Example #29
Source File: JmeBatchRenderBackend.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Texture2D createAtlasTextureInternal(final int width, final int height) throws Exception {
    ByteBuffer initialData = BufferUtils.createByteBuffer(width * height * 4);
    for (int i = 0; i < width * height * 4; i++) {
        initialData.put((byte) 0x00);
    }
    initialData.rewind();

    Texture2D texture = new Texture2D(new com.jme3.texture.Image(Format.RGBA8, width, height, initialData, ColorSpace.sRGB));
    texture.setMinFilter(MinFilter.NearestNoMipMaps);
    texture.setMagFilter(MagFilter.Nearest);
    return texture;
}
 
Example #30
Source File: ImageFlipper.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void flipImage(Image img, int index){
    if (img.getFormat().isCompressed())
        throw new UnsupportedOperationException("Flipping compressed " +
                                                "images is unsupported.");

    int w = img.getWidth();
    int h = img.getHeight();
    int halfH = h / 2;

    // bytes per pixel
    int bpp = img.getFormat().getBitsPerPixel() / 8;
    int scanline = w * bpp;

    ByteBuffer data = img.getData(index);
    ByteBuffer temp = BufferUtils.createByteBuffer(scanline);
    
    data.rewind();
    for (int y = 0; y < halfH; y++){
        int oppY = h - y - 1;
        // read in scanline
        data.position(y * scanline);
        data.limit(data.position() + scanline);

        temp.rewind();
        temp.put(data);

    }
}