예제 #1
0
        static void Main(string[] args)
        {
            try
            {
                ServiceContainer Services = new ServiceContainer();

                Builder         = new ContentBuilder();
                ContentExternal = new ContentManager(Services, "../Content/");

                string[] Files;

                #region Ressources building

                #region Units map icons

                Files = Directory.GetFiles("../Content/Units", "*.png", SearchOption.AllDirectories);
                // Tell the ContentBuilder what to build.
                for (int F = 0; F < Files.Count(); F++)
                {
                    if (!File.Exists(Path.ChangeExtension(Files[F], ".xnb")))
                    {
                        Builder.Add(Path.GetFullPath(Files[F]), Files[F].Substring(0, Files[F].Length - 4).Remove(0, 11), "TextureImporter", "TextureProcessor");
                    }
                }

                #endregion

                #region Map tilesets

                Files = Directory.GetFiles("../Content/Maps/Tilesets", "*.png", SearchOption.AllDirectories);
                // Tell the ContentBuilder what to build.
                for (int F = 0; F < Files.Count(); F++)
                {
                    if (!File.Exists(Path.ChangeExtension(Files[F], ".xnb")))
                    {
                        Builder.Add(Path.GetFullPath(Files[F]), Files[F].Substring(0, Files[F].Length - 4).Remove(0, 11), "TextureImporter", "TextureProcessor");
                    }
                }

                #endregion

                // Build this new model data.
                string buildError = Builder.Build();
                if (!string.IsNullOrEmpty(buildError))
                {
                    throw new Exception(buildError);
                }

                #endregion
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.Read();
            }
        }
        void LoadModel(string fileName)
        {
            Cursor = Cursors.WaitCursor;

            // Unload any existing model.
            modelViewerControl1.Model = null;
            contentManager.Unload();

            // Tell the ContentBuilder what to build.
            contentBuilder.Clear();
            contentBuilder.Add(fileName, "Model", 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.
                modelViewerControl1.Model = contentManager.Load <Model>("Model");
            }
            else
            {
                // If the build failed, display an error message.
                MessageBox.Show(buildError, "Error");
            }

            Cursor = Cursors.Arrow;
        }
예제 #3
0
        public void GenerateBabylonFile(string file, string outputFile, bool skinned)
        {
            if (OnImportProgressChanged != null)
            {
                OnImportProgressChanged(0);
            }


            var scene = new BabylonScene(Path.GetDirectoryName(outputFile));

            var services = new ServiceContainer();

            // Create a graphics device
            var form = new Form();

            services.AddService <IGraphicsDeviceService>(BabylonExport.Core.Exporters.FBX.GraphicsDeviceService.AddRef(form.Handle, 1, 1));

            var contentBuilder = new ContentBuilder();
            var contentManager = new ContentManager(services, contentBuilder.OutputDirectory);

            // Tell the ContentBuilder what to build.
            contentBuilder.Clear();
            contentBuilder.Add(Path.GetFullPath(file), "Model", null, skinned ? "SkinnedModelProcessor" : "ModelProcessor");

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

            if (string.IsNullOrEmpty(buildError))
            {
                var model = contentManager.Load <Model>("Model");
                ParseModel(model, scene);
            }
            else
            {
                throw new Exception(buildError);
            }

            // Output
            scene.Prepare();
            using (var outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write))
            {
                var ser = new DataContractJsonSerializer(typeof(BabylonScene));
                ser.WriteObject(outputStream, scene);
            }

            // Cleaning
            foreach (var path in exportedTexturesFilename.Values)
            {
                File.Delete(path);
            }

            if (OnImportProgressChanged != null)
            {
                OnImportProgressChanged(100);
            }
        }
