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

The following examples show how to use java.nio.FloatBuffer#get() . 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: GeometrySimplifier.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
private boolean matchExactlyTheSame(GeometryData geometryDate, GeometryData d) {
	ByteBuffer bb1 = ByteBuffer.wrap(geometryDate.getVertices().getData());
	bb1.order(ByteOrder.LITTLE_ENDIAN);
	FloatBuffer buffer1 = bb1.asFloatBuffer();
	ByteBuffer bb2 = ByteBuffer.wrap(d.getVertices().getData());
	bb2.order(ByteOrder.LITTLE_ENDIAN);
	FloatBuffer buffer2 = bb2.asFloatBuffer();
	if (buffer1.capacity() != buffer2.capacity()) {
		return false;
	}
	for (int i=0; i<buffer1.capacity(); i++) {
		float a = buffer1.get();
		float b = buffer1.get();
		if (b != a) {
			return false;
		}
	}
	return true;
}
 
Example 2
Source File: Image.java    From JavaAV with GNU General Public License v2.0 6 votes vote down vote up
public static void copy(FloatBuffer srcBuf, int srcStep, FloatBuffer dstBuf, int dstStep) {
	int w = Math.min(srcStep, dstStep);
	int srcLine = srcBuf.position();
	int dstLine = dstBuf.position();

	while (srcLine < srcBuf.capacity() && dstLine < dstBuf.capacity()) {
		srcBuf.position(srcLine);
		dstBuf.position(dstLine);

		w = Math.min(Math.min(w, srcBuf.remaining()), dstBuf.remaining());

		for (int x = 0; x < w; x++) {
			float in = srcBuf.get();
			float out = in;

			dstBuf.put(out);
		}

		srcLine += srcStep;
		dstLine += dstStep;
	}
}
 
Example 3
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Vector2f[] getFrameBufferSamplePositions(FrameBuffer fb) {
    if (fb.getSamples() <= 1) {
        throw new IllegalArgumentException("Framebuffer must be multisampled");
    }
    if (!caps.contains(Caps.TextureMultisample)) {
        throw new RendererException("Multisampled textures are not supported");
    }

    setFrameBuffer(fb);

    Vector2f[] samplePositions = new Vector2f[fb.getSamples()];
    FloatBuffer samplePos = BufferUtils.createFloatBuffer(2);
    for (int i = 0; i < samplePositions.length; i++) {
        glext.glGetMultisample(GLExt.GL_SAMPLE_POSITION, i, samplePos);
        samplePos.clear();
        samplePositions[i] = new Vector2f(samplePos.get(0) - 0.5f,
                samplePos.get(1) - 0.5f);
    }
    return samplePositions;
}
 
Example 4
Source File: DMesh.java    From Lemur with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void morph( FloatBuffer sourcePos, FloatBuffer sourceNorms,
                      FloatBuffer targetPos, FloatBuffer targetNorms ) {
    if( deform == null )
        return;

    int count = sourcePos.limit() / 3;
    Vector3f v = new Vector3f();
    Vector3f normal = new Vector3f();

    for( int i = 0; i < count; i++ ) {
        v.x = sourcePos.get();
        v.y = sourcePos.get();
        v.z = sourcePos.get();
        normal.x = sourceNorms.get();
        normal.y = sourceNorms.get();
        normal.z = sourceNorms.get();

        morphVertex(v, normal);

        targetPos.put(v.x).put(v.y).put(v.z);
        targetNorms.put(normal.x).put(normal.y).put(normal.z);
    }
}
 
Example 5
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
}
 
Example 6
Source File: Object3DData.java    From react-native-3d-model-view with MIT License 5 votes vote down vote up
@Deprecated
public void centerScale()
/*
 * Position the model so it's center is at the origin, and scale it so its longest dimension is no bigger than
 * maxSize.
 */
{
	// calculate a scale factor
	float scaleFactor = 1.0f;
	float largest = modelDimensions.getLargest();
	// System.out.println("Largest dimension: " + largest);
	if (largest != 0.0f)
		scaleFactor = (1.0f / largest);
	Log.i("Object3DData","Scaling model with factor: " + scaleFactor+". Largest: "+largest);

	// get the model's center point
	Tuple3 center = modelDimensions.getCenter();
	Log.i("Object3DData","Objects actual position: " + center.toString());

	// modify the model's vertices
	float x0, y0, z0;
	float x, y, z;
	FloatBuffer vertexBuffer = getVertexBuffer() != null? getVertexBuffer() : getVertexArrayBuffer();
	for (int i = 0; i < vertexBuffer.capacity()/3; i++) {
		x0 = vertexBuffer.get(i*3);
		y0 = vertexBuffer.get(i*3+1);
		z0 = vertexBuffer.get(i*3+2);
		x = (x0 - center.getX()) * scaleFactor;
		vertexBuffer.put(i*3,x);
		y = (y0 - center.getY()) * scaleFactor;
		vertexBuffer.put(i*3+1,y);
		z = (z0 - center.getZ()) * scaleFactor;
		vertexBuffer.put(i*3+2,z);
	}
}
 
