Пример #1
0
            /// <summary>
            /// Creates a new ScaledVersion Loader from the Injector context.
            /// </summary>
            public ScaledVersionLoader()
            {
                // Is this the parser context?
                if (!Injector.IsInPrefab)
                {
                    throw new InvalidOperationException("Must be executed in Injector context.");
                }

                // Get the scaled version object
                Value            = generatedBody.celestialBody;
                Value.scaledBody = generatedBody.scaledVersion;
                type             = new EnumParser <BodyType>(Loader.currentBody.template == null
                    ? BodyType.Atmospheric
                    : Loader.currentBody.template.type);

                // Ensure scaled version at least has a mesh filter and mesh renderer
                if (Value.scaledBody.GetComponent <MeshFilter>() == null)
                {
                    Value.scaledBody.AddComponent <MeshFilter>();
                }
                if (Value.scaledBody.GetComponent <MeshRenderer>() == null)
                {
                    Value.scaledBody.AddComponent <MeshRenderer>();
                    Value.scaledBody.GetComponent <Renderer>().material = null;
                }

                if (options == null)
                {
                    options = new PlanetTextureExporter.TextureOptions();
                }
            }
Пример #2
0
            /// <summary>
            /// Creates a new ScaledVersion Loader from the Injector context.
            /// </summary>
            public ScaledVersionLoader()
            {
                // Is this the parser context?
                if (!Injector.IsInPrefab)
                {
                    throw new InvalidOperationException("Must be executed in Injector context.");
                }

                // Get the scaled version object
                Value            = generatedBody.celestialBody;
                Value.scaledBody = generatedBody.scaledVersion;
                Body currentBody = Parser.GetState <Body>("Kopernicus:currentBody");

                type = new EnumParser <BodyType>(currentBody.template?.type ?? BodyType.Atmospheric);

                // Ensure scaled version at least has a mesh filter and mesh renderer
                if (Value.scaledBody.GetComponent <MeshFilter>() == null)
                {
                    Value.scaledBody.AddComponent <MeshFilter>();
                }
                if (Value.scaledBody.GetComponent <MeshRenderer>() == null)
                {
                    Value.scaledBody.AddComponent <MeshRenderer>();
                    Value.scaledBody.GetComponent <Renderer>().sharedMaterial = null;
                }

                if (options == null)
                {
                    options = new PlanetTextureExporter.TextureOptions();
                    if (generatedBody.pqsVersion != null)
                    {
                        options.Resolution = generatedBody.pqsVersion.mapFilesize;
                    }
                }
            }
Пример #3
0
        /// <summary>
        /// Creates a new ScaledVersion Loader from a spawned CelestialBody.
        /// </summary>
        public ScaledVersionLoader(CelestialBody body)
        {
            // Is this a spawned body?
            if (body.scaledBody == null || Injector.IsInPrefab)
            {
                throw new InvalidOperationException("The body must be already spawned by the PSystemManager.");
            }

            // Get the scaled version object
            Value   = body;
            Coronas = Value.scaledBody.GetComponentsInChildren <SunCoronas>(true).Select(c => new CoronaLoader(c))
                      .ToList();
            if (!Coronas.Any())
            {
                Coronas = null;
            }

            if (Type != ScaledMaterialType.Star)
            {
                ScaledSpaceFader fader = Value.scaledBody.GetComponent <ScaledSpaceFader>();
                if (!(fader is SharedScaledSpaceFader))
                {
                    Utility.CopyObjectFields(fader, Value.scaledBody.AddComponent <SharedScaledSpaceFader>());
                    Object.Destroy(fader);
                }
            }
            else
            {
                SunShaderController controller = Value.scaledBody.GetComponent <SunShaderController>();
                if (controller != null && !(controller is SharedSunShaderController))
                {
                    Utility.CopyObjectFields(controller, Value.scaledBody.AddComponent <SharedSunShaderController>());
                    Object.Destroy(controller);
                }
            }

            if (Options != null)
            {
                return;
            }

            Options = new PlanetTextureExporter.TextureOptions();
            if (body.pqsController == null)
            {
                return;
            }

            Options.Resolution   = body.pqsController.mapFilesize;
            Options.TextureDelta = body.pqsController.mapMaxHeight;
        }
