/// <summary> /// Sets the transform info once all branch lines have been loaded. /// </summary> public void SetTransform(TreeInfo tree) { if (_lines.Count > 0) { int baseID = _lines[0].id; int baseParent = _lines[0].parentId; foreach (var line in _lines) { bool containsParent = false; bool containsChild = false; foreach (var line2 in _lines) { if (line2.id == line.parentId) { containsParent = true; } if (line.id == line2.parentId) { containsChild = true; } } if (!containsParent) { startPt = line.startPt; } if (!containsChild) { endPt = line.endPt; } } position = startPt + (endPt - startPt) / 2; //Orentation = Quaternion.LookRotation((endPt- startPt).normalized); Orentation = Quaternion.FromToRotation(Vector3.up, (endPt - startPt).normalized); scale = new Vector3(radius, length / 2, radius); transform = Matrix4x4.TRS(position, Orentation, scale); } }
public BranchInfo(string[] _data, TreeInfo _parentTree) { //[0] rowID, parentRowID, startPtX, startPtY, startPtZ, endPtX, endPtY, endPtZ, rowRadius, rowElevation, rowInclination, rowLength, rowDistToTip, //[13] segmentID, parentSegmentID, segType, segIsDead, segRadius, segElevation, segExposure, segInclination, segLength, segDistToTip if (_data.Length <= 23) { id = (int.Parse(_data[13])); parentId = (int.Parse(_data[14])); typeName = _data[15]; if (Enum.TryParse(typeName, out BranchType _Type)) { bType = _Type; } else { bType = BranchType.Undefined; } isDead = bool.Parse(_data[16]); length = (float.Parse(_data[21])); if (length < lengthLimit.x) { lengthLimit.x = length; } if (length > lengthLimit.y) { lengthLimit.y = length; } radius = (float.Parse(_data[17])); if (radius < radiusLimit.x) { radiusLimit.x = radius; } if (radius > radiusLimit.y) { radiusLimit.y = radius; } elevation = (float.Parse(_data[18])); if (elevation < elevationLimit.x) { elevationLimit.x = elevation; } if (elevation > elevationLimit.y) { elevationLimit.y = elevation; } exposure = (int.Parse(_data[19])); if (exposure < exposureLimit.x) { exposureLimit.x = exposure; } if (exposure > exposureLimit.y) { exposureLimit.y = exposure; } inclanation = (float.Parse(_data[20])); if (inclanation < inclanationLimit.x) { inclanationLimit.x = inclanation; } if (inclanation > inclanationLimit.y) { inclanationLimit.y = inclanation; } distanceToTip = (float.Parse(_data[22])); if (distanceToTip < distanceToTipLimit.x) { distanceToTipLimit.x = distanceToTip; } if (distanceToTip > distanceToTipLimit.y) { distanceToTipLimit.y = distanceToTip; } tree = _parentTree; } else { id = int.MinValue; } }