Runtime Load

December 29, 2022 ยท View on GitHub

RuntimeLoad scene show you how to load avatar assets.

Simplest Method

Common Method (Auto detect whether the model is for Avatar or Scene)

await BVASceneManager.Instance.LoadAsync(path);

Avatar Optimized Load (Load synchronously)

await BVASceneManager.Instance.LoadAvatar(path);

Scene Method (Load scene in a recursive way)

await BVASceneManager.Instance.LoadSceneAsync(path);

Using Shader Loader

Before execute load method, set Shader Loader firstly.

var shaderLoader = new AssetBundleShaderLoader(Application.platform);
shaderLoader.LoadFiles(shaderAssetBundleLocation);
BVASceneManager.Instance.SetShaderLoader(shaderLoader);

General Method

if (string.IsNullOrEmpty(path)) return;
var importOptions = new ImportOptions
{
    RuntimeImport = true,
};

string directoryPath = URIHelper.GetDirectoryName(path);
importOptions.DataLoader = new CryptoZipFileLoader(directoryPath);

var Factory = ScriptableObject.CreateInstance<DefaultImporterFactory>();
var sceneImporter = Factory.CreateSceneImporter(path, importOptions);
await sceneImporter.LoadAsync();

Using Shader Loader

pass IShaderLoader to GLTFSceneImporter construction method.

public GLTFSceneImporter(string gltfFileName, ImportOptions options, IShaderLoader shaderLoader = null)

By default, BVA privide 2 Shader Loader:

  • BuildinShaderLoader
  • AssetBundleShaderLoader
var shaderLoader = new AssetBundleShaderLoader(Application.platform);
shaderLoader.LoadFiles(shaderAssetBundleLocation);

For more information, check Shader Loader

Editor Entry

Check RuntimeLoadMenu.cs dive into the details.

Import Settings

These options can be founded at GLTFSceneImporter.cs

NameTypeDescriptionDefault
MaximumLodintMaximum LOD300
IsMultithreadedboolUse Multithreading or not. In editor, this is always false. This is to prevent a freeze in editortrue
SceneParentTransformThe parent transform for the created GameObjectnull
CreatedObjectGameObjectThe last created objectnull
ColliderColliderTypeAdds colliders to primitive objects when createdNone
KeepCPUCopyOfMeshboolWhether to keep a CPU-side copy of the mesh after upload to GPU (for example, in case normals/tangents need recalculation)null
KeepCPUCopyOfTextureboolWhether to keep a CPU-side copy of the texture after upload to GPUnull
GenerateMipMapsForTexturesboolSpecifies whether the MipMap chain should be generated for model texturesnull
EnableEnvironmentReflectionboolSpecifies whether Environment Reflection should be enabled for materialsnull
EnableSpecularHighlightboolSpecifies whether Specular Highlight should be enabled for materialsnull
CullFarLODboolWhen screen coverage is above threashold and no LOD mesh cull the objectnull