euv-ui 0.51.0

Cross-platform UI component library and 17-scheme design system for the euv framework with pixel-consistent rendering across Web, Android, iOS, iPadOS, macOS, Windows, and Linux.
Documentation
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
use super::*;

/// Default three-quarter studio orbit camera for `EuvViewport3DCameraState`.
impl Default for EuvViewport3DCameraState {
    /// Returns the canonical three-quarter studio camera looking at the world origin.
    ///
    /// # Returns
    ///
    /// - `Self` - Default `EuvViewport3DCameraState`.
    fn default() -> Self {
        Self {
            target: Vec3::new(0.0, 0.5, 0.0),
            yaw_rad: VIEWPORT3D_DEFAULT_YAW_RAD,
            pitch_rad: VIEWPORT3D_DEFAULT_PITCH_RAD,
            distance: VIEWPORT3D_DEFAULT_DISTANCE,
            fov_deg: VIEWPORT3D_DEFAULT_FOV_DEG,
            near: VIEWPORT3D_DEFAULT_NEAR,
            far: VIEWPORT3D_DEFAULT_FAR,
            orbit_sensitivity: VIEWPORT3D_DEFAULT_ORBIT_SENS,
            pan_sensitivity: VIEWPORT3D_DEFAULT_PAN_SENS,
            zoom_sensitivity: VIEWPORT3D_DEFAULT_ZOOM_SENS,
            move_speed: VIEWPORT3D_DEFAULT_MOVE_SPEED,
            navigation_mode: EuvViewport3DNavigationMode::Orbit,
        }
    }
}

/// Interactive orbit, pan, zoom, keyboard navigation, and preset helpers for `EuvViewport3DCameraState`.
impl EuvViewport3DCameraState {
    /// Computes the unit forward look direction derived from `(yaw_rad, pitch_rad)`.
    ///
    /// # Returns
    ///
    /// - `Vec3` - Unit forward direction vector pointing toward `target`.
    #[must_use]
    pub fn forward(&self) -> Vec3 {
        let yaw: f32 = self.get_yaw_rad();
        let pitch: f32 = self.get_pitch_rad();
        let cp: f32 = pitch.cos();
        Vec3::new(yaw.cos() * cp, pitch.sin(), yaw.sin() * cp).normalize()
    }

    /// Computes the unit right vector orthogonal to `forward()` and world `+Y`.
    ///
    /// # Returns
    ///
    /// - `Vec3` - Unit right basis vector.
    #[must_use]
    pub fn right(&self) -> Vec3 {
        let cross: Vec3 = self.forward().cross(Vec3::new(0.0, 1.0, 0.0));
        if cross.length_sq() < 1e-6 {
            Vec3::new(1.0, 0.0, 0.0)
        } else {
            cross.normalize()
        }
    }

    /// Computes the unit camera up vector orthogonal to `right()` and `forward()`.
    ///
    /// # Returns
    ///
    /// - `Vec3` - Unit camera up basis vector.
    #[must_use]
    pub fn up(&self) -> Vec3 {
        self.right().cross(self.forward()).normalize()
    }

    /// Computes the world-space eye position at `target - forward() * distance`.
    ///
    /// # Returns
    ///
    /// - `Vec3` - World-space camera eye coordinates.
    #[must_use]
    pub fn eye_position(&self) -> Vec3 {
        self.get_target() - self.forward().scale(self.get_distance())
    }

    /// Converts this orbit camera state into a core `Camera3D` for `Renderer3D` and projection math.
    ///
    /// # Returns
    ///
    /// - `Camera3D` - Equivalent perspective `Camera3D`.
    #[must_use]
    pub fn to_camera3d(&self) -> Camera3D {
        let mut cam: Camera3D = Camera3D::default();
        let _: &mut Camera3D = cam
            .set_position(self.eye_position())
            .set_yaw(self.get_yaw_rad())
            .set_pitch(
                self.get_pitch_rad()
                    .clamp(VIEWPORT3D_PITCH_MIN, VIEWPORT3D_PITCH_MAX),
            )
            .set_fov_deg(self.get_fov_deg().clamp(15.0, 120.0))
            .set_near(self.get_near().max(0.01))
            .set_far(self.get_far().max(self.get_near() + 1.0));
        cam
    }

