net-lisias-ksp/DistantObject

Support ReStock!

Closed this issue · 22 comments

As explained here on Forum by the Fellow Kerbonaut Alexsys:

A portion of tweakscaled non Restock modified assets are now visible, it's a grand step :)

(Actually. It decides to render those parts with stock textures (even though Restock by default tries to eliminate them being loaded into the game) and both in tweakscaled manner)
Basically it sees tweakscaled objects perfectly now, and converts the texture rendered in DOE to stock. (only a certain few parts that by default are retextured by restock, mostly are invisible)


This is not going to be simple, but I don't thing it will that hard neither - I need to understand how ReStock handles the MODEL section - and there's a good chance that this is purely Stock behaviour that would end up beneficing everybody!

It ended up being extremely simple - after I refactored what I call now "MeshEngine", where the mesh handling code is now properly decoupled from the rest of the life cycle of the plugin.

ReStock doesn't do anything "fancy" - it merely adds many MODEL sections, each one with the mesh for a part of the part (pun not intended!). So, by example, ReStock can reuse the top and the bottom parts of a fuel tank into another one with the same bulkhead, but taller.

Yep. Preliminary tests suggests that my GPU is near committing suicide every tome a ReStock part is rendered on the Telescope window...

Beefier machines will probably pass trough unscratched - and puny machines like mine should not be using ReStock anyway. :)

screenshot52

Implemented on commit 5b06bf3 .

I will keep this issue open, as I doubt this task will be finished without some more work. The performance when ReStock is installed is abysmal...

Something that crossed my mind now…

Why only when using ReStock the performance on my rig plummets? Assuming the same conditions of temperature and pressure, there should be no differences between rendering a stock textured part and a ReStock one. Other than the size of the texture, of course, as ReStock are way heavier than Stock on GPUs.

But, yet, it should tax the same my GPU when flying the craft, and no only on the Telescope, no?

What am I missing here?

I was wrong! ReStock was only the straw that broke the camel's back - I found a huge performance problem and fixed it, and this made even my rig work fine with DOE and ReStock.

This task is concluded.

I talked too soon. The ReStock's Probodobodyne Stayputnik is not being rendered by the MeshEngine.

Oh well… :)

screenshot60

Well… It ended up being exaclty this: supporting ReStock is, in essence, properly support Stock! :)

So now the task is to support variants, and then procedural parts as Fairings. But this will tacked down in another fight, as I will close this as the task itself is fulfilled!

ReStock is replacing some StockModules by custom ones, and this is screwing up the MeshEngine. Update it.

I was wrong. I don't remember anymore what leaded me to believe the problem were the new PartModules - I probably misdiagnosed it while checking at that time.

The history is that even the simplest parts are not being shown when ReStock is installed - salvo some separators, as it appears.

This is the test subject, scaled to 5M, using ReStock. This is proof that ReStock is working fine:
aeroequus-restock

I launched an "Observatory" vessel and VesselMove'd it to 2.8Km from the LaunchPad, then took the following screenshot without DOE installed:
without-doe

This is the same scenario, Stock only (and TweakScale), and DOE:
with-doe-stock

And, finally, this is the same scenario, but with ReStock (and Plus) installed:
with-doe-restock

This is the whole savegame: test-doe-restock.zip

And the KSP.log, MMPatch and ConfigCache: Archive.zip

Note: The scaled up aeroequus is prone to explode after reloading the savegame and focusing on it. Just recover whatever survive the ordeal, fix the launch pad and launch the Aeroeruus from the savegame again.

I redid the test without TweakScale installed - just in case.

Had to use something big using StockOnly Parts that can be reasonably seen from ~3KM, fortunately one of the Stock Shuttles, the Dynawing, did the trick.

screenshot12

screenshot13

Archive.zip

And surprise, surprise!! It's working!!!

As it appears, the trouble maker is the TweakScale support!!!

