static private BufferArray <Common.BufferElements.EntityBuffer> _ReleaseCompositesFromPatternGroup(EntityCommandBuffer commandBuffer, BufferArray <Common.BufferElements.EntityBuffer> a_compositeEntities, int i_prefabIndex) { // get number of composites in this patter group int i_compositesCount = a_compositeEntities [i_prefabIndex].Length; // iterate through owned composites, to detach them for (int i = 0; i < i_compositesCount; i++) { Common.BufferElements.EntityBuffer compositeEntityBuffer = a_compositeEntities [i_prefabIndex][i]; // Set as not assigned // And reset position _ReleaseCompositesFromPatternRequest(commandBuffer, compositeEntityBuffer); } // fiinally clear store of detached compoenents a_compositeEntities [i_prefabIndex].Clear(); return(a_compositeEntities); }
/// <summary> /// Set as not assigned /// And reset position /// </summary> /// <param name="commandBuffer"></param> /// <param name="compositeEntityBuffer"></param> static public void _ReleaseCompositesFromPatternRequest(EntityCommandBuffer commandBuffer, Common.BufferElements.EntityBuffer compositeEntityBuffer) { // set as not assigned commandBuffer.AddComponent(compositeEntityBuffer.entity, new Common.Components.IsNotAssignedTag()); // reset position commandBuffer.SetComponent(compositeEntityBuffer.entity, new Position() { Value = new float3(0, 5, 5) }); commandBuffer.SetComponent(compositeEntityBuffer.entity, new Scale() { Value = new float3(1, 1, 1) * 0.1f }); }
// public float3 f3_moveAbout ; // Blocks.MovePatternComonent public void Execute() // for IJob // public void Execute ( int i ) // for IJobParallelFor { // f3_moveAbout += new float3 ( random.NextFloat ( -0.01f, 0.01f ) ,0,0 ) ; // iterate through patterns group, to move its composites for (int i = 0; i < movePatternData.Length; i++) { PatternComponent patternGroup = movePatternData.a_compositePatternComponent [i]; //int i_ComponentsPatternIndex = compositePatternComponent.i_patternIndex ; patternGroup.f_baseScale = 3; // test temp movePatternData.a_compositePatternComponent [i] = patternGroup; MovePattern movePattern = movePatternData.a_movePatterns [i]; //int i_entityBufferCount = movePatternData.a_compositeEntities [i].Length ; //movePattern.f3_position = f3_moveAbout + new float3 (1,0,0) * i * patternGroup.f_baseScale + new float3 (5,0,0) ; // * 0.001f; movePattern.f3_position = f3_moveAbout + patternGroup.f3_localPosition * patternGroup.f_baseScale + new float3(5, 0, 0); // * 0.001f; movePatternData.a_movePatterns [i] = movePattern; // update float f_distance = math.lengthSquared(movePattern.f3_position); Entity paternEntity = movePatternData.a_entities [i]; // move composite Position position = new Position() { Value = movePattern.f3_position }; //position.Value = blockCompositeBufferElement.f3_position + movePattern.f3_position ; // commandBuffer.SetComponent ( paternEntity, position ) ; // commandBuffer.AddComponent ( paternEntity, new Blocks.Pattern.RequestPatternSetupTag () ) ; int i_entityBufferCount = movePatternData.a_compositeEntities [i].Length; if (i_entityBufferCount > 0) { // iterate through pattern's group composites for (int i_bufferIndex = 0; i_bufferIndex < i_entityBufferCount; i_bufferIndex++) { Common.BufferElements.EntityBuffer entityBuffer = movePatternData.a_compositeEntities [i][i_bufferIndex]; Entity compositeEntity = entityBuffer.entity; // get composite data Blocks.CompositeComponent compositeComponent = a_compositeComponents [compositeEntity]; Blocks.Pattern.CompositeInPatternPrefabComponent blockCompositeBufferElement = Pattern.AddPatternPrefabSystem._GetCompositeFromPatternPrefab(compositeComponent.i_inPrefabIndex); // move composite // Position position = new Position () ; position.Value = blockCompositeBufferElement.f3_position * patternGroup.f_baseScale + movePattern.f3_position; commandBuffer.SetComponent(compositeEntity, position); Scale scale = new Scale() { Value = blockCompositeBufferElement.f3_scale * patternGroup.f_baseScale }; commandBuffer.SetComponent(compositeEntity, scale); if (f_distance > 10) { } else { // Entity paternEntity = movePatternData.a_entities [i] ; // commandBuffer.AddComponent ( paternEntity, new Blocks.Pattern.RequestPatternReleaseTag () ) ; //Test02.AddBlockSystem._AddBlockRequestViaCustomBufferWithEntity ( commandBuffer, paternEntity, movePattern.f3_position, new float3 (1,1,1), float3.zero, new Entity (), float4.zero ) ; } } // for } else { Entity compositeEntity = patternGroup.blockEntity; // get composite data Blocks.CompositeComponent compositeComponent = a_compositeComponents [compositeEntity]; Blocks.Pattern.CompositeInPatternPrefabComponent blockCompositeBufferElement = Pattern.AddPatternPrefabSystem._GetCompositeFromPatternPrefab(compositeComponent.i_inPrefabIndex); // move composite // Position position = new Position () ; position.Value = blockCompositeBufferElement.f3_position * patternGroup.f_baseScale + movePattern.f3_position; commandBuffer.SetComponent(compositeEntity, position); //Scale scale = new Scale () { Value = blockCompositeBufferElement.f3_scale * patternGroup.f_baseScale * 3 } ; //commandBuffer.SetComponent ( compositeEntity, scale ) ; } } // for }
/// <summary> /// Assigns composite patter, to selected entity /// </summary> /// <param name="entityWithPatern"></param> static private EntityCommandBuffer _AssignComposites2Pattern(EntityCommandBuffer commandBuffer, RequestPatternSetupData requestPatternSetupData, int i_patternGroupIndex, EntityArray a_spareCompositeEntities) { //Entity assignComposites2PatternEntity = assignComposite2PatternData.a_entities [i_entityWithPaternIndex] ; //CompositeComponent compositeComponent = assignComposite2PatternData.a_compositeEntityRelatives [i_entityWithPaternIndex] ; Blocks.PatternComponent pattern = requestPatternSetupData.a_compositesInPattern [i_patternGroupIndex]; BufferArray <Common.BufferElements.EntityBuffer> a_patternsStore = requestPatternSetupData.a_entityBuffer; int i_patternIndex = pattern.i_patternIndex; int i_patternOffsetIndex = i_patternIndex * Pattern.AddPatternPrefabSystem.i_compositesCountPerPatternGroup; Entity requestPatternSetupEntity = requestPatternSetupData.a_entities [i_patternGroupIndex]; // clear store for each pattern group entity a_patternsStore [i_patternGroupIndex].Clear(); int i_spareEntitiesOffsetIndex = i_patternGroupIndex * Pattern.AddPatternPrefabSystem.i_compositesCountPerPatternGroup; // int i_patterGroupOffsetIndex = i_componentsPatternIndex * i_compositesCountPerPatternGroup ; // assign composite entity to entity with pattern for (int i_spareEntityIndex = 0; i_spareEntityIndex < Pattern.AddPatternPrefabSystem.i_compositesCountPerPatternGroup; i_spareEntityIndex++) { // get element from patern prefab to copy into group int i_compositeInPrefabIndex = i_patternOffsetIndex + i_spareEntityIndex; Blocks.Pattern.CompositeInPatternPrefabComponent compositeInPatternPrefab = Pattern.AddPatternPrefabSystem.a_patternPrefabs [i_compositeInPrefabIndex]; // This composite is different type as previous composite. // This composite mesh will be scaled, to overlap next composite, if the type is the same. // Hence next mesh may be not required, hwen type is < 0 if (compositeInPatternPrefab.i_compositePrefabIndex >= 0) { // Assign relative references to composite Blocks.CompositeComponent composite = new CompositeComponent() { blockEntity = pattern.blockEntity, // assign grand parent entity to composite patternEntity = requestPatternSetupEntity, // assign parent pattern group entity to composite i_inPrefabIndex = i_compositeInPrefabIndex // used prefab }; Entity spareCompositeEntity = a_spareCompositeEntities [i_spareEntitiesOffsetIndex + i_spareEntityIndex]; Common.BufferElements.EntityBuffer spareEntityBuffer = new Common.BufferElements.EntityBuffer() { entity = spareCompositeEntity }; // expand buffer array if is too small a_patternsStore [i_patternGroupIndex].Add(spareEntityBuffer); commandBuffer.SetComponent(spareCompositeEntity, composite); MeshInstanceRenderer renderer; switch (compositeInPatternPrefab.i_compositePrefabIndex) { case 1: renderer = Bootstrap.octreeCenter02; break; case 2: renderer = Bootstrap.octreeCenter03; break; case 3: renderer = Bootstrap.octreeCenter04; break; case 4: renderer = Bootstrap.octreeCenter05; break; case 5: renderer = Bootstrap.octreeCenter06; break; case 6: renderer = Bootstrap.octreeCenter07; break; default: renderer = Bootstrap.octreeCenter01; break; } commandBuffer.SetSharedComponent(spareCompositeEntity, renderer); Position position = new Position() { Value = compositeInPatternPrefab.f3_position }; commandBuffer.SetComponent(spareCompositeEntity, position); Scale scale = new Scale() { Value = compositeInPatternPrefab.f3_scale * pattern.f_baseScale }; commandBuffer.SetComponent(spareCompositeEntity, scale); // Store composite back in //Pattern.AddPatternPrefabSystem.a_patternPrefabs [ i_compositeInPrefabIndex ] = compositeInPatternPrefab ; // Composite entity has been assigned // Now is ready for rendering, or other processing commandBuffer.RemoveComponent <Common.Components.IsNotAssignedTag> (spareCompositeEntity); } else { // Iteration reached composite index in the prefab store, which should be ignored. // Any later index for this prefab should also be ignored, as expanded mesh took its place. break; } } return(commandBuffer); }
// public float3 f3_moveAbout ; // Blocks.MovePatternComonent public void Execute() // for IJob // public void Execute ( int i ) // for IJobParallelFor { // Iterate through patterns groups, to move its composites for (int i = 0; i < movePatternData.Length; i++) { PatternComponent patternGroup = movePatternData.a_compositePatternComponent [i]; // int i_componentsPatternIndex = patternGroup.i_patternIndex ; patternGroup.f_baseScale = 1f; // test temp MovePattern movePattern = movePatternData.a_movePatterns [i]; int i_entityBufferCount = movePatternData.a_compositeEntities [i].Length; // position offset test //movePattern.f3_position = f3_moveAbout + patternGroup.f_localPosition * patternGroup.f_baseScale * 3; // * 0.001f; // movePattern.f3_position = f3_moveAbout + patternGroup.f_localPosition * patternGroup.f_baseScale + new float3 (5,0,0) ; // * 0.001f; movePattern.f3_position = f3_moveAbout + patternGroup.f3_localPosition * 3 + new float3(5, 0, 0); // * 0.001f; movePatternData.a_movePatterns [i] = movePattern; // update float f_distance = math.lengthSquared(movePattern.f3_position); // if ( f_distance < 8 ) // { // iterate through pattern's group composites for (int i_bufferIndex = 0; i_bufferIndex < i_entityBufferCount; i_bufferIndex++) { Common.BufferElements.EntityBuffer entityBuffer = movePatternData.a_compositeEntities [i][i_bufferIndex]; Entity compositeEntity = entityBuffer.entity; if (compositeEntity.Index != 0) { // get composite data Blocks.CompositeComponent compositeComponent = a_compositeComponents [compositeEntity]; Blocks.Pattern.CompositeInPatternPrefabComponent blockCompositeBufferElement = Pattern.AddPatternPrefabSystem._GetCompositeFromPatternPrefab(compositeComponent.i_inPrefabIndex); // move composite Position position = new Position(); position.Value = blockCompositeBufferElement.f3_position * patternGroup.f_baseScale + movePattern.f3_position; //position.Value = blockCompositeBufferElement.f3_position * 3 + movePattern.f3_position ; // movePattern.f3_position = f3_moveAbout + patternGroup.f_localPosition * patternGroup.f_baseScale + new float3 (5,0,0) ; // * 0.001f; commandBuffer.SetComponent(compositeEntity, position); Scale scale = new Scale() { Value = blockCompositeBufferElement.f3_scale * patternGroup.f_baseScale }; commandBuffer.SetComponent(compositeEntity, scale); } } // for // } // else // { /* * Entity paternEntity = movePatternData.a_entities [i] ; * commandBuffer.AddComponent ( paternEntity, new Blocks.Pattern.RequestPatternReleaseTag () ) ; * * // Test02.AddBlockSystem._AddBlockRequestViaCustomBufferWithEntity ( commandBuffer, paternEntity, movePattern.f3_position, new float3 (1,1,1), float3.zero, new Entity (), float4.zero ) ; * commandBuffer.AddComponent ( paternEntity, new Common.Components.Lod05Tag () ) ; // test only * commandBuffer.AddComponent ( paternEntity, new Blocks.Pattern.RequestPatternSetupTag () ) ; */ //patternGroup.f_baseScale = 3 ; //movePatternData.a_compositePatternComponent [i] = patternGroup ; // } } // for }