AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
GLTFComponent.cs
Go to the documentation of this file.
1 using System.Collections;
2 using System.IO;
3 using UnityEngine;
4 
5 namespace UnityGLTF
6 {
7 
11  class GLTFComponent : MonoBehaviour
12  {
13  public string Url = "";
14  public bool Multithreaded = true;
15  public bool UseStream = false;
16 
17  public int MaximumLod = 300;
18 
19  public Shader GLTFStandard = null;
20  public Shader GLTFStandardSpecular = null;
21  public Shader GLTFConstant = null;
22 
23  public bool addColliders = false;
24 
25  IEnumerator Start()
26  {
27  GLTFSceneImporter loader = null;
28  FileStream gltfStream = null;
29  if (UseStream)
30  {
31  var fullPath = Path.Combine(Application.streamingAssetsPath, Url);
32  gltfStream = File.OpenRead(fullPath);
33  loader = new GLTFSceneImporter(
34  fullPath,
35  gltfStream,
36  gameObject.transform,
37  addColliders
38  );
39  }
40  else
41  {
42  loader = new GLTFSceneImporter(
43  Url,
44  gameObject.transform,
45  addColliders
46  );
47  }
48 
49  loader.SetShaderForMaterialType(GLTFSceneImporter.MaterialType.PbrMetallicRoughness, GLTFStandard);
50  loader.SetShaderForMaterialType(GLTFSceneImporter.MaterialType.KHR_materials_pbrSpecularGlossiness, GLTFStandardSpecular);
51  loader.SetShaderForMaterialType(GLTFSceneImporter.MaterialType.CommonConstant, GLTFConstant);
52  loader.MaximumLod = MaximumLod;
53  yield return loader.Load(-1, Multithreaded);
54  if (gltfStream != null)
55  {
56 #if WINDOWS_UWP
57  gltfStream.Dispose();
58 #else
59  gltfStream.Close();
60 #endif
61  }
62  }
63  }
64 }
IEnumerator Load(int sceneIndex=-1, bool isMultithreaded=false)
Loads via a web call the gltf file and then constructs a scene
Component to load a GLTF scene with
virtual void SetShaderForMaterialType(MaterialType type, Shader shader)
Configures shaders in the shader cache for a given material type