public DXTreeSkeleton(CS_Tree tree, CS_Params csParams) { InitShaders(); DXTreeSkeleton_TreeTraversal traversal = new DXTreeSkeleton_TreeTraversal(csParams); tree.traverseTree(traversal); BBox = traversal.BBox; for (int i = 0; i < 5; i++) { if (traversal.Vertices2[i].Count != 0) { var stream = new DataStream(traversal.Vertices2[i].Count * Marshal.SizeOf(typeof(DXSKV)), true, true); stream.WriteRange(traversal.Vertices2[i].ToArray()); stream.Position = 0; _vertexBuffer2[i] = new Buffer(DXDevice, stream, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = traversal.Vertices2[i].Count * Marshal.SizeOf(typeof(DXSKV)), Usage = ResourceUsage.Default }); stream.Dispose(); List <UInt32> indices = new List <UInt32>(); for (int k = 0; k < traversal.Vertices2[i].Count; k++) { indices.Add((UInt32)k); } stream = new DataStream(indices.Count * sizeof(UInt32), true, true); stream.WriteRange(indices.ToArray()); stream.Position = 0; _indexBuffer2[i] = new Buffer(DXDevice, stream, new BufferDescription() { BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = indices.Count * sizeof(UInt32), Usage = ResourceUsage.Default }); stream.Dispose(); IndexCount2[i] = indices.Count; } } }
public DXArbaroTreeMesh(CS_Tree tree, CS_Params csParams) : base() { _csParams = csParams; DXTreeMesh_TreeTraversal traversal = new DXTreeMesh_TreeTraversal(meshes, csParams); tree.traverseTree(traversal); InitShaders(); BBox = new BoundingBox(); BBox.Minimum = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue); BBox.Maximum = new Vector3(float.MinValue, float.MinValue, float.MinValue); for (int i = 0; i < 5; i++) { // Build vertex buffer if (meshes[i].Faces.Count != 0) { var streamV = new DataStream(meshes[i].Vertices.Count * Marshal.SizeOf(typeof(DXMEV)), true, true); DataStream streamI = new DataStream(meshes[i].Faces.Count * 3 * sizeof(UInt32), true, true); // Let's make it simple for now // We now we are dealing with a quad mesh // and we hope everything wii be OK foreach (DXBaseArbaroTreeMesh.DXVertex dxv in meshes[i].Vertices) { Vector3 pos = dxv.Traits.Position; DXMEV dxmev = new DXMEV(); dxmev.P = new Vector4(pos.X, pos.Y, pos.Z, 1); streamV.Write(dxmev); BBox.Minimum = Vector3.Min(BBox.Minimum, pos); BBox.Maximum = Vector3.Max(BBox.Maximum, pos); } streamV.Position = 0; _vertexBuffer2[i] = new Buffer(DXDevice, streamV, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = meshes[i].Vertices.Count * Marshal.SizeOf(typeof(DXMEV)), Usage = ResourceUsage.Default }); streamV.Dispose(); foreach (DXBaseArbaroTreeMesh.DXFace dxf in meshes[i].Faces) { List <int> indices = new List <int>(); foreach (DXBaseArbaroTreeMesh.DXVertex dxv in dxf.Vertices) { indices.Add(dxv.Index); } streamI.Write(indices[0]); streamI.Write(indices[1]); streamI.Write(indices[2]); } streamI.Position = 0; _indexBuffer2[i] = new Buffer(DXDevice, streamI, new BufferDescription() { BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = meshes[i].Faces.Count * 3 * sizeof(UInt32), Usage = ResourceUsage.Default }); streamI.Dispose(); IndexCount2[i] = meshes[i].Faces.Count * 3; } } }