当前位置: 首页>>代码示例>>Java>>正文


Java BufferUtils.populateFromBuffer方法代码示例

本文整理汇总了Java中com.jme3.util.BufferUtils.populateFromBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java BufferUtils.populateFromBuffer方法的具体用法?Java BufferUtils.populateFromBuffer怎么用?Java BufferUtils.populateFromBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jme3.util.BufferUtils的用法示例。


在下文中一共展示了BufferUtils.populateFromBuffer方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: apply

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
/**
 * Applies the offsets of this pose to the vertex buffer given by the blend factor.
 *
 * @param blend Blend factor, 0 = no change to vert buf, 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);

        // aquire vert
        BufferUtils.populateFromBuffer(tempVec2, vertbuf, vertIndex);

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

        // write modified vert
        BufferUtils.setInBuffer(tempVec2, vertbuf, vertIndex);
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:24,代码来源:Pose.java

示例2: getTriangle

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
/**
 * Gets the triangle vertex positions at the given triangle index 
 * and stores them into the v1, v2, v3 arguments.
 * 
 * @param index The index of the triangle. 
 * Should be between 0 and {@link #getTriangleCount()}.
 * 
 * @param v1 Vector to contain first vertex position
 * @param v2 Vector to contain second vertex position
 * @param v3 Vector to contain third vertex position
 */