Пример #4
0
        /// <summary>
        /// Creates a new ScaledVersion Loader from the Injector context.
        /// </summary>
        public ScaledVersionLoader()
        {
            // Is this the parser context?
            if (!Injector.IsInPrefab)
            {
                throw new InvalidOperationException("Must be executed in Injector context.");
            }

            // Get the scaled version object
            Value            = generatedBody.celestialBody;
            Value.scaledBody = generatedBody.scaledVersion;

            // Ensure scaled version at least has a mesh filter and mesh renderer
            if (Value.scaledBody.GetComponent <MeshFilter>() == null)
            {
                Value.scaledBody.AddComponent <MeshFilter>();
            }

            if (Value.scaledBody.GetComponent <MeshRenderer>() == null)
            {
                Value.scaledBody.AddComponent <MeshRenderer>();
                Value.scaledBody.GetComponent <Renderer>().sharedMaterial = null;
            }

            if (Options != null)
            {
                return;
            }

            Options = new PlanetTextureExporter.TextureOptions();
            if (generatedBody.pqsVersion == null)
            {
                return;
            }

            Options.Resolution   = generatedBody.pqsVersion.mapFilesize;
            Options.TextureDelta = generatedBody.pqsVersion.mapMaxHeight;
        }
Пример #5
0
        /// <summary>
        /// Creates a new ScaledVersion Loader from a spawned CelestialBody.
        /// </summary>
        public ScaledVersionLoader(CelestialBody body)
        {
            // Is this a spawned body?
            if (body.scaledBody == null || Injector.IsInPrefab)
            {
                throw new InvalidOperationException("The body must be already spawned by the PSystemManager.");
            }

            // Get the scaled version object
            Value   = body;
            Coronas = Value.scaledBody.GetComponentsInChildren <SunCoronas>(true).Select(c => new CoronaLoader(c))
                      .ToList();
            if (!Coronas.Any())
            {
                Coronas = null;
            }

            // Figure out what kind of body we are
            if (Value.scaledBody.GetComponentsInChildren <SunShaderController>(true).Length > 0)
            {
                Type = BodyType.Star;
            }
            else if (Value.atmosphere)
            {
                Type = BodyType.Atmospheric;
            }
            else
            {
                Type = BodyType.Vacuum;
            }

            if (Type != BodyType.Star)
            {
                ScaledSpaceFader fader = Value.scaledBody.GetComponent <ScaledSpaceFader>();
                if (!(fader is SharedScaledSpaceFader))
                {
                    Utility.CopyObjectFields(fader, Value.scaledBody.AddComponent <SharedScaledSpaceFader>());
                    Object.Destroy(fader);
                }
            }
            else
            {
                SunShaderController controller = Value.scaledBody.GetComponent <SunShaderController>();
                if (controller != null && !(controller is SharedSunShaderController))
                {
                    Utility.CopyObjectFields(controller, Value.scaledBody.AddComponent <SharedSunShaderController>());
                    Object.Destroy(controller);
                }
            }

            // Assign the proper scaled space loaders
            if (Material == null)
            {
                return;
            }

            if (ScaledPlanetSimple.UsesSameShader(Material))
            {
                Material = new ScaledPlanetSimpleLoader(Material);
            }

            if (ScaledPlanetRimAerial.UsesSameShader(Material))
            {
                Material = new ScaledPlanetRimAerialLoader(Material);
            }

            if (EmissiveMultiRampSunspots.UsesSameShader(Material))
            {
                Material = new EmissiveMultiRampSunspotsLoader(Material);
            }

            if (Options != null)
            {
                return;
            }

            Options = new PlanetTextureExporter.TextureOptions();
            if (body.pqsController == null)
            {
                return;
            }

            Options.Resolution   = body.pqsController.mapFilesize;
            Options.TextureDelta = body.pqsController.mapMaxHeight;
        }