    /// Rotates camera orbit yaw and pitch from a screen-space pointer drag delta `(dx, dy)`.
    ///
    /// # Arguments
    ///
    /// - `f32` - Horizontal drag delta in logical pixels.
    /// - `f32` - Vertical drag delta in logical pixels.
    pub fn apply_orbit_delta(&mut self, dx: f32, dy: f32) {
        let sens: f32 = self.get_orbit_sensitivity();
        let next_yaw: f32 = (self.get_yaw_rad() + dx * sens).rem_euclid(TAU);
        let next_pitch: f32 =
            (self.get_pitch_rad() - dy * sens).clamp(VIEWPORT3D_PITCH_MIN, VIEWPORT3D_PITCH_MAX);
        let _: &mut Self = self.set_yaw_rad(next_yaw).set_pitch_rad(next_pitch);
    }

    /// Translates the orbit focus target parallel to the view plane from pointer drag delta `(dx, dy)`.
    ///
    /// # Arguments
    ///
    /// - `f32` - Horizontal drag delta in logical pixels.
    /// - `f32` - Vertical drag delta in logical pixels.
    pub fn apply_pan_delta(&mut self, dx: f32, dy: f32) {
        let scale: f32 = self.get_distance() * self.get_pan_sensitivity();
        let right_vec: Vec3 = self.right().scale(-dx * scale);
        let up_vec: Vec3 = self.up().scale(dy * scale);
        let next_target: Vec3 = self.get_target() + right_vec + up_vec;
        let _: &mut Self = self.set_target(next_target);
    }

    /// Adjusts orbit distance smoothly from scroll wheel or trackpad vertical delta.
    ///
    /// # Arguments
    ///
    /// - `f32` - Scroll delta along the Y axis (positive zooms out, negative zooms in).
    pub fn apply_zoom_delta(&mut self, scroll_y: f32) {
        let factor: f32 = (1.0 + scroll_y * self.get_zoom_sensitivity()).clamp(0.5, 2.0);
        let next_dist: f32 =
            (self.get_distance() * factor).clamp(VIEWPORT3D_DIST_MIN, VIEWPORT3D_DIST_MAX);
        let _: &mut Self = self.set_distance(next_dist);
    }

    /// Applies keyboard WASD/Arrow/Q/E/R/+- camera controls, returning `true` when camera state changed.
    ///
    /// # Arguments
    ///
    /// - `KeyCode` - Pressed keyboard key.
    /// - `Modifiers` - Active modifier keys (`Shift` accelerates step size `2.5x`).
    ///
    /// # Returns
    ///
    /// - `bool` - `true` when the key mutated camera state.
    pub fn apply_key_navigation(&mut self, code: KeyCode, modifiers: Modifiers) -> bool {
        let boost: f32 = if modifiers.get_shift() { 2.5 } else { 1.0 };
        let step: f32 = self.get_move_speed() * boost;
        let forward_flat: Vec3 = {
            let fwd: Vec3 = self.forward();
            let flat: Vec3 = Vec3::new(fwd.get_x(), 0.0, fwd.get_z());
            if flat.length_sq() < 1e-6 {
                Vec3::new(0.0, 0.0, -1.0)
            } else {
                flat.normalize()
            }
        };
        let right_vec: Vec3 = self.right();
        match code {
            KeyCode::Character('w') | KeyCode::Character('W') | KeyCode::ArrowUp => {
                let _: &mut Self = self.set_target(self.get_target() + forward_flat.scale(step));
                true
            }
            KeyCode::Character('s') | KeyCode::Character('S') | KeyCode::ArrowDown => {
                let _: &mut Self = self.set_target(self.get_target() - forward_flat.scale(step));
                true
            }
            KeyCode::Character('d') | KeyCode::Character('D') | KeyCode::ArrowRight => {
                let _: &mut Self = self.set_target(self.get_target() + right_vec.scale(step));
                true
            }
            KeyCode::Character('a') | KeyCode::Character('A') | KeyCode::ArrowLeft => {
                let _: &mut Self = self.set_target(self.get_target() - right_vec.scale(step));
                true
            }
            KeyCode::Character('e') | KeyCode::Character('E') | KeyCode::PageUp => {
                let _: &mut Self = self.set_target(self.get_target() + Vec3::new(0.0, step, 0.0));
                true
            }
            KeyCode::Character('q') | KeyCode::Character('Q') | KeyCode::PageDown => {
                let _: &mut Self = self.set_target(self.get_target() - Vec3::new(0.0, step, 0.0));
                true
            }
            KeyCode::Character('+') | KeyCode::Character('=') => {
                self.apply_zoom_delta(-90.0);
                true
            }
            KeyCode::Character('-') | KeyCode::Character('_') => {
                self.apply_zoom_delta(90.0);
                true
            }
            KeyCode::Character('r') | KeyCode::Character('R') | KeyCode::Home => {
                self.apply_preset_reset();
                true
            }
            _ => false,
        }
    }