public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3){
    VertexBuffer pb = getBuffer(Type.Position);
    IndexBuffer ib = getIndicesAsList();
    if (pb != null && pb.getFormat() == Format.Float && pb.getNumComponents() == 3){
        FloatBuffer fpb = (FloatBuffer) pb.getData();

        // aquire triangle's vertex indices
        int vertIndex = index * 3;
        int vert1 = ib.get(vertIndex);
        int vert2 = ib.get(vertIndex+1);
        int vert3 = ib.get(vertIndex+2);

        BufferUtils.populateFromBuffer(v1, fpb, vert1);
        BufferUtils.populateFromBuffer(v2, fpb, vert2);
        BufferUtils.populateFromBuffer(v3, fpb, vert3);
    }else{
        throw new UnsupportedOperationException("Position buffer not set or "
                                              + " has incompatible format");
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:32,代码来源:Mesh.java

示例3: convertNormals

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:24,代码来源:FloatToFixed.java

示例4: convertTexCoords2D

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
private static void convertTexCoords2D(FloatBuffer input, Buffer output){
    if (output.capacity() < input.capacity())
        throw new RuntimeException("Output must be at least as large as input!");

    input.clear();
    output.clear();
    Vector2f temp = new Vector2f();
    int vertexCount = input.capacity() / 2;

    ShortBuffer sb = null;
    IntBuffer ib = null;

    if (output instanceof ShortBuffer)
        sb = (ShortBuffer) output;
    else if (output instanceof IntBuffer)
        ib = (IntBuffer) output;
    else
        throw new UnsupportedOperationException();

    for (int i = 0; i < vertexCount; i++){
        BufferUtils.populateFromBuffer(temp, input, i);

        if (sb != null){
            sb.put( (short) (temp.getX()*Short.MAX_VALUE) );
            sb.put( (short) (temp.getY()*Short.MAX_VALUE) );
        }else{
            int v1 = (int) (temp.getX() * ((float)(1 << 16)));
            int v2 = (int) (temp.getY() * ((float)(1 << 16)));
            ib.put(v1).put(v2);
        }
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:33,代码来源:FloatToFixed.java

示例5: getColor

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
public static ColorRGBA getColor( Geometry geom, Vector3f pt, int index, Tweed tweed ) {
		
		MatParam param = geom.getMaterial().getParam( "DiffuseMap" );
		
		ImageRaster ir = ImageRaster.create( tweed.getAssetManager().loadTexture( ((Texture2D)param.getValue()).getName() ).getImage() );
    	
		Mesh mesh = geom.getMesh();
//		geom.getMaterial().getMaterialDef().
		
        VertexBuffer pb = mesh.getBuffer(Type.Position);
        VertexBuffer tb = mesh.getBuffer( Type.TexCoord );
        
        IndexBuffer  ib = mesh.getIndicesAsList();
        
        Vector2f uva = new Vector2f(), uvb = new Vector2f(), uvc = new Vector2f();
        Vector3f la  = new Vector3f(), lb  = new Vector3f(), lc  = new Vector3f();
        
        if (pb != null && pb.getFormat() == Format.Float && pb.getNumComponents() == 3) {
        	
            FloatBuffer fpb = (FloatBuffer) pb.getData();
            FloatBuffer ftb = (FloatBuffer) tb.getData();

            // aquire triangle's vertex indices
            int vertIndex = index * 3;
            
            int va = ib.get(vertIndex);
            int vb = ib.get(vertIndex+1);
            int vc = ib.get(vertIndex+2);
            
            BufferUtils.populateFromBuffer( la, fpb, va );
            BufferUtils.populateFromBuffer( lb, fpb, vb );
            BufferUtils.populateFromBuffer( lc, fpb, vc );
            
            BufferUtils.populateFromBuffer( uva, ftb, va );
            BufferUtils.populateFromBuffer( uvb, ftb, vb );
            BufferUtils.populateFromBuffer( uvc, ftb, vc );
            
//            PaintThing.debug.put(1, new Line ( la.x, la.z, lb.x, lb.z) );
//            PaintThing.debug.put(2, new Line ( lb.x, lb.z, lc.x, lc.z) );
//            PaintThing.debug.put(3, new Line ( lc.x, lc.z, la.x, la.z) );
            
            float[] bary = barycentric( pt, la, lb, lc );
            
            int x = (int)( ( uva.x * bary[0] + uvb.x * bary[1] + uvc.x * bary[2] ) * ir.getWidth ()) ,
            	y = (int)( ( uva.y * bary[0] + uvb.y * bary[1] + uvc.y * bary[2] ) * ir.getHeight()) ;
            
            ColorRGBA out = ir.getPixel( x, y );//ir.getHeight() - y -1 );

//            for (Pair<Vector3f, Vector2f> pair : new Pair[]{ new Pair( la, uva), new Pair (lb, uvb), new Pair (lc, uvc)}) {
//            	
//            	int xx = (int)(pair.second().x * ir.getWidth () ),
//            	    yy = (int)(pair.second().y * ir.getHeight() );
//            	
//            	System.out.println("xx "+xx+" yy "+ yy );
//            	
//            	ColorRGBA o = ir.getPixel( 
//            			xx,
//            			yy );
//            	
//            	PaintThing.debug.put(1, new ColPt( pair.first().x, pair.first().z, o.r, o.g, o.b ));
//            }
            
//            System.out.println("<< "+ ((Texture2D)param.getValue()).getName());
//			System.out.println( x + " " + y + " :: " + bary[ 0 ] + " " + bary[ 1 ] + " " + bary[ 2 ] + 
//					" --> " + out.r + "," + out.g + "," + out.b );
            
            return out;
            
        }else{
        	
            throw new UnsupportedOperationException("Position buffer not set or has incompatible format");
        }
    }
 
开发者ID:twak,项目名称:chordatlas,代码行数:74,代码来源:SkelFootprint.java

示例6: orthogonalLineFit

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
public void orthogonalLineFit(FloatBuffer points) {
    if (points == null) {
        return;
    }

    TempVars vars = TempVars.get();

    Vector3f compVec1 = vars.vect1;
    Vector3f compVec2 = vars.vect2;
    Matrix3f compMat1 = vars.tempMat3;
    Eigen3f compEigen1 = vars.eigen;

    points.rewind();

    // compute average of points
    int length = points.remaining() / 3;

    BufferUtils.populateFromBuffer(origin, points, 0);
    for (int i = 1; i < length; i++) {
        BufferUtils.populateFromBuffer(compVec1, points, i);
        origin.addLocal(compVec1);
    }

    origin.multLocal(1f / (float) length);

    // compute sums of products
    float sumXX = 0.0f, sumXY = 0.0f, sumXZ = 0.0f;
    float sumYY = 0.0f, sumYZ = 0.0f, sumZZ = 0.0f;

    points.rewind();
    for (int i = 0; i < length; i++) {
        BufferUtils.populateFromBuffer(compVec1, points, i);
        compVec1.subtract(origin, compVec2);
        sumXX += compVec2.x * compVec2.x;
        sumXY += compVec2.x * compVec2.y;
        sumXZ += compVec2.x * compVec2.z;
        sumYY += compVec2.y * compVec2.y;
        sumYZ += compVec2.y * compVec2.z;
        sumZZ += compVec2.z * compVec2.z;
    }

    //find the smallest eigen vector for the direction vector
    compMat1.m00 = sumYY + sumZZ;
    compMat1.m01 = -sumXY;
    compMat1.m02 = -sumXZ;
    compMat1.m10 = -sumXY;
    compMat1.m11 = sumXX + sumZZ;
    compMat1.m12 = -sumYZ;
    compMat1.m20 = -sumXZ;
    compMat1.m21 = -sumYZ;
    compMat1.m22 = sumXX + sumYY;

    compEigen1.calculateEigen(compMat1);
    direction = compEigen1.getEigenVector(0);

    vars.release();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:58,代码来源:Line.java

示例7: computeLodEntropy

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
public static float computeLodEntropy(Mesh terrainBlock, IntBuffer lodIndices){
    // Bounding box for the terrain block
    BoundingBox bbox = (BoundingBox) terrainBlock.getBound();

    // Vertex positions for the block
    FloatBuffer positions = terrainBlock.getFloatBuffer(Type.Position);

    // Prepare to cast rays
    Vector3f pos = new Vector3f();
    Vector3f dir = new Vector3f(0, -1, 0);
    Ray ray = new Ray(pos, dir);

    // Prepare collision results
    CollisionResults results = new CollisionResults();

    // Set the LOD indices on the block
    VertexBuffer originalIndices = terrainBlock.getBuffer(Type.Index);

    terrainBlock.clearBuffer(Type.Index);
    terrainBlock.setBuffer(Type.Index, 3, lodIndices);

    // Recalculate collision mesh
    terrainBlock.createCollisionData();

    float entropy = 0;
    for (int i = 0; i < positions.capacity() / 3; i++){
        BufferUtils.populateFromBuffer(pos, positions, i);

        float realHeight = pos.y;

        pos.addLocal(0, bbox.getYExtent(), 0);
        ray.setOrigin(pos);

        results.clear();
        terrainBlock.collideWith(ray, Matrix4f.IDENTITY, bbox, results);

        if (results.size() > 0){
            Vector3f contactPoint = results.getClosestCollision().getContactPoint();
            float delta = Math.abs(realHeight - contactPoint.y);
            entropy = Math.max(delta, entropy);
        }
    }

    // Restore original indices
    terrainBlock.clearBuffer(Type.Index);
    terrainBlock.setBuffer(originalIndices);

    return entropy;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:50,代码来源:EntropyComputeUtil.java

示例8: containAABB

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
/**
 * <code>containAABB</code> creates a minimum-volume axis-aligned bounding
 * box of the points, then selects the smallest enclosing sphere of the box
 * with the sphere centered at the boxes center.
 * 
 * @param points
 *            the list of points.
 */
public void containAABB(FloatBuffer points) {
    if (points == null) {
        return;
    }

    points.rewind();
    if (points.remaining() <= 2) // we need at least a 3 float vector
    {
        return;
    }

    TempVars vars = TempVars.get();

    BufferUtils.populateFromBuffer(vars.vect1, points, 0);
    float minX = vars.vect1.x, minY = vars.vect1.y, minZ = vars.vect1.z;
    float maxX = vars.vect1.x, maxY = vars.vect1.y, maxZ = vars.vect1.z;

    for (int i = 1, len = points.remaining() / 3; i < len; i++) {
        BufferUtils.populateFromBuffer(vars.vect1, points, i);

        if (vars.vect1.x < minX) {
            minX = vars.vect1.x;
        } else if (vars.vect1.x > maxX) {
            maxX = vars.vect1.x;
        }

        if (vars.vect1.y < minY) {
            minY = vars.vect1.y;
        } else if (vars.vect1.y > maxY) {
            maxY = vars.vect1.y;
        }

        if (vars.vect1.z < minZ) {
            minZ = vars.vect1.z;
        } else if (vars.vect1.z > maxZ) {
            maxZ = vars.vect1.z;
        }
    }

    vars.release();

    center.set(minX + maxX, minY + maxY, minZ + maxZ);
    center.multLocal(0.5f);

    xExtent = maxX - center.x;
    yExtent = maxY - center.y;
    zExtent = maxZ - center.z;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:57,代码来源:BoundingBox.java

示例9: recurseMini

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
/**
 * Used from calcWelzl. This function recurses to calculate a minimum
 * bounding sphere a few points at a time.
 *
 * @param points
 *            The array of points to look through.
 * @param p
 *            The size of the list to be used.
 * @param b
 *            The number of points currently considering to include with the
 *            sphere.
 * @param ap
 *            A variable simulating pointer arithmatic from C++, and offset
 *            in <code>points</code>.
 */
private void recurseMini(FloatBuffer points, int p, int b, int ap) {
    TempVars vars = TempVars.get();

    Vector3f tempA = vars.vect1;
    Vector3f tempB = vars.vect2;
    Vector3f tempC = vars.vect3;
    Vector3f tempD = vars.vect4;

    switch (b) {
        case 0:
            this.radius = 0;
            this.center.set(0, 0, 0);
            break;
        case 1:
            this.radius = 1f - RADIUS_EPSILON;
            BufferUtils.populateFromBuffer(center, points, ap - 1);
            break;
        case 2:
            BufferUtils.populateFromBuffer(tempA, points, ap - 1);
            BufferUtils.populateFromBuffer(tempB, points, ap - 2);
            setSphere(tempA, tempB);
            break;
        case 3:
            BufferUtils.populateFromBuffer(tempA, points, ap - 1);
            BufferUtils.populateFromBuffer(tempB, points, ap - 2);
            BufferUtils.populateFromBuffer(tempC, points, ap - 3);
            setSphere(tempA, tempB, tempC);
            break;
        case 4:
            BufferUtils.populateFromBuffer(tempA, points, ap - 1);
            BufferUtils.populateFromBuffer(tempB, points, ap - 2);
            BufferUtils.populateFromBuffer(tempC, points, ap - 3);
            BufferUtils.populateFromBuffer(tempD, points, ap - 4);
            setSphere(tempA, tempB, tempC, tempD);
            vars.release();
            return;
    }
    for (int i = 0; i < p; i++) {
        BufferUtils.populateFromBuffer(tempA, points, i + ap);
        if (tempA.distanceSquared(center) - (radius * radius) > RADIUS_EPSILON - 1f) {
            for (int j = i; j > 0; j--) {
                BufferUtils.populateFromBuffer(tempB, points, j + ap);
                BufferUtils.populateFromBuffer(tempC, points, j - 1 + ap);
                BufferUtils.setInBuffer(tempC, points, j + ap);
                BufferUtils.setInBuffer(tempB, points, j - 1 + ap);
            }
            vars.release();
            recurseMini(points, i, b + 1, ap + 1);

        }
    }
    vars.release();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:69,代码来源:BoundingSphere.java

示例10: createCone

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
private static Mesh createCone(int radialSamples, float radius, float height) {
    Mesh cone = new Mesh();

    float fInvRS = 1.0f / radialSamples;

    // Generate points on the unit circle to be used in computing the mesh
    // points on a dome slice.
    float[] afSin = new float[radialSamples];
    float[] afCos = new float[radialSamples];
    for (int i = 0; i < radialSamples; i++) {
        float fAngle = FastMath.TWO_PI * fInvRS * i;
        afCos[i] = FastMath.cos(fAngle);
        afSin[i] = FastMath.sin(fAngle);
    }

    FloatBuffer vb = BufferUtils.createVector3Buffer(radialSamples + 2);
    cone.setBuffer(Type.Position, 3, vb);

    TempVars vars = TempVars.get();
    Vector3f tempVa = vars.vect1;

    for (int i = 0; i < radialSamples; i++) {
        Vector3f kRadial = tempVa.set(afCos[i], 0, afSin[i]);
        kRadial.mult(radius, tempVa);
        vb.put(tempVa.x).put(tempVa.y).put(tempVa.z);

        BufferUtils.populateFromBuffer(tempVa, vb, i);

    }
    vars.release();

    // top of the cone
    vb.put(0).put(height).put(0);
    // base of the cone
    vb.put(0).put(0).put(0);

    ShortBuffer ib = BufferUtils.createShortBuffer(3 * (radialSamples) * 2);
    cone.setBuffer(Type.Index, 3, ib);

    short top = (short) radialSamples;
    short bot = (short) (radialSamples + 1);

    for (int i = 0; i < radialSamples; i++) {
        short a = (short) i;
        short b = (short) ((i + 1) % radialSamples);
        ib.put(top);
        ib.put(b);
        ib.put(a);

        ib.put(a);
        ib.put(b);
        ib.put(bot);
    }

    cone.updateBound();

    return cone;
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:59,代码来源:SceneEditTool.java

示例11: createCone

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
public static Mesh createCone(int radialSamples, float radius, float height) {
    Mesh cone = new Mesh();

    float fInvRS = 1.0f / radialSamples;

    // Generate points on the unit circle to be used in computing the mesh
    // points on a dome slice.
    float[] afSin = new float[radialSamples];
    float[] afCos = new float[radialSamples];
    for (int i = 0; i < radialSamples; i++) {
        float fAngle = FastMath.TWO_PI * fInvRS * i;
        afCos[i] = FastMath.cos(fAngle);
        afSin[i] = FastMath.sin(fAngle);
    }

    FloatBuffer vb = BufferUtils.createVector3Buffer(radialSamples + 2);
    cone.setBuffer(VertexBuffer.Type.Position, 3, vb);

    TempVars vars = TempVars.get();
    Vector3f tempVa = vars.vect1;

    for (int i = 0; i < radialSamples; i++) {
        Vector3f kRadial = tempVa.set(afCos[i], 0, afSin[i]);
        kRadial.mult(radius, tempVa);
        vb.put(tempVa.x).put(tempVa.y).put(tempVa.z);

        BufferUtils.populateFromBuffer(tempVa, vb, i);

    }
    vars.release();

    // top of the cone
    vb.put(0).put(height).put(0);
    // base of the cone
    vb.put(0).put(0).put(0);

    ShortBuffer ib = BufferUtils.createShortBuffer(3 * (radialSamples) * 2);
    cone.setBuffer(VertexBuffer.Type.Index, 3, ib);

    short top = (short) radialSamples;
    short bot = (short) (radialSamples + 1);

    for (int i = 0; i < radialSamples; i++) {
        short a = (short) i;
        short b = (short) ((i + 1) % radialSamples);
        ib.put(top);
        ib.put(b);
        ib.put(a);

        ib.put(a);
        ib.put(b);
        ib.put(bot);
    }

    cone.updateBound();

    return cone;
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:59,代码来源:GeometryUtils.java

示例12: processTriangleStrip

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
private static List<VertexData> processTriangleStrip(Mesh mesh, int[] index, Vector3f[] v, Vector2f[] t) {
	IndexBuffer indexBuffer = mesh.getIndexBuffer();
	FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
	FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();

	List<VertexData> vertices = initVertexData(vertexBuffer.limit() / 3);

	index[0] = indexBuffer.get(0);
	index[1] = indexBuffer.get(1);

	populateFromBuffer(v[0], vertexBuffer, index[0]);
	populateFromBuffer(v[1], vertexBuffer, index[1]);

	populateFromBuffer(t[0], textureBuffer, index[0]);
	populateFromBuffer(t[1], textureBuffer, index[1]);

	for (int i = 2; i < indexBuffer.size(); i++) {
		index[2] = indexBuffer.get(i);
		BufferUtils.populateFromBuffer(v[2], vertexBuffer, index[2]);
		BufferUtils.populateFromBuffer(t[2], textureBuffer, index[2]);

		boolean isDegenerate = isDegenerateTriangle(v[0], v[1], v[2]);
		TriangleData triData = processTriangle(index, v, t);

		if (triData != null && !isDegenerate) {
			vertices.get(index[0]).triangles.add(triData);
			vertices.get(index[1]).triangles.add(triData);
			vertices.get(index[2]).triangles.add(triData);
		}

		Vector3f vTemp = v[0];
		v[0] = v[1];
		v[1] = v[2];
		v[2] = vTemp;

		Vector2f tTemp = t[0];
		t[0] = t[1];
		t[1] = t[2];
		t[2] = tTemp;

		index[0] = index[1];
		index[1] = index[2];
	}

	return vertices;
}
 
开发者ID:meltzow,项目名称:supernovae,代码行数:47,代码来源:SilentTangentBinormalGenerator.java


注:本文中的com.jme3.util.BufferUtils.populateFromBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。