Example 7
Source File: FullMatrix.java    From jipes with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructs fully backed matrix with values from a CSV file.
 *
 * @param csvFile file
 * @param charset charset
 * @param separator seperator between values, usually ','
 * @param ignoreFirstLine whether the first line should be ignored (non-numerical headers)
 * @throws IOException
 */
public FullMatrix(final File csvFile, final String charset, final char separator, final boolean ignoreFirstLine) throws IOException {
    final CSVReader csvReader = new CSVReader();
    csvReader.read(csvFile, charset, separator, ignoreFirstLine);
    this.rows = csvReader.getRows();
    this.columns = csvReader.getColumns();
    final FloatBuffer floats = csvReader.getValues();
    this.buffer = new MatrixBackingBuffer() {
        @Override
        public void allocate(final int size) {
        }

        @Override
        public boolean isAllocated() {
            return true;
        }

        @Override
        public void set(final int index, final float value) {
            floats.put(index, value);
        }

        @Override
        public float get(final int index) {
            return floats.get(index);
        }
    };
}
 
Example 8
Source File: HullCollisionShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected float[] getPoints(Mesh mesh) {
    FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
    vertices.rewind();
    int components = mesh.getVertexCount() * 3;
    float[] pointsArray = new float[components];
    for (int i = 0; i < components; i += 3) {
        pointsArray[i] = vertices.get();
        pointsArray[i + 1] = vertices.get();
        pointsArray[i + 2] = vertices.get();
    }
    return pointsArray;
}
 
Example 9
Source File: PointCloud.java    From ParaViewTangoRecorder with Apache License 2.0 5 votes vote down vote up
public synchronized void UpdatePoints(byte[] byteArray, int pointCount) {
    FloatBuffer mPointCloudFloatBuffer;
    mPointCloudFloatBuffer = ByteBuffer.wrap(byteArray)
            .order(ByteOrder.nativeOrder()).asFloatBuffer();
    mPointCount = pointCount;
    mVertexBuffer.clear();
    mVertexBuffer.position(0);
    mVertexBuffer.put(mPointCloudFloatBuffer);
    float totalZ = 0;
    for (int i = 0; i < mPointCloudFloatBuffer.capacity() - 3; i = i + 3) {
        totalZ = totalZ + mPointCloudFloatBuffer.get(i + 2);
    }
    mAverageZ = totalZ / mPointCount;
}
 
Example 10
Source File: GImpactCollisionShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" 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.getIndicesAsList();
        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 11
Source File: MorphControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void mergeTargetBuffer(float[] array, float weight, FloatBuffer src, boolean init) {
    src.rewind();
    for (int j = 0; j < src.capacity(); j++) {
        if (init) {
            array[j] = 0;
        }
        array[j] += weight * src.get();
    }
}
 
Example 12
Source File: RawDataFileImpl.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized DataPoint[] readDataPoints(int ID) throws IOException {

    final Long currentOffset = dataPointsOffsets.get(ID);
    final Integer numOfDataPoints = dataPointsLengths.get(ID);

    if ((currentOffset == null) || (numOfDataPoints == null)) {
      throw new IllegalArgumentException("Unknown storage ID " + ID);
    }

    final int numOfBytes = numOfDataPoints * 2 * 4;

    if (buffer.capacity() < numOfBytes) {
      buffer = ByteBuffer.allocate(numOfBytes * 2);
    } else {
      // JDK 9 breaks compatibility with JRE8: need to cast
      // https://stackoverflow.com/questions/48693695/java-nio-buffer-not-loading-clear-method-on-runtime
      ((Buffer) buffer).clear();
    }

    dataPointsFile.seek(currentOffset);
    dataPointsFile.read(buffer.array(), 0, numOfBytes);

    FloatBuffer floatBuffer = buffer.asFloatBuffer();

    DataPoint dataPoints[] = new DataPoint[numOfDataPoints];

    for (int i = 0; i < numOfDataPoints; i++) {
      float mz = floatBuffer.get();
      float intensity = floatBuffer.get();
      dataPoints[i] = new SimpleDataPoint(mz, intensity);
    }

    return dataPoints;

  }
 