It's not a surprise I couldn't find the problem before, as I was looking on the wrong place. The thingy that are in need to be updated is the Mesh Engine for TweakScale.

Well… It was a productive day, but it ended. I will need to work on it on another day - but, hey, now I know what to do!!

This is now a bug, since it's stablished that the Mesh Engine for TweakScale somehow is screwing the ReStock parts.

This was unexpected… the Mesh Engine for TweakScale appears to be innocent.

The DEBUG Log suggests that the MeshEngines are just don't being called at all - this is the reason by nothing being drawn, the Render interface is just not being called.

So TweakScale is a trigger for the problem, not the cause…

Oukey. Carefully reading the KSP.log instead of fast eyeing it looking for what you (think you) want is very productive.

[LOG 17:46:01.187] [DistantObject] WARNING: Failed to load model Squad/Parts/Command/mk1pod_v2/Mk1Pod_v2 for part mk1pod.v2 from vessel AeroEquus! Vessel will not be rendered as expected!

This is happening for all Parts touched by ReStock. Now I need to understand why this is happening when TweakScale is installed.

AWWWW, KRAP!!!

Non scaled parts are being rendered allright - even with the WARNING above. The presence of TweakScale is not a problem, the problem is happening when the part is scaled.

The WARNING from the previous post is something to check, but it's not causing the problem.

Oukey, since we are here.

This is the log entrey for trussAdapter:

[LOG 17:56:56.106] [DistantObject] WARNING: Failed to load model Squad/Parts/Structural/trussGirderAdapter/model for part trussAdapter from vessel Observatory! Vessel will not be rendered as expected!

And this is what's on the MM ConfigCache about this part:

{
        parentUrl = Squad/Parts/Structural/trussGirderAdapter/trussGirderAdapter.cfg
        PART
        {
                name = trussAdapter
                module = Part
                author = Chris Adderley (Nertea)
                rescaleFactor = 1
                node_stack_bottom = 0.0, -0.4108305, 0.0, 0.0, -1.0, 0.0, 1
                node_stack_top = 0.0, 0.6493708, 0.0, 0.0, 1.0, 0.0, 1
                TechRequired = specializedConstruction
                entryCost = 4800
                cost = 50
                category = Structural
                subcategory = 0
                title = Modular Girder Adapter
                manufacturer = Maxo Construction Toys
                description = This piece allows you to attach Modular Girder parts to standard 1.25m attachment points.
                attachRules = 1,0,1,1,0
                mass = 0.25
                dragModelType = default
                maximum_drag = 0.2
                minimum_drag = 0.2
                angularDrag = 1
                crashTolerance = 80
                breakingForce = 200
                breakingTorque = 200
                maxTemp = 2000
                bulkheadProfiles = size1
                tags = connect frame scaffold structur strut truss
                MODULE
                {
                        name = Driftless
                        active = True
                }
                MODULE
                {
                        name = FundsKeeper
                }
                MODULE
                {
                        name = StealBackMyFunds
                        active = True
                }
                MODULE
                {
                        name = TweakScale
                        type = stack
                        defaultScale = 1.25
                }
                MODEL
                {
                        model = ReStock/Assets/Structural/restock-truss-adapter-125-1
                        position = 0.0, 0.0, 0.0
                        scale = 1,1,1
                        rotation = 0, 0, 0
                }
                MODULE
                {
                        name = AttachedOnEditor
                        active = True
                }
        }
}

Apparently, ReStock is not updating all the data it needs inside KSP's guts… [edit]: nope. DOE was being initialised before MM did the patchings)

Obviously, it's not a patching problem.

But yet, DistantObject is getting the original model name instead of the ReStock one when querying the GameDatabase…

Looking carefully about the subject on the KSP.log, I think I found the problem:

[LOG 03:32:26.377] [DistantObject] TRACE: Adding trussAdapter Squad/Parts/Structural/trussGirderAdapter/model

