示例#1
0
        /// <summary>
        /// Queues new or rebuild of the specified group.
        /// </summary>
        /// <param name="group">The group to rebuild.</param>
        private void QueueRebuild(StaticBatchingGroupKey group)
        {
            // Read instances
            List <StaticMeshInstance> instances;

            if (!this.meshInstances.TryGetValue(group, out instances))
            {
                return;
            }

            // Prepare data arrays for job
            int vCounter = 0, iCounter = 0; // Vertex and index counter
            StaticBatchingRebuildJobData jobData = new StaticBatchingRebuildJobData()
            {
                groupKey = group
            };

            jobData.PreAllocate();

            foreach (var instance in instances)
            {
                var cache = GetVisCache(instance.mesh);
                jobData.meshInstances.Add(instance);
                jobData.vertexOffsets.Add(vCounter);
                jobData.indexOffsets.Add(iCounter);
                vCounter += cache.vertices.Length;
                iCounter += cache.indices.Length;
            }

            // Allocate job data memory
            jobData.Allocate(vCounter, iCounter);

            // Dispatch jobs
            var dep = new TransformJob()
            {
                dataId = this.runningJobDataCounter
            }.Schedule(jobData.meshInstances.Count, 4);

            dep = new CopyJob()
            {
                dataId = this.runningJobDataCounter
            }.Schedule(dep);
            jobData.jobHandle = dep;

            jobData.jobId = this.runningJobDataCounter++;
            this.runningJobs.Add(jobData.jobId, jobData);
            JobHandle.ScheduleBatchedJobs();
        }
示例#2
0
        /// <summary>
        /// Executes a <see cref="BatchingCommandInsert"/>.
        /// </summary>
        /// <param name="command">The command to execute.</param>
        /// <param name="rebuilds">List containing all groups which require a rebuild.</param>
        private void InsertCommand(BatchingCommandInsert command, HashSet <StaticBatchingGroupKey> rebuilds)
        {
            // Build group key
            var groupKey = new StaticBatchingGroupKey()
            {
                chunk    = GetChunk(command.transform.MultiplyPoint3x4(Vector3.zero)),
                layer    = command.layer,
                material = command.material
            };

            // Insert instance
            this.meshInstances.GetOrCreate(groupKey).Add(new StaticMeshInstance()
            {
                groupKey  = groupKey,
                owner     = command.owner,
                transform = command.transform,
                mesh      = command.mesh
            });

            // Queue rebuild
            rebuilds.Add(groupKey);
        }