예제 #1
0
        public void LoadFile(string fileName, XnaBuildProperties buildProperties)
        {
            _fillModeSolid.Enabled             = true;
            _fillModeWireframe.Enabled         = true;
            _fillModeSolidAndWireframe.Enabled = true;
            _normals.Enabled           = true;
            _alphaBlend.Enabled        = true;
            _textureSize.Enabled       = true;
            _boundingBox.Enabled       = true;
            _primitiveSphere.Enabled   = true;
            _primitiveCube.Enabled     = true;
            _primitiveCylinder.Enabled = true;
            _primitiveTorus.Enabled    = true;
            _primitivePlane.Enabled    = true;
            _primitiveTeapot.Enabled   = true;

            AssetType assetType = ((ContentPreviewToolWindowControl)base.Content).LoadFile(fileName, buildProperties);

            switch (assetType)
            {
            case AssetType.Model:
                _primitiveSphere.Enabled   = false;
                _primitiveCube.Enabled     = false;
                _primitiveCylinder.Enabled = false;
                _primitiveTorus.Enabled    = false;
                _primitivePlane.Enabled    = false;
                _primitiveTeapot.Enabled   = false;

                _textureSize.Enabled = false;
                break;

            case AssetType.Texture:
                _fillModeSolid.Enabled             = false;
                _fillModeWireframe.Enabled         = false;
                _fillModeSolidAndWireframe.Enabled = false;
                _normals.Enabled           = false;
                _alphaBlend.Enabled        = false;
                _boundingBox.Enabled       = false;
                _primitiveSphere.Enabled   = false;
                _primitiveCube.Enabled     = false;
                _primitiveCylinder.Enabled = false;
                _primitiveTorus.Enabled    = false;
                _primitivePlane.Enabled    = false;
                _primitiveTeapot.Enabled   = false;


                _textureSize.Enabled = true;
                break;
            }

            //bool isModelLoaded = ((ContentPreviewToolWindowControl) base.Content).IsModelLoaded;
            //_fillModeSolid.Enabled = _fillModeWireframe.Enabled = isModelLoaded;

            ChangeFillMode();
            ChangePrimitive();
            ShowNormals();
            ShowBoundingBox();
        }
예제 #2
0
        public void ShowPreview(IVsHierarchy hierarchy, uint itemID, string fileName)
        {
            if (FileExtensionUtility.IsInspectableFile(_optionsService, fileName))
            {
                ContentPreviewToolWindow window = ShowPreviewInternal();

                XnaBuildProperties buildProperties = VsHelper.GetXnaBuildProperties(hierarchy, itemID);
                window.LoadFile(fileName, buildProperties);
            }
        }
        /// <summary>
        /// Loads a new XNA asset file into the ModelViewerControl.
        /// </summary>
        public AssetType LoadFile(string fileName, XnaBuildProperties buildProperties)
        {
            if (!_loaded)
            {
                return(AssetType.None);
            }

            // Unload any existing content.
            graphicsDeviceControl.AssetRenderer = null;
            AssetHandler assetHandler = _assetHandlers.GetAssetHandler(fileName);

            assetHandler.ResetRenderer();

            windowsFormsHost.Visibility = Visibility.Collapsed;
            txtInfo.Text       = "Loading...";
            txtInfo.Visibility = Visibility.Visible;

            // Load asynchronously.
            var           ui       = TaskScheduler.FromCurrentSynchronizationContext();
            Task <string> loadTask = new Task <string>(() =>
            {
                _contentManager.Unload();

                // Tell the ContentBuilder what to build.
                _contentBuilder.Clear();
                _contentBuilder.SetReferences(buildProperties.ProjectReferences);

                string assetName = fileName;
                foreach (char c in Path.GetInvalidFileNameChars())
                {
                    assetName = assetName.Replace(c.ToString(), string.Empty);
                }
                assetName = Path.GetFileNameWithoutExtension(assetName);
                _contentBuilder.Add(fileName, assetName, buildProperties.Importer,
                                    buildProperties.Processor ?? assetHandler.ProcessorName,
                                    buildProperties.ProcessorParameters);

                // Build this new model data.
                string buildErrorInternal = _contentBuilder.Build();

                if (string.IsNullOrEmpty(buildErrorInternal))
                {
                    // If the build succeeded, use the ContentManager to
                    // load the temporary .xnb file that we just created.
                    assetHandler.LoadContent(assetName);

                    graphicsDeviceControl.AssetRenderer = assetHandler.Renderer;
                }

                return(buildErrorInternal);
            });

            loadTask.ContinueWith(t =>
            {
                string buildError = t.Result;
                if (!string.IsNullOrEmpty(buildError))
                {
                    // If the build failed, display an error message.
                    txtInfo.Text = "Uh-oh. Something went wrong. Check the Output window for details.";
                    XBuilderWindowPane.WriteLine(buildError);
                }
                else
                {
                    windowsFormsHost.Visibility = Visibility.Visible;
                    txtInfo.Visibility          = Visibility.Hidden;
                }
            }, ui);

            loadTask.Start();

            return(_assetHandlers.GetAssetType(fileName));
        }