在分配变量获得任何数据之前设置它



在翻转草地动态壁纸后,我已经完成了这段代码-它创建了草叶网格并设置了索引:

private void createMesh() {
    mVertexBuffer = new ScriptField_Vertex(mRS, mVerticies * 2);
    final Mesh.AllocationBuilder meshBuilder = new Mesh.AllocationBuilder(mRS);
    meshBuilder.addVertexAllocation(mVertexBuffer.getAllocation());
    mBladesIndicies = Allocation.createSized(mRS, Element.U16(mRS), mIndicies);
    meshBuilder.addIndexSetAllocation(mBladesIndicies, Primitive.TRIANGLE);
    mBladesMesh = meshBuilder.create();
    short[] idx = new short[mIndicies];
    int idxIdx = 0;
    int vtxIdx = 0;
    for (int i = 0; i < mBladeSizes.length; i++) {
        for (int ct = 0; ct < mBladeSizes[i]; ct ++) {
            idx[idxIdx + 0] = (short)(vtxIdx + 0);
            idx[idxIdx + 1] = (short)(vtxIdx + 1);
            idx[idxIdx + 2] = (short)(vtxIdx + 2);
            idx[idxIdx + 3] = (short)(vtxIdx + 1);
            idx[idxIdx + 4] = (short)(vtxIdx + 3);
            idx[idxIdx + 5] = (short)(vtxIdx + 2);
            idxIdx += 6;
            vtxIdx += 2;
        }
        vtxIdx += 2;
    }
    mBladesIndicies.copyFrom(idx);
}

我对这两行感到困惑:meshBuilder.addIndexSetAllocation(mBladesIndicies, Primitive.TRIANGLE);mBladesIndicies.copyFrom(idx);为什么在mBladesIndicies变量实际获得mBladesIndicies.copyFrom(idx);的数据之前,他们将mBladesIndicies发送给网格构建器并创建网格

简而言之——为什么meshBuilder.addIndexSetAllocation(mBladesIndicies, Primitive.TRIANGLE);mBladesMesh = meshBuilder.create();出现在之前 mBladesIndicies.copyFrom(idx); ?

分配通过引用而不是副本连接到Mesh。因此,添加数据的顺序并不重要。

网。生成器在创建之后保留分配引用。

相关内容

  • 没有找到相关文章

最新更新