Last active
October 26, 2021 17:05
-
-
Save afk-mario/5a2a7967913e4e4a51818339d486ccdc to your computer and use it in GitHub Desktop.
Custom script that modifies specular param on Godot imported 3D scenes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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