// 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); }
// 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); }