Does anyone know if there is a method, on gdscript side, to do what EditorFileSystem::_reimport_file basically does with the custom_options field?
I want to set the material of a glTF to point to an external material. So I assume need to write use_external/enabled = true and use_external/path = some_path; or is there another method how one point it to the new material resource?
I don’t think that functionality is exposed to the scripting language.
You can use an EditorScenePostImport script to modify the imported scene as you need.
For example:
@tool
extends EditorScenePostImport
func _post_import(scene):
iterate(scene)
return scene
func iterate(node):
if node != null:
if node is MeshInstance3D:
# Create a static body
var body = StaticBody3D.new()
# Generate a convex collision shape from the mesh
var shape = CollisionShape3D.new()
var collision_shape = node.mesh.create_convex_shape(true, true)
shape.shape = collision_shape
# Add the shape to the created static body
body.add_child(shape, true)
# Add the static body as a child of the node
node.add_child(body, true)
# Configure the collision layers and masks
body.set_collision_layer_value(1, true)
body.set_collision_mask_value(1, true)
# Set the owner property of the body and shape to the node's owner
body.owner = node.owner
shape.owner = node.owner
# Override the materials of the mesh with a custom material
var mesh:Mesh = node.mesh
for i in mesh.get_surface_count():
mesh.surface_set_material(i, preload("res://assets/kaykit dungeon/dungeon_material.tres"))
# Keep iterating
for child in node.get_children():
iterate(child)
I had a look at import plugins but still got stuck and can not do what I actually want to; which is bascially same as the advanced import window’s Extract action; just in bulk/batch.
So my options seem to generate inherited scenes and set the materials in there or messing with the .import file directly.
[edit] Oh I see you are talking about post import plugin. I’ll have a look into it first.
[edit2] Ye, a post import will be good enough for what I am trying to do and fits into the workflow. Thanks for the suggestion.
One problem I found is that if I rename the material and do a reimport I’d loose that link with the new material since the name of the material discovered via mesh.SurfaceGetMaterial is still the original one. I guess the info from mesh.SurfaceSetMaterial is saved to .godot.
I tested that too and deleting the .godot folder would revert the mesh to using the original material. So I am guessing restoring the project from git or backup would be a mess since .godot does not go into the backups.
use_external/enabled = true and use_external/path = some_path would be ideal since that info is in the .import file next to the .glb.