Esempio n. 1
0
        public static Vector3Double SmoothDamp(Vector3Double current, Vector3Double target, ref Vector3Double currentVelocity, double smoothTime)
        {
            double deltaTime = (double)Time.deltaTime;
            double maxSpeed  = double.PositiveInfinity;

            return(Vector3Double.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime));
        }
Esempio n. 2
0
 public static Vector3Double ClampMagnitude(Vector3Double vector, double maxLength)
 {
     if (vector.sqrMagnitude > maxLength * maxLength)
     {
         return(vector.normalized * maxLength);
     }
     else
     {
         return(vector);
     }
 }
Esempio n. 3
0
        public static void OrthoNormalize(ref Vector3Double normal, ref Vector3Double tangent)
        {
            Vector3 v3normal  = new Vector3();
            Vector3 v3tangent = new Vector3();

            v3normal  = (Vector3)normal;
            v3tangent = (Vector3)tangent;
            Vector3.OrthoNormalize(ref v3normal, ref v3tangent);
            normal  = new Vector3Double(v3normal);
            tangent = new Vector3Double(v3tangent);
        }
Esempio n. 4
0
        public static Vector3Double Normalize(Vector3Double value)
        {
            double num = Vector3Double.Magnitude(value);

            if (num > 9.99999974737875E-06)
            {
                return(value / num);
            }
            else
            {
                return(Vector3Double.zero);
            }
        }
Esempio n. 5
0
        public static Vector3Double Project(Vector3Double vector, Vector3Double onNormal)
        {
            double num = Vector3Double.Dot(onNormal, onNormal);

            if (num < 1.40129846432482E-45d)
            {
                return(Vector3Double.zero);
            }
            else
            {
                return(onNormal * Vector3Double.Dot(vector, onNormal) / num);
            }
        }
Esempio n. 6
0
        public static Vector3Double MoveTowards(Vector3Double current, Vector3Double target, double maxDistanceDelta)
        {
            Vector3Double vector3   = target - current;
            double        magnitude = vector3.magnitude;

            if (magnitude <= maxDistanceDelta || magnitude == 0.0d)
            {
                return(target);
            }
            else
            {
                return(current + vector3 / magnitude * maxDistanceDelta);
            }
        }
Esempio n. 7
0
        public override bool Equals(object other)
        {
            if (!(other is Vector3Double))
            {
                return(false);
            }
            Vector3Double vector3d = (Vector3Double)other;

            if (this.x.Equals(vector3d.x) && this.y.Equals(vector3d.y))
            {
                return(this.z.Equals(vector3d.z));
            }
            else
            {
                return(false);
            }
        }
Esempio n. 8
0
        public void SetLoadingRange(Double regularLoadingRange, Double impostorLoadingRange)
        {
#if UNITY_EDITOR
            if (regularLoadingRange > 0 || impostorLoadingRange > 0)
            {
                Vector3Double targetLoadingExtentsRegular  = new Vector3Double(regularLoadingRange, regularLoadingRange, regularLoadingRange);
                Vector3Double targetLoadingExtentsImpostor = new Vector3Double(impostorLoadingRange, impostorLoadingRange, impostorLoadingRange);

                BoundsDouble loadingBounds = m_sceneViewOriginLoadingBounds;
                if (m_centerSceneViewLoadingOn == CenterSceneViewLoadingOn.SceneViewCamera)
                {
                    var allCameras = SceneView.GetAllSceneCameras();
                    if (allCameras.Length > 0)
                    {
                        if (m_sceneViewCameraLoadingBounds.center.Equals((Vector3Double)allCameras[0].transform.position) && m_sceneViewCameraLoadingBounds.extents.Equals(targetLoadingExtentsRegular) && m_sceneViewImpostorLoadingBounds.extents.Equals(targetLoadingExtentsImpostor))
                        {
                            //this exact setup is what is already currently loaded, skip the rest of processing
                            return;
                        }

                        m_sceneViewCameraLoadingBounds.center = (Vector3Double)allCameras[0].transform.position;
                    }
                    loadingBounds = m_sceneViewCameraLoadingBounds;
                }
                loadingBounds.extents = targetLoadingExtentsRegular;
                m_sceneViewOriginLoadingBounds.extents   = loadingBounds.extents;
                m_sceneViewImpostorLoadingBounds.center  = loadingBounds.center;
                m_sceneViewImpostorLoadingBounds.extents = targetLoadingExtentsImpostor;

                EditorUtility.SetDirty(this);
                UpdateTerrainLoadState(loadingBounds, m_sceneViewImpostorLoadingBounds, gameObject);
            }
            else
            {
                m_sceneViewOriginLoadingBounds.extents   = Vector3.zero;
                m_sceneViewImpostorLoadingBounds.extents = Vector3.zero;
                foreach (TerrainScene ts in m_terrainSceneStorage.m_terrainScenes)
                {
                    ts.RemoveRegularReference(gameObject);
                    ts.RemoveImpostorReference(gameObject);
                }
            }
#endif
        }
