Ejemplo n.º 1
0
        public void TransfromtoLocal_ChildObjectTransform_LocalTransform()
        {
            GameObject parent = new GameObject();

            parent.transform.position = new Vector3(1, 1, 1);
            GameObject child = new GameObject();

            child.transform.parent        = parent.transform;
            child.transform.localPosition = new Vector3(.2f, .3f, .5f);
            child.transform.localRotation = new Quaternion(.3f, .4f, .5f, 1);

            var testMsg     = child.transform.ToLocal <FLU>();
            var fluPosition = child.transform.localPosition.To <FLU>();
            var fluRotation = child.transform.localRotation.To <FLU>();

            Assert.IsNotNull(testMsg);
            Assert.AreApproximatelyEqual(fluPosition.x, (float)testMsg.translation.x);
            Assert.AreApproximatelyEqual(fluPosition.y, (float)testMsg.translation.y);
            Assert.AreApproximatelyEqual(fluPosition.z, (float)testMsg.translation.z);
            Assert.AreApproximatelyEqual(fluRotation.x, (float)testMsg.rotation.x);
            Assert.AreApproximatelyEqual(fluRotation.y, (float)testMsg.rotation.y);
            Assert.AreApproximatelyEqual(fluRotation.z, (float)testMsg.rotation.z);
            Assert.AreApproximatelyEqual(fluRotation.w, (float)testMsg.rotation.w);

            Object.DestroyImmediate(parent);
        }
Ejemplo n.º 2
0
        public IEnumerator BBoxHandlerUI()
        {
            const int numSteps = 2;
            var       bbox     = InstantiateSceneAndDefaultBbox();

            bbox.ShowRotationHandleForX = true;
            bbox.ShowRotationHandleForY = true;
            bbox.ShowRotationHandleForZ = true;
            bbox.ShowScaleHandles       = true;
            bbox.ProximityEffectActive  = true;
            bbox.ScaleHandleSize        = 0.1f;
            bbox.RotationHandleSize     = 0.1f;
            bbox.FarScale    = 1.0f;
            bbox.MediumScale = 1.5f;
            bbox.CloseScale  = 1.5f;
            yield return(null);

            var bounds = bbox.GetComponent <BoxCollider>().bounds;

            Assert.AreEqual(new Vector3(0, 0, 1.5f), bounds.center);
            Assert.AreEqual(new Vector3(.5f, .5f, .5f), bounds.size);

            // Defining the edge and corner handlers that will be used
            Debug.Log(bbox.transform.Find("rigRoot/midpoint_0").GetChild(0));
            var originalCornerHandlerScale = bbox.transform.Find("rigRoot/corner_1/visualsScale/visuals").transform.localScale;
            var cornerHandlerPosition      = bbox.transform.Find("rigRoot/corner_1").transform.position;
            var originalEdgeHandlerScale   = bbox.transform.Find("rigRoot/midpoint_0/Sphere").transform.localScale;
            var edgeHandlerPosition        = bbox.transform.Find("rigRoot/midpoint_0").transform.position;

            // Wait for the scaling/unscaling animation to finish
            yield return(new WaitForSeconds(0.2f));

            // Move the hand to a handler on the corner
            TestHand rightHand = new TestHand(Handedness.Right);

            yield return(rightHand.Show(new Vector3(0, 0, 0.5f)));

            yield return(rightHand.MoveTo(cornerHandlerPosition, numSteps));

            // Wait for the scaling/unscaling animation to finish
            yield return(new WaitForSeconds(0.4f));

            TestUtilities.AssertAboutEqual(bbox.transform.Find("rigRoot/midpoint_0/Sphere").transform.localScale, originalEdgeHandlerScale, "The edge handler changed mistakingly");
            TestUtilities.AssertAboutEqual(bbox.transform.Find("rigRoot/corner_1/visualsScale/visuals").transform.localScale.normalized, originalCornerHandlerScale.normalized, "The corner handler scale has changed");
            Assert.AreApproximatelyEqual(bbox.transform.Find("rigRoot/corner_1/visualsScale/visuals").transform.localScale.x / originalCornerHandlerScale.x, bbox.MediumScale, 0.1f, "The corner handler did not grow when a pointer was near it");

            // Move the hand to a handler on the edge
            yield return(rightHand.MoveTo(edgeHandlerPosition, numSteps));

            // Wait for the scaling/unscaling animation to finish
            yield return(new WaitForSeconds(0.4f));

            TestUtilities.AssertAboutEqual(bbox.transform.Find("rigRoot/corner_1/visualsScale/visuals").transform.localScale, originalCornerHandlerScale, "The corner handler changed mistakingly");
            TestUtilities.AssertAboutEqual(bbox.transform.Find("rigRoot/midpoint_0/Sphere").transform.localScale.normalized, originalEdgeHandlerScale.normalized, "The edge handler scale has changed");
            Assert.AreApproximatelyEqual(bbox.transform.Find("rigRoot/midpoint_0/Sphere").transform.localScale.x / originalEdgeHandlerScale.x, bbox.MediumScale, 0.1f, "The edge handler did not grow when a pointer was near it");

            Object.Destroy(bbox.gameObject);
            // Wait for a frame to give Unity a change to actually destroy the object
            yield return(null);
        }
