-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node3D: Allow using global transform when not inside tree #70443
base: master
Are you sure you want to change the base?
Node3D: Allow using global transform when not inside tree #70443
Conversation
c8da9d9
to
1005897
Compare
Did some testing, I'm not sure what I documented is true. Would need to flag the global transform as dirty when exiting the tree to force recomputing the out-of-tree "global" transform. |
1005897
to
74eda28
Compare
74eda28
to
d8ad160
Compare
Did that, and it seems to work as I'd expect it, in a very simple test. I don't do much 3D so I'd appreciate more extensive testing from others. Here's how I tested so far: extends Node3D
var room: Node3D
var cube: MeshInstance3D
func _ready():
room = Node3D.new()
add_child(room)
room.transform.origin = Vector3(1, 10, 100)
cube = MeshInstance3D.new()
cube.mesh = BoxMesh.new()
room.add_child(cube)
cube.transform.origin = Vector3(4, 40, 400)
var count = 0
func _process(delta):
count += 1
if count % 60 == 0:
print("Cube Local: " + var_to_str(cube.transform))
print("Cube Global: " + var_to_str(cube.global_transform))
# 60 prints base state
if count == 90:
print("### Adding (2, 20, 200) to in-tree global position.")
cube.global_transform.origin += Vector3(2, 20, 200)
# 120 prints change
if count == 150:
print("### Removing from tree.")
room.remove_child(cube)
# 180 prints change
if count == 210:
print("### Adding (2, 20, 200) to out-of-tree global position.")
cube.global_transform.origin += Vector3(2, 20, 200)
# 240 prints change
if count == 270:
print("### Reparent to tree.")
room.add_child(cube)
# 300 prints change
if count == 330:
get_tree().quit() Prints:
I also had to run the |
I can only give rough feedback as away from home for xmas on tablet but im in favour of something like this. There are two obvious variations:
They both have advantages and disadvantages but i would probably tend towards the approach in this pr .. it is arguable either way. |
@Zylann I think you were looking for something like this. |
🤔 shouldn't a node without (connected) parent always have a global initial state of zero? With current patch:
|
No. That's kind of the point of having out of tree global transforms. |
At least from the logic standpoint, the global transformation in nowhere doesn't make much sense and can probably just be ignored. For a global transformation (which does what it says in the name), you could always attach it to a temporary parent. No? |
This is perhaps why this was treated as an error before, it seems you are misunderstanding the coordinate spaces, and perhaps this will be a common problem with users. Maybe we could use a different function name, like
I wonder whether a way to address this might be to make the main function |
Edit: I thought the behaviors were intentional and not a bug. Some tests with sub-nodes
|
I wasn't quite sure immediately what you meant, but there is indeed a bug (which occurs on my PR too which is just a variation on this one). When calling
I'll see how this can be fixed, it's kind of strange behaviour I'm not sure why the parent is not set immediately on Yes it seems that the current paradigm is that the This same behaviour occurs in 3.x, so it seems historical. Interestingly the This c++ code triggers the bug:
We can probably solve this by moving some of the |
Ok I've now got a tentative fix in my version of this PR (#74659), see the It will be up to @akien-mga how he wants to fix this in this PR. @capnm If you want to test my PR that would be useful, as the two PRs are intended to be essentially the same (bar the renaming of the function for the out-of-tree version). |
Bad joke, I take it back. |
I can't alter @akien-mga 's PR, only provide a possible fix as I have done above. Just to reiterate .. I have no particular preference for one name over the other - Using the existing name is simpler technically, but on the downside:
|
Technically you can, all maintainers can check out a PR branch locally, amend it, and force push to the PR author's remote (unless the PR author specifically disallowed it when opening the PR). I kind of lost oversight on this PR, I'm happy to go with any consensual solution :) |
Complements #67710.
Fixes #30445.