Example 13
Source File: GPUImageTransformFilter.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(final int textureId, final FloatBuffer cubeBuffer,
                   final FloatBuffer textureBuffer) {

    FloatBuffer vertBuffer = cubeBuffer;

    if (!ignoreAspectRatio) {

        float[] adjustedVertices = new float[8];

        cubeBuffer.position(0);
        cubeBuffer.get(adjustedVertices);

        float normalizedHeight = (float) getOutputHeight() / (float) getOutputWidth();
        adjustedVertices[1] *= normalizedHeight;
        adjustedVertices[3] *= normalizedHeight;
        adjustedVertices[5] *= normalizedHeight;
        adjustedVertices[7] *= normalizedHeight;

        vertBuffer = ByteBuffer.allocateDirect(adjustedVertices.length * 4)
                .order(ByteOrder.nativeOrder())
                .asFloatBuffer();

        vertBuffer.put(adjustedVertices).position(0);
    }

    super.onDraw(textureId, vertBuffer, textureBuffer);
}
 
Example 14
Source File: BufferUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 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 15
Source File: CachedPointFieldCalc.java    From Ultraino with MIT License 4 votes vote down vote up
public void initFieldConstantsOnlyForAmp(Renderer r){
    pre.reset();
    swap.reset(); tmp.reset();
    diffVec.reset(); diffVecS.reset();
    tPos.reset();
    nor.reset();
    
    final FloatBuffer positions = r.getPositions();
    final FloatBuffer specs = r.getSpecs();
    final FloatBuffer normals = r.getNormals();
   
    for(int i = 0; i < nTotalTrans; ++i){
        final int i3 = i*3;
        final int i4 = i*4;
        final float x,y,z;
        
        x = positions.get(i3+0); y = positions.get(i3+1); z = positions.get(i3+2);
        tPos.set(x , y , z);
        nor.set( normals.get(i3+0), normals.get(i3+1), normals.get(i3+2) );
        position.subtract(tPos, diffVec);
        float d = diffVec.length();
      
        float k = specs.get(i4 + 0);
        float kd = k*d;
        float cosKD = M.cos(kd);
        float sinKD = M.sin(kd);

        diffVecS.set(diffVec).multLocal(diffVec);
        float amp = specs.get(i4 + 1);
 
        //0 derivative
        swap.x =  cosKD;
        swap.y =  sinKD;
        swap.multLocal( amp / d );
        ka[i] = swap.x; kb[i] = swap.y;

        //directivity
        if (useDirectivity) {
            final float dir = calcDir(x, y, z, nor, k);
            ka[i] *= dir; kb[i] *= dir;
        }
                    
    }
    
    if(isReflector){
        for(int i = 0; i < nTrans; ++i){
            ka[i] +=  ka[i + nTrans]; 
            kb[i] +=  kb[i + nTrans];
        }
    }
    
}
 