    /// Resets orbit angle, target, and distance to the default three-quarter studio view.
    pub fn apply_preset_reset(&mut self) {
        let _: &mut Self = self
            .set_target(Vec3::new(0.0, 0.5, 0.0))
            .set_yaw_rad(VIEWPORT3D_DEFAULT_YAW_RAD)
            .set_pitch_rad(VIEWPORT3D_DEFAULT_PITCH_RAD)
            .set_distance(VIEWPORT3D_DEFAULT_DISTANCE);
    }

    /// Aligns the camera to a top-down orthographic-like overview preset.
    pub fn apply_preset_top(&mut self) {
        let _: &mut Self = self
            .set_yaw_rad(0.0)
            .set_pitch_rad(-1.38)
            .set_distance(VIEWPORT3D_DEFAULT_DISTANCE * 1.25);
    }

    /// Aligns the camera to a level front elevation preset.
    pub fn apply_preset_front(&mut self) {
        let _: &mut Self = self
            .set_yaw_rad(-FRAC_PI_2)
            .set_pitch_rad(0.0)
            .set_distance(VIEWPORT3D_DEFAULT_DISTANCE);
    }

    /// Aligns the camera to a level side elevation preset.
    pub fn apply_preset_side(&mut self) {
        let _: &mut Self = self
            .set_yaw_rad(0.0)
            .set_pitch_rad(0.0)
            .set_distance(VIEWPORT3D_DEFAULT_DISTANCE);
    }
}

/// Construction helpers converting core `ImportedScene3D` and `World3D` instances into `EuvViewport3DSceneSummary`.
impl EuvViewport3DSceneSummary {
    /// Builds a lightweight Studio inspector summary directly from a parsed Blender/glTF `ImportedScene3D`.
    ///
    /// # Arguments
    ///
    /// - `&ImportedScene3D` - Imported 3D scene graph, meshes, materials, and animations.
    ///
    /// # Returns
    ///
    /// - `Self` - Populated Studio inspector summary.
    #[must_use]
    pub fn from_imported_scene(scene: &ImportedScene3D) -> Self {
        let nodes: Vec<EuvViewport3DNodeItem> = scene
            .get_scene_graph()
            .get_nodes()
            .iter()
            .enumerate()
            .map(|(idx, node): (usize, &SceneNode3D)| {
                EuvViewport3DNodeItem::new(
                    idx as u32,
                    node.get_name().clone(),
                    node.get_depth(),
                    node.get_visible(),
                    node.try_get_mesh_id().is_some(),
                    node.try_get_camera_id().is_some(),
                    node.try_get_light_id().is_some(),
                )
            })
            .collect();
        let materials: Vec<EuvViewport3DMaterialItem> = scene
            .get_materials()
            .iter()
            .enumerate()
            .map(
                |(idx, mat): (usize, &PrincipledMaterial3D)| EuvViewport3DMaterialItem {
                    index: idx,
                    name: mat.get_name().clone(),
                    base_color: mat.get_base_color_factor(),
                    metallic: mat.get_metallic_factor(),
                    roughness: mat.get_roughness_factor(),
                    ior: mat.get_ior(),
                    clearcoat: mat.get_clearcoat_factor(),
                    transmission: mat.get_transmission_factor(),
                    emissive_strength: mat.get_emissive_strength(),
                },
            )
            .collect();
        let collections: Vec<String> = scene
            .get_scene_graph()
            .get_collections()
            .get_entries()
            .iter()
            .map(|entry: &CollectionEntry3D| entry.get_name().clone())
            .collect();
        let cameras: Vec<String> = scene
            .get_cameras()
            .iter()
            .map(|cam: &ImportedCamera3D| cam.get_name().clone())
            .collect();
        let mut total_vertices: usize = 0;
        let mut total_triangles: usize = 0;
        for mesh in scene.get_meshes().iter() {
            total_vertices = total_vertices.saturating_add(mesh.get_vertices().len());
            total_triangles = total_triangles.saturating_add(mesh.get_indices().len());
        }
        Self {
            scene_name: scene.get_name().clone(),
            generator: scene.get_generator().clone(),
            nodes,
            materials,
            collections,
            cameras,
            total_vertices,
            total_triangles,
            animation_count: scene.get_animations().len(),
        }
    }

