Esempio n. 1
0
 public PlanetConfig(PlanetConfig other)
 {
     this.name     = other.name;
     this.radius   = other.radius;
     this.lodDepth = other.lodDepth;
     this.highestQualityAtDistance = other.highestQualityAtDistance;
     this.generationService        = other.generationService;
     this.textureService           = other.textureService;
     this.detailService            = other.detailService;
 }
Esempio n. 2
0
 public Planet(PlanetConfig config)
 {
     this.config = config;
 }
Esempio n. 3
0
 public abstract void Init(PlanetConfig config);
Esempio n. 4
0
 public override void Init(PlanetConfig config)
 {
     material.SetFloat("_SeaLevel", config.radius);
 }
Esempio n. 5
0
 public override void Init(PlanetConfig config)
 {
 }
Esempio n. 6
0
 public abstract void Init(PlanetConfig config, Material mat);
Esempio n. 7
0
        public Planet[] RenderOn(GameObject parent)
        {
            //Set sun as child
            FloatingTransform sunFloat;

            if (config.sunObject != parent)
            {
                config.sunObject.transform.SetParent(parent.transform);
                config.sunObject.transform.localPosition = Vector3.zero;
            }
            sunFloat = config.sunObject.GetComponent <FloatingTransform>();
            if (sunFloat != null)
            {
                sunFloat.worldPosition = WorldPosition.zero;
            }

            List <Planet> generatedAstralBodies = new List <Planet>();

            //Deal with children
            for (int i = 0; i < this.config.planets.Length; i++)
            {
                //Get references
                PlanetConfig conf = this.config.planets[i].planetConfig;
                SolarSystemConfig.SolarSystemConfigOrbitalParameters orbit = this.config.planets[i].orbit;

                //Create gameobject
                GameObject go = new GameObject();
                go.name = "Planet: " + conf.name;
                go.transform.SetParent(parent.transform);

                //Create planet
                Planet planet = new Planet(conf);
                generatedAstralBodies.Add(planet);

                //Create-Configure orbit prefab
                SimpleOrbit orb = go.AddComponent <SimpleOrbit>();
                orb.semiMajorAxis = orbit.semiMajorAxis;
                orb.eccentricity  = orbit.eccentricity;
                orb.rotation      = orbit.rotation;

                orb.focusPoint  = SimpleOrbit.FocalPoint.NegativeMajorAxis;
                orb.focusObject = config.sunObject.transform;

                orb.startPosition = orbit.startPosition;

                //Create-Config floating transform (if using this system)
                FloatingTransform floater = go.AddComponent <FloatingTransform>();

                if (sunFloat != null)
                {
                    orb.floatingFocusObject = sunFloat;
                }

                floater.unityPosition = orb.Evaluate(orb.startPosition);

                if (sunFloat != null)
                {
                    floater.worldPosition = orb.EvaluateFloating(orb.startPosition);
                }

                //Render the planet
                planet.RenderOn(go);

                //for (int j = 0; j < this.config.planets[i].moons.Length; i++) {
                //
                //}
            }

            return(generatedAstralBodies.ToArray());
        }
        public void InitializeSystem()
        {
            //Clear old data
            if (generateName)
            {
                name = (new Spaceworks.PhenomicNameGenerator()).Generate(4, 8);
            }

            DestorySystem();

            //Make the floating origin if it does not exist
            FloatingOrigin.Make();

            //Create the sun's reference (0,0,0) in the model (view not made)
            this.sun = new KeplerBody(this.SolarMass, null);

            //Create the initial states of all planetoids
            this.planetStates = new PlanetoidState[this.planetoids.Length];
            for (int i = 0; i < this.planetoids.Length; i++)
            {
                try {
                    //Init references
                    Planetoid      planet   = this.planetoids[i];
                    GameObject     planetGO = new GameObject(string.IsNullOrEmpty(planet.planetData.name) ? this.name + " - " + i : planet.planetData.name);
                    PlanetoidState state    = new PlanetoidState();
                    this.planetStates[i] = state;

                    //Init orbit model
                    state.orbit      = new KeplerOrbit(this.sun, planet.orbit);
                    state.body       = new KeplerBody(planet.mass, state.orbit);
                    state.gameobject = planetGO;

                    //Configure components
                    FloatingTransform transform = planetGO.AddComponent <FloatingTransform>();
                    transform.worldPosition = new WorldPosition(state.orbit.GetCurrentPosition());
                    state.transform         = transform;

                    CubemapMeshGenerator meshService = planetGO.AddComponent <CubemapMeshGenerator>();
                    meshService.range     = planet.mountains;
                    meshService.useSkirts = true;
                    meshService.heights   = planet.heights;
                    meshService.Init();

                    CubemapTextureService textureService = planetGO.AddComponent <CubemapTextureService>();
                    textureService.top = planet.baseMaterial;
                    textureService.top.SetTexture("_MainTex", planet.textures.top);

                    textureService.bottom = planet.baseMaterial;
                    textureService.bottom.SetTexture("_MainTex", planet.textures.bottom);

                    textureService.left = planet.baseMaterial;
                    textureService.left.SetTexture("_MainTex", planet.textures.left);

                    textureService.right = planet.baseMaterial;
                    textureService.right.SetTexture("_MainTex", planet.textures.right);

                    textureService.front = planet.baseMaterial;
                    textureService.front.SetTexture("_MainTex", planet.textures.front);

                    textureService.back = planet.baseMaterial;
                    textureService.back.SetTexture("_MainTex", planet.textures.back);

                    PlanetConfig pcc = new PlanetConfig(planet.planetData);
                    pcc.generationService = meshService;
                    pcc.textureService    = textureService;

                    Planet p = new Planet(pcc);
                    p.RenderOn(planetGO);
                    if (Camera.main)
                    {
                        p.ForceUpdateLODs(Camera.main.transform.position);
                    }

                    state.planet = p;
                }
                catch (Exception e) {
                    Debug.Log("Failed to fully instanciate planetoid: " + i + " because");
                    Debug.Log(e.Message);
                    Debug.Log(e.StackTrace);
                }
            }
        }