Add class names to HTerrain and HTerrainDetailLayer
jkulawik opened this issue · 2 comments
Is your feature request related to a problem? Please describe.
I need to differentiate HTerrain nodes (and perhaps HTerrainDetailLayer too) from other nodes.
Describe the solution you'd like
Adding class_name
to both of these should be sufficient. Then you can do if node is HTerrain
.
Describe alternatives you've considered
Maybe a naming scheme could be used, but as far as I know, there's no way of checking a node's in-editor name. Besides, this is an effortless addition, however I imagine there might be compatibility issues.
Additional context
I'm trying to make a system which detects what the player is standing on to play an appropriate step sound.
There are 2 options:
- structure nodes in a way that allows consistent access from collider to the mesh, and then get the material of the mesh. Choose the sound based on that.
- Attach a node which holds the material type to colliders and work from there
Neither of these will work with this plugin: the different textures don't use separate materials and the second system fails altogether here.
My idea is to get the splatmap, find the color under the player and then proceed based on the colour. But this requires making sure that the node under the player is HTerrain
I'm also considering using the HTerrainDetailLayer data to check if the player is hiding in bushes (for stealth mechanics).
PS. There are two features related to this that would be awesome:
- translating a global transform into a position on the splatmap
- the ability to get the texture (or detail map) based on coords
I will probably post them as separate issues, either with code or without depending on whether I manage to tackle this.
Finally, a quick question:
Will different shaders (Classic4 or MultiSplat16) require separate handling? I imagine that MultiSplat16 uses 4 different images, so getting the texture will probably require accessing the logic that mixes them into the final result.
Oh, also please inform me if there's something like that already in the code and I'm reinventing the wheel
I don't understand how giving a global class_name
to HTerrain solves anything in your presented use case. If you need that in a script, you can write this on top:
const HTerrain = preload("res://addons/zylann.hterrain/hterrain.gd")
And anywhere in your script you become allowed to do if node is HTerrain
. You can do that in multiple scripts too and will still work.
You could also give a special collision layer to your terrain so you can filter collisions and know what hits what.
translating a global transform into a position on the splatmap
It's easily done with terrain.get_internal_transform().affine_inverse() * global_position
. Just make sure it's also within bounds. Maybe a convenience function could be added for a bit more clarity.
the ability to get the texture (or detail map) based on coords
Already asked here #285
Will different shaders (Classic4 or MultiSplat16) require separate handling?
Yes.
You are asking multiple unrelated questions and requests here, I recommend checking existing issues or creating separate ones for it to be easier to track.
Thanks for answering my tacked-on questions, hopefully won't be needing additional issues for them with what you've given me.
I don't understand how giving a global class_name to HTerrain solves anything in your presented use case. If you need that in a script, you can write this on top:
const HTerrain = preload("res://addons/zylann.hterrain/hterrain.gd")
Surprisingly, that works (even though I'm not sure how). I wasn't aware that it's a thing, thanks!