- Edited
kuligs2 you do know there's a label3D
node and material billboard
? right?
kuligs2 you do know there's a label3D
node and material billboard
? right?
Jesusemora Did not know such thing existed, so i just did the next best thing - improvised . Will look into it.
xyz But thats counter-intuitive. One would think that you keep that data/node with the ItemNode itself. Will have to try it out.
kuligs2 But thats counter-intuitive
Not really. It's how it's typically done. Parenting implies transformation inheritance. A label doesn't need to inherit object's transformation matrices, it just needs to follow the object. This following is often not strict. Many situations can happen where you have to nudge or adapt the label position for various reasons so the relative position from the object can vary. Also parenting will inherit rotation and scaling which you typically don't want. From logical/design standpoint the relation between an object and its label is not parent-child relation.
xyz unless we use label3D
and billboard
, then we don't have to worry about rotation, or any code at all.
Jesusemora unless we use label3D and billboard, then we don't have to worry about rotation, or any code at all.
We actually still have the rotation inheritance problem. For example if you want the label to always appear "above" the object and you position a child Label3D in that way, if you rotate the parent object for e.g. 180 degrees the label will go "below". So you still need to nullify the rotation. The parent space transformation will affect the position of the parented label which is typically what you don't want. Sure, you can set the label transforms to be top level but then all the placement code would need to be exactly the same as if it wasn't parented at all. So there's really no way to do it without some placement code.
xyz i tried your method by adding tooltip to the world (child of world) and then set transforms to the item so that it appears at the top of the object, but still i face the same problem where the label is falling behind the item placement when its going real fast.
Its pretty much the same result i had when using the tooltip inside the Item Node. This time like you say, i didnt have to set top_level = true because the rotation of the item does not affect the tooltip.
Also i used the Label3D in this example. Works fine i guess. Few less nodes to worry about.
Mu hunch for the delayed transforms is this line in the _process() function:
self.global_transform.origin = owner_node.global_transform.origin + v_offset + v_mesh_end
where v_offset
is an exported value and customizable, default 0.0 and v_mesh_end
is vertical offset of the mesh end, owner_node.global_transform.origin
is the basepoint of the Item Node at 0,0,0
Maybe setting the property .origin
is not the best practice? Maybe i should use a function, maybe translate()
or something?
kuligs2 It doesn't matter where exactly they are, just that they are executed in said order. Otherwise the label will copy object's position from the previous frame because object's current frame script hasn't yet been executed. Scripts always execute in order in which nodes appear in the tree (for siblings) and children are executed before parents. So note that you can change the order of execution by merely shuffling the nodes around. Print something from each script's _ready()
to see in what order they execute if you're not sure.
Alternatively you can do updating of both things from the same script.
xyz Printing out _ready()
ItemNode
ItemNode
ItemNode
ItemNode
ItemNode
ItemNode
ItemNode
Tooltip3dv2
Tooltip3dv2
Tooltip3dv2
Tooltip3dv2
Tooltip3dv2
Tooltip3dv2
Tooltip3dv2
--- Debugging process stopped ---
Hmm... i just noticed something. The problem is not where i set the value but the vertical offset calculation. As i ascend the slope the tooltip ascends with me
So i guess there goes my math. ..
Need few moments to catch my bug in the code... brb
EDIT: Found the bug
added -owner_node.global_transform.origin
Works good now.. need to clean up but principle is now understandable
func get_mesh_end(_owner_node:Item):
var item_mesh:MeshInstance3D = _owner_node.item_mesh
if not item_mesh == null:
var end:Vector3
var aabb = _owner_node.item_visual_node.global_transform * item_mesh.get_aabb().abs()
var size = aabb.size
var tooltip_rect = label_3d.get_aabb().abs().size
var tooltip_size = Vector3.UP * (tooltip_rect )
end = Vector3.UP * ((tooltip_size + (aabb.end )) - _owner_node.global_transform.origin)
return end
else:
return null
func set_node_size_and_position_v2(_owner_node):
if not _owner_node == null and _owner_node is Item:
if not _owner_node.item_mesh == null:
v_mesh_end = get_mesh_end(_owner_node)
self.global_transform.origin = _owner_node.global_transform.origin + v_offset + v_mesh_end #- offset
TLDR check your vectors!