@@ -117,7 +117,7 @@ func try_load_cached_file(cache_key: String) -> Variant:
117117 if not FileAccess .file_exists (file_path ):
118118 return null
119119 if Util .path_is_model (file_path ):
120- return TMFileUtil . load_gltf_file_as_node (file_path , Zone . is_host () )
120+ return load_gltf_thread_task (file_path )
121121 elif Util .path_is_image (file_path ):
122122 return Util .load_image (file_path )
123123 elif Util .path_is_scene (file_path ):
@@ -132,12 +132,13 @@ func try_load_cached_file(cache_key: String) -> Variant:
132132var _cached_pairs = {}
133133
134134func load_gltf_thread_task (cache_key : String ) -> Promise :
135- for m in _model_load_queue :
136- if m . key == cache_key :
137- return m .promise
135+ if _cached_pairs . has ( cache_key ) :
136+ print ( "Cache found... not loading twice" )
137+ return _cached_pairs [ cache_key ] .promise
138138 var pair = KeyPromisePair .new ()
139139 pair .key = cache_key
140140 pair .promise = Promise .new ()
141+ _cached_pairs [pair .key ] = pair
141142
142143 if not cached_file_exists (pair .key ):
143144 pair .promise .set_error ("File does not exists, cannot load." )
@@ -146,11 +147,19 @@ func load_gltf_thread_task(cache_key: String) -> Promise:
146147 var file_path : String = get_file_path (file_name )
147148
148149 var task_id = WorkerThreadPool .add_task (func ():
149- Thread .set_thread_safety_checks_enabled (false )
150+ # future: we'll pack all the assets to .tscn and dependencies
151+ # it should be faster than packing / repacking things. maybe even .scn files.
152+ # if ResourceLoader.exists(file_path + ".tscn"):
153+ # var node = ResourceLoader.load(file_path + ".tscn").instantiate()
154+ # call_thread_safe("_cached_file_is_loaded", pair, node)
155+ # return
150156 var node = TMFileUtil .load_gltf_file_as_node (file_path , Zone .is_host ())
157+ # var scene: PackedScene = PackedScene.new()
158+ # scene.pack(node)
159+ # ResourceSaver.save(scene, file_path + ".tscn")
160+ # print("Path: ", file_path + ".tscn")
151161 call_thread_safe ("_cached_file_is_loaded" , pair , node )
152162 )
153- _cached_pairs [task_id ]
154163
155164
156165 return pair .promise
0 commit comments