Example #1
0
 private void OnBodySpawned(KeplerOrbitMover b)
 {
     if (b != null)
     {
         AddBody(b);
     }
 }
        private KeplerOrbitMover SpawnBody(JPLElementsData data, string attractorName)
        {
            KeplerOrbitMover attractor = FindBodyInstance(attractorName);
            KeplerOrbitMover body      = Instantiate(BodyTemplate, parent: attractor == null ? null : attractor.transform);

            if (!string.IsNullOrEmpty(data.BodyName))
            {
                body.name = data.BodyName.Trim();
            }

            Transform bodyTransform = body.transform;

            if (attractor != null)
            {
                body.AttractorSettings.AttractorMass = data.AttractorMass;
            }

            double unitsPerAU = UnitsPerAU;

            if (IsAllowedRangeScaleMltPerBody)
            {
                // By default MLT value is 1,
                // but for moons it may be larger than 1 for better visualization.
                unitsPerAU *= data.RangeMlt;
            }

            // G constant is used as free parameter to fixate orbits periods values while SemiMajor axis parameter is adjusted for the scene.
            double compensatedGConst = GConstant / Math.Pow(AU / unitsPerAU, 3d);

            body.AttractorSettings.GravityConstant = (float)compensatedGConst;
            body.AttractorSettings.AttractorObject = attractor == null ? null : attractor.transform;
            body.OrbitData = new KeplerOrbitData(
                eccentricity: data.EC,
                semiMajorAxis: data.A * unitsPerAU,
                meanAnomalyDeg: data.MA,
                inclinationDeg: data.IN,
                argOfPerifocusDeg: data.W,
                ascendingNodeDeg: data.OM,
                attractorMass: body.AttractorSettings.AttractorMass,
                gConst: compensatedGConst);
            if (attractor != null && data.A > 0)
            {
                body.ForceUpdateViewFromInternalState();
            }
            else
            {
                body.enabled = false;
            }

            var mat = data.Type == 1 ? MainAttractorMaterial : null;

            SetBodyColorAndDiameter(bodyTransform, data.Color, mat, (float)data.Diameter, ScalePerDiameter);
            body.gameObject.SetActive(true);
            return(body);
        }
Example #3
0
 private void AddTargetBody(KeplerOrbitMover body, KeplerOrbitLineDisplay lineDisplay)
 {
     _targets.Add(new TargetItem()
     {
         Body        = body,
         LineDisplay = lineDisplay,
         OrbitPoints = new Vector3d[0],
     }
                  );
     lineDisplay.enabled = false;
 }
Example #4
0
        private void AddBody(KeplerOrbitMover b)
        {
            // Body's initial mean anomaly is taken as origin point for the epoch.
            // And the origin timestamp for the epoch is defined in this component's parameters.
            _bodies.Add(new BodyTimeData()
            {
                body = b,
                initialMeanAnomaly = b.OrbitData.MeanAnomaly
            });

            b.TimeScale = _currentTimeScale;
        }
 // Start is called before the first frame update
 void Start()
 {
     keplerOrbitMover = GetComponent <KeplerOrbitMover>();
     if (keplerOrbitMover.AttractorSettings.AttractorObject != null)
     {
         isAttached = true;
     }
     else
     {
         isAttached = false;
     }
 }
        private void SpawnAll(JPLElementsData[] inputData)
        {
            // Spawn all bodies in multiple passes to resolve parent-child connections.
            // All spawned bodies are instantiated from signle template, which has no visual components attached,
            // because this example is designed only for simplest orbits loading process demonstration.

            if (inputData == null || inputData.Length == 0)
            {
                return;
            }
            List <JPLElementsData> spawnOrder = new List <JPLElementsData>(inputData);

            ClearAllInstances();
            bool isAnySpawned = true;

            while (spawnOrder.Count > 0 && isAnySpawned)
            {
                isAnySpawned = false;
                for (int i = 0; i < spawnOrder.Count; i++)
                {
                    var spawnItem     = spawnOrder[0];
                    var attractorName = spawnItem.AttractorName != null?spawnItem.AttractorName.Trim() : "";

                    bool Predicate(KeplerOrbitMover s)
                    {
                        return(s.name == attractorName);
                    }

                    bool isAttractorSpawned = string.IsNullOrEmpty(attractorName) || _spawnedInstances.Any(Predicate);
                    if (isAttractorSpawned)
                    {
                        KeplerOrbitMover body = SpawnBody(spawnItem, attractorName);
                        spawnOrder.RemoveAt(0);
                        i--;
                        _spawnedInstances.Add(body);
                        _spawnNotifier.NotifyBodySpawned(body);
                        isAnySpawned = true;
                    }
                    else
                    {
                        // If attractor not spawned yet, then wait for next spawn cycle pass.
                    }
                }
            }

            if (!isAnySpawned && spawnOrder.Count > 0)
            {
                Debug.LogError("Couldn't spawn " + spawnOrder.Count + " because assigned attractor was not found");
            }
        }
Example #7
0
        private void AddTargetBody(KeplerOrbitMover obj)
        {
            if (obj.AttractorSettings.AttractorObject == null || obj.OrbitData.MeanMotion <= 0)
            {
                return;
            }

            var lineDisplay = obj.GetComponent <KeplerOrbitLineDisplay>();

            if (lineDisplay != null)
            {
                AddTargetBody(obj, lineDisplay);
            }
        }
Example #8
0
    ///Users/segalcodin/Documents/Sat_data_base
    void Start()
    {
        savePath = Application.dataPath + "/Saves";
        if (File.Exists(savePath + "/save.binary" + this.transform.name))
        {
            LoadData();
        }
        string appPath  = "";
        var    info     = new DirectoryInfo(Application.dataPath);
        var    fileInfo = info.GetFiles();

        foreach (var item in fileInfo)
        {
            if (item.FullName.Contains(".txt") & !item.FullName.Contains(".meta"))
            {
                appPath = item.FullName;
            }
        }
        if (File.Exists(appPath))
        {
            string[] lines = File.ReadAllLines(appPath);
            for (int i = 0; i < (lines.Length - (lines.Length - nr_sat)) - 2; i += 2)
            {
                Vector3   position;
                Vector3   velocity;
                Satellite sat = new Satellite(new Tle("SGP4", lines[i], lines[i + 1]));
                Eci       eci = sat.PositionEci(360);
                position.x = (float)eci.Position.X / 100;
                position.y = (float)eci.Position.Y / 100;
                position.z = (float)eci.Position.Z / 100;
                velocity.x = (float)eci.Velocity.X;
                velocity.y = (float)eci.Velocity.Y;
                velocity.z = (float)eci.Velocity.Z;

                GameObject satilite = Instantiate(Satelatite);
                satilite.name = "A" + i;
                satilite.transform.position = position;
                KeplerOrbitMover body = satilite.GetComponent <KeplerOrbitMover>();
                body.AttractorSettings.AttractorObject = Atractor;
                body.AttractorSettings.AttractorMass   = attractorMass;
                body.CreateNewOrbitFromPositionAndVelocity(body.transform.position, velocity);
                body.SetAutoCircleOrbit();
                body.LockOrbitEditing     = true;
                satilite.transform.parent = this.transform;
            }
            StateOfMachine.Instance.SetSate = false;
        }
    }
Example #9
0
        private void SpawnAll(JPLElementsData[] inputData)
        {
            // Spawn all bodies in multiple passes to resolve parent-child connections.
            // All spawned bodies are instantiated from signle template, which has no visual components attached,
            // because this example is designed only for simplest orbits loading process demonstration.

            if (inputData == null || inputData.Length == 0)
            {
                return;
            }
            List <JPLElementsData>  spawnOrder       = new List <JPLElementsData>(inputData);
            List <KeplerOrbitMover> spawnedInstances = new List <KeplerOrbitMover>();

            if (GameObject.FindObjectsOfType <Transform>().Length > 5)
            {
                Debug.Log("Warning! too many object on scene. Don't forget to remove old spawned object before spawning new pass");
            }

            bool isAnySpawned = true;

            while (spawnOrder.Count > 0 && isAnySpawned)
            {
                isAnySpawned = false;
                for (int i = 0; i < spawnOrder.Count; i++)
                {
                    var  attractorName      = spawnOrder[0].AttractorName != null ? spawnOrder[0].AttractorName.Trim() : "";
                    bool isAttractorSpawned =
                        string.IsNullOrEmpty(attractorName)
                                                ?true
                                                :spawnedInstances.Any(s => s.name == attractorName);
                    if (isAttractorSpawned)
                    {
                        KeplerOrbitMover attractor = string.IsNullOrEmpty(attractorName)
                                                        ? null
                                                        : spawnedInstances.First(s => s.name == attractorName);
                        KeplerOrbitMover body = Instantiate(BodyTemplate, parent: attractor == null ? null : attractor.transform);
                        if (!string.IsNullOrEmpty(spawnOrder[0].BodyName))
                        {
                            body.name = spawnOrder[0].BodyName.Trim();
                        }
                        if (attractor != null)
                        {
                            body.AttractorSettings.AttractorMass = spawnOrder[0].AttractorMass;
                        }
                        body.AttractorSettings.GravityConstant = (float)GConstant;
                        body.AttractorSettings.AttractorObject = attractor == null ? null : attractor.transform;
                        body.OrbitData = new KeplerOrbitData(
                            eccentricity: spawnOrder[i].EC,
                            semiMajorAxis: spawnOrder[i].A * UnitsPerAU,
                            meanAnomalyDeg: spawnOrder[i].MA,
                            inclinationDeg: spawnOrder[i].IN,
                            argOfPerifocusDeg: spawnOrder[i].W,
                            ascendingNodeDeg: spawnOrder[i].OM,
                            attractorMass: body.AttractorSettings.AttractorMass,
                            gConst: GConstant);
                        if (attractor != null)
                        {
                            body.ForceUpdateViewFromInternalState();
                        }
                        else
                        {
                            body.enabled = false;
                        }
                        body.gameObject.SetActive(true);
                        spawnOrder.RemoveAt(0);
                        i--;
                        spawnedInstances.Add(body);
                        isAnySpawned = true;
                    }
                    else
                    {
                        // If attractor not spawned yet, then wait for next spawn cycle pass.
                    }
                }
            }
            if (!isAnySpawned && spawnOrder.Count > 0)
            {
                Debug.LogError("Couldn't spawn " + spawnOrder.Count + " because assigned attractor was not found");
            }
        }