public void TestAngle()
 {
     {
         Vector3 v1    = Vector3.up;
         Vector2 v2    = Vector3.left;
         float   angle = UnityVectorExtensions.Angle(v1, v2);
         Assert.AreApproximatelyEqual(angle, 90f);
         float angle2 = Vector2.Angle(v1, v2);
         Assert.AreApproximatelyEqual(angle, angle2);
     }
     {
         Vector3 v1    = Vector3.up;
         Vector2 v2    = Vector3.right;
         float   angle = UnityVectorExtensions.Angle(v1, v2);
         Assert.AreApproximatelyEqual(angle, 90f);
         float angle2 = Vector2.Angle(v1, v2);
         Assert.AreApproximatelyEqual(angle, angle2);
     }
     {
         Vector3 v1    = Vector3.up;
         Vector2 v2    = new Vector3(-0.0001f, 1, 0);
         float   angle = UnityVectorExtensions.Angle(v1, v2);
         Assert.AreApproximatelyEqual(angle, 0.00572958f);
     }
     {
         Vector3 v1    = Vector3.up;
         Vector2 v2    = new Vector3(0.0001f, 1, 0);
         float   angle = UnityVectorExtensions.Angle(v1, v2);
         Assert.AreApproximatelyEqual(angle, 0.00572958f);
     }
 }
 public void TestSignedAngle()
 {
     {
         Vector3 v1    = Vector3.up;
         Vector2 v2    = Vector3.left;
         float   angle = UnityVectorExtensions.SignedAngle(v1, v2, Vector3.forward);
         Assert.AreApproximatelyEqual(angle, 90f);
         float angle2 = Vector2.SignedAngle(v1, v2);
         Assert.AreApproximatelyEqual(angle, angle2);
         float angle3 = UnityVectorExtensions.SignedAngle(v1, v2, Vector3.back);
         Assert.AreApproximatelyEqual(angle, -angle3);
     }
     {
         Vector3 v1    = Vector3.up;
         Vector2 v2    = Vector3.right;
         float   angle = UnityVectorExtensions.SignedAngle(v1, v2, Vector3.forward);
         Assert.AreApproximatelyEqual(angle, -90f);
         float angle2 = Vector2.SignedAngle(v1, v2);
         Assert.AreApproximatelyEqual(angle, angle2);
         float angle3 = UnityVectorExtensions.SignedAngle(v1, v2, Vector3.back);
         Assert.AreApproximatelyEqual(angle, -angle3);
     }
     {
         Vector3 v1    = Vector3.up;
         Vector2 v2    = new Vector3(-0.0001f, 1, 0);
         float   angle = UnityVectorExtensions.SignedAngle(v1, v2, Vector3.forward);
         Assert.AreApproximatelyEqual(angle, 0.00572958f);
         float angle3 = UnityVectorExtensions.SignedAngle(v1, v2, Vector3.back);
         Assert.AreApproximatelyEqual(angle, -angle3);
     }
     {
         Vector3 v1    = Vector3.up;
         Vector2 v2    = new Vector3(0.0001f, 1, 0);
         float   angle = UnityVectorExtensions.SignedAngle(v1, v2, Vector3.forward);
         Assert.AreApproximatelyEqual(angle, -0.00572958f);
         float angle3 = UnityVectorExtensions.SignedAngle(v1, v2, Vector3.back);
         Assert.AreApproximatelyEqual(angle, -angle3);
     }
 }
Example #3
0
    public IEnumerator EntityBasicMaterialUpdate()
    {
        string entityId   = "1";
        string materialID = "a-material";

        Assert.IsFalse(scene.disposableComponents.ContainsKey(materialID));

        // Instantiate entity with default material
        TestHelpers.InstantiateEntityWithMaterial(scene, entityId, new Vector3(8, 1, 8),
                                                  new BasicMaterial.Model(), materialID);

        var meshObject = scene.entities[entityId].meshRootGameObject;

        Assert.IsTrue(meshObject != null,
                      "Every entity with a shape should have the mandatory 'Mesh' object as a child");

        var meshRenderer      = meshObject.GetComponent <MeshRenderer>();
        var materialComponent = scene.disposableComponents[materialID] as BasicMaterial;

        yield return(materialComponent.routine);

        // Check if material initialized correctly
        {
            Assert.IsTrue(meshRenderer != null, "MeshRenderer must exist");

            var assignedMaterial = meshRenderer.sharedMaterial;
            Assert.IsTrue(meshRenderer != null, "MeshRenderer.sharedMaterial must be the same as assignedMaterial");

            Assert.AreEqual(assignedMaterial, materialComponent.material, "Assigned material");
        }

        // Check default properties
        {
            Assert.IsTrue(materialComponent.material.GetTexture("_BaseMap") == null);
            Assert.AreApproximatelyEqual(1.0f, materialComponent.material.GetFloat("_AlphaClip"));
        }

        DCLTexture dclTexture = TestHelpers.CreateDCLTexture(
            scene,
            Utils.GetTestsAssetsPath() + "/Images/atlas.png",
            DCLTexture.BabylonWrapMode.MIRROR,
            FilterMode.Bilinear);

        // Update material
        scene.SharedComponentUpdate(materialID, JsonUtility.ToJson(new BasicMaterial.Model
        {
            texture   = dclTexture.id,
            alphaTest = 0.5f,
        }));

        yield return(materialComponent.routine);

        // Check updated properties
        {
            Texture mainTex = materialComponent.material.GetTexture("_BaseMap");
            Assert.IsTrue(mainTex != null);
            Assert.AreApproximatelyEqual(0.5f, materialComponent.material.GetFloat("_Cutoff"));
            Assert.AreApproximatelyEqual(1.0f, materialComponent.material.GetFloat("_AlphaClip"));
            Assert.AreEqual(TextureWrapMode.Mirror, mainTex.wrapMode);
            Assert.AreEqual(FilterMode.Bilinear, mainTex.filterMode);
        }
    }
Example #4
0
 public static void AreApproximatelyEqual(float expected, float actual, float tolerance)
 {
     Assert.AreApproximatelyEqual(expected, actual, tolerance, null);
 }