public override bool Init() { if (!base.Init()) return false; Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _texMgr = new TextureManager(); _texMgr.Init(Device); _bunnyModel = BasicModel.LoadSdkMesh(Device, _texMgr, "Models/bunny.sdkmesh", "Textures"); _bunnyInstance = new BasicModelInstance(_bunnyModel) { World = Matrix.Scaling(0.1f, 0.1f, 0.1f) }; _effect = new ForwardLightingEffect(Device, "FX/forwardLight.fxo"); var passDesc = _effect.Ambient.GetPassByIndex(0).Description; _layout = new InputLayout(Device, passDesc.Signature, InputLayoutDescriptions.PosNormalTexTan); AddUIElements(); return true; }
public static BasicModel LoadSdkMesh(Device device, TextureManager texMgr, string filename, string texturePath) { // NOTE: this assumes that the model file only contains a single mesh var sdkMesh = new SdkMesh(filename); var ret = new BasicModel(); var faceStart = 0; var vertexStart = 0; foreach (var sdkMeshSubset in sdkMesh.Subsets) { var subset = new MeshGeometry.Subset { FaceCount = (int)(sdkMeshSubset.IndexCount / 3), FaceStart = faceStart, VertexCount = (int)sdkMeshSubset.VertexCount, VertexStart = vertexStart }; // fixup any subset indices that assume that all vertices and indices are not in the same buffers faceStart = subset.FaceStart + subset.FaceCount; vertexStart = subset.VertexStart + subset.VertexCount; ret.Subsets.Add(subset); } var max = new Vector3(float.MinValue); var min = new Vector3(float.MaxValue); foreach (var vb in sdkMesh.VertexBuffers) { foreach (var vertex in vb.Vertices) { max = Vector3.Maximize(max, vertex.Pos); min = Vector3.Minimize(min, vertex.Pos); ret.Vertices.Add(vertex); } } ret.BoundingBox = new BoundingBox(min, max); foreach (var ib in sdkMesh.IndexBuffers) { ret.Indices.AddRange(ib.Indices.Select(i => i)); } foreach (var sdkMeshMaterial in sdkMesh.Materials) { var material = new Material { Ambient = sdkMeshMaterial.Ambient, Diffuse = sdkMeshMaterial.Diffuse, Reflect = Color.Black, Specular = sdkMeshMaterial.Specular }; material.Specular.Alpha = sdkMeshMaterial.Power; ret.Materials.Add(material); if (!string.IsNullOrEmpty(sdkMeshMaterial.DiffuseTexture)) { ret.DiffuseMapSRV.Add(texMgr.CreateTexture(Path.Combine(texturePath, sdkMeshMaterial.DiffuseTexture))); } else { ret.DiffuseMapSRV.Add(texMgr["default"]); } if (!string.IsNullOrEmpty(sdkMeshMaterial.NormalTexture)) { ret.NormalMapSRV.Add(texMgr.CreateTexture(Path.Combine(texturePath, sdkMeshMaterial.NormalTexture))); } else { ret.NormalMapSRV.Add(texMgr["defaultNorm"]); } } ret.ModelMesh.SetSubsetTable(ret.Subsets); ret.ModelMesh.SetVertices(device, ret.Vertices); ret.ModelMesh.SetIndices(device, ret.Indices); return ret; }
public FireWorkRule(int type, float minAge, float maxAge, Vector3 minVel, Vector3 maxVel, float damping, BasicModel model) : this() { Type = type; MinAge = minAge; MaxAge = maxAge; MinVelocity = minVel; MaxVelocity = maxVel; Damping = damping; _model = model; }
public override bool Init() { if (!base.Init()) return false; Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _texMgr = new TextureManager(); _texMgr.Init(Device); _bunnyModel = BasicModel.LoadSdkMesh(Device, _texMgr, "Models/bunny.sdkmesh", "Textures"); _bunnyInstance = new BasicModelInstance(_bunnyModel) { World = Matrix.Scaling(0.1f, 0.1f, 0.1f) }; return true; }
public void Init(Device device, TextureManager texMgr, float width, float depth, string texture1 = "Textures/waves0.dds", string texture2 = "textures/waves1.dds") { NormalMap0 = texMgr.CreateTexture(texture1); NormalMap1 = texMgr.CreateTexture(texture2); _gridModel = new BasicModel(); _gridModel.CreateGrid(device, width, depth, ((int)width) * 2, ((int)depth) * 2); // BasicModel.CreateGrid(device, width, depth, ((int)width) * 2, ((int)depth) * 2); Material = new Material { Ambient = new Color4(0.1f, 0.1f, 0.3f), Diffuse = new Color4(0.4f, 0.4f, 0.7f), Specular = new Color4(128f, 0.8f, 0.8f, 0.8f), Reflect = new Color4(0.4f, 0.4f, 0.4f) }; _grid = new BasicModelInstance(_gridModel); TexTransform = Matrix.Identity; World = Matrix.Translation(0, -0.2f, 0); }
public Firework(int type, float age, BasicModel m) { Type = type; Age = age; Model = new BasicModelInstance(m); }
public BasicModelInstance(BasicModel model) : base(model) { }
public override bool Init() { if (!base.Init()) return false; Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _texMgr = new TextureManager(); _texMgr.Init(Device); _treeModel = new BasicModel(Device, _texMgr, "Models/tree.x", "Textures"); _modelInstance = new BasicModelInstance { Model = _treeModel, World = Matrix.RotationX(MathF.PI / 2) }; _stoneModel = new BasicModel(Device, _texMgr, "Models/stone.x", "Textures"); _stoneInstance = new BasicModelInstance { Model = _stoneModel, World = Matrix.Scaling(0.1f, 0.1f, 0.1f) * Matrix.Translation(2, 0, 2) }; return true; }
private static BasicModel BuildFromMeshData(Device device, GeometryGenerator.MeshData mesh) { var ret = new BasicModel(); var subset = new MeshGeometry.Subset { FaceCount = mesh.Indices.Count / 3, FaceStart = 0, VertexCount = mesh.Vertices.Count, VertexStart = 0 }; ret._subsets.Add(subset); var max = new Vector3(float.MinValue); var min = new Vector3(float.MaxValue); foreach (var vertex in mesh.Vertices) { max = Vector3.Maximize(max, vertex.Position); min = Vector3.Minimize(min, vertex.Position); } ret.BoundingBox = new BoundingBox(min, max); ret._vertices.AddRange(mesh.Vertices.Select(v => new PosNormalTexTan(v.Position, v.Normal, v.TexC, v.TangentU)).ToList()); ret._indices.AddRange(mesh.Indices.Select(i => (short)i)); ret.Materials.Add(new Material { Ambient = Color.Gray, Diffuse = Color.White, Specular = new Color4(16, 1, 1, 1) }); ret.DiffuseMapSRV.Add(null); ret.NormalMapSRV.Add(null); ret._modelMesh.SetSubsetTable(ret._subsets); ret._modelMesh.SetVertices(device, ret._vertices); ret._modelMesh.SetIndices(device, ret._indices); return ret; }
public override bool Init() { if (!base.Init()) return false; Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _texMgr = new TextureManager(); _texMgr.Init(Device); _geosphereModel = new BasicModel(); _geosphereModel.CreateGeosphere(Device, 5, _subdivisions); _geosphereModel.Materials[0] = _material; _sphereModel = new BasicModel(); _sphereModel.CreateSphere(Device, 5, 20,20); _sphereModel.Materials[0] = new Material() { Ambient = Color.Blue, Diffuse = Color.Red, Specular = new Color4(16.0f, 0.75f, 0.75f, 0.75f) }; _geosphere = new BasicModelInstance(_geosphereModel) { World = Matrix.Identity }; _sphere = new BasicModelInstance(_sphereModel); return true; }
public override bool Init() { if (!base.Init()) return false; Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); Patch.InitPatchData(Terrain.CellsPerPatch, Device); _sky = new Sky(Device, "Textures/grasscube1024.dds", 5000.0f); var tii = new InitInfo { HeightMapFilename = null, LayerMapFilename0 = "textures/grass.png", LayerMapFilename1 = "textures/hills.png", LayerMapFilename2 = "textures/stone.png", LayerMapFilename3 = "Textures/lightdirt.dds", LayerMapFilename4 = "textures/snow.png", Material = new Material() { Ambient = Color.LightGray, Diffuse = Color.LightGray, Specular = new Color4(64, 0, 0, 0) }, BlendMapFilename = null, HeightScale = 50.0f, HeightMapWidth = 2049, HeightMapHeight = 2049, CellSpacing = 0.5f, Seed = MathF.Rand(), NoiseSize1 = 3.0f, Persistence1 = 0.7f, Octaves1 = 7, NoiseSize2 = 2.5f, Persistence2 = 0.8f, Octaves2 = 3, }; _terrain = new Terrain(); //_terrain.DebugQuadTree = true; _terrain.Init(Device, ImmediateContext, tii); _camera.Height = _terrain.Height; _camera.SetLens(0.25f * MathF.PI, AspectRatio, 1.0f, 1000.0f); _ssao = new Ssao(Device, ImmediateContext, ClientWidth, ClientHeight, _camera.FovY, _camera.FarZ); _whiteTex = ShaderResourceView.FromFile(Device, "Textures/white.dds"); _sMap = new ShadowMap(Device, SMapSize, SMapSize); _sceneBounds = new BoundingSphere(new Vector3(), MathF.Sqrt(_terrain.Width * _terrain.Width + _terrain.Depth * _terrain.Depth) / 2); _minimap = new Minimap(Device, ImmediateContext, MinimapSize, MinimapSize, _terrain, _camera); _sphereModel = new BasicModel(); _sphereModel.CreateSphere(Device, 0.25f, 10, 10); _sphereModel.Materials[0] = new Material { Ambient = new Color4(63, 0, 0), Diffuse = Color.Red, Specular = new Color4(32, 1.0f, 1.0f, 1.0f) }; _sphereModel.DiffuseMapSRV[0] = _whiteTex; _sphere = new BasicModelInstance(_sphereModel); _unit = new Unit(_sphere, _terrain.GetTile(511, 511), _terrain); FontCache.RegisterFont("bold", 16, "Courier New", FontWeight.Bold); return true; }
private void BuildSkullGeometryBuffers() { _skullModel = BasicModel.LoadFromTxtFile(Device, "Models/skull.txt"); _skullModel.Materials[0] = new Material { Ambient = new Color4(0.2f, 0.2f, 0.2f), Diffuse = new Color4(0.2f, 0.2f, 0.2f), Specular = new Color4(16.0f, 0.8f, 0.8f, 0.8f), Reflect = new Color4(0.5f, 0.5f, 0.5f) }; _skull = new BasicModelInstance(_skullModel) { World = Matrix.Scaling(0.5f, 0.5f, 0.5f) * Matrix.Translation(0, 1.0f, 0) }; }
public override bool Init() { if (!base.Init()) return false; Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _sky = new Sky(Device, "Textures/grasscube1024.dds", 5000.0f); _texMgr = new TextureManager(); _texMgr.Init(Device); _gridModel = new BasicModel(); _gridModel.CreateGrid(Device, 20, 20, 40, 40); _gridModel.Materials[0] = new Material { Diffuse = Color.LightGray, Specular = new Color4(16, .9f, .9f, .9f) }; _gridModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/floor.dds"); _gridModel.NormalMapSRV[0] = _texMgr.CreateTexture("textures/floor_nmap.dds"); _grid = new BasicModelInstance(_gridModel) { TexTransform = Matrix.Scaling(10, 10, 1), World = Matrix.Scaling(10, 1, 10) }; InitFireworksRules(); _cylinderModel = new BasicModel(); _cylinderModel.CreateCylinder(Device, 1, 1, 3, 20, 20); _cylinderModel.Materials[0] = new Material { Ambient = Color.Green, Diffuse = Color.Green, Specular = new Color4(64.0f, 1.0f, 1.0f, 1.0f) }; _cylinderModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/stones.dds"); _cylinderModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/stones_nmap.dds"); _cylinder = new BasicModelInstance(_cylinderModel) { World = Matrix.Translation(0, 1.5f, 0) }; return true; }
public static BasicModel LoadFromTxtFile(Device device, string filename) { var vertices = new List <Basic32>(); var indices = new List <int>(); var vcount = 0; var tcount = 0; using (var reader = new StreamReader(filename)) { var input = reader.ReadLine(); if (input != null) { // VertexCount: X vcount = Convert.ToInt32(input.Split(new[] { ':' })[1].Trim()); } input = reader.ReadLine(); if (input != null) { //TriangleCount: X tcount = Convert.ToInt32(input.Split(new[] { ':' })[1].Trim()); } // skip ahead to the vertex data do { input = reader.ReadLine(); } while (input != null && !input.StartsWith("{")); // Get the vertices for (int i = 0; i < vcount; i++) { input = reader.ReadLine(); if (input != null) { var vals = input.Split(new[] { ' ' }); vertices.Add( new Basic32( new Vector3( Convert.ToSingle(vals[0].Trim()), Convert.ToSingle(vals[1].Trim()), Convert.ToSingle(vals[2].Trim())), new Vector3( Convert.ToSingle(vals[3].Trim()), Convert.ToSingle(vals[4].Trim()), Convert.ToSingle(vals[5].Trim())), new Vector2() ) ); } } // skip ahead to the index data do { input = reader.ReadLine(); } while (input != null && !input.StartsWith("{")); // Get the indices for (var i = 0; i < tcount; i++) { input = reader.ReadLine(); if (input == null) { break; } var m = input.Trim().Split(new[] { ' ' }); indices.Add(Convert.ToInt32(m[0].Trim())); indices.Add(Convert.ToInt32(m[1].Trim())); indices.Add(Convert.ToInt32(m[2].Trim())); } } var ret = new BasicModel(); var subset = new MeshGeometry.Subset { FaceCount = indices.Count / 3, FaceStart = 0, VertexCount = vertices.Count, VertexStart = 0 }; ret.Subsets.Add(subset); var max = new Vector3(float.MinValue); var min = new Vector3(float.MaxValue); foreach (var vertex in vertices) { max = Vector3.Maximize(max, vertex.Position); min = Vector3.Minimize(min, vertex.Position); } ret.BoundingBox = new BoundingBox(min, max); ret.Vertices.AddRange(vertices.Select(v => new PosNormalTexTan(v.Position, v.Normal, v.Tex, new Vector3(1, 0, 0))).ToList()); ret.Indices.AddRange(indices.Select(i => (short)i)); ret.Materials.Add(new Material { Ambient = Color.Gray, Diffuse = Color.White, Specular = new Color4(16, 1, 1, 1) }); ret.DiffuseMapSRV.Add(null); ret.NormalMapSRV.Add(null); ret.ModelMesh.SetSubsetTable(ret.Subsets); ret.ModelMesh.SetVertices(device, ret.Vertices); ret.ModelMesh.SetIndices(device, ret.Indices); return(ret); }
private void BuildShapeGeometryBuffers() { _texMgr = new TextureManager(); _texMgr.Init(Device); _boxModel = BasicModel.CreateBox(Device, 1, 1, 1); _boxModel.Materials[0] = new Material { Ambient = new Color4(0.8f, 0.8f, 0.8f), Diffuse = new Color4(0.4f, 0.4f, 0.4f), Specular = new Color4(16.0f, 0.8f, 0.8f, 0.8f), Reflect = Color.Black }; _boxModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/bricks.dds"); _boxModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/bricks_nmap.dds"); _gridModel = BasicModel.CreateGrid(Device, 20, 30, 50, 40); _gridModel.Materials[0] = new Material { Ambient = new Color4(0.7f, 0.7f, 0.7f), Diffuse = new Color4(0.6f, 0.6f, 0.6f), Specular = new Color4(16.0f, 0.4f, 0.4f, 0.4f), Reflect = Color.Black }; _gridModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/floor.dds"); _gridModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/floor_nmap.dds"); _sphereModel = BasicModel.CreateSphere(Device, 0.5f, 20, 20); _sphereModel.Materials[0] = new Material { Ambient = new Color4(0.3f, 0.4f, 0.5f), Diffuse = new Color4(0.2f, 0.3f, 0.4f), Specular = new Color4(16.0f, 0.9f, 0.9f, 0.9f), Reflect = new Color4(0.3f, 0.3f, 0.3f) }; _cylinderModel = BasicModel.CreateCylinder(Device, 0.5f, 0.5f, 3.0f, 15, 15); _cylinderModel.Materials[0] = new Material { Ambient = new Color4(0.8f, 0.8f, 0.8f), Diffuse = new Color4(0.4f, 0.4f, 0.4f), Specular = new Color4(32.0f, 1f, 1f, 1f), Reflect = Color.Black }; _cylinderModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/bricks.dds"); _cylinderModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/bricks_nmap.dds"); for (var i = 0; i < 5; i++) { _cylinders[i * 2] = new BasicModelInstance { Model = _cylinderModel, World = Matrix.Translation(-5.0f, 1.5f, -10.0f + i * 5.0f), TexTransform = Matrix.Scaling(1, 2, 1) }; _cylinders[i * 2 + 1] = new BasicModelInstance { Model = _cylinderModel, World = Matrix.Translation(5.0f, 1.5f, -10.0f + i * 5.0f), TexTransform = Matrix.Scaling(1, 2, 1) }; _spheres[i * 2] = new BasicModelInstance { Model = _sphereModel, World = Matrix.Translation(-5.0f, 3.5f, -10.0f + i * 5.0f) }; _spheres[i * 2 + 1] = new BasicModelInstance { Model = _sphereModel, World = Matrix.Translation(5.0f, 3.5f, -10.0f + i * 5.0f) }; } _grid = new BasicModelInstance { Model = _gridModel, TexTransform = Matrix.Scaling(8, 10, 1), World = Matrix.Identity }; _box = new BasicModelInstance { Model = _boxModel, TexTransform = Matrix.Scaling(2, 1, 1), World = Matrix.Scaling(3.0f, 1.0f, 3.0f) * Matrix.Translation(0, 0.5f, 0) }; }
public override bool Init() { if (!base.Init()) return false; Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); Patch.InitPatchData(Terrain.CellsPerPatch, Device); _sky = new Sky(Device, "Textures/grasscube1024.dds", 5000.0f); var tii = new InitInfo { HeightMapFilename = null, LayerMapFilename0 = "textures/grass.dds", LayerMapFilename1 = "textures/darkdirt.dds", LayerMapFilename2 = "textures/stone.dds", LayerMapFilename3 = "Textures/lightdirt.dds", LayerMapFilename4 = "textures/snow.dds", BlendMapFilename = null, HeightScale = 50.0f, HeightMapWidth = 2049, HeightMapHeight = 2049, CellSpacing = 0.5f, Seed = 0, NoiseSize1 = 3.0f, Persistence1 = 0.7f, Octaves1 = 7, NoiseSize2 = 2.5f, Persistence2 = 0.8f, Octaves2 = 3, }; _terrain = new Terrain(); _terrain.Init(Device, ImmediateContext, tii); _camera.Height = _terrain.Height; _camera.SetLens(0.25f * MathF.PI, AspectRatio, 1.0f, 1000.0f); _ssao = new Ssao(Device, ImmediateContext, ClientWidth, ClientHeight, _camera.FovY, _camera.FarZ); _whiteTex = ShaderResourceView.FromFile(Device, "Textures/white.dds"); BuildScreenQuadGeometryBuffers(); _sMap = new ShadowMap(Device, SMapSize, SMapSize); _sceneBounds = new BoundingSphere(new Vector3(), MathF.Sqrt(_terrain.Width * _terrain.Width + _terrain.Depth * _terrain.Depth) / 2); _minimap = new Minimap(Device, ImmediateContext, MinimapSize, MinimapSize, _terrain, _camera); _sphereModel = BasicModel.CreateSphere(Device, 0.25f, 10, 10); _sphereModel.Materials[0] = new Material { Ambient = Color.Red, Diffuse = Color.Red, Specular = new Color4(32, 1.0f, 1.0f, 1.0f) }; _sphereModel.DiffuseMapSRV[0] = _whiteTex; _sphere = new BasicModelInstance {Model = _sphereModel}; _spherePos = new Vector3(float.MaxValue); return true; }
public override bool Init() { if (!base.Init()) return false; Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _texMgr = new TextureManager(); _texMgr.Init(Device); _drone = new SkinnedModel(Device, _texMgr, "Models/drone.x", "Textures", true); _droneInstance = new SkinnedModelInstance( "Attack", Matrix.RotationY(MathF.PI), _drone ); foreach (var clip in _droneInstance.Clips) { _droneInstance.AddClip(clip); } _droneInstance.LoopClips = true; _mage = new SkinnedModel(Device, _texMgr, "Models/magician.x", "textures", true); _mageInstance = new SkinnedModelInstance( "Attack", Matrix.RotationY(MathF.PI)*Matrix.Translation(4.0f, 0, 0), _mage ); foreach (var clip in _mageInstance.Clips) { _mageInstance.AddClip(clip); } _mageInstance.LoopClips = true; _soldier = new SkinnedModel(Device, _texMgr, "Models/soldier.x", "Textures", true); _soldierInstance = new SkinnedModelInstance ( "Attack", Matrix.RotationY(MathF.PI)*Matrix.Translation(10, 0, 0), _soldier ); foreach (var clip in _soldierInstance.Clips) { _soldierInstance.AddClip(clip); } _soldierInstance.LoopClips = true; _grid = BasicModel.CreateGrid(Device, 30, 30, 60, 60); _grid.DiffuseMapSRV[0] = (_texMgr.CreateTexture("Textures/floor.dds")); _grid.NormalMapSRV[0]= (_texMgr.CreateTexture("Textures/floor_nmap.dds")); _gridInstance = new BasicModelInstance() { Model = _grid, World = Matrix.Translation(0, -1.5f, 0) }; return true; }
public override bool Init() { if (!base.Init()) return false; Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _texMgr = new TextureManager(); _texMgr.Init(Device); _bunnyModel = BasicModel.LoadSdkMesh(Device, _texMgr, "Models/bunny.sdkmesh", "Textures"); _bunnyInstance = new BasicModelInstance(_bunnyModel); _effect = new FowardLightingEffect(Device, "FX/ForwardLight.fxo"); var blendDesc = new BlendStateDescription { AlphaToCoverageEnable = false, IndependentBlendEnable = false }; blendDesc.RenderTargets[0].BlendEnable = true; blendDesc.RenderTargets[0].SourceBlend = BlendOption.One; blendDesc.RenderTargets[0].DestinationBlend = BlendOption.One; blendDesc.RenderTargets[0].BlendOperation = BlendOperation.Add; blendDesc.RenderTargets[0].SourceBlendAlpha = BlendOption.One; blendDesc.RenderTargets[0].DestinationBlendAlpha = BlendOption.One; blendDesc.RenderTargets[0].BlendOperationAlpha = BlendOperation.Add; blendDesc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; _additiveBlend = BlendState.FromDescription(Device, blendDesc); var passDesc = _effect.Ambient.GetPassByIndex(0).Description; _layout = new InputLayout(Device, passDesc.Signature, InputLayoutDescriptions.PosNormalTexTan); AddUIElements(); return true; }
public override bool Init() { if (!base.Init()) return false; Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _texMgr = new TextureManager(); _texMgr.Init(Device); _treeModel = new BasicModel(Device, _texMgr, "Models/tree.x", "Textures"); _modelInstance = new BasicModelInstance (_treeModel) { World = Matrix.RotationX(MathF.PI / 2) }; _stoneModel = new BasicModel(Device, _texMgr, "Models/stone.x", "Textures"); _stoneInstance = new BasicModelInstance(_stoneModel) { World = Matrix.Scaling(0.1f, 0.1f, 0.1f) * Matrix.Translation(2, 0, 2) }; _dwarfModel = new BasicModel(Device, _texMgr, "Models/Bob.md5mesh", "Textures", true); for (int i = 0; i < _dwarfModel.Materials.Count; i++) { _dwarfModel.Materials[i] = new Material() { Ambient = Color.DarkGray, Diffuse = Color.White, Specular = new Color4(128, 1f, 1.0f, 1.0f) }; } _dwarfInstance = new BasicModelInstance(_dwarfModel) { World = Matrix.RotationX(-MathF.PI / 2)* Matrix.Scaling(0.05f, 0.05f, 0.05f)*Matrix.Translation(4, 0, 4) }; return true; }
public override bool Init() { if ( ! base.Init()) return false; Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _sky = new Sky(Device, "Textures/grasscube1024.dds", 5000.0f); Patch.InitPatchData(Terrain.CellsPerPatch, Device); var tii = new InitInfo { HeightMapFilename = "Textures/terrain.raw", LayerMapFilename0 = "textures/grass.dds", LayerMapFilename1 = "textures/darkdirt.dds", LayerMapFilename2 = "textures/stone.dds", LayerMapFilename3 = "Textures/lightdirt.dds", LayerMapFilename4 = "textures/snow.dds", BlendMapFilename = "textures/blend.dds", HeightScale = 50.0f, HeightMapWidth = 2049, HeightMapHeight = 2049, CellSpacing = 0.5f }; _terrain = new Terrain(); _terrain.Init(Device, ImmediateContext, tii); _camera.Height = _terrain.Height; _txMgr = new TextureManager(); _txMgr.Init(Device); _treeModel = new BasicModel(Device, _txMgr, "Models/tree.x", "Textures"); _treeInstances = new List<BasicModelInstance>(); for (var i = 0; i < NumTrees; i++) { var good = false; var x = MathF.Rand(0, _terrain.Width); var z = MathF.Rand(0, _terrain.Depth); while (!good) { if (_terrain.Height(x, z) < 12.0f) { good = true; } x = MathF.Rand(-_terrain.Width/2, _terrain.Width/2); z = MathF.Rand(-_terrain.Depth/2, _terrain.Depth/2); } var treeInstance = new BasicModelInstance(_treeModel) { World = Matrix.RotationX(MathF.PI / 2) * Matrix.Translation(x, _terrain.Height(x, z), z) }; _treeInstances.Add(treeInstance); } BuildInstancedBuffer(); return true; }
private BasicModel CreateFireworkModel(Color diffuse) { var m1 = new BasicModel(); m1.CreateSphere(Device, .2f, 5, 5); m1.Materials[0] = new Material { Ambient = Color.White, Diffuse = diffuse, Specular = new Color4(128.0f, 1.0f, 1.0f, 1.0f) }; return m1; }
public override bool Init() { if (!base.Init()) return false; Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _texMgr = new TextureManager(); _texMgr.Init(Device); _gridModel = new BasicModel(); _gridModel.CreateGrid(Device, 20, 20, 40, 40); _gridModel.Materials[0] = new Material() { Diffuse = Color.SaddleBrown, Specular = new Color4(16, .9f, .9f, .9f) }; _gridModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/floor.dds"); _gridModel.NormalMapSRV[0] = _texMgr.CreateTexture("textures/floor_nmap.dds"); _sphereModel = new BasicModel(); _sphereModel.CreateSphere(Device, 0.3f, 5, 4); _sphereModel.Materials[0] = new Material() { Ambient = Color.Blue, Diffuse = Color.Blue, Specular = new Color4(64.0f, 1.0f, 1.0f, 1.0f) }; _sphereModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/stones_nmap.dds"); _cylinderModel = new BasicModel(); _cylinderModel.CreateCylinder(Device, 1, 1, 3, 20, 20); _cylinderModel.Materials[0] = new Material() { Ambient = Color.Green, Diffuse = Color.Green, Specular = new Color4(64.0f, 1.0f, 1.0f, 1.0f) }; _cylinderModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/stones_nmap.dds"); _grid = new BasicModelInstance(_gridModel) { TexTransform = Matrix.Scaling(10, 10, 1), World = Matrix.Scaling(10, 1, 10)*Matrix.Translation(0, 0, 90) }; _sphere = new BasicModelInstance(_sphereModel); _cylinder = new BasicModelInstance(_cylinderModel) { World = Matrix.Translation(0, 1.5f, 0) }; return true; }
private void RebuildGeosphere() { if (_inputDelay < 0) { Util.ReleaseCom(ref _geosphereModel); _geosphereModel = new BasicModel(); _geosphereModel.CreateGeosphere(Device, 5, _subdivisions); _geosphere.Model = _geosphereModel; _geosphereModel.Materials[0] = _material; _inputDelay = 1; } }
private void BuildShapeGeometryBuffers() { _boxModel = new BasicModel(); _boxModel.CreateBox(Device, 1, 1, 1); _boxModel.Materials[0] = new Material { Ambient = new Color4(1f, 1f, 1f), Diffuse = new Color4(1f, 1f, 1f), Specular = new Color4(16.0f, 0.8f, 0.8f, 0.8f), Reflect = Color.Black }; _boxModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/bricks.dds"); _boxModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/bricks_nmap.dds"); _sphereModel = new BasicModel(); _sphereModel.CreateSphere(Device, 0.5f, 20, 20); _sphereModel.Materials[0] = new Material { Ambient = new Color4(0.2f, 0.3f, 0.4f), Diffuse = new Color4(0.2f, 0.3f, 0.4f), Specular = new Color4(16.0f, 0.9f, 0.9f, 0.9f), Reflect = new Color4(0.4f, 0.4f, 0.4f) }; _cylinderModel = new BasicModel(); _cylinderModel.CreateCylinder(Device, 0.5f, 0.3f, 3.0f, 15, 15); _cylinderModel.Materials[0] = new Material { Ambient = new Color4(1f, 1f, 1f), Diffuse = new Color4(1f, 1f, 1f), Specular = new Color4(32.0f, 1f, 1f, 1f), Reflect = Color.Black }; _cylinderModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/bricks.dds"); _cylinderModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/bricks_nmap.dds"); for (var i = 0; i < 5; i++) { _cylinders[i * 2] = new BasicModelInstance(_cylinderModel) { World = Matrix.Translation(-5.0f, 1.5f, -10.0f + i * 5.0f), TexTransform = Matrix.Scaling(1, 2, 1) }; _cylinders[i * 2 + 1] = new BasicModelInstance(_cylinderModel) { World = Matrix.Translation(5.0f, 1.5f, -10.0f + i * 5.0f), TexTransform = Matrix.Scaling(1, 2, 1) }; _spheres[i * 2] = new BasicModelInstance(_sphereModel) { World = Matrix.Translation(-5.0f, 3.45f, -10.0f + i * 5.0f) }; _spheres[i * 2 + 1] = new BasicModelInstance(_sphereModel) { World = Matrix.Translation(5.0f, 3.45f, -10.0f + i * 5.0f) }; } _box = new BasicModelInstance(_boxModel) { TexTransform = Matrix.Scaling(2, 1, 1), World = Matrix.Scaling(3.0f, 1.0f, 3.0f) * Matrix.Translation(0, 0.5f, 0) }; }
public static BasicModel LoadFromTxtFile(Device device, string filename) { var vertices = new List<Basic32>(); var indices = new List<int>(); var vcount = 0; var tcount = 0; using (var reader = new StreamReader(filename)) { var input = reader.ReadLine(); if (input != null) // VertexCount: X vcount = Convert.ToInt32(input.Split(new[] { ':' })[1].Trim()); input = reader.ReadLine(); if (input != null) //TriangleCount: X tcount = Convert.ToInt32(input.Split(new[] { ':' })[1].Trim()); // skip ahead to the vertex data do { input = reader.ReadLine(); } while (input != null && !input.StartsWith("{")); // Get the vertices for (int i = 0; i < vcount; i++) { input = reader.ReadLine(); if (input != null) { var vals = input.Split(new[] { ' ' }); vertices.Add( new Basic32( new Vector3( Convert.ToSingle(vals[0].Trim()), Convert.ToSingle(vals[1].Trim()), Convert.ToSingle(vals[2].Trim())), new Vector3( Convert.ToSingle(vals[3].Trim()), Convert.ToSingle(vals[4].Trim()), Convert.ToSingle(vals[5].Trim())), new Vector2() ) ); } } // skip ahead to the index data do { input = reader.ReadLine(); } while (input != null && !input.StartsWith("{")); // Get the indices for (var i = 0; i < tcount; i++) { input = reader.ReadLine(); if (input == null) { break; } var m = input.Trim().Split(new[] { ' ' }); indices.Add(Convert.ToInt32(m[0].Trim())); indices.Add(Convert.ToInt32(m[1].Trim())); indices.Add(Convert.ToInt32(m[2].Trim())); } } var ret = new BasicModel(); var subset = new MeshGeometry.Subset { FaceCount = indices.Count / 3, FaceStart = 0, VertexCount = vertices.Count, VertexStart = 0 }; ret._subsets.Add(subset); var max = new Vector3(float.MinValue); var min = new Vector3(float.MaxValue); foreach (var vertex in vertices) { max = Vector3.Maximize(max, vertex.Position); min = Vector3.Minimize(min, vertex.Position); } ret.BoundingBox = new BoundingBox(min, max); ret._vertices.AddRange(vertices.Select(v => new PosNormalTexTan(v.Position, v.Normal, v.Tex, new Vector3(1, 0, 0))).ToList()); ret._indices.AddRange(indices.Select(i => (short)i)); ret.Materials.Add(new Material { Ambient = Color.Gray, Diffuse = Color.White, Specular = new Color4(16, 1, 1, 1) }); ret.DiffuseMapSRV.Add(null); ret.NormalMapSRV.Add(null); ret._modelMesh.SetSubsetTable(ret._subsets); ret._modelMesh.SetVertices(device, ret._vertices); ret._modelMesh.SetIndices(device, ret._indices); return ret; }