Esempio n. 1
0
        public static bool[] GetBoolValues(this ConfigNode node, String name)
        {
            String[] values = node.GetValues(name);
            int      len    = values.Length;

            bool[] vals = new bool[len];
            for (int i = 0; i < len; i++)
            {
                vals[i] = ENUtils.safeParseBool(values[i]);
            }
            return(vals);
        }
Esempio n. 2
0
        public static float[] GetFloatValues(this ConfigNode node, String name)
        {
            String baseVal = node.GetStringValue(name);

            if (!String.IsNullOrEmpty(baseVal))
            {
                String[] split = baseVal.Split(new char[] { ',' });
                float[]  vals  = new float[split.Length];
                for (int i = 0; i < split.Length; i++)
                {
                    vals[i] = ENUtils.safeParseFloat(split[i]);
                }
                return(vals);
            }
            return(new float[0]);
        }
Esempio n. 3
0
        public static Vector3 GetVector3(this ConfigNode node, String name, Vector3 defaultValue)
        {
            String value = node.GetValue(name);

            if (value == null)
            {
                return(defaultValue);
            }
            String[] vals = value.Split(',');
            if (vals.Length < 3)
            {
                MonoBehaviour.print("ERROR parsing values for Vector3 from input: " + value + ". found less than 3 values, cannot create Vector3");
                return(defaultValue);
            }
            return(new Vector3((float)ENUtils.safeParseDouble(vals[0]), (float)ENUtils.safeParseDouble(vals[1]), (float)ENUtils.safeParseDouble(vals[2])));
        }
Esempio n. 4
0
        public static Material loadMaterial(String diffuse, String normal, String emissive, String shader)
        {
            Material material;
            Texture  diffuseTexture  = ENUtils.findTexture(diffuse, false);
            Texture  normalTexture   = String.IsNullOrEmpty(normal) ? null : ENUtils.findTexture(normal, true);
            Texture  emissiveTexture = String.IsNullOrEmpty(emissive) ? null : ENUtils.findTexture(emissive, false);

            material = new Material(Shader.Find(shader));
            material.SetTexture("_MainTex", diffuseTexture);
            if (normalTexture != null)
            {
                material.SetTexture("_BumpMap", normalTexture);
            }
            if (emissiveTexture != null)
            {
                material.SetTexture("_Emissive", emissiveTexture);
            }
            return(material);
        }
Esempio n. 5
0
        public static void findShieldedPartsCylinder(Part basePart, Bounds fairingRenderBounds, List <Part> shieldedParts, float topY, float bottomY, float topRadius, float bottomRadius)
        {
            float height        = topY - bottomY;
            float largestRadius = topRadius > bottomRadius ? topRadius : bottomRadius;

            Vector3 lookupCenterLocal  = new Vector3(0, bottomY + (height * 0.5f), 0);
            Vector3 lookupTopLocal     = new Vector3(0, topY, 0);
            Vector3 lookupBottomLocal  = new Vector3(0, bottomY, 0);
            Vector3 lookupCenterGlobal = basePart.transform.TransformPoint(lookupCenterLocal);

            Ray lookupRay = new Ray(lookupBottomLocal, new Vector3(0, 1, 0));

            List <Part> partsFound = new List <Part>();

            Collider[] foundColliders = Physics.OverlapSphere(lookupCenterGlobal, height * 1.5f, 1);
            foreach (Collider col in foundColliders)
            {
                Part pt = col.gameObject.GetComponentUpwards <Part>();
                if (pt != null && pt != basePart && pt.vessel == basePart.vessel && !partsFound.Contains(pt))
                {
                    partsFound.Add(pt);
                }
            }

            Bounds[] otherPartBounds;
            Vector3  otherPartCenterLocal;

            float partYPos;
            float partYPercent;
            float partYRadius;
            float radiusOffset = topRadius - bottomRadius;

            foreach (Part pt in partsFound)
            {
                //check basic render bounds for containment

                //TODO this check misses the case where the fairing is long/tall, containing a wide part; it will report that the wide part can fit inside
                //of the fairing, due to the relative size of their colliders
                otherPartBounds = pt.GetRendererBounds();
                if (PartGeometryUtil.MergeBounds(otherPartBounds, pt.transform).size.sqrMagnitude > fairingRenderBounds.size.sqrMagnitude)
                {
                    continue;
                }

                Vector3 otherPartCenter = pt.partTransform.TransformPoint(PartGeometryUtil.FindBoundsCentroid(otherPartBounds, pt.transform));
                if (!fairingRenderBounds.Contains(otherPartCenter))
                {
                    continue;
                }

                //check part bounds center point against conic projection of the fairing
                otherPartCenterLocal = basePart.transform.InverseTransformPoint(otherPartCenter);

                //check vs top and bottom of the shielded area
                if (otherPartCenterLocal.y > lookupTopLocal.y || otherPartCenterLocal.y < lookupBottomLocal.y)
                {
                    continue;
                }

                //quick check vs cylinder radius
                float distFromLine = ENUtils.distanceFromLine(lookupRay, otherPartCenterLocal);
                if (distFromLine > largestRadius)
                {
                    continue;
                }

                //more precise check vs radius of the cone at that Y position
                partYPos     = otherPartCenterLocal.y - lookupBottomLocal.y;
                partYPercent = partYPos / height;
                partYRadius  = partYPercent * radiusOffset;
                if (distFromLine > (partYRadius + bottomRadius))
                {
                    continue;
                }
                shieldedParts.Add(pt);
            }
        }
