public override bool enterStem(CS_Stem stem) { foreach (CS_SegmentImpl seg in stem.getSections()) { if (seg.getSubsegmentCount() == 1) { DXSKV v0, v1; Vector3 cv0 = seg.getLowerPosition(); Vector3 cv1 = seg.getUpperPosition(); // the tree is caculated in openGL coordinates with Z "up" so... v0.P = new Vector3(cv0.X, cv0.Z, cv0.Y); v1.P = new Vector3(cv1.X, cv1.Z, cv1.Y); v0.C = colors[Math.Min(3, stem.getLevel())]; v1.C = colors[Math.Min(3, stem.getLevel())]; BBox.Maximum = Vector3.Max(BBox.Maximum, v0.P); BBox.Maximum = Vector3.Max(BBox.Maximum, v1.P); BBox.Minimum = Vector3.Min(BBox.Minimum, v0.P); BBox.Minimum = Vector3.Min(BBox.Minimum, v1.P); Vertices2[Math.Min(stem.getLevel(), 3)].Add(v0); Vertices2[Math.Min(stem.getLevel(), 3)].Add(v1); } else { Vector3 currPos = seg.getLowerPosition(); for (int subindex = 0; subindex < seg.getSubsegmentCount(); subindex++) { DXSKV v0, v1; v0.P = new Vector3(currPos.X, currPos.Z, currPos.Y); v1.P = new Vector3(0, 0, 0); v1.P = seg.subsegments[subindex].getTransformation().apply(v1.P); currPos = v1.P; v1.P = new Vector3(v1.P.X, v1.P.Z, v1.P.Y); v0.C = colors[Math.Min(3, stem.getLevel())]; v1.C = colors[Math.Min(3, stem.getLevel())]; Vertices2[Math.Min(stem.getLevel(), 3)].Add(v0); Vertices2[Math.Min(stem.getLevel(), 3)].Add(v1); BBox.Maximum = Vector3.Max(BBox.Maximum, v0.P); BBox.Maximum = Vector3.Max(BBox.Maximum, v1.P); BBox.Minimum = Vector3.Min(BBox.Minimum, v0.P); BBox.Minimum = Vector3.Min(BBox.Minimum, v1.P); } } } return(true); }
public override bool enterStem(CS_Stem stem) { // 1. Create the first section bool first = true; Vector3[] section_base = stem.getSections()[0].getSectionPoints(); AddRangeVector3(section_base, stem.getLevel(), first); first = false; // 2. for each section but the last one - generate the upper part of the section // and connect it with triangles to the previous section // we use the lower section of next segment as upper section of current segment for (int i = 0; i < stem.getSections().Count; i++) { if (stem.getSections()[i].getSubsegmentCount() == 1 && i != stem.getSections().Count - 1) { Vector3[] section_next = stem.getSections()[i + 1].getSectionPoints(); AddRangeVector3(section_next, stem.getLevel(), first); } else { CS_SegmentImpl seg = stem.getSections()[i]; for (int j = 0; j < seg.getSubsegmentCount(); j++) { CS_SubsegmentImpl subseg = seg.subsegments[j]; Vector3[] section_next = subseg.getSectionPoints(); AddRangeVector3(section_next, stem.getLevel(), first); } } } // 3. The last section I don't know how it gets calculated in initial Arbaro implementation :-( // So I modified getSectionPoints to retrieve explicitely this last section if (stem.getSections()[stem.getSections().Count - 1].getSubsegmentCount() == 1) { Vector3[] section_last = stem.getSections()[stem.getSections().Count - 1].getSectionPoints(false); AddRangeVector3(section_last, stem.getLevel(), first); } return(true); }
public override bool leaveStem(CS_Stem stem) { return(true); }
public override bool enterStem(CS_Stem stem) { // 1. Create the first section Vector3[] section_base = stem.getSections()[0].getSectionPoints(); List <DXBaseArbaroTreeMesh.DXVertex> dxvv1 = new List <DXBaseArbaroTreeMesh.DXVertex>(); foreach (Vector3 v in section_base) { DXBaseArbaroTreeMesh.DXVertex dxv = _meshes[stem.getLevel()].Vertices.Add(new DXArbaroVertexTrait(v)); dxvv1.Add(dxv); } // 2. for each section but the last one - generate the upper part of the section // and connect it with triangles to the previous section // we use the lower section of next segment as upper section of current segment for (int i = 0; i < stem.getSections().Count; i++) { if (stem.getSections()[i].getSubsegmentCount() == 1 && i != stem.getSections().Count - 1) { Vector3[] section_next = stem.getSections()[i + 1].getSectionPoints(); List <DXBaseArbaroTreeMesh.DXVertex> dxvv2 = new List <DXBaseArbaroTreeMesh.DXVertex>(); foreach (Vector3 v in section_next) { DXBaseArbaroTreeMesh.DXVertex dxv = _meshes[stem.getLevel()].Vertices.Add(new DXArbaroVertexTrait(v)); dxvv2.Add(dxv); } AddRangeVertex(_meshes[stem.getLevel()], dxvv1, dxvv2); dxvv1 = dxvv2; } else { CS_SegmentImpl seg = stem.getSections()[i]; for (int j = 0; j < seg.getSubsegmentCount(); j++) { CS_SubsegmentImpl subseg = seg.subsegments[j]; Vector3[] section_next = subseg.getSectionPoints(); List <DXBaseArbaroTreeMesh.DXVertex> dxvv2 = new List <DXBaseArbaroTreeMesh.DXVertex>(); foreach (Vector3 v in section_next) { DXBaseArbaroTreeMesh.DXVertex dxv = _meshes[stem.getLevel()].Vertices.Add(new DXArbaroVertexTrait(v)); dxvv2.Add(dxv); } AddRangeVertex(_meshes[stem.getLevel()], dxvv1, dxvv2); dxvv1 = dxvv2; } } } // 3. The last section I don't know how it gets calculated in initial Arbaro implementation :-( // So I modified getSectionPoints to retrieve explicitely this last section if (stem.getSections()[stem.getSections().Count - 1].getSubsegmentCount() == 1) { Vector3[] section_last = stem.getSections()[stem.getSections().Count - 1].getSectionPoints(false); List <DXBaseArbaroTreeMesh.DXVertex> dxvv2 = new List <DXBaseArbaroTreeMesh.DXVertex>(); foreach (Vector3 v in section_last) { DXBaseArbaroTreeMesh.DXVertex dxv = _meshes[stem.getLevel()].Vertices.Add(new DXArbaroVertexTrait(v)); dxvv2.Add(dxv); } AddRangeVertex(_meshes[stem.getLevel()], dxvv1, dxvv2); } return(true); }