// Iterate over all colliders and store those whose cell span has changed.
            public void Execute(int i)
            {
                float size  = bounds[i].AverageAxisLength();
                int   level = NativeMultilevelGrid <int> .GridLevelForSize(size);

                float cellSize = NativeMultilevelGrid <int> .CellSizeOfLevel(level);

                // get new collider bounds cell coordinates:
                BurstCellSpan newSpan = new BurstCellSpan(new int4(GridHash.Quantize(bounds[i].min.xyz, cellSize), level),
                                                          new int4(GridHash.Quantize(bounds[i].max.xyz, cellSize), level));

                // if the collider is 2D, project it to the z = 0 cells.
                if (colliders[i].is2D != 0)
                {
                    newSpan.min[2] = 0;
                    newSpan.max[2] = 0;
                }

                // if the collider is at the tail (removed), we will only remove it from its current cellspan.
                // if the new cellspan and the current one are different, we must remove it from its current cellspan and add it to its new one.
                if (i >= colliderCount || cellIndices[i] != newSpan)
                {
                    // Add the collider to the list of moving colliders:
                    movingColliders.Enqueue(new MovingCollider()
                    {
                        oldSpan = cellIndices[i],
                        newSpan = newSpan,
                        entity  = i
                    });

                    // Update previous coords:
                    cellIndices[i] = newSpan;
                }
            }
Exemple #2
0
            // Iterate over all colliders and store those whose cell span has changed.
            public void Execute(int i)
            {
                BurstAabb velocityBounds = bounds[i];

                // Expand bounds by rigidbody's linear velocity:
                if (shapes[i].rigidbodyIndex >= 0)
                {
                    velocityBounds.Sweep(rigidbodies[shapes[i].rigidbodyIndex].velocity * dt);
                }

                // Expand bounds by collision material's stick distance:
                if (shapes[i].materialIndex >= 0)
                {
                    velocityBounds.Expand(collisionMaterials[shapes[i].materialIndex].stickDistance);
                }

                float size  = velocityBounds.AverageAxisLength();
                int   level = NativeMultilevelGrid <int> .GridLevelForSize(size);

                float cellSize = NativeMultilevelGrid <int> .CellSizeOfLevel(level);

                // get new collider bounds cell coordinates:
                BurstCellSpan newSpan = new BurstCellSpan(new int4(GridHash.Quantize(velocityBounds.min.xyz, cellSize), level),
                                                          new int4(GridHash.Quantize(velocityBounds.max.xyz, cellSize), level));

                // if the collider is 2D, project it to the z = 0 cells.
                if (shapes[i].is2D != 0)
                {
                    newSpan.min[2] = 0;
                    newSpan.max[2] = 0;
                }

                // if the collider is at the tail (removed), we will only remove it from its current cellspan.
                // if the new cellspan and the current one are different, we must remove it from its current cellspan and add it to its new one.
                if (i >= colliderCount || cellIndices[i] != newSpan)
                {
                    // Add the collider to the list of moving colliders:
                    movingColliders.Enqueue(new MovingCollider()
                    {
                        oldSpan = cellIndices[i],
                        newSpan = newSpan,
                        entity  = i
                    });

                    // Update previous coords:
                    cellIndices[i] = newSpan;
                }
            }
Exemple #3
0
            public void Execute(int i)
            {
                int level = NativeMultilevelGrid <int> .GridLevelForSize(simplexBounds[i].AverageAxisLength());

                float cellSize = NativeMultilevelGrid <int> .CellSizeOfLevel(level);

                // get new particle cell coordinate:
                int4 newCellCoord = new int4(GridHash.Quantize(simplexBounds[i].center.xyz, cellSize), level);

                // if the solver is 2D, project the particle to the z = 0 cell.
                if (is2D)
                {
                    newCellCoord[2] = 0;
                }

                cellCoords[i] = newCellCoord;
            }
            public void Execute(int index)
            {
                int i = activeParticles[index];

                // Find this particle's stick distance:
                float stickDistance = 0;

                if (particleMaterialIndices[i] >= 0)
                {
                    stickDistance = collisionMaterials[particleMaterialIndices[i]].stickDistance;
                }

                // Use it (together with radius and fluid radius) to calculate its size in the grid.
                float size = radii[i].x * 2.2f + stickDistance;

                size = math.max(size, fluidRadii[i] * 1.1f);

                int level = NativeMultilevelGrid <int> .GridLevelForSize(size);

                float cellSize = NativeMultilevelGrid <int> .CellSizeOfLevel(level);

                // get new particle cell coordinate:
                int4 newCellCoord = new int4(GridHash.Quantize(positions[i].xyz, cellSize), level);

                // if the solver is 2D, project the particle to the z = 0 cell.
                if (is2D)
                {
                    newCellCoord[2] = 0;
                }

                // if the current cell is different from the current one, the particle has changed cell.
                if (!newCellCoord.Equals(cellCoord[i]))
                {
                    movingParticles.Enqueue(new MovingEntity()
                    {
                        oldCellCoord = cellCoord[i],
                        newCellCoord = newCellCoord,
                        entity       = i
                    });
                    cellCoord[i] = newCellCoord;
                }
            }