Пример #1
0
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            //we always want to generate tangent frames, as we use tangent space normal mapping
            GenerateTangentFrames = true;

            //merge transforms
            MeshHelper.TransformScene(input, input.Transform);
            input.Transform = Matrix.Identity;

            if (!_isSkinned)
                MergeTransforms(input);

            ModelContent model = base.Process(input, context);
            //gather some information that will be useful in run time
            MeshMetadata metadata = new MeshMetadata();
            BoundingBox aabb = new BoundingBox();
            metadata.BoundingBox = ComputeBoundingBox(input, ref aabb, metadata);

            //assign it to our Tag
            model.Tag = metadata;
            return model;
        }
Пример #2
0
        private BoundingBox ComputeBoundingBox(NodeContent input, ref BoundingBox aabb, MeshMetadata metadata)
        {
            BoundingBox boundingBox;
            if (input is MeshContent)
            {
                MeshContent mc = (MeshContent)input;
                MeshHelper.TransformScene(mc, mc.Transform);
                mc.Transform = Matrix.Identity;

                boundingBox = BoundingBox.CreateFromPoints(mc.Positions);
                //create sub mesh information
                MeshMetadata.SubMeshMetadata subMeshMetadata = new MeshMetadata.SubMeshMetadata();
                subMeshMetadata.BoundingBox = boundingBox;
                subMeshMetadata.RenderQueue = _renderQueue;
                subMeshMetadata.CastShadows = CastShadows;
                metadata.AddSubMeshMetadata(subMeshMetadata);
                if (metadata.SubMeshesMetadata.Count > 1)
                    boundingBox = BoundingBox.CreateMerged(boundingBox, aabb);
            }
            else
            {
                boundingBox = aabb;
            }

            foreach (NodeContent c in input.Children)
            {
                boundingBox = BoundingBox.CreateMerged(boundingBox, ComputeBoundingBox(c, ref boundingBox, metadata));
            }
            return boundingBox;
        }