public static async Task <GameObject> GetSvrfModelAsync(MediaModel model, SvrfModelOptions options = null, GameObject gameObject = null) { // It's impossible to use null coalescing operator with Unity objects. gameObject = gameObject == null ? new GameObject("Svrf Model") : gameObject; options = options ?? DefaultOptions; await SvrfModelUtility.AddSvrfModel(gameObject, model, options); return(gameObject); }
public async void Start() { var model = (await SvrfApi.Media.GetByIdAsync(SvrfModelId)).Media; var options = new SvrfModelOptions { ShaderOverride = ShaderOverride, WithOccluder = WithOccluder }; await SvrfModelUtility.AddSvrfModel(gameObject, model, options); IsLoading = false; }
public IEnumerator Start() { SvrfApi api = new SvrfApi(); TaskBasedCoroutine <MultipleMediaResponse> requestCoroutine = api.Media.GetTrendingAsync().AsCoroutine(); yield return(requestCoroutine); MediaModel model = requestCoroutine.Result.Media.First(); SvrfModelOptions options = new SvrfModelOptions { WithOccluder = false }; yield return(SvrfModel.GetSvrfModelAsync(model, options).AsCoroutine()); Destroy(GameObject.Find("Loading")); }
private async void OnLoadFaceFilter(MediaModel faceFilter) { Destroy(FaceFilterController.FaceFilter); _spinner = Instantiate(SpinnerPrefab); _spinner.transform.SetParent(SpinnerContainer.transform, false); SvrfModelOptions options = new SvrfModelOptions { WithOccluder = !Application.isEditor }; GameObject svrfModel = await SvrfModel.GetSvrfModelAsync(faceFilter, options); svrfModel.transform.SetParent(FaceFilterController.transform); FaceFilterController.FaceFilter = svrfModel; Destroy(_spinner); }
internal static async Task AddSvrfModel(GameObject gameObject, MediaModel model, SvrfModelOptions options) { var gltfComponent = gameObject.AddComponent <GLTFComponent>(); // Do not load the model automatically: let us call .Load() method manually and await it. SetGltfComponentField(gltfComponent, "loadOnStart", false); gltfComponent.GLTFUri = model.GetMainGltfFile(); SetGltfComponentField(gltfComponent, "shaderOverride", options.ShaderOverride); await gltfComponent.Load(); var gltfRoot = gameObject.transform.GetChild(0); var occluder = FindDescendant(gltfRoot, "Occluder"); // GLTF models are right-handed, but the Unity coordinates are left-handed, // so rotating the model around Y axis. gltfRoot.transform.Rotate(Vector3.up, 180); if (occluder == null) { return; } if (options.WithOccluder) { var meshRenderer = occluder.transform.Find("Primitive").GetComponent <SkinnedMeshRenderer>(); // If we need to handle occlusion, apply our custom shader to handle it. meshRenderer.sharedMaterials[0].shader = Shader.Find("Svrf/Occluder"); } else { // If we don't need to handle occlusion, hide the occluder. occluder.gameObject.SetActive(false); } }
internal static async Task AddSvrfModel(GameObject gameObject, MediaModel model, SvrfModelOptions options) { var gltfComponent = gameObject.AddComponent <GLTFComponent>(); // Do not load the model automatically: let us call .Load() method manually and await it. SetGltfComponentField(gltfComponent, "loadOnStart", false); gltfComponent.GLTFUri = model.Files.GltfMain; SetGltfComponentField(gltfComponent, "shaderOverride", options.ShaderOverride); if (!Application.isEditor) { Task.Run(() => SegmentTracking.TrackModelRequest(model)); } await gltfComponent.Load(); var gltfRoot = gameObject.transform.GetChild(0); var integratedOccluder = FindDescendant(gltfRoot, "Occluder"); integratedOccluder?.gameObject.SetActive(false); // TODO: Remove it when we remove occluder from all models if (options.WithOccluder) { var occluder = Object.Instantiate(Resources.Load <GameObject>("Occluder")); occluder.transform.parent = gltfRoot; } // GLTF models are right-handed, but the Unity coordinates are left-handed, // so rotating the model around Y axis. gltfRoot.transform.Rotate(Vector3.up, 180); }