46 lines
1.5 KiB
GDScript3
46 lines
1.5 KiB
GDScript3
|
@tool class_name GLTFExtrasImporterPlugin extends EditorPlugin
|
||
|
|
||
|
var importer
|
||
|
|
||
|
func _enter_tree() -> void:
|
||
|
importer = ExtrasImporter.new()
|
||
|
GLTFDocument.register_gltf_document_extension(importer)
|
||
|
|
||
|
func _exit_tree() -> void:
|
||
|
GLTFDocument.unregister_gltf_document_extension(importer)
|
||
|
|
||
|
class ExtrasImporter extends GLTFDocumentExtension:
|
||
|
func _import_post(state: GLTFState, root: Node) -> Error:
|
||
|
print("GLTFExtrasImporterPlugin called")
|
||
|
var materials_json := state.json.get(&'materials', []) as Array
|
||
|
var meshes_json := state.json.get(&'meshes', []) as Array
|
||
|
var nodes_json := state.json.get(&'nodes', []) as Array
|
||
|
var materials := state.get_materials()
|
||
|
var meshes := state.get_meshes()
|
||
|
var gltf_nodes := state.get_nodes()
|
||
|
var extras := {}
|
||
|
for i in state.get_nodes().size():
|
||
|
var gltf_node := gltf_nodes[i]
|
||
|
var node := state.get_scene_node(i)
|
||
|
var node_extras := {
|
||
|
&'node': nodes_json[i].get(&'extras', {}),
|
||
|
&'mesh': {},
|
||
|
&'surfaces': []
|
||
|
}
|
||
|
if node is MeshInstance3D or node is ImporterMeshInstance3D:
|
||
|
var j := gltf_node.mesh
|
||
|
if j >= 0:
|
||
|
node_extras[&'mesh'] = meshes_json[j].get(&'extras', {})
|
||
|
for k in node.mesh.get_surface_count():
|
||
|
var m := materials.find(
|
||
|
node.mesh.get_surface_material(k)
|
||
|
)
|
||
|
node_extras[&'surfaces'].push_back(
|
||
|
materials_json[m].get(&'extras', {}) if m >= 0
|
||
|
else {}
|
||
|
)
|
||
|
extras[root.get_path_to(node)] = node_extras
|
||
|
root.set_meta(&'extras', extras)
|
||
|
print("Meta: %s" % extras)
|
||
|
return OK
|