예제 #4
0
        public void GenerateBabylonFile(string file, string outputFile, bool skinned, bool rightToLeft)
        {
            if (OnImportProgressChanged != null)
                OnImportProgressChanged(0);


            var scene = new BabylonScene(Path.GetDirectoryName(outputFile));

            var services = new ServiceContainer();

            // Create a graphics device
            var form = new Form();
            
            services.AddService<IGraphicsDeviceService>(GraphicsDeviceService.AddRef(form.Handle, 1, 1));

            var contentBuilder = new ContentBuilder(ExtraPipelineAssemblies);
            var contentManager = new ContentManager(services, contentBuilder.OutputDirectory);

            // Tell the ContentBuilder what to build.
            contentBuilder.Clear();
            contentBuilder.Add(Path.GetFullPath(file), "Model", Importer, skinned ? "SkinnedModelProcessor" : "ModelProcessor");

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

            if (string.IsNullOrEmpty(buildError))
            {
                var model = contentManager.Load<Model>("Model");
                ParseModel(model, scene, rightToLeft);
            }
            else
            {
                throw new Exception(buildError);
            }

            // Output
            scene.Prepare();
            using (var outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write))
            {
                var ser = new DataContractJsonSerializer(typeof(BabylonScene));
                ser.WriteObject(outputStream, scene);
            }

            // Cleaning
            foreach (var path in exportedTexturesFilename.Values)
            {
                File.Delete(path);
            }

            if (OnImportProgressChanged != null)
                OnImportProgressChanged(100);
        }
 private void CreateInternalTexture(String fileName)
 {
     if (!textureLoaded.ContainsKey(fileName))
     {
         ContentBuilder.Clear();
         String iname = "Texture" + StaticRandom.Random();
         ContentBuilder.Add(fileName, iname, null, "TextureProcessor");
         String buildError = ContentBuilder.Build();
         if (string.IsNullOrEmpty(buildError))
         {
             if (!Directory.Exists(Directory.GetCurrentDirectory() + "/Content/Loaded"))
             {
                 Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/Content/Loaded");
             }
             MakeCopy(ContentBuilder.OutputDirectory, Directory.GetCurrentDirectory() + "/Content/Loaded/");
             textureLoaded.Add(fileName, iname);
         }
         else
         {
             throw new Exception(buildError);
         }
     }
 }
예제 #6
0
        public void ImportHeightMapAndGridMap(string heightmapFile, string gridmapFile = null)
        {
            if (File.Exists(heightmapFile))
            {
                heightmapContent = new ContentManager(graphicsDeviceControl1.Services, contentBuilder.OutputDirectory);
                contentBuilder.Add(heightmapFile, "heightmap", null, "TextureProcessor");
                bool gridmapFileExists = !string.IsNullOrEmpty(gridmapFile) && File.Exists(gridmapFile);
                if (gridmapFileExists)
                {
                    contentBuilder.Add(gridmapFile, "gridmap", null, "TextureProcessor");
                }
                contentBuilder.Build();
                camera.Detach(Terrain.TerrainIndexer);
                Terrain         = new Terrain(GraphicsDevice, camera, heightmapContent.Load <Texture2D>("heightmap"), heightmapFile, effectFile, terrainTextureFile);
                Terrain.Texture = grassTexture;

                terrainBrush.Terrain = Terrain;

                if (gridmapFileExists)
                {
                    List <string> assets = Grid.RoadAssetFiles;
                    Grid                 = new Grid(Terrain, 8, camera, GraphicsDevice, basicEffect);
                    Grid.RoadModel       = contentManager.Load <Model>("jalan_raya");
                    Grid.RoadModel_belok = contentManager.Load <Model>("jalan_raya_belok");
                    Grid.GridMapFile     = gridmapFile;
                    Grid.GridMap         = heightmapContent.Load <Texture2D>("gridmap");
                    Grid.ImportGridMap();
                    Grid.RoadAssetFiles = assets;

                    gridPointer  = new GridPointer(Grid);
                    gridPointers = new List <GridPointer>();
                }

                camera.Attach(Terrain.TerrainIndexer);
                camera.Notify();
            }
        }
        public void Load()
        {
            // Create our Builder
            ContentBuilder builder = new ContentBuilder(@"C:\Build\Output");

            // Add our Build Files
            builder.Add(@"C:\Build\Original\Stadium1.fbx", "Stadium1", null, "ModelProcessor");

            // Build our content
            string result = builder.Build();

            // Display Results
            if (string.IsNullOrEmpty(result))
            {
                Console.WriteLine("Success ok to load model!");
            }
            else
            {
                Console.WriteLine(result);
            }
        }
예제 #8
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog OpenFileDialog = new OpenFileDialog();

            OpenFileDialog.Filter = "X Files (*.x)|*.x";
            OpenFileDialog.ShowDialog();
            String fileName = OpenFileDialog.FileName;

            if (String.IsNullOrEmpty(fileName))
            {
                return;
            }
            ContentBuilder.Add(fileName, "Model", null, "ModelProcessor");
            String buildError = ContentBuilder.Build();

            if (string.IsNullOrEmpty(buildError))
            {
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/Content/Loaded");
                MakeCopy(ContentBuilder.OutputDirectory, Directory.GetCurrentDirectory() + "/Content/Loaded/");

                SimpleModel simpleModel = new SimpleModel(EditorTestScreen.GraphicFactory, "Loaded/Model");
                ///Physic info (position, rotation and scale are set here)
                TriangleMeshObject tmesh = new TriangleMeshObject(simpleModel, Vector3.Zero, Microsoft.Xna.Framework.Matrix.Identity, Vector3.One, MaterialDescription.DefaultBepuMaterial());
                ///Shader info (must be a deferred type)
                DeferredNormalShader shader = new DeferredNormalShader();
                ///Material info (must be a deferred type also)
                DeferredMaterial fmaterial = new DeferredMaterial(shader);
                ///The object itself
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                ///Add to the world
                EditorTestScreen.World.AddObject(obj);
            }
            else
            {
                // If the build failed, display an error message.
                MessageBox.Show(buildError, "Error");
            }
        }
