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; } } }
private void MakeTreeFromParams(string filename, bool paramExists = false) { if (!paramExists) { csParams = new CS_Params(); csParams.prepare(13); ResetMenuItems(); if (filename != "") { Text = "Arbaro C# V0.1 - " + Path.GetFileName(mainOpenFileDialog.FileName); csParams.readFromXML(mainOpenFileDialog.FileName); } else { Text = "Arbaro C# V0.1"; } // refresh params GUI pgv = new CS_ParamGroupsView(treeView1); pvt = new CS_ParamValueTable(paramTablePanel, paramExplanationPanel, csParams); pev = new CS_ParamExplanationView(paramExplanationPanel, paramTablePanel, csParams); csParams.enableDisable(); csParams.OnParamChanged += csParams_OnParamChanged; } CS_PreciseTimer t0 = new CS_PreciseTimer(10); DateTime tStart = t0.Now; CS_TreeGenerator treeGenerator = CS_TreeGeneratorFactory.createShieldedTreeGenerator(csParams); tree = treeGenerator.makeTree(new Object()); DateTime tEnd = t0.Now; // make 3D Tree if (Program.Renderer.RenderableList.ContainsKey("Skeleton")) { DXRenderable s = Program.Renderer.RenderableList["Skeleton"]; Program.Renderer.RenderableList.Remove("Skeleton"); s.Dispose(); } DXTreeSkeleton sk = new DXTreeSkeleton(tree, csParams); sk.Visible = false; Program.Renderer.RenderableList.Add("Skeleton", sk); if (skeletonToolStripMenuItem.Checked) { sk.Visible = true; } else { sk.Visible = false; } if (Program.Renderer.RenderableList.ContainsKey("TreeMesh")) { DXRenderable s = Program.Renderer.RenderableList["TreeMesh"]; Program.Renderer.RenderableList.Remove("TreeMesh"); s.Dispose(); } //DXTreeMesh me = new DXTreeMesh(tree, csParams); //Program.Renderer.RenderableList.Add("TreeMesh", me); DXArbaroTreeMesh me = new DXArbaroTreeMesh(tree, csParams); Program.Renderer.RenderableList.Add("TreeMesh", me); if (solidWireframeToolStripMenuItem.Checked) { me.Visible = true; } else { me.Visible = false; } // only reset the view when a new tree is loaded if (!paramExists) { Program.Renderer.CameraControler.LookAt(me.BBox); } float elapsed = (float)(tEnd.Subtract(tStart)).TotalMilliseconds; Console.WriteLine(elapsed); }
public override bool enterTree(CS_Tree tree) { return(true); }
public override bool leaveTree(CS_Tree tree) { return(true); }
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; } } }