Esempio n. 1
0
        private static void parseStarData()
        {
            TextAsset asterismCSV = Resources.Load("Stardata/AsterismLookupTable") as TextAsset;

            if (asterismCSV == null)
            {
                Debug.LogError("could not load asterism csv.");
                return;
            }

            string[] lines = asterismCSV.ToString().Split('\n');
            AsterismData = new Asterism[lines.Length];

            for (int i = 0; i < lines.Length; i++)
            {
                string   line        = lines[i];
                Asterism newAsterism = new Asterism();

                newAsterism.IsSelected  = false;
                newAsterism.scaleFactor = 1.0f;

                string[] fields = line.Split(',');

                if (fields.Length <= 1)
                {
                    Debug.LogError("Asterism data has fewer than 2 fields. Cannot parse.");
                    continue;
                }

                newAsterism.name   = fields[0];
                newAsterism.HD_ids = new uint[fields.Length - 1];

                for (int j = 1; j < fields.Length; j++)
                {
                    uint hdId;
                    bool parseSuccessful = uint.TryParse(fields[j], out hdId);
                    if (parseSuccessful)
                    {
                        newAsterism.HD_ids[j - 1] = hdId;
                        m_asterismStars.Add(hdId);
                    }
                    else
                    {
                        Debug.LogError("Could not parse asterism " + newAsterism.name + " star HDID: " + fields[j]);
                    }
                }

                AsterismData[i] = newAsterism;
            }
        }
Esempio n. 2
0
 public static void RecalculateCentroids()
 {
     for (int i = 0; i < AsterismData.Length; i++)
     {
         Asterism asterism    = AsterismData[i];
         Vector3  newCentroid = averageStarLocations(asterism.HD_ids);
         if (asterism.root != null)
         {
             removeParents(asterism.HD_ids);
             asterism.root.transform.position = newCentroid;
             attachParents(asterism.HD_ids, asterism.mover.transform);
         }
     }
 }
Esempio n. 3
0
        public static void GetAsterismLines(ref StarData[] starData)
        {
            for (int i = 0; i < AsterismParser.AsterismData.Length; i++)
            {
                Asterism  asterism      = AsterismParser.AsterismData[i];
                Vector3[] positionArray = new Vector3[asterism.HD_ids.Length];
                for (int j = 0; j < asterism.HD_ids.Length; j++)
                {
                    uint hdid = asterism.HD_ids[j];
                    if (StarParser.HD_idToIndex != null && StarParser.HD_idToIndex.ContainsKey(hdid))
                    {
                        StarData   star    = starData[StarParser.HD_idToIndex[hdid]];
                        GameObject starObj = star.GameObjectRepresentation;
                        if (starObj != null)
                        {
                            positionArray[j] = starObj.transform.position;
                        }
                        else
                        {
                            Debug.LogError("Ummm...this star is missing a game object. Skipping the asterism: " + asterism.name);
                        }
                    }
                    else
                    {
                        Debug.LogError("Ummm...this star is missing. Skipping the asterism: " + asterism.name);
                        continue;
                    }
                }

                if (asterism.lineArt == null)
                {
                    if (m_lineMat == null)
                    {
                        m_lineMat = Resources.Load("Lines/LineMat") as Material;
                    }

                    VectorLine asterismLines = new VectorLine(asterism.name + "_line", positionArray, m_lineMat, 1.0f, LineType.Discrete);
                    asterism.lineArt = asterismLines;
                }
                else
                {
                    asterism.lineArt.points3 = positionArray;
                }
                AsterismParser.AsterismData[i] = asterism;
            }

            setAsterismColor(m_asterismColor);
        }
Esempio n. 4
0
        public static void LoadAsterismData()
        {
            TextAsset asterismCSV = Resources.Load("Stardata/AsterismLookupTable") as TextAsset;

            if ( asterismCSV == null ) {
                Debug.LogError("could not load asterism csv.");
                return;
            }

            string[] lines = asterismCSV.ToString().Split('\n');
            AsterismData = new Asterism[lines.Length];

            for(int i=0; i<lines.Length; i++) {
                string line = lines[i];
                Asterism newAsterism = new Asterism();

                string[] fields = line.Split(',');

                if( fields.Length <= 1 ) {
                    Debug.LogError("Asterism data has fewer than 2 fields. Cannot parse.");
                    continue;
                }

                newAsterism.name = fields[0];
                newAsterism.HD_ids = new uint[fields.Length - 1];

                for(int j=1;j<fields.Length;j++) {
              uint hdId;
              bool parseSuccessful = uint.TryParse(fields[j], out hdId);
              if ( parseSuccessful ) {
            newAsterism.HD_ids[j-1] = hdId;
            m_asterismStars.Add(hdId);
              }
              else {
            Debug.LogError("Could not parse asterism " + newAsterism.name + " star HDID: " + fields[j] );
              }
                }

                AsterismData[i] = newAsterism;
            }

            return;
        }
Esempio n. 5
0
        private static void calcAsterismScaleFactor()
        {
            for (int i = 0; i < AsterismData.Length; i++)
            {
                Asterism asterism = AsterismData[i];

                Bounds bounds = new Bounds();

                foreach (var r in asterism.mover.transform.GetComponentsInChildren <Renderer>())
                {
                    bounds.Encapsulate(r.bounds);
                }

                float maxBound    = Mathf.Max(new float[] { bounds.size.x, bounds.size.y, bounds.size.z });
                float ratio       = maxBound / 35.0f;
                float scaleFactor = 1 / ratio;
                asterism.scaleFactor = scaleFactor;
                AsterismData[i]      = asterism;
            }
        }
Esempio n. 6
0
        private static void parseBoundaryData()
        {
            GameObject collisionRoot = new GameObject("CollisionRoot");

            collisionRoot.transform.position = Vector3.zero;
            collisionRoot.transform.rotation = Quaternion.identity;

            GameObject borderRoot = new GameObject("BordernRoot");

            borderRoot.transform.position = Vector3.zero;
            borderRoot.transform.rotation = Quaternion.identity;

            TextAsset bordersCSV = Resources.Load("Stardata/boundaries") as TextAsset;

            if (bordersCSV == null)
            {
                Debug.LogError("could not load border csv.");
                return;
            }

            string[] lines = bordersCSV.ToString().Split('\n');

            List <Vector2> borderPoints         = new List <Vector2>();
            int            currentAsterismIndex = -1;

            for (int i = 0; i < lines.Length; i++)
            {
                string   line   = lines[i];
                string[] fields = line.Split(',');

                if (fields.Length < 4)
                {
                    Debug.Log("incompleteLine: " + line);
                    continue;
                }

                string abreviation       = fields[2];
                string constellationName = m_abrevLookup[abreviation];

                if (currentAsterismIndex == -1 || constellationName != AsterismData[currentAsterismIndex].name)
                {
                    // Store vertecies from last asterism parsed.
                    if (currentAsterismIndex != -1 && borderPoints != null)
                    {
                        Asterism  currentAsterism = AsterismData[currentAsterismIndex];
                        Vector2[] border          = borderPoints.ToArray();

                        Vector3[] lineVerticies = new Vector3[border.Length + 1];
                        coordsToThreeSpace(border).CopyTo(lineVerticies, 1);
                        lineVerticies[0] = lineVerticies[lineVerticies.Length - 1];

                        if (m_borderLineMaterial == null)
                        {
                            m_borderLineMaterial = Resources.Load("Lines/LineMat") as Material;
                        }

                        LineObject borderLine = LineObject.LineFactory(lineVerticies, 5.0f, AsterismDrawer.Target, m_borderLineMaterial, true);
                        borderLine.transform.parent = borderRoot.transform;
                        currentAsterism.borderArt   = borderLine;

                        Mesh       newMesh = meshFromBorders(border);
                        GameObject prefab  = Resources.Load("baseObj") as GameObject;
                        GameObject go      = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;
                        go.transform.GetComponent <MeshFilter>().mesh            = newMesh;
                        go.transform.GetComponent <MeshCollider>().sharedMesh    = newMesh;
                        go.transform.GetComponent <AsterismReference>().Asterism = currentAsterism;
                        go.transform.GetComponent <AsterismReference>().index    = currentAsterismIndex;
                        go.name             = "Collision_" + currentAsterism.name;
                        go.transform.parent = collisionRoot.transform;
                        AsterismData[currentAsterismIndex] = currentAsterism;
                    }

                    // Grab the next asterism being parsed.
                    int indexOfAsterism = asterismIndexFromName(constellationName);
                    if (indexOfAsterism == -1)
                    {
                        currentAsterismIndex = -1;
//            Debug.LogError("Parsing border of unknown constellation: " + constellationName);
                        continue;
                    }
                    currentAsterismIndex = indexOfAsterism;
                    borderPoints         = new List <Vector2>();
                }

                float xComponent = 0.0f;
                float yComponent = 0.0f;

                bool xParsed = float.TryParse(fields[0], out xComponent);
                bool yParsed = float.TryParse(fields[1], out yComponent);

                if (!xParsed || !yParsed)
                {
                    Debug.LogError("Could not parse x and y coords");
                    continue;
                }

                Vector2 newCoord = new Vector2(xComponent, yComponent);

                borderPoints.Add(newCoord);

                // Make sure to store the last point.
                if (i == lines.Length - 1)
                {
                    if (i < AsterismData.Length)
                    {
                        Asterism currentAsterism = AsterismData[i];
                        currentAsterism.borders = borderPoints.ToArray();
                        AsterismData[i]         = currentAsterism;
                    }
                }
            }
        }