Example 16
Source File: HitTester.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
public void display(final GLAutoDrawable drawable, final Matrix44f modelViewProjectionMatrix) {
    final GL3 gl = drawable.getGL().getGL3();
    if (needsResize) {
        gl.glBindRenderbuffer(GL3.GL_RENDERBUFFER, hitTestDepthBufferName[0]);
        gl.glRenderbufferStorage(GL3.GL_RENDERBUFFER, GL3.GL_DEPTH_COMPONENT32, width, height);

        gl.glBindRenderbuffer(GL3.GL_RENDERBUFFER, hitTestRboName[0]);
        gl.glRenderbufferStorage(GL3.GL_RENDERBUFFER, GL3.GL_R32F, width, height);

        gl.glBindRenderbuffer(GL3.GL_RENDERBUFFER, 0);
        needsResize = false;
    }
    if (!notificationQueues.isEmpty()) {
        final int x = hitTestRequest.getX();
        final int y = hitTestRequest.getY();

        //  Windows-DPI-Scaling
        //
        // If JOGL is ever fixed or another solution is found, either change
        // needsManualDPIScaling to return false (so there is effectively no
        // DPI scaling here) or to remove dpiScaleY below.            
        float dpiScaleY = 1.0f;
        if (GLTools.needsManualDPIScaling()) {
            dpiScaleY = parent.getDPIScaleY();
        }
        final int surfaceHeight = (int) (drawable.getSurfaceHeight() * dpiScaleY);

        // Allocate 3 floats for RGB values.
        FloatBuffer fbuf = Buffers.newDirectFloatBuffer(3);

        gl.glBindFramebuffer(GL3.GL_READ_FRAMEBUFFER, hitTestFboName[0]);
        gl.glReadBuffer(hitTestBufferName);
        gl.glReadPixels(x, surfaceHeight - y, 1, 1, GL3.GL_RGB, GL3.GL_FLOAT, fbuf);

        // There are enough colors in the buffer that we only need worry about
        // r component for now. That gives us 2**22 distinct values.
        final int r = (int) (fbuf.get(0));

        final int id;
        final HitType currentHitType;
        if (r == 0) {
            currentHitType = HitType.NO_ELEMENT;
            id = -1;
        } else {
            currentHitType = r > 0 ? HitType.VERTEX : HitType.TRANSACTION;
            id = r > 0 ? r - 1 : -r - 1;
        }

        final HitState hitState = hitTestRequest.getHitState();
        hitState.setCurrentHitId(id);
        hitState.setCurrentHitType(currentHitType);
        if (hitTestRequest.getFollowUpOperation() != null) {
            hitTestRequest.getFollowUpOperation().accept(hitState);
        }
        synchronized (this.notificationQueues) {
            while (!notificationQueues.isEmpty()) {
                final Queue<HitState> queue = notificationQueues.remove();
                if (queue != null) {
                    queue.add(hitState);
                }
            }
        }
    }
}
 
Example 17
Source File: BatchNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void doTransforms(FloatBuffer bindBufPos, FloatBuffer bindBufNorm, FloatBuffer bindBufTangents, FloatBuffer bufPos, FloatBuffer bufNorm, FloatBuffer bufTangents, int start, int end, Matrix4f transform) {
    TempVars vars = TempVars.get();
    Vector3f pos = vars.vect1;
    Vector3f norm = vars.vect2;
    Vector3f tan = vars.vect3;

    int length = (end - start) * 3;
    int tanLength = (end - start) * 4;

    // offset is given in element units
    // convert to be in component units
    int offset = start * 3;
    int tanOffset = start * 4;

    bindBufPos.rewind();
    bindBufPos.get(tmpFloat, 0, length);

    if (bindBufNorm != null) {
        bindBufNorm.rewind();
        bindBufNorm.get(tmpFloatN, 0, length);
    }

    if (bindBufTangents != null) {
        bindBufTangents.rewind();
        bindBufTangents.get(tmpFloatT, 0, tanLength);
    }

    int index = 0;
    int tanIndex = 0;
    int index1, index2, tanIndex1, tanIndex2;

    while (index < length) {
        index1 = index + 1;
        index2 = index + 2;

        pos.x = tmpFloat[index];
        pos.y = tmpFloat[index1];
        pos.z = tmpFloat[index2];
        transform.mult(pos, pos);
        tmpFloat[index] = pos.x;
        tmpFloat[index1] = pos.y;
        tmpFloat[index2] = pos.z;

        if (bindBufNorm != null) {
            norm.x = tmpFloatN[index];
            norm.y = tmpFloatN[index1];
            norm.z = tmpFloatN[index2];
            transform.multNormal(norm, norm);
            tmpFloatN[index] = norm.x;
            tmpFloatN[index1] = norm.y;
            tmpFloatN[index2] = norm.z;
        }

        index += 3;

        if (bindBufTangents != null) {
            tanIndex1 = tanIndex + 1;
            tanIndex2 = tanIndex + 2;
            tan.x = tmpFloatT[tanIndex];
            tan.y = tmpFloatT[tanIndex1];
            tan.z = tmpFloatT[tanIndex2];
            transform.multNormal(tan, tan);
            tmpFloatT[tanIndex] = tan.x;
            tmpFloatT[tanIndex1] = tan.y;
            tmpFloatT[tanIndex2] = tan.z;
            tanIndex += 4;
        }

    }
    vars.release();

    //using bulk put as it's faster
    bufPos.position(offset);
    bufPos.put(tmpFloat, 0, length);

    if (bindBufNorm != null) {
        bufNorm.position(offset);
        bufNorm.put(tmpFloatN, 0, length);
    }

    if (bindBufTangents != null) {
        bufTangents.position(tanOffset);
        bufTangents.put(tmpFloatT, 0, tanLength);
    }
}
 