Esempio n. 6
0
        public override void OnStart(PartModule.StartState state)
        {
            base.OnStart(state);

            #region animationSetup
            animationController = ENAnimateControlled.locateAnimationController(part, animationID, onAnimationStatusChanged);
            #endregion

            #region gui setup
            Events["retractEvent"].guiName  = retractGuiName;
            Events["deployEvent"].guiName   = deployGuiName;
            Events["repairEvent"].guiName   = repairGuiName;
            Actions["toggleAction"].guiName = actionGroupGuiName;

            Events["retractEvent"].active = legState == LegState.DEPLOYED;
            Events["deployEvent"].active  = legState == LegState.RETRACTED;
            Events["repairEvent"].active  = legState == LegState.BROKEN;
            #endregion

            #region colliderSetup
            if (HighLogic.LoadedSceneIsFlight)
            {
                //setup suspension upper limits, defaults to config value for suspension travel
                if (suspensionUpperLimit == -1)
                {
                    suspensionUpperLimit = suspensionTravel;
                }

                String[] wcNameArray   = wheelColliderNames.Split(',');
                String[] susNameArray  = suspensionTransformNames.Split(',');
                String[] footNameArray = footColliderNames.Split(',');
                int      length        = wcNameArray.Length < susNameArray.Length ? wcNameArray.Length : susNameArray.Length;

                LandingLegData legData;
                Transform      suspensionTransform;
                Transform      wheelColliderTransform;
                Transform      footColliderTransform;
                WheelCollider  wheelCollider;
                float          wcRadius = 0, wcTravel = 0, wcTarget = 0, wcSpring = 0, wcDamper = 0;

                for (int i = 0; i < length; i++)
                {
                    suspensionTransform    = part.FindModelTransform(susNameArray[i].Trim());
                    wheelColliderTransform = part.FindModelTransform(wcNameArray[i].Trim());
                    if (suspensionTransform == null || wheelColliderTransform == null)
                    {
                        print("error locating transforms for names: " + susNameArray[i] + ", " + wcNameArray[i]);
                        print("found objects: " + suspensionTransform + ", " + wheelColliderTransform);
                        continue;
                    }
                    wheelCollider = wheelColliderTransform.GetComponent <WheelCollider>();
                    if (wheelCollider == null)
                    {
                        print("Wheel collider transform does not contain a valid wheel collider!  name: " + wcNameArray[i]);
                        ENUtils.recursePrintComponents(wheelColliderTransform.gameObject, "");
                        continue;
                    }
                    if (i < footNameArray.Length)
                    {
                        footColliderTransform = part.FindModelTransform(footNameArray[i].Trim());
                    }
                    else
                    {
                        footColliderTransform = null;
                    }
                    legData = new LandingLegData();
                    legData.suspensionTransform   = suspensionTransform;
                    legData.wheelCollider         = wheelCollider;
                    legData.footColliderTransform = footColliderTransform;
                    this.legData.Add(legData);

                    //use default values if config values were not written
                    wcRadius = wheelColliderRadius == -1 ? wheelCollider.radius : wheelColliderRadius;
                    wcTravel = suspensionTravel == -1 ? wheelCollider.suspensionDistance : suspensionTravel;
                    wcTarget = suspensionTarget == -1 ? wheelCollider.suspensionSpring.targetPosition : suspensionTarget;
                    wcSpring = suspensionSpring == -1 ? wheelCollider.suspensionSpring.spring : suspensionSpring;
                    wcDamper = suspensionDamper == -1 ? wheelCollider.suspensionSpring.damper : suspensionDamper;

                    //setup wheel collider radius and suspension distance in case of overrides in config
                    wheelCollider.radius             = wcRadius;
                    wheelCollider.suspensionDistance = wcTravel;
                    wheelCollider.brakeTorque        = 1000f;

                    //setup a new JointSpring for the wheel to use, overriding values from config if needed
                    JointSpring spring = new JointSpring();
                    spring.spring                  = wcSpring;
                    spring.damper                  = wcDamper;
                    spring.targetPosition          = wcTarget;
                    wheelCollider.suspensionSpring = spring;//assign the new spring joint to the wheel collider
                }
            }

            #endregion

            if (controlOn)
            {
                enableModule();
            }
            else
            {
                disableModule();
            }
            setLegState(legState);
            if (!moduleControlEnabled)
            {
                onControlDisabled();
            }
        }