Ejemplo n.º 1
0
        /// <summary>
        /// Loads a new 3D model file into the Game Project and displays
        /// it in the editorViewerControl.
        /// </summary>
        private void LoadModel(string fileName, bool fromBackup = false)
        {
            Cursor = Cursors.WaitCursor;

            // Determine the model's path
            string path = Path.Combine("Models", Path.GetFileNameWithoutExtension(fileName));

            string buildError = null;

            if (!fromBackup)
            {
                // Tell the ContentBuilder what to build.
                contentBuilder.Clear();
                contentBuilder.Add(fileName, path, null, "ModelProcessor");

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

            if (string.IsNullOrEmpty(buildError))
            {
                // If the build succeeded, use the ContentManager to
                // load the temporary .xnb file that we just created.
                Model model = contentManager.Load <Model>(path);

                // Display the model in our EditorViewerControl
                if (!fromBackup)
                {
                    editorViewerControl.Model = model;
                }

                // Also store the model in our game manifest
                gameManifest.Models[path] = model;

                // Backup the Xnb files for this object so that they
                // can be used later to save the object
                BackupXnbFiles();
            }
            else
            {
                // If the build failed, display an error message.
                MessageBox.Show(buildError, "Error");
            }

            if (!fromBackup)
            {
                Cursor = Cursors.Arrow;
            }
        }
Ejemplo n.º 2
0
        private void loadTextures()
        {
            // Determine the texture's path
            string[]    textureFiles = { "grass.jpg", "stone.jpg", "wood.png" };
            Texture2D[] textures     = new Texture2D[textureFiles.Length];
            //string fileName = textureFiles[0];
            for (int textureNum = 0; textureNum < textureFiles.Length; textureNum++)
            {
                string fileName = (Path.GetFullPath(Path.Combine(Assembly.GetExecutingAssembly().Location, "../../../../Content/Textures/")) + (textureFiles[textureNum]));
                string path     = Path.Combine("Textures", Path.GetFileNameWithoutExtension(fileName));

                // Tell the ContentBuilder what to build.
                contentBuilder.Clear();
                contentBuilder.Add(fileName, path, null, "TextureProcessor");

                // Build this new texture 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.
                    textures[textureNum] = contentManager.Load <Texture2D>(path);

                    // Store the texture in our game manifest
                    // gameManifest.Textures.Add(path, texture);
                }
                else
                {
                    // If the build failed, display an error message.
                    MessageBox.Show(buildError, "Error");
                }
            }

            grassTexture = textures[0];
            stoneTexture = textures[1];
            woodTexture  = textures[2];
        }