    /// Builds a Studio inspector summary from a live `World3D` open-world scene.
    ///
    /// # Arguments
    ///
    /// - `&World3D` - Live `World3D` scene instance.
    ///
    /// # Returns
    ///
    /// - `Self` - Populated inspector summary listing scene objects and materials.
    #[must_use]
    pub fn from_world(world: &World3D) -> Self {
        let nodes: Vec<EuvViewport3DNodeItem> = world
            .get_objects()
            .iter()
            .enumerate()
            .map(|(idx, obj): (usize, &SceneObject3D)| {
                EuvViewport3DNodeItem::new(
                    idx as u32,
                    obj.get_name().clone(),
                    0,
                    true,
                    true,
                    false,
                    false,
                )
            })
            .collect();
        let materials: Vec<EuvViewport3DMaterialItem> = world
            .get_objects()
            .iter()
            .enumerate()
            .map(|(idx, obj): (usize, &SceneObject3D)| {
                let pbr: PbrMaterial = obj.get_material();
                let albedo: Vec3 = pbr.get_base_color();
                EuvViewport3DMaterialItem {
                    index: idx,
                    name: obj.get_name().clone(),
                    base_color: [albedo.get_x(), albedo.get_y(), albedo.get_z(), 1.0],
                    metallic: pbr.get_metallic(),
                    roughness: pbr.get_roughness(),
                    ior: 1.5,
                    clearcoat: 0.0,
                    transmission: 0.0,
                    emissive_strength: pbr.get_emissive().length(),
                }
            })
            .collect();
        let mut total_vertices: usize = 0;
        let mut total_triangles: usize = 0;
        for chain in world.get_mesh_library().iter() {
            if let Some(lod0) = chain.get_levels().first() {
                total_vertices = total_vertices.saturating_add(lod0.get_vertices().len());
                total_triangles = total_triangles.saturating_add(lod0.get_indices().len());
            }
        }
        Self {
            scene_name: VIEWPORT3D_DEFAULT_TITLE.to_string(),
            generator: String::new(),
            nodes,
            materials,
            collections: Vec::new(),
            cameras: Vec::new(),
            total_vertices,
            total_triangles,
            animation_count: 0,
        }
    }
}

/// Default Live-Link connection state targeting `http://127.0.0.1:9877/blender/events`.
impl Default for EuvViewport3DLiveLinkState {
    /// Returns a disconnected Live-Link state targeting port `9877`.
    ///
    /// # Returns
    ///
    /// - `Self` - Default `EuvViewport3DLiveLinkState`.
    fn default() -> Self {
        Self {
            endpoint_url: VIEWPORT3D_DEFAULT_LIVE_LINK_URL.to_string(),
            status: EuvViewport3DLiveLinkStatus::Disconnected,
            last_seq: 0,
            delta_count: 0,
            asset_count: 0,
            last_message: VIEWPORT3D_STATUS_DISCONNECTED.to_string(),
        }
    }
}

/// Constructors and fluent `#[prop(custom)]` helpers for `EuvViewport3D`.
impl EuvViewport3D {
    /// Creates an `EuvViewport3D` in clean `Game` mode (screen+keyboard controls and ONLY a single fullscreen toggle button; inspector OFF by default).
    ///
    /// # Arguments
    ///
    /// - `ThemeTokens` - Active `euv-ui` design tokens.
    ///
    /// # Returns
    ///
    /// - `Self` - Configured `EuvViewport3D` in `Game` mode.
    #[must_use]
    pub fn new(tokens: ThemeTokens) -> Self {
        Self {
            title: VIEWPORT3D_DEFAULT_TITLE.to_string(),
            mode: EuvViewport3DMode::Game,
            camera: Signal::new(EuvViewport3DCameraState::default()),
            fullscreen: Signal::new(false),
            show_inspector: false,
            inspector_open: Signal::new(false),
            active_tab: Signal::new(EuvViewport3DInspectorTab::Scene),
            selected_node: Signal::new(None),
            selected_material: Signal::new(None),
            scene_summary: None,
            live_link: None,
            world: None,
            quality: None,
            painter: None,
            on_key_input: None,
            on_select_node: None,
            on_material_change: None,
            on_live_link_toggle: None,
            tokens,
            style: None,
        }
    }