Ejemplo n.º 3
0
        public IEnumerator Incremental([Range(0.0f, 360.0f, 15.0f)] float angle)
        {
            using (var texture = new MonochromeTexture("Maskox/Linear"))
            {
                texture.Material.SetFloat("_Maskox_Angle", angle);

                yield return(texture.Initialize());

                yield return(texture.Update());

                var radian = angle * Mathf.Deg2Rad;

                var direction = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.right;
                UnityAssert.AreEqual(0.0f, direction.z);
                UnityAssert.AreApproximatelyEqual(1.0f, direction.magnitude);

                var center  = new Vector2(0.5f, 0.5f);
                var extents = new Vector2(direction.x * 0.5f, direction.y * 0.5f);
                var start   = center - extents;
                var end     = center + extents;

                UnityAssert.AreApproximatelyEqual(0.5f, texture[0.5f, 0.5f], 1.0f / 256.0f);

                texture.AssertIncremental(start, end);
            }
        }
Ejemplo n.º 4
0
        public void TestSolve2d()
        {
            float3 up = new float3(0, 1, 0);

            SurfaceConstraintInfo plane1 = CreateConstraint(ColliderKey.Empty, float3.zero, new float3(0, 1, 0), 1, 0, 0, false, float3.zero);
            SurfaceConstraintInfo plane2 = CreateConstraint(ColliderKey.Empty, float3.zero, new float3(0, -1, 0), 1, 0, 0, false, float3.zero);
            SurfaceConstraintInfo plane3 = CreateConstraint(ColliderKey.Empty, float3.zero, new float3(1, 0, 0), 1, 0, 0, false, float3.zero);
            SurfaceConstraintInfo plane4 = CreateConstraint(ColliderKey.Empty, float3.zero, math.normalize(new float3(1.0f, 1.0f, 0)), 1, 0, 0, false, float3.zero);
            SurfaceConstraintInfo plane5 = CreateConstraint(ColliderKey.Empty, float3.zero, math.normalize(new float3(-1.0f, 1.0f, 0)), 1, 0, 0, false, float3.zero);

            // Test the parallel planes scenario
            float3 velocity = new float3(0, -1, 0);

            Solve2d(up, plane1, plane2, ref velocity);
            Assert.AreApproximatelyEqual(velocity.x, 0);
            Assert.AreApproximatelyEqual(velocity.y, 0);
            Assert.AreApproximatelyEqual(velocity.z, 0);

            // Test the not-parallel planes scenario
            velocity = new float3(0, -1, 0);
            Solve2d(up, plane1, plane3, ref velocity);
            Assert.AreApproximatelyEqual(velocity.x, 0);
            Assert.AreApproximatelyEqual(velocity.y, 0);
            Assert.AreApproximatelyEqual(velocity.z, 0);

            // A little more complicated scenario
            velocity = new float3(0, -1, 0);
            Solve2d(up, plane4, plane5, ref velocity);
            Assert.AreApproximatelyEqual(velocity.x, 0);
            Assert.AreApproximatelyEqual(velocity.y, 0);
            Assert.AreApproximatelyEqual(velocity.z, 0);

            // Introduce plane velocities
            plane4.Velocity = new float3(0, 1, 0);
            plane5.Velocity = new float3(0, 1, 0);
            velocity        = new float3(0, -1, 0);
            Solve2d(up, plane4, plane5, ref velocity);
            Assert.AreApproximatelyEqual(velocity.x, 0);
            Assert.AreApproximatelyEqual(velocity.y, 1);
            Assert.AreApproximatelyEqual(velocity.z, 0);

            // Case where one plane drifts away
            plane4.Velocity = new float3(0, 1, 0);
            plane5.Velocity = new float3(0, -1, 0);
            velocity        = new float3(0, -1, 0);
            Solve2d(up, plane4, plane5, ref velocity);
            Assert.AreApproximatelyEqual(velocity.x, 1.0f);
            Assert.AreApproximatelyEqual(velocity.y, 0);
            Assert.AreApproximatelyEqual(velocity.z, 0);

            // Case where both planes drift to the side
            plane4.Velocity = new float3(-1, 0, 0);
            plane5.Velocity = new float3(1, 0, 0);
            velocity        = new float3(0, -1, 0);
            Solve2d(up, plane4, plane5, ref velocity);
            Assert.AreApproximatelyEqual(velocity.x, 0);
            Assert.AreApproximatelyEqual(velocity.y, -1);
            Assert.AreApproximatelyEqual(velocity.z, 0);
        }