Esempio n. 9
0
        public static Vector3Double SmoothDamp(Vector3Double current, Vector3Double target, ref Vector3Double currentVelocity, double smoothTime, double maxSpeed, double deltaTime)
        {
            smoothTime = Mathd.Max(0.0001d, smoothTime);
            double        num1      = 2d / smoothTime;
            double        num2      = num1 * deltaTime;
            double        num3      = (1.0d / (1.0d + num2 + 0.479999989271164d * num2 * num2 + 0.234999999403954d * num2 * num2 * num2));
            Vector3Double vector    = current - target;
            Vector3Double vector3_1 = target;
            double        maxLength = maxSpeed * smoothTime;
            Vector3Double vector3_2 = Vector3Double.ClampMagnitude(vector, maxLength);

            target = current - vector3_2;
            Vector3Double vector3_3 = (currentVelocity + num1 * vector3_2) * deltaTime;

            currentVelocity = (currentVelocity - num1 * vector3_3) * num3;
            Vector3Double vector3_4 = target + (vector3_2 + vector3_3) * num3;

            if (Vector3Double.Dot(vector3_1 - current, vector3_4 - vector3_1) > 0.0)
            {
                vector3_4       = vector3_1;
                currentVelocity = (vector3_4 - vector3_1) / deltaTime;
            }
            return(vector3_4);
        }
Esempio n. 10
0
        public void SyncLocationFromStamperSettings()
        {
            BoundsDouble b = new BoundsDouble();

            TerrainHelper.GetTerrainBounds(ref b);
            Transform worldmapTransform = transform.parent.parent;
            Terrain   worldMapTerrain   = worldmapTransform.GetComponent <Terrain>();
            //TODO: review if this needs to be in double precision

            Vector3Double origin = TerrainLoaderManager.Instance.GetOrigin();

            float relativeX = (float)(m_connectedStamperSettings.m_x - b.min.x + origin.x / TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize) / (float)b.size.x;
            float relativeY = (float)m_connectedStamperSettings.m_y * TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize;
            float relativeZ = (float)(m_connectedStamperSettings.m_z - b.min.z + origin.z / TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize) / (float)b.size.z;

            //float relativeX = (float)(m_connectedStamperSettings.m_x - b.min.x) / (float)b.size.x;
            //float relativeY = (float) m_connectedStamperSettings.m_y * SessionManager.m_session.m_worldMaprelativeSize;
            //float relativeZ = (float)(m_connectedStamperSettings.m_z - b.min.z) / (float)b.size.z;

            float newX = worldmapTransform.position.x + worldMapTerrain.terrainData.size.x * relativeX;
            float newZ = worldmapTransform.position.z + worldMapTerrain.terrainData.size.z * relativeZ;

            transform.position = new Vector3(newX, relativeY, newZ);
        }
Esempio n. 11
0
 public static double Magnitude(Vector3Double a)
 {
     return(Math.Sqrt(a.x * a.x + a.y * a.y + a.z * a.z));
 }
Esempio n. 12
0
        public static double Distance(Vector3Double a, Vector3Double b)
        {
            Vector3Double vector3d = new Vector3Double(a.x - b.x, a.y - b.y, a.z - b.z);

            return(Math.Sqrt(vector3d.x * vector3d.x + vector3d.y * vector3d.y + vector3d.z * vector3d.z));
        }
Esempio n. 13
0
 public TerrainScene GetTerrainSceneAtPosition(Vector3Double center)
 {
     return(m_terrainSceneStorage.m_terrainScenes.Find(x => x.m_bounds.Contains(center)));
 }
