//private Buffer _indices; /// <summary> /// Set of lines in 3D space. /// </summary> /// <param name="origin"></param> /// <param name="xAxis"></param> /// <param name="yAxis"></param> /// <param name="scale">Scaling the field extent.</param> /// <param name="field"></param> public Mesh(Plane plane, TileSurface surf, RenderEffect effect = RenderEffect.DEFAULT, Colormap colormap = Colormap.Parula) { _color = surf.Color; this._vertexSizeBytes = Marshal.SizeOf(typeof(Vector4)); this._topology = PrimitiveTopology.TriangleList; this. // Setting up the vertex buffer. UsedMap = colormap; _planeNormal = plane.ZAxis; _planeNormal.Normalize(); _effect = _meshEffect; SetRenderEffect(effect); GenerateGeometry(plane, surf); this._vertexLayout = new InputLayout(_device, _technique.GetPassByIndex(0).Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0), new InputElement("SCALAR", 0, Format.R32_Float, 12, 0) }); }
/// <summary> /// Setting up the vertex buffer. Vertex size and number has to be known. /// </summary> /// <param name="origin"></param> /// <param name="xAxis"></param> /// <param name="yAxis"></param> /// <param name="scale"></param> protected void GenerateGeometry(Plane plane, TileSurface surf) { Vector4[] verts = surf.GetVertices(plane); uint[] idxs = surf.Indices; _numVertices = verts.Length; _numindices = idxs.Length; // Write poition and UV-map data. var stream = new DataStream(_numVertices * _vertexSizeBytes, true, true); stream.WriteRange(verts); stream.Position = 0; // Create and fill buffer. _vertices = new Buffer(_device, stream, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = _numVertices * _vertexSizeBytes, Usage = ResourceUsage.Default }); stream.Dispose(); stream = new DataStream(idxs.Length * sizeof(uint), true, true); stream.WriteRange(idxs); stream.Position = 0; _indices = new Buffer(_device, stream, new BufferDescription() { BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = idxs.Length * sizeof(int), Usage = ResourceUsage.Default }); }