/// <summary> /// Loads a model using the given model file and texture files. /// </summary> /// <param name="meshFile">Mesh to load</param> /// <param name="textureBaseName">Texture to load</param> /// <param name="colorName">Color map texture to load</param> /// <returns>Model that is set up to use the atlas</returns> public Model LoadModel(string meshFile, string diffuseName, string colorName) { Mesh mesh = null; try { using (var stream = TitleContainer.OpenStream("Content/" + BaseModelDirectory + "/" + meshFile + ".obj")) { mesh = ObjParser.FromStream(stream); } } catch (Exception e) { throw new Exception("Exception when loading model", e); } var diffuseTexture = TryLoadTexture(BaseTextureDirectory + "/" + diffuseName); var colorTexture = TryLoadTexture(BaseTextureDirectory + "/" + colorName); if (diffuseTexture == null || colorTexture == null) { throw new Exception("Need both a color and diffuse texture!"); } // Color and Diffuse UVs are seperate atlas.AddTexture(diffuseTexture); colorAtlas.AddTexture(colorTexture); atlas.UpdateMeshUVs(mesh, diffuseTexture, 0); colorAtlas.UpdateMeshUVs(mesh, colorTexture, 1); return(new Model(mesh, Material)); }
protected override void LoadContent() { // Load shader, set up settings var black = Game.Content.Load <Texture2D>("Textures/black"); basicShader = Game.Content.Load <Effect>("Shaders/BasicColorMapped"); basicShader.CurrentTechnique = basicShader.Techniques["DefaultTechnique"]; basicShader.Parameters["ColorMapTexture"].SetValue(black); basicShader.Parameters["ColorInfluence"].SetValue(1.0f); basicShader.Parameters["FogColor"].SetValue(SkyColor.ToVector4()); basicShader.Parameters["FogEndDistance"].SetValue(FogDistance); // Load models, decoration and biome data var modelLoader = new AtlasModelLoader(2048, 2048, basicShader, Game.Content); var decorationData = orbis.Content.Load <XMLModel.DecorationCollection>("Config/Decorations"); var decorationManager = new DecorationManager(decorationData, modelLoader, GraphicsDevice); // Load decorations foreach (var data in decorationData.Decorations) { decorations.Add(data.Name, new DecorationPool(decorationManager.GetDecorationMesh(data.Name), GraphicsDevice, 1)); } var biomeData = orbis.Content.Load <XMLModel.BiomeCollection>("Config/Biomes"); biomeMappedData = new Dictionary <string, BiomeMappedData>(); // Load biomes foreach (var biome in biomeData.Biomes) { biomeMappedData.Add(biome.Name, new BiomeMappedData { HexMesh = modelLoader.LoadModel(biome.HexModel.Name, biome.HexModel.Texture, biome.HexModel.ColorTexture).Mesh, DefaultDecoration = biome.DefaultDecoration, DefaultDensity = biome.DecorationDensity, }); } // Load tile highlight mesh var model = modelLoader.LoadModel("flag", "flag"); tileHighlightMesh = new RenderableMesh(GraphicsDevice, model.Mesh); modelLoader.FinializeLoading(GraphicsDevice); // Set up shader textures basicShader.Parameters["MainTexture"].SetValue(modelLoader.Material.Texture); basicShader.Parameters["ColorMapTexture"].SetValue(modelLoader.Material.ColorMap); if (atlasDebugEnabled) { // Atlas texture debugging Mesh mesh = null; using (var stream = TitleContainer.OpenStream("Content/Meshes/quad_up.obj")) { mesh = ObjParser.FromStream(stream); } atlasDebugInstance = new RenderInstance { mesh = new RenderableMesh(GraphicsDevice, mesh), matrix = Matrix.CreateScale(10) * Matrix.CreateTranslation(0, 0, 30), }; basicShader.Parameters["ColorMapTexture"].SetValue(black); } base.LoadContent(); }