Jump to content

Vessel Length?


Recommended Posts

Ok, this shouldn't be buried this deep.  Is there any way to get the vessel length of the flightglobals.activevessel???   I know how to get this in the editor but there doesn't seem to be an easy way to do this once it's out and about.

Thanks

Link to comment
Share on other sites

I was not able to find this myself either when I looked for it.

If there is something, it's probably going to be something in the underlying Unity stuff, rather then the KSP stuff.

The one method I did find was the .closestPointOnBounds method which I was able to finagle for my purposes, but I'm not sure how you'd go about using that to get vessel length.

D.

Link to comment
Share on other sites

 PartGeometryUtil.GetPartRendererBound or then PartGeometryUtil.GetPartColliderBounds and then PartGeometryUtil.MergeBounds ?

(they returns array so I would not call those each frame)

Edited by sarbian
Link to comment
Share on other sites

Thanks @sarbian but... wow... just wow.  That would be an absolute mess to figure out the way I see it.  If you want to get the volume of a vessel, that would work because you end up with a Vector3.  But the length?

That seems like a LOT of work to figure out how long a vessel is.  Isn't there something like this?  

Vector3 dimensions = this.vessel.GetComponent<Collider>().bounds.size;

I know that gives a null ref but isn't there anything like that?

Edited by Fengist
Link to comment
Share on other sites

 

this is how SQUAD calculates ship height (lenght) in VAB.   public static Vector3 CalculateCraftSize(ShipConstruct ship)

	Bounds bounds = default(Bounds);
	Vector3 orgPos = ship.parts[0].orgPos;
	bounds.center = orgPos;
	List<Bounds> list = new List<Bounds>();
	foreach (Part current in ship.parts)
	{
		Bounds[] partRendererBounds = PartGeometryUtil.GetPartRendererBounds(current);
		Bounds[] array = partRendererBounds;
		for (int i = 0; i < array.Length; i++)
		{
			Bounds bounds2 = array[i];
			Bounds bounds3 = bounds2;
			bounds3.size *= current.boundsMultiplier;
			Vector3 size = bounds3.size;
			bounds3.Expand(current.GetModuleSize(size));
			list.Add(bounds2);
		}
	}
	return PartGeometryUtil.MergeBounds(list.ToArray(), ship.parts[0].transform.root).size;

if change ship to vessel we can teoretically get vessel lenght in flight, but, i guess, usefull results will be only when it goes vertically.

Edited by DennyTX
Link to comment
Share on other sites

Thanks @DennyTX but didn't work.

Put that into a function and got the x,y,z of the Vector3 it returns and I get this.

Vessel x: 46.6925 y:22.34021 z:74.10925

In the SPH, the vessel is listed at 

h:19.4, w:22.2 and l:80.2

The good news is, the vessel orientation didn't really affect those numbers.

 

And I was right.  That's an absolute mess of a methodology for getting the vessel size.

Edited by Fengist
Link to comment
Share on other sites

8 hours ago, Fengist said:

***

In the SPH, the vessel is listed at 

****

the previous example was for  VAB only

for SPH, SQUAD has another branch, as well as for subassemblies

Edited by DennyTX
Link to comment
Share on other sites

1 hour ago, DennyTX said:

the previous example was for  VAB only

for SPH, SQUAD has another branch, as well as for subassemblies

Right, but I'm not looking to get the size in any editor.  I need it outside.  And when the vessel is out there I shouldn't have to ask where it was created in order to determine it's dimensions.  My god this is ridiculous.  I shouldn't have to be jumping through hoops to get a basic vessel size.  It should be right there along with it's mass.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...