public IEnumerator ShapeUpdate() { string entityId = "1"; TestHelpers.CreateSceneEntity(scene, entityId); Assert.IsTrue( scene.entities[entityId].gameObject.GetComponentInChildren <UnityGLTF.InstantiatedGLTFObject>() == null, "Since the shape hasn't been updated yet, the 'GLTFScene' child object shouldn't exist"); TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeObject( new { src = Utils.GetTestsAssetsPath() + "/GLB/Lantern/Lantern.glb" })); LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]); yield return(new WaitUntil(() => gltfShape.alreadyLoaded)); Assert.IsTrue( scene.entities[entityId].gameObject.GetComponentInChildren <UnityGLTF.InstantiatedGLTFObject>() != null, "'GLTFScene' child object with 'InstantiatedGLTF' component should exist if the GLTF was loaded correctly"); }
public IEnumerator DCLAnimatorResetAnimation() { GLTFShape gltfShape = TestHelpers.CreateEntityWithGLTFShape(scene, Vector3.zero, new LoadableShape.Model { src = Utils.GetTestsAssetsPath() + "/GLB/Shark/shark_anim.gltf" }); var entity = gltfShape.attachedEntities.First(); DCLAnimator.Model animatorModel = new DCLAnimator.Model { states = new[] { new DCLAnimator.Model.DCLAnimationState { name = "Bite", clip = "shark_skeleton_bite", playing = true, weight = 1, speed = 1 }, new DCLAnimator.Model.DCLAnimationState { name = "Swim", clip = "shark_skeleton_swim", playing = true, weight = 1, speed = 1 } } }; DCLAnimator animator = TestHelpers.EntityComponentCreate <DCLAnimator, DCLAnimator.Model>(scene, entity, animatorModel); LoadWrapper gltfLoader = GLTFShape.GetLoaderForEntity(entity); yield return(new WaitUntil(() => gltfLoader.alreadyLoaded)); yield return(animator.routine); animator.animComponent.cullingType = AnimationCullingType.AlwaysAnimate; yield return(new WaitForSeconds(1.5f)); Animation animation = entity.gameObject.GetComponentInChildren <Animation>(); foreach (AnimationState animState in animation) { Assert.AreNotEqual(0f, animState.time); } animatorModel.states[1].shouldReset = true; yield return(TestHelpers.EntityComponentUpdate(animator, animatorModel)); animator.ResetAnimation(animator.GetStateByString("Swim")); foreach (AnimationState animState in animation) { if (animator.GetStateByString("Swim").clipReference.name == animState.clip.name) { Assert.AreEqual(0f, animState.time); } else { Assert.AreNotEqual(0f, animState.time); } } }
public IEnumerator NonSkeletalAnimationsSupport() { DecentralandEntity entity = TestHelpers.CreateSceneEntity(scene); TestHelpers.SetEntityTransform(scene, entity, new Vector3(8, 2, 8), Quaternion.identity, Vector3.one); Assert.IsTrue(entity.gameObject.GetComponentInChildren <UnityGLTF.InstantiatedGLTFObject>() == null, "Since the shape hasn't been updated yet, the 'GLTFScene' child object shouldn't exist"); TestHelpers.CreateAndSetShape(scene, entity.entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeObject(new { src = Utils.GetTestsAssetsPath() + "/GLB/non-skeletal-3-transformations.glb" })); string clipName = "All"; DCLAnimator.Model animatorModel = new DCLAnimator.Model { states = new DCLAnimator.Model.DCLAnimationState[] { new DCLAnimator.Model.DCLAnimationState { name = "clip01", clip = clipName, playing = false, weight = 1, speed = 1, looping = false } } }; DCLAnimator animator = TestHelpers.EntityComponentCreate <DCLAnimator, DCLAnimator.Model>(scene, entity, animatorModel); LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(entity); yield return(new WaitUntil(() => gltfShape.alreadyLoaded == true)); animator.animComponent.cullingType = AnimationCullingType.AlwaysAnimate; Assert.IsTrue(!animator.animComponent.isPlaying); Assert.AreEqual(animator.animComponent.clip.name, clipName); Assert.IsFalse(animator.animComponent.clip.wrapMode == WrapMode.Loop); Transform animatedGameObject = animator.animComponent.transform.GetChild(0); Vector3 originalScale = animatedGameObject.transform.localScale; Vector3 originalPos = animatedGameObject.transform.localPosition; Quaternion originalRot = animatedGameObject.transform.localRotation; // start animation animatorModel.states[0].playing = true; yield return(TestHelpers.EntityComponentUpdate(animator, animatorModel)); yield return(new WaitForSeconds(3f)); Assert.IsFalse(animatedGameObject.localScale == originalScale); Assert.IsFalse(animatedGameObject.localPosition == originalPos); Assert.IsFalse(animatedGameObject.localRotation == originalRot); }
public IEnumerator AnimationStartsAutomaticallyWithNoDCLAnimator() { // GLTFShape without DCLAnimator DecentralandEntity entity = TestHelpers.CreateSceneEntity(scene); Assert.IsTrue(entity.gameObject.GetComponentInChildren <UnityGLTF.InstantiatedGLTFObject>() == null, "Since the shape hasn't been updated yet, the 'GLTFScene' child object shouldn't exist"); TestHelpers.CreateAndSetShape(scene, entity.entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeObject(new { src = Utils.GetTestsAssetsPath() + "/GLB/CesiumMan/CesiumMan.glb" })); LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(entity); yield return(new WaitUntil(() => gltfShape.alreadyLoaded == true)); Animation animation = entity.meshRootGameObject.GetComponentInChildren <Animation>(); Assert.IsTrue(animation != null); Assert.IsTrue(animation.isPlaying); // GLTFShape with DCLAnimator DecentralandEntity entity2 = TestHelpers.CreateSceneEntity(scene); Assert.IsTrue(entity2.gameObject.GetComponentInChildren <UnityGLTF.InstantiatedGLTFObject>() == null, "Since the shape hasn't been updated yet, the 'GLTFScene' child object shouldn't exist"); TestHelpers.CreateAndSetShape(scene, entity2.entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeObject(new { src = Utils.GetTestsAssetsPath() + "/GLB/CesiumMan/CesiumMan.glb" })); string clipName = "animation:0"; DCLAnimator.Model animatorModel = new DCLAnimator.Model { states = new DCLAnimator.Model.DCLAnimationState[] { new DCLAnimator.Model.DCLAnimationState { name = "clip01", clip = clipName, playing = false, weight = 1, speed = 1, looping = false } } }; DCLAnimator animator = TestHelpers.EntityComponentCreate <DCLAnimator, DCLAnimator.Model>(scene, entity, animatorModel); LoadWrapper gltfShape2 = GLTFShape.GetLoaderForEntity(entity); yield return(new WaitUntil(() => gltfShape2.alreadyLoaded == true)); Assert.IsTrue(animator.animComponent != null); Assert.AreEqual(animator.animComponent.clip.name, clipName); Assert.IsFalse(animator.animComponent.isPlaying); }
public IEnumerator PreExistentShapeUpdate() { string entityId = "1"; TestHelpers.CreateSceneEntity(scene, entityId); var entity = scene.entities[entityId]; Assert.IsTrue(entity.meshRootGameObject == null, "meshGameObject should be null"); // Set its shape as a BOX var componentId = TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.BOX_SHAPE, "{}"); yield return(((scene.GetSharedComponent(componentId)) as IDelayedComponent).routine); var meshName = entity.meshRootGameObject.GetComponent <MeshFilter>().mesh.name; Assert.AreEqual("DCL Box Instance", meshName); // Update its shape to a cylinder TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.CYLINDER_SHAPE, "{}"); yield return((scene.GetSharedComponent(componentId) as IDelayedComponent).routine); Assert.IsTrue(entity.meshRootGameObject != null, "meshGameObject should not be null"); meshName = entity.meshRootGameObject.GetComponent <MeshFilter>().mesh.name; Assert.AreEqual("DCL Cylinder Instance", meshName); Assert.IsTrue(entity.meshRootGameObject.GetComponent <MeshFilter>() != null, "After updating the entity shape to a basic shape, the mesh filter shouldn't be removed from the object"); Assert.IsTrue(entity.meshesInfo.currentShape != null, "current shape must exist 1"); Assert.IsTrue(entity.meshesInfo.currentShape is CylinderShape, "current shape is BoxShape"); // Update its shape to a GLTF TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeObject( new { src = Utils.GetTestsAssetsPath() + "/GLB/Lantern/Lantern.glb" })); LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]); yield return(new WaitUntil(() => gltfShape.alreadyLoaded)); Assert.IsTrue(entity.meshesInfo.currentShape != null, "current shape must exist 2"); Assert.IsTrue(entity.meshesInfo.currentShape is GLTFShape, "current shape is GLTFShape"); Assert.IsTrue(entity.meshRootGameObject != null); Assert.IsTrue(entity.meshRootGameObject.GetComponent <MeshFilter>() == null, "After updating the entity shape to a GLTF shape, the mesh filter should be removed from the object"); Assert.IsTrue( scene.entities[entityId].gameObject.GetComponentInChildren <UnityGLTF.InstantiatedGLTFObject>() != null, "'GLTFScene' child object with 'InstantiatedGLTF' component should exist if the GLTF was loaded correctly"); // Update its shape to a sphere TestHelpers.CreateAndSetShape(scene, entityId, CLASS_ID.SPHERE_SHAPE, "{}"); yield return((scene.GetSharedComponent(componentId) as IDelayedComponent).routine); yield return(null); Assert.IsTrue(entity.meshRootGameObject != null); meshName = entity.meshRootGameObject.GetComponent <MeshFilter>().mesh.name; Assert.AreEqual("DCL Sphere Instance", meshName); Assert.IsTrue( scene.entities[entityId].gameObject.GetComponentInChildren <UnityGLTF.InstantiatedGLTFObject>() == null, "'GLTFScene' child object with 'InstantiatedGLTF' component shouldn't exist after the shape is updated to a non-GLTF shape"); }
public IEnumerator MaterialTransitionWithGLTF() { var entity1 = TestHelpers.CreateSceneEntity(scene); ParcelSettings.VISUAL_LOADING_ENABLED = true; var prevLoadingType = RendereableAssetLoadHelper.loadingType; RendereableAssetLoadHelper.loadingType = RendereableAssetLoadHelper.LoadingType.GLTF_ONLY; Shader hologramShader = Shader.Find("DCL/FX/Hologram"); Assert.IsTrue(hologramShader != null, "Hologram shader == null??"); DecentralandEntity entity = null; GLTFShape shape = TestHelpers.InstantiateEntityWithShape <GLTFShape, GLTFShape.Model> (scene, DCL.Models.CLASS_ID.GLTF_SHAPE, Vector3.zero, out entity, new GLTFShape.Model() { src = DCL.Helpers.Utils.GetTestsAssetsPath() + "/GLB/Lantern/Lantern.glb" }); LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(entity); yield return(new WaitUntil(() => gltfShape.alreadyLoaded)); float timeout = 0; while (timeout < 10) { timeout += Time.deltaTime; if (entity.meshRootGameObject != null) { var c = entity.meshRootGameObject.GetComponentInChildren <MaterialTransitionController>(); if (c != null && c.placeholder != null) // NOTE(Brian): Wait for it { Assert.IsTrue(c.useHologram, "useHologram must be true"); Assert.IsTrue(entity.meshRootGameObject != null, "meshGameObject is null"); Assert.AreEqual(c.gameObject.transform, c.placeholder.transform.parent, "MaterialTransitionController is not parented correctly"); Assert.IsTrue(c.placeholder.GetComponent <MeshFilter>() != null, "MeshFilter missing from placeholder object"); Assert.IsTrue(c.placeholder.GetComponent <Renderer>() != null, "Renderer missing from placeholder object"); Assert.IsTrue(c.placeholder.GetComponent <Renderer>().sharedMaterial != null, "SharedMaterial missing from placeholder's renderer"); Assert.AreEqual(hologramShader, c.placeholder.GetComponent <Renderer>().sharedMaterial.shader, "Placeholder is not hologram"); yield return(new WaitForSeconds(2f)); Assert.IsTrue(c == null, "MaterialTransitionController should be destroyed by now!"); break; } } yield return(null); } Assert.Less(timeout, 10.1f, "Timeout! MaterialTransitionController never appeared?"); RendereableAssetLoadHelper.loadingType = prevLoadingType; yield return(null); }
public FileOperationResult ObservedLoad(NamedFileOperationDelegate loadNamedFileDelegate, string fileName, string message, FileErrorPolicy policy) { LoadWrapper loadWrapper = new LoadWrapper(loadNamedFileDelegate, fileName); FileOperationDelegate fileOperationDelegate = new FileOperationDelegate(loadWrapper.Invoke); return ObservedLoad(fileOperationDelegate, fileName, message, policy); }