Beispiel #1
0
        public new void OnPutToGround(PartHeightQuery qr)
        {
            base.OnPutToGround(qr);
            Debug.Log(String.Format("[EL ELC] OnPutToGround qr: {0}", qr.lowestPoint));
            foreach (var p in qr.lowestOnParts)
            {
                Debug.Log(String.Format("[EL ELC] OnPutToGround qr.lop: {0}", p));
            }
            anchor = part.FindModelTransform(trf_anchor_name);
            var col = FindCollider(anchor);

            if (col)
            {
                var min  = col.bounds.min;
                var max  = col.bounds.max;
                var size = max - min;
                Debug.Log(String.Format("[EL ELC] OnPutToGround: {0} {1} {2}", min, max, size));
                points = new Vector3[] {
                    MakePoint(anchor, min, 0, 0),
                    MakePoint(anchor, min, size.x, 0),
                    MakePoint(anchor, min, 0, size.z),
                    MakePoint(anchor, min, size.x, size.z),
                };
                Debug.Log(String.Format("[EL ELC] OnPutToGround: {0}", points));
            }
        }
 public new void OnPutToGround(PartHeightQuery qr)
 {
     base.OnPutToGround (qr);
     if (CompatibilityChecker.IsWin64 ()) {
         return;
     }
     Debug.Log (String.Format ("[EL ELC] OnPutToGround qr: {0}", qr.lowestPoint));
     foreach (var p in qr.lowestOnParts) {
         Debug.Log (String.Format ("[EL ELC] OnPutToGround qr.lop: {0}", p));
     }
     anchor = part.FindModelTransform (trf_anchor_name);
     var col = FindCollider (anchor);
     if (col) {
         var min = col.bounds.min;
         var max = col.bounds.max;
         var size = max - min;
         Debug.Log (String.Format ("[EL ELC] OnPutToGround: {0} {1} {2}", min, max, size));
         points = new Vector3[] {
             MakePoint (anchor, min, 0,      0),
             MakePoint (anchor, min, size.x, 0),
             MakePoint (anchor, min, 0,      size.z),
             MakePoint (anchor, min, size.x, size.z),
         };
         Debug.Log (String.Format ("[EL ELC] OnPutToGround: {0}", points));
     }
 }
Beispiel #3
0
        public override void OnInitialize()
        {
            Debug.Log("[FS Hover] Init");

            if (HighLogic.LoadedSceneIsFlight)
            {
                var partHeightQuery = new PartHeightQuery(float.MaxValue);
                int count           = this.vessel.parts.Count;
                for (int i = 0; i < count; i++)
                {
                    var p = this.vessel[i];
                    partHeightQuery.lowestOnParts.Add(p, float.MaxValue);
                    Collider[] componentsInChildren = p.GetComponentsInChildren <Collider>();
                    int        num = componentsInChildren.Length;
                    for (int j = 0; j < num; j++)
                    {
                        Collider collider = componentsInChildren[j];
                        if (collider.enabled && collider.gameObject.layer != 21)
                        {
                            partHeightQuery.lowestPoint      = Mathf.Min(partHeightQuery.lowestPoint, collider.bounds.min.y);
                            partHeightQuery.lowestOnParts[p] = Mathf.Min(partHeightQuery.lowestOnParts[p], collider.bounds.min.y);
                        }
                    }
                }
                count = this.vessel.parts.Count;
                for (int k = 0; k < count; k++)
                {
                    this.vessel[k].SendMessage("OnPutToGround", partHeightQuery, SendMessageOptions.DontRequireReceiver);
                }
                this.vessel.situation = Vessel.Situations.LANDED;
                base.vessel.Landed    = true;
                base.vessel.landedAt  = "";
            }
        }