예제 #9
0
        public void saveTexture()
        {
            //   try
            //   {
            if (!String.IsNullOrEmpty(sourcePath) && !String.IsNullOrEmpty(_AnimationDefinition["Texture"]))
            {
                ContentBuilder contentBuilder = new ContentBuilder();

                //create a combo item for the texture
                compiledTextures = new ComboItem[textureSheetCount];

                if (textureSheetCount > 0)
                {
                    for (int i = 0; i < textureSheetCount; i++)
                    {
                        string indexKey       = (i == 0) ? "" : i.ToString();
                        string multiSheetPath = System.IO.Path.Combine(Settings.projectDirectory, Settings.animationSheetDir, _AnimationDefinition["Texture Path"].Split('/', '\\').Last() + indexKey + ".png");

                        //create the list items
                        compiledTextures[i] = new ComboItem(_AnimationDefinition["Texture"] + indexKey, multiSheetPath);
                        contentBuilder.Add(compiledTextures[i]);
                    }
                }
                else
                {
                    compiledTextures    = new ComboItem[1];
                    compiledTextures[0] = new ComboItem(_AnimationDefinition["Texture"], sourcePath);
                    contentBuilder.Add(compiledTextures[0]);
                }

                //Compile
                String error = contentBuilder.Build();

                if (!String.IsNullOrEmpty(error))
                {
                    MessageBox.Show(error);
                    return;
                }


                //Copy files to the output directory
                string tempPath = contentBuilder.OutputDirectory;
                outputFiles = Directory.GetFiles(tempPath, "*.xnb");

                tProcessBuildOutput = new Thread(new ParameterizedThreadStart(processBuildOutput));
                tProcessBuildOutput.Start();

                tProcessBuildOutput.Join();

                StreamWriter outStream = null;
                try
                {
                    outStream = new StreamWriter(System.IO.Path.Combine(Settings.projectDirectory, Settings.textureDir, Settings.texturesFile));

                    foreach (KeyValuePair <string, string> kvp in MainWindow.textures)
                    {
                        outStream.WriteLine(kvp.Key + "," + kvp.Value);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (outStream != null)
                    {
                        outStream.Close();
                    }
                }

                checkTextureName(textureName.Text);
            }
            //    }
            //     catch (Exception ex)
            //     {
            //         MessageBox.Show(ex.Message);
            //     }
        }
예제 #10
0
        private void Editor_Load(object sender, EventArgs e)
        {
            string errorBuild = "";

            try
            {
                mapModel = new EditorModel.MapModel();

                mouseMoving      = false;
                mouseEventArgs   = null;
                tempMouseX       = tempMouseY = -1;
                text             = "";
                basicEffect      = new BasicEffect(graphicsDeviceControl1.GraphicsDevice);
                contentBuilder   = ContentBuilder.Instance;
                contentManager   = new ContentManager(graphicsDeviceControl1.Services, contentBuilder.OutputDirectory);
                heightmapContent = new ContentManager(graphicsDeviceControl1.Services, contentBuilder.OutputDirectory);
                spriteBatch      = new SpriteBatch(graphicsDeviceControl1.GraphicsDevice);
                //MessageBox.Show(GraphicsDevice.Adapter.Description);

                effectFile         = AssemblyDirectory + "\\Assets\\effects.fx";
                terrainTextureFile = AssemblyDirectory + "\\Assets\\Textures\\grass.dds";
                //importer reference: http://msdn.microsoft.com/en-us/library/bb447762%28v=xnagamestudio.20%29.aspx
                contentBuilder.Add(AssemblyDirectory + "\\Assets\\SegoeUI.spritefont", "SegoeUI.spritefont", null, "FontDescriptionProcessor");
                contentBuilder.Add(effectFile, "effects", null, "EffectProcessor");
                contentBuilder.Add(AssemblyDirectory + "\\Assets\\brush.bmp", "brush", null, "TextureProcessor");
                contentBuilder.Add(terrainTextureFile, "grass", null, "TextureProcessor");
                contentBuilder.Add(AssemblyDirectory + "\\Assets\\video_camera.png", "video_camera", null, "TextureProcessor");
                contentBuilder.Add(AssemblyDirectory + "\\Assets\\Roads\\jalan_raya.fbx", "jalan_raya", null, "ModelProcessor");
                contentBuilder.Add(AssemblyDirectory + "\\Assets\\Roads\\jalan_raya_belok.fbx", "jalan_raya_belok", null, "ModelProcessor");
                contentBuilder.Add(AssemblyDirectory + "\\Assets\\heightmap2.png", "heightmap", null, "TextureProcessor");
                string error = contentBuilder.Build();
                if (!string.IsNullOrEmpty(error))
                {
                    throw new Exception(error);
                }

                errorBuild     = contentBuilder.Build();
                spriteFont     = contentManager.Load <SpriteFont>("SegoeUI.spritefont");
                terrainEffect  = contentManager.Load <Effect>("effects");
                brushHeightMap = contentManager.Load <Texture2D>("brush");
                grassTexture   = contentManager.Load <Texture2D>("grass");

                camera             = new Camera(GraphicsDevice);
                camera.Position    = new Vector3(0, 50, 0);
                camera.AspectRatio = graphicsDeviceControl1.GraphicsDevice.Viewport.AspectRatio;
                camera.Rotate(20, 45, 0);
                camera.Attach(this);
                CheckIsOrthographic();

                string heightMapFile = AssemblyDirectory + "\\test_HeightMap.png";
                Terrain         = new Terrain(GraphicsDevice, camera, heightMapFile, effectFile, terrainTextureFile, 128, 128);
                Terrain.Texture = grassTexture;

                //heightmapContent = new ContentManager(graphicsDeviceControl1.Services, contentBuilder.OutputDirectory);
                //quadTreeTerrain = new QuadTree(Vector3.Zero, 1025, 1025, camera, GraphicsDevice, 1);
                //quadTreeTerrain.Effect.Texture = grassTexture;

                editorMode = new EditorMode_Select(this);

                Selected                        = null;
                selectedBoundingBox             = new ModelBoundingBox(graphicsDeviceControl1.GraphicsDevice, camera, false);
                selectedBoundingBox.SpriteBatch = spriteBatch;
                selectedBoundingBox.SpriteFont  = spriteFont;
                CheckActiveTransformMode();

                terrainBrush             = new TerrainBrush(GraphicsDevice, Terrain, brushHeightMap);
                terrainBrush.BasicEffect = basicEffect;

                Grid                 = new Grid(Terrain, 8, camera, GraphicsDevice, basicEffect);
                Grid.RoadModel       = contentManager.Load <Model>("jalan_raya");
                Grid.RoadModel_belok = contentManager.Load <Model>("jalan_raya_belok");
                Grid.GridMapFile     = AssemblyDirectory + "\\Assets\\gridmap.png";
                Grid.ExportGridMap();
                Grid.RoadAssetFiles.Add(AssemblyDirectory + "\\Assets\\Roads\\jalan_raya.fbx");
                Grid.RoadAssetFiles.Add(AssemblyDirectory + "\\Assets\\Roads\\jalan_raya_belok.fbx");
                Grid.RoadAssetFiles.Add(AssemblyDirectory + "\\Assets\\Roads\\texture_jalan_raya.png");
                Grid.RoadAssetFiles.Add(AssemblyDirectory + "\\Assets\\Roads\\texture_jalan_raya_belok.png");

                gridPointer  = new GridPointer(Grid);
                gridPointers = new List <GridPointer>();

                mapModel.MainCamera.Texture        = contentManager.Load <Texture2D>("video_camera");
                mapModel.MainCamera.GraphicsDevice = GraphicsDevice;
                mapModel.MainCamera.Camera         = camera;
                mapModel.MainCamera.BasicEffect    = basicEffect;

                timer = new System.Threading.Timer((c) => SetGravity(), null, Timeout.Infinite, Timeout.Infinite);

                camera.Notify();
            }
            catch (Exception ex)
            {
                if (!DesignMode)
                {
                    if (mainUserControl != null && mainUserControl.StatusStrip1 != null)
                    {
                        mainUserControl.StatusStrip1.Text = ex.Message + "\r\n" + ex.StackTrace;
                    }
                    else
                    {
                        MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
                    }
                }
            }
        }
        /// <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));
        }