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


Java Mesh.clearBuffer方法代码示例

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


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

示例1: convertToList

import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public static void convertToList(Mesh mesh){
    IndexBuffer inBuf = mesh.getIndicesAsList();
    IndexBuffer outBuf = IndexBuffer.createIndexBuffer(mesh.getVertexCount(),
                                                       inBuf.size());

    for (int i = 0; i < inBuf.size(); i++){
        outBuf.put(i, inBuf.get(i));
    }

    mesh.clearBuffer(Type.Index);
    switch (mesh.getMode()){
        case LineLoop:
        case LineStrip:
            mesh.setMode(Mode.Lines);
            break;
        case TriangleStrip:
        case TriangleFan:
            mesh.setMode(Mode.Triangles);
            break;
        default:
            break;
    }
    if (outBuf instanceof IndexIntBuffer){
        mesh.setBuffer(Type.Index, 3, (IntBuffer)outBuf.getBuffer());
    }else{
        mesh.setBuffer(Type.Index, 3, (ShortBuffer)outBuf.getBuffer());
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:29,代码来源:WrappedIndexBuffer.java

示例2: optimize

import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public static void optimize(Mesh mesh, boolean toFixed){
        // update any data that need updating
        mesh.updateBound();
        mesh.updateCounts();

        // set all buffers into STATIC_DRAW mode
        mesh.setStatic();

        if (mesh.getBuffer(Type.Index) != null){
            // compress index buffer from UShort to UByte (if possible)
            FloatToFixed.compressIndexBuffer(mesh);

            // generate triangle strips stitched with degenerate tris
            generateStrips(mesh, false, false, 16, 0);
        }

        IntMap<VertexBuffer> bufs = mesh.getBuffers();
        for (Entry<VertexBuffer> entry : bufs){
            VertexBuffer vb = entry.getValue();
            if (vb == null || vb.getBufferType() == Type.Index)
                continue;

             if (vb.getFormat() == Format.Float){
                if (vb.getBufferType() == Type.Color){
                    // convert the color buffer to UByte
                    vb = FloatToFixed.convertToUByte(vb);
                    vb.setNormalized(true);
                }else if (toFixed){
                    // convert normals, positions, and texcoords
                    // to fixed-point (16.16)
                    vb = FloatToFixed.convertToFixed(vb);
//                    vb = FloatToFixed.convertToFloat(vb);
                }
                mesh.clearBuffer(vb.getBufferType());
                mesh.setBuffer(vb);
            }
        }
        mesh.setInterleaved();
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:40,代码来源:ModelConverter.java

示例3: compressIndexBuffer

import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public static void compressIndexBuffer(Mesh mesh){
    int vertCount = mesh.getVertexCount();
    VertexBuffer vb = mesh.getBuffer(Type.Index);
    Format targetFmt;
    if (vb.getFormat() == Format.UnsignedInt && vertCount <= 0xffff){
        if (vertCount <= 256)
            targetFmt = Format.UnsignedByte;
        else
            targetFmt = Format.UnsignedShort;
    }else if (vb.getFormat() == Format.UnsignedShort && vertCount <= 0xff){
        targetFmt = Format.UnsignedByte;
    }else{
        return;
    }

    IndexBuffer src = mesh.getIndexBuffer();
    Buffer newBuf = VertexBuffer.createBuffer(targetFmt, vb.getNumComponents(), src.size());

    VertexBuffer newVb = new VertexBuffer(Type.Index);
    newVb.setupData(vb.getUsage(), vb.getNumComponents(), targetFmt, newBuf);
    mesh.clearBuffer(Type.Index);
    mesh.setBuffer(newVb);

    IndexBuffer dst = mesh.getIndexBuffer();
    for (int i = 0; i < src.size(); i++){
        dst.put(i, src.get(i));
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:29,代码来源:FloatToFixed.java

示例4: doUndoTool

import com.jme3.scene.Mesh; //导入方法依赖的package包/类
@Override
protected void doUndoTool(AbstractSceneExplorerNode rootNode, Object undoObject) {
    Geometry geom = rootNode.getLookup().lookup(Geometry.class);
    if( undoObject instanceof Mesh){
        Mesh keptMesh = (Mesh)undoObject;
        geom.setMesh(keptMesh);
        geom.updateModelBound();
    }else{
        Mesh mesh = geom.getMesh();
        if (mesh != null) {
            mesh.clearBuffer(Type.Tangent);
        }
    }
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:15,代码来源:GenerateTangentsTool.java

示例5: writeColorBuffer

import com.jme3.scene.Mesh; //导入方法依赖的package包/类
private static void writeColorBuffer(List<VertexData> vertices, ColorRGBA[] cols, Mesh mesh) {
	FloatBuffer colors = BufferUtils.createFloatBuffer(vertices.size() * 4);
	colors.rewind();
	for (ColorRGBA color : cols) {
		colors.put(color.r);
		colors.put(color.g);
		colors.put(color.b);
		colors.put(color.a);
	}
	mesh.clearBuffer(Type.Color);
	mesh.setBuffer(Type.Color, 4, colors);
}
 
开发者ID:meltzow,项目名称:supernovae,代码行数:13,代码来源:SilentTangentBinormalGenerator.java

示例6: computeLodEntropy

import com.jme3.scene.Mesh; //导入方法依赖的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

示例7: generate

import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public static void generate(Mesh mesh, boolean approxTangents, boolean splitMirrored) {
	int[] index = new int[3];
	Vector3f[] v = new Vector3f[3];
	Vector2f[] t = new Vector2f[3];
	for (int i = 0; i < 3; i++) {
		v[i] = new Vector3f();
		t[i] = new Vector2f();
	}

	if (mesh.getBuffer(Type.Normal) == null) {
		throw new IllegalArgumentException("The given mesh has no normal data!");
	}

	List<VertexData> vertices;
	switch (mesh.getMode()) {
		case Triangles:
			vertices = processTriangles(mesh, index, v, t, splitMirrored);
			if (splitMirrored) {
				splitVertices(mesh, vertices, splitMirrored);
			}
			break;
		case TriangleStrip:
			vertices = processTriangleStrip(mesh, index, v, t);
			break;
		case TriangleFan:
			vertices = processTriangleFan(mesh, index, v, t);
			break;
		default:
			throw new UnsupportedOperationException(mesh.getMode() + " is not supported.");
	}

	processTriangleData(mesh, vertices, approxTangents, splitMirrored);

	// if the mesh has a bind pose, we need to generate the bind pose for the tangent buffer
	if (mesh.getBuffer(Type.BindPosePosition) != null) {

		VertexBuffer tangents = mesh.getBuffer(Type.Tangent);
		if (tangents != null) {
			VertexBuffer bindTangents = new VertexBuffer(Type.BindPoseTangent);
			bindTangents.setupData(Usage.CpuOnly, 4, Format.Float, BufferUtils.clone(tangents.getData()));

			if (mesh.getBuffer(Type.BindPoseTangent) != null) {
				mesh.clearBuffer(Type.BindPoseTangent);
			}
			mesh.setBuffer(bindTangents);
			tangents.setUsage(Usage.Stream);
		}
	}
}
 
开发者ID:meltzow,项目名称:supernovae,代码行数:50,代码来源:SilentTangentBinormalGenerator.java


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