示例#1
0
    // Build a job chain with a given scanner.
    JobHandle BuildJobChain(float3 origin, Scanner scanner, JobHandle deps)
    {
        // Transform output destination
        var transforms = _voxelGroup.GetComponentDataArray <LocalToWorld>();

        if (transforms.Length == 0)
        {
            return(deps);
        }

        if (_pTransformCount == null)
        {
            // Initialize the transform counter.
            _pTransformCount = (int *)UnsafeUtility.Malloc(
                sizeof(int), sizeof(int), Allocator.Persistent);
            *_pTransformCount = 0;
        }
        else
        {
            // Wrap around the transform counter to avoid overlfow.
            *_pTransformCount %= transforms.Length;
        }

        // Total count of rays
        var total = scanner.Resolution.x * scanner.Resolution.y;

        // Ray cast command/result array
        var commands = new NativeArray <RaycastCommand>(total, Allocator.TempJob);
        var hits     = new NativeArray <RaycastHit>(total, Allocator.TempJob);

        // 1: Set-up jobs
        var setupJob = new SetupJob {
            Commands   = commands,
            Origin     = origin,
            Extent     = scanner.Extent,
            Resolution = scanner.Resolution
        };

        deps = setupJob.Schedule(total, 64, deps);

        // 2: Raycast jobs
        deps = RaycastCommand.ScheduleBatch(commands, hits, 16, deps);

        // 3: Transfer jobs
        var transferJob = new TransferJob {
            RaycastCommands = commands,
            RaycastHits     = hits,
            Scale           = scanner.Extent.x * 2 / scanner.Resolution.x,
            Transforms      = transforms,
            pCounter        = _pTransformCount
        };

        deps = transferJob.Schedule(total, 64, deps);

        return(deps);
    }
示例#2
0
        protected override void OnUpdate()
        {
            var transferJob = new TransferJob()
            {
                transferRate   = GenericInformation.TransferRate,
                potentialGroup = GetComponentDataFromEntity <PotentialValue>()
            };

            Dependency = transferJob.Schedule(stepPhysicsWorld.Simulation, ref buildPhysicsWorld.PhysicsWorld, Dependency);

            // Finishes all accumulated events before going for the next task
            Dependency.Complete();
        }
示例#3
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var positions = _bulletsGroup.GetComponentDataArray <Position>();
            var rotations = _bulletsGroup.GetComponentDataArray <Rotation>();


            if (positions.Length == 0)
            {
                return(inputDeps);
            }


            var raycastCommands = new NativeArray <RaycastCommand>(_bulletsGroup.CalculateLength(), Allocator.TempJob);
            var raycastHits     = new NativeArray <RaycastHit>(_bulletsGroup.CalculateLength(), Allocator.TempJob);

            var setupRaycastsJob = new RaycastHitCommands()
            {
                Positions  = positions,
                Directions = rotations,
                Raycasts   = raycastCommands,
            };

            var setupDependency = setupRaycastsJob.Schedule(_bulletsGroup.CalculateLength(), 32, inputDeps);

            var deps = RaycastCommand.ScheduleBatch(raycastCommands, raycastHits, 32, setupDependency);

            deps.Complete();

            var transferJob = new TransferJob
            {
                EntityCommandBuffer = _bulletRayBarrier.CreateCommandBuffer(),
                Entities            = _bulletsGroup.GetEntityArray(),
                RaycastCommands     = raycastCommands,
                RaycastHits         = raycastHits,
            };

            inputDeps = transferJob.Schedule(_bulletsGroup.CalculateLength(), 64, deps);

            return(inputDeps);
        }
示例#4
0
    // Build a job chain with a given scanner.
    JobHandle BuildJobChain(float3 origin, Scanner scanner, JobHandle deps)
    {
        // Transform output destination
        //var transforms = _voxelGroup.GetComponentDataArray<TransformMatrix>();
        var positions = _voxelGroup.ToComponentDataArray <Translation>(Allocator.TempJob);
        var scales    = _voxelGroup.ToComponentDataArray <Scale>(Allocator.TempJob);

        //Debug.Log("positions.Length:" + positions.Length + ",scales.Length:" + scales.Length);
        if (positions.Length == 0)
        {
            return(deps);
        }

        if (m_preTranslation.Length != 0)
        {
            m_preTranslation.Dispose();
            m_preScale.Dispose();
        }
        m_preTranslation = positions;
        m_preScale       = scales;

        if (_pTransformCount == null)
        {
            // Initialize the transform counter.
            _pTransformCount = (int *)UnsafeUtility.Malloc(
                sizeof(int), sizeof(int), Allocator.Persistent);
            *_pTransformCount = 0;
        }
        else
        {
            // Wrap around the transform counter to avoid overlfow.
            *_pTransformCount %= positions.Length;
        }

        // Total count of rays
        var total = scanner.Resolution.x * scanner.Resolution.y;

        // Ray cast command/result array
        var commands = new NativeArray <RaycastCommand>(total, Allocator.TempJob);
        var hits     = new NativeArray <RaycastHit>(total, Allocator.TempJob);

        // 1: Set-up jobs
        var setupJob = new SetupJob {
            Commands   = commands,
            Origin     = origin,
            Extent     = scanner.Extent,
            Resolution = scanner.Resolution
        };

        deps = setupJob.Schedule(total, 64, deps);

        // 2: Raycast jobs
        deps = RaycastCommand.ScheduleBatch(commands, hits, 16, deps);

        // 3: Transfer jobs
        var transferJob = new TransferJob {
            RaycastCommands = commands,
            RaycastHits     = hits,
            Scale           = scanner.Extent.x * 2 / scanner.Resolution.x,
            Positions       = positions,
            Scales          = scales,
            pCounter        = _pTransformCount
        };

        deps = transferJob.Schedule(total, 64, deps);

        // 4: SetTranslationAndScale jobs
        var setJob = new SetTranslationAndScale
        {
            targetTranslations = positions,
            targetScales       = scales
        };

        deps = setJob.Schedule(_voxelGroup, deps);

        return(deps);
    }