Exemple #1
0
        private static Matrix4x4 CalculateSurfaceToWorldMatrix(int triangleIndex, Mesh mesh)
        {
            RawTriangle t       = mesh.GetRawTriangleByIndex(triangleIndex);
            Vector3     right   = (t.v2 - t.v1).normalized;
            Vector3     forward = Vector3.Cross(right, t.v3 - t.v1).normalized;
            Vector3     up      = Vector3.Cross(forward, right);

            var result = new Matrix4x4();

            result.SetColumn(0, right);
            result.SetColumn(1, up);
            result.SetColumn(2, forward);
            Vector3 p = t.v1;

            result.SetColumn(3, new Vector4(p.x, p.y, p.z, 1));

            return(result);
        }
Exemple #2
0
        public static BoundsOctree <int> GenerateOctree(this Mesh mesh)
        {
            var octree = new BoundsOctree <int>(64, Vector3.zero, 1, 1.25f);

            Func <int, Bounds> getTriangleBounds = (int index) => {
                RawTriangle t    = mesh.GetRawTriangleByIndex(index);
                Bounds      aabb = new Bounds(t.v1, Vector3.zero);
                aabb.Encapsulate(t.v2);
                aabb.Encapsulate(t.v3);

                return(aabb);
            };

            int triangleCount = mesh.GetSaneTriangles(0).Length;

            for (int i = 0; i < triangleCount; ++i)
            {
                octree.Add(i, getTriangleBounds(i));
            }

            return(octree);
        }