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(); }
public static XnaBuildProperties GetXnaBuildProperties(IVsHierarchy hierarchy, uint itemID) { XnaBuildProperties buildProperties = new XnaBuildProperties(); // Get project object for specified hierarchy. VSProject project = GetProject(hierarchy); if (project == null) throw new InvalidOperationException("Could not find content project for this item."); // Get references from project. int referenceCount = project.References.Count; for (int i = 1; i <= referenceCount; ++i) { Reference reference = project.References.Item(i); buildProperties.ProjectReferences.Add(reference.Path); } IVsBuildPropertyStorage buildPropertyStorage = (IVsBuildPropertyStorage) hierarchy; string importer; buildPropertyStorage.GetItemAttribute(itemID, XnaConstants.Importer, out importer); if (!string.IsNullOrEmpty(importer)) buildProperties.Importer = importer; string processor; buildPropertyStorage.GetItemAttribute(itemID, XnaConstants.Processor, out processor); if (!string.IsNullOrEmpty(processor)) buildProperties.Processor = processor; if (buildProperties.Processor == null) return buildProperties; // TODO: Look into caching ContentPipelineManager, but then we need to take care of refreshing it // when the content project references change. ContentPipelineManager contentPipelineManager = new ContentPipelineManager(project.References, XnaConstants.XnaFrameworkVersion); var processorParameters = contentPipelineManager.GetProcessorParameters(buildProperties.Processor); foreach (IParameterDescriptor processorParameter in processorParameters) { string propertyValue; buildPropertyStorage.GetItemAttribute(itemID, XnaConstants.ProcessorParametersPrefix + processorParameter.PropertyName, out propertyValue); buildProperties.ProcessorParameters.Add(XnaConstants.ProcessorParametersPrefix + processorParameter.PropertyName, propertyValue); } /* // Cannot use MSBuild object model because it uses a static instance of the Engine. XDocument projectDocument = XDocument.Load(project.Project.FullName); string projectFolder = Path.GetDirectoryName(project.Project.FullName); var projectItem = projectDocument.Descendants().FirstOrDefault(n => { XAttribute attr = n.Attribute("Include"); if (attr == null) return false; string includeValue = attr.Value; return string.Equals(Path.Combine(projectFolder, includeValue), fileName, StringComparison.InvariantCultureIgnoreCase); }); if (projectItem == null) throw new InvalidOperationException("Could not find item in project."); if (projectItem.Element(PropertyNames.Importer) != null) buildProperties.Importer = projectItem.Element(PropertyNames.Importer).Value; if (projectItem.Element(PropertyNames.Processor) != null) buildProperties.Processor = projectItem.Element(PropertyNames.Processor).Value; foreach (XElement processorParameter in projectItem.Elements().Where(e => e.Name.LocalName.StartsWith(PropertyNames.ProcessorParametersPrefix))) buildProperties.ProcessorParameters.Add(processorParameter.Name.LocalName, processorParameter.Value); * */ return 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); }
public static XnaBuildProperties GetXnaBuildProperties(IVsHierarchy hierarchy, uint itemID) { XnaBuildProperties buildProperties = new XnaBuildProperties(); // Get project object for specified hierarchy. VSProject project = GetProject(hierarchy); if (project == null) { throw new InvalidOperationException("Could not find content project for this item."); } // Get references from project. int referenceCount = project.References.Count; for (int i = 1; i <= referenceCount; ++i) { Reference reference = project.References.Item(i); buildProperties.ProjectReferences.Add(reference.Path); } IVsBuildPropertyStorage buildPropertyStorage = (IVsBuildPropertyStorage)hierarchy; string importer; buildPropertyStorage.GetItemAttribute(itemID, XnaConstants.Importer, out importer); if (!string.IsNullOrEmpty(importer)) { buildProperties.Importer = importer; } string processor; buildPropertyStorage.GetItemAttribute(itemID, XnaConstants.Processor, out processor); if (!string.IsNullOrEmpty(processor)) { buildProperties.Processor = processor; } if (buildProperties.Processor == null) { return(buildProperties); } // TODO: Look into caching ContentPipelineManager, but then we need to take care of refreshing it // when the content project references change. ContentPipelineManager contentPipelineManager = new ContentPipelineManager(project.References, XnaConstants.XnaFrameworkVersion); var processorParameters = contentPipelineManager.GetProcessorParameters(buildProperties.Processor); foreach (IParameterDescriptor processorParameter in processorParameters) { string propertyValue; buildPropertyStorage.GetItemAttribute(itemID, XnaConstants.ProcessorParametersPrefix + processorParameter.PropertyName, out propertyValue); buildProperties.ProcessorParameters.Add(XnaConstants.ProcessorParametersPrefix + processorParameter.PropertyName, propertyValue); } /* * // Cannot use MSBuild object model because it uses a static instance of the Engine. * XDocument projectDocument = XDocument.Load(project.Project.FullName); * string projectFolder = Path.GetDirectoryName(project.Project.FullName); * * var projectItem = projectDocument.Descendants().FirstOrDefault(n => * { * XAttribute attr = n.Attribute("Include"); * if (attr == null) * return false; * * string includeValue = attr.Value; * return string.Equals(Path.Combine(projectFolder, includeValue), fileName, StringComparison.InvariantCultureIgnoreCase); * }); * if (projectItem == null) * throw new InvalidOperationException("Could not find item in project."); * * if (projectItem.Element(PropertyNames.Importer) != null) * buildProperties.Importer = projectItem.Element(PropertyNames.Importer).Value; * if (projectItem.Element(PropertyNames.Processor) != null) * buildProperties.Processor = projectItem.Element(PropertyNames.Processor).Value; * * foreach (XElement processorParameter in projectItem.Elements().Where(e => e.Name.LocalName.StartsWith(PropertyNames.ProcessorParametersPrefix))) * buildProperties.ProcessorParameters.Add(processorParameter.Name.LocalName, processorParameter.Value); * */ return(buildProperties); }