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


Java IndexBuffer类代码示例

本文整理汇总了Java中com.jme3.scene.mesh.IndexBuffer的典型用法代码示例。如果您正苦于以下问题:Java IndexBuffer类的具体用法?Java IndexBuffer怎么用?Java IndexBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: initTriList

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
private void initTriList(FloatBuffer vb, IndexBuffer ib) {
    pointData = new float[numTris * 3 * 3];
    int p = 0;
    for (int i = 0; i < numTris * 3; i += 3) {
        int vert = ib.get(i) * 3;
        pointData[p++] = vb.get(vert++);
        pointData[p++] = vb.get(vert++);
        pointData[p++] = vb.get(vert);

        vert = ib.get(i + 1) * 3;
        pointData[p++] = vb.get(vert++);
        pointData[p++] = vb.get(vert++);
        pointData[p++] = vb.get(vert);

        vert = ib.get(i + 2) * 3;
        pointData[p++] = vb.get(vert++);
        pointData[p++] = vb.get(vert++);
        pointData[p++] = vb.get(vert);
    }

    triIndices = new int[numTris];
    for (int i = 0; i < numTris; i++) {
        triIndices[i] = i;
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:26,代码来源:BIHTree.java

示例2: BIHTree

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
public BIHTree(Mesh mesh, int maxTrisPerNode) {
    this.mesh = mesh;
    this.maxTrisPerNode = maxTrisPerNode;

    if (maxTrisPerNode < 1 || mesh == null) {
        throw new IllegalArgumentException();
    }

    bihSwapTmp = new float[9];

    FloatBuffer vb = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
    IndexBuffer ib = mesh.getIndexBuffer();
    if (ib == null) {
        ib = new VirtualIndexBuffer(mesh.getVertexCount(), mesh.getMode());
    } else if (mesh.getMode() != Mode.Triangles) {
        ib = new WrappedIndexBuffer(mesh);
    }

    numTris = ib.size() / 3;
    initTriList(vb, ib);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:22,代码来源:BIHTree.java

示例3: getTriangle

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

示例4: getIndicesAsList

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
/**
 * Acquires an index buffer that will read the vertices on the mesh
 * as a list.
 * 
 * @param mesh The mesh to read from
 * @return A virtual or wrapped index buffer to read the data as a list
 */
public IndexBuffer getIndicesAsList(){
    if (mode == Mode.Hybrid)
        throw new UnsupportedOperationException("Hybrid mode not supported");
    
    IndexBuffer ib = getIndexBuffer();
    if (ib != null){
        if (mode.isListMode()){
            // already in list mode
            return ib; 
        }else{
            // not in list mode but it does have an index buffer
            // wrap it so the data is converted to list format
            return new WrappedIndexBuffer(this);
        }
    }else{
        // return a virtual index buffer that will supply
        // "fake" indices in list format
        return new VirtualIndexBuffer(vertCount, mode);
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:28,代码来源:Mesh.java

示例5: getIndexBuffer

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
/**
 * Get the index buffer for this mesh. 
 * Will return <code>null</code> if no index buffer is set.
 * 
 * @return The index buffer of this mesh.
 * 
 * @see Type#Index
 */
public IndexBuffer getIndexBuffer() {
    VertexBuffer vb = getBuffer(Type.Index);
    if (vb == null)
        return null;
    
    Buffer buf = vb.getData();
    if (buf instanceof ByteBuffer) {
        return new IndexByteBuffer((ByteBuffer) buf);
    } else if (buf instanceof ShortBuffer) {
        return new IndexShortBuffer((ShortBuffer) buf);
    } else if (buf instanceof IntBuffer) {
        return new IndexIntBuffer((IntBuffer) buf);
    } else {
        throw new UnsupportedOperationException("Index buffer type unsupported: "+ buf.getClass());
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:25,代码来源:Mesh.java

示例6: convert

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
public static Mesh convert(IndexedMesh mesh) {
    Mesh jmeMesh = new Mesh();

    jmeMesh.setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(mesh.numTriangles * 3));
    jmeMesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(mesh.numVertices * 3));

    IndexBuffer indicess = jmeMesh.getIndexBuffer();
    FloatBuffer vertices = jmeMesh.getFloatBuffer(Type.Position);

    for (int i = 0; i < mesh.numTriangles * 3; i++) {
        indicess.put(i, mesh.triangleIndexBase.getInt(i * 4));
    }

    for (int i = 0; i < mesh.numVertices * 3; i++) {
        vertices.put(i, mesh.vertexBase.getFloat(i * 4));
    }
    jmeMesh.updateCounts();
    jmeMesh.updateBound();
    jmeMesh.getFloatBuffer(Type.Position).clear();

    return jmeMesh;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:23,代码来源:Converter.java

示例7: generateLodEntropies

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
/**
 * This calculation is slow, so don't use it often.
 */
public void generateLodEntropies() {
    float[] entropies = new float[getMaxLod()+1];
    for (int i = 0; i <= getMaxLod(); i++){
        int curLod = (int) Math.pow(2, i);
        IndexBuffer idxB = geomap.writeIndexArrayLodDiff(curLod, false, false, false, false, totalSize);
        Buffer ib;
        if (idxB.getBuffer() instanceof IntBuffer)
            ib = (IntBuffer)idxB.getBuffer();
        else
            ib = (ShortBuffer)idxB.getBuffer();
        entropies[i] = EntropyComputeUtil.computeLodEntropy(mesh, ib);
    }

    lodEntropy = entropies;
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:19,代码来源:TerrainPatch.java

示例8: reIndexGeometry

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
protected void reIndexGeometry(HashMap<String,UpdatedTerrainPatch> updated, boolean useVariableLod) {

        UpdatedTerrainPatch utp = updated.get(getName());

        if (utp != null && utp.isReIndexNeeded() ) {
            int pow = (int) Math.pow(2, utp.getNewLod());
            boolean left = utp.getLeftLod() > utp.getNewLod();
            boolean top = utp.getTopLod() > utp.getNewLod();
            boolean right = utp.getRightLod() > utp.getNewLod();
            boolean bottom = utp.getBottomLod() > utp.getNewLod();

            IndexBuffer idxB;
            if (useVariableLod)
                idxB = geomap.writeIndexArrayLodVariable(pow, (int) Math.pow(2, utp.getRightLod()), (int) Math.pow(2, utp.getTopLod()), (int) Math.pow(2, utp.getLeftLod()), (int) Math.pow(2, utp.getBottomLod()), totalSize);
            else
                idxB = geomap.writeIndexArrayLodDiff(pow, right, top, left, bottom, totalSize);
            
            Buffer b;
            if (idxB.getBuffer() instanceof IntBuffer)
                b = (IntBuffer)idxB.getBuffer();
            else
                b = (ShortBuffer)idxB.getBuffer();
            utp.setNewIndexBuffer(b);
        }

    }
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:27,代码来源:TerrainPatch.java

示例9: generateNormals

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
/**
 * The method generates normal buffer for the created mesh of the curve.
 * 
 * @param indexes
 *            the indexes of the mesh points
 * @param points
 *            the mesh's points
 * @param smooth
 *            the flag indicating if the result is to be smooth or solid
 * @return normals buffer for the mesh
 */
private FloatBuffer generateNormals(IndexBuffer indexes, FloatBuffer points, boolean smooth) {
    Map<Integer, Vector3f> normalMap = new TreeMap<Integer, Vector3f>();
    Vector3f[] allVerts = BufferUtils.getVector3Array(points);

    for (int i = 0; i < indexes.size(); i += 3) {
        int index1 = indexes.get(i);
        int index2 = indexes.get(i + 1);
        int index3 = indexes.get(i + 2);

        Vector3f n = FastMath.computeNormal(allVerts[index1], allVerts[index2], allVerts[index3]);
        this.addNormal(n, normalMap, smooth, index1, index2, index3);
    }

    FloatBuffer normals = BufferUtils.createFloatBuffer(normalMap.size() * 3);
    for (Entry<Integer, Vector3f> entry : normalMap.entrySet()) {
        normals.put(entry.getValue().x);
        normals.put(entry.getValue().y);
        normals.put(entry.getValue().z);
    }
    return normals;
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:33,代码来源:CurvesHelper.java

示例10: compressIndexBuffer

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

示例11: optimize

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
public Mesh optimize(Mesh mesh) {
    nmgen = new NavmeshGenerator(cellSize, cellHeight, minTraversableHeight,
            maxTraversableStep, maxTraversableSlope,
            clipLedges, traversableAreaBorderSize,
            smoothingThreshold, useConservativeExpansion,
            minUnconnectedRegionSize, mergeRegionSize,
            maxEdgeLength, edgeMaxDeviation, maxVertsPerPoly,
            contourSampleDistance, contourMaxDeviation);

    FloatBuffer pb = mesh.getFloatBuffer(Type.Position);
    IndexBuffer ib = mesh.getIndexBuffer();

    // copy positions to float array
    float[] positions = new float[pb.capacity()];
    pb.clear();
    pb.get(positions);

    // generate int array of indices
    int[] indices = new int[ib.size()];
    for (int i = 0; i < indices.length; i++) {
        indices[i] = ib.get(i);
    }


    TriangleMesh triMesh = buildNavMesh(positions, indices, intermediateData);
    if (triMesh == null) {
        return null;
    }

    int[] indices2 = triMesh.indices;
    float[] positions2 = triMesh.vertices;

    Mesh mesh2 = new Mesh();
    mesh2.setBuffer(Type.Position, 3, positions2);
    mesh2.setBuffer(Type.Index, 3, indices2);
    mesh2.updateBound();
    mesh2.updateCounts();

    return mesh2;
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:41,代码来源:NavMeshGenerator.java

示例12: processTriangles

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
private static List<VertexData> processTriangles(Mesh mesh, int[] index, Vector3f[] v, Vector2f[] t, boolean splitMirrored) {
	IndexBuffer indexBuffer = mesh.getIndexBuffer();
	FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
	if (mesh.getBuffer(Type.TexCoord) == null) {
		throw new IllegalArgumentException("Can only generate tangents for " + "meshes with texture coordinates");
	}

	FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();

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

	for (int i = 0; i < indexBuffer.size() / 3; i++) {
		for (int j = 0; j < 3; j++) {
			index[j] = indexBuffer.get(i * 3 + j);
			populateFromBuffer(v[j], vertexBuffer, index[j]);
			populateFromBuffer(t[j], textureBuffer, index[j]);
		}

		TriangleData triData = processTriangle(index, v, t);
		if (splitMirrored) {
			triData.setIndex(index);
			triData.triangleOffset = i * 3;
		}
		if (triData != null) {
			vertices.get(index[0]).triangles.add(triData);
			vertices.get(index[1]).triangles.add(triData);
			vertices.get(index[2]).triangles.add(triData);
		}
	}

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

示例13: loadFromMesh

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
public void loadFromMesh(Mesh mesh) {
    clear();

    Vector3f a = new Vector3f();
    Vector3f b = new Vector3f();
    Vector3f c = new Vector3f();

    Plane up = new Plane();
    up.setPlanePoints(Vector3f.UNIT_X, Vector3f.ZERO, Vector3f.UNIT_Z);
    up.getNormal();

    IndexBuffer ib = mesh.getIndexBuffer();
    FloatBuffer pb = mesh.getFloatBuffer(Type.Position);
    pb.clear();
    for (int i = 0; i < mesh.getTriangleCount() * 3; i += 3) {
        int i1 = ib.get(i + 0);
        int i2 = ib.get(i + 1);
        int i3 = ib.get(i + 2);
        BufferUtils.populateFromBuffer(a, pb, i1);
        BufferUtils.populateFromBuffer(b, pb, i2);
        BufferUtils.populateFromBuffer(c, pb, i3);

        Plane p = new Plane();
        p.setPlanePoints(a, b, c);
        if (up.pseudoDistance(p.getNormal()) <= 0.0f) {
            System.out.println("Warning, normal of the plane faces downward!!!");
            continue;
        }

        addFace(a, b, c);
    }

    linkCells();
}
 
开发者ID:samynk,项目名称:DArtE,代码行数:35,代码来源:NavMesh.java

示例14: createMesh

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
public Mesh createMesh(Vector3f scale, Vector2f tcScale, Vector2f tcOffset, float offsetAmount, int totalSize, boolean center, int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod) {
    FloatBuffer pb = writeVertexArray(null, scale, center);
    FloatBuffer texb = writeTexCoordArray(null, tcOffset, tcScale, offsetAmount, totalSize);
    FloatBuffer nb = writeNormalArray(null, scale);
    Buffer ib;
    IndexBuffer idxB = writeIndexArrayLodDiff(lod, rightLod, topLod, leftLod, bottomLod, totalSize);
    if (idxB.getBuffer() instanceof IntBuffer)
        ib = (IntBuffer)idxB.getBuffer();
    else
        ib = (ShortBuffer)idxB.getBuffer();
    FloatBuffer bb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3);
    FloatBuffer tanb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3);
    writeTangentArray(nb, tanb, bb, texb, scale);
    Mesh m = new Mesh();
    m.setMode(Mode.TriangleStrip);
    m.setBuffer(Type.Position, 3, pb);
    m.setBuffer(Type.Normal, 3, nb);
    m.setBuffer(Type.Tangent, 3, tanb);
    m.setBuffer(Type.Binormal, 3, bb);
    m.setBuffer(Type.TexCoord, 2, texb);
    if (ib instanceof IntBuffer)
        m.setBuffer(Type.Index, 3, (IntBuffer)ib);
    else if (ib instanceof ShortBuffer)
        m.setBuffer(Type.Index, 3, (ShortBuffer)ib);
    m.setStatic();
    m.updateBound();
    return m;
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:29,代码来源:LODGeomap.java

示例15: createCollisionMesh

import com.jme3.scene.mesh.IndexBuffer; //导入依赖的package包/类
private void createCollisionMesh(Mesh mesh) {
    triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4);
    vertexBase = BufferUtils.createByteBuffer(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.getIndexBuffer();
    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();
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:28,代码来源:MeshCollisionShape.java


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