Esempio n. 14
0
        public void LoadStorageData()
        {
#if UNITY_EDITOR
            //Try to get the terrain scene storage file from the last used GUID first
            if (!String.IsNullOrEmpty(m_lastUsedGUID))
            {
                m_terrainSceneStorage = (TerrainSceneStorage)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(m_lastUsedGUID), typeof(TerrainSceneStorage));
            }

            //No guid / storage object? Then we need to create one in the current session directory
            if (m_terrainSceneStorage == null)
            {
                GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager();
                if (gsm != null && gsm.m_session != null)
                {
                    string path = GaiaDirectories.GetScenePath(gsm.m_session) + "/TerrainScenes.asset";
                    if (File.Exists(path))
                    {
                        m_terrainSceneStorage = (TerrainSceneStorage)AssetDatabase.LoadAssetAtPath(path, typeof(TerrainSceneStorage));
                    }
                    else
                    {
                        m_terrainSceneStorage = ScriptableObject.CreateInstance <TerrainSceneStorage>();
                        if (TerrainHelper.GetWorldMapTerrain() != null)
                        {
                            m_terrainSceneStorage.m_hasWorldMap = true;
                        }
                        AssetDatabase.CreateAsset(m_terrainSceneStorage, path);
                        AssetDatabase.ImportAsset(path);
                    }
                }
                else
                {
                    m_terrainSceneStorage = ScriptableObject.CreateInstance <TerrainSceneStorage>();
                }
            }

            //Check if there are scene files existing already and if they are in the storage data - if not, we should pick them up accordingly
            string directory = GaiaDirectories.GetTerrainScenePathForStorageFile(m_terrainSceneStorage);
            var    dirInfo   = new DirectoryInfo(directory);

            bool madeChanges = false;

            if (dirInfo != null)
            {
                FileInfo[] allFiles = dirInfo.GetFiles();
                foreach (FileInfo fileInfo in allFiles)
                {
                    if (fileInfo.Extension == ".unity")
                    {
                        string path = GaiaDirectories.GetPathStartingAtAssetsFolder(fileInfo.FullName);

                        if (!m_terrainSceneStorage.m_terrainScenes.Exists(x => x.GetTerrainName() == x.GetTerrainName(path)))
                        {
                            string firstSegment = fileInfo.Name.Split('-')[0];
                            int    xCoord = -99;
                            int    zCoord = -99;
                            bool   successX, successZ;
                            try
                            {
                                successX = Int32.TryParse(firstSegment.Substring(firstSegment.IndexOf('_') + 1, firstSegment.LastIndexOf('_') - (firstSegment.IndexOf('_') + 1)), out xCoord);
                                successZ = Int32.TryParse(firstSegment.Substring(firstSegment.LastIndexOf('_') + 1, firstSegment.Length - 1 - firstSegment.LastIndexOf('_')), out zCoord);
                            }
                            catch (Exception ex)
                            {
                                if (ex.Message == "123")
                                {
                                }
                                successX = false;
                                successZ = false;
                            }


                            if (successX && successZ)
                            {
                                //double centerX = (xCoord - (m_terrainSceneStorage.m_terrainTilesX / 2f)) * m_terrainSceneStorage.m_terrainTilesSize + (m_terrainSceneStorage.m_terrainTilesSize /2f);
                                //double centerZ = (zCoord - (m_terrainSceneStorage.m_terrainTilesZ / 2f)) * m_terrainSceneStorage.m_terrainTilesSize + (m_terrainSceneStorage.m_terrainTilesSize / 2f);
                                Vector2       offset   = new Vector2(-m_terrainSceneStorage.m_terrainTilesSize * m_terrainSceneStorage.m_terrainTilesX * 0.5f, -m_terrainSceneStorage.m_terrainTilesSize * m_terrainSceneStorage.m_terrainTilesZ * 0.5f);
                                Vector3Double position = new Vector3(m_terrainSceneStorage.m_terrainTilesSize * xCoord + offset.x, 0, m_terrainSceneStorage.m_terrainTilesSize * zCoord + offset.y);
                                Vector3Double center   = new Vector3Double(position + new Vector3Double(m_terrainSceneStorage.m_terrainTilesSize / 2f, 0f, m_terrainSceneStorage.m_terrainTilesSize / 2f));
                                BoundsDouble  bounds   = new BoundsDouble(center, new Vector3Double(m_terrainSceneStorage.m_terrainTilesSize, m_terrainSceneStorage.m_terrainTilesSize * 4, m_terrainSceneStorage.m_terrainTilesSize));
                                //Use forward slashes in the path - The Unity scene management classes expect it that way
                                path = path.Replace("\\", "/");
                                TerrainScene terrainScene = new TerrainScene()
                                {
                                    m_scenePath           = path,
                                    m_pos                 = position,
                                    m_bounds              = bounds,
                                    m_useFloatingPointFix = m_terrainSceneStorage.m_useFloatingPointFix
                                };

                                if (File.Exists(path.Replace("Terrain", GaiaConstants.ImpostorTerrainName)))
                                {
                                    terrainScene.m_impostorScenePath = path.Replace("Terrain", GaiaConstants.ImpostorTerrainName);
                                }

                                if (File.Exists(path.Replace("Terrain", "Collider")))
                                {
                                    terrainScene.m_colliderScenePath = path.Replace("Terrain", "Collider");
                                }

                                if (File.Exists(path.Replace("Terrain", "Backup")))
                                {
                                    terrainScene.m_backupScenePath = path.Replace("Terrain", "Backup");
                                }

                                m_terrainSceneStorage.m_terrainScenes.Add(terrainScene);
                                madeChanges = true;
                            }
                        }
                    }
                }
                if (madeChanges)
                {
                    EditorUtility.SetDirty(m_terrainSceneStorage);
                    AssetDatabase.SaveAssets();
                }
            }

            m_lastUsedGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_terrainSceneStorage));


            RefreshTerrainsWithCurrentData();

            RefreshSceneViewLoadingRange();

            ////Go over the currently open scene and close the ones that do not seem to have a reference on them
            //for (int i = EditorSceneManager.loadedSceneCount-1; i >= 0; i--)
            //{
            //    Scene scene = EditorSceneManager.GetSceneAt(i);
            //    if (EditorSceneManager.GetActiveScene().Equals(scene))
            //    {
            //        continue;
            //    }
            //      TerrainScene terrainScene = m_terrainSceneStorage.m_terrainScenes.Find(x => x.m_scenePath == scene.path || x.m_impostorScenePath == scene.path || x.m_colliderScenePath == scene.path);
            //      if (terrainScene != null)
            //      {
            //            terrainScene.UpdateWithCurrentData();
            //      }
            //      else
            //      {
            //            EditorSceneManager.UnloadSceneAsync(scene);
            //      }
            //}
