diff --git a/packages/ludic.render3d/env.ludic b/packages/ludic.render3d/env.ludic index 777766e3..ddd97122 100644 --- a/packages/ludic.render3d/env.ludic +++ b/packages/ludic.render3d/env.ludic @@ -108,6 +108,10 @@ export state Render3dState { gltf_mat_nrm: words = null gltf_mat_arm: words = null gltf_mat_n: int = 0 + gltf_kept: []Model = null # gltf_cached's: a still model by dir, file and node, loaded once + gltf_kept_dir: []string = null + gltf_kept_file: []string = null + gltf_kept_node: []string = null gltf_cutout: bool = false # the material being loaded is alpha-blended (a cut-out atlas) gpu_kind: int = 0 # the backend running; 0 until gpu_select gpu_wanted: int = 0 # what was asked for (setting or R3D_GFX) diff --git a/packages/ludic.render3d/gltf_cached.ludic b/packages/ludic.render3d/gltf_cached.ludic new file mode 100644 index 00000000..7ae57cfe --- /dev/null +++ b/packages/ludic.render3d/gltf_cached.ludic @@ -0,0 +1,27 @@ +# gltf_cached.ludic - a still model loaded once: the same (dir, file, node) asked again hands back the +# model the first load made, found by comparing the names in place, so asking allocates nothing. For +# props a game places while it plays (a fish, a sign an animal leaves); a model whose document is +# read after the load (ludic.anim's clips) still goes through gltf_load. A model loaded here is shared +# by every actor drawing it, and is never released. +export function gltf_cached(render3d_st: mut Render3dState, dir: string, file: string, node_name: string) -> Model { + if render3d_st.gltf_kept == null { + render3d_st.gltf_kept = new []Model + render3d_st.gltf_kept_dir = new []string + render3d_st.gltf_kept_file = new []string + render3d_st.gltf_kept_node = new []string + } + for i in 0 .. len(render3d_st.gltf_kept) { + if render3d_st.gltf_kept_node[i] == node_name and render3d_st.gltf_kept_file[i] == file and render3d_st.gltf_kept_dir[i] == dir { return render3d_st.gltf_kept[i] } + } + let m = gltf_load(render3d_st, dir, file, node_name) + push(render3d_st.gltf_kept, m) + push(render3d_st.gltf_kept_dir, dir) + push(render3d_st.gltf_kept_file, file) + push(render3d_st.gltf_kept_node, node_name) + return m +} + +export function gltf_cached_count(render3d_st: Render3dState) -> int { + if render3d_st.gltf_kept == null { return 0 } + return len(render3d_st.gltf_kept) +} diff --git a/packages/ludic.render3d/r3d.ludic b/packages/ludic.render3d/r3d.ludic index 695579ff..a3bde3fa 100644 --- a/packages/ludic.render3d/r3d.ludic +++ b/packages/ludic.render3d/r3d.ludic @@ -29,6 +29,7 @@ import "post.ludic" import "quat.ludic" import "gltf.ludic" import "gltf_release.ludic" +import "gltf_cached.ludic" import "skin.ludic" import "scatter.ludic" import "actor.ludic"