JonnyOThan / TweakScale

Forked from Gaius Goodspeed's Goodspeed Aerospace Part & TweakScale plugin
Other
3 stars 2 forks source link

SAF Fairings with B9PS variants don't scale correctly #40

Open JonnyOThan opened 5 months ago

JonnyOThan commented 5 months ago

SAF on its own seems ok. Getting a report that bluedog_FairingBase_0p625m_SAF doesn't scale propertly after switching the b9ps variant.

JonnyOThan commented 5 months ago

Looks like this is using a pretty simple b9ps module switch: https://github.com/Wallum/Bluedog-Design-Bureau/blob/3c336ced5d1a5ef7106c7da6c7b0b288a3311df6/Gamedata/Bluedog_DB/Parts/SAF_Fairings/bluedog_0p625m_Fairings_SAF.cfg#L278

I'm guessing that switching the subtype after scaling the part isn't applying the scale factor to those module fields. One possible fix here would be to apply scaling to all the subtypes in the b9ps module...but are those actually created per part instance or are they shared? If the latter then that wouldn't work.

So can we re-run the scaling logic on just the module that changed? It might be feasible to just run the scaling logic on the entire part with a relative scale of 1.0, but then if that particular module needed relative scale for something that wouldn't work either.

Confirmed: switching the subtype and then scaling works, the reverse does not.

Looks like there's an event that could be hooked up here: https://github.com/blowfishpro/B9PartSwitch/blob/e282eb138340aa0ea2c2926cb48e9c6a1e408d93/B9PartSwitch/PartSwitch/PartModifiers/ModuleDataHandlerBasic.cs#L42C33-L42C50

JonnyOThan commented 5 months ago

OK so it's actually way worse than that. TweakScale doesn't actually scale anything about SimpleAdjustableFairings - it just works because the fairing is a child gameobject of the model: https://github.com/blowfishpro/SimpleAdjustableFairings/blob/7d33d008c52033ac7ae284e54db156d2a1ad02ae/SimpleAdjustableFairings/ModuleSimpleAdjustableFairing.cs#L546

HOWEVER in cases where you call SetupFairing on something that is already scaled, NestToParent doesn't really handle the scale correctly. It calls Transform.SetParent, leaving worldPositionStays = true. Then it sets the local position and rotation to identity, but doesn't change scale. So the fairing will always be at default scale, regardless of what the parent transform is.