Example #1
0
 public void SetSurfaceUV0(int descriptionIndex, UVMatrix uv0)
 {
     if (descriptionIndex < 0 || descriptionIndex >= surfaces.Length)
     {
         return;
     }
     surfaces[descriptionIndex].surfaceDescription.UV0 = uv0;
 }
Example #2
0
        public void Decompose(out Vector2 translation, out Vector3 normal, out float rotation, out Vector2 scale)
        {
            normal = planeNormal;
            var orientation     = Quaternion.LookRotation(normal);
            var inv_orientation = Quaternion.Inverse(orientation);

            var u = inv_orientation * (Vector3)U;
            var v = inv_orientation * (Vector3)V;

            rotation = -Vector3.SignedAngle(Vector3.right, u, Vector3.forward);

            const double min_rotate = 1.0 / 10000.0;

            rotation = (float)(Math.Round(rotation / min_rotate) * min_rotate);

            scale = new Vector2(u.magnitude, v.magnitude);

            const double min_scale = 1.0 / 10000.0;

            scale.x = (float)(Math.Round(scale.x / min_scale) * min_scale);
            scale.y = (float)(Math.Round(scale.y / min_scale) * min_scale);

            var rotation2d = Quaternion.AngleAxis(-rotation, Vector3.forward);

            translation = new Vector2(U.w, V.w);

            const double min_translation = 1.0 / 32768.0;

            translation.x = (float)(Math.Round(translation.x / min_translation) * min_translation);
            translation.y = (float)(Math.Round(translation.y / min_translation) * min_translation);


            // TODO: figure out a better way to find if we scale negatively
            var newUvMatrix = UVMatrix.TRS(translation, normal, rotation, scale);

            if (Vector3.Dot(V, newUvMatrix.V) < 0)
            {
                scale.y = -scale.y;
            }
            if (Vector3.Dot(U, newUvMatrix.U) < 0)
            {
                scale.x = -scale.x;
            }
        }
Example #3
0
        public void Decompose(out Vector2 translation, out float rotation, out Vector2 scale)
        {
            translation = new Vector2(U.w, V.w);

            const double min_translation = 1.0 / 32768.0;

            translation.x = (float)(math.round(translation.x / min_translation) * min_translation);
            translation.y = (float)(math.round(translation.y / min_translation) * min_translation);

            var matrix = ToFloat4x4();

            var q   = new quaternion(math.transpose((float3x3)matrix));
            var q_i = math.inverse(q);
            var q_u = ((UnityEngine.Quaternion)q_i);

            rotation = q_u.eulerAngles[2];

            const double min_rotate = 1.0 / 10000.0;

            rotation = (float)(Math.Round(rotation / min_rotate) * min_rotate);

            var uScale = math.length(math.mul(q, matrix.c0.xyz));
            var vScale = math.length(math.mul(q, matrix.c1.xyz));

            scale = new float2(uScale, vScale);

            scale.x = (float)(math.round(scale.x / kScaleStep) * kScaleStep);
            scale.y = (float)(math.round(scale.y / kScaleStep) * kScaleStep);

            scale.x = (float)math.max(math.abs(scale.x), kMinScale) * Math.Sign(scale.x);
            scale.y = (float)math.max(math.abs(scale.y), kMinScale) * Math.Sign(scale.y);

            var newUvMatrix = UVMatrix.TRS(translation, rotation, scale);

            if (math.dot((Vector3)V, (Vector3)newUvMatrix.V) < 0)
            {
                scale.y = -scale.y;
            }
            if (math.dot((Vector3)U, (Vector3)newUvMatrix.U) < 0)
            {
                scale.x = -scale.x;
            }
        }
Example #4
0
        public void Decompose(out Vector2 translation, out float rotation, out Vector2 scale)
        {
            var normal = new float3(0, 0, 1);

            var u = (Vector3)U;
            var v = (Vector3)V;

            if (Math.Abs(u.x) < kSnapEpsilon)
            {
                u.x = 0;
            }
            if (Math.Abs(u.y) < kSnapEpsilon)
            {
                u.y = 0;
            }
            if (Math.Abs(u.z) < kSnapEpsilon)
            {
                u.z = 0;
            }

            if (Math.Abs(v.x) < kSnapEpsilon)
            {
                v.x = 0;
            }
            if (Math.Abs(v.y) < kSnapEpsilon)
            {
                v.y = 0;
            }
            if (Math.Abs(v.z) < kSnapEpsilon)
            {
                v.z = 0;
            }

            //var inverted = Vector3.Cross(U, V).z < 0.0f;

            var rotationU = -Vector3.SignedAngle(Vector3.right, u, normal);
            var rotationV = -Vector3.SignedAngle(Vector3.up, v, normal);


            rotation = Math.Abs(rotationU) < Math.Abs(rotationV) ? rotationU : rotationV;

            const double min_rotate = 1.0 / 10000.0;

            rotation = (float)(Math.Round(rotation / min_rotate) * min_rotate);

            var rotation2d = Quaternion.AngleAxis(rotation, normal);
            var invRotate  = Quaternion.Inverse(rotation2d);

            u = (invRotate * U).normalized;
            v = (invRotate * V).normalized;

            var udir = Vector3.right;
            var vdir = Vector3.up;

            var uScale = Vector3.Dot(udir, u);
            var vScale = Vector3.Dot(vdir, v);

            scale = new Vector2(uScale, vScale);

            scale.x = (float)(Math.Round(scale.x / kScaleStep) * kScaleStep);
            scale.y = (float)(Math.Round(scale.y / kScaleStep) * kScaleStep);

            scale.x = (float)Math.Max(Math.Abs(scale.x), kMinScale) * Math.Sign(scale.x);
            scale.y = (float)Math.Max(Math.Abs(scale.y), kMinScale) * Math.Sign(scale.y);


            //var rotation2d  = Quaternion.AngleAxis(-rotation, Vector3.forward);
            translation = new Vector2(U.w, V.w);

            const double min_translation = 1.0 / 32768.0;

            translation.x = (float)(Math.Round(translation.x / min_translation) * min_translation);
            translation.y = (float)(Math.Round(translation.y / min_translation) * min_translation);


            // TODO: figure out a better way to find if we scale negatively
            var newUvMatrix = UVMatrix.TRS(translation, rotation, scale);

            if (Vector3.Dot((Vector3)V, (Vector3)newUvMatrix.V) < 0)
            {
                scale.y = -scale.y;
            }
            if (Vector3.Dot((Vector3)U, (Vector3)newUvMatrix.U) < 0)
            {
                scale.x = -scale.x;
            }
        }