Skip to content

Commit

Permalink
project and scene environment added #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Zamme committed Jun 17, 2024
1 parent f70f77a commit a6fa42d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
42 changes: 36 additions & 6 deletions B2G3/blender2godot/b2g_tools/advanced_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
LIGHTS_INFO_FILENAME = "lights_info.json"
GODOT_PROJECT_SETTINGS_INFO_FILENAME = "godot_project_settings.json"

def Vector3ToString(_vector3):
_string = str(_vector3[0]) + "," + str(_vector3[1]) + "," + str(_vector3[2])
return _string

class my_dictionary(dict):
# __init__ function
def __init__(self):
Expand Down Expand Up @@ -317,20 +321,46 @@ def export_colliders(self, context, _scene):

def export_environment(self, context, _scene):
# TODO : sky
print("Exporting environment ...")
_dict = my_dictionary()
_sky = None
_skydict = my_dictionary()
if _scene.world:
if _scene.world.use_nodes:
_nodes = _scene.world.node_tree.nodes
for _node in _nodes:
if _node.bl_idname == "ShaderNodeBackground":
_background_color = _node.inputs[0].default_value
#_surface_input = _node.inputs["Surface"]
_color_string = str(_background_color[0]) + "," + str(_background_color[1]) + "," + str(_background_color[2])
_background_color = None
_color_string = ""
_world_nodes = _scene.world.node_tree.nodes
for _world_node in _world_nodes:
print("Scanning node:", _world_node.bl_idname)
if _world_node.bl_idname == "ShaderNodeOutputWorld":
print("World output:", _world_node.name)
_surface_socket = _world_node.inputs["Surface"]
_surface_socket_links = _surface_socket.links
for _sslink in _surface_socket_links:
if _sslink.from_node.bl_idname == "ShaderNodeBackground":
_bg_node = _sslink.from_node
_background_color = _bg_node.inputs["Color"].default_value
_bg_color_input = _bg_node.inputs["Color"]
if len(_bg_color_input.links) > 0:
if _bg_color_input.links[0].from_node.bl_idname == "ShaderNodeTexSky":
print("Sky found!", _bg_color_input.links[0].from_node.name)
_sky = _bg_color_input.links[0].from_node
if _background_color is not None:
_color_string = str(_background_color[0]) + "," + str(_background_color[1]) + "," + str(_background_color[2])
if _sky:
_skydict.add("Type", _sky.sky_type)
_skydict.add("SunDirection", Vector3ToString(_sky.sun_direction))
_skydict.add("SunElevation", _sky.sun_elevation)
_skydict.add("SunIntensity", _sky.sun_intensity)
_skydict.add("SunRotation", _sky.sun_rotation)
_skydict.add("SunSize", _sky.sun_size)
_dict.add("Sky", _skydict)
else:
_color_string = str(_scene.world.color[0]) + "," + str(_scene.world.color[1]) + "," + str(_scene.world.color[2])
_dict.add("Color", _color_string)
else:
_dict = "None"
print("Environment exported.")
return _dict

def export_game_project(self, context):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@ func create_environment(_environment_json):
var _splits = _environment_json["Color"].split(",")
var _color : Color = Color(_splits[0], _splits[1], _splits[2])
_new_environment.background_color = _color
if _environment_json.has("Sky"):
_new_environment.background_mode = Environment.BG_SKY
var _proc_sky : ProceduralSky = ProceduralSky.new()
_new_environment.background_sky = _proc_sky
_new_world_environment.environment = _new_environment
return _new_world_environment

Expand Down

0 comments on commit a6fa42d

Please sign in to comment.