Esempio n. 7
0
        private static void setupAsterismGrabbers()
        {
            GameObject starRoot = new GameObject("StarRoot");

            for (int i = 0; i < AsterismData.Length; i++)
            {
                Asterism asterism = AsterismData[i];
                Vector3  centroid = averageStarLocations(asterism.HD_ids);

                GameObject newRoot   = new GameObject();
                GameObject rest      = new GameObject();
                GameObject jewelcase = new GameObject();

                newRoot.name = asterism.name + "_root";
                newRoot.transform.position = centroid;
                newRoot.transform.rotation = Quaternion.identity;

                rest.name                    = "rest";
                rest.transform.parent        = newRoot.transform;
                rest.transform.localPosition = Vector3.zero;
                rest.transform.localRotation = Quaternion.identity;
                rest.transform.localScale    = new Vector3(1.0f, 1.0f, 1.0f);

                jewelcase.name                    = "jewelcase";
                jewelcase.transform.parent        = newRoot.transform;
                jewelcase.transform.localPosition = Vector3.zero;
                jewelcase.transform.localRotation = Quaternion.identity;
                jewelcase.transform.localScale    = new Vector3(1.0f, 1.0f, 1.0f);
                PullToHold pullscript = jewelcase.AddComponent <PullToHold>();
                pullscript.asterismKey = i;
                pullscript.rest        = rest.transform;
                pullscript.maxSpeed    = 20.0f;

                newRoot.transform.parent = starRoot.transform;
                asterism.root            = newRoot;
                asterism.rest            = rest;
                asterism.mover           = jewelcase;

                System.Collections.Generic.HashSet <uint> used = new System.Collections.Generic.HashSet <uint>();

                GameObject constellationLabel = GameObject.Instantiate(Stars.StarUpdater.Instance.ConstellationLabelPrototype) as GameObject;
                constellationLabel.SetActive(true);
                ConstellationLabel labelBehavior = constellationLabel.GetComponent <ConstellationLabel>();

                if (asterism.root != null)
                {
                    labelBehavior.transform.parent = asterism.root.transform;
                }

                labelBehavior.Label = asterism.name;
                labelBehavior.transform.localPosition = (asterism.root.transform.position.normalized * 500.0f);
                asterism.label = labelBehavior;
                labelBehavior.LabelComp.color = new Color(1.0f, 1.0f, 1.0f, Stars.StarUpdater.Instance.LabelOpacity * 0.8f);

                Stars.StarUpdater.Instance.m_constellationLabels.Add(labelBehavior);

                foreach (uint hdId in asterism.HD_ids)
                {
                    if (!Stars.StarParser.HD_idToIndex.ContainsKey(hdId))
                    {
                        continue;
                    }

                    int            index = Stars.StarParser.HD_idToIndex[hdId];
                    Stars.StarData star  = Stars.StarParser.Instance.Stars[index];

                    star.AsterismIndex = i;
                    Stars.StarParser.Instance.Stars[index] = star;
                    if (star.GameObjectRepresentation != null)
                    {
                        star.GameObjectRepresentation.name             = hdId.ToString();
                        star.GameObjectRepresentation.transform.parent = jewelcase.transform;
                        if (star.Label != "")
                        {
                            if (used.Contains(star.HD_id))
                            {
                                continue;
                            }

                            Stars.StarUpdater.Instance.GenerateStarLabel(star, star.GameObjectRepresentation.transform);
                            used.Add(star.HD_id);
                        }
                    }
                }

                AsterismData[i] = asterism;
            }
        }