    /// Sets the presentation mode (`Game` or `Studio`) fluently.
    ///
    /// # Arguments
    ///
    /// - `EuvViewport3DMode` - Target presentation mode.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated viewport descriptor.
    #[must_use]
    pub fn mode(mut self, mode: EuvViewport3DMode) -> Self {
        let _: &mut Self = self.set_mode(mode);
        self
    }

    /// Switches to unobstructed `Game` mode (screen+keyboard controls + ONLY a single fullscreen toggle button).
    ///
    /// # Returns
    ///
    /// - `Self` - Game-mode viewport descriptor.
    #[must_use]
    pub fn game(mut self) -> Self {
        let _: &mut Self = self
            .set_mode(EuvViewport3DMode::Game)
            .set_show_inspector(false);
        self
    }

    /// Switches to `Studio` mode enabling the optional collapsible Scene/Materials/Camera/Live-Link inspector rail.
    ///
    /// # Returns
    ///
    /// - `Self` - Studio-mode viewport descriptor.
    #[must_use]
    pub fn studio(mut self) -> Self {
        let _: &mut Self = self
            .set_mode(EuvViewport3DMode::Studio)
            .set_show_inspector(true);
        self
    }

    /// Explicitly toggles whether the optional collapsible Studio inspector rail is mounted.
    ///
    /// # Arguments
    ///
    /// - `bool` - `true` to enable the Studio inspector rail, `false` to hide all inspector chrome.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated viewport descriptor.
    #[must_use]
    pub fn show_inspector(mut self, enabled: bool) -> Self {
        let _: &mut Self = self.set_show_inspector(enabled);
        self
    }

    /// Attaches a custom 3D canvas painter replacing the default studio grid / `Renderer3D` pass.
    ///
    /// # Arguments
    ///
    /// - `PainterFn` - Closure painting into `DisplayList` from `(Rect, EuvViewport3DCameraState)`.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated viewport descriptor.
    #[must_use]
    pub fn painter<PainterFn>(mut self, painter_fn: PainterFn) -> Self
    where
        PainterFn: Fn(Rect, EuvViewport3DCameraState, &mut DisplayList) + 'static,
    {
        let _: &mut Self = self.set_painter(Some(Rc::new(painter_fn)));
        self
    }

    /// Attaches a keyboard hook invoked on every key press while the 3D viewport is focused.
    ///
    /// # Arguments
    ///
    /// - `CallbackFn` - Keyboard callback closure.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated viewport descriptor.
    #[must_use]
    pub fn on_key_input<CallbackFn>(mut self, callback: CallbackFn) -> Self
    where
        CallbackFn: Fn(KeyCode, Modifiers) + 'static,
    {
        let _: &mut Self = self.set_on_key_input(Some(Rc::new(callback)));
        self
    }

    /// Attaches a callback invoked when a scene node is selected inside the Studio Scene inspector.
    ///
    /// # Arguments
    ///
    /// - `CallbackFn` - Node selection callback closure.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated viewport descriptor.
    #[must_use]
    pub fn on_select_node<CallbackFn>(mut self, callback: CallbackFn) -> Self
    where
        CallbackFn: Fn(u32) + 'static,
    {
        let _: &mut Self = self.set_on_select_node(Some(Rc::new(callback)));
        self
    }

    /// Attaches a callback invoked when a Principled BSDF material is adjusted in the Studio Materials inspector.
    ///
    /// # Arguments
    ///
    /// - `CallbackFn` - Material mutation callback closure.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated viewport descriptor.
    #[must_use]
    pub fn on_material_change<CallbackFn>(mut self, callback: CallbackFn) -> Self
    where
        CallbackFn: Fn(usize, EuvViewport3DMaterialItem) + 'static,
    {
        let _: &mut Self = self.set_on_material_change(Some(Rc::new(callback)));
        self
    }

    /// Attaches a callback invoked when Live-Link connect/disconnect is toggled in the Studio Live-Link inspector.
    ///
    /// # Arguments
    ///
    /// - `CallbackFn` - Live-Link toggle callback closure.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated viewport descriptor.
    #[must_use]
    pub fn on_live_link_toggle<CallbackFn>(mut self, callback: CallbackFn) -> Self
    where
        CallbackFn: Fn(bool) + 'static,
    {
        let _: &mut Self = self.set_on_live_link_toggle(Some(Rc::new(callback)));
        self
    }
}