#endif
        }
Esempio n. 15
0
 public static Vector3Double Exclude(Vector3Double excludeThis, Vector3Double fromThat)
 {
     return(fromThat - Vector3Double.Project(fromThat, excludeThis));
 }
Esempio n. 16
0
        public void SetOrigin(Vector3Double newOrigin)
        {
#if GAIA_PRO_PRESENT
            if (newOrigin != m_sceneViewOriginLoadingBounds.center)
            {
                //a origin shift has occured,
                Vector3Double shiftDifference = newOrigin - m_sceneViewOriginLoadingBounds.center;

                //Don't shift on y-axis this will only lead to problems with sea level, height based rules, etc.
                //and should not be required under normal circumstances.
                shiftDifference.y = 0;

                //shift all tools such as stampers and spawners
                //Stamper[] allStampers = Resources.FindObjectsOfTypeAll<Stamper>();
                //foreach (Stamper stamper in allStampers)
                //{
                //    stamper.transform.position = (Vector3)((Vector3Double)stamper.transform.position + m_originLoadingBounds.center - shiftDifference);
                //}

                //if not in playmode, shift the player, if exists, very confusing otherwise
                if (!Application.isPlaying)
                {
                    GameObject playerObj = GameObject.Find(GaiaConstants.playerFlyCamName);

                    if (playerObj == null)
                    {
                        playerObj = GameObject.Find(GaiaConstants.playerFirstPersonName);
                    }

                    if (playerObj == null)
                    {
                        playerObj = GameObject.Find(GaiaConstants.playerThirdPersonName);
                    }

                    if (playerObj != null)
                    {
                        playerObj.transform.position = (Vector3)((Vector3Double)playerObj.transform.position - shiftDifference);
                    }

                    //Move spawners also only when not in playmode
                    Spawner[] allSpawners = Resources.FindObjectsOfTypeAll <Spawner>();
                    foreach (Spawner spawner in allSpawners)
                    {
                        spawner.transform.position = (Vector3)((Vector3Double)spawner.transform.position - shiftDifference);
                    }

                    //Move world map stamp tokens also only when not in playmode
                    WorldMapStampToken[] mapStampTokens = Resources.FindObjectsOfTypeAll <WorldMapStampToken>();
                    foreach (WorldMapStampToken token in mapStampTokens)
                    {
                        token.UpdateGizmoPos();
                    }

                    //When the application is not playing we can look for all floating point fix members, if it is playing we should
                    //rely on the list of members being filled correctly at the start of the scene
                    m_allFloatingPointFixMembers = Resources.FindObjectsOfTypeAll <FloatingPointFixMember>().ToList();
                }
                m_allFloatingPointFixMembers.RemoveAll(x => x == null);
                foreach (FloatingPointFixMember member in m_allFloatingPointFixMembers)
                {
                    member.transform.position = (Vector3)((Vector3Double)member.transform.position - shiftDifference);
                }


                //shift world space particles accordingly - only worth dealing with during playmode
                if (Application.isPlaying)
                {
                    m_allWorldSpaceParticleSystems.RemoveAll(x => x == null);
                    foreach (ParticleSystem ps in m_allWorldSpaceParticleSystems)
                    {
                        bool wasPaused  = ps.isPaused;
                        bool wasPlaying = ps.isPlaying;
                        ParticleSystem.Particle[] currentParticles = null;

                        if (!wasPaused)
                        {
                            ps.Pause();
                        }

                        if (currentParticles == null || currentParticles.Length < ps.main.maxParticles)
                        {
                            currentParticles = new ParticleSystem.Particle[ps.main.maxParticles];
                        }

                        int num = ps.GetParticles(currentParticles);

                        for (int i = 0; i < num; i++)
                        {
                            currentParticles[i].position -= (Vector3)shiftDifference;
                        }

                        ps.SetParticles(currentParticles, num);

                        if (wasPlaying)
                        {
                            ps.Play();
                        }
                    }
                }

                m_sceneViewOriginLoadingBounds.center = newOrigin;
#if UNITY_EDITOR
                EditorUtility.SetDirty(this);
#endif

                //if (WorldMapTerrain != null)
                //{
                //    WorldMapTerrain.transform.position = -m_originLoadingBounds.center - (new Vector3Double(WorldMapTerrain.terrainData.size.x / 2f, 0f, WorldMapTerrain.terrainData.size.z / 2f));
                //}

                //Update terrain loading state for all terrains since the session manager loads itself around the origin
                RefreshSceneViewLoadingRange();
            }
#endif
        }
