在翻动草动态壁纸之后,我已经绕过了这段代码 - 它创建了草刀片网并设置了索引:
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);
}
我很困惑这2行:meshBuilder.addIndexSetAllocation(mBladesIndicies, Primitive.TRIANGLE);
和mBladesIndicies.copyFrom(idx);
为什么他们将mBladesIndicies
发送到网格构建器并创建网格,然后mBladesIndicies
变量实际得到mBladesIndicies.copyFrom(idx);
简而言之 - 为什么meshBuilder.addIndexSetAllocation(mBladesIndicies, Primitive.TRIANGLE);
和mBladesMesh = meshBuilder.create();
来之前 mBladesIndicies.copyFrom(idx);
?
答案 0 :(得分:1)
分配通过引用而不是副本连接到Mesh。因此,添加数据的顺序无关紧要。
Mesh.Builder在创建后会保留分配引用。