public int RebuildBVH(BVHHandle bvhHandle) { // build baker context m_baker.m_sourcePaths = new string[] { AssetDatabase.GetAssetPath(bvhHandle.SourceMeshData.sharedMesh) }; m_baker.m_guids = new string[] { "" + m_baker.m_meshes[0].GetUniqueId() }; m_baker.m_meshRenderers = new MeshRenderer[] { bvhHandle.SourceMeshData.GetComponent <MeshRenderer>() }; // parse data and fill in missing context BakeContext.BuildSceneContext(new MeshFilter[] { bvhHandle.SourceMeshData }, m_baker); #if DDR_RUNTIME_DLL_LINKING_ int err = Invoke <int, _RebuildBVH>(bvhHandle.Ptr(), m_baker.m_meshIdsPtr, m_baker.m_vertexCountsPtr, m_baker.m_triangleCountPtr , m_baker.m_matDataPtr, m_baker.m_meshDataPtr, m_baker.m_triangleDataPtr, m_baker.m_bakeOptionsPtr, 1, m_baker.m_guids, m_baker.m_sourcePaths); #else int err = _RebuildBVH(bvhHandle.Ptr(), m_baker.m_meshIdsPtr, m_baker.m_vertexCountsPtr, m_baker.m_triangleCountPtr , m_baker.m_matDataPtr, m_baker.m_meshDataPtr, m_baker.m_triangleDataPtr, m_baker.m_bakeOptionsPtr, 1, m_baker.m_guids, m_baker.m_sourcePaths); #endif m_baker.FreeContext(); if (err != 0) { string error = GetLastError(); VertexBakerLib.LogError(error); } return(err); }
public int TessellateTriangles(BVHHandle bvhHandle, Vector3 startPoint, Vector3 endPoint) { m_baker.m_sourcePaths = new string[] { AssetDatabase.GetAssetPath(bvhHandle.SourceMeshData.sharedMesh) }; m_baker.m_guids = new string[] { "" + m_baker.m_meshes[0].GetUniqueId() }; m_baker.m_meshRenderers = new MeshRenderer[] { bvhHandle.SourceMeshData.GetComponent <MeshRenderer>() }; List <MeshFilter> meshes = new List <MeshFilter>() { bvhHandle.SourceMeshData }; m_baker.InitBakeContext(meshes, null); BakeContext.IVertex vertexFormat = new BakeContext.DefaultVertex(); BakeContext.BuildSceneContext(m_baker.m_meshes.ToArray(), m_baker, vertexFormat); int[] outIndex = new int[1]; outIndex[0] = -1; #if DDR_RUNTIME_DLL_LINKING_ bool success = Invoke <bool, _TessellateTriangles>(bvhHandle.Ptr() , m_baker.m_meshIdsPtr , m_baker.m_vertexCountsPtr , m_baker.m_triangleCountPtr , vertexFormat.ElementCount , vertexFormat.Definition.ToArray() , m_baker.m_matDataPtr , m_baker.m_meshDataPtr , m_baker.m_triangleDataPtr , m_baker.m_bakeOptionsPtr , m_baker.m_guids , m_baker.m_sourcePaths , m_baker.m_settingsPtrs); #else bool success = _TessellateTriangles(bvhHandle.Ptr() , m_baker.m_meshIdsPtr , m_baker.m_vertexCountsPtr , m_baker.m_triangleCountPtr , vertexFormat.ElementCount , vertexFormat.Definition.ToArray() , m_baker.m_matDataPtr , m_baker.m_meshDataPtr , m_baker.m_triangleDataPtr , m_baker.m_bakeOptionsPtr , m_baker.m_guids , m_baker.m_sourcePaths , m_baker.m_settingsPtrs); #endif if (!success) { string error = GetLastError(); VertexBakerLib.LogError(error); } return(outIndex[0]); }
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 string BuildBVH(MeshFilter[] meshes, ref BVHHandle[] bvhHandles) { m_baker.m_guids = new string[meshes.Length]; m_baker.m_sourcePaths = new string[meshes.Length]; m_baker.m_meshRenderers = new MeshRenderer[meshes.Length]; for (int i = 0; i < meshes.Length; ++i) { m_baker.m_sourcePaths[i] = AssetDatabase.GetAssetPath(meshes[i].sharedMesh); m_baker.m_guids[i] = "" + meshes[i].GetUniqueId(); m_baker.m_meshRenderers[i] = meshes[i].GetComponent <MeshRenderer>(); } m_baker.m_meshCount = meshes.Length; BakeContext.BuildSceneContext(meshes, m_baker); IntPtr[] handles = new IntPtr[meshes.Length]; for (int i = 0; i < handles.Length; ++i) { handles[i] = IntPtr.Zero; } #if DDR_RUNTIME_DLL_LINKING_ string msg = Marshal.PtrToStringAnsi(Invoke <IntPtr, _BuildBVH>(m_baker.m_meshIdsPtr, m_baker.m_vertexCountsPtr, m_baker.m_triangleCountPtr, m_baker.m_matDataPtr , m_baker.m_meshDataPtr, m_baker.m_triangleDataPtr, m_baker.m_bakeOptionsPtr, m_baker.m_meshCount , m_baker.m_guids, m_baker.m_sourcePaths, m_baker.m_settingsIndicesPtr, m_baker.m_settingsPtrs, handles)); #else string msg = Marshal.PtrToStringAnsi(_BuildBVH(m_baker.m_meshIdsPtr, m_baker.m_vertexCountsPtr, m_baker.m_triangleCountPtr, m_baker.m_matDataPtr , m_baker.m_meshDataPtr, m_baker.m_triangleDataPtr, m_baker.m_bakeOptionsPtr, m_baker.m_meshCount , m_baker.m_guids, m_baker.m_sourcePaths, m_baker.m_settingsIndicesPtr, m_baker.m_settingsPtrs, handles)); #endif m_baker.FreeContext(); // output specialized handle bvhHandles = new BVHHandle[handles.Length]; for (int i = 0; i < handles.Length; ++i) { bvhHandles[i] = new BVHHandle(meshes[i], handles[i], this); } return(msg); }
public static GpuSmitsBVHNode[] CreateBVH(IEnumerable<TriangleDataInfo> triangles, IEnumerable<Point> vertices, uint treeType = 4u, int csamples = 4, int intersectionCost = 60, int traverseCost = 20, float emptyBonus = 20f) { var triData = new DLLx.TriangleData( triangles.Select(tri => new DLLx.TriInfo() { id = 0, v1 = (int)tri.v0.VertexIndex, v2 = (int)tri.v1.VertexIndex, v3 = (int)tri.v2.VertexIndex }).ToArray(), vertices.Select(v => new DLLx.VertInfo(v.x, v.y, v.z)).ToArray()); Tracer.TraceLine("Start building"); using (var bvhHandle = new BVHHandle(triData, treeType, csamples, intersectionCost, traverseCost, emptyBonus)) { var data = bvhHandle.GetData(); Tracer.TraceLine("Complete!"); return data. //Except(new[]{data.First()}). Select(item => new GpuSmitsBVHNode() { bbox = new AABBInfo(new Point(item.bbox.pMin.x, item.bbox.pMin.y, item.bbox.pMin.z), new Point(item.bbox.pMax.x, item.bbox.pMax.y, item.bbox.pMax.z)), primitive = item.primitive, skipIndex = item.skipIndex }).ToArray(); } }