private void BuildGeometryBuffers() { var box = GeometryGenerator.CreateBox(1, 1, 1); _boxVertexOffset = 0; _boxIndexCount = box.Indices.Count; _boxIndexOffset = 0; var vertices = new List <Basic32>(); foreach (var vertex in box.Vertices) { vertices.Add(new Basic32(vertex.Position, vertex.Normal, vertex.TexC)); } var vbd = new BufferDescription(Basic32.Stride * vertices.Count, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _boxVB = new Buffer(Device, new DataStream(vertices.ToArray(), false, false), vbd); var indices = box.Indices; var ibd = new BufferDescription(sizeof(int) * indices.Count, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _boxIB = new Buffer(Device, new DataStream(indices.ToArray(), false, false), ibd); }
protected override void CreateBoxInternal(Device device, float width, float height, float depth) { var box = GeometryGenerator.CreateBox(width, height, depth); InitFromMeshData(device, box); _meshCount = 1; }
private void BuildShapeGeometryBuffers() { var box = GeometryGenerator.CreateBox(1, 1, 1); var grid = GeometryGenerator.CreateGrid(20, 30, 60, 40); var sphere = GeometryGenerator.CreateSphere(0.5f, 20, 20); var cylinder = GeometryGenerator.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20); _boxVertexOffset = 0; _gridVertexOffset = box.Vertices.Count; _sphereVertexOffset = _gridVertexOffset + grid.Vertices.Count; _cylinderVertexOffset = _sphereVertexOffset + sphere.Vertices.Count; _boxIndexCount = box.Indices.Count; _gridIndexCount = grid.Indices.Count; _sphereIndexCount = sphere.Indices.Count; _cylinderIndexCount = cylinder.Indices.Count; _boxIndexOffset = 0; _gridIndexOffset = _boxIndexCount; _sphereIndexOffset = _gridIndexOffset + _gridIndexCount; _cylinderIndexOffset = _sphereIndexOffset + _sphereIndexCount; var totalVertexCount = box.Vertices.Count + grid.Vertices.Count + sphere.Vertices.Count + cylinder.Vertices.Count; var totalIndexCount = _boxIndexCount + _gridIndexCount + _sphereIndexCount + _cylinderIndexCount; var vertices = box.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC)).ToList(); vertices.AddRange(grid.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC))); vertices.AddRange(sphere.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC))); vertices.AddRange(cylinder.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC))); var vbd = new BufferDescription(Basic32.Stride * totalVertexCount, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _shapesVB = new Buffer(Device, new DataStream(vertices.ToArray(), false, false), vbd); var indices = new List <int>(); indices.AddRange(box.Indices); indices.AddRange(grid.Indices); indices.AddRange(sphere.Indices); indices.AddRange(cylinder.Indices); var ibd = new BufferDescription(sizeof(int) * totalIndexCount, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _shapesIB = new Buffer(Device, new DataStream(indices.ToArray(), false, false), ibd); }
private void BuildGeometryBuffers() { var box = GeometryGenerator.CreateBox(1.0f, 1.0f, 1.0f); var grid = GeometryGenerator.CreateGrid(20.0f, 30.0f, 60, 40); var sphere = GeometryGenerator.CreateSphere(0.5f, 20, 20); var cylinder = GeometryGenerator.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20); _boxVertexOffset = 0; _gridVertexOffset = box.Vertices.Count; _sphereVertexOffset = _gridVertexOffset + grid.Vertices.Count; _cylinderVertexOffset = _sphereVertexOffset + sphere.Vertices.Count; _boxIndexCount = box.Indices.Count; _gridIndexCount = grid.Indices.Count; _sphereIndexCount = sphere.Indices.Count; _cylinderIndexCount = cylinder.Indices.Count; _boxIndexOffset = 0; _gridIndexOffset = _boxIndexCount; _sphereIndexOffset = _gridIndexOffset + _gridIndexCount; _cylinderIndexOffset = _sphereIndexOffset + _sphereIndexCount; var totalVertexCount = box.Vertices.Count + grid.Vertices.Count + sphere.Vertices.Count + cylinder.Vertices.Count; var totalIndexCount = _boxIndexCount + _gridIndexCount + _sphereIndexCount + _cylinderIndexCount; var vs = new List <VertexPC>(); foreach (var vertex in box.Vertices) { vs.Add(new VertexPC(vertex.Position, Color.Red)); } foreach (var v in grid.Vertices) { vs.Add(new VertexPC(v.Position, Color.Green)); } foreach (var v in sphere.Vertices) { vs.Add(new VertexPC(v.Position, Color.Blue)); } foreach (var v in cylinder.Vertices) { vs.Add(new VertexPC(v.Position, Color.Yellow)); } var vbd = new BufferDescription(VertexPC.Stride * totalVertexCount, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _vb = new Buffer(Device, new DataStream(vs.ToArray(), false, false), vbd); var indices = new List <int>(); indices.AddRange(box.Indices); indices.AddRange(grid.Indices); indices.AddRange(sphere.Indices); indices.AddRange(cylinder.Indices); var ibd = new BufferDescription(sizeof(int) * totalIndexCount, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _ib = new Buffer(Device, new DataStream(indices.ToArray(), false, false), ibd); }
public override void CreateBox(Device device, float width, float height, float depth) { var box = GeometryGenerator.CreateBox(width, height, depth); InitFromMeshData(device, box); }
private void CreateBoxInternal(Device device, float width, float height, float depth) { var box = GeometryGenerator.CreateBox(width, height, depth); InitFromMeshData(device, box); }