private void Reset()
        {
            StopAnimation();

            _monoGameContent?.Dispose();
            _monoGameContent = null;

            Debug.Assert(ModelNode == null || ModelNode.IsDisposed, "ModelNode should be disposed together with the ContentManager.");
            ModelNode = null;
            Model     = null;

            _tempDirectoryHelper?.Dispose();
            _tempDirectoryHelper = null;

            _assimpScene = null;

            if (_outlineService != null && _outlineService.Outline == Outline)
            {
                _outlineService.Outline = null;
            }

            if (_propertiesService != null && _propertiesService.PropertySource == _currentPropertySource)
            {
                _propertiesService.PropertySource = null;
            }

            CleanErrors();
        }
        private static Tuple <string, TempDirectoryHelper> BuildXnb(IServiceLocator services, string applicationName, string fileName, bool createModelNode, bool recreateModelAndMaterialFiles)
        {
            Debug.Assert(services != null);
            Debug.Assert(applicationName != null);
            Debug.Assert(applicationName.Length > 0);
            Debug.Assert(fileName != null);
            Debug.Assert(fileName.Length > 0);

            var tempDirectoryHelper = new TempDirectoryHelper(applicationName, "ModelDocument");

            try
            {
                var contentBuilder = new GameContentBuilder(services)
                {
                    IntermediateFolder = tempDirectoryHelper.TempDirectoryName + "\\obj",
                    OutputFolder       = tempDirectoryHelper.TempDirectoryName + "\\bin",
                };

                string processorName;
                var    processorParams = new OpaqueDataDictionary();
                if (createModelNode)
                {
                    processorName = "GameModelProcessor";
                    processorParams.Add("RecreateModelDescriptionFile", recreateModelAndMaterialFiles);
                    processorParams.Add("RecreateMaterialDefinitionFiles", recreateModelAndMaterialFiles);
                }
                else
                {
                    processorName = "ModelProcessor";
                }

                string errorMessage;
                bool   success = contentBuilder.Build(Path.GetFullPath(fileName), null, processorName, processorParams, out errorMessage);
                if (!success)
                {
                    throw new EditorException(Invariant($"Could not process 3d model: {fileName}.\n See output window for details."));
                }

                // Return output folder into which we built the XNB.
                var outputFolder = contentBuilder.OutputFolder;
                if (!Path.IsPathRooted(outputFolder))
                {
                    outputFolder = Path.GetFullPath(Path.Combine(contentBuilder.ExecutableFolder, contentBuilder.OutputFolder));
                }

                return(Tuple.Create(outputFolder, tempDirectoryHelper));
            }
            catch
            {
                tempDirectoryHelper.Dispose();
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// Releases the unmanaged resources used by an instance of the
        /// <see cref="XnaContentBuilder"/> class and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">
        /// <see langword="true"/> to release both managed and unmanaged resources;
        /// <see langword="false"/> to release only unmanaged resources.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
                if (disposing)
                {
                    // Dispose managed resources.
                    _tempDirectoryHelper.Dispose();
                }

                // Release unmanaged resources.

                IsDisposed = true;
            }
        }
Exemple #4
0
        private static Tuple<string, TempDirectoryHelper> BuildXnb(IServiceLocator services, string applicationName, string fileName, bool createModelNode, bool recreateModelAndMaterialFiles)
        {
            Debug.Assert(services != null);
            Debug.Assert(applicationName != null);
            Debug.Assert(applicationName.Length > 0);
            Debug.Assert(fileName != null);
            Debug.Assert(fileName.Length > 0);

            var tempDirectoryHelper = new TempDirectoryHelper(applicationName, "ModelDocument");
            try
            {
                var contentBuilder = new GameContentBuilder(services)
                {
                    IntermediateFolder = tempDirectoryHelper.TempDirectoryName + "\\obj",
                    OutputFolder = tempDirectoryHelper.TempDirectoryName + "\\bin",
                };

                string processorName;
                var processorParams = new OpaqueDataDictionary();
                if (createModelNode)
                {
                    processorName = "GameModelProcessor";
                    processorParams.Add("RecreateModelDescriptionFile", recreateModelAndMaterialFiles);
                    processorParams.Add("RecreateMaterialDefinitionFiles", recreateModelAndMaterialFiles);
                }
                else
                {
                    processorName = "ModelProcessor";
                }

                string errorMessage;
                bool success = contentBuilder.Build(Path.GetFullPath(fileName), null, processorName, processorParams, out errorMessage);
                if (!success)
                    throw new EditorException(Invariant($"Could not process 3d model: {fileName}.\n See output window for details."));

                // Return output folder into which we built the XNB.
                var outputFolder = contentBuilder.OutputFolder;
                if (!Path.IsPathRooted(outputFolder))
                    outputFolder = Path.GetFullPath(Path.Combine(contentBuilder.ExecutableFolder, contentBuilder.OutputFolder));

                return Tuple.Create(outputFolder, tempDirectoryHelper);
            }
            catch
            {
                tempDirectoryHelper.Dispose();
                throw;
            }
        }