public void InitEngineLights() { try { // wrap the parts engine module(s) and FX modules for simpler calls later this.engine = new EngineModuleWrapper(this.part); this.exhaustColor = new Color(this.exhaustR, this.exhaustG, this.exhaustB); jitterBuffer = new JitterBuffer(); float maxThrust = engine.GetMaxThrust(); List <Tuple <Vector3, Vector3> > thrustTransforms = this.engine.GetThrustTransforms(); this.lightStacks = new Tuple <Light, Light> [thrustTransforms.Count]; for (int i = 0; i < thrustTransforms.Count; i++) { Tuple <Light, Light> lights = this.MakeLightStack(thrustTransforms[i].Item1, exhaustColor, thrustTransforms[i].Item2, this.exhaustOffsetZ); this.lightStacks[i] = lights; } this.multiTransformIntensityMult = GetIntensityMult(thrustTransforms.Count); //this.initOccurred = true; // this is how you do debug only printing... #if DEBUG Utils.Log("Light calculations (" + this.part.name + ") resulted in: " + lightPower); Utils.Log("coords of engine: " + engine.transform.position); #else Utils.Log("Detected and activating for engine: (" + this.part.name + ")"); #endif } catch (Exception exception) { Utils.Log("Error in init(): " + exception.Message); } }
public void initEngineLights() { try { // wrap the parts engine module(s) and FX modules for simpler calls later engineModule = new EngineModule(this.part); if (!engineModule.hasEmissive) // not all engines have emissives { enableEmissiveLight = false; } else { emissiveColor = emissiveColorBase = new Color(emissiveRed, emissiveGreen, emissiveBlue); emissiveColorLogModifier = new Color(emissiveLogRed, emissiveLogGreen, emissiveLogBlue); emissiveColorQuadModifier = new Color(emissiveQuadRed, emissiveQuadGreen, emissiveQuadBlue); } exhaustColor = new Color(exhaustRed, exhaustGreen, exhaustBlue); // increase the minimum light range for larger parts AttachNode node = this.part.FindModuleImplementing <AttachNode>(); if (node != null) { minimumLightRange += node.radius; } jitterBuffer = new JitterBuffer(); // cache function call float maxThrust = engineModule.getMaxThrust(); // calculate light power from engine max thrust - follows a quadratic: lightPower = ((LIGHT_CURVE * maxThrust * maxThrust) + (LIGHT_LINEAR * maxThrust) + LIGHT_MINIMUM) * lightPower; // use the multiplier read from config file lightPower = Utils.clampValue(lightPower, 0, MAXIMUM_LIGHT_INTENSITY, "light intensity"); // old config used 40 as default - but that was way too high: // it caused light to reach planetary surfaces from low orbit: 20 is a more sensible max value // less considering the minimum offset I've introduced lightRange = Utils.clampValue(lightRange, 0, MAXIMUM_LIGHT_RANGE, "light range"); jitterMultiplier = Utils.clampValue(jitterMultiplier, 0, MAXIMUM_JITTER, "jitter multiplier"); //Make lights: (Using part position) averageThrustTransform = engineModule.getAverageThrustTransform(); GameObject engineLightObject = new GameObject(); engineLightObject.AddComponent <Light>(); Light engineLight = engineLightObject.GetComponent <Light>(); // Light Settings: engineLight.type = LightType.Point; engineLight.color = exhaustColor; engineLight.enabled = false; // Transform Settings: engineLightObject.transform.parent = engineModule.transform; engineLightObject.transform.forward = engineModule.transform.forward; //not really required? engineLightObject.transform.position = averageThrustTransform; // this (like colour) is applied per-frame - because it looks better lightOffset = new Vector3(lightOffsetX, 0, lightOffsetY); // and we're done - register our local variables and flag success this.engineLightObject = engineLightObject; this.engineLight = engineLight; initOccurred = true; // this is how you do debug only printing... #if DEBUG Utils.log("Light calculations (" + this.part.name + ") resulted in: " + lightPower); Utils.log("coords of engine: " + engineModule.transform.position); Utils.log("coords of thrust: " + averageThrustTransform); //Utils.log("coords of thrust offset: " + thrustOffset); Utils.log("coords of light: " + engineLightObject.transform.position); #else Utils.log("Detected and activating for engine: (" + this.part.name + ")"); #endif } catch (Exception exception) { Utils.log("Error in init(): " + exception.Message); } }