public TelescopeShell addChildShell(TelescopeShell parent, TelescopeParameters parentParams, TelescopeParameters childParams, TelescopeParameters nextParams, bool isNotLast) { int i = shells.Count; // Make the new shell, and set the previous shell as its parent GameObject shellObj = new GameObject(); shellObj.transform.parent = parent.transform; shellObj.name = name + "-shell" + i; // Make the geometry, etc. TelescopeShell newShell = shellObj.AddComponent <TelescopeShell>(); newShell.GenerateGeometry(childParams, nextParams, doOverhang: true); newShell.setMaterial(material); // Set the shell's rest transformation relative to its parent. // When the shell's current extension ratio is 0, this is where // it is located relative to its parent. // newShell.baseRadians = newShell.radiansOfLength(wallThickness); newShell.baseTranslation = TelescopeUtils.childBasePosition(parentParams, childParams); newShell.baseRotation = TelescopeUtils.childBaseRotation(parentParams, childParams); shells.Add(newShell); shellObj.layer = 8; newShell.containingSegment = this; return(newShell); }
CylinderMesh GenerateInnerCylinder(TelescopeParameters nextParams, bool overhang, float arcOffset, int extraRings = 0) { TelescopeParameters ourParams = getParameters(); CylinderMesh innerCyl; // If there is a change in profile from this shell to the next... if (nextParams != null && (nextParams.curvature != curvature || nextParams.torsion != torsion || nextParams.radius < radius - Constants.WALL_THICKNESS * 1.01f)) { // Generate the outer profile of the child shell; this will become // the inner profile of this shell. TelescopeParameters innerParams = new TelescopeParameters(nextParams.length, nextParams.radius, nextParams.thickness, nextParams.curvature, nextParams.torsion, nextParams.twistFromParent); innerCyl = GenerateCylinder(innerParams, Constants.TAPER_SLOPE, innerGroove: true, overhang: overhang, extraRings: extraRings); // Move and rotate the inner profile so that the end circles align. Quaternion alignRotation = TelescopeUtils.childBaseRotation(ourParams, nextParams); Vector3 alignTranslation = TelescopeUtils.childBasePosition(ourParams, nextParams); Quaternion backRotation = TelescopeUtils.RotateAlongHelix(nextParams.curvature, nextParams.torsion, arcOffset); Vector3 backTranslation = TelescopeUtils.TranslateAlongHelix(nextParams.curvature, nextParams.torsion, arcOffset); innerCyl.ApplyRotation(backRotation); innerCyl.ApplyTranslation(backTranslation); innerCyl.ApplyRotation(alignRotation); innerCyl.ApplyTranslation(alignTranslation); } else { TelescopeParameters innerParams = new TelescopeParameters(length, radius - thickness, thickness, curvature, torsion, 0); innerCyl = GenerateCylinder(innerParams, Constants.TAPER_SLOPE, innerGroove: (nextParams != null), overhang: overhang, extraRings: extraRings); if (nextParams != null) { Quaternion backRotation = TelescopeUtils.RotateAlongHelix(nextParams.curvature, nextParams.torsion, arcOffset); Vector3 backTranslation = TelescopeUtils.TranslateAlongHelix(nextParams.curvature, nextParams.torsion, arcOffset); innerCyl.ApplyRotation(backRotation); innerCyl.ApplyTranslation(backTranslation); } } return(innerCyl); }