Esempio n. 8
0
    // Identify pulled object using view of hand
    void Update()
    {
        if (view == null)
        {
            return;
        }

        if (m_hand.CurrentHand == null)
        {
            if (pulled != null)
            {
                if (!attemptingToReaquire)
                {
                    StartCoroutine(reaquireHand(2.0f));
                }
            }
            return;
        }

        if (pulled != null)
        {
            return;
        }



        if (Hold == null && m_hand.CurrentHand != null)
        {
            updateHold();
            //GrabberHand grabberHand = m_hand.CurrentHand.gameObject.GetComponent<GrabberHand>();
            //if ( grabberHand == null ) { return; }
            //Hold = grabberHand.hold;
        }


        Vector2 screenPoint = m_leftCam.WorldToScreenPoint(m_hand.CurrentHand.GetPalmPosition());
        Ray     throughHand = m_leftCam.ScreenPointToRay(screenPoint);

        //Debug.DrawRay(m_leftCam.transform.position, m_leftCam.ScreenPointToRay(screenPoint).direction * 1000.0f);

        RaycastHit castInfo;
        bool       hit = Physics.Raycast(throughHand, out castInfo, float.PositiveInfinity, LayerMask.GetMask("AsterismColliders"));

        if (hit)
        {
            if (!Activate())
            {
                this.enabled = false;
                return;
            }

            AsterismReference asterismRef = castInfo.transform.GetComponent <AsterismReference>();
            if (asterismRef != null)
            {
                Asterisms.Asterism hitAsterism = asterismRef.Asterism;

                PullToHold intersect = hitAsterism.mover.GetComponent <PullToHold>();

                if (intersect.cameraPoint == null)
                {
                    intersect.cameraPoint = m_leftCam.transform;
                }

                if (intersect != null)
                {
                    SelectStars(hitAsterism.mover);
                    Acquire(intersect);
                }
            }
        }
    }
Esempio n. 9
0
        public static void GetAsterismLines(ref StarData[] starData)
        {
            bool initilized = true;

            for (int i = 0; i < AsterismParser.AsterismData.Length; i++)
            {
                if (!initilized)
                {
                    break;
                }
                Asterism  asterism      = AsterismParser.AsterismData[i];
                Vector3[] positionArray = new Vector3[asterism.HD_ids.Length];
                for (int j = 0; j < asterism.HD_ids.Length; j++)
                {
                    uint hdid = asterism.HD_ids[j];

                    try {
                        StarData   star    = starData[StarParser.HD_idToIndex[hdid]];
                        GameObject starObj = star.GameObjectRepresentation;
                        if (starObj != null)
                        {
                            if (starObj.transform.position == Vector3.zero)
                            {
                                initilized = false;
                                break;
                            }

                            positionArray[j] = starObj.transform.position;
                        }
                        else
                        {
                            Debug.LogWarning("Ummm...this star is missing a game object. Skipping the asterism: " + asterism.name);
                        }
                    }
                    catch (KeyNotFoundException e) {
                        Debug.Log(e.Message);
                        Debug.LogWarning("Ummm...this star is missing: " + hdid + ". Skipping the asterism: " + asterism.name);
                        continue;
                    }
                }

                if (!initilized)
                {
                    return;
                }

                if (asterism.lineArt == null)
                {
                    if (m_lineMat == null)
                    {
                        m_lineMat = Resources.Load("Lines/LineMat") as Material;
                    }

                    if (m_asterismLineRoot == null)
                    {
                        m_asterismLineRoot = new GameObject("AsterismLineRoot");
                    }

                    LineObject asterismLines = LineObject.LineFactory(positionArray, 3.0f, m_target, m_lineMat);

                    asterismLines.gameObject.name = asterism.name + "_line";

                    asterismLines.transform.parent = m_asterismLineRoot.transform;

                    asterism.lineArt = asterismLines;
                }
                else
                {
                    asterism.lineArt.Points = positionArray;
                }
                AsterismParser.AsterismData[i] = asterism;
            }

            setAsterismColor(m_asterismColor);
        }