Add basic SpotLight instancing#249
Conversation
50396df to
a712969
Compare
a712969 to
79bf9a6
Compare
| if parent == null: | ||
| return | ||
| var light_root = parent.get_parent() | ||
| var is_end = parent.name.begins_with("end") |
There was a problem hiding this comment.
I'm not sure about this parent-child relation and hardcoded names of related nodes.
There was a problem hiding this comment.
Me neither, but that's the best I could come up with. Also _end is a part of their standard naming of light-related nodes
There was a problem hiding this comment.
- I think that e3d_light contains logic which should be moved to e3d instancing or e3d parsing stage.
- MaSzyna quirks like matching something by part of a node name should be configurable. Please note that node name in Godot can be different than e3d (sub)model name.
- E3D Light in this implementation will be always a spotlight. You never be able to create omni lights or other lights. That's why it is better to move nodes creation to the factories like e3d nodes instancer.
- At the e3d parsing stage you can traverse e3d model tree to find parent-child relationships between submodels, if needed.
- Try to store references between e3d submodels in thei, i.e. add properties similar to nodepath (you can't use nodepath though, but a reference to other node should work)
| func _ready(): | ||
| _update_state() | ||
|
|
||
| func _update_state(): |
There was a problem hiding this comment.
I think the high level API for lights control should be on E3DModelInstance, which is a node proxy for instancer and a reference holder for a e3d model.
Optimised instancer will not use this node. It will control lights by calling RenderingServer directly.
| for light in lights: | ||
| var base_name = light.name.to_lower() | ||
|
|
||
| var on_suffixes = ["_on", "_xon"] |
There was a problem hiding this comment.
Instancer should work with a structure resolved by parser. E3dmodel should have references to light nodes. We shouldn't implement e3d quirks here like finding node by specific name
|
|
||
| E3DSubModel.SubModelType.SUBMODEL_FREE_SPOTLIGHT: | ||
| obj = SpotLight3D.new() | ||
| obj.set_script(preload("res://addons/libmaszyna/e3d/e3d_light.gd")) |
There was a problem hiding this comment.
So I don't understand why we're using set_script and preloading instead of classes like MyCustomClass.new()
| <member name="light_range" type="float" setter="set_light_range" getter="get_light_range" default="0.0"> | ||
| The maximum range of the light source. | ||
| </member> | ||
| <member name="near_atten_start" type="float" setter="set_near_atten_start" getter="get_near_atten_start" default="0.0"> |
There was a problem hiding this comment.
Please use full names instead of shortcuts
|
It's almost fine. I would like to move lights controller to e3dmodelinstance, which will delegate lights handling to a selected instancer. E3DSpotlight node is probably unnecessary. I think the code is partially AI assisted. Please clean the code before next review (inconsistent naming, preloading scripts inside the logic code, using set_script etc) |
marcinn
left a comment
There was a problem hiding this comment.
Stil, I think that references to lights / array of lights should be implemented at the resource layer (e3dmodel/e3dsubmodel). Instancer should only fetch the lights and apply transforms if needed.
Also there should be a kind of high level API for toggling lights - E3DModelInstance should be a good place, because it is a connector between e3d model and instancer. E3DModelInstance should delegate light control to instancer, same as instantiating and cleaning up.
This PR is not handling texture based lights. We can split this, of course, but thinking about submodels with emissive materials as lights (instead of spotlights) should be helpful for designing the lights api.
|
|
||
| E3DSubModel.SubModelType.SUBMODEL_FREE_SPOTLIGHT: | ||
| obj = SpotLight3D.new() | ||
| obj.set_script(preload("res://addons/libmaszyna/e3d/e3d_light.gd")) |
There was a problem hiding this comment.
So I don't understand why we're using set_script and preloading instead of classes like MyCustomClass.new()
| if parent == null: | ||
| return | ||
| var light_root = parent.get_parent() | ||
| var is_end = parent.name.begins_with("end") |
There was a problem hiding this comment.
- I think that e3d_light contains logic which should be moved to e3d instancing or e3d parsing stage.
- MaSzyna quirks like matching something by part of a node name should be configurable. Please note that node name in Godot can be different than e3d (sub)model name.
- E3D Light in this implementation will be always a spotlight. You never be able to create omni lights or other lights. That's why it is better to move nodes creation to the factories like e3d nodes instancer.
- At the e3d parsing stage you can traverse e3d model tree to find parent-child relationships between submodels, if needed.
- Try to store references between e3d submodels in thei, i.e. add properties similar to nodepath (you can't use nodepath though, but a reference to other node should work)
| if not child: | ||
| continue | ||
|
|
||
| if child.has_method("_update_state"): |
There was a problem hiding this comment.
this is not a property which identifies the light. you're assuming here that any object with "_update_state" is a light.
| if child is Node3D and submodel.transform: | ||
| var child_node:Node3D = child as Node3D | ||
| child_node.transform = submodel.transform | ||
| if child is SpotLight3D: |
There was a problem hiding this comment.
This code assumes that there is only one type of light - a SpotLight3D, not even E3DLight. Checking E3DSubModel.SubModelType.SUBMODEL_FREE_SPOTLIGHT will be consistent with _create_submodel_instance() impl.
f863cac to
b197cc2
Compare
193e997 to
175af9e
Compare
Fixes #134