//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// #endregion #region //// Properties //////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// #endregion #region //// Construstors ////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// #endregion #region //// Methods /////////// //////////////////////////////////////////////////////////////////////////// public static Container Load(Manager manager, string asset) { Container win = null; XDocument doc = new XDocument(); ContentManager content = new ContentManager(manager.Game.Services); try { content.RootDirectory = manager.LayoutDirectory; #if (!XBOX && !XBOX_FAKE) string file = content.RootDirectory + asset; if (File.Exists(file)) { doc = XDocument.Load(file) as XDocument; } else #endif { doc = content.Load<XDocument>(asset); } if (doc != null && doc.Element("Layout").Element("Controls") != null && doc.Element("Layout").Element("Controls").HasElements) { var enumem = doc.Element("Layout").Element("Controls").Elements("Control").GetEnumerator(); if (enumem.MoveNext() == false) throw new Exception("Must be at least one control"); var node = enumem.Current; string cls = node.Attribute("Class").Value; Type type = Type.GetType(cls); if (type == null) { cls = "TomShane.Neoforce.Controls." + cls; type = Type.GetType(cls); } win = (Container)LoadControl(manager, node, type, null); } } finally { content.Dispose(); } return win; }
protected override void LoadContent(ContentState state) { //load the default font. drawStats.Font = state.Load<SpriteFont>("Arial"); //load the character model model.ModelData = state.Load<Xen.Ex.Graphics.Content.ModelData>(@"xna_dude/dude"); //set the shader on the model model.ShaderProvider = new CharacterShaderProvider(characterRenderShader, model.ModelData, state.ContentRegister, "xna_dude"); //setup the render configuration this.renderConfig = new RenderConfiguration(this); renderConfig.UseGammaCorrection = true; renderConfig.UseExposureTonemapping = true; renderConfig.AmbientSphericalHarmonicScale = 1; renderConfig.DiffuseLightingScale = 1; renderConfig.SpecularLightingScale = 1; renderConfig.AlbedoTextureScale = 1; renderConfig.AmbientOcclusionTextureScale = 1; renderConfig.ShadowMapTermScale = 1; renderConfig.SkinLightScatteringScale = 1; renderConfig.ShowBloomRenderTarget = false; renderConfig.ShowEncodedRgbmRenderTarget = false; renderConfig.PauseModelAnimation = false; renderConfig.PauseModelRotation = false; renderConfig.TargetLensExposure = 0.3f; //setup common defaults for the scene configs. SceneConfiguration defaultSC = new SceneConfiguration(); defaultSC.RgbmImageScale = 20.0f; defaultSC.BloomThreshold = 1.5f; defaultSC.BloomScale = 1.0f; defaultSC.SunSpecularPower = 32.0f; defaultSC.SunSpecularIntensity = 30.0f; defaultSC.RgbmRenderScale = 200.0f; defaultSC.SkinLightScattering = new Vector3(0.15f, 0.02f, 0.002f); // 15% of the red channel is transferred under the skin //Load the source cubemap scene textures. //Note: To make it easier to view the source images, the RGBM images have been split into two images, //One store the RGB portion, one stores the M portion. This makes it much easier to view the textures //and see how they are stored - but it is also extremely wasteful, using 2x the texture data. //Ideally, the images would be loaded directly as a PNG, however this cannot easily be done on the Xbox. //Because these textures are only uses locally as an image data source, they are loaded in a temporary //content manager, which is disposed at the end of this method. ContentManager localManager = new ContentManager(this.Services, state.ContentRegister.RootDirectory); Texture2D textureDirtroad = localManager.Load<Texture2D>("LightProbes/DirtRoadHDR.rgb"); Texture2D textureWaterfront = localManager.Load<Texture2D>("LightProbes/WaterfrontHDR.rgb"); Texture2D textureArches = localManager.Load<Texture2D>("LightProbes/ArchesHDR.rgb"); Texture2D textureMill = localManager.Load<Texture2D>("LightProbes/MillHDR.rgb"); Texture2D textureDirtroadAlpha = localManager.Load<Texture2D>("LightProbes/DirtRoadHDR.m"); Texture2D textureWaterfrontAlpha = localManager.Load<Texture2D>("LightProbes/WaterfrontHDR.m"); Texture2D textureArchesAlpha = localManager.Load<Texture2D>("LightProbes/ArchesHDR.m"); Texture2D textureMillAlpha = localManager.Load<Texture2D>("LightProbes/MillHDR.m"); //setup DirtRoadHDR specifics this.DirtRoadConfig = defaultSC.Clone(); this.DirtRoadConfig.BackgroundScene = new RgbmCubeMap(textureDirtroad, textureDirtroadAlpha, this.DirtRoadConfig.RgbmImageScale); this.DirtRoadConfig.SunColour = new Vector3(1, 0.9f, 0.75f); this.DirtRoadConfig.SunDirection = Vector3.Normalize(new Vector3(0, 0.1f, 1)); this.DirtRoadConfig.SunIntensity = 20.0f; this.DirtRoadConfig.DefaultLensExposure = 0.15f; this.DirtRoadConfig.DefaultCamPos = new Vector3(6.062489f, 4.9959f, -0.6131198f); this.DirtRoadConfig.DefaultCamViewPos = new Vector3(5.147717f, 5.02338f, -0.2100832f); //setup Arches specifics this.ArchesConfig = defaultSC.Clone(); this.ArchesConfig.BackgroundScene = new RgbmCubeMap(textureArches, textureArchesAlpha, this.ArchesConfig.RgbmImageScale); this.ArchesConfig.SunColour = new Vector3(1, 1, 1); this.ArchesConfig.SunDirection = Vector3.Normalize(new Vector3(-0.4f, 0.4f, 0.5f)); this.ArchesConfig.SunIntensity = 15.0f; this.ArchesConfig.DefaultLensExposure = 0.15f; this.ArchesConfig.DefaultCamPos = new Vector3(-2.667145f, 6.280345f, 4.98485f); this.ArchesConfig.DefaultCamViewPos = new Vector3(-2.470318f, 6.176862f, 4.009888f); //setup WaterfrontHDR specifics this.WaterfrontConfig = defaultSC.Clone(); this.WaterfrontConfig.BackgroundScene = new RgbmCubeMap(textureWaterfront, textureWaterfrontAlpha, this.WaterfrontConfig.RgbmImageScale); this.WaterfrontConfig.SunColour = new Vector3(0.9f, 0.95f, 1); this.WaterfrontConfig.SunDirection = Vector3.Normalize(new Vector3(-0.2f, 1, 0)); this.WaterfrontConfig.SunIntensity = 15.0f; this.WaterfrontConfig.DefaultLensExposure = 0.35f; this.WaterfrontConfig.DefaultCamPos = new Vector3(5.251021f,5.877438f,-2.74239f); this.WaterfrontConfig.DefaultCamViewPos = new Vector3(4.579107f, 5.783906f, -2.007691f); //setup MillHDR specifics this.MillConfig = defaultSC.Clone(); this.MillConfig.BackgroundScene = new RgbmCubeMap(textureMill, textureMillAlpha, this.MillConfig.RgbmImageScale); this.MillConfig.SunColour = new Vector3(1, 0.975f, 0.95f); this.MillConfig.SunDirection = Vector3.Normalize(new Vector3(-1, 1, -1)); this.MillConfig.SunIntensity = 25.0f; this.MillConfig.DefaultLensExposure = 0.5f; this.MillConfig.BloomScale = 0.5f; this.MillConfig.BloomThreshold = 1.0f; this.MillConfig.DefaultCamPos = new Vector3(6.087461f,6.132507f,-0.8147218f); this.MillConfig.DefaultCamViewPos = new Vector3(5.203656f,5.989332f,-0.3693113f); //Textures are no longer needed. localManager.Dispose(); this.sceneConfig = this.ArchesConfig; }
private void generateDefault_Click(object sender, EventArgs e) { string outputPath =Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\My Games\Terraria\Texture Packs\Stock\Images"; Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\My Games\Terraria\Texture Packs\Stock"); Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\My Games\Terraria\Texture Packs\Stock\Fonts"); Directory.CreateDirectory(outputPath); GameServiceContainer gsc = new GameServiceContainer(); GraphicsAdapter ga = GraphicsAdapter.DefaultAdapter; GraphicsProfile gp = GraphicsProfile.HiDef; PresentationParameters pp = new PresentationParameters(); pp.DeviceWindowHandle = this.Handle; pp.IsFullScreen = false; pp.BackBufferHeight = this.ClientSize.Height; pp.BackBufferWidth = this.ClientSize.Width; pp.BackBufferFormat = SurfaceFormat.Color; GraphicsDevice gd = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, gp, pp); gsc.AddService(typeof(IGraphicsDeviceService), new FakeGraphicsDeviceService(gd)); ContentManager cm = new ContentManager(gsc, Directory.GetCurrentDirectory() + @"\Content"); DirectoryInfo di = new DirectoryInfo(@"Content\Images"); foreach (var fi in di.GetFiles("*.xnb")) { var image = cm.Load<Texture2D>("Images/" + fi.Name.Substring(0, fi.Name.Length - 4)); if (image != null) { using (var fs = new FileStream(String.Format(@"{0}\{1}.png", outputPath, fi.Name.Substring(0, fi.Name.Length - 4)), FileMode.Create, FileAccess.Write)) { image.SaveAsPng(fs, image.Width, image.Height); } } } cm.Dispose(); MessageBox.Show("Stock texture pack created at: \n\n" + outputPath); }
protected override void LoadContent(ContentState state) { //load the default font. SpriteFont arial = state.Load<SpriteFont>("Arial"); drawStats.Font = arial; //load the character model model.ModelData = state.Load<Xen.Ex.Graphics.Content.ModelData>(@"xna_dude/dude"); //set the shader on the model model.ShaderProvider = new CharacterShaderProvider(characterRenderShader, model.ModelData, state.ContentRegister, "xna_dude"); //setup the render configuration this.renderConfig = new RenderConfiguration(this); renderConfig.UseGammaCorrection = true; renderConfig.UseExposureTonemapping = true; renderConfig.AmbientSphericalHarmonicScale = 1; renderConfig.DiffuseLightingScale = 1; renderConfig.SpecularLightingScale = 1; renderConfig.AlbedoTextureScale = 1; renderConfig.AmbientOcclusionTextureScale = 1; renderConfig.ShadowMapTermScale = 1; renderConfig.SkinLightScatteringScale = 1; renderConfig.ShowBloomRenderTarget = false; renderConfig.ShowEncodedRgbmRenderTarget = false; renderConfig.PauseModelAnimation = false; renderConfig.PauseModelRotation = false; renderConfig.TargetLensExposure = 0.3f; //setup common defaults for the scene configs. SceneConfiguration defaultSC = new SceneConfiguration(); defaultSC.RgbmImageScale = 20.0f; defaultSC.BloomThreshold = 1.5f; defaultSC.BloomScale = 1.0f; defaultSC.SunSpecularPower = 32.0f; defaultSC.SunSpecularIntensity = 30.0f; defaultSC.RgbmRenderScale = 200.0f; defaultSC.SkinLightScattering = new Vector3(0.15f, 0.02f, 0.002f); // 15% of the red channel is transferred under the skin //Load the source cubemap scene textures. //Note: To make it easier to view the source images, the RGBM images have been split into two images, //One store the RGB portion, one stores the M portion. This makes it much easier to view the textures //and see how they are stored - but it is also extremely wasteful, using 2x the texture data. //Ideally, the images would be loaded directly as a PNG, however this cannot easily be done on the Xbox. //Because these textures are only uses locally as an image data source, they are loaded in a temporary //content manager, which is disposed at the end of this method. ContentManager localManager = new ContentManager(this.Services, state.ContentRegister.RootDirectory); Texture2D textureDirtroad = localManager.Load<Texture2D>("LightProbes/DirtRoadHDR.rgb"); Texture2D textureWaterfront = localManager.Load<Texture2D>("LightProbes/WaterfrontHDR.rgb"); Texture2D textureArches = localManager.Load<Texture2D>("LightProbes/ArchesHDR.rgb"); Texture2D textureMill = localManager.Load<Texture2D>("LightProbes/MillHDR.rgb"); Texture2D textureDirtroadAlpha = localManager.Load<Texture2D>("LightProbes/DirtRoadHDR.m"); Texture2D textureWaterfrontAlpha = localManager.Load<Texture2D>("LightProbes/WaterfrontHDR.m"); Texture2D textureArchesAlpha = localManager.Load<Texture2D>("LightProbes/ArchesHDR.m"); Texture2D textureMillAlpha = localManager.Load<Texture2D>("LightProbes/MillHDR.m"); //setup DirtRoadHDR specifics this.DirtRoadConfig = defaultSC.Clone(); this.DirtRoadConfig.BackgroundScene = new RgbmCubeMap(textureDirtroad, textureDirtroadAlpha, this.DirtRoadConfig.RgbmImageScale); this.DirtRoadConfig.SunColour = new Vector3(1, 0.9f, 0.75f); this.DirtRoadConfig.SunDirection = Vector3.Normalize(new Vector3(0, 0.1f, 1)); this.DirtRoadConfig.SunIntensity = 20.0f; this.DirtRoadConfig.DefaultLensExposure = 0.15f; this.DirtRoadConfig.DefaultCamPos = new Vector3(6.062489f, 105.9959f, -0.6131198f); this.DirtRoadConfig.DefaultCamViewPos = new Vector3(5.147717f, 105.02338f, -0.2100832f); //setup Arches specifics this.ArchesConfig = defaultSC.Clone(); this.ArchesConfig.BackgroundScene = new RgbmCubeMap(textureArches, textureArchesAlpha, this.ArchesConfig.RgbmImageScale); this.ArchesConfig.SunColour = new Vector3(1, 1, 1); this.ArchesConfig.SunDirection = Vector3.Normalize(new Vector3(-0.4f, 0.4f, 0.5f)); this.ArchesConfig.SunIntensity = 15.0f; this.ArchesConfig.DefaultLensExposure = 0.15f; this.ArchesConfig.DefaultCamPos = new Vector3(-2.667145f, 105.280345f, 4.98485f); this.ArchesConfig.DefaultCamViewPos = new Vector3(-2.470318f, 105.176862f, 4.009888f); //this.ArchesConfig.BloomScale = 0f; // temporary bloom disable for wireframe //setup WaterfrontHDR specifics this.WaterfrontConfig = defaultSC.Clone(); this.WaterfrontConfig.BackgroundScene = new RgbmCubeMap(textureWaterfront, textureWaterfrontAlpha, this.WaterfrontConfig.RgbmImageScale); this.WaterfrontConfig.SunColour = new Vector3(0.9f, 0.95f, 1); this.WaterfrontConfig.SunDirection = Vector3.Normalize(new Vector3(-0.2f, 1, 0)); this.WaterfrontConfig.SunIntensity = 15.0f; this.WaterfrontConfig.DefaultLensExposure = 0.35f; this.WaterfrontConfig.DefaultCamPos = new Vector3(5.251021f, 105.877438f, -2.74239f); this.WaterfrontConfig.DefaultCamViewPos = new Vector3(4.579107f, 105.783906f, -2.007691f); //setup MillHDR specifics this.MillConfig = defaultSC.Clone(); this.MillConfig.BackgroundScene = new RgbmCubeMap(textureMill, textureMillAlpha, this.MillConfig.RgbmImageScale); this.MillConfig.SunColour = new Vector3(1, 0.975f, 0.95f); this.MillConfig.SunDirection = Vector3.Normalize(new Vector3(-1, 1, -1)); this.MillConfig.SunIntensity = 25.0f; this.MillConfig.DefaultLensExposure = 0.5f; this.MillConfig.BloomScale = 0.5f; this.MillConfig.BloomThreshold = 1.0f; this.MillConfig.DefaultCamPos = new Vector3(6.087461f, 105.132507f, -0.8147218f); this.MillConfig.DefaultCamViewPos = new Vector3(5.203656f, 104.989332f, -0.3693113f); this.sceneConfig = this.ArchesConfig; this.viewCamera.LookAt(this.sceneConfig.DefaultCamViewPos, this.sceneConfig.DefaultCamPos, new Vector3(0, 1, 0)); //Textures are no longer needed. localManager.Dispose(); localManager = new ContentManager(this.Services, state.ContentRegister.RootDirectory); // Generate terrain /* const int terrainSeed = 70; GenerateTerrain(terrainSeed); terrainManager.SideColor = localManager.Load<Texture2D>("TerrainTextures/cliffs2"); terrainManager.BottomColor = localManager.Load<Texture2D>("TerrainTextures/rock1"); terrainManager.TopColor = localManager.Load<Texture2D>("TerrainTextures/grassyrock2"); terrainManager.SideNormal = localManager.Load<Texture2D>("TerrainTextures/rock_normal"); terrainManager.TopNormal = terrainManager.SideNormal; terrainManager.BottomNormal = terrainManager.SideNormal; terrainManager.terrainShader.SideColor = terrainManager.SideColor; terrainManager.terrainShader.SideNormal = terrainManager.SideNormal; terrainManager.terrainShader.BottomColor = terrainManager.BottomColor; terrainManager.terrainShader.BottomNormal = terrainManager.BottomNormal; terrainManager.terrainShader.TopColor = terrainManager.TopColor; terrainManager.terrainShader.TopNormal = terrainManager.TopNormal; terrainManager.terrainShader.TextureScale = 0.1f + ((1 / terrainManager.cellDimensions.X) / 2.5f); SetupTerrainShader(); */ // xpf gui initialisation /* Microsoft.Xna.Framework.Game g = (Microsoft.Xna.Framework.Game)this; this.spriteBatchAdapter = new SpriteBatchAdapter(new SpriteBatch(g.GraphicsDevice)); var primitivesService = new PrimitivesService(g.GraphicsDevice); var renderer = new Renderer(this.spriteBatchAdapter, primitivesService); this.rootElement = new RootElement(g.GraphicsDevice.Viewport.ToRect(), renderer); var spriteFontAdapter = new SpriteFontAdapter(arial); var textBlock = new TextBlock(spriteFontAdapter) { Text = "Hello from XPF!", Foreground = new RedBadger.Xpf.Media.SolidColorBrush(RedBadger.Xpf.Media.Colors.White), //Background = new RedBadger.Xpf.Media.SolidColorBrush(RedBadger.Xpf.Media.Colors.Red), HorizontalAlignment = RedBadger.Xpf.HorizontalAlignment.Left, VerticalAlignment = RedBadger.Xpf.VerticalAlignment.Top }; this.rootElement.Content = textBlock;*/ // calculate physics for terrain and add it simpleTerrain.CalculatePhysicsHull(); world.AddBody(simpleTerrain.RigidBody); // add player model to physics sim float height = model.ModelData.StaticBounds.Maximum.Y - model.ModelData.StaticBounds.Minimum.Y; float width = model.ModelData.StaticBounds.Maximum.X - model.ModelData.StaticBounds.Minimum.X; RigidBody playerBody = new RigidBody(new CapsuleShape(0.16f, 0.08f)); playerBody.Position = new JVector(0, 100, 0); playerBody.UseUserMassProperties(JMatrix.Zero, 1.0f, true); playerBody.Restitution = 0.0f; //playerBody.Orientation = Matrix.CreateRotationZ(MathHelper.Pi).ToJitterMatrix(); characterController = new CharacterController(world, playerBody); world.AddBody(playerBody); world.AddConstraint(characterController); }