Пример #1
0
        public VoxelPhysicsResponse Execute(VoxelPhysicsWorkerData data, VoxelModel model)
        {
            _command.startPosition    = data.initialPosition;
            _command.startVoxel       = data.startVoxel;
            _command.volumeVoxels     = model.Voxels;
            _command.voxelsSize       = model.Size;
            _command.voxelsList       = data.collapseVoxels;
            _command.voxelsDictionary = data.voxelsDictionary;

            var result = _command.Execute();

            return(result);
        }
Пример #2
0
        public VoxelPhysicsResponse Execute(VoxelPhysicsRequest request, VoxelModel model)
        {
            var volumeSize       = model.Size;
            var collapseVoxels   = new List <VoxelFallingEntity>(512 * 512);
            var voxelsDictionary = new Dictionary <int, byte>(1024 * 256);
            var position         = request.initialPosition;

            var bounds       = new VoxelPhysicsBounds(int.MaxValue, int.MinValue);
            var isDestructed = false;
            var voxelIndex   = VoxelUtility.GetVoxelIndex(position, volumeSize);
            var voxel        = model.GetVoxel(voxelIndex);
            var pivot        = new Vector3();

            if (voxel.IsEmpty)
            {
                var directionMask = new VoxelPhysicsDirectionMask(VoxelPhysicsDirectionMaskPriorityType.TopYPriority);

                for (var v = 0; v < 6; v++)
                {
                    var direction       = directionMask[v];
                    var currentPosition = new Vector3Int(
                        position.x + direction.x,
                        position.y + direction.y,
                        position.z + direction.z);

                    voxelIndex = VoxelUtility.GetVoxelIndex(currentPosition, volumeSize);
                    voxel      = model.GetVoxel(voxelIndex);

                    if (voxel.IsSolid)
                    {
                        var workerRequest = new VoxelPhysicsWorkerData
                        {
                            startVoxel       = voxel,
                            initialPosition  = currentPosition,
                            collapseVoxels   = collapseVoxels,
                            voxelsDictionary = voxelsDictionary
                        };
                        var result = _worker.Execute(workerRequest, model);

                        if (result.isDestroyed)
                        {
                            for (var i = 0; i < 3; i++)
                            {
                                if (bounds.min[i] > result.fallingVoxelBounds.min[i])
                                {
                                    bounds.min[i] = result.fallingVoxelBounds.min[i];
                                }

                                if (bounds.max[i] < result.fallingVoxelBounds.max[i])
                                {
                                    bounds.max[i] = result.fallingVoxelBounds.max[i];
                                }
                            }

                            isDestructed = true;
                        }
                    }
                }
            }

            var voxelsDictionaryCount = voxelsDictionary.Count;

            pivot.x = pivot.x / voxelsDictionaryCount + 0.5F;
            pivot.y = pivot.y / voxelsDictionaryCount + 0.5F;
            pivot.z = pivot.z / voxelsDictionaryCount + 0.5F;

            return(new VoxelPhysicsResponse
            {
                isDestroyed = isDestructed,
                fallingVoxelList = collapseVoxels,
                fallingVoxelDictionary = voxelsDictionary,
                fallingVoxelBounds = bounds,
            });
        }