Ejemplo n.º 5
0
        public void JacobianUtilitiesCalculateErrorTest()
        {
            float x   = 5.0f;
            float min = 0.0f;
            float max = 10.0f;

            Assert.AreApproximatelyEqual(0.0f, JacobianUtilities.CalculateError(x, min, max));
        }
Ejemplo n.º 6
0
        public void EdgeLength_from_Vector3_has_equal_component_values()
        {
            var vector     = new Vector3(10f, 20f, 30f);
            var edgeLength = EdgeLength.FromUnityVector(vector);

            Assert.AreApproximatelyEqual((float)edgeLength.X, vector.x);
            Assert.AreApproximatelyEqual((float)edgeLength.Y, vector.y);
            Assert.AreApproximatelyEqual((float)edgeLength.Z, vector.z);
        }
Ejemplo n.º 7
0
        public void EdgeLength_to_Vector3_has_equal_component_values()
        {
            var edgeLength = new EdgeLength(10f, 20f, 30f);
            var vector     = edgeLength.ToUnityVector();

            Assert.AreApproximatelyEqual((float)edgeLength.X, vector.x);
            Assert.AreApproximatelyEqual((float)edgeLength.Y, vector.y);
            Assert.AreApproximatelyEqual((float)edgeLength.Z, vector.z);
        }
Ejemplo n.º 8
0
        public void Division_operator_returns_correct_result()
        {
            var c1 = new Coordinates(10d, 20d, 30d);
            var c2 = c1 / 10d;

            Assert.AreApproximatelyEqual((float)c2.X, 1f);
            Assert.AreApproximatelyEqual((float)c2.Y, 2f);
            Assert.AreApproximatelyEqual((float)c2.Z, 3f);
        }
Ejemplo n.º 9
0
        public void Multiplication_operator_returns_correct_result()
        {
            var e1 = new EdgeLength(10d, 20d, 30d);
            var e2 = e1 * 10d;

            Assert.AreApproximatelyEqual((float)e2.X, 100f);
            Assert.AreApproximatelyEqual((float)e2.Y, 200f);
            Assert.AreApproximatelyEqual((float)e2.Z, 300f);
        }
Ejemplo n.º 10
0
        public void JacobianUtilitiesCalculateCorrectionTest()
        {
            float predictedError = 0.2f;
            float initialError   = 0.1f;
            float tau            = 0.6f;
            float damping        = 1.0f;

            Assert.AreApproximatelyEqual(0.16f, JacobianUtilities.CalculateCorrection(predictedError, initialError, tau, damping));
        }
Ejemplo n.º 11
0
        public void Coordinates_from_Vector3_has_equal_component_values()
        {
            var vector = new Vector3(10f, 20f, 30f);
            var coords = Coordinates.FromUnityVector(vector);

            Assert.AreApproximatelyEqual((float)coords.X, vector.x);
            Assert.AreApproximatelyEqual((float)coords.Y, vector.y);
            Assert.AreApproximatelyEqual((float)coords.Z, vector.z);
        }
Ejemplo n.º 12
0
        public void Division_operator_returns_correct_result()
        {
            var e1 = new EdgeLength(10d, 20d, 30d);
            var e2 = e1 / 10d;

            Assert.AreApproximatelyEqual((float)e2.X, 1f);
            Assert.AreApproximatelyEqual((float)e2.Y, 2f);
            Assert.AreApproximatelyEqual((float)e2.Z, 3f);
        }
Ejemplo n.º 13
0
        public void Multiplication_operator_returns_correct_result()
        {
            var c1 = new Coordinates(10d, 20d, 30d);
            var c2 = c1 * 10d;

            Assert.AreApproximatelyEqual((float)c2.X, 100f);
            Assert.AreApproximatelyEqual((float)c2.Y, 200f);
            Assert.AreApproximatelyEqual((float)c2.Z, 300f);
        }
Ejemplo n.º 14
0
        public void Coordinates_to_Vector3_has_equal_component_values()
        {
            var coords = new Coordinates(10f, 20f, 30f);
            var vector = coords.ToUnityVector();

            Assert.AreApproximatelyEqual((float)coords.X, vector.x);
            Assert.AreApproximatelyEqual((float)coords.Y, vector.y);
            Assert.AreApproximatelyEqual((float)coords.Z, vector.z);
        }
Ejemplo n.º 15
0
        public void Addition_operator_returns_correct_result()
        {
            var e1 = new EdgeLength(10d, 20d, 30d);
            var e2 = new EdgeLength(40d, 50d, 60d);

            var e3 = e1 + e2;

            Assert.AreApproximatelyEqual((float)e3.X, 50f);
            Assert.AreApproximatelyEqual((float)e3.Y, 70f);
            Assert.AreApproximatelyEqual((float)e3.Z, 90f);
        }
Ejemplo n.º 16
0
        public void ComputeAreaOfTriangle_IgnoresTranslations(float area, Vector2[] triangle)
        {
            var translation = m_Rand.NextFloat2();

            for (var i = 0; i < 3; i++)
            {
                triangle[i] = (Vector2)translation + triangle[i];
            }
            Assert.AreApproximatelyEqual(area,
                                         ObjectPlacementUtilities.ComputeAreaOfTriangle(triangle[0], triangle[1], triangle[2]));
        }
Ejemplo n.º 17
0
        public void Subtraction_operator_returns_correct_result()
        {
            var c1 = new Coordinates(10d, 20d, 30d);
            var c2 = new Coordinates(40d, 50d, 60d);

            var c3 = c2 - c1;

            Assert.AreApproximatelyEqual((float)c3.X, 30f);
            Assert.AreApproximatelyEqual((float)c3.Y, 30f);
            Assert.AreApproximatelyEqual((float)c3.Z, 30f);
        }
Ejemplo n.º 18
0
        public void Addition_operator_returns_correct_result()
        {
            var c1 = new Coordinates(10d, 20d, 30d);
            var c2 = new Coordinates(40d, 50d, 60d);

            var c3 = c1 + c2;

            Assert.AreApproximatelyEqual((float)c3.X, 50f);
            Assert.AreApproximatelyEqual((float)c3.Y, 70f);
            Assert.AreApproximatelyEqual((float)c3.Z, 90f);
        }
Ejemplo n.º 19
0
        public void Subtraction_operator_returns_correct_result()
        {
            var e1 = new EdgeLength(10d, 20d, 30d);
            var e2 = new EdgeLength(40d, 50d, 60d);

            var e3 = e2 - e1;

            Assert.AreApproximatelyEqual((float)e3.X, 30f);
            Assert.AreApproximatelyEqual((float)e3.Y, 30f);
            Assert.AreApproximatelyEqual((float)e3.Z, 30f);
        }
Ejemplo n.º 20
0
        public void JacobianUtilitiesCalculateTauAndDampingTest()
        {
            float springFrequency    = 1.0f;
            float springDampingRatio = 1.0f;
            float timestep           = 1.0f;
            int   iterations         = 4;

            JacobianUtilities.CalculateTauAndDamping(springFrequency, springDampingRatio, timestep, iterations, out float tau, out float damping);

            Assert.AreApproximatelyEqual(0.4774722f, tau);
            Assert.AreApproximatelyEqual(0.6294564f, damping);
        }
Ejemplo n.º 21
0
        public void ComputeAreaOfTriangle_IgnoresZAxis(float area, Vector2[] triangle)
        {
            var triangle3d = new Vector3[3];

            for (var i = 0; i < 3; i++)
            {
                triangle3d[i] = (Vector3)triangle[i] + m_Rand.NextFloat(-10f, 10f) * Vector3.forward;
            }

            Assert.AreApproximatelyEqual(area,
                                         ObjectPlacementUtilities.ComputeAreaOfTriangle(triangle3d[0], triangle3d[1], triangle3d[2]));
        }
Ejemplo n.º 22
0
        public void MotionVelocityCalculateExpansionTest()
        {
            var motionVelocity = new MotionVelocity()
            {
                LinearVelocity         = new float3(2.0f, 1.0f, 5.0f),
                AngularVelocity        = new float3(3.0f, 4.0f, 5.0f),
                InverseInertiaAndMass  = new float4(2.0f, 3.0f, 4.0f, 2.0f),
                AngularExpansionFactor = 1.2f
            };
            var motionExpansion = motionVelocity.CalculateExpansion(1.0f / 60.0f);

            Assert.AreEqual(new float3(1.0f / 30.0f, 1.0f / 60.0f, 1.0f / 12.0f), motionExpansion.Linear);
            Assert.AreApproximatelyEqual((float)math.SQRT2 / 10.0f, motionExpansion.Uniform);
        }
Ejemplo n.º 23
0
 public void ComputeAreaOfTriangle_IsOrderInvariant(float area, Vector2[] triangle)
 {
     Assert.AreApproximatelyEqual(area,
                                  ObjectPlacementUtilities.ComputeAreaOfTriangle(triangle[0], triangle[1], triangle[2]));
     Assert.AreApproximatelyEqual(area,
                                  ObjectPlacementUtilities.ComputeAreaOfTriangle(triangle[0], triangle[2], triangle[1]));
     Assert.AreApproximatelyEqual(area,
                                  ObjectPlacementUtilities.ComputeAreaOfTriangle(triangle[1], triangle[0], triangle[2]));
     Assert.AreApproximatelyEqual(area,
                                  ObjectPlacementUtilities.ComputeAreaOfTriangle(triangle[1], triangle[2], triangle[0]));
     Assert.AreApproximatelyEqual(area,
                                  ObjectPlacementUtilities.ComputeAreaOfTriangle(triangle[2], triangle[1], triangle[0]));
     Assert.AreApproximatelyEqual(area,
                                  ObjectPlacementUtilities.ComputeAreaOfTriangle(triangle[2], triangle[0], triangle[1]));
 }
Ejemplo n.º 24
0
        public void LoadAsFbxCompareMeshTransforms()
        {
            // Compare camera transforms
            var usdMeshTr = usdRoot.transform.Find("group2/group1/pCube1");
            var fbxMeshTr = fbxRoot.transform.Find("group1/pCube1");

            Debug.Log("Comparing mesh positions...");
            Assert.AreApproximatelyEqual(usdMeshTr.position.x, fbxMeshTr.position.x);
            Assert.AreApproximatelyEqual(usdMeshTr.position.y, fbxMeshTr.position.y);
            Assert.AreApproximatelyEqual(usdMeshTr.position.z, fbxMeshTr.position.z);
            Debug.Log("Comparing mesh rotations...");
            Assert.AreApproximatelyEqual(usdMeshTr.localRotation.x, fbxMeshTr.localRotation.x);
            Assert.AreApproximatelyEqual(usdMeshTr.localRotation.y, fbxMeshTr.localRotation.y);
            Assert.AreApproximatelyEqual(usdMeshTr.localRotation.z, fbxMeshTr.localRotation.z);
        }
Ejemplo n.º 25
0
        public void LoadAsFbxCompareCameraTransforms()
        {
            // Compare camera transforms
            var usdCamTr = usdRoot.transform.Find("group2/camera1");
            var fbxCamTr = fbxRoot.transform.Find("camera1");

            Debug.Log("Comparing camera positions...");
            Assert.AreApproximatelyEqual(usdCamTr.position.x, fbxCamTr.position.x);
            Assert.AreApproximatelyEqual(usdCamTr.position.y, fbxCamTr.position.y);
            Assert.AreApproximatelyEqual(usdCamTr.position.z, fbxCamTr.position.z);
            Debug.Log("Comparing camera rotations...");
            Assert.AreApproximatelyEqual(usdCamTr.localRotation.x, fbxCamTr.localRotation.x);
            Assert.AreApproximatelyEqual(usdCamTr.localRotation.y, fbxCamTr.localRotation.y);
            Assert.AreApproximatelyEqual(usdCamTr.localRotation.z, fbxCamTr.localRotation.z);
        }
Ejemplo n.º 26
0
        public void JacobianUtilitiesCalculateTauAndDampingFromConstraintTest()
        {
            var constraint = new Constraint {
                SpringFrequency = 1.0f, SpringDamping = 1.0f
            };
            float timestep   = 1.0f;
            int   iterations = 4;

            float tau;
            float damping;

            JacobianUtilities.CalculateTauAndDamping(constraint, timestep, iterations, out tau, out damping);

            Assert.AreApproximatelyEqual(0.4774722f, tau);
            Assert.AreApproximatelyEqual(0.6294564f, damping);
        }
Ejemplo n.º 27
0
        public void CenterAsIntended()
        {
            Transform atlasContainerTransform = MapRenderer.i.atlas.container.transform;

            CommonScriptableObjects.playerWorldPosition.Set(new Vector3(1, 1, 1));
            CommonScriptableObjects.playerWorldPosition.Set(new Vector3(0, 0, 0));
            Assert.AreApproximatelyEqual(-1500, atlasContainerTransform.position.x);
            Assert.AreApproximatelyEqual(-1500, atlasContainerTransform.position.y);

            CommonScriptableObjects.playerWorldPosition.Set(new Vector3(100, 0, 100));
            Assert.AreApproximatelyEqual(-1562.5f, atlasContainerTransform.position.x);
            Assert.AreApproximatelyEqual(-1562.5f, atlasContainerTransform.position.y);

            CommonScriptableObjects.playerWorldPosition.Set(new Vector3(-100, 0, -100));
            Assert.AreApproximatelyEqual(-1437.5f, atlasContainerTransform.position.x);
            Assert.AreApproximatelyEqual(-1437.5f, atlasContainerTransform.position.y);
        }
Ejemplo n.º 28
0
        public IEnumerator UpdateTransformUpdatesBounds()
        {
            BoundsControl boundsControl = InstantiateSceneAndDefaultBoundsControl();

            yield return(VerifyInitialBoundsCorrect(boundsControl));

            boundsControl.HideElementsInInspector = false;
            yield return(null);

            var startBounds = GetBoundsControlRigBounds(boundsControl);

            TestUtilities.AssertAboutEqual(startBounds.center, boundsControlStartCenter, "boundsControl incorrect center at start");
            TestUtilities.AssertAboutEqual(startBounds.size, boundsControlStartScale, "boundsControl incorrect size at start");

            boundsControl.gameObject.transform.localScale *= 2;
            yield return(null);

            var afterScaleBounds = GetBoundsControlRigBounds(boundsControl);
            var scaledSize       = boundsControlStartScale * 2;

            TestUtilities.AssertAboutEqual(afterScaleBounds.center, boundsControlStartCenter, "boundsControl incorrect center after scale");
            TestUtilities.AssertAboutEqual(afterScaleBounds.size, scaledSize, "boundsControl incorrect size after scale");

            boundsControl.gameObject.transform.position += Vector3.one;
            yield return(null);

            var afterTranslateBounds = GetBoundsControlRigBounds(boundsControl);
            var afterTranslateCenter = Vector3.one + boundsControlStartCenter;

            TestUtilities.AssertAboutEqual(afterTranslateBounds.center, afterTranslateCenter, "boundsControl incorrect center after translate");
            TestUtilities.AssertAboutEqual(afterTranslateBounds.size, scaledSize, "boundsControl incorrect size after translate");

            var     c0 = boundsControl.gameObject.transform.Find("rigRoot/corner_0");
            var     boundsControlBottomCenter = afterTranslateBounds.center - Vector3.up * afterTranslateBounds.extents.y;
            Vector3 cc0          = c0.position - boundsControlBottomCenter;
            float   rotateAmount = 30;

            boundsControl.gameObject.transform.Rotate(new Vector3(0, rotateAmount, 0));
            yield return(null);

            Vector3 cc0_rotated = c0.position - boundsControlBottomCenter;

            Assert.AreApproximatelyEqual(Vector3.Angle(cc0, cc0_rotated), 30, $"rotated angle is not correct. expected {rotateAmount} but got {Vector3.Angle(cc0, cc0_rotated)}");

            GameObject.Destroy(boundsControl.gameObject);
        }
        public IEnumerator UpdateTransformUpdatesBounds()
        {
            var bbox = InstantiateSceneAndDefaultBbox();

            bbox.HideElementsInInspector = false;
            yield return(null);

            var startBounds = GetBoundingBoxRigBounds(bbox);
            var startCenter = new Vector3(0, 0, 1.5f);
            var startSize   = new Vector3(.5f, .5f, .5f);

            TestUtilities.AssertAboutEqual(startBounds.center, startCenter, "bbox incorrect center at start");
            TestUtilities.AssertAboutEqual(startBounds.size, startSize, "bbox incorrect size at start");

            bbox.gameObject.transform.localScale *= 2;
            yield return(null);

            var afterScaleBounds = GetBoundingBoxRigBounds(bbox);
            var scaledSize       = startSize * 2;

            TestUtilities.AssertAboutEqual(afterScaleBounds.center, startCenter, "bbox incorrect center after scale");
            TestUtilities.AssertAboutEqual(afterScaleBounds.size, scaledSize, "bbox incorrect size after scale");

            bbox.gameObject.transform.position += Vector3.one;
            yield return(null);

            var afterTranslateBounds = GetBoundingBoxRigBounds(bbox);
            var afterTranslateCenter = Vector3.one + startCenter;

            TestUtilities.AssertAboutEqual(afterTranslateBounds.center, afterTranslateCenter, "bbox incorrect center after translate");
            TestUtilities.AssertAboutEqual(afterTranslateBounds.size, scaledSize, "bbox incorrect size after translate");

            var     c0 = bbox.ScaleCorners[0];
            var     bboxBottomCenter = afterTranslateBounds.center - Vector3.up * afterTranslateBounds.extents.y;
            Vector3 cc0          = c0.transform.position - bboxBottomCenter;
            float   rotateAmount = 30;

            bbox.gameObject.transform.Rotate(new Vector3(0, rotateAmount, 0));
            yield return(null);

            Vector3 cc0_rotated = c0.transform.position - bboxBottomCenter;

            Assert.AreApproximatelyEqual(Vector3.Angle(cc0, cc0_rotated), 30, $"rotated angle is not correct. expected {rotateAmount} but got {Vector3.Angle(cc0, cc0_rotated)}");

            GameObject.Destroy(bbox.gameObject);
        }
Ejemplo n.º 30
0
        public void ConvertPBRArguments(float dielectricSpecular)
        {
            var mr = new PBRUtils.MetallicRoughness()
            {
                baseColor = new Color(0.1f, 0.2f, 0.3f, 0.5f),
                opacity   = 0.5f,
                roughness = 0.6f,
                metallic  = 0.4f
            };

            var sp = PBRUtils.ConvertToSpecularGlossiness(mr);

            var mr2 = PBRUtils.ConvertToMetallicRoughness(sp);

            Assert.AreApproximatelyEqual(mr.opacity, mr2.opacity, 1e-6f);
            Assert.AreApproximatelyEqual(mr.metallic, mr2.metallic, 1e-6f);
            Assert.AreApproximatelyEqual(mr.roughness, mr2.roughness, 1e-6f);
            Assert.AreApproximatelyEqual(mr.baseColor.a, mr2.baseColor.a, 1e-6f);
            Assert.AreApproximatelyEqual(mr.baseColor.r, mr2.baseColor.r, 1e-6f);
            Assert.AreApproximatelyEqual(mr.baseColor.g, mr2.baseColor.g, 1e-6f);
            Assert.AreApproximatelyEqual(mr.baseColor.b, mr2.baseColor.b, 1e-6f);
        }