Esempio n. 1
0
        /// <summary>
        /// Called by the framework when importing a game asset. This is the method called by XNA when
        /// an asset is to be imported into an object that can be recognized by the Content Pipeline.
        /// </summary>
        /// <param name="filename">Name of a game asset file.</param>
        /// <param name="context">
        /// Contains information for importing a game asset, such as a logger interface.
        /// </param>
        /// <returns>Resulting game asset.</returns>
        public override NodeContent Import(string filename, ContentImporterContext context)
        {
            var wrappedContext   = new ContentPipelineContext(context);
            var identity         = new ContentIdentity(filename);
            var modelDescription = ModelDescription.Load(filename, wrappedContext, false);

            if (modelDescription == null)
            {
                throw new InvalidContentException("Error loading model description.", identity);
            }

            return(new DeferredNodeContent(modelDescription)
            {
                Identity = identity
            });
        }
Esempio n. 2
0
        /*
         * /// <summary>
         * /// Gets or sets the value of the <strong>X Axis Rotation</strong> processor parameter.
         * /// </summary>
         * /// <value>The amount of rotation, in degrees, around the x-axis.</value>
         * [DefaultValue(0f)]
         * [DisplayName("X Axis Rotation")]
         * [Description("Rotates the model a specified number of degrees around the x-axis.")]
         * public virtual float RotationX
         * {
         * get { return _rotationX; }
         * set { _rotationX = value; }
         * }
         * private float _rotationX;
         *
         *
         * /// <summary>
         * /// Gets or sets the value of the <strong>Y Axis Rotation</strong> processor parameter.
         * /// </summary>
         * /// <value>The amount of rotation, in degrees, around the y-axis.</value>
         * [DefaultValue(0f)]
         * [DisplayName("Y Axis Rotation")]
         * [Description("Rotates the model a specified number of degrees around the y-axis.")]
         * public virtual float RotationY
         * {
         * get { return _rotationY; }
         * set { _rotationY = value; }
         * }
         * private float _rotationY;
         *
         *
         * /// <summary>
         * /// Gets or sets the value of the <strong>Z Axis Rotation</strong> processor parameter.
         * /// </summary>
         * /// <value>The amount of rotation, in degrees, around the z-axis.</value>
         * [DefaultValue(0f)]
         * [DisplayName("Z Axis Rotation")]
         * [Description("Rotates the model a specified number of degrees around the z-axis.")]
         * public virtual float RotationZ
         * {
         * get { return _rotationZ; }
         * set { _rotationZ = value; }
         * }
         * private float _rotationZ;
         *
         *
         * /// <summary>
         * /// Gets or sets the value of the <strong>Scale</strong> processor parameter.
         * /// </summary>
         * /// <value>The scaling factor to be applied.</value>
         * [DefaultValue(1f)]
         * [DisplayName("Scale")]
         * [Description("Scales the model uniformly along all three axes.")]
         * public virtual float Scale
         * {
         * get { return _scale; }
         * set { _scale = value; }
         * }
         * private float _scale = 1f;
         */
        #endregion


        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        /// <summary>
        /// Converts mesh content to model content.
        /// </summary>
        /// <param name="input">The root node content.</param>
        /// <param name="context">Contains any required custom process parameters.</param>
        /// <returns>The model content.</returns>
        public override DRModelNodeContent Process(NodeContent input, ContentProcessorContext context)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // The content processor may write text files. We want to use invariant culture number formats.
            // TODO: Do not set Thread.CurrentThread.CurrentCulture. Make sure that all read/write operations explicitly use InvariantCulture.
            var originalCulture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            try
            {
                // Uncomment this to launch and attach a debugger.
                //System.Diagnostics.Debugger.Launch();

                // Uncomment this to visualize the content tree.
                //ContentHelper.PrintContentTree(input, context);

                _context = context;

                var delayedNode = input as DeferredNodeContent;
                if (delayedNode != null)
                {
                    // Model description was imported.
                    _modelDescription = delayedNode.ModelDescription;

                    // Load the model.
                    delayedNode.Import(context);
                    _input = input;
                }
                else
                {
                    // The model was imported.
                    _input = input;

                    // Load the model description.
                    var wrappedContext = new ContentPipelineContext(context);
                    if (input.Identity != null && input.Identity.SourceFilename != null)
                    {
                        _modelDescription = ModelDescription.Load(input.Identity.SourceFilename, wrappedContext, CreateMissingModelDescription);
                    }
                }

                if (_modelDescription != null)
                {
                    _modelDescription.Validate(_input, _context);
                }

                ValidateInput();

                // Try to find skeleton root bone.
                _rootBone = MeshHelper.FindSkeleton(input);
                if (_rootBone != null)
                {
#if ANIMATION
                    MergeAnimationFiles();
#endif
                    BakeTransforms(input);
                    TransformModel();
#if ANIMATION
                    BuildSkeleton();
                    BuildAnimations();
#endif
                    SetSkinnedMaterial();
                }
                else
                {
                    TransformModel();
                }

                BuildSceneGraph();
                PrepareMaterials();
                BuildMeshes();
                BuildOccluders();
                CombineLodGroups();
                ValidateOutput();

                _model.Name = Path.GetFileNameWithoutExtension(context.OutputFilename);
            }
            finally
            {
                // Clean up.
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }

            return(_model);
        }