예제 #1
0
        protected override Model ReadContent(IContentManager readerManager, GraphicsDevice device, ref ContentReaderParameters parameters)
        {
            var readerOptions = parameters.Options as ModelContentReaderOptions;

            if (parameters.Options != null && readerOptions == null)
            {
                throw new ArgumentException("Invalid options. Must be instance of ModelContentReaderOptions", "options");
            }

            var assetPath = Path.GetDirectoryName(parameters.AssetName);

            // Loads the model.
            var model = Model.Load(device, parameters.Stream, name =>
            {
                // Try to load the texture with its texture path as is
                // otherwise try to load with tkb extension
                var texturePath = Path.Combine(assetPath ?? string.Empty, name);
                if (!readerManager.Exists(texturePath))
                {
                    // Use the extension tkb to load a texture
                    texturePath = Path.ChangeExtension(texturePath, "tkb");
                }

                // If the texture exists, return it, otherwise return null without throwing an exception.
                return(readerManager.Exists(texturePath) ? readerManager.Load <Texture>(texturePath) : null);
            });

            if (model == null)
            {
                return(null);
            }

            // If the model has no name, use filename
            if (model.Name == null)
            {
                model.Name = Path.GetFileName(parameters.AssetName);
            }

            // Applies the Effect installer on the model.
            bool disableInstaller = readerOptions != null && readerOptions.DisableEffectInstaller;

            if (!disableInstaller)
            {
                IEffectInstaller effectInstaller;
                if (readerOptions != null && readerOptions.EffectInstaller != null)
                {
                    effectInstaller = readerOptions.EffectInstaller;
                }
                else
                {
                    effectInstaller = new BasicEffectInstaller(device);
                }

                effectInstaller.Apply(model);
            }

            return(model);
        }
예제 #2
0
        /// <summary>
        /// Check if the specified asset url exists.
        /// </summary>
        /// <param name="content">The <see cref="IContentManager"/>.</param>
        /// <param name="urlReference">The URL.</param>
        /// <returns><c>true</c> if the specified asset url exists, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="urlReference"/> is <c>null</c> or <c>empty</c>. Or <paramref name="content"/> is <c>null</c>.</exception>
        public static bool Exists(this IContentManager content, IUrlReference urlReference)
        {
            CheckArguments(content, urlReference);

            return(content.Exists(urlReference.Url));
        }