示例#1
0
 // DO NOT USE THIS IN CODE!!!
 public void OnMeshTreeBuildFinished(EditorMesh editorMesh, bool completedOnSeparateThread)
 {
     if (editorMesh != null && MeshTreeBuildFinished != null)
     {
         MeshTreeBuildFinished(editorMesh, completedOnSeparateThread);
     }
 }
        /// <summary>
        /// Registers the specified object with the tree.
        /// </summary>
        private bool RegisterGameObject(GameObject gameObject)
        {
            if (!CanGameObjectBeRegisteredWithTree(gameObject))
            {
                return(false);
            }

            // Build the object's sphere
            Box      objectWorldBox = gameObject.GetWorldBox();
            Sphere3D objectSphere   = objectWorldBox.GetEncapsulatingSphere();

            // Add the object as a terminal node. Also store the node in the dictionary so that we can
            // use it when it's needed.
            SphereTreeNode <GameObject> objectNode = _sphereTree.AddTerminalNode(objectSphere, gameObject);

            _gameObjectToNode.Add(gameObject, objectNode);

            #if !USE_TRANSFORM_HAS_CHANGED
            _gameObjectToTransformData.Add(gameObject, GetGameObjectTransformData(gameObject));
            #endif

            // If it is a mesh object, start silent building the mesh
            if (gameObject.HasMesh())
            {
                EditorMesh editorMesh = EditorMeshDatabase.Instance.CreateEditorMesh(gameObject.GetMesh());
                if (editorMesh != null)
                {
                    EditorMeshDatabase.Instance.AddMeshToSilentBuild(editorMesh);
                }
            }

            EditorCamera.Instance.AdjustObjectVisibility(gameObject);
            return(true);
        }
示例#3
0
        public bool AddMeshToSilentBuild(EditorMesh editorMesh)
        {
            if (RuntimeEditorApplication.Instance.UseUnityColliders)
            {
                return(false);
            }
            if (!Contains(editorMesh.Mesh) || IsMeshSilentBuilding(editorMesh))
            {
                return(false);
            }

            _sortedSilentBuildCandidates.Add(editorMesh);
            _sortedSilentBuildCandidates.Sort(delegate(EditorMesh mesh0, EditorMesh mesh1)
            {
                if (mesh0.NumberOfTriangles < mesh1.NumberOfTriangles)
                {
                    return(1);
                }
                if (mesh1.NumberOfTriangles < mesh0.NumberOfTriangles)
                {
                    return(-1);
                }
                return(0);
            });

            return(true);
        }
示例#4
0
        private IEnumerator DoEditorMeshSilentBuild()
        {
            while (true)
            {
                // Only proceed if Unity coliders are not being used
                if (!RuntimeEditorApplication.Instance.UseUnityColliders)
                {
                    if (_silentBuildMeshes.Count < _maxNumberOfSilentBuildMeshes)
                    {
                        while (_silentBuildMeshes.Count < _maxNumberOfSilentBuildMeshes && _sortedSilentBuildCandidates.Count != 0)
                        {
                            EditorMesh editorMesh = _sortedSilentBuildCandidates[0];
                            _silentBuildMeshes.Add(editorMesh);
                            editorMesh.StartSilentTreeBuild();

                            _sortedSilentBuildCandidates.RemoveAt(0);
                        }
                    }

                    _silentBuildMeshes.RemoveAll(item => !item.IsBuildingTreeSilent);
                }

                yield return(null);
            }
        }
示例#5
0
        public List <EditorMesh> CreateEditorMeshes(List <Mesh> meshes)
        {
            if (RuntimeEditorApplication.Instance.UseUnityColliders)
            {
                return(new List <EditorMesh>());
            }
            if (meshes == null || meshes.Count == 0)
            {
                return(new List <EditorMesh>());
            }

            var editorMeshes = new List <EditorMesh>(meshes.Count);

            foreach (var mesh in meshes)
            {
                EditorMesh editorMesh = CreateEditorMesh(mesh);
                if (editorMesh == null)
                {
                    continue;
                }

                editorMeshes.Add(editorMesh);
            }

            return(editorMeshes);
        }
示例#6
0
 public MeshSphereTree(EditorMesh editorMesh)
 {
     _editorMesh = editorMesh;
     _sphereTree = new SphereTree <MeshSphereTreeTriangle>(2);
     _buildJob   = new MeshSphereTreeBuildJob(_editorMesh.GetAllTriangles(), _sphereTree);
     _buildJob.ValidateTriangle       = new MeshSphereTreeBuildJob.TriangleValidation(IsTriangleValid);
     _buildJob.OnSilentBuildFinished += OnSilentBuildFinished;
 }
示例#7
0
        public void BuildAllMeshesInScene()
        {
            var allMeshFilters = GameObject.FindObjectsOfType <MeshFilter>();

            foreach (var meshFilter in allMeshFilters)
            {
                Mesh       mesh       = meshFilter.sharedMesh;
                EditorMesh editorMesh = CreateEditorMesh(mesh);
                if (editorMesh != null)
                {
                    editorMesh.Build();
                }
            }
        }
        public static bool RaycastMesh(this GameObject gameObject, Ray ray, out GameObjectRayHit objectRayHit)
        {
            objectRayHit = null;
            Mesh objectMesh = gameObject.GetMeshFromFilterOrSkinnedMeshRenderer();

            if (objectMesh == null)
            {
                return(false);
            }

            EditorMesh editorMesh = EditorMeshDatabase.Instance.GetEditorMesh(objectMesh);

            if (editorMesh != null)
            {
                MeshRayHit meshRayHit = editorMesh.Raycast(ray, gameObject.transform.GetWorldMatrix());
                if (meshRayHit == null)
                {
                    return(false);
                }

                objectRayHit = new GameObjectRayHit(ray, gameObject, null, meshRayHit, null, null);
                return(true);
            }
            else
            {
                MeshCollider meshCollider = gameObject.GetComponent <MeshCollider>();
                if (meshCollider != null)
                {
                    RaycastHit rayHit;
                    if (meshCollider.Raycast(ray, out rayHit, float.MaxValue))
                    {
                        MeshRayHit meshRayHit = new MeshRayHit(ray, rayHit.distance, rayHit.triangleIndex, rayHit.point, rayHit.normal);
                        objectRayHit = new GameObjectRayHit(ray, gameObject, null, meshRayHit, null, null);
                        return(true);
                    }
                }
                else
                {
                    return(gameObject.RaycastBox(ray, out objectRayHit));
                }
            }

            return(false);
        }
        public EditorMesh CreateEditorMesh(Mesh mesh)
        {
            if (!IsMeshValid(mesh))
            {
                return(null);
            }

            if (_meshes.ContainsKey(mesh))
            {
                return(null);
            }
            else
            {
                EditorMesh editorMesh = new EditorMesh(mesh);
                _meshes.Add(mesh, editorMesh);

                return(editorMesh);
            }
        }
        private IEnumerator DoEditorMeshSilentBuild()
        {
            while (true)
            {
                if (_silentBuildMeshes.Count < _maxNumberOfSilentBuildMeshes)
                {
                    while (_silentBuildMeshes.Count < _maxNumberOfSilentBuildMeshes && _sortedSilentBuildCandidates.Count != 0)
                    {
                        EditorMesh editorMesh = _sortedSilentBuildCandidates[0];
                        _silentBuildMeshes.Add(editorMesh);
                        editorMesh.StartSilentTreeBuild();

                        _sortedSilentBuildCandidates.RemoveAt(0);
                    }
                }

                _silentBuildMeshes.RemoveAll(item => !item.IsBuildingTreeSilent);
                yield return(null);
            }
        }
        public List <EditorMesh> CreateEditorMeshes(List <Mesh> meshes)
        {
            if (meshes == null || meshes.Count == 0)
            {
                return(new List <EditorMesh>());
            }

            var editorMeshes = new List <EditorMesh>(meshes.Count);

            foreach (var mesh in meshes)
            {
                EditorMesh editorMesh = CreateEditorMesh(mesh);
                if (editorMesh == null)
                {
                    continue;
                }

                editorMeshes.Add(editorMesh);
            }

            return(editorMeshes);
        }
示例#12
0
        public EditorMesh CreateEditorMesh(Mesh mesh)
        {
            if (RuntimeEditorApplication.Instance.UseUnityColliders)
            {
                return(null);
            }
            if (!IsMeshValid(mesh))
            {
                return(null);
            }

            if (_meshes.ContainsKey(mesh))
            {
                return(null);
            }
            else
            {
                EditorMesh editorMesh = new EditorMesh(mesh);
                _meshes.Add(mesh, editorMesh);

                return(editorMesh);
            }
        }
示例#13
0
 public bool IsMeshSilentBuilding(EditorMesh editorMesh)
 {
     return(_silentBuildMeshes.Contains(editorMesh) || _sortedSilentBuildCandidates.Contains(editorMesh));
 }
示例#14
0
 public MeshSphereTree(EditorMesh editorMesh)
 {
     _editorMesh = editorMesh;
     _sphereTree = new SphereTree <MeshSphereTreeTriangle>(2);
 }