Beispiel #4
0
        Box GetVesselBox(ShipConstruct ship)
        {
            RotateLaunchClamps(ship);

            PartHeightQuery phq = null;
            Box             box = null;

            for (int i = 0; i < ship.parts.Count; i++)
            {
                Part p         = ship[i];
                var  colliders = get_colliders(p);
                for (int j = 0; j < colliders.Length; j++)
                {
                    var col = colliders[j];
                    if (col.gameObject.layer != 21 && col.enabled)
                    {
                        if (box == null)
                        {
                            box = new Box(col.bounds);
                        }
                        else
                        {
                            box.Add(col.bounds);
                        }

                        float min_y = col.bounds.min.y;
                        if (phq == null)
                        {
                            phq = new PartHeightQuery(min_y);
                        }
                        phq.lowestPoint = Mathf.Min(phq.lowestPoint, min_y);

                        if (!phq.lowestOnParts.ContainsKey(p))
                        {
                            phq.lowestOnParts.Add(p, min_y);
                        }
                        phq.lowestOnParts[p] = Mathf.Min(phq.lowestOnParts[p], min_y);
                    }
                }
            }
            Part root = ship.parts[0].localRoot;

            Debug.Log($"[EL] GetVesselBox {root.transform.position} {box}");
            Debug.Log($"[EL]   {root.transform.InverseTransformPoint(box.min)} {root.transform.InverseTransformPoint(box.max)}");
            for (int i = 0; i < ship.parts.Count; i++)
            {
                Part p = ship[i];
                p.SendMessage("OnPutToGround", phq,
                              SendMessageOptions.DontRequireReceiver);
            }
            return(box);
        }
        public void OnPutToGround(PartHeightQuery qr)
        {
            qr.lowestOnParts[part] = 0;

            if (qr.lowestPoint < qr.lowestOnParts[part])
            {
                height    += qr.lowestOnParts[part] - qr.lowestPoint;
                baseHeight = -1;
            }
            else
            {
                qr.lowestPoint = qr.lowestOnParts[part];
            }
        }
        Box GetVesselBox(ShipConstruct ship)
        {
            PartHeightQuery phq = null;
            Box             box = null;

            for (int i = 0; i < ship.parts.Count; i++)
            {
                Part p         = ship[i];
                var  colliders = get_colliders(p);
                for (int j = 0; j < colliders.Length; j++)
                {
                    var col = colliders[j];
                    if (col.gameObject.layer != 21 && col.enabled)
                    {
                        if (box == null)
                        {
                            box = new Box(col.bounds);
                        }
                        else
                        {
                            box.Add(col.bounds);
                        }

                        float min_y = col.bounds.min.y;
                        if (phq == null)
                        {
                            phq = new PartHeightQuery(min_y);
                        }
                        phq.lowestPoint = Mathf.Min(phq.lowestPoint, min_y);

                        if (!phq.lowestOnParts.ContainsKey(p))
                        {
                            phq.lowestOnParts.Add(p, min_y);
                        }
                        phq.lowestOnParts[p] = Mathf.Min(phq.lowestOnParts[p], min_y);
                    }
                }
            }
            Debug.Log(String.Format("[EL] GetVesselBox {0} {1}", box.min, box.max));
            for (int i = 0; i < ship.parts.Count; i++)
            {
                Part p = ship[i];
                p.SendMessage("OnPutToGround", phq,
                              SendMessageOptions.DontRequireReceiver);
            }
            return(box);
        }
        // Thanks to taniwha's Extraplanetary launchpads!
        public Bounds GetAABB(ShipConstruct a_Ship)
        {
            PartHeightQuery partHeight = null;
            Bounds aabb = new Bounds();
            bool initialize = true;
            for (int i = 0; i < a_Ship.parts.Count; i++)
            {
                Part currentPart = a_Ship[i];
                Collider[] colliders = currentPart.transform.FindChild("model").GetComponentsInChildren<Collider>();
                for (int j = 0; j < colliders.Length; j++)
                {
                    Collider currentCollider = colliders[j];

                    if (currentCollider.gameObject.layer != 21 && currentCollider.enabled) // Not sure where the 21 is coming from, have to ask taniwha
                    {
                        if (initialize)
                        {
                            initialize = false;
                            aabb = currentCollider.bounds;
                        }
                        else
                        {
                            aabb.Add(currentCollider.bounds);
                        }

                        float lowest = currentCollider.bounds.min.y;
                        if(partHeight == null)
                        {
                            partHeight = new PartHeightQuery(lowest);
                        }
                        partHeight.lowestPoint = Mathf.Min(partHeight.lowestPoint, lowest);

                        if(partHeight.lowestOnParts.ContainsKey(currentPart))
                        {
                            partHeight.lowestOnParts[currentPart] = Mathf.Min(partHeight.lowestOnParts[currentPart], lowest);
                        }
                    }
                }
            }

            for(int i = 0; i < a_Ship.parts.Count; i++)
            {
                a_Ship[i].SendMessage("OnPutToGround", partHeight, SendMessageOptions.DontRequireReceiver);
            }

            return new Bounds();
        }