<yada yada yada>

[LOG 03:32:31.605] [Restock] Removing Squad/Parts/Structural/trussGirderAdapter/model.mu

Check the timestamps: Distant Object is building its internal database before ReStock removes the Stock meshes from memory. And it's doing it using the models before the patching, what suggests I'm doing it too early...

Commit f4f586c solved the problem described in the last two posts.

Scaled up parts are still not being shown by DistantObject, but at least I got rid of a annoying problem - that may have a role on this issue - I'm guessing this is a problem with many triggers...

Now let's try to get rid of these messages:

[LOG 04:08:10.605] [DistantObject] WARNING: Could not find ConfigNode for part HeatShield0.  Part will not render for VesselDraw.

That's odd….

This is the ConfigNode as being fetched by DOE for the HeatShield0 with ReStock:

[LOG 04:25:26.372] [DistantObject] ******* PART
{
	module = Part
	rescaleFactor = 1
	node_stack_bottom = 0.0, -0.0095, 0.0, 0.0, -1.0, 0.0, 0
	node_stack_top = 0.0, 0.052, 0.0, 0.0, 1.0, 0.0, 1
	sound_vent_medium = decouple
	CoPOffset = 0.0, 0.5, 0.0
	CoLOffset = 0.0, -0.075, 0.0
	subcategory = 0
	attachRules = 1,0,1,0,0
	mass = 0.025
	dragModelType = default
	maximum_drag = 0.2
	minimum_drag = 0.2
	angularDrag = 2
	breakingForce = 100
	breakingTorque = 100
	crashTolerance = 9
	maxTemp = 3300
	fuelCrossFeed = False
	PhysicsSignificance = 0
	stageOffset = 1
	childStageOffset = 1
	thermalMassModifier = 1.0
	node_stack_bottom02 = 0.0, -0.0626, 0.0, 0.0, -1.0, 0.0, 0
	MODULE
	{
		name = ModuleAblator
		ablativeResource = Ablator
		lossExp = -7500
		lossConst = 0.1
		pyrolysisLossFactor = 6000
		reentryConductivity = 0.01
		ablationTempThresh = 500
		useChar = True
		charModuleName = shieldChar
	}
	MODULE
	{
		name = ModuleColorChanger
		moduleID = shieldChar
		shaderProperty = _BurnColor
		useRate = False
		toggleInEditor = False
		toggleInFlight = False
		excludedRenderer = HeatShield0625Fairing
		excludedRenderer = HeatShield0625Internal
		redCurve
		{
			key = 0 0
			key = 1 1
		}
		greenCurve
		{
			key = 0 0
			key = 1 1
		}
		blueCurve
		{
			key = 0 0
			key = 1 1
		}
		alphaCurve
		{
			key = 0 0.8
		}
	}
	MODULE
	{
		name = ModuleDecouple
		ejectionForce = 50
		isOmniDecoupler = true
		menuName = Jettison Heat Shield
		stagingEnabled = False
		stagingEnableText = HS Jettison Not Staged
		stagingDisableText = HS Jettison Staged
	}
	MODULE
	{
		name = ModuleTestSubject
		useStaging = False
		useEvent = True
		situationMask = 15
		CONSTRAINT
		{
			type = ATMOSPHERE
			value = True
		}
		CONSTRAINT
		{
			type = SITUATION
			value = 11
			body = _NotHome
		}
		CONSTRAINT
		{
			type = SPEEDENV
			test = LT
			value = 350
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = SPEEDENV
			test = GT
			value = 250
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = SPEEDENV
			test = LT
			value = 500
			prestige = Significant
		}
		CONSTRAINT
		{
			type = SPEEDENV
			test = GT
			value = 300
			prestige = Significant
		}
		CONSTRAINT
		{
			type = SPEEDENV
			test = LT
			value = 600
			prestige = Exceptional
		}
		CONSTRAINT
		{
			type = SPEEDENV
			test = GT
			value = 400
			prestige = Exceptional
		}
		CONSTRAINT
		{
			type = SPEED
			test = LT
			value = 1500
			situationMask = 8
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = SPEED
			test = GT
			value = 1000
			situationMask = 8
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = SPEED
			test = LT
			value = 2500
			situationMask = 8
			prestige = Significant
		}
		CONSTRAINT
		{
			type = SPEED
			test = GT
			value = 1500
			situationMask = 8
			prestige = Significant
		}
		CONSTRAINT
		{
			type = SPEED
			test = LT
			value = 6000
			situationMask = 8
			prestige = Exceptional
		}
		CONSTRAINT
		{
			type = SPEED
			test = GT
			value = 2000
			situationMask = 8
			prestige = Exceptional
		}
		CONSTRAINT
		{
			type = DENSITY
			test = LT
			value = 0.1
		}
		CONSTRAINT
		{
			type = ALTITUDEENV
			test = GT
			value = 4000
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = ALTITUDEENV
			test = LT
			value = 6000
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = ALTITUDEENV
			test = GT
			value = 8000
			prestige = Significant
		}
		CONSTRAINT
		{
			type = ALTITUDEENV
			test = LT
			value = 12000
			prestige = Significant
		}
		CONSTRAINT
		{
			type = ALTITUDEENV
			test = GT
			value = 12000
			prestige = Exceptional
		}
		CONSTRAINT
		{
			type = ALTITUDEENV
			test = LT
			value = 16000
			prestige = Exceptional
		}
		CONSTRAINT
		{
			type = REPEATABILITY
			value = ALWAYS
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = REPEATABILITY
			value = BODYANDSITUATION
			prestige = Significant
		}
		CONSTRAINT
		{
			type = REPEATABILITY
			value = ONCEPERPART
			prestige = Exceptional
		}
	}
	RESOURCE
	{
		name = Ablator
		amount = 50
		maxAmount = 50
	}
	MODULE
	{
		name = ModuleLiftingSurface
		useInternalDragModel = False
		deflectionLiftCoeff = 0.0875
		liftingSurfaceCurve = CapsuleBottom
		disableBodyLift = False
		omnidirectional = False
		perpendicularOnly = True
		transformDir = Y
		transformSign = -1
		nodeEnabled = True
		attachNodeName = bottom
	}
	MODULE
	{
		name = Driftless
		active = True
	}
	MODULE
	{
		name = FundsKeeper
	}
	MODULE
	{
		name = StealBackMyFunds
		active = True
	}
	MODULE
	{
		name = TweakScale
		type = stack_square
		defaultScale = 0.625
	}
	MODEL
	{
		model = ReStock/Assets/Aero/restock-heatshield-0625-1
	}
	DRAG_CUBE
	{
		cube = Fairing, 0.05634,0.7512,0.6665, 0.05634,0.7603,0.5694, 0.3044,0.9566,0.1698, 0.3044,0.932,0.1674, 0.05487,0.7518,0.4044, 0.05488,0.7514,0.4076, 0.001332,0.001115,-0.002111, 0.625,0.1071,0.625
		cube = Clean, 0.06044,0.4659,0.4447, 0.06044,0.4659,0.4447, 0.3843,0.9488,0.1482, 0.3843,0.9396,0.1682, 0.06044,0.4645,0.4447, 0.06044,0.4673,0.4447, 0,0.003277,-3.906E-10, 0.7,0.1,0.7
	}
	MODULE
	{
		name = ModuleJettison
		jettisonName = HeatShield0625Fairing
		bottomNodeName = bottom02
		isFairing = True
		jettisonedObjectMass = 0.5
		jettisonForce = 15
		jettisonDirection = 0 0 1
		stagingEnabled = False
		checkBottomNode = True
	}
	MODULE
	{
		name = ModulePartVariants
		useMultipleDragCubes = false
		baseVariant = Classic
		VARIANT
		{
			name = Classic
			displayName = Classic
			primaryColor = #8d6c24
			GAMEOBJECTS
			{
				HeatShield0625Brown = true
				HeatShield0625Red = false
				HeatShield0625Black = false
			}
		}
		VARIANT
		{
			name = Black
			displayName = Black
			primaryColor = #303030
			GAMEOBJECTS
			{
				HeatShield0625Brown = false
				HeatShield0625Red = false
				HeatShield0625Black = true
			}
		}
		VARIANT
		{
			name = Red
			displayName = Unpainted
			primaryColor = #793b25
			GAMEOBJECTS
			{
				HeatShield0625Brown = false
				HeatShield0625Red = true
				HeatShield0625Black = false
			}
		}
	}
	MODULE
	{
		name = AttachedOnEditor
		active = True
	}
}

