1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Declarative 3D Canvas Viewport extraction and DrawViewport3D command generation.
use super::*;
impl AppRuntime {
/// Extracts declarative or programmatic 3D canvas viewports when not already emitted by [`Compositor`].
pub fn render_canvas_3d_scenes(&mut self) {
if self.display_list.commands.iter().any(|cmd| {
matches!(
cmd,
strata_render::compositor::DrawCommand::DrawViewport3D { .. }
)
}) {
return;
}
Self::collect_canvas_3d_recursive(
&self.root_blueprint,
&self.layout_root,
&mut self.display_list.commands,
);
}
fn collect_canvas_3d_recursive(
blueprint: &NodeBlueprint,
layout_node: &LayoutNode,
commands: &mut Vec<strata_render::compositor::DrawCommand>,
) {
match blueprint {
NodeBlueprint::Element {
tag,
attributes,
children,
..
} => {
let has_scene_payload = attributes
.iter()
.any(|a| matches!(a, strata_dom::Attribute::ScenePayload(_)));
let is_3d_canvas = has_scene_payload
|| (matches!(tag, Tag::Canvas | Tag::Custom("Canvas3D"))
&& (attributes.iter().any(|a| {
matches!(a, strata_dom::Attribute::Property { key, value } if key == "data-strata-canvas3d" && value == "true")
}) || children.iter().any(|c| match c {
NodeBlueprint::Element {
tag: Tag::Custom(name),
..
} => matches!(
*name,
"PerspectiveCamera"
| "OrthographicCamera"
| "AmbientLight"
| "DirectionalLight"
| "PointLight"
| "Mesh"
| "BoxGeometry"
| "SphereGeometry"
| "PlaneGeometry"
| "CylinderGeometry"
| "StandardMaterial"
| "ShaderMaterial"
),
_ => false,
})));
if is_3d_canvas {
let scene = strata_render::scene3d::compile_scene3d_from_blueprint(blueprint);
let bounds = if layout_node.geometry.content_box.width > 0.0
&& layout_node.geometry.content_box.height > 0.0
{
layout_node.geometry.content_box
} else {
layout_node.geometry.border_box
};
commands.push(strata_render::compositor::DrawCommand::DrawViewport3D {
bounds,
scene: std::sync::Arc::new(scene),
});
if matches!(tag, Tag::Canvas | Tag::Custom("Canvas3D")) {
return;
}
}
let mut flat_children = Vec::new();
for c in children {
Self::flatten_blueprints(c, &mut flat_children);
}
for (child_bp, child_layout) in
flat_children.iter().zip(layout_node.children.iter())
{
Self::collect_canvas_3d_recursive(child_bp, child_layout, commands);
}
}
NodeBlueprint::Fragment(children) => {
let mut flat_children = Vec::new();
for c in children {
Self::flatten_blueprints(c, &mut flat_children);
}
for (child_bp, child_layout) in
flat_children.iter().zip(layout_node.children.iter())
{
Self::collect_canvas_3d_recursive(child_bp, child_layout, commands);
}
}
_ => {}
}
}
}