コード例 #1
0
        /// <summary>
        /// Loads a new 3D model file into the ModelViewerControl.
        /// </summary>
        FyriModel LoadModelToProject(string fileName)
        {
            if (currentProject != null)
            {
                Cursor = Cursors.WaitCursor;

                FyriModel loadedModel = modelManager.LoadModel(fileName);

                if (loadedModel != null)
                {
                    if (!currentProject.LoadedModels.Exists(p => p.OriginalFileName == fileName))
                    {
                        currentProject.LoadedModels.Add(loadedModel);
                    }

                    //modelViewerControl.Model = loadedModel.Model;
                    AddModelToTreeView(loadedModel);
                }
                Cursor = Cursors.Arrow;

                return(loadedModel);
            }

            return(null);
        }
コード例 #2
0
        void AddModelToTreeView(FyriModel modelToAdd)
        {
            if (ModelNode == null)
            {
                if (AssetsNode == null)
                {
                    AssetsNode      = new TreeNode();
                    AssetsNode.Text = "Assets";
                    ProjectNameNode.Nodes.Add(AssetsNode);
                }
                ModelNode      = new TreeNode();
                ModelNode.Text = "Models";
                AssetsNode.Nodes.Add(ModelNode);
            }

            TreeNode nodeToAdd = new TreeNode();

            nodeToAdd.Text = modelToAdd.ModelName;
            nodeToAdd.Tag  = modelToAdd;

            ModelNode.Nodes.Add(nodeToAdd);

            contentTreeView.CollapseAll();
            nodeToAdd.EnsureVisible();
            contentTreeView.Refresh();
        }
コード例 #3
0
        private void projectContentTV_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode selectedNode = projectContentTV.SelectedNode;

            if (selectedNode != null)
            {
                if (selectedNode.Tag != null)
                {
                    if (selectedNode.Tag is FyriModel)
                    {
                        FyriModel model = selectedNode.Tag as FyriModel;
                        //modelViewerControl.Model = model.Model;
                    }
                }
            }
        }
コード例 #4
0
        void AddModelToTreeView(FyriModel modelToAdd)
        {
            if (ModelNode == null)
            {
                ModelNode      = new TreeNode();
                ModelNode.Text = "Models";
                //ProjectNameNode.Nodes.Add(ModelNode);
            }

            TreeNode nodeToAdd = new TreeNode();

            nodeToAdd.Text = modelToAdd.ModelName;
            nodeToAdd.Tag  = modelToAdd;

            ModelNode.Nodes.Add(nodeToAdd);

            //projectContentTV.CollapseAll();
            nodeToAdd.EnsureVisible();
            //projectContentTV.Refresh();
        }
コード例 #5
0
        public FyriModel LoadModel(string fileName)
        {
            if (modelList.FirstOrDefault(p => p.OriginalFileName == fileName) != null)
            {
                return(modelList.FirstOrDefault(p => p.OriginalFileName == fileName));
            }

            FyriModel newlyAddedModel = new FyriModel();

            newlyAddedModel.OriginalFileName = fileName;

            string pathToMoveTo = ProjectOriginalContentFolder + "\\" + Path.GetFileName(fileName);

            if (!File.Exists(pathToMoveTo))
            {
                File.Copy(fileName, pathToMoveTo);
            }
            newlyAddedModel.FileName = pathToMoveTo;

            newlyAddedModel.XnbFileLocation = contentBuilder.OutputDirectory;

            string modelName = Path.GetFileNameWithoutExtension(fileName);

            newlyAddedModel.ModelName = modelName;

            Model loadedModel = null;

            string xnbFileLoc    = newlyAddedModel.XnbFileLocation + "\\" + modelName + ".xnb";
            bool   xnbFileExists = File.Exists(xnbFileLoc);

            if (!xnbFileExists)
            {
                // Unload any existing model.
                //xna2dEditorControl.Model = null;
                //contentManager.Unload();

                // Tell the ContentBuilder what to build.
                contentBuilder.Clear();

                contentBuilder.Add(fileName, modelName, null, "ModelProcessor");

                // Build this new model data.
                string buildError = contentBuilder.Build();

                if (string.IsNullOrEmpty(buildError))
                {
                    // If the build succeeded, use the ContentManager to
                    // load the temporary .xnb file that we just created.
                    loadedModel = contentManager.Load <Model>(modelName);
                }
                else
                {
                    // If the build failed, display an error message.
                    MessageBox.Show(buildError, "Error");
                    return(null);
                }
            }
            else
            {
                loadedModel = contentManager.Load <Model>(modelName);
            }

            if (loadedModel != null)
            {
                newlyAddedModel.Model = loadedModel;
            }
            else
            {
                return(null);
            }

            modelList.Add(newlyAddedModel);
            return(newlyAddedModel);
        }
コード例 #6
0
        public FyriModel GetModel(string modelName)
        {
            FyriModel modelToReturn = modelList.FirstOrDefault(p => p.ModelName == modelName);

            return(modelToReturn);
        }