Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom script that modifies specular param on Godot imported 3D scenes.
tool
extends EditorScenePostImport
enum LogLevelEnum { QUIET, VERBOSE }
var log_level :int = LogLevelEnum.VERBOSE
export var specular := 0
func post_import(scene):
talk("Setting custom specular on Spatial Materials...")
iterate(scene)
return scene
func iterate(node):
if node == null:
return node
if "mesh" in node:
talk("Found mesh on: %s" % node.name)
handleMesh(node.mesh)
for child in node.get_children():
iterate(child)
func handleMesh(mesh: Mesh):
var surfacesCount :int= mesh.get_surface_count()
for i in range(surfacesCount):
handleMaterial(mesh.surface_get_material(i))
func handleMaterial(material: SpatialMaterial):
talk("Material %s modifiying..." % material.resource_name)
talk("Specular before: %s" % material.metallic_specular)
material.metallic_specular = specular
talk("Specular after: %s" % material.metallic_specular)
material.emit_changed()
var error = ResourceSaver.save(material.resource_path, material)
if error:
push_error(error)
func talk(message):
if log_level != LogLevelEnum.VERBOSE:
return
print(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment