コード例 #1
0
 protected static void TryLoadBVH(MeshFilter meshFilter)
 {
     if (meshFilter != null && meshFilter.sharedMesh != null)
     {
         if (!VertexBakerLib.Instance.LoadBVH(meshFilter, ref s_bvhHandle))
         {
             // Load from scratch
             VertexBakerLib.Log("Could not load BVH data, building from scratch");
             VertexBakerLib.BVHHandle[] bvhHandles = new VertexBakerLib.BVHHandle[1];
             // build BVH and get handle
             VertexBakerLib.Instance.BuildBVH(new MeshFilter[] { meshFilter }, ref bvhHandles);
             // make sure its good
             if (bvhHandles != null && VertexBakerLib.Instance.ValidHandle(bvhHandles[0].Ptr()))
             {
                 s_bvhHandle = bvhHandles[0];
                 if (VertexBakerLib.s_logging == VertexBakerLib.Logging.kVerbose)
                 {
                     VertexBakerLib.Log("BVH build success!");
                 }
             }
             else
             {
                 s_bvhHandle = null;
                 VertexBakerLib.LogError("Invalid BVH Handle, BVH not built");
             }
         }
     }
 }
コード例 #2
0
        protected static void Init(MeshFilter meshFilter, Mesh untessellatedMesh)
        {
            if (!Directory.Exists(FBSConstants.BasePath + "/Cache/"))
            {
                Directory.CreateDirectory(FBSConstants.BasePath + "/Cache/");
            }
            if (!Directory.Exists(FBSConstants.BasePath + "/BVHCache/"))
            {
                Directory.CreateDirectory(FBSConstants.BasePath + "/BVHCache/");
            }

            if (meshFilter.sharedMesh == null)
            {
                Debug.LogWarning(meshFilter.gameObject.GetPath() + " is missing its source mesh");
                return;
            }
            s_debugState = BakeData.Instance().GetDebugState();

#if _DAYDREAM_STATIC_LIGHTING_DEBUG
            DateTime start = DateTime.Now;

            // if we still have a handle for some reason try to free it
            if (s_lastInstanceId != meshFilter.GetUniqueId())
            {
                if (s_bvhHandle != null)
                {
                    VertexBakerLib.Instance.FreeHandle(s_bvhHandle.Ptr());
                }
                s_bvhHandle = null;

                BuildWorldVertices(meshFilter);

                s_debugState.m_tessFaces = null;
            }

            TryLoadBVH(meshFilter);

            s_lastInstanceId = meshFilter.GetUniqueId();

            if (s_bvhWrapper == null)
            {
                s_bvhWrapper = new BVHNode_FBWrapper();
            }

            string sourceAssetPath = AssetDatabase.GetAssetPath(untessellatedMesh);
            if (!string.IsNullOrEmpty(sourceAssetPath) && !Application.isPlaying)
            {
                Debug.LogWarning("Could not find asset " + untessellatedMesh.name + " the asset may be an instance. Some debug data may not be available.");
            }

            string path = BVH.ConvertMeshIdToBVHPath(s_lastInstanceId);
            s_bvhWrapper.SetPath(path);
            s_bvhWrapper.Validate();

            s_cacheWrapper.SetPath("" + s_lastInstanceId);
            s_cacheWrapper.Validate();

            VertexBakerLib.Log("Debug setup time: " + (DateTime.Now - start).TotalSeconds + " seconds");
#endif
        }
コード例 #3
0
        protected static void Init(MeshFilter meshFilter)
        {
            if (meshFilter.sharedMesh == null)
            {
                Debug.LogWarning(meshFilter.gameObject.GetPath() + " is missing its mesh");
                return;
            }
            s_debugState = BakeData.Instance().GetDebugState();

#if _DAYDREAM_STATIC_LIGHTING_DEBUG
            // if we still have a handle for some reason try to free it
            if (s_lastInstanceId != meshFilter.GetUniqueId())
            {
                if (s_bvhHandle != null)
                {
                    VertexBakerLib.Instance.FreeHandle(s_bvhHandle.Ptr());
                }
                s_bvhHandle = null;

                BuildWorldVertices(meshFilter);
            }

            TryLoadBVH(meshFilter);

            s_lastInstanceId = meshFilter.GetUniqueId();

            if (s_bvhWrapper == null)
            {
                s_bvhWrapper = new BVHNode_FBWrapper();
            }
            string path = BVH.ConvertMeshIdToBVHPath(s_lastInstanceId);
            s_bvhWrapper.SetPath(path);
            s_bvhWrapper.Validate();

            string sourceAssetPath = AssetDatabase.GetAssetPath(meshFilter.sharedMesh);
            if (!string.IsNullOrEmpty(sourceAssetPath))
            {
                s_cacheWrapper.SetPath("" + s_lastInstanceId);
                s_cacheWrapper.Validate();
            }
            else if (!Application.isPlaying)
            {
                Debug.LogError("Could not find asset " + meshFilter.sharedMesh.name + " the asset may be an instance. Some debug data may not be available.");
            }
#endif
        }
コード例 #4
0
        public void TestLoadBVH(DaydreamVertexLighting source)
        {
            DateTime   start      = DateTime.Now;
            MeshFilter meshFilter = source.GetComponent <MeshFilter>();

            if (meshFilter != null)
            {
                try
                {
                    VertexBakerLib.BVHHandle bvhHandle = null;
                    if (VertexBakerLib.Instance.LoadBVH(meshFilter, ref bvhHandle))
                    {
                        VertexBakerLib.Instance.FreeHandle(bvhHandle.Ptr());
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError(e.Message + "\n" + e.StackTrace);
                }
            }

            VertexBakerLib.Log("Seconds to complete: " + (DateTime.Now - start).TotalSeconds);
        }
コード例 #5
0
 protected static void BuildTessFaces(VertexBakerLib.BVHHandle bvh, MeshFilter sourceMesh, Mesh bakeData)
 {
     VertexBakerLib.Instance.FindTessellationTriangles(bvh, sourceMesh, bakeData, out s_debugState.m_tessFaces);
 }