three_rs/objects/bone.rs
1//! Port of `three.js/src/objects/Bone.js`.
2//!
3//! `Bone` adds nothing to `Object3D` but `isBone` and `type = 'Bone'`. The
4//! scene graph stores its payload as [`Object3D`], which has no `is_bone`
5//! field, so the marker is `object_type == "Bone"`; [`is_bone`] is the test.
6
7use crate::core::{Object3D, ObjectRef};
8
9/// `class Bone extends Object3D`.
10pub struct Bone;
11
12impl Bone {
13 /// `new Bone()`, as a scene-graph [`ObjectRef`].
14 #[allow(clippy::new_ret_no_self)] // `new` mirrors three.js's constructor and returns a scene-graph `ObjectRef`, not `Self`; public API, not changing.
15 pub fn new() -> ObjectRef {
16 let object = Object3D {
17 object_type: "Bone",
18 ..Default::default()
19 };
20 object.into_node()
21 }
22
23 /// `new Bone()` with a name, which is how `GLTFLoader` builds them.
24 pub fn named(name: &str) -> ObjectRef {
25 let node = Self::new();
26 node.borrow_mut().name = name.to_string();
27 node
28 }
29}
30
31/// `object.isBone`.
32pub fn is_bone(object: &Object3D) -> bool {
33 object.object_type == "Bone"
34}