Exemple #1
0
        public static bool RayIntersectToMesh(int *triangles, int triangleCount, MeshAppdata *appdatas, float3 origin, float3 dir, float4x4 *transformMatrix, out RayIntersectResult result)
        {
            NativeList <RayIntersectResult> allResults = new NativeList <RayIntersectResult>(triangleCount, Allocator.Temp);
            RayIntersectJob jb = new RayIntersectJob
            {
                appdatas        = appdatas,
                dir             = dir,
                origin          = origin,
                results         = allResults,
                triangles       = triangles,
                transformMatrix = transformMatrix
            };

            jb.Schedule(triangleCount, max(1, triangleCount / 10)).Complete();
            if (allResults.Length <= 0)
            {
                result = new RayIntersectResult();
                return(false);
            }
            float minT  = allResults[0].t;
            int   index = 0;

            for (int i = 1; i < allResults.Length; ++i)
            {
                if (minT > allResults[i].t)
                {
                    index = i;
                }
            }
            result = allResults[index];
            return(true);
        }
Exemple #2
0
        public static NativeList <RayIntersectResult> RayIntersectToMesh(int *triangles, int triangleCount, MeshAppdata *appdatas, float3 origin, float3 dir, float4x4 *transformMatrix, Allocator alloc)
        {
            NativeList <RayIntersectResult> allResults = new NativeList <RayIntersectResult>(triangleCount, alloc);
            RayIntersectJob jb = new RayIntersectJob
            {
                appdatas        = appdatas,
                dir             = dir,
                origin          = origin,
                results         = allResults,
                triangles       = triangles,
                transformMatrix = transformMatrix
            };

            jb.Schedule(triangleCount, max(1, triangleCount / 10)).Complete();
            return(allResults);
        }