Ejemplo n.º 1
0
        /// <summary>
        /// Apply this model to the KeplerBody it represents, and scale up the model.
        /// </summary>
        /// <param name="scaleMultiplier"></param>
        public virtual void Apply(double scaleMultiplier)
        {
            KeplerOrbitalParameters realKop = orbitalParameters * scaleMultiplier;

            if (parent == null)
            {
                modelOf.worldPosition = new WorldPosition(new Vector3d(this.transform.position) * scaleMultiplier);
            }
            else
            {
                KeplerBody  body = new KeplerBody(parent.mass, null);
                KeplerOrbit ko   = new KeplerOrbit(body, realKop);
                generatedScaledOrbit  = ko;
                modelOrbit            = new KeplerOrbit(body, orbitalParameters);
                modelOf.worldPosition = new WorldPosition(ko.GetCurrentPosition());
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }