| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL.Configuration; |
| | 4 | | using UnityEditor; |
| | 5 | | using UnityEngine; |
| | 6 | | using Object = UnityEngine.Object; |
| | 7 | |
|
| | 8 | | namespace DCL |
| | 9 | | { |
| | 10 | | public class Asset_GLTFast_Instance : Asset_WithPoolableContainer |
| | 11 | | { |
| | 12 | | internal AssetPromise_GLTFast_Loader ownerPromise; |
| 0 | 13 | | public sealed override GameObject container { get; set; } |
| | 14 | |
|
| 0 | 15 | | public Asset_GLTFast_Instance() |
| | 16 | | { |
| 0 | 17 | | container = new GameObject("GLTFast Container") |
| | 18 | | { |
| | 19 | | transform = { position = EnvironmentSettings.MORDOR } |
| | 20 | | }; |
| 0 | 21 | | } |
| | 22 | |
|
| 0 | 23 | | public Renderer[] ExtractRenderers() => container.GetComponentsInChildren<Renderer>(); |
| | 24 | |
|
| | 25 | | public override void Cleanup() |
| | 26 | | { |
| 0 | 27 | | AssetPromiseKeeper_GLTFast.i.Forget(ownerPromise); |
| 0 | 28 | | Object.Destroy(container); |
| 0 | 29 | | } |
| | 30 | |
|
| | 31 | | public void Hide() |
| | 32 | | { |
| 0 | 33 | | container.SetActive(false); |
| 0 | 34 | | container.transform.parent = null; |
| 0 | 35 | | container.transform.position = EnvironmentSettings.MORDOR; |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | public void Show(Action success) |
| | 39 | | { |
| 0 | 40 | | container.SetActive(true); |
| 0 | 41 | | success?.Invoke(); |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | public Rendereable ToRendereable() |
| | 45 | | { |
| 0 | 46 | | Renderer[] renderers = container.gameObject.GetComponentsInChildren<Renderer>(); |
| 0 | 47 | | HashSet<Mesh> meshes = new HashSet<Mesh>(); |
| 0 | 48 | | HashSet<Material> materials = new HashSet<Material>(); |
| 0 | 49 | | HashSet<Texture> textures = new HashSet<Texture>(); |
| | 50 | |
|
| 0 | 51 | | foreach (Renderer renderer in renderers) |
| | 52 | | { |
| | 53 | | switch (renderer) |
| | 54 | | { |
| | 55 | | case SkinnedMeshRenderer skinnedMeshRenderer: |
| 0 | 56 | | meshes.Add(skinnedMeshRenderer.sharedMesh); |
| 0 | 57 | | break; |
| | 58 | | case MeshRenderer: |
| 0 | 59 | | meshes.Add(renderer.GetComponent<MeshFilter>().sharedMesh); |
| | 60 | | break; |
| | 61 | | } |
| | 62 | |
|
| 0 | 63 | | foreach (Material material in renderer.sharedMaterials) { materials.Add(material); } |
| | 64 | | } |
| | 65 | |
|
| 0 | 66 | | for (int i = 0; i < ownerPromise.asset.GltfImport.TextureCount; i++) |
| 0 | 67 | | textures.Add(ownerPromise.asset.GltfImport.GetTexture(i)); |
| | 68 | |
|
| 0 | 69 | | HashSet<AnimationClip> animations = new HashSet<AnimationClip>(); |
| | 70 | |
|
| 0 | 71 | | var animationClips = ownerPromise.asset.GltfImport.GetAnimationClips(); |
| | 72 | |
|
| 0 | 73 | | if (animationClips != null) |
| 0 | 74 | | foreach (AnimationClip clip in animationClips) |
| 0 | 75 | | animations.Add(clip); |
| | 76 | |
|
| 0 | 77 | | return new Rendereable |
| | 78 | | { |
| | 79 | | container = container, |
| | 80 | | meshes = meshes, |
| | 81 | | renderers = new HashSet<Renderer>(renderers), |
| | 82 | | materials = materials, |
| | 83 | | textures = textures, |
| | 84 | | meshToTriangleCount = new Dictionary<Mesh, int>(), |
| | 85 | | animationClips = animations, |
| | 86 | |
|
| | 87 | | // TODO: Fill me! |
| | 88 | | totalTriangleCount = 0, |
| | 89 | | animationClipSize = 0, |
| | 90 | | meshDataSize = 0, |
| | 91 | | isGLTFast = true |
| | 92 | | }; |
| | 93 | | } |
| | 94 | | } |
| | 95 | | } |