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;

                }
            }
        }
Beispiel #2
0
        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;
                }
            }
        }