Jump to content

How to get dimensions of a prefab


Recommended Posts

In the Editor, given the PartLoader.LoadedPartsList, I can find a specific part.

How can I get the x,y,z dimensions of it, everything I've tried so far still returns 0,0,0

I've tried the following:

  Part p = PartLoader.LoadedPartsList[desiredPart];

  var v = p.partPrefab.GetModuleSize(d);
  Log.Info("part: " + p.name + ", height x,y,z: " + v.x.ToString() + ", " + v.y.ToString() + ", " + v.z.ToString());

and

  var v = p.partPrefab.prefabSize;

and

  var v = p.partPrefab.moduleSize;

 

Thanks in advance

Link to comment
Share on other sites

On 8/18/2017 at 2:14 PM, Benjamin Kerman said:

@allista shoudl know about this, with Bounds. 

GetModuleSize is like GetModuleMass/Cost -- it retrieves modified size from IPartSizeModifier modules, if they're present.

What I do is I actually measure them mesh-by-mesh, encapsulating either meshFilter.bounds or meshFilter.vertices (for wheels, not needed in Editor), all transformed from meshFilter.transform to part.transform:

https://github.com/allista/AT_Utils/blob/4d68ac1e5e4fa0a6dfcaf8f790d9384541039476/Metric.cs#L91

I've wrote this in KSP-0.24 times, when there was no notion of size in editor.

Now the ShipConstruction calculates ship size almost the same way, using MeshRenderer.bounds (which are in worldspace) and remembering, unlike me, that there are also SkinnedMeshRenderers :rolleyes:

There's a bug in current ShipConstruction.CalculateCraftSize method, though, preventing it from accounting for part.boundsMultiplier and part.GetModuleSize (I wonder, does anyone noticed it yet?).

Here's what KSP does:

[snip]

Edited by Vanamonde
Link to comment
Share on other sites

All this designed for parts already instantiated in editor (or parts in-flight, in my case).

It should work with prefabs as well, but be carefull with GetModuleSize, as modules in a prefab are not started so may not be completely initialized.

I hope that's enough to get going with :)

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...