Beispiel #8
0
        public static void PutShipToGround(ShipConstruct ship, Transform spawnPoint, Vector3 offset)
        {
            var partHeightQuery = new PartHeightQuery(float.MaxValue);
            int count           = ship.parts.Count;

            for (int i = 0; i < count; i++)
            {
                var p = ship[i];
                partHeightQuery.lowestOnParts.Add(p, float.MaxValue);
                Collider[] componentsInChildren = p.GetComponentsInChildren <Collider>();
                int        num = componentsInChildren.Length;
                for (int j = 0; j < num; j++)
                {
                    Collider collider = componentsInChildren[j];
                    if (collider.enabled && collider.gameObject.layer != 21)
                    {
                        partHeightQuery.lowestPoint      = Mathf.Min(partHeightQuery.lowestPoint, collider.bounds.min.y);
                        partHeightQuery.lowestOnParts[p] = Mathf.Min(partHeightQuery.lowestOnParts[p], collider.bounds.min.y);
                    }
                }
            }
            for (int k = 0; k < count; k++)
            {
                ship[k].SendMessage("OnPutToGround", partHeightQuery, SendMessageOptions.DontRequireReceiver);
            }
            Utils.Log("putting ship to ground: " + partHeightQuery.lowestPoint);
            float   angle;
            Vector3 axis;

            spawnPoint.rotation.ToAngleAxis(out angle, out axis);
            var root = ship.parts[0].localRoot.transform;

            offset += spawnPoint.position;
            var CoG = ship.Bounds().center;

            offset -= new Vector3(CoG.x, partHeightQuery.lowestPoint, CoG.z);
            root.Translate(offset, Space.World);
            root.RotateAround(spawnPoint.position, axis, angle);
        }
		Box GetVesselBox (ShipConstruct ship)
		{
			PartHeightQuery phq = null;
			Box box = null;
			for (int i = 0; i < ship.parts.Count; i++) {
				Part p = ship[i];
				var colliders = get_colliders (p);
				for (int j = 0; j < colliders.Length; j++) {
					var col = colliders[j];
					if (col.gameObject.layer != 21 && col.enabled) {
						if (box == null) {
							box = new Box (col.bounds);
						} else {
							box.Add (col.bounds);
						}

						float min_y = col.bounds.min.y;
						if (phq == null) {
							phq = new PartHeightQuery (min_y);
						}
						phq.lowestPoint = Mathf.Min (phq.lowestPoint, min_y);

						if (!phq.lowestOnParts.ContainsKey (p)) {
							phq.lowestOnParts.Add (p, min_y);
						}
						phq.lowestOnParts[p] = Mathf.Min (phq.lowestOnParts[p], min_y);
					}
				}
			}
			Debug.Log (String.Format ("[EL] GetVesselBox {0} {1}", box.min, box.max));
			for (int i = 0; i < ship.parts.Count; i++) {
				Part p = ship[i];
				p.SendMessage ("OnPutToGround", phq,
							   SendMessageOptions.DontRequireReceiver);
			}
			return box;
		}
Beispiel #10
0
 public void OnPutToGround(PartHeightQuery q)
 {
     Log.Info(q.lowestPoint.ToString());
     q.lowestPoint = -height;
     Log.Info(q.lowestPoint.ToString());
 }
Beispiel #11
0
 public void OnPutToGround(PartHeightQuery q)
 {
     Log.dbg("OnPutToGround {0}", q.lowestPoint);
     q.lowestPoint = -height;
     Log.dbg("OnPutToGround {0}", q.lowestPoint);
 }