[LOG 04:25:26.373] [DistantObject] WARNING: Could not find ConfigNode for part HeatShield0.  Part will not render for VesselDraw.

And here, the same but without ReStock:

[LOG 04:52:55.974] [DistantObject] ******* PART
{
	module = Part
	rescaleFactor = 1
	node_stack_bottom = 0.0, -0.0095, 0.0, 0.0, -1.0, 0.0, 1
	node_stack_top = 0.0, 0.052, 0.0, 0.0, 1.0, 0.0, 1
	sound_vent_medium = decouple
	CoPOffset = 0.0, 0.5, 0.0
	CoLOffset = 0.0, -0.075, 0.0
	subcategory = 0
	attachRules = 1,0,1,0,0
	mass = 0.025
	dragModelType = default
	maximum_drag = 0.2
	minimum_drag = 0.2
	angularDrag = 2
	breakingForce = 100
	breakingTorque = 100
	crashTolerance = 9
	maxTemp = 3300
	fuelCrossFeed = False
	PhysicsSignificance = 0
	stageOffset = 1
	childStageOffset = 1
	thermalMassModifier = 1.0
	MODEL
	{
		model = Squad/Parts/Aero/HeatShield/HeatShield0
	}
	MODULE
	{
		name = ModuleAblator
		ablativeResource = Ablator
		lossExp = -7500
		lossConst = 0.1
		pyrolysisLossFactor = 6000
		reentryConductivity = 0.01
		ablationTempThresh = 500
		useChar = True
		charModuleName = shieldChar
	}
	MODULE
	{
		name = ModuleColorChanger
		moduleID = shieldChar
		shaderProperty = _BurnColor
		useRate = False
		toggleInEditor = False
		toggleInFlight = False
		redCurve
		{
			key = 0 0
			key = 1 1
		}
		greenCurve
		{
			key = 0 0
			key = 1 1
		}
		blueCurve
		{
			key = 0 0
			key = 1 1
		}
		alphaCurve
		{
			key = 0 0.8
		}
	}
	MODULE
	{
		name = ModuleDecouple
		ejectionForce = 50
		isOmniDecoupler = true
		menuName = Jettison Heat Shield
		stagingEnabled = False
		stagingEnableText = HS Jettison Not Staged
		stagingDisableText = HS Jettison Staged
	}
	MODULE
	{
		name = ModuleTestSubject
		useStaging = False
		useEvent = True
		situationMask = 15
		CONSTRAINT
		{
			type = ATMOSPHERE
			value = True
		}
		CONSTRAINT
		{
			type = SITUATION
			value = 11
			body = _NotHome
		}
		CONSTRAINT
		{
			type = SPEEDENV
			test = LT
			value = 350
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = SPEEDENV
			test = GT
			value = 250
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = SPEEDENV
			test = LT
			value = 500
			prestige = Significant
		}
		CONSTRAINT
		{
			type = SPEEDENV
			test = GT
			value = 300
			prestige = Significant
		}
		CONSTRAINT
		{
			type = SPEEDENV
			test = LT
			value = 600
			prestige = Exceptional
		}
		CONSTRAINT
		{
			type = SPEEDENV
			test = GT
			value = 400
			prestige = Exceptional
		}
		CONSTRAINT
		{
			type = SPEED
			test = LT
			value = 1500
			situationMask = 8
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = SPEED
			test = GT
			value = 1000
			situationMask = 8
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = SPEED
			test = LT
			value = 2500
			situationMask = 8
			prestige = Significant
		}
		CONSTRAINT
		{
			type = SPEED
			test = GT
			value = 1500
			situationMask = 8
			prestige = Significant
		}
		CONSTRAINT
		{
			type = SPEED
			test = LT
			value = 6000
			situationMask = 8
			prestige = Exceptional
		}
		CONSTRAINT
		{
			type = SPEED
			test = GT
			value = 2000
			situationMask = 8
			prestige = Exceptional
		}
		CONSTRAINT
		{
			type = DENSITY
			test = LT
			value = 0.1
		}
		CONSTRAINT
		{
			type = ALTITUDEENV
			test = GT
			value = 4000
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = ALTITUDEENV
			test = LT
			value = 6000
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = ALTITUDEENV
			test = GT
			value = 8000
			prestige = Significant
		}
		CONSTRAINT
		{
			type = ALTITUDEENV
			test = LT
			value = 12000
			prestige = Significant
		}
		CONSTRAINT
		{
			type = ALTITUDEENV
			test = GT
			value = 12000
			prestige = Exceptional
		}
		CONSTRAINT
		{
			type = ALTITUDEENV
			test = LT
			value = 16000
			prestige = Exceptional
		}
		CONSTRAINT
		{
			type = REPEATABILITY
			value = ALWAYS
			prestige = Trivial
		}
		CONSTRAINT
		{
			type = REPEATABILITY
			value = BODYANDSITUATION
			prestige = Significant
		}
		CONSTRAINT
		{
			type = REPEATABILITY
			value = ONCEPERPART
			prestige = Exceptional
		}
	}
	RESOURCE
	{
		name = Ablator
		amount = 50
		maxAmount = 50
	}
	MODULE
	{
		name = ModuleLiftingSurface
		useInternalDragModel = False
		deflectionLiftCoeff = 0.0875
		liftingSurfaceCurve = CapsuleBottom
		disableBodyLift = False
		omnidirectional = False
		perpendicularOnly = True
		transformDir = Y
		transformSign = -1
		nodeEnabled = True
		attachNodeName = bottom
	}
	MODULE
	{
		name = Driftless
		active = True
	}
	MODULE
	{
		name = FundsKeeper
	}
	MODULE
	{
		name = StealBackMyFunds
		active = True
	}
	MODULE
	{
		name = TweakScale
		type = stack_square
		defaultScale = 0.625
	}
	MODULE
	{
		name = AttachedOnEditor
		active = True
	}
}

[LOG 04:52:55.974] [DistantObject] WARNING: Could not find ConfigNode for part HeatShield0.  Part will not render for VesselDraw.

The thing is missing the name value!!! This is happening with and without ReStock, so it's not involved on this one.

Commit 1fcac3d fixes the WARNING from the last post.

Frankly, I don't now why (and I don't remember when right now) I wrote this krappy excuse of code removed by that commit, but it was not only useless (as even KSP 1.3.1 don't give us the name as the code was expecting), but essentially hurtful.

I should had paid attention to this the first time an user complained about. Mea culpa, mea maxima culpa.

More interesting yet, this last commit (and probably the previous too) fixed the ReStock problem.

I had said before somewhere in the codebase, Forum or Issue tracking, that supporting ReStock is essentially supporting Stock the right way, and this issue confirms that.

Again, mea culpa, mea maxima culpa.. :/

Now I need to swallow my pride and see what else I could had done correctly on this thing before publishing a new release.

This issue is closed/fixed.