Example #1
0
        public ModelBatchList ComputeBatches(IViewPoint viewPoint, TextureCube skybox)
        {
            var transparentBatches = new List <ModelRenderBatch>(this.TransparentModels.Count);

            var transparentModels = this.SortBackToFront(this.TransparentModels, viewPoint);
            var batches           = this.ComputeBatches(transparentModels, viewPoint);

            for (var i = 0; i < batches.Count; i++)
            {
                transparentBatches.Add(new ModelRenderBatch(batches[i], viewPoint, skybox));
            }

            this.OpaqueModelBatchList.Clear();
            for (var i = 0; i < this.OpaqueModels.Count; i++)
            {
                var model  = this.OpaqueModels[i];
                var bounds = this.Bounds.Get(model.Entity);

                if (bounds.IsInView)
                {
                    var pose      = this.Poses.Get(model.Entity);
                    var modelPose = new ModelPose(model, pose);
                    this.OpaqueModelBatchList.Add(modelPose);
                }
            }

            return(new ModelBatchList(new ModelRenderBatch(this.OpaqueModelBatchList, viewPoint, skybox), transparentBatches));
        }
Example #2
0
        private IReadOnlyList <List <ModelPose> > ComputeBatches(List <AModel> models, IViewPoint viewPoint)
        {
            var batches = new List <List <ModelPose> >();

            var currentBatch  = new List <ModelPose>();
            var currentBounds = new BoundingRectangle();

            for (var i = 0; i < models.Count; i++)
            {
                var model = models[i];

                var bounds    = this.Bounds.Get(model.Entity);
                var pose      = this.Poses.Get(model.Entity);
                var modelPose = new ModelPose(model, pose);

                var boundingRectangle = BoundingRectangle.CreateFromProjectedBoundingBox(bounds.BoundingBox, viewPoint);

                if (currentBatch.Count == 0)
                {
                    currentBounds = boundingRectangle;
                    currentBatch.Add(modelPose);
                }
                else if (boundingRectangle.Intersects(currentBounds))
                {
                    batches.Add(currentBatch);
                    currentBatch = new List <ModelPose> {
                        modelPose
                    };
                    currentBounds = boundingRectangle;
                }
                else
                {
                    currentBatch.Add(modelPose);
                    currentBounds = BoundingRectangle.CreateMerged(currentBounds, boundingRectangle);
                }
            }

            if (currentBatch.Count > 0)
            {
                batches.Add(currentBatch);
            }

            return(batches);
        }