feat: render programmable 3d scenes cameras and picking

This commit is contained in:
2026-11-10 23:19:26 +08:00
parent 040b779f5f
commit ad2c01bc29
33 changed files with 2463 additions and 42 deletions
+35 -2
View File
@@ -421,6 +421,10 @@ impl Default for Frame {
pub struct MountGeometry {
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub canvas_viewport: bool,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub scene3d_viewport: bool,
#[serde(default)]
pub camera_controls: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub viewport_clip: Option<[f32; 4]>,
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -452,9 +456,9 @@ impl MountGeometry {
}
impl Frame {
pub fn canvas_at(&self, point: Point) -> Option<&MountGeometry> {
pub fn camera_at(&self, point: Point) -> Option<&MountGeometry> {
self.mounts.iter().rev().find(|mount| {
mount.canvas_viewport
(mount.canvas_viewport || mount.scene3d_viewport && mount.camera_controls)
&& mount.contains(point)
&& mount.viewport_clip.is_some_and(|clip| {
Rect::new(clip[0], clip[1], clip[2], clip[3]).contains(point)
@@ -483,6 +487,13 @@ fn default_background() -> String {
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RenderCommand {
Scene3D {
x: f32,
y: f32,
width: f32,
height: f32,
view: Arc<crate::scene3d::View>,
},
RoundedRect {
x: f32,
y: f32,
@@ -518,6 +529,18 @@ pub enum RenderCommand {
impl RenderCommand {
pub(crate) fn validate(&self) -> Result<()> {
match self {
Self::Scene3D {
x,
y,
width,
height,
view,
} => {
validate_rect(*x, *y, *width, *height, 0.0)?;
if !view.valid() {
bail!("invalid 3D view");
}
}
Self::RoundedRect {
x,
y,
@@ -578,6 +601,16 @@ impl RenderCommand {
fn to_draw_command(&self, scale: f32) -> Result<DrawCommand> {
Ok(match self {
Self::Scene3D {
x,
y,
width,
height,
view,
} => DrawCommand::Scene3D {
rect: scaled_rect(*x, *y, *width, *height, scale),
view: view.clone(),
},
Self::RoundedRect {
x,
y,