/// Declarative `#[component]` rendering implementation for `EuvViewport3D`.
#[component]
impl EuvViewport3D {
    /// Renders `EuvViewport3D` with direct pointer/keyboard controls, edge-to-edge fullscreen portal, and optional Studio inspector rail.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root 3D viewport node handle.
    fn render(&self) -> NodeId {
        let ctx: Context = current_context();
        bind_fullscreen_context(&ctx);
        let base_tokens: ThemeTokens = self.get_tokens();
        let tokens: ThemeTokens = live_tokens_untracked(base_tokens);
        let palette: ThemePalette = tokens.get_palette();
        let geometry: ThemeGeometry = tokens.get_geometry();
        let camera_sig: Signal<EuvViewport3DCameraState> =
            resolve_or_alloc_signal(self.get_camera(), EuvViewport3DCameraState::default());
        let fs_sig: Signal<bool> = resolve_or_alloc_signal(self.get_fullscreen(), false);
        let inspector_enabled: bool =
            self.get_show_inspector() || self.get_mode() == EuvViewport3DMode::Studio;
        let inspector_open: Signal<bool> =
            resolve_or_alloc_signal(self.get_inspector_open(), inspector_enabled);
        let active_tab: Signal<EuvViewport3DInspectorTab> =
            resolve_or_alloc_signal(self.get_active_tab(), EuvViewport3DInspectorTab::Scene);
        let selected_node: Signal<Option<u32>> =
            resolve_or_alloc_signal(self.get_selected_node(), None);
        let selected_material: Signal<Option<usize>> =
            resolve_or_alloc_signal(self.get_selected_material(), None);
        let Self {
            title,
            scene_summary,
            live_link,
            world,
            quality,
            painter,
            on_key_input,
            on_select_node,
            on_material_change,
            on_live_link_toggle,
            style,
            ..
        } = self;
        let title_label: String = if title.trim().is_empty() {
            VIEWPORT3D_DEFAULT_TITLE.to_string()
        } else {
            title.clone()
        };
        let shared_renderer: Rc<RefCell<Option<Box<Renderer3D>>>> = Rc::new(RefCell::new(None));
        let inline_canvas: NodeId = mount_viewport3d_canvas_surface(Viewport3DCanvasSpec {
            camera: camera_sig,
            fullscreen: fs_sig,
            world: world.clone(),
            renderer: Rc::clone(&shared_renderer),
            quality: *quality,
            painter: painter.clone(),
            on_key_input: on_key_input.clone(),
            title: title_label.clone(),
            tokens: base_tokens,
        });
        let inline_fs_btn: NodeId = mount_viewport3d_fullscreen_button(fs_sig, false, base_tokens);
        let on_expand_inspector = move |_: &UiEvent| {
            let next: bool = !inspector_open.get_untracked();
            let _: bool = inspector_open.set_if_changed(next);
        };
        let inline_overlay_style: Style = style! {
            FlexDirection::Row
            Position::Absolute
            Inset(Some(SPACE_SM), Some(SPACE_SM), None, None)
            AlignItems::Center
            Gap(SPACE_XS)
            ZIndex(10)
        };
        let base_container_style: Style = style! {
            FlexDirection::Row
            Width(Length::Percent(100.0))
            Height(Length::Px(VIEWPORT3D_DEFAULT_HEIGHT))
            Gap(SPACE_MD)
            AlignItems::Stretch
            Overflow::Hidden
        };
        let root_style: Style = base_container_style.with_overrides(*style);
        let stage_style: Style = style! {
            FlexDirection::Column
            Position::Relative
            FlexGrow(1.0)
            FlexShrink(1.0)
            MinWidth(Length::Px(0.0))
            Height(Length::Percent(100.0))
            Background(palette.get_media_surface())
            Border::new(geometry.get_border_width(), palette.get_border())
            Radius(geometry.get_radius_md())
            Overflow::Hidden
        };
        let inspector_rail_opt: Option<NodeId> = if inspector_enabled {
            Some(mount_viewport3d_inspector_rail(Viewport3DInspectorSpec {
                inspector_open,
                active_tab,
                camera: camera_sig,
                selected_node,
                selected_material,
                scene_summary: *scene_summary,
                live_link: *live_link,
                on_select_node: on_select_node.clone(),
                on_material_change: on_material_change.clone(),
                on_live_link_toggle: on_live_link_toggle.clone(),
                tokens: base_tokens,
            }))
        } else {
            None
        };
        let inspector_toggle_style = move || -> Style {
            let is_open: bool = inspector_open.get();
            let display_mode: Display = if is_open {
                Display::None
            } else {
                Display::Flex
            };
            style! {
                display_mode
                AlignItems::Center
            }
        };
        let portal_style: Style = style! {
            FlexDirection::Column
            Display::None
            Position::Fixed
            Inset(Some(0.0), Some(0.0), Some(0.0), Some(0.0))
            Width(Length::Percent(100.0))
            Height(Length::Percent(100.0))
            Padding(Edges::all(0.0))
            Margin(Edges::all(0.0))
            Background(palette.get_media_surface())
            Border::new(0.0, COLOR_TRANSPARENT)
            Radius(0.0)
            Overflow::Hidden
            PointerEvents::None
            StopScrollPropagation(true)
            StopEventPropagation(true)
            ZIndex(Z_INDEX_FULLSCREEN)
        };
        let mut fs_portal: NodeId = NodeId::default();
        let root: NodeId = view! {
            row {
                style: root_style
                column {
                    style: stage_style
                    { inline_canvas }
                    row {
                        style: inline_overlay_style
                        if inspector_enabled {
                            row {
                                bind_style: inspector_toggle_style
                                role: A11yRole::Group
                                a11y_label: VIEWPORT3D_A11Y_TOGGLE_INSPECTOR.to_string()
                                EuvButton {
                                    label: VIEWPORT3D_BTN_INSPECT.to_string()
                                    tokens: tokens
                                    secondary()
                                    small()
                                    on_click: on_expand_inspector
                                }
                            }
                        }
                        { inline_fs_btn }
                    }
                }
                if let Some(inspector_node) = inspector_rail_opt {
                    { inspector_node }
                }
                portal {
                    node_ref: fs_portal
                    style: portal_style
                }
            }
        };
        let world_fs: Option<Rc<RefCell<World3D>>> = world.clone();
        let quality_fs: Option<Signal<RenderQualityConfig>> = *quality;
        let painter_fs: Option<Viewport3DPainter> = painter.clone();
        let key_fs: Option<Viewport3DKeyCallback> = on_key_input.clone();
        let title_fs: String = title_label;
        let ctx_fs: Context = ctx.clone();
        let build_fs_panel = move || -> NodeId {
            let live_tok: ThemeTokens = live_tokens_untracked(base_tokens);
            let live_p: ThemePalette = live_tok.get_palette();
            let safe_sig: Signal<SafeAreaInsets> = ctx_fs.get_safe_area();
            let vp_sig: Signal<Size> = ctx_fs.get_viewport_size();
            let fs_canvas: NodeId = mount_viewport3d_canvas_surface(Viewport3DCanvasSpec {
                camera: camera_sig,
                fullscreen: fs_sig,
                world: world_fs.clone(),
                renderer: Rc::clone(&shared_renderer),
                quality: quality_fs,
                painter: painter_fs.clone(),
                on_key_input: key_fs.clone(),
                title: title_fs.clone(),
                tokens: base_tokens,
            });
            let fs_exit_btn: NodeId = mount_viewport3d_fullscreen_button(fs_sig, true, base_tokens);
            let fs_root_style: Style = style! {
                FlexDirection::Column
                Position::Relative
                Width(Length::Percent(100.0))
                Height(Length::Percent(100.0))
                Padding(Edges::all(0.0))
                Margin(Edges::all(0.0))
                Background(live_p.get_media_surface())
                Overflow::Hidden
                StopEventPropagation(true)
            };
            let fs_controls_style = move || -> Style {
                let safe_lay: FullscreenSafeLayout =
                    resolve_fullscreen_safe_layout(vp_sig.get(), safe_sig.get());
                let pad: Edges = safe_lay.get_header_padding();
                let top_inset: f32 = pad.get_top().max(SPACE_SM);
                let right_inset: f32 = pad.get_right().max(SPACE_SM);
                style! {
                    FlexDirection::Row
                    Position::Absolute
                    Inset(Some(top_inset), Some(right_inset), None, None)
                    AlignItems::Center
                    ZIndex(10)
                }
            };
            view! {
                column {
                    style: fs_root_style
                    { fs_canvas }
                    row {
                        bind_style: fs_controls_style
                        { fs_exit_btn }
                    }
                }
            }
        };
        let handle: SceneHandle = ctx.get_scene().clone();
        let ctx_build: Context = ctx.clone();
        let prev_open: Rc<Cell<bool>> = Rc::new(Cell::new(false));
        let fs_acquired: Rc<Cell<bool>> = Rc::new(Cell::new(false));
        let fs_cleanup: Rc<Cell<bool>> = Rc::clone(&fs_acquired);
        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
            on_cleanup(move || {
                if fs_cleanup.replace(false) {
                    exit_fullscreen();
                }
            });
            let _: Effect =
                EuvOverlayStack::bind_signal(fs_sig, VIEWPORT3D_OVERLAY_NAME, Z_INDEX_FULLSCREEN);
            let vp_sig: Signal<Size> = ctx_build.get_viewport_size();
            let handle_vp: SceneHandle = handle.clone();
            let _: Effect = Effect::new(move || {
                let box_size: Size = vp_sig.get();
                if !fs_sig.get() {
                    return;
                }
                let vw: f32 = box_size.get_width().max(1.0);
                let vh: f32 = box_size.get_height().max(1.0);
                handle_vp.with_write(
                    |scene_tree: &mut SceneTree| {
                        if let Some(node) = scene_tree.get_node_mut(fs_portal) {
                            let _: &mut LayoutStyle = node
                                .get_mut_style()
                                .get_mut_layout()
                                .set_width(Length::Px(vw))
                                .set_height(Length::Px(vh));
                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
                            scene_tree.mark_dirty(fs_portal, dirty_l | DIRTY_PAINT);
                            notify_frame_needed();
                        }
                    },
                    (),
                );
            });
            Effect::new(move || {
                let is_open: bool = fs_sig.get();
                if is_open == prev_open.replace(is_open) {
                    return;
                }
                if is_open {
                    let vp_now: Size = vp_sig.get_untracked();
                    let vw: f32 = vp_now.get_width().max(1.0);
                    let vh: f32 = vp_now.get_height().max(1.0);
                    let live_p: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
                    let fs_panel: NodeId = with_context(ctx_build.clone(), &build_fs_panel);
                    let portal_shown: bool = fs_panel != NodeId::default()
                        && handle.with_write(
                            |tree: &mut SceneTree| {
                                if tree.get_node(fs_portal).is_none()
                                    || tree.get_node(fs_panel).is_none()
                                {
                                    return false;
                                }
                                tree.cancel_subtree_transitions(fs_portal);
                                tree.replace_children(fs_portal, vec![fs_panel]);
                                if let Some(node) = tree.get_node_mut(fs_portal) {
                                    let st: &mut Style = node.get_mut_style();
                                    let _: &mut LayoutStyle = st
                                        .get_mut_layout()
                                        .set_display(Display::Flex)
                                        .set_width(Length::Px(vw))
                                        .set_height(Length::Px(vh));
                                    let _: &mut PaintStyle = st
                                        .get_mut_paint()
                                        .set_background(Some(live_p.get_media_surface()))
                                        .set_pointer_events(PointerEvents::Auto)
                                        .set_opacity(1.0)
                                        .set_transform(Transform2D::default());
                                }
                                let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
                                tree.mark_dirty(fs_portal, dirty_l | DIRTY_PAINT);
                                notify_frame_needed();
                                true
                            },
                            false,
                        );
                    let entered: bool = portal_shown
                        && (fs_acquired.get()
                            || enter_fullscreen_for_portal(&ctx_build, fs_portal));
                    if entered {
                        fs_acquired.set(true);
                    } else {
                        handle.dismiss_portal_immediate(fs_portal);
                        if fs_acquired.replace(false) {
                            exit_fullscreen();
                        }
                        prev_open.set(false);
                        let _: bool = fs_sig.set_if_changed(false);
                    }
                    notify_frame_needed();
                } else {
                    if fs_acquired.replace(false) {
                        exit_fullscreen();
                    }
                    handle.dismiss_portal_immediate(fs_portal);
                }
            })
        });
        ctx.get_scene().with_write(
            |tree: &mut SceneTree| {
                tree.attach_scope(root, scope);
            },
            (),
        );
        root
    }
}