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 }
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 }
public bool LoadBVH(MeshFilter mesh, ref BVHHandle bvhHandle) { IntPtr[] handle = new IntPtr[1]; #if DDR_RUNTIME_DLL_LINKING_ int err = Invoke <int, _LoadBVH>(mesh.GetUniqueId(), handle); #else int err = _LoadBVH(mesh.GetUniqueId(), handle); #endif bvhHandle = new BVHHandle(mesh, handle[0], this); if (err != 0) { string error = GetLastError(); VertexBakerLib.LogError(error); return(false); } return(true); }
public bool IsValidBVH(MeshFilter mesh) { IntPtr matDataPtr = Alloc(16 * SIZE_FLOAT); float[] matArr = new float[16]; int matIndex = 0; AssignMat4(ref matArr, mesh.transform.localToWorldMatrix, ref matIndex); // 64 bytes Marshal.Copy(matArr, 0, matDataPtr, 16); #if DDR_RUNTIME_DLL_LINKING_ bool ret = Invoke <bool, _IsValidBVH>(mesh.GetUniqueId(), matDataPtr); #else bool ret = _IsValidBVH(mesh.GetUniqueId(), matDataPtr); #endif Free(matDataPtr); return(ret); }
public string GetBVHBoundingBoxList(MeshFilter mesh, ref Vector3[] center, ref Vector3[] size) { #if DDR_RUNTIME_DLL_LINKING_ string msg = Marshal.PtrToStringAnsi(Invoke <IntPtr, _GetBVHBoundingBoxList>(mesh.GetUniqueId(), center, size)); #else string msg = Marshal.PtrToStringAnsi(_GetBVHBoundingBoxList(mesh.GetUniqueId(), ref center, ref size)); #endif return(msg); }
public void RefreshVisuals(DaydreamVertexLighting source) { s_bvhWrapper.UnLoad(); s_cacheWrapper.UnLoad(); MeshFilter meshFilter = source.GetComponent <MeshFilter>(); string filepath = BVH.ConvertMeshIdToBVHPath(meshFilter.GetUniqueId()); s_bvhWrapper.SetPath(filepath); s_bvhWrapper.Validate(); s_cacheWrapper.SetPath(filepath); s_cacheWrapper.Validate(); }