Example 18
Source File: RagdollUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Enumerate vertices that meet the weight threshold for the indexed bone.
 *
 * @param mesh the mesh to analyze (not null)
 * @param boneIndex the index of the bone (&ge;0)
 * @param initialScale a scale applied to vertex positions (not null,
 * unaffected)
 * @param offset an offset subtracted from vertex positions (not null,
 * unaffected)
 * @param weightThreshold the minimum bone weight for inclusion in the
 * result (&ge;0, &le;1)
 * @return a new list of vertex coordinates (not null, length a multiple of
 * 3)
 */
private static List<Float> getPoints(Mesh mesh, int boneIndex, Vector3f initialScale, Vector3f offset, float weightThreshold) {

    FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
    VertexBuffer biBuf = mesh.getBuffer(VertexBuffer.Type.BoneIndex);
    Buffer boneIndices = biBuf.getDataReadOnly();
    FloatBuffer boneWeight = (FloatBuffer) mesh.getBuffer(Type.BoneWeight).getData();

    vertices.rewind();
    boneIndices.rewind();
    boneWeight.rewind();

    ArrayList<Float> results = new ArrayList<Float>();

    int vertexComponents = mesh.getVertexCount() * 3;

    for (int i = 0; i < vertexComponents; i += 3) {
        int k;
        boolean add = false;
        int start = i / 3 * 4;
        for (k = start; k < start + 4; k++) {
            if (readIndex(boneIndices, k) == boneIndex
                    && boneWeight.get(k) >= weightThreshold) {
                add = true;
                break;
            }
        }
        if (add) {

            Vector3f pos = new Vector3f();
            pos.x = vertices.get(i);
            pos.y = vertices.get(i + 1);
            pos.z = vertices.get(i + 2);
            pos.subtractLocal(offset).multLocal(initialScale);
            results.add(pos.x);
            results.add(pos.y);
            results.add(pos.z);

        }
    }

    return results;
}
 
Example 19
Source File: MeshConverter.java    From sciview with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static net.imagej.mesh.Mesh toImageJ( final graphics.scenery.Mesh scMesh ) {
    // Extract buffers from Scenery mesh.
    final FloatBuffer verts = scMesh.getVertices();
    final FloatBuffer vNormals = scMesh.getNormals();
    final FloatBuffer texCoords = scMesh.getTexcoords();
    final IntBuffer indices = scMesh.getIndices();

    // Compute the triangle normals.
    final FloatBuffer tNormals = //
            BufferUtils.allocateFloat( indices.capacity() );
    for( int i = 0; i < indices.position(); i += 3 ) {
        final int v0 = indices.get( i );
        final int v1 = indices.get( i + 1 );
        final int v2 = indices.get( i + 2 );

        final float v0x = verts.get( v0 );
        final float v0y = verts.get( v0 + 1 );
        final float v0z = verts.get( v0 + 2 );
        final float v1x = verts.get( v1 );
        final float v1y = verts.get( v1 + 1 );
        final float v1z = verts.get( v1 + 2 );
        final float v2x = verts.get( v2 );
        final float v2y = verts.get( v2 + 1 );
        final float v2z = verts.get( v2 + 2 );

        final float v10x = v1x - v0x;
        final float v10y = v1y - v0y;
        final float v10z = v1z - v0z;

        final float v20x = v2x - v0x;
        final float v20y = v2y - v0y;
        final float v20z = v2z - v0z;

        final float nx = v10y * v20z - v10z * v20y;
        final float ny = v10z * v20x - v10x * v20z;
        final float nz = v10x * v20y - v10y * v20x;

        tNormals.put( nx );
        tNormals.put( ny );
        tNormals.put( nz );
    }

    return new BufferMesh( verts, vNormals, texCoords, indices, tNormals );
}
 
Example 20
Source File: BufferUtils.java    From Ultraino with MIT License 2 votes vote down vote up
/**
 * Updates the values of the given vector from the specified buffer at the
 * index provided.
 *
 * @param vector
 *            the vector to set data on
 * @param buf
 *            the buffer to read from
 * @param index
 *            the position (in terms of vectors, not floats) to read from
 *            the buf
 */
public static void populateFromBuffer(Vector2f vector, FloatBuffer buf, int index) {
    vector.x = buf.get(index * 2);
    vector.y = buf.get(index * 2 + 1);
}