Esempio n. 17
0
 public static double Dot(Vector3Double lhs, Vector3Double rhs)
 {
     return(lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z);
 }
Esempio n. 18
0
        /// <summary>
        /// Get the bounds of the terrain at this location or fail with a null
        /// </summary>
        /// <param name="locationWU">Location to check and get terrain for</param>
        /// <returns>Bounds of selected terrain or null if invalid for some reason</returns>
        public static bool GetTerrainBounds(ref BoundsDouble bounds, bool activeTerrainsOnly = false)
        {
            //Terrain terrain = GetTerrain(locationWU);
            //if (terrain == null)
            //{
            //    return false;
            //}
            //bounds.center = terrain.transform.position;
            //bounds.size = terrain.terrainData.size;
            //bounds.center += bounds.extents;

            Vector3Double accumulatedCenter = new Vector3Double();

            //Do we use dynamic loaded terrains in the scene?
            if (GaiaUtils.HasDynamicLoadedTerrains() && !activeTerrainsOnly)
            {
#if GAIA_PRO_PRESENT
                //we do have dynamic terrains -> calculate the bounds according to the terrain scene data in the session
                GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager(false);

                foreach (TerrainScene t in TerrainLoaderManager.TerrainScenes)
                {
                    accumulatedCenter += t.m_bounds.center;
                }

                bounds.center = accumulatedCenter / TerrainLoaderManager.TerrainScenes.Count;

                foreach (TerrainScene t in TerrainLoaderManager.TerrainScenes)
                {
                    bounds.Encapsulate(t.m_bounds);
                }
#endif
            }
            else
            {
                //no placeholder -> calculate bounds according to the active terrains in the scene
                if (Terrain.activeTerrains.Length > 0)
                {
                    foreach (Terrain t in Terrain.activeTerrains)
                    {
                        if (!TerrainHelper.IsWorldMapTerrain(t))
                        {
                            if (t.terrainData != null)
                            {
                                accumulatedCenter += new Vector3Double(t.transform.position) + new Vector3Double(t.terrainData.bounds.extents);
                            }
                            else
                            {
                                Debug.LogWarning("Terrain " + t.name + " in the scene is missing the terrain data object!");
                            }
                        }
                    }
                    bounds.center = accumulatedCenter / Terrain.activeTerrains.Length;

                    foreach (Terrain t in Terrain.activeTerrains)
                    {
                        if (!TerrainHelper.IsWorldMapTerrain(t))
                        {
                            if (t.terrainData != null)
                            {
                                Bounds newBounds = new Bounds();
                                newBounds.center  = t.transform.position;
                                newBounds.size    = t.terrainData.size;
                                newBounds.center += t.terrainData.bounds.extents;
                                bounds.Encapsulate(newBounds);
                            }
                        }
                    }
                }
                else
                {
                    bounds = new BoundsDouble(Vector3Double.zero, Vector3Double.zero);
                    //No active terrains? There might be mesh terrains we can use then
                    GameObject meshTerrainExportObject = GaiaUtils.GetTerrainExportObject(false);
                    if (meshTerrainExportObject != null)
                    {
                        foreach (Transform t in meshTerrainExportObject.transform)
                        {
                            MeshRenderer mr = t.GetComponent <MeshRenderer>();
                            if (mr != null)
                            {
                                bounds.Encapsulate(mr.bounds);
                            }
                        }
                    }
                }
            }


            return(true);
        }
Esempio n. 19
0
 public static Vector3Double Reflect(Vector3Double inDirection, Vector3Double inNormal)
 {
     return(-2d * Vector3Double.Dot(inNormal, inDirection) * inNormal + inDirection);
 }
Esempio n. 20
0
 public static bool operator !=(Vector3Double lhs, Vector3Double rhs)
 {
     return((double)Vector3Double.SqrMagnitude(lhs - rhs) >= 0.0 / 1.0);
 }
Esempio n. 21
0
 public static Vector3Double Cross(Vector3Double lhs, Vector3Double rhs)
 {
     return(new Vector3Double(lhs.y * rhs.z - lhs.z * rhs.y, lhs.z * rhs.x - lhs.x * rhs.z, lhs.x * rhs.y - lhs.y * rhs.x));
 }
Esempio n. 22
0
 public static double AngleBetween(Vector3Double from, Vector3Double to)
 {
     return(Mathd.Acos(Mathd.Clamp(Vector3Double.Dot(from.normalized, to.normalized), -1d, 1d)));
 }
Esempio n. 23
0
 public static double SqrMagnitude(Vector3Double a)
 {
     return(a.x * a.x + a.y * a.y + a.z * a.z);
 }
Esempio n. 24
0
        //public static explicit operator Vector3(Vector3Double vector3d)
        //{
        //    return new Vector3((float)vector3d.x, (float)vector3d.y, (float)vector3d.z);
        //}

        public static Vector3Double Lerp(Vector3Double from, Vector3Double to, double t)
        {
            t = Mathd.Clamp01(t);
            return(new Vector3Double(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t, from.z + (to.z - from.z) * t));
        }
Esempio n. 25
0
        public static Vector3Double RotateTowards(Vector3Double current, Vector3Double target, double maxRadiansDelta, double maxMagnitudeDelta)
        {
            Vector3 v3 = Vector3.RotateTowards((Vector3)current, (Vector3)target, (float)maxRadiansDelta, (float)maxMagnitudeDelta);

            return(new Vector3Double(v3));
        }
Esempio n. 26
0
        public static Vector3Double Slerp(Vector3Double from, Vector3Double to, double t)
        {
            Vector3 v3 = Vector3.Slerp((Vector3)from, (Vector3)to, (float)t);

            return(new Vector3Double(v3));
        }
Esempio n. 27
0
 public static Vector3Double Max(Vector3Double lhs, Vector3Double rhs)
 {
     return(new Vector3Double(Mathd.Max(lhs.x, rhs.x), Mathd.Max(lhs.y, rhs.y), Mathd.Max(lhs.z, rhs.z)));
 }
Esempio n. 28
0
 public static Vector3Double Scale(Vector3Double a, Vector3Double b)
 {
     return(new Vector3Double(a.x * b.x, a.y * b.y, a.z * b.z));
 }
Esempio n. 29
0
 public void Scale(Vector3Double scale)
 {
     this.x *= scale.x;
     this.y *= scale.y;
     this.z *= scale.z;
 }
Esempio n. 30
0
        private static void DrawTopPanel()
        {
            bool currentGUIState = GUI.enabled;

            float dpiScalingFactor   = (96 / Screen.dpi);
            float scaledScreenWidth  = (Camera.current.pixelRect.size.x * dpiScalingFactor);
            float scaledScreenHeight = (Camera.current.pixelRect.size.y * dpiScalingFactor);


            float sizeX = GaiaSettings.m_gaiaPanelSizeType == PositionType.Relative ? scaledScreenWidth * GaiaSettings.m_gaiaPanelSize.x / 100f : GaiaSettings.m_gaiaPanelSize.x;
            float sizeY = GaiaSettings.m_gaiaPanelSizeType == PositionType.Relative ? scaledScreenHeight * GaiaSettings.m_gaiaPanelSize.y / 100f : GaiaSettings.m_gaiaPanelSize.y;
            float x     = GaiaSettings.m_gaiaPanelPositionType == PositionType.Relative ? (scaledScreenWidth * GaiaSettings.m_gaiaPanelPosition.x / 100f) - (sizeX + 50f) / 2f : GaiaSettings.m_gaiaPanelPosition.x;
            float y     = GaiaSettings.m_gaiaPanelPositionType == PositionType.Relative ? (scaledScreenHeight * GaiaSettings.m_gaiaPanelPosition.y / 100f) : GaiaSettings.m_gaiaPanelPosition.y;

            GUILayout.BeginArea(new Rect(x, y, sizeX + 50, sizeY));
            float leftSpace = 6f;

            EditorGUI.BeginChangeCheck();


            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();
                EditorGUILayout.BeginVertical(GUIStylePanel, GUILayout.MaxWidth(sizeX));
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        GUILayout.Space(leftSpace);
                        if (GUILayout.Button("Manager", GUILayout.Height(15), GUILayout.Width(70)))
                        {
                            var manager = EditorWindow.GetWindow <Gaia.GaiaManagerEditor>(false, "Gaia Manager");
                            //Manager can be null if the dependency package installation is started upon opening the manager window.
                            if (manager != null)
                            {
                                Vector2 initialSize = new Vector2(650f, 450f);
                                manager.position = new Rect(new Vector2(Screen.currentResolution.width / 2f - initialSize.x / 2f, Screen.currentResolution.height / 2f - initialSize.y / 2f), initialSize);
                                manager.Show();
                            }
                        }

                        if (TerrainLoaderManager.Instance.TerrainSceneStorage.m_hasWorldMap)
                        {
                            GUILayout.Label("Gaia", GUIStyleHeader, GUILayout.MaxHeight(16));
                            if (WorldMapTerrain != null)
                            {
                                if (!GaiaUtils.HasTerrains())
                                {
                                    GUI.enabled = false;
                                }
                                if (GUILayout.Button("Terrain", GUILayout.Height(15), GUILayout.Width(75)))
                                {
                                    TerrainLoaderManager.Instance.SwitchToLocalMap();
                                }
                                GUI.enabled = currentGUIState;


                                if (GUILayout.Button("Designer", GUILayout.Height(15), GUILayout.Width(75)))
                                {
                                    TerrainLoaderManager.Instance.SwitchToWorldMap();
                                }
                            }
                            else
                            {
                                //GUILayout.Space(200);
                            }
                        }
                        else
                        {
                            GUILayout.Space(-50);
                            GUILayout.Label("Gaia", GUIStyleHeader, GUILayout.MaxHeight(16));
                            if (!TerrainLoaderManager.Instance.ShowLocalTerrain)
                            {
                                TerrainLoaderManager.Instance.SwitchToLocalMap();
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
#if GAIA_PRO_PRESENT
                    if (SessionManager.m_showSceneViewPanel)
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            GUILayout.Label("Go To Terrain:", GUILayout.Width(100));
                            GUILayout.Label("X", GUILayout.Width(coordLabelWidth));
                            GaiaTerrainLoaderManager.Instance.m_originTargetTileX = EditorGUILayout.DelayedIntField(GaiaTerrainLoaderManager.Instance.m_originTargetTileX, GUILayout.Width(coordInputWidth));
                            GUILayout.Space(84);
                            GUILayout.Label("Z", GUILayout.Width(coordLabelWidth));
                            GaiaTerrainLoaderManager.Instance.m_originTargetTileZ = EditorGUILayout.DelayedIntField(GaiaTerrainLoaderManager.Instance.m_originTargetTileZ, GUILayout.Width(coordInputWidth));
                            if (GUILayout.Button("Go", GUILayout.Height(15), GUILayout.Width(52)))
                            {
                                GaiaTerrainLoaderManager.Instance.SetOriginByTargetTile();
                                range      = GaiaTerrainLoaderManager.Instance.GetLoadingRange();
                                currentPos = GaiaTerrainLoaderManager.Instance.GetOrigin();
                            }
                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();


                        EditorGUILayout.BeginHorizontal();
                        {
                            GUILayout.Label("Selected:", GUILayout.Width(100));
                            if (Selection.activeObject != null)
                            {
                                if (Selection.activeObject.GetType() == typeof(GameObject))
                                {
                                    GameObject selectedObject = (GameObject)Selection.activeObject;
                                    if (selectedObject.scene != null)
                                    {
                                        GUILayout.Label("X", GUILayout.Width(coordLabelWidth));
                                        GUILayout.Label((selectedObject.transform.position.x + currentPos.x).ToString(), GUILayout.Width(coordInputWidth));
                                        GUILayout.FlexibleSpace();
                                        GUILayout.Label("Y", GUILayout.Width(coordLabelWidth));
                                        GUILayout.Label((selectedObject.transform.position.y + currentPos.y).ToString(), GUILayout.Width(coordInputWidth));
                                        GUILayout.FlexibleSpace();
                                        GUILayout.Label("Z", GUILayout.Width(coordLabelWidth));
                                        GUILayout.Label((selectedObject.transform.position.z + currentPos.z).ToString(), GUILayout.Width(coordInputWidth));
                                        GUI.enabled = !Application.isPlaying;
                                        if (GUILayout.Button("Center", GUILayout.Height(15)))
                                        {
                                            currentPos = new Vector3Double(selectedObject.transform.position.x + currentPos.x, selectedObject.transform.position.y + currentPos.y, selectedObject.transform.position.z + currentPos.z);
                                            bool needsShift = true;

                                            //Check if we should shift the selected object around as well
                                            if (selectedObject.scene != SessionManager.gameObject.scene)
                                            {
                                                //in a separate scene from session manager -> should be shifted automatically
                                                needsShift = false;
                                            }

                                            if (needsShift && selectedObject.transform.GetComponentInParent <Terrain>() != null)
                                            {
                                                //child of a terrain -> should be shifted automatically
                                                needsShift = false;
                                            }

                                            if (needsShift && selectedObject.transform.GetComponentInParent <FloatingPointFixMember>() != null)
                                            {
                                                //is child of a floating point fix member -> should be shifted automatically
                                                needsShift = false;
                                            }

                                            if (needsShift)
                                            {
                                                //still needs to be shifted -> ask the user if they wish to add a floating point fix
                                                if (EditorUtility.DisplayDialog("Shift centered object?", "You are about to center on an object that does not seem to be set up to be shifted together with the world origin. Do you want to add a Floating Point Fix Member component on this object so that it will be shifted with the world, or do you want the object not to be affected by the shift?", "Add component", "Leave object in place"))
                                                {
                                                    selectedObject.AddComponent <FloatingPointFixMember>();
                                                }
                                            }
                                        }
                                        GUI.enabled = currentGUIState;
                                    }
                                }
                            }
                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        {
                            GUI.enabled = !Application.isPlaying;
                            GUILayout.Label("Origin:", GUILayout.Width(100));
                            GUILayout.Label("X", GUILayout.Width(coordLabelWidth));
                            currentPos.x = EditorGUILayout.DelayedDoubleField(currentPos.x, GUILayout.Width(coordInputWidth));
                            GUILayout.FlexibleSpace();
                            GUILayout.Label("Y", GUILayout.Width(coordLabelWidth));
                            currentPos.y = EditorGUILayout.DelayedDoubleField(currentPos.y, GUILayout.Width(coordInputWidth));
                            GUILayout.FlexibleSpace();
                            GUILayout.Label("Z", GUILayout.Width(coordLabelWidth));
                            currentPos.z = EditorGUILayout.DelayedDoubleField(currentPos.z, GUILayout.Width(coordInputWidth));
                            GUILayout.Space(56);
                            GUI.enabled = currentGUIState;
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        GUI.enabled = !Application.isPlaying;
                        {
                            GUILayout.Label("Loading Range:", GUILayout.Width(115));
                            range = EditorGUILayout.DelayedDoubleField(range, GUILayout.Width(60));
                            GUILayout.Space(25);
                            SessionManager.m_showOriginLoadingBounds = EditorGUILayout.Toggle("Show Loading Range", SessionManager.m_showOriginLoadingBounds);
                        }
                        GUI.enabled = currentGUIState;
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        {
                            if (GUILayout.Button("Show Loader Manager...", GUILayout.Height(15), GUILayout.Width(180)))
                            {
                                GameObject loaderObj = GaiaUtils.GetTerrainLoaderManagerObject();
                                Selection.activeObject = loaderObj;
                            }
                            GUILayout.Space(25);
                            SessionManager.m_showOriginTerrainBoxes = EditorGUILayout.Toggle("Show Terrain Boxes", SessionManager.m_showOriginTerrainBoxes);
                        }

                        EditorGUILayout.EndHorizontal();
                    }
                    //else
                    //{
                    //    GUILayout.Space(Camera.current.pixelRect.size.x / 2f + 188);
                    //}
                }
                EditorGUILayout.EndVertical();
                GUIContent buttonContent = null;

                if (EditorGUIUtility.isProSkin)
                {
                    if (SessionManager.m_showSceneViewPanel)
                    {
                        buttonContent = new GUIContent(GaiaSettings.m_originUIProUnfoldUp, "Hide Gaia Panel");
                    }
                    else
                    {
                        buttonContent = new GUIContent(GaiaSettings.m_originUIProUnfoldDown, "Show Gaia Panel");
                    }
                }
                else
                {
                    if (SessionManager.m_showSceneViewPanel)
                    {
                        buttonContent = new GUIContent(GaiaSettings.m_originUIUnfoldUp, "Hide Gaia Panel");
                    }
                    else
                    {
                        buttonContent = new GUIContent(GaiaSettings.m_originUIUnfoldDown, "Show Gaia Panel");
                    }
                }
                if (GUILayout.Button(new GUIContent(buttonContent), GUIStylePanel, GUILayout.Width(20), GUILayout.Height(20)))
                {
                    SessionManager.m_showSceneViewPanel = !SessionManager.m_showSceneViewPanel;
                }
                GUILayout.FlexibleSpace();
            }
            EditorGUILayout.EndHorizontal();
#else
                }