Add headless wgpu vision and camera controls
This commit is contained in:
@@ -746,6 +746,82 @@ impl crate::behavior::EmbodimentSink for LibremetaverseEmbodimentSink {
|
||||
.map_err(|_| crate::behavior::BehaviorError::NativeOperation)
|
||||
})
|
||||
}
|
||||
|
||||
fn set_camera(
|
||||
&self,
|
||||
generation: u64,
|
||||
position: crate::perception::WorldPosition,
|
||||
target: crate::perception::WorldPosition,
|
||||
vertical_fov_degrees: f64,
|
||||
cancellation: CancellationToken,
|
||||
) -> crate::behavior::EmbodimentFuture<'_, ()> {
|
||||
Box::pin(async move {
|
||||
if cancellation.is_cancellation_requested() {
|
||||
return Err(crate::behavior::BehaviorError::Cancelled);
|
||||
}
|
||||
self.ensure_generation(generation)?;
|
||||
self.agent
|
||||
.movement
|
||||
.camera
|
||||
.look_at_with_vector3_vector3(
|
||||
libremetaverse_types::Vector3 {
|
||||
x: position.x as f32,
|
||||
y: position.y as f32,
|
||||
z: position.z as f32,
|
||||
},
|
||||
libremetaverse_types::Vector3 {
|
||||
x: target.x as f32,
|
||||
y: target.y as f32,
|
||||
z: target.z as f32,
|
||||
},
|
||||
)
|
||||
.map_err(|_| crate::behavior::BehaviorError::NativeOperation)?;
|
||||
self.agent
|
||||
.movement
|
||||
.set_fov_vertical_angle((vertical_fov_degrees as f32).to_radians())
|
||||
.and_then(|()| self.agent.movement.send_update_with_boolean(Some(true)))
|
||||
.map_err(|_| crate::behavior::BehaviorError::NativeOperation)
|
||||
})
|
||||
}
|
||||
|
||||
fn reset_camera(
|
||||
&self,
|
||||
generation: u64,
|
||||
cancellation: CancellationToken,
|
||||
) -> crate::behavior::EmbodimentFuture<'_, ()> {
|
||||
Box::pin(async move {
|
||||
if cancellation.is_cancellation_requested() {
|
||||
return Err(crate::behavior::BehaviorError::Cancelled);
|
||||
}
|
||||
self.ensure_generation(generation)?;
|
||||
let avatar = self.agent.sim_position();
|
||||
let forward = libremetaverse_types::Vector3::mul_with_vector3_quaternion(
|
||||
libremetaverse_types::Vector3::unit_x(),
|
||||
self.agent.sim_rotation(),
|
||||
);
|
||||
let position = libremetaverse_types::Vector3 {
|
||||
x: avatar.x,
|
||||
y: avatar.y,
|
||||
z: avatar.z + 1.6,
|
||||
};
|
||||
let target = libremetaverse_types::Vector3 {
|
||||
x: position.x + forward.x * 4.0,
|
||||
y: position.y + forward.y * 4.0,
|
||||
z: position.z + forward.z * 4.0,
|
||||
};
|
||||
self.agent
|
||||
.movement
|
||||
.camera
|
||||
.look_at_with_vector3_vector3(position, target)
|
||||
.and_then(|()| {
|
||||
self.agent
|
||||
.movement
|
||||
.set_fov_vertical_angle(60.0_f32.to_radians())
|
||||
})
|
||||
.and_then(|()| self.agent.movement.send_update_with_boolean(Some(true)))
|
||||
.map_err(|_| crate::behavior::BehaviorError::NativeOperation)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "live-grid")]
|
||||
|
||||
Reference in New Issue
Block a user