Exemplo n.º 1
0
 private void SetCylindricalDiameter(float diameter)
 {
     if (SetShape <ProceduralShapeCylinder>())
     {
         ProceduralShapeCylinder cyl = part.GetModule <ProceduralShapeCylinder>();
         cyl.diameter = diameter;
     }
     else if (SetShape <ProceduralShapePill>())
     {
         ProceduralShapePill pil = part.GetModule <ProceduralShapePill>();
         pil.diameter = diameter;
     }
 }
Exemplo n.º 2
0
 private void SetCylindricalDiameter(float diameter)
 {
     if (SetShape <ProceduralShapeCylinder>())
     {
         ProceduralShapeCylinder cyl = part.Modules.GetModule <ProceduralShapeCylinder>();
         float prevDiameter          = cyl.diameter;
         cyl.diameter = diameter;
         Notify(() => cyl.OnShapeDimensionChanged(cyl.Fields["diameter"], prevDiameter));
     }
     else if (SetShape <ProceduralShapePill>())
     {
         ProceduralShapePill pil = part.Modules.GetModule <ProceduralShapePill>();
         float prevDiameter      = pil.diameter;
         pil.diameter = diameter;
         Notify(() => pil.OnShapeDimensionChanged(pil.Fields["diameter"], prevDiameter));
     }
 }
Exemplo n.º 3
0
        public void ScaleNow()
        {
            if (HighLogic.LoadedSceneIsEditor && wetDensity > 0)
            {
                // Volume of fuel to use:
                double idealVolume = IdealTotalMass / wetDensity;

                if (part.HasModule <ProceduralShapeCylinder>())
                {
                    ProceduralShapeCylinder cyl = part.GetModule <ProceduralShapeCylinder>();
                    double radius           = 0.5 * cyl.diameter;
                    double crossSectionArea = Math.PI * radius * radius;
                    double idealLength      = idealVolume / crossSectionArea;
                    if (idealLength < radius)
                    {
                        idealLength = radius;
                    }
                    if (Math.Abs(cyl.length - idealLength) > 0.05)
                    {
                        cyl.length = (float)idealLength;
                        if (part.GetModule <ProceduralPart>().shapeName == cyl.displayName)
                        {
                            cyl.Update();
                        }
                    }
                }
                if (part.HasModule <ProceduralShapePill>())
                {
                    // We won't try to change the "fillet", so we can treat it as a constant
                    // Diameter is likewise a constant here
                    ProceduralShapePill pil = part.GetModule <ProceduralShapePill>();
                    double fillet = pil.fillet, diameter = pil.diameter;
                    double idealLength = (idealVolume * 24f / Math.PI - (10f - 3f * Math.PI) * fillet * fillet * fillet - 3f * (Math.PI - 4) * diameter * fillet * fillet) / (6f * diameter * diameter);
                    if (idealLength < 1)
                    {
                        idealLength = 1;
                    }
                    if (Math.Abs(pil.length - idealLength) > 0.05)
                    {
                        pil.length = (float)idealLength;
                        if (part.GetModule <ProceduralPart>().shapeName == pil.displayName)
                        {
                            pil.Update();
                        }
                    }
                }
                if (part.HasModule <ProceduralShapeCone>())
                {
                    ProceduralShapeCone con = part.GetModule <ProceduralShapeCone>();
                    double topDiameter = con.topDiameter, bottomDiameter = con.bottomDiameter;
                    double idealLength = idealVolume * 12f / (Math.PI * (topDiameter * topDiameter + topDiameter * bottomDiameter + bottomDiameter * bottomDiameter));
                    if (idealLength < 1)
                    {
                        idealLength = 1;
                    }
                    if (Math.Abs(con.length - idealLength) > 0.05)
                    {
                        con.length = (float)idealLength;
                        if (part.GetModule <ProceduralPart>().shapeName == con.displayName)
                        {
                            con.Update();
                        }
                    }
                }
                // BezierCone shapes not supported because they're too complicated.
                // See ProceduralShapeBezierCone.CalcVolume to see why.
            }
        }