// Request to add some instances. // User is responsible to ensure, that instances IDs are unique in the octrtree. static public void _RequesAddInstances(ref EntityCommandBuffer ecb, Entity octreeEntity, BufferFromEntity <AddInstanceBufferElement> addInstanceBufferElement, ref NativeArray <Entity> na_instanceEntities, int i_instances2AddCount) { DynamicBuffer <AddInstanceBufferElement> a_addInstanceBufferElement = addInstanceBufferElement [octreeEntity]; a_addInstanceBufferElement.ResizeUninitialized(i_instances2AddCount); // Set required capacity. int i_instanceEntityIndex = 0; for (int i_instanceID = 0; i_instanceID < i_instances2AddCount; i_instanceID++) { Entity newBlockEntity = na_instanceEntities [i_instanceEntityIndex]; i_instanceEntityIndex++; // Formation A /* * int x = i_instanceID % 1000 ; * int y = i_instanceID % 100 ; * int z = (int) math.floor ( i_instanceID / 1000 ) ; */ // Formation B int z = (int)math.floor(i_instanceID / 625); // 25*25 = 625 int y = (int)math.floor(i_instanceID / 25) - z * 25; int x = i_instanceID % 25; float3 f3_blockCenter = new float3(x, y, z) + new float3(1, 1, 1) * 0.5f; // For rendering. Blocks.PublicMethods._AddBlockRequestViaCustomBufferWithEntity(ref ecb, newBlockEntity, f3_blockCenter, new float3(1, 1, 1) * 0.90f, MeshType.Prefab01); // Blocks.PublicMethods._AddBlockRequestViaCustomBufferWithEntity ( ecb, newBlockEntity, f3_blockCenter, new float3 ( 1, 1, 1 ) * 1 ) ; // Bounds of instance node, // hence entity block as well. Bounds bounds = new Bounds() { center = f3_blockCenter, size = new float3(1, 1, 1) * 1 }; a_addInstanceBufferElement [i_instanceID] = new AddInstanceBufferElement() { i_instanceID = newBlockEntity.Index, i_version = newBlockEntity.Version, instanceBounds = bounds }; // a_addInstanceBufferElement.Add ( addInstanceBuffer ) ; } }
// Request to add some instances. // User is responsible to ensure, that instances IDs are unique in the octrtree. static public void _RequesAddInstances(EntityCommandBuffer ecb, Entity octreeEntity, BufferFromEntity <AddInstanceBufferElement> addInstanceBufferElement, ref NativeArray <Entity> a_instanceEntities, int i_instances2AddCount) { DynamicBuffer <AddInstanceBufferElement> a_addInstanceBufferElement = addInstanceBufferElement [octreeEntity]; int i_instanceEntityIndex = 0; for (int i_instanceID = 0; i_instanceID < i_instances2AddCount; i_instanceID++) { Entity newBlockEntity = a_instanceEntities [i_instanceEntityIndex]; i_instanceEntityIndex++; int x = i_instanceID % 1000; int y = i_instanceID % 100; int z = (int)math.floor(i_instanceID / 1000); float3 f3_blockCenter = new float3(x, y, z) + new float3(1, 1, 1) * 0.5f; Blocks.PublicMethods._AddBlockRequestViaCustomBufferWithEntity(ecb, newBlockEntity, f3_blockCenter, new float3(1, 1, 1) * 1); // Bounds of instance node, // hence entity block as well. Bounds bounds = new Bounds() { center = f3_blockCenter, size = new float3(1, 1, 1) * 1 }; AddInstanceBufferElement addInstanceBuffer = new AddInstanceBufferElement() { i_instanceID = newBlockEntity.Index, i_version = newBlockEntity.Version, instanceBounds = bounds }; a_addInstanceBufferElement.Add(addInstanceBuffer); } }