コード例 #1
0
        private void OptimizeBatchButton_Click(object sender, EventArgs e)
        {
            if (CurrentBatch.Instances == null || CurrentBatch.Instances.Length <= 0)
            {
                return;
            }
            var d = MessageBox.Show(
                @"You are about to split the selected batch into multiple parts. Are you sure you want to do this?",
                @"Instance Optimizer", MessageBoxButtons.YesNo);

            if (d == DialogResult.No)
            {
                return;
            }

            lock (ProjectForm.WorldForm.RenderSyncRoot)
            {
                var newBatches = CurrentBatch?.OptimizeInstances(CurrentBatch, (float)OptmizationThresholdNumericUpDown.Value);
                if (newBatches == null || newBatches.Length <= 0)
                {
                    return;
                }

                // Remove our batch from the ymap
                CurrentBatch.Ymap.RemoveGrassBatch(CurrentBatch);
                foreach (var batch in newBatches)
                {
                    var b = batch.Batch;
                    b.lodDist          = CurrentBatch.Batch.lodDist;
                    b.LodInstFadeRange = CurrentBatch.Batch.LodInstFadeRange;
                    b.LodFadeStartDist = CurrentBatch.Batch.LodFadeStartDist;
                    b.ScaleRange       = CurrentBatch.Batch.ScaleRange;
                    b.OrientToTerrain  = CurrentBatch.Batch.OrientToTerrain;
                    b.archetypeName    = CurrentBatch.Batch.archetypeName;
                    batch.Batch        = b;
                    batch.Archetype    = CurrentBatch.Archetype;
                    batch.UpdateInstanceCount();
                    ProjectForm.NewGrassBatch(batch);
                }
                CurrentBatch.Ymap.CalcExtents();
                CurrentBatch.Ymap.Save();

                // TODO: Select the last grass batch in the new list on the project explorer.
                ProjectForm.ProjectExplorer.TrySelectGrassBatchTreeNode(CurrentBatch.Ymap.GrassInstanceBatches[0]);
            }
        }