Skip to content

Commit

Permalink
fix: animator, player transform, audio source out of the scene and Te…
Browse files Browse the repository at this point in the history
…xtShape align (#491)

* fix: animator controller regression
fix: player.avatar for calculate PlayerEntity transform
fix: TextShape size not dismissed for non wrapping ones

* fix: player node reference
fix: AudioSource not updating volume_db until it's moving
  • Loading branch information
leanmendoza authored Nov 13, 2024
1 parent fb70332 commit a4a494a
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 37 deletions.
8 changes: 4 additions & 4 deletions godot/default_bus_layout.tres
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ resource_name = "Amplify"
resource_name = "Capture"

[resource]
bus/0/volume_db = 0.0672607
bus/0/volume_db = 0.0
bus/1/name = &"Scene"
bus/1/solo = false
bus/1/mute = false
bus/1/bypass_fx = false
bus/1/volume_db = 0.0672607
bus/1/volume_db = 0.0
bus/1/send = &""
bus/2/name = &"VoiceChat"
bus/2/solo = false
bus/2/mute = false
bus/2/bypass_fx = false
bus/2/volume_db = 0.0672607
bus/2/volume_db = 0.0
bus/2/send = &""
bus/3/name = &"UI"
bus/3/solo = false
bus/3/mute = false
bus/3/bypass_fx = false
bus/3/volume_db = 0.0672607
bus/3/volume_db = 0.0
bus/3/send = &""
bus/4/name = &"Music"
bus/4/solo = false
Expand Down
10 changes: 6 additions & 4 deletions godot/src/decentraland_components/audio_source.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ func apply_audio_props(action_on_playing: bool):
attenuation_model = AudioStreamPlayer3D.ATTENUATION_INVERSE_DISTANCE

if not dcl_enable:
self.volume_db = -80
self.max_db = -100
else:
# TODO: Check if it should be 10 instead 20 to talk in terms of power
self.volume_db = 20 * log(dcl_volume)
# -80 = 20 log 0.00001, so muted is when (volume <= 0.00001)
self.max_db = 0

# TODO: Check if it should be 10 instead 20 to talk in terms of power
self.volume_db = 20 * log(dcl_volume)
# -80 = 20 log 0.00001, so muted is when (volume <= 0.00001)

if action_on_playing:
if self.playing and not dcl_playing:
Expand Down
16 changes: 10 additions & 6 deletions godot/src/test/testing_api.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var scene_tests: Array[SceneTestItem] = []
var realm_change_emited: bool = false

var test_camera_node: DclCamera3D
var test_player_node: Node3D
var test_player_body_node: Node3D

var snapshot_folder: String = ""
var snapshot_comparison_folder: String = ""
Expand Down Expand Up @@ -124,10 +124,14 @@ func on_realm_changed():
self.process_mode = Node.PROCESS_MODE_ALWAYS

test_camera_node = Global.scene_runner.camera_node
test_player_node = Global.scene_runner.player_node
test_player_body_node = Global.scene_runner.player_body_node
var test_player_avatar_node = Global.scene_runner.player_avatar_node

Global.scene_runner.set_camera_and_player_node(
test_camera_node, test_player_node, self._on_scene_console_message
test_camera_node,
test_player_avatar_node,
test_player_body_node,
self._on_scene_console_message
)
Global.scene_fetcher.set_scene_radius(0)

Expand Down Expand Up @@ -194,8 +198,8 @@ func async_take_and_compare_snapshot(
avatar.hide()
avatar.emote_controller.freeze_on_idle()

Global.scene_runner.player_node.avatar.emote_controller.freeze_on_idle()
Global.scene_runner.player_node.avatar.hide()
Global.scene_runner.player_avatar_node.emote_controller.freeze_on_idle()
Global.scene_runner.player_avatar_node.hide()

await get_tree().process_frame
await get_tree().process_frame
Expand Down Expand Up @@ -287,7 +291,7 @@ func _process(_delta):
if not scene.already_telep:
scene.already_telep = true
scene.reset_timeout()
test_player_node.global_position = Vector3(
test_player_body_node.global_position = Vector3(
scene.parcel_position.x * 16.0 + 8.0,
1.0,
-scene.parcel_position.y * 16.0 - 8.0
Expand Down
16 changes: 10 additions & 6 deletions godot/src/tool/scene_renderer/scene_orchestor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var scene_already_telep: bool = false
var realm_change_emited: bool = false

var test_camera_node: DclCamera3D
var test_player_node: Node3D
var test_player_body_node: Node3D
var test_camera_tune: bool = false
var test_camera_tune_base_position: Vector3

Expand Down Expand Up @@ -140,10 +140,14 @@ func on_realm_changed():
self.process_mode = Node.PROCESS_MODE_ALWAYS

test_camera_node = Global.scene_runner.camera_node
test_player_node = Global.scene_runner.player_node
test_player_body_node = Global.scene_runner.player_body_node
var test_player_avatar_node = Global.scene_runner.player_avatar_node

Global.scene_runner.set_camera_and_player_node(
test_camera_node, test_player_node, self._on_scene_console_message
test_camera_node,
test_player_avatar_node,
test_player_body_node,
self._on_scene_console_message
)
Global.scene_fetcher.set_scene_radius(0)
Global.comms.change_adapter("offline")
Expand Down Expand Up @@ -194,7 +198,7 @@ func _on_timer_timeout():

match current_payload_state:
PayloadState.NONE:
test_player_node.global_position = Vector3(
test_player_body_node.global_position = Vector3(
scene.coords.x * 16.0 + 8.0, 1.0, -scene.coords.y * 16.0 - 8.0
)

Expand Down Expand Up @@ -305,8 +309,8 @@ func async_take_camera_photo(input: SceneRendererInputHelper.SceneRendererInputS
avatar.hide()
avatar.emote_controller.freeze_on_idle()

Global.scene_runner.player_node.avatar.emote_controller.freeze_on_idle()
Global.scene_runner.player_node.avatar.hide()
Global.scene_runner.player_avatar_node.emote_controller.freeze_on_idle()
Global.scene_runner.player_avatar_node.hide()

await get_tree().process_frame
await get_tree().process_frame
Expand Down
2 changes: 1 addition & 1 deletion godot/src/ui/components/chat/chat.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func on_chats_arrived(chats: Array):
var avatar = Global.avatars.get_avatar_by_address(address)
if avatar == null:
if address == Global.player_identity.get_address_str():
avatar = Global.scene_runner.player_node.avatar
avatar = Global.scene_runner.player_avatar_node

var avatar_name: String = ""
if avatar != null:
Expand Down
7 changes: 3 additions & 4 deletions godot/src/ui/explorer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,11 @@ func _ready():
player.look_at(16 * Vector3(start_parcel_position.x + 1, 0, -(start_parcel_position.y + 1)))

Global.scene_runner.camera_node = player.camera
Global.scene_runner.player_node = player
Global.scene_runner.player_avatar_node = player.avatar
Global.scene_runner.player_body_node = player
Global.scene_runner.console = self._on_scene_console_message
Global.scene_runner.pointer_tooltip_changed.connect(self._on_pointer_tooltip_changed)
Global.scene_runner.player_node.avatar.emote_triggered.connect(
Global.scene_runner.on_primary_player_trigger_emote
)
player.avatar.emote_triggered.connect(Global.scene_runner.on_primary_player_trigger_emote)
ui_root.add_child(Global.scene_runner.base_ui)
ui_root.move_child(Global.scene_runner.base_ui, 0)

Expand Down
21 changes: 20 additions & 1 deletion lib/src/godot_classes/animator_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl MultipleAnimationController {
anim_item.time_param_ref_str.clone(),
playing_time.to_variant(),
));
self.finished_animations.insert(anim_name.clone());
}

if !looping {
Expand Down Expand Up @@ -163,6 +164,22 @@ impl MultipleAnimationController {
.unwrap_or(&0.0)
};

changes.push((
anim_state.time_param_ref_str.clone(),
playing_time.to_variant(),
));
} else if self.finished_animations.contains(&new_state.clip) {
self.finished_animations.remove(&new_state.clip);

let playing_time = if !anim_state.value.playing_backward() {
0.0
} else {
*self
.existing_anims_duration
.get(&anim_state.value.clip)
.unwrap_or(&0.0)
};

changes.push((
anim_state.time_param_ref_str.clone(),
playing_time.to_variant(),
Expand Down Expand Up @@ -211,7 +228,9 @@ impl MultipleAnimationController {
} else {
let time = self.base().get(anim_state.time_param_ref_str.clone());
if let Ok(time) = time.try_to::<f32>() {
self.current_time.insert(anim.clip.clone(), time);
if time > 0.0 {
self.current_time.insert(anim.clip.clone(), time);
}
}
}

Expand Down
14 changes: 11 additions & 3 deletions lib/src/scene_runner/components/text_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,19 @@ pub fn update_text_shape(scene: &mut Scene, crdt_state: &mut SceneCrdtState) {
label_3d.set_font_size(font_size as i32);
label_3d.set_outline_size(outline_size as i32);
label_3d.set_outline_modulate(outline_color);
label_3d.set_alpha_cut_mode(AlphaCutMode::OPAQUE_PREPASS);
label_3d.set_alpha_cut_mode(AlphaCutMode::DISCARD);

let text_wrapping = new_value.text_wrapping.unwrap_or_default();

let (width_meter, height_meter) = if text_wrapping {
(
new_value.width.unwrap_or(0.0),
new_value.height.unwrap_or(0.0),
)
} else {
(0.0, 0.0)
};

if text_wrapping {
label_3d.set_autowrap_mode(AutowrapMode::WORD_SMART);
label_3d.set_width(200.0 * new_value.width.unwrap_or(16.0));
Expand Down Expand Up @@ -122,8 +132,6 @@ pub fn update_text_shape(scene: &mut Scene, crdt_state: &mut SceneCrdtState) {
| TextAlignMode::TamBottomCenter => (HorizontalAlignment::CENTER, 0.0),
};

let width_meter = new_value.width.unwrap_or(0.0);
let height_meter = new_value.width.unwrap_or(0.0);
label_3d.set_position(Vector3::new(width_meter * x_pos, height_meter * y_pos, 0.0));
label_3d.set_vertical_alignment(v_align);
label_3d.set_horizontal_alignment(h_align);
Expand Down
22 changes: 14 additions & 8 deletions lib/src/scene_runner/scene_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ pub struct SceneManager {
camera_node: Option<Gd<Camera3D>>,

#[export]
player_node: Gd<Node3D>,
player_avatar_node: Gd<Node3D>,

#[export]
player_body_node: Gd<Node3D>,

#[var]
console: Callable,
Expand Down Expand Up @@ -259,11 +262,13 @@ impl SceneManager {
fn set_camera_and_player_node(
&mut self,
camera_node: Gd<Camera3D>,
player_node: Gd<Node3D>,
player_avatar_node: Gd<Node3D>,
player_body_node: Gd<Node3D>,
console: Callable,
) {
self.camera_node = Some(camera_node.clone());
self.player_node = player_node.clone();
self.player_avatar_node = player_avatar_node.clone();
self.player_body_node = player_body_node.clone();
self.console = console;
}

Expand Down Expand Up @@ -332,7 +337,7 @@ impl SceneManager {
fn compute_scene_distance(&mut self) {
self.current_parcel_scene_id = SceneId::INVALID;

let mut player_global_position = self.player_node.get_global_transform().origin;
let mut player_global_position = self.player_avatar_node.get_global_transform().origin;
player_global_position.x *= 0.0625;
player_global_position.y *= 0.0625;
player_global_position.z *= -0.0625;
Expand Down Expand Up @@ -369,7 +374,7 @@ impl SceneManager {
}
let camera_node = self.camera_node.clone().unwrap();

let player_global_transform = self.player_node.get_global_transform();
let player_global_transform = self.player_avatar_node.get_global_transform();
let camera_global_transform = camera_node.get_global_transform();

let camera_node = camera_node.try_cast::<DclCamera3D>();
Expand Down Expand Up @@ -718,7 +723,7 @@ impl SceneManager {
let scene_position = scene.godot_dcl_scene.root_node_3d.get_position();
let raycast_data = RaycastHit::from_godot_raycast(
scene_position,
self.player_node.get_position(),
self.player_avatar_node.get_position(),
&raycast_result,
Some(dcl_entity_id as u32),
)?;
Expand Down Expand Up @@ -964,7 +969,8 @@ impl INode for SceneManager {
thread_sender_to_main,

camera_node: None,
player_node: Node3D::new_alloc(),
player_avatar_node: Node3D::new_alloc(),
player_body_node: Node3D::new_alloc(),

player_position: Vector2i::new(-1000, -1000),

Expand Down Expand Up @@ -1089,7 +1095,7 @@ impl INode for SceneManager {
.godot_dcl_scene
.get_node_or_null_3d_mut(&SceneEntityId::PLAYER)
{
player_node.set_global_transform(self.player_node.get_global_transform());
player_node.set_global_transform(self.player_avatar_node.get_global_transform());
}

if let Some(camera_node) = scene
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a4a494a

Please sign in to comment.