Exemple #1
0
        /// Transform a subset of a array of Vector4 elements as z distances.
        /// Pass:
        ///   m        - the transform to apply.
        ///   iVert    - start of verts to transform
        ///   iVertEnd - end (not inclusive) of verts to transform
        ///   v4       - the array of vectors to transform
        public static void TransformVector4AsZDistance(float scale, int iVert, int iVertEnd,
                                                       Vector4[] v4)
        {
#if USE_TILT_BRUSH_CPP
            unsafe
            {
                fixed(Vector4 *v4Fixed = v4)
                {
                    TiltBrushCpp.TransformVector4AsZDistance(scale, iVert, iVertEnd, v4Fixed);
                }
            }
#else
            for (int i = iVert; i < iVertEnd; i++)
            {
                v4[i] = new Vector4(v4[i].x, v4[i].y, scale * v4[i].z, v4[i].w);
            }
#endif
        }
Exemple #2
0
        /// Transform a subset of an array of Vector3 elements as z distances.
        /// Pass:
        ///   m        - the transform to apply.
        ///   iVert    - start of verts to transform
        ///   iVertEnd - end (not inclusive) of verts to transform
        ///   v3       - the array of vectors to transform
        public static void TransformVector3AsZDistance(float scale, int iVert, int iVertEnd,
                                                       Vector3[] v3)
        {
#if USE_TILT_BRUSH_CPP
            unsafe
            {
                fixed(Vector3 *v3Fixed = v3)
                {
                    TiltBrushCpp.TransformVector3AsZDistance(scale, iVert, iVertEnd, v3Fixed);
                }
            }
#else
            for (int i = iVert; i < iVertEnd; i++)
            {
                v3[i] = new Vector3(v3[i].x, v3[i].y, scale * v3[i].z);
            }
#endif
        }
Exemple #3
0
        /// Transform a subset of an array of Vector3 elements as vectors.
        /// Pass:
        ///   m        - the transform to apply.
        ///   iVert    - start of verts to transform
        ///   iVertEnd - end (not inclusive) of verts to transform
        ///   v3       - the array of vectors to transform
        public static void TransformVector3AsVector(Matrix4x4 mat, int iVert, int iVertEnd,
                                                    Vector3[] v3)
        {
#if USE_TILT_BRUSH_CPP
            unsafe
            {
                fixed(Vector3 *v3Fixed = v3)
                {
                    TiltBrushCpp.TransformVector3AsVector(mat, iVert, iVertEnd, v3Fixed);
                }
            }
#else
            for (int i = iVert; i < iVertEnd; i++)
            {
                v3[i] = mat.MultiplyVector(v3[i]);
            }
#endif
        }
Exemple #4
0
        /// Transform a subset of a array of Vector4 elements as vectors.
        /// Pass:
        ///   m        - the transform to apply.
        ///   iVert    - start of verts to transform
        ///   iVertEnd - end (not inclusive) of verts to transform
        ///   v4       - the array of vectors to transform
        public static void TransformVector4AsVector(Matrix4x4 mat, int iVert, int iVertEnd,
                                                    Vector4[] v4)
        {
#if USE_TILT_BRUSH_CPP
            unsafe
            {
                fixed(Vector4 *v4Fixed = v4)
                {
                    TiltBrushCpp.TransformVector4AsVector(mat, iVert, iVertEnd, v4Fixed);
                }
            }
#else
            for (int i = iVert; i < iVertEnd; i++)
            {
                Vector3 vNew = mat.MultiplyVector(new Vector3(v4[i].x, v4[i].y, v4[i].z));
                v4[i] = new Vector4(vNew.x, vNew.y, vNew.z, v4[i].w);
            }
#endif
        }
Exemple #5
0
        /// Get the bounds for a transformed subset of an array of Vector3 point elements.
        /// Pass:
        ///   mat      - the transform to apply.
        ///   iVert    - start of verts to transform
        ///   iVertEnd - end (not inclusive) of verts to transform
        ///   v3       - the array of vectors to transform
        /// Output:
        ///   center   - the center of the bounds.
        ///   size     - the size of the bounds.
        public static void GetBoundsFor(Matrix4x4 mat, int iVert, int iVertEnd, Vector3[] v3,
                                        out Vector3 center, out Vector3 size)
        {
#if USE_TILT_BRUSH_CPP
            center = new Vector3();
            size   = new Vector3();
            unsafe
            {
                fixed(Vector3 *v3Fixed = v3)
                fixed(Vector3 * centerPtr = &center)
                fixed(Vector3 * sizePtr   = &size)
                {
                    TiltBrushCpp.GetBoundsFor(mat, iVert, iVertEnd, v3Fixed,
                                              centerPtr, sizePtr);
                }
            }
#else
            Vector3[] transformedVert;
            if (mat == Matrix4x4.identity)
            {
                transformedVert = v3;
            }
            else
            {
                transformedVert = new Vector3[v3.Length];
                v3.CopyTo(transformedVert, 0);
                MathUtils.TransformVector3AsPoint(mat, iVert, iVertEnd,
                                                  transformedVert);
            }

            // We use floats here instead of Vector3 because it saves 8% of the time in this function.
            float minX = transformedVert[iVert].x;
            float maxX = minX;
            float minY = transformedVert[iVert].y;
            float maxY = minY;
            float minZ = transformedVert[iVert].z;
            float maxZ = minZ;
            for (int i = iVert + 1; i < iVertEnd; ++i)
            {
                if (minX > transformedVert[i].x)
                {
                    minX = transformedVert[i].x;
                }
                else if (maxX < transformedVert[i].x)
                {
                    maxX = transformedVert[i].x;
                }
                if (minY > transformedVert[i].y)
                {
                    minY = transformedVert[i].y;
                }
                else if (maxY < transformedVert[i].y)
                {
                    maxY = transformedVert[i].y;
                }
                if (minZ > transformedVert[i].z)
                {
                    minZ = transformedVert[i].z;
                }
                else if (maxZ < transformedVert[i].z)
                {
                    maxZ = transformedVert[i].z;
                }
            }

            center = new Vector3(0.5f * (minX + maxX),
                                 0.5f * (minY + maxY),
                                 0.5f * (minZ + maxZ));
            size = new Vector3(maxX - minX,
                               maxY - minY,
                               maxZ - minZ);
#endif
        }