Skip to content

Preserve dimensions when switching shapes - #377

Open
chambm wants to merge 1 commit into
KSP-RO:masterfrom
chambm:feat/keep-dimensions-on-shape-change
Open

Preserve dimensions when switching shapes#377
chambm wants to merge 1 commit into
KSP-RO:masterfrom
chambm:feat/keep-dimensions-on-shape-change

Conversation

@chambm

@chambm chambm commented Jun 15, 2026

Copy link
Copy Markdown

Switching a part's procedural shape in the editor reset every dimension to the new shape's persisted defaults, which often shifted the part and its attached children and is just generally not what users want for an existing part. Turning a cylinder into a cone or vice versa is probably the most common case where it's very annoying to not have the dimensions carry over, so here we carry the previous shape's bounding length and outer/inner diameter onto the new shape instead.

  • Add ProceduralAbstractShape.CopyDimensions(fromShape): no-op by default, overridden per shape to map the generic Length / MaxDiameter / InnerMaxDiameter onto its own fields. Called from ProceduralPart.ChangeShape (editor only) before the attachment reposition so nodes/children map onto the same size. Cones collapse to a straight profile; a truss maps the diameter to its top/bottom envelope; hollow shapes carry the bore.
  • ChangeShape does a single AdjustDimensionBounds()/UpdateShape() pass per switch (the tail pass is skipped once the editor block has refreshed), avoiding a redundant mesh rebuild and the duplicate model/collider-changed events it would fire.
  • Enforce dimension validity for programmatic writes, not just the sliders: hollow shapes clamp the inner-diameter value below the outer, and the pill shapes clamp the fillet value to its max, in AdjustDimensionBounds -- so a carried-in thin wall can't build a degenerate torus/capsule.

Switching a part's procedural shape in the editor reset every dimension to the
new shape's persisted defaults, which (because the part is anchored by its
attach nodes) shifted the part and its attached children. Carry the previous
shape's bounding length and outer/inner diameter onto the new shape instead.

- Add ProceduralAbstractShape.CopyDimensions(fromShape): no-op by default,
  overridden per shape to map the generic Length / MaxDiameter / InnerMaxDiameter
  onto its own fields. Called from ProceduralPart.ChangeShape (editor only)
  before the attachment reposition so nodes/children map onto the same size.
  Cones collapse to a straight profile; a truss maps the diameter to its
  top/bottom envelope; hollow shapes carry the bore.
- ChangeShape does a single AdjustDimensionBounds()/UpdateShape() pass per
  switch (the tail pass is skipped once the editor block has refreshed),
  avoiding a redundant mesh rebuild and the duplicate model/collider-changed
  events it would fire.
- Enforce dimension validity for programmatic writes, not just the sliders:
  hollow shapes clamp the inner-diameter value below the outer, and the pill
  shapes clamp the fillet value to its max, in AdjustDimensionBounds -- so a
  carried-in thin wall can't build a degenerate torus/capsule.
@chambm

chambm commented Jun 29, 2026

Copy link
Copy Markdown
Author

@DRVeyl Could you review this when you get a chance please? Thanks.

@Clayell

Clayell commented Aug 17, 2026

Copy link
Copy Markdown

After testing, It Just Works™. Good PR 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants