# graphics3d/skinnedmodel (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/graphics3d/skinnedmodel/

Skinned model. (the original graphics3d/skinnedmodel.js)
- Model instance, mesh/bone/skin/material/animation data + pose state. Rendering is handled by SkinnedModelRenderer.
- Interprets GLB (binary glTF) and binary FBX into a common neutral schema (MeshDescription + MaterialDescription) and builds GL resources.
  (importers only parse → neutral schema → shared GL upload upload_meshes_and_materials)
- Static meshes without a skin use a synthetic skin (1 joint), and morph targets are uploaded as float textures, so they draw through the same skinning path.
- Supports animation cross-fades, joint rotation offsets (procedural pose adjustment) and morph weights (glTF weights / code) like the original.
- Differences from the original:
  - The original is async and fetches URLs (loadFromUrl, loadFromBytes for bytes). The byte functions of the Rust version
    load_from_bytes / load_from_fbx_bytes / add_animations_from_fbx_bytes finish on the spot.
    The URL functions load_from_url / load_from_fbx_url, like ImageAsset, use the engine's asset loading (asset folder candidates on desktop, fetch from asset_base_url on the web)
    to request the bytes and return a load handle (SkinnedModelLoadHandle). Once loaded, the handle's create_model(gl, renderer) builds the model. (the form without await)
    The original await SkinnedModel.loadFromUrl(gl, url, renderer) becomes load_from_url_async(engine, path, renderer).await inside an engine task. (load_from_fbx_url_async for fbx)
    Once loaded, the model is built with the GL of the engine polling the task. (the renderer only shares its shader program at the call and is not borrowed)
    add_animations_from_fbx_url requests the load and returns an awaitable AnimationLoadHandle. Like the original, the clips are already added when await finishes.
    (the clip list is shared with the handle, and once loaded, whichever comes first among the awaiting future, the next update or play_animation adds them. They are added in load order like the original)
  - Functions that use GL take gl. update(delta_time) does not use GL. Step 6 of the original update (uploading changed morph targets) is
    done instead by the renderer's draw / draw_depth / draw_wireframe through upload_pending_morph_targets. (that is why the draw functions take a &mut model)
    Thanks to this, update can be called in the scene's tick.
  - The original node / drawable / skin / clip objects are the SkinnedModelNode / Drawable / Skin / AnimationClip structs.
    A drawable's material is `Rc<Material>`. Clips are referred to by index, and sample_animation also takes a clip index.
    upload_wireframe_indices / upload_morph_targets take a drawable index instead of the original drawable object. (a drawable cannot be passed while the model is borrowed as &mut)
  - A drawable's mesh_description has empty morph_targets because the morph targets were moved to morph_target_list. (the large delta arrays are not held twice)
  - Like the original, node matrix, CUBICSPLINE interpolation and primitive mode are ignored. Like the original, FBX draws only meshes with a skin attached.
- The uploaded buffers, material prototypes, morph textures, node and skin prototypes and clips are held once by SkinnedModelAsset, and the model is its instance. (same as the original)
  create_instance and create_from_asset build instances without a GPU upload, and loads (create_model, load_from_url_async) use the asset cache.
  destroy deletes this instance's resources (wireframe buffers, forked morph textures, materials forked by get_material) and releases the asset.
  Materials given from outside with set_material are not deleted. (same as the original)

Example: Interpret glTF content and compute the pose without GL (a mesh without a skin gets a synthetic skin with the node itself as the joint)

```rust
use serde_json::json;
use vanilla::SkinnedModel;

let positions: [f32; 9] = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0];
let binary_buffer: Vec<u8> = positions.iter().flat_map(|value| value.to_le_bytes()).collect();
let json = json!({
	"scenes": [{ "nodes": [0] }],
	"nodes": [{ "name": "Triangle", "mesh": 0, "translation": [0.0, 2.0, 0.0] }],
	"meshes": [{ "primitives": [{ "attributes": { "POSITION": 0 } }] }],
	"accessors": [{ "bufferView": 0, "componentType": 5126, "count": 3, "type": "VEC3" }],
	"bufferViews": [{ "buffer": 0, "byteOffset": 0, "byteLength": 36 }]
});
let mut skinned_model = SkinnedModel::create_without_shader_program();
let (mesh_description_list, material_description_list) = skinned_model.interpret_content(&json, &binary_buffer).unwrap();
assert_eq!(mesh_description_list.len(), 1);
assert!(material_description_list.is_empty());
skinned_model.update(0.0);
let joint_matrix_array = &skinned_model.get_skin_list()[0].joint_matrix_array;
assert_eq!(joint_matrix_array[13], 2.0);
```

## SkinnedModelNode (struct) (Clone, Debug)

Model node. (bone hierarchy + pose state, an element of the original nodeList)

Example: Find a node by name and read its world position (the value after update)

```rust
use vanilla::{SkinnedModel, SkinnedModelNode};

fn find_world_position(skinned_model: &SkinnedModel, node_name: &str) -> Option<[f64; 3]> {
	let node: &SkinnedModelNode = skinned_model.get_node_list().iter().find(|node| node.name == node_name)?;
	let elements = node.world_matrix.read_elements();
	Some([elements[12], elements[13], elements[14]])
}

let skinned_model = SkinnedModel::create_without_shader_program();
assert_eq!(find_world_position(&skinned_model, "Head"), None);
```

- `pub name: String` (field, since 0.3.2): Node name. (glTF node name, the Model name with the kind tail removed for FBX, an empty string if missing)
  - returns String
- `pub child_indices: Vec<usize>` (field, since 0.3.2): Child node index list.
  - returns Vec<usize>
- `pub mesh_index: Option<usize>` (field, since 0.3.2): glTF mesh index. (None if there is no mesh or for FBX)
  - returns Option<usize>
- `pub skin_index: Option<usize>` (field, since 0.3.2): Skin index. (position in skin_list, glTF mesh nodes without a skin get a synthetic skin. None if missing)
  - returns Option<usize>
- `pub base_translation: [f64; 3]` (field, since 0.3.2): Base pose translation. (update starts from this value every time)
  - returns [f64; 3]
- `pub base_rotation: Quaternion` (field, since 0.3.2): Base pose rotation. (for FBX, with the pre-rotation multiplied in)
  - returns Quaternion
- `pub base_scale: [f64; 3]` (field, since 0.3.2): Base pose scale.
  - returns [f64; 3]
- `pub current_translation: [f64; 3]` (field, since 0.3.2): Current pose translation. (the value the last update sampled from the clip on top of the base pose)
  - returns [f64; 3]
- `pub current_rotation: Quaternion` (field, since 0.3.2): Current pose rotation. (with the joint rotation offset multiplied in)
  - returns Quaternion
- `pub current_scale: [f64; 3]` (field, since 0.3.2): Current pose scale.
  - returns [f64; 3]
- `pub world_matrix: Matrix4` (field, since 0.3.2): Model-space world matrix. (update computes it from the root, nodes not reachable from a root are left as is)
  - returns Matrix4

## Skin (struct) (Clone, Debug)

Skin. (joint node indices + inverse bind matrices + joint matrix array to upload to the shader)

Example: Take one joint's matrix out of the joint matrix array

```rust
use vanilla::{Matrix4, Skin};

fn read_joint_matrix(skin: &Skin, joint_index: usize) -> Option<Matrix4> {
	let elements = skin.joint_matrix_array.get(joint_index * 16..joint_index * 16 + 16)?;
	let mut matrix = Matrix4::create_identity();
	matrix.elements.copy_from_slice(elements);
	Some(matrix)
}

let skin = Skin {
	joint_node_indices: vec![0],
	inverse_bind_matrices: vec![Matrix4::create_identity()],
	joint_matrix_array: Matrix4::create_translation(1.0, 2.0, 3.0).get_elements().to_vec(),
};
assert_eq!(read_joint_matrix(&skin, 0).unwrap().elements[13], 2.0);
assert!(read_joint_matrix(&skin, 1).is_none());
```

- `pub joint_node_indices: Vec<usize>` (field, since 0.3.2): Node index per joint. (joints without a node are set to usize::MAX and use the identity matrix)
  - returns Vec<usize>
- `pub inverse_bind_matrices: Vec<Matrix4>` (field, since 0.3.2): Inverse bind matrix per joint. (same positions as joint_node_indices)
  - returns Vec<Matrix4>
- `pub joint_matrix_array: Vec<f32>` (field, since 0.3.2): Joint matrices to upload to the shader. (16 column-major values per joint, world x inverse bind, filled by update)
  - returns Vec<f32>

## MorphTarget (struct) (Clone, Debug, PartialEq)

Morph target. (per-vertex position deltas + optional normal deltas)

Example: Lay out a 2-vertex target into morph texture texels

```rust
use vanilla::{MorphTarget, SkinnedModel};

let morph_target = MorphTarget {
	name: String::from("smile"),
	position_deltas: vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
	normal_deltas: None,
};
let (texture_width, rows_per_target, texel_data) = SkinnedModel::build_morph_texel_data(&[morph_target], 2);
assert_eq!((texture_width, rows_per_target), (2, 1));
assert_eq!(texel_data.len(), 2 * 2 * 4);
assert_eq!(&texel_data[0..8], &[1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 6.0, 0.0]);
```

- `pub name: String` (field, since 0.3.2): Target name. (glTF mesh.extras.targetNames, in the form "target0" if missing)
  - returns String
- `pub position_deltas: Vec<f64>` (field, since 0.3.2): Position delta per vertex. (3 each: x, y, z)
  - returns Vec<f64>
- `pub normal_deltas: Option<Vec<f64>>` (field, since 0.3.2): Normal delta per vertex. (3 each, None if missing)
  - returns Option<Vec<f64>>

## FbxCornerArrays (struct) (Clone, Debug, Default)

FBX corner arrays. (cornerArrays of the original splitFbxCornersByMaterial, values per non-indexed corner)

Example: Corner arrays of one triangle (with only one material number they come back as they are)

```rust
use vanilla::SkinnedModel;
use vanilla::graphics3d::skinnedmodel::FbxCornerArrays;

let corner_arrays = FbxCornerArrays {
	positions: vec![0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0],
	normals: vec![0.0; 9],
	texture_coordinates: vec![0.0; 6],
	joints: vec![0; 12],
	weights: vec![1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
};
let sub_mesh_list = SkinnedModel::split_fbx_corners_by_material(&[3], corner_arrays);
assert_eq!(sub_mesh_list.len(), 1);
assert_eq!(sub_mesh_list[0].0, 3);
assert_eq!(sub_mesh_list[0].1.positions.len(), 9);
```

- `pub positions: Vec<f64>` (field, since 0.4.0): Corner positions. (x, y, z per corner)
  - returns Vec<f64>
- `pub normals: Vec<f64>` (field, since 0.4.0): Corner normals. (3 per corner)
  - returns Vec<f64>
- `pub texture_coordinates: Vec<f64>` (field, since 0.4.0): Corner UVs. (2 per corner)
  - returns Vec<f64>
- `pub joints: Vec<u16>` (field, since 0.4.0): 4 joints per corner. (Positions in the skin's joint_node_indices)
  - returns Vec<u16>
- `pub weights: Vec<f64>` (field, since 0.4.0): 4 joint weights per corner.
  - returns Vec<f64>

## MeshDescription (struct) (Clone, Debug)

Neutral mesh description. (the original meshDescription, pure CPU arrays)
- joints / weights are 4 per vertex, the default material if material_index is None, node_index is the target node of the morph weight channel.

Example: Description of a glTF triangle without a skin (weight 1 on a single synthetic skin)

```rust
use serde_json::json;
use vanilla::SkinnedModel;

let positions: [f32; 9] = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0];
let binary_buffer: Vec<u8> = positions.iter().flat_map(|value| value.to_le_bytes()).collect();
let json = json!({
	"scenes": [{ "nodes": [0] }],
	"nodes": [{ "name": "Triangle", "mesh": 0 }],
	"meshes": [{ "primitives": [{ "attributes": { "POSITION": 0 } }] }],
	"accessors": [{ "bufferView": 0, "componentType": 5126, "count": 3, "type": "VEC3" }],
	"bufferViews": [{ "buffer": 0, "byteOffset": 0, "byteLength": 36 }]
});
let mut skinned_model = SkinnedModel::create_without_shader_program();
let (mesh_description_list, _material_description_list) = skinned_model.interpret_content(&json, &binary_buffer).unwrap();
let mesh_description = &mesh_description_list[0];
assert_eq!(mesh_description.positions.len(), 9);
assert_eq!(mesh_description.normals.as_deref(), Some(&[0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0][..]));
assert!(mesh_description.indices.is_none());
assert_eq!(&mesh_description.weights[0..4], &[1.0, 0.0, 0.0, 0.0]);
assert_eq!(mesh_description.material_index, None);
assert_eq!(skinned_model.get_skin_list()[mesh_description.skin_index].joint_node_indices, vec![0]);
```

- `pub positions: Vec<f64>` (field, since 0.3.2): Vertex positions. (x, y, z per vertex)
  - returns Vec<f64>
- `pub normals: Option<Vec<f64>>` (field, since 0.3.2): Vertex normals. (3 each, smooth normals are built and used at upload when None, always Some for glTF because flat normals are built when normals are missing)
  - returns Option<Vec<f64>>
- `pub texture_coordinates: Option<Vec<f64>>` (field, since 0.3.2): Vertex UVs. (2 each, None if missing)
  - returns Option<Vec<f64>>
- `pub joints: Vec<u16>` (field, since 0.3.2): 4 joints per vertex. (positions in the skin's joint_node_indices)
  - returns Vec<u16>
- `pub weights: Vec<f64>` (field, since 0.3.2): 4 joint weights per vertex. (0 ~ 1)
  - returns Vec<f64>
- `pub indices: Option<IndexArray>` (field, since 0.3.2): Triangle indices. (when None, every 3 vertices are drawn as a triangle)
  - returns Option<IndexArray>
- `pub skin_index: usize` (field, since 0.3.2): Skin index used. (position in the model's skin_list)
  - returns usize
- `pub material_index: Option<usize>` (field, since 0.3.2): Material description index. (the default material when None)
  - returns Option<usize>
- `pub material_name: String` (field, since 0.3.2): Material name. (name in glTF materials, the Material name in FBX, an empty string if none)
  - returns String
- `pub node_index: Option<usize>` (field, since 0.3.2): Index of the node that owns this mesh. (target of the morph weight channel, None if missing)
  - returns Option<usize>
- `pub morph_targets: Vec<MorphTarget>` (field, since 0.3.2): Morph target list.
  - returns Vec<MorphTarget>
- `pub morph_weights: Vec<f32>` (field, since 0.3.2): Default weight per target. (weights of the glTF node or mesh, 0 if missing)
  - returns Vec<f32>

## Drawable (struct) (Clone)

Drawable. (an element of the original drawableList, vertex array, indices, skin, material reference, morph state)

Example: Find a drawable's position by material name (the position to pass to set_material)

```rust
use vanilla::SkinnedModel;

fn find_drawable_index(skinned_model: &SkinnedModel, material_name: &str) -> Option<usize> {
	skinned_model.get_drawable_list().iter().position(|drawable| drawable.material_name == material_name)
}

let skinned_model = SkinnedModel::create_without_shader_program();
assert_eq!(find_drawable_index(&skinned_model, "Body"), None);
```

- `pub vertex_array: GlVertexArray` (field, since 0.3.2): Vertex array. (vertex buffers and index buffer bound together)
  - returns GlVertexArray
- `pub vertex_buffer_list: Vec<GlBuffer>` (field, since 0.3.2): Vertex buffer list. (only the attributes the shader uses)
  - returns Vec<GlBuffer>
- `pub is_indexed: bool` (field, since 0.3.2): Whether it draws with indices. (drawArrays when false)
  - returns bool
- `pub index_buffer: Option<GlBuffer>` (field, since 0.3.2): Index buffer. (None if there are no indices)
  - returns Option<GlBuffer>
- `pub index_count: usize` (field, since 0.3.2): Index count.
  - returns usize
- `pub index_component_type: u32` (field, since 0.3.2): Index GL type. (UNSIGNED_SHORT or UNSIGNED_INT, 0 if there are no indices)
  - returns u32
- `pub index_byte_offset: i32` (field, since 0.3.2): Index buffer start byte. (upload sets it to 0)
  - returns i32
- `pub wireframe_index_buffer: Option<GlBuffer>` (field, since 0.3.2): Wireframe line index buffer. (built on the first draw_wireframe, None before that)
  - returns Option<GlBuffer>
- `pub wireframe_index_count: usize` (field, since 0.3.2): Line index count. (edge count x 2)
  - returns usize
- `pub wireframe_index_component_type: u32` (field, since 0.3.2): Line index GL type. (UNSIGNED_INT when there are more than 65535 vertices)
  - returns u32
- `pub vertex_count: usize` (field, since 0.3.2): Vertex count.
  - returns usize
- `pub material: Rc<Material>` (field, since 0.3.2): Material. (can be shared with Rc with other drawables of the same model or elsewhere)
  - returns Rc<Material>
- `pub material_name: String` (field, since 0.3.2): Material name. (material_name of MeshDescription)
  - returns String
- `pub skin_index: usize` (field, since 0.3.2): Skin index used.
  - returns usize
- `pub node_index: Option<usize>` (field, since 0.3.2): Index of the node that owns the mesh. (target of the morph weight channel)
  - returns Option<usize>
- `pub mesh_description: Rc<MeshDescription>` (field, since 0.3.2): Uploaded mesh description. (empty morph targets because they were moved to morph_target_list; shared by the instances of the same asset)
  - returns Rc<MeshDescription>
- `pub morph_target_list: Rc<Vec<MorphTarget>>` (field, since 0.3.2): Morph target list. (up to MORPH_TARGET_MAXIMUM, shared with the asset and forked into this drawable's own on add_morph_target)
  - returns Rc<Vec<MorphTarget>>
- `pub morph_weights: Vec<f32>` (field, since 0.3.2): Weight per target. (same positions as morph_target_list)
  - returns Vec<f32>
- `pub morph_texture: Option<GlTexture>` (field, since 0.3.2): Morph delta texture. (RGBA32F, None if there are no targets or before upload)
  - returns Option<GlTexture>
- `pub morph_rows_per_target: i32` (field, since 0.3.2): Row count of one target block. (the position block and the normal block each have this many)
  - returns i32
- `pub morph_texture_width: i32` (field, since 0.3.2): Morph texture width. (texels, the vertex count clamped to 1 ~ 2048)
  - returns i32
- `pub is_morph_texture_shared: bool` (field, since 0.4.0): Whether the morph texture is shared with the asset. (if true, destroy does not delete it, and uploading again creates this drawable's own)
  - returns bool
- `pub is_morph_dirty: bool` (field, since 0.3.2): Whether the morph targets need to be uploaded again. (the renderer uploads them with upload_pending_morph_targets before drawing)
  - returns bool

## AnimationChannel (struct) (Clone, Debug)

Animation channel. (node index + path + time/value curve + keyframe cursor)

Example: Count only the rotation channels in a clip

```rust
use vanilla::{AnimationClip, AnimationPath};
use vanilla::graphics3d::skinnedmodel::AnimationChannel;

let animation_clip = AnimationClip {
	name: String::from("Rise"),
	duration: 2.0,
	channels: vec![AnimationChannel {
		node_index: 0,
		path: AnimationPath::Translation,
		times: vec![0.0, 2.0],
		values: vec![0.0, 0.0, 0.0, 0.0, 4.0, 0.0],
		cursor: 0,
	}],
};
let rotation_channel_count = animation_clip.channels.iter().filter(|channel| channel.path == AnimationPath::Rotation).count();
assert_eq!(rotation_channel_count, 0);
assert_eq!(animation_clip.channels[0].times.last().copied(), Some(animation_clip.duration));
```

- `pub node_index: usize` (field, since 0.3.2): Target node index.
  - returns usize
- `pub path: AnimationPath` (field, since 0.3.2): Channel path.
  - returns AnimationPath
- `pub times: Vec<f64>` (field, since 0.3.2): Key time list. (seconds, ascending)
  - returns Vec<f64>
- `pub values: Vec<f64>` (field, since 0.3.2): Value per key. (3 for translation and scale, 4 quaternion values for rotation, as many as the target count for morph weights)
  - returns Vec<f64>
- `pub cursor: usize` (field, since 0.3.2): Keyframe cursor. (key position of the last sampling, searched again from 0 when time goes backward)
  - returns usize

## AnimationClip (struct) (Clone, Debug)

Animation clip.

Example: Find the name of the longest clip

```rust
use vanilla::SkinnedModel;

fn find_longest_clip_name(skinned_model: &SkinnedModel) -> Option<String> {
	let animation_list = skinned_model.get_animation_list();
	let longest_clip = animation_list.iter().max_by(|left, right| left.duration.total_cmp(&right.duration))?;
	Some(longest_clip.name.clone())
}

let skinned_model = SkinnedModel::create_without_shader_program();
assert_eq!(find_longest_clip_name(&skinned_model), None);
```

- `pub name: String` (field, since 0.3.2): Clip name. (glTF animation name, for FBX the stack name or the name given when adding)
  - returns String
- `pub duration: f64` (field, since 0.3.2): Length. (seconds, the largest last key time among the channels, loops with this length)
  - returns f64
- `pub channels: Vec<AnimationChannel>` (field, since 0.3.2): Channel list.
  - returns Vec<AnimationChannel>

## SkinnedModel (struct)

Skinned model.

Example: Interpret glTF with two clips and cross-fade over 1 second (pose only, without GL)

```rust
use serde_json::json;
use vanilla::SkinnedModel;

let float_values: [f32; 23] = [
	0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0,
	0.0, 2.0,
	0.0, 0.0, 0.0, 0.0, 4.0, 0.0,
	0.0, 1.0, 0.0, 0.0, 1.0, 0.0,
];
let binary_buffer: Vec<u8> = float_values.iter().flat_map(|value| value.to_le_bytes()).collect();
let json = json!({
	"scenes": [{ "nodes": [0] }],
	"nodes": [{ "name": "Triangle", "mesh": 0 }],
	"meshes": [{ "primitives": [{ "attributes": { "POSITION": 0 } }] }],
	"accessors": [
		{ "bufferView": 0, "componentType": 5126, "count": 3, "type": "VEC3" },
		{ "bufferView": 1, "componentType": 5126, "count": 2, "type": "SCALAR" },
		{ "bufferView": 2, "componentType": 5126, "count": 2, "type": "VEC3" },
		{ "bufferView": 3, "componentType": 5126, "count": 2, "type": "VEC3" }
	],
	"bufferViews": [
		{ "buffer": 0, "byteOffset": 0, "byteLength": 36 },
		{ "buffer": 0, "byteOffset": 36, "byteLength": 8 },
		{ "buffer": 0, "byteOffset": 44, "byteLength": 24 },
		{ "buffer": 0, "byteOffset": 68, "byteLength": 24 }
	],
	"animations": [
		{ "name": "Rise", "samplers": [{ "input": 1, "output": 2 }], "channels": [{ "sampler": 0, "target": { "node": 0, "path": "translation" } }] },
		{ "name": "Hold", "samplers": [{ "input": 1, "output": 3 }], "channels": [{ "sampler": 0, "target": { "node": 0, "path": "translation" } }] }
	]
});
let mut skinned_model = SkinnedModel::create_without_shader_program();
skinned_model.interpret_content(&json, &binary_buffer).unwrap();
assert_eq!(skinned_model.get_animation_name_list(), vec![String::from("Rise"), String::from("Hold")]);
skinned_model.update(1.0);
assert_eq!(skinned_model.get_node_list()[0].current_translation, [0.0, 2.0, 0.0]);
skinned_model.play_animation("Hold", 1.0);
skinned_model.update(0.5);
assert_eq!(skinned_model.get_node_list()[0].current_translation, [0.0, 2.0, 0.0]);
skinned_model.update(0.5);
assert_eq!(skinned_model.get_node_list()[0].current_translation, [0.0, 1.0, 0.0]);
```

- `pub fn new(shader_program: Rc<ShaderProgram>) -> SkinnedModel` (constructor, since 0.3.2): Constructor. (the shader program is the renderer's template, renderer.get_shader_program())
  - `shader_program` Rc<ShaderProgram>: Shader program used for upload and drawing. (renderer.get_shader_program())
  - returns SkinnedModel: An empty model with no nodes, drawables or clips. (playback speed 1)
- `pub fn create_without_shader_program() -> SkinnedModel` (static, since 0.3.2): Creates without a shader. (a model that only interprets and computes poses, upload_meshes_and_materials is an error)
  - returns SkinnedModel: An empty model without a shader. (interpret_content, interpret_fbx_content and update work, upload_meshes_and_materials is Err)
- `pub fn load_from_bytes(gl: &crate::GlContext, bytes: &[u8], skinned_model_renderer: &SkinnedModelRenderer) -> Result<SkinnedModel, String>` (static, since 0.3.2): Loads from bytes. (GLB binary glTF, the part after fetch in the original static loadFromUrl)
  - `gl` &crate::GlContext: GL context to build the model in.
  - `bytes` &[u8]: All bytes of the GLB file.
  - `skinned_model_renderer` &SkinnedModelRenderer: Renderer that shares its shader program.
  - returns Result<SkinnedModel, String>: A fully uploaded model. (if there are clips, the first clip is set as playing) Err if it is not GLB or interpretation or upload fails.

  Example: Build a model from GLB bytes and compute the base pose

  ```rust
  use vanilla::{SkinnedModel, SkinnedModelRenderer};
  
  fn create_model(gl: &vanilla::GlContext, skinned_model_renderer: &SkinnedModelRenderer, glb_bytes: &[u8]) -> Result<SkinnedModel, String> {
  	let mut skinned_model = SkinnedModel::load_from_bytes(gl, glb_bytes, skinned_model_renderer)?;
  	skinned_model.update(0.0);
  	Ok(skinned_model)
  }
  ```

- `pub fn load_from_fbx_bytes(gl: &crate::GlContext, bytes: &[u8], skinned_model_renderer: &SkinnedModelRenderer) -> Result<SkinnedModel, String>` (static, since 0.3.2): Loads from bytes. (binary FBX, the part after fetch in the original static loadFromFbxUrl)
  - `gl` &crate::GlContext: GL context to build the model in.
  - `bytes` &[u8]: All bytes of the binary FBX file.
  - `skinned_model_renderer` &SkinnedModelRenderer: Renderer that shares its shader program.
  - returns Result<SkinnedModel, String>: A fully uploaded model. (only meshes with a skin attached become drawables) Err if parsing, interpretation or upload fails.

  Example: Attach an animation FBX to a character FBX by bone name and play it

  ```rust
  use vanilla::{SkinnedModel, SkinnedModelRenderer};
  
  fn create_character(gl: &vanilla::GlContext, skinned_model_renderer: &SkinnedModelRenderer, character_bytes: &[u8], walk_bytes: &[u8]) -> Result<SkinnedModel, String> {
  	let mut skinned_model = SkinnedModel::load_from_fbx_bytes(gl, character_bytes, skinned_model_renderer)?;
  	skinned_model.add_animations_from_fbx_bytes(walk_bytes, "Walk", true)?;
  	skinned_model.play_animation("Walk", 0.0);
  	Ok(skinned_model)
  }
  ```

- `pub fn load_from_url(engine: &Engine, url: &str) -> SkinnedModelLoadHandle` (static, since 0.4.0): Requests a load from an asset path (URL on the web). (GLB, the original static loadFromUrl, once loaded the handle's create_model builds it)
  - `engine` &Engine: Engine to ask for the bytes.
  - `url` &str: GLB asset path. (on desktop a path relative to the asset folder candidates, on the web an address relative to asset_base_url)
  - returns SkinnedModelLoadHandle: Load handle. (once loaded, build with create_model)
- `pub fn load_from_fbx_url(engine: &Engine, url: &str) -> SkinnedModelLoadHandle` (static, since 0.4.0): Requests a load from an asset path (URL on the web). (binary FBX, the original static loadFromFbxUrl)
  - `engine` &Engine: Engine to ask for the bytes.
  - `url` &str: Binary FBX asset path. (on desktop a path relative to the asset folder candidates, on the web an address relative to asset_base_url)
  - returns SkinnedModelLoadHandle: Load handle. (once loaded, build with create_model)
- `pub fn load_from_url_async(engine: &Engine, url: &str, skinned_model_renderer: &SkinnedModelRenderer) -> impl Future<Output = Result<SkinnedModel, String>> + 'static` (static, since 0.4.0): Loads a model from an asset path (URL on the web). (GLB, the original await SkinnedModel.loadFromUrl(gl, url, renderer), awaited inside an engine task)
  - Once loaded, it is built with the GL of the engine polling the task. The renderer only shares its current shader program, so the future does not borrow the renderer.
  - `engine` &Engine: Engine to ask for the bytes.
  - `url` &str: GLB asset path.
  - `skinned_model_renderer` &SkinnedModelRenderer: Renderer that shares its shader program.
  - returns impl Future<Output = Result<SkinnedModel, String>> + 'static: Future awaited inside an engine task. Err("SkinnedModel load failed: path") if loading fails, Err if polled outside a task of an engine with graphics attached, and that Err if interpretation or upload fails.

  Example: Load a model in an engine task and put it in a shared slot

  ```rust
  use std::cell::RefCell;
  use std::rc::Rc;
  use vanilla::{Engine, SkinnedModel, SkinnedModelRenderer};
  
  fn start_model_load(engine: &Engine, skinned_model_renderer: &SkinnedModelRenderer, model_slot: Rc<RefCell<Option<SkinnedModel>>>) {
  	let model_future = SkinnedModel::load_from_url_async(engine, "fox.glb", skinned_model_renderer);
  	engine.spawn_task(move |_engine_context| async move {
  		match model_future.await {
  			Ok(skinned_model) => {
  				*model_slot.borrow_mut() = Some(skinned_model);
  			}
  			Err(error_message) => {
  				eprintln!("{}", error_message);
  			}
  		}
  	});
  }
  ```

- `pub fn load_from_fbx_url_async(engine: &Engine, url: &str, skinned_model_renderer: &SkinnedModelRenderer) -> impl Future<Output = Result<SkinnedModel, String>> + 'static` (static, since 0.4.0): Loads a model from an asset path (URL on the web). (binary FBX, the original await SkinnedModel.loadFromFbxUrl(gl, url, renderer))
  - `engine` &Engine: Engine to ask for the bytes.
  - `url` &str: Binary FBX asset path.
  - `skinned_model_renderer` &SkinnedModelRenderer: Renderer that shares its shader program.
  - returns impl Future<Output = Result<SkinnedModel, String>> + 'static: Future awaited inside an engine task. Err("FbxLoader load failed: path") if loading fails, Err if polled outside a task of an engine with graphics attached, and that Err if parsing, interpretation or upload fails.
- `pub fn read_glb_chunks(bytes: &[u8]) -> Result<(Value, Vec<u8>), String>` (static, since 0.3.2): Reads GLB chunks. (header check + JSON chunk + BIN chunk, GL independent)
  - `bytes` &[u8]: All bytes of the GLB file.
  - returns Result<(Value, Vec<u8>), String>: (glTF JSON, BIN chunk bytes). Err if the header is not glTF, a chunk points outside the file, the JSON is broken, or either the JSON or BIN chunk is missing.

  Example: Take JSON and BIN out of a hand-wrapped GLB

  ```rust
  use vanilla::SkinnedModel;
  
  let json_bytes = br#"{"asset":{"version":"2.0"}}"#;
  let binary_bytes = [1u8, 2, 3, 4];
  let mut glb_bytes = Vec::new();
  glb_bytes.extend_from_slice(b"glTF");
  glb_bytes.extend_from_slice(&2u32.to_le_bytes());
  glb_bytes.extend_from_slice(&((12 + 8 + json_bytes.len() + 8 + binary_bytes.len()) as u32).to_le_bytes());
  glb_bytes.extend_from_slice(&(json_bytes.len() as u32).to_le_bytes());
  glb_bytes.extend_from_slice(b"JSON");
  glb_bytes.extend_from_slice(json_bytes);
  glb_bytes.extend_from_slice(&(binary_bytes.len() as u32).to_le_bytes());
  glb_bytes.extend_from_slice(b"BIN\0");
  glb_bytes.extend_from_slice(&binary_bytes);
  let (json, binary_buffer) = SkinnedModel::read_glb_chunks(&glb_bytes).unwrap();
  assert_eq!(json["asset"]["version"], "2.0");
  assert_eq!(binary_buffer, vec![1, 2, 3, 4]);
  assert!(SkinnedModel::read_glb_chunks(b"not a glb").is_err());
  ```

- `pub fn parse_binary(&mut self, gl: &crate::GlContext, bytes: &[u8]) -> Result<(), String>` (method, since 0.3.2): Interprets GLB binary. (chunk reading → content interpretation → GL upload)
  - `gl` &crate::GlContext: GL context to upload to.
  - `bytes` &[u8]: All bytes of the GLB file.
  - returns Result<(), String>: Ok when done. The Err of chunk reading, interpretation or upload.
- `pub fn parse_content(&mut self, gl: &crate::GlContext, json: &Value, binary_buffer: &[u8]) -> Result<(), String>` (method, since 0.3.2): Parses glTF content. (nodes / skins / meshes / animations / textures → GL upload)
  - `gl` &crate::GlContext: GL context to upload to.
  - `json` &Value: The whole glTF JSON.
  - `binary_buffer` &[u8]: BIN chunk bytes.
  - returns Result<(), String>: Ok when done. The Err of interpretation or upload.
- `pub fn interpret_content(&mut self, json: &Value, binary_buffer: &[u8]) -> Result<(Vec<MeshDescription>, Vec<MaterialDescription>), String>` (method, since 0.3.2): Parses glTF content. (GL independent, fills nodes / skins / animations and returns neutral mesh / material descriptions)
  - Replaces the model's nodes, roots, skins and clips with this content. If there are clips, the first clip is set as playing.
  - A primitive without normals has flat normals (one per triangle) as the glTF 2.0 specification says. The vertices are split per triangle and given the face normal, and indices is None.
  - `json` &Value: The whole glTF JSON.
  - `binary_buffer` &[u8]: BIN chunk bytes.
  - returns Result<(Vec<MeshDescription>, Vec<MaterialDescription>), String>: (mesh description list, material description list). Err if there is no node or scene, a missing mesh is referenced, a primitive has no POSITION, a skinned mesh has no JOINTS_0 or WEIGHTS_0, or an accessor cannot be read.
- `pub fn parse_fbx_content(&mut self, gl: &crate::GlContext, scene_data: &FbxSceneData) -> Result<(), String>` (method, since 0.3.2): Parses the FBX intermediate representation. (nodes/skins/meshes/textures/animations → existing skinning pipeline)
  - `gl` &crate::GlContext: GL context to upload to.
  - `scene_data` &FbxSceneData: Intermediate representation produced by FbxLoader.
  - returns Result<(), String>: Ok when done. The Err of upload.
- `pub fn interpret_fbx_content(&mut self, scene_data: &FbxSceneData) -> Result<(Vec<MeshDescription>, Vec<MaterialDescription>), String>` (method, since 0.3.2): Parses the FBX intermediate representation. (GL independent, fills nodes / skins / animations and returns neutral mesh / material descriptions)
  - Replaces the model's nodes, roots, skins and clips with this content. If there are clips, the first clip is set as playing.
  - `scene_data` &FbxSceneData: Intermediate representation produced by FbxLoader.
  - returns Result<(Vec<MeshDescription>, Vec<MaterialDescription>), String>: (Mesh description list, material description list). (One mesh per skin deformer with a connected geometry and per material that geometry uses, currently never returns Err)
- `pub fn add_animations_from_fbx_scene_data(&mut self, scene_data: &FbxSceneData, clip_name: &str, ignore_translation: bool)` (method, since 0.3.2): Adds an animation FBX. (retargeting by bone name matching, intermediate representation of an animation-only Mixamo FBX)
  - Assuming the same skeleton, adds clips by remapping channels to node indices of the current model.
  - ignore_translation: drops translation channels in clips with baked root motion. (when game logic controls the position)
  - clip_name: this name if there is one stack with channels, and "this name/stack name" per stack if there are several.
  - `scene_data` &FbxSceneData: Intermediate representation of the animation FBX.
  - `clip_name` &str: Name of the clip to add. (if there are several stacks, they all get this name)
  - `ignore_translation` bool: If true, translation channels are dropped.
- `pub fn add_animations_from_fbx_bytes(&mut self, bytes: &[u8], clip_name: &str, ignore_translation: bool) -> Result<(), String>` (method, since 0.3.2): Adds animation FBX. (bytes, the part after fetch in the original addAnimationsFromFbxUrl)
  - `bytes` &[u8]: All bytes of the animation FBX file.
  - `clip_name` &str: Name of the clip to add.
  - `ignore_translation` bool: If true, translation channels are dropped.
  - returns Result<(), String>: Ok if added. If parsing fails, no clip is added and Err is returned.

  Example: Bytes that are not FBX give Err with no clip

  ```rust
  use vanilla::SkinnedModel;
  
  let mut skinned_model = SkinnedModel::create_without_shader_program();
  assert!(skinned_model.add_animations_from_fbx_bytes(b"not an fbx", "Walk", true).is_err());
  assert!(skinned_model.get_animation_name_list().is_empty());
  ```

- `pub fn add_animations_from_fbx_url(&mut self, engine: &Engine, url: &str, clip_name: &str, ignore_translation: bool) -> AnimationLoadHandle` (method, since 0.4.0): Adds animation FBX. (asset path, the original addAnimationsFromFbxUrl, returns an awaitable handle)
  - Awaiting waits until loading finishes and the clips are added. (like the original, the clips are already added when await finishes)
    Even without await, they are added on the next update or play_animation after loading. They are added in load order. (the order in which the original async functions finish)
  - If loading or parsing fails, no clip is added, an error is printed, and await ends with the reason. (the original Promise is rejected)
  - Node names are matched against the nodes at the time of the call. Call it after the model is built.
  - `engine` &Engine: Engine to ask for the bytes.
  - `url` &str: Animation FBX asset path.
  - `clip_name` &str: Name of the clip to add.
  - `ignore_translation` bool: If true, translation channels are dropped.
  - returns AnimationLoadHandle: Awaitable load handle. (even if dropped, the model holds it and the clips are added)
- `pub fn upload_meshes_and_materials(&mut self, gl: &crate::GlContext, mesh_description_list: Vec<MeshDescription>, material_description_list: Vec<MaterialDescription>) -> Result<(), String>` (method, since 0.3.2): Upload neutral mesh/material descriptions. (shared path, creates Materials and builds vertex arrays/drawables)
  - Releases the previous asset first. (destroy, so calling it again does not leak)
  - Bundles the uploaded buffers, materials and morph textures with the current nodes, skins and clips into a new asset (SkinnedModelAsset, reference count 1), and this model becomes its first instance.
  - `gl` &crate::GlContext: GL context to upload to.
  - `mesh_description_list` Vec<MeshDescription>: Mesh description list.
  - `material_description_list` Vec<MaterialDescription>: Material description list. (the positions material_index points to)
  - returns Result<(), String>: Ok when done. Err if the model was made without a shader, or a material or GL object cannot be built.
- `pub fn create_from_asset(skinned_model_asset: &Rc<SkinnedModelAsset>) -> Result<SkinnedModel, String>` (static, since 0.4.0): Create an instance from an asset. (shares the asset's buffers, material prototypes and clips, keeps its own pose and playback state, no GPU upload)
  - `skinned_model_asset` &Rc<SkinnedModelAsset>: Asset to share.
  - returns Result<SkinnedModel, String>: New instance that added one to the asset's reference count. (nodes are copied from the prototypes taken when the asset was uploaded) Err if the asset was destroyed.
- `pub fn create_instance(&self) -> Result<SkinnedModel, String>` (method, since 0.4.0): Create an instance. (a new model sharing this model's asset; like Unity's Instantiate, GPU resources are not uploaded again)
  - returns Result<SkinnedModel, String>: New instance. (nodes copied from the prototypes taken when the asset was uploaded, playback starts fresh) Err before upload.

  Example: Load one fox and spawn ten

  ```rust
  use vanilla::SkinnedModel;
  
  fn spawn_foxes(source_model: &SkinnedModel) -> Result<Vec<SkinnedModel>, String> {
  	let mut model_list = Vec::new();
  	for model_index in 1..10 {
  		let mut instance_model = source_model.create_instance()?;
  		instance_model.play_animation(if model_index % 2 == 0 { "Walk" } else { "Run" }, 0.0);
  		model_list.push(instance_model);
  	}
  	Ok(model_list)
  }
  
  fn destroy_foxes(gl: &vanilla::GlContext, source_model: &mut SkinnedModel, model_list: &mut Vec<SkinnedModel>) {
  	let skinned_model_asset = source_model.get_asset().cloned();
  	for model in model_list.iter_mut() {
  		model.destroy(gl);
  	}
  	source_model.destroy(gl);
  	assert!(skinned_model_asset.is_some_and(|skinned_model_asset| skinned_model_asset.is_destroyed()));
  }
  ```

- `pub fn get_asset(&self) -> Option<&Rc<SkinnedModelAsset>>` (method, since 0.4.0): Return the asset.
  - returns Option<&Rc<SkinnedModelAsset>>: Shared asset. (None before upload or after destroy)
- `pub fn upload_wireframe_indices(&mut self, gl: &crate::GlContext, drawable_index: usize) -> Result<(), String>` (method, since 0.3.2): Upload wireframe indices. (Triangle indices → unique edge line indices, three edges per triangle for non-indexed meshes)
  - A separate element buffer independent of the drawable's vertex array. The renderer swaps it in briefly when drawing lines.
  - An already uploaded line buffer is deleted and uploaded again.
  - `gl` &crate::GlContext: GL context to upload to.
  - `drawable_index` usize: Drawable index.
  - returns Result<(), String>: Ok if uploaded. Err if there is no drawable or a buffer cannot be built.
- `pub fn split_fbx_corners_by_material(material_index_per_triangle: &[i32], corner_arrays: FbxCornerArrays) -> Vec<(usize, FbxCornerArrays)>` (static, since 0.4.0): Split FBX corners by material. (GL independent, non-indexed corner arrays)
  - When one mesh has several materials, it is drawn as one sub-mesh per material. (Groups in three.js FBXLoader, sub-meshes in Unity and Unreal)
  - Sub-meshes come in ascending material number and keep the original triangle order. With only one material number the arrays are used as they are.
  - `material_index_per_triangle` &[i32]: Material number per triangle. (A position in the owner node's material_ids, negative values count as 0)
  - `corner_arrays` FbxCornerArrays: Per corner: 3 position, 3 normal, 2 UV, 4 joint and 4 weight values.
  - returns Vec<(usize, FbxCornerArrays)>: List of (material number, corner arrays for that number).

  Example: Of three triangles only the middle one uses material 1 (two sub-meshes, with 2 triangles and 1)

  ```rust
  use vanilla::SkinnedModel;
  use vanilla::graphics3d::skinnedmodel::FbxCornerArrays;
  
  let corner_count = 9;
  let corner_arrays = FbxCornerArrays {
  	positions: (0..corner_count * 3).map(|index| index as f64).collect(),
  	normals: vec![0.0; corner_count * 3],
  	texture_coordinates: vec![0.0; corner_count * 2],
  	joints: vec![0; corner_count * 4],
  	weights: vec![0.0; corner_count * 4],
  };
  let sub_mesh_list = SkinnedModel::split_fbx_corners_by_material(&[0, 1, 0], corner_arrays);
  assert_eq!(sub_mesh_list.len(), 2);
  assert_eq!(sub_mesh_list[0].0, 0);
  assert_eq!(sub_mesh_list[0].1.positions.len() / 9, 2);
  assert_eq!(sub_mesh_list[1].1.positions[0], 9.0);
  ```

- `pub fn build_wireframe_edge_list(triangle_indices: Option<&IndexArray>, vertex_count: usize) -> Vec<usize>` (static, since 0.3.2): Builds the wireframe edge list. (GL independent, list of index pairs)
  - `triangle_indices` Option<&IndexArray>: Triangle indices. (when None, every 3 vertices form a triangle)
  - `vertex_count` usize: Vertex count.
  - returns Vec<usize>: List of line index pairs. (smaller index first, then larger, shared edges only once)

  Example: The 5 edges of a quad (two triangles)

  ```rust
  use vanilla::SkinnedModel;
  use vanilla::graphics3d::skinnedmodel::IndexArray;
  
  let quad_indices = IndexArray::UnsignedShort(vec![0, 1, 2, 2, 1, 3]);
  let edge_list = SkinnedModel::build_wireframe_edge_list(Some(&quad_indices), 4);
  assert_eq!(edge_list, vec![0, 1, 1, 2, 0, 2, 1, 3, 2, 3]);
  assert_eq!(SkinnedModel::build_wireframe_edge_list(None, 3), vec![0, 1, 1, 2, 2, 0]);
  ```

- `pub fn upload_morph_targets(&mut self, gl: &crate::GlContext, drawable_index: usize) -> Result<(), String>` (method, since 0.3.2): Uploads morph targets. (drawable's delta list → RGBA32F texture, position block + normal block per target)
  - texel index = vertex index. block start row = target index x 2 x rows per target.
  - `gl` &crate::GlContext: GL context to upload to.
  - `drawable_index` usize: Drawable index.
  - returns Result<(), String>: Ok if uploaded. (if there are no targets, the texture is deleted and Ok) Err if there is no drawable or the texture cannot be built.
- `pub fn build_morph_texel_data(morph_target_list: &[MorphTarget], vertex_count: usize) -> (usize, usize, Vec<f32>)` (static, since 0.3.2): Builds morph texel data. (GL independent, texture width, rows per target, RGBA float array)
  - `morph_target_list` &[MorphTarget]: Morph target list.
  - `vertex_count` usize: Vertex count.
  - returns (usize, usize, Vec<f32>): (texture width, rows per target, RGBA float array). (the width is the vertex count clamped to 1 ~ 2048, the height is rows x 2 x target count, alpha is 0)
- `pub fn upload_pending_morph_targets(&mut self, gl: &crate::GlContext)` (method, since 0.3.2): Uploads changed morph targets. (step 6 of the original update, only added/changed drawables, called by the renderer before drawing)
  - A drawable that fails to upload prints an error and is not uploaded again.
  - `gl` &crate::GlContext: GL context to upload to.
- `pub fn add_morph_target(&mut self, drawable_index: usize, target_name: &str, position_deltas: Vec<f64>, normal_deltas: Option<Vec<f64>>) -> Result<(), String>` (method, since 0.3.2): Adds a morph target. (created in code, per-vertex position deltas [+ normal deltas], uploaded before the next draw)
  - `drawable_index` usize: Drawable index.
  - `target_name` &str: Target name. (set_morph_weight looks it up by this name)
  - `position_deltas` Vec<f64>: Position delta per vertex. (must be vertex count x 3)
  - `normal_deltas` Option<Vec<f64>>: Normal delta per vertex. (normals are left as is when None)
  - returns Result<(), String>: Ok if added. (starts at weight 0) Err if there is no drawable, there are already MORPH_TARGET_MAXIMUM targets, or the delta count does not match.

  Example: Add a target that moves every vertex of the first drawable up and apply it halfway (Err if there is no drawable)

  ```rust
  use vanilla::SkinnedModel;
  
  fn add_lift_target(skinned_model: &mut SkinnedModel) -> Result<(), String> {
  	let vertex_count = skinned_model.get_drawable_list().first().map(|drawable| drawable.vertex_count).unwrap_or(0);
  	let mut position_deltas = vec![0.0; vertex_count * 3];
  	for vertex_index in 0..vertex_count {
  		position_deltas[vertex_index * 3 + 1] = 0.1;
  	}
  	skinned_model.add_morph_target(0, "Lift", position_deltas, None)?;
  	skinned_model.set_morph_weight("Lift", 0.5);
  	Ok(())
  }
  
  let mut skinned_model = SkinnedModel::create_without_shader_program();
  assert!(add_lift_target(&mut skinned_model).is_err());
  ```

- `pub fn set_morph_weight(&mut self, target_name: &str, weight: f64)` (method, since 0.3.2): Sets the morph weight. (all targets with a matching name, several drawables can share the same name)
  - `target_name` &str: Target name. (all targets with the same name)
  - `weight` f64: Weight. (0 = none, 1 = the full delta, not clamped)
- `pub fn get_morph_weight(&self, target_name: &str) -> f64` (method, since 0.3.2): Returns the morph weight. (first matching target, 0 if none)
  - `target_name` &str: Target name.
  - returns f64: Weight of the first matching target. 0 if none.
- `pub fn set_material(&mut self, drawable_index: usize, material: Rc<Material>) -> Result<(), String>` (method, since 0.3.2): Replaces the material. (per drawable, applies a material instance made from an external texture)
  - `drawable_index` usize: Drawable index.
  - `material` Rc<Material>: Material to swap in.
  - returns Result<(), String>: Ok if swapped. Err if there is no drawable.
- `pub fn get_material(&mut self, drawable_index: usize) -> Result<Rc<Material>, String>` (method, since 0.4.0): Return this instance's material. (Unity Renderer.material: the first call forks a copy of the current material and puts it on this drawable)
  - The copy borrows the textures and keeps its own values. Changing them leaves other instances of the same asset as they are. This model's destroy deletes the copy.
  - If it is already this instance's copy, returns it.
  - `drawable_index` usize: Drawable index.
  - returns Result<Rc<Material>, String>: Material used only by this instance. Err if the drawable does not exist.

  Example: Tint only one of several in red

  ```rust
  use vanilla::SkinnedModel;
  
  fn tint_red(blue_fox: &SkinnedModel) -> Result<SkinnedModel, String> {
  	let mut red_fox = blue_fox.create_instance()?;
  	red_fox.get_material(0)?.set_base_color_factor([1.0, 0.3, 0.3]);
  	assert_ne!(blue_fox.get_shared_material(0)?.get_base_color_factor(), red_fox.get_shared_material(0)?.get_base_color_factor());
  	Ok(red_fox)
  }
  ```

- `pub fn get_shared_material(&self, drawable_index: usize) -> Result<Rc<Material>, String>` (method, since 0.4.0): Return the material on the drawable. (Unity Renderer.sharedMaterial, does not fork. If it is the asset's prototype, changing it changes every instance of that asset)
  - `drawable_index` usize: Drawable index.
  - returns Result<Rc<Material>, String>: Material currently on the drawable. (the copy if get_material forked it, or the one given to set_material) Err if the drawable does not exist.
- `pub fn generate_smooth_normals(positions: &[f64], indices: Option<&IndexArray>) -> Vec<f64>` (static, since 0.3.2): Generates smooth normals. (meshes without normals, based on the bind pose, skinning rotation is applied in the shader)
  - `positions` &[f64]: Vertex positions. (3 each)
  - `indices` Option<&IndexArray>: Triangle indices. (when None, every 3 vertices form a triangle)
  - returns Vec<f64>: Unit normal per vertex. (same length as positions, face normals are added with area weighting and normalized. 0 for vertices not used by any triangle)

  Example: A counterclockwise triangle on the xy plane is +Z

  ```rust
  use vanilla::SkinnedModel;
  
  let positions = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0];
  let normals = SkinnedModel::generate_smooth_normals(&positions, None);
  assert_eq!(normals, vec![0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0]);
  ```

- `pub fn bind_float_attribute(gl: &crate::GlContext, shader_program: &ShaderProgram, attribute_name: &str, data_array: &[f64], component_count: i32) -> Result<Option<GlBuffer>, String>` (static, since 0.3.2): Binds a float attribute. (creates a new buffer + sets the pointer, None if the shader does not use the attribute)
  - Attaches to the currently bound vertex array.
  - `gl` &crate::GlContext: GL context.
  - `shader_program` &ShaderProgram: Shader to look up the attribute location in.
  - `attribute_name` &str: Attribute name. (such as vertexPosition)
  - `data_array` &[f64]: Vertex data.
  - `component_count` i32: Components per vertex. (1 ~ 4)
  - returns Result<Option<GlBuffer>, String>: Newly built vertex buffer. Ok(None) if the shader does not use that attribute, Err if the buffer cannot be built.
- `pub fn bind_integer_attribute(gl: &crate::GlContext, shader_program: &ShaderProgram, attribute_name: &str, data_array: &[u16], component_count: i32) -> Result<Option<GlBuffer>, String>` (static, since 0.3.2): Binds an integer attribute. (joint indices, None if the shader does not use the attribute)
  - Attaches to the currently bound vertex array. The shader reads it as an integer attribute (such as uvec4).
  - `gl` &crate::GlContext: GL context.
  - `shader_program` &ShaderProgram: Shader to look up the attribute location in.
  - `attribute_name` &str: Attribute name. (such as vertexJoints)
  - `data_array` &[u16]: u16 vertex data.
  - `component_count` i32: Components per vertex. (1 ~ 4)
  - returns Result<Option<GlBuffer>, String>: Newly built vertex buffer. Ok(None) if the shader does not use that attribute, Err if the buffer cannot be built.
- `pub fn play_animation(&mut self, animation_name: &str, fade_duration: f64)` (method, since 0.3.2): Plays an animation. (crossfade, the last one like the original if several have the same name, the original fadeDuration default 0.25. Adds the clips of fully received animation FBX first)
  - `animation_name` &str: Name of the clip to play. (ignored if the name does not exist or is the same as the current clip)
  - `fade_duration` f64: Cross-fade time. (seconds, at 0 it switches right away on the next update)
- `pub fn sample_animation(&mut self, animation_index: usize, time: f64, blend_weight: f64)` (method, since 0.3.2): Samples an animation. (clip index, weighted blend into the current node pose)
  - `animation_index` usize: Clip index. (ignored if out of range)
  - `time` f64: Clip time. (seconds, loops using the remainder of division by the clip length)
  - `blend_weight` f64: Blend ratio. (0 ~ 1, 0 keeps the current pose, 1 is the clip value)
- `pub fn update(&mut self, delta_time: f64)` (method, since 0.3.2): Update. (adds clips of loaded animation FBX → advances time → samples the pose → computes world/joint matrices, GL independent)
  - `delta_time` f64: Elapsed time. (seconds, the playback speed is multiplied into the clip time but not into the cross-fade time)
- `pub fn set_joint_rotation_offset(&mut self, joint_name_part: &str, offset_rotation: Quaternion)` (method, since 0.3.2): Sets a joint rotation offset. (accumulates local rotation on nodes whose name partially matches)
  - `joint_name_part` &str: Text contained in the node name. (partial match, all matching nodes)
  - `offset_rotation` Quaternion: Rotation multiplied after the sampled local rotation. (giving it again for the same node replaces it)

  Example: Rotate nodes whose name contains Head 30 degrees more around the Y axis

  ```rust
  use vanilla::{Quaternion, SkinnedModel};
  
  let mut skinned_model = SkinnedModel::create_without_shader_program();
  skinned_model.set_joint_rotation_offset("Head", Quaternion::create_from_euler(0.0, 30.0f64.to_radians(), 0.0));
  skinned_model.update(0.0);
  skinned_model.clear_joint_rotation_offsets();
  ```

- `pub fn clear_joint_rotation_offsets(&mut self)` (method, since 0.3.2): Clears all joint rotation offsets.
- `pub fn get_animation_name_list(&self) -> Vec<String>` (method, since 0.3.2): Returns the list of animation names.
  - returns Vec<String>: List of clip names. (in clip order, several may share a name)
- `pub fn set_time_scale(&mut self, time_scale: f64)` (method, since 0.3.2): Sets the playback speed.
  - `time_scale` f64: Playback speed multiplier. (default 1, stops at 0, not applied to the cross-fade time)
- `pub fn get_shader_program(&self) -> Option<&Rc<ShaderProgram>>` (method, since 0.3.2): Returns the shader program. (None for a model made without a shader)
  - returns Option<&Rc<ShaderProgram>>: Shader program used for upload. None for a model made without a shader.
- `pub fn get_node_list(&self) -> &[SkinnedModelNode]` (method, since 0.3.2): Returns the node list.
  - returns &[SkinnedModelNode]: Node list. (in node index order)
- `pub fn get_node_list_mut(&mut self) -> &mut [SkinnedModelNode]` (method, since 0.3.2): Returns the node list. (for modification, the original hands out the live array)
  - returns &mut [SkinnedModelNode]: Mutable node list. (changing the base_ values changes the base pose from the next update)
- `pub fn get_root_node_indices(&self) -> &[usize]` (method, since 0.3.2): Returns the list of root node indices.
  - returns &[usize]: Root node index list.
- `pub fn get_skin_list(&self) -> &[Skin]` (method, since 0.3.2): Returns the skin list.
  - returns &[Skin]: Skin list. (the joint matrices are from the last update)
- `pub fn get_drawable_list(&self) -> &[Drawable]` (method, since 0.3.2): Returns the drawable list.
  - returns &[Drawable]: Drawable list. (empty before upload or for a model made without a shader)
- `pub fn get_drawable_list_mut(&mut self) -> &mut [Drawable]` (method, since 0.3.2): Returns the drawable list. (for modification)
  - returns &mut [Drawable]: Mutable drawable list.
- `pub fn get_animation_list(&self) -> std::cell::Ref<'_, [AnimationClip]>` (method, since 0.3.2): Returns the animation clip list. (for viewing lengths and channels. The list is shared with animation FBX load handles, so it is given as a borrowed value)
  - returns std::cell::Ref<'_, [AnimationClip]>: Borrowed value of the clip list. (while the `Ref` is held, an AnimationLoadFuture being awaited cannot add clips and waits)
- `pub fn destroy(&mut self, gl: &crate::GlContext)` (method, since 0.3.2): Destroy. (deletes this instance's resources and releases the asset; for the last instance the asset deletes its buffers, vertex arrays, morph textures and material prototypes)
  - This instance's resources: wireframe buffers, morph textures forked by add_morph_target, materials forked by get_material.
  - Materials given from outside with set_material are not deleted. If the asset's material prototypes were put on another model, they are deleted together when the asset is destroyed.
  - `gl` &crate::GlContext: GL context the drawables were built in.

## AnimationLoadHandle (struct) (Clone, std::fmt::Debug, IntoFuture)

Animation FBX load handle. (returned by SkinnedModel::add_animations_from_fbx_url, stands in for the Promise of the original addAnimationsFromFbxUrl)
- Awaiting waits until loading finishes and the clips are added to the model. If loading or parsing fails, it ends with the reason. (the original reject)

Example: Attach a walk clip and play it once attached

```rust
use std::cell::RefCell;
use std::rc::Rc;
use vanilla::{Engine, SkinnedModel};

fn add_walk_clip(engine: &Engine, skinned_model: Rc<RefCell<SkinnedModel>>) {
	let animation_load_handle = skinned_model.borrow_mut().add_animations_from_fbx_url(engine, "anims/walk.fbx", "Walk", true);
	engine.spawn_task(move |_engine_context| async move {
		if animation_load_handle.await.is_ok() {
			skinned_model.borrow_mut().play_animation("Walk", 0.25);
		}
	});
}
```

- `pub fn get_load_handle(&self) -> &AssetLoadHandle` (method, since 0.4.0): Byte read handle. (for handing to a scene)
  - returns &AssetLoadHandle: FBX byte read handle. (passed to SceneBase::track_load_handle)
- `pub fn is_finished(&self) -> bool` (method, since 0.4.0): Whether it has finished. (clips added or failed)
  - returns bool: true if the clips were added or loading or parsing failed. (even after all bytes are loaded, false until one of update, play_animation or await adds them)

## AnimationLoadFuture (struct) (Clone, Future)

Future that waits for the animation FBX load. (once loaded, it adds the clips and finishes)

Example: Turn the handle into a future and get the failure reason

```rust
use std::future::IntoFuture;
use vanilla::{AnimationLoadFuture, Engine, SkinnedModel};

fn request_idle_clip(engine: &Engine, skinned_model: &mut SkinnedModel) {
	let animation_load_future: AnimationLoadFuture = skinned_model.add_animations_from_fbx_url(engine, "anims/idle.fbx", "Idle", false).into_future();
	engine.spawn_task(move |_engine_context| async move {
		if let Err(error_message) = animation_load_future.await {
			eprintln!("{}", error_message);
		}
	});
}
```

## SkinnedModelLoadHandle (struct) (Clone, Debug)

Model load handle. (returned by SkinnedModel::load_from_url and load_from_fbx_url, stands in for the Promise of the original loadFromUrl and loadFromFbxUrl)
- A scene can hand get_load_handle to SceneBase::track_load_handle to defer initialize until loading finishes.
- The model is built with create_model(gl, renderer) where GL is available.

Example: The scene tracks the load and builds the renderer and model in draw, where GL is available

```rust
use vanilla::{Engine, Graphic, Scene, SceneBase, SkinnedModel, SkinnedModelLoadHandle, SkinnedModelRenderer};

struct CharacterScene {
	scene_base: SceneBase,
	model_load_handle: Option<SkinnedModelLoadHandle>,
	skinned_model_renderer: Option<SkinnedModelRenderer>,
	skinned_model: Option<SkinnedModel>,
}

impl Scene for CharacterScene {
	fn get_scene_base(&self) -> &SceneBase {
		&self.scene_base
	}

	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
		&mut self.scene_base
	}

	fn load(&mut self, engine: &Engine) {
		let model_load_handle = SkinnedModel::load_from_url(engine, "fox.glb");
		self.scene_base.track_load_handle(model_load_handle.get_load_handle());
		self.model_load_handle = Some(model_load_handle);
	}

	fn tick(&mut self, time_delta: f64) {
		self.scene_base.tick(time_delta);
		if let Some(skinned_model) = &mut self.skinned_model {
			skinned_model.update(time_delta);
		}
	}

	fn draw(&mut self, graphic: &mut Graphic) {
		let gl = graphic.get_gl();
		if self.skinned_model_renderer.is_none() {
			self.skinned_model_renderer = SkinnedModelRenderer::new(gl, None, None).ok();
		}
		let model_result = match (&self.skinned_model_renderer, &self.model_load_handle) {
			(Some(skinned_model_renderer), Some(model_load_handle)) => {
				model_load_handle.create_model(gl, skinned_model_renderer)
			}
			_ => {
				None
			}
		};
		if let Some(model_result) = model_result {
			self.model_load_handle = None;
			match model_result {
				Ok(skinned_model) => {
					self.skinned_model = Some(skinned_model);
				}
				Err(error_message) => {
					eprintln!("{}", error_message);
				}
			}
		}
	}
}
```

- `pub fn get_load_handle(&self) -> &AssetLoadHandle` (method, since 0.4.0): Byte read handle. (for handing to a scene)
  - returns &AssetLoadHandle: Byte read handle. (passed to SceneBase::track_load_handle)
- `pub fn is_finished(&self) -> bool` (method, since 0.4.0): Whether it has finished. (loaded or failed)
  - returns bool: true if loading has finished (loaded or failed).
- `pub fn create_model(&self, gl: &crate::GlContext, skinned_model_renderer: &SkinnedModelRenderer) -> Option<Result<SkinnedModel, String>>` (method, since 0.4.0): Builds a model from the loaded bytes. (None while loading, Err when loading or interpretation fails. The original message is "SkinnedModel load failed: url")
  - Uses the asset cache. If an asset for the same path (SkinnedModelAsset::normalize_key) exists with the same shader program, returns a new instance sharing it without parsing or uploading.
    Otherwise builds from the loaded bytes and adds it to the cache. (calling again after it finished creates one more instance)
  - A handle does not know the renderer when the load is requested, so it reads the bytes. (concurrent loads of the same file read once)
  - `gl` &crate::GlContext: GL context to build the model in. (graphic.get_gl())
  - `skinned_model_renderer` &SkinnedModelRenderer: Renderer that shares its shader program.
  - returns Option<Result<SkinnedModel, String>>: None while loading. When finished, the built model, Err("SkinnedModel load failed: path", for FBX "FbxLoader load failed: path") when loading fails, and that Err when interpretation or upload fails.

## Functions and constants

- `pub const COMPONENT_TYPE_BYTE: u32 = 5120` (field, since 0.4.0): Signed 8-bit integer. (glTF componentType 5120, such as KHR_mesh_quantization normals)
  - returns u32
- `pub const COMPONENT_TYPE_UNSIGNED_BYTE: u32 = 5121` (field, since 0.3.2): Accessor component type. (the keys of the original COMPONENT_ARRAY_TABLE)
  - returns u32
- `pub const COMPONENT_TYPE_SHORT: u32 = 5122` (field, since 0.4.0): Signed 16-bit integer. (glTF componentType 5122, such as KHR_mesh_quantization positions, normals and rotation animations)
  - returns u32
- `pub const COMPONENT_TYPE_UNSIGNED_SHORT: u32 = 5123` (field, since 0.3.2): Unsigned 16-bit integer. (glTF componentType 5123)
  - returns u32
- `pub const COMPONENT_TYPE_UNSIGNED_INT: u32 = 5125` (field, since 0.3.2): Unsigned 32-bit integer. (glTF componentType 5125)
  - returns u32
- `pub const COMPONENT_TYPE_FLOAT: u32 = 5126` (field, since 0.3.2): 32-bit float. (glTF componentType 5126)
  - returns u32
- `pub const MORPH_TARGET_MAXIMUM: usize = 96` (field, since 0.3.2): Maximum morph targets per drawable. (matches the shader uniform array size)
  - returns usize
- `pub fn create_quaternion_from_fbx_euler(x_degree: f64, y_degree: f64, z_degree: f64) -> Quaternion` (method, since 0.3.2): FBX Euler (degrees) → quaternion. (eEulerXYZ = X applied first, composed as Rz x Ry x Rx for column vectors)
  - `x_degree` f64: Rotation around the X axis. (degrees)
  - `y_degree` f64: Rotation around the Y axis. (degrees)
  - `z_degree` f64: Rotation around the Z axis. (degrees)
  - returns Quaternion: Rotation applied in X, Y, Z order.

  Example: X 90 degrees then Z 90 degrees: the +X axis goes to +Y

  ```rust
  use vanilla::Matrix4;
  use vanilla::graphics3d::skinnedmodel::create_quaternion_from_fbx_euler;
  
  let rotation = create_quaternion_from_fbx_euler(90.0, 0.0, 90.0);
  let rotated_x = Matrix4::create_rotation_from_quaternion(rotation).transform_direction(1.0, 0.0, 0.0);
  assert!((rotated_x.y - 1.0).abs() < 1.0e-5);
  ```

- `pub fn read_accessor_array(json: &Value, binary_buffer: &[u8], accessor_index: usize) -> Result<AccessorArray, String>` (method, since 0.3.2): Reads an accessor on the CPU. (supports tightly packed + interleaved (byte_stride) + sparse accessors)
  - `json` &Value: The whole glTF JSON.
  - `binary_buffer` &[u8]: BIN chunk bytes.
  - `accessor_index` usize: Accessor index.
  - returns Result<AccessorArray, String>: Array in the component type as is. (not normalized, accessors without a bufferView are filled with 0) Err if the accessor does not exist, the type is unknown, it points outside the buffer, or it points to a buffer outside the binary chunk (buffers[0]).

  Example: Read one float VEC2 accessor

  ```rust
  use serde_json::json;
  use vanilla::graphics3d::skinnedmodel::{read_accessor_array, AccessorArray};
  
  let binary_buffer: Vec<u8> = [0.5f32, 1.0, 1.5, 2.0].iter().flat_map(|value| value.to_le_bytes()).collect();
  let json = json!({
  	"accessors": [{ "bufferView": 0, "componentType": 5126, "count": 2, "type": "VEC2" }],
  	"bufferViews": [{ "buffer": 0, "byteOffset": 0, "byteLength": 16 }]
  });
  assert_eq!(read_accessor_array(&json, &binary_buffer, 0), Ok(AccessorArray::Float(vec![0.5, 1.0, 1.5, 2.0])));
  assert!(read_accessor_array(&json, &binary_buffer, 1).is_err());
  ```

- `pub fn read_float_accessor_array(json: &Value, binary_buffer: &[u8], accessor_index: usize) -> Result<Vec<f64>, String>` (method, since 0.4.0): CPU read of an accessor used as floats. (positions, normals, texture coordinates, morph deltas, animation values, dequantizing KHR_mesh_quantization integer attributes into floats)
  - Normalized integers are divided with the glTF spec formulas. (unsigned ones as c / 255, c / 65535, signed ones as max(c / 127, -1), max(c / 32767, -1))
  - Non-normalized integers are moved to floats as is. (the node transform or inverseBindMatrices takes care of position scale and offset, KHR_texture_transform takes care of texture coordinates)
  - `json` &Value: The whole glTF JSON.
  - `binary_buffer` &[u8]: BIN chunk bytes.
  - `accessor_index` usize: Accessor index.
  - returns Result<Vec<f64>, String>: A new list of values rounded to 32-bit floats, stored as f64. (the same values as the original's Float32Array) If read_accessor_array returns Err, that Err.

  Example: Reading a normalized SHORT VEC2 accessor (-32768 is below -1, so it is clamped to -1)

  ```rust
  use serde_json::json;
  use vanilla::graphics3d::skinnedmodel::read_float_accessor_array;
  
  let binary_buffer: Vec<u8> = [-32768i16, 32767, 0, 16384].iter().flat_map(|value| value.to_le_bytes()).collect();
  let json = json!({
  	"accessors": [{ "bufferView": 0, "componentType": 5122, "normalized": true, "count": 2, "type": "VEC2" }],
  	"bufferViews": [{ "buffer": 0, "byteOffset": 0, "byteLength": 8 }]
  });
  let values = read_float_accessor_array(&json, &binary_buffer, 0).unwrap();
  assert_eq!(values[..3], [-1.0, 1.0, 0.0]);
  assert_eq!(values[3], (16384.0f64 / 32767.0) as f32 as f64);
  ```

## AnimationPath (enum) (Clone, Copy, Debug, PartialEq, Eq, Hash)

Animation channel path. (the original strings "translation" / "rotation" / "scale" / "weights")

- `Translation`: Translation. (3 per key: x, y, z)
- `Rotation`: Rotation. (4 per key: quaternion x, y, z, w)
- `Scale`: Scale. (3 per key: x, y, z)
- `Weights`: Morph weights. (as many per key as there are morph targets)

- `pub fn from_name(path_name: &str) -> Option<AnimationPath>` (static, since 0.3.2): From a glTF path string. (None for an unknown path)
  - `path_name` &str: glTF channel path. ("translation", "rotation", "scale", "weights", the case must match too)
  - returns Option<AnimationPath>: The matching path. None for an unknown string.

## IndexArray (enum) (Clone, Debug, PartialEq)

Index array. (the original Uint16Array / Uint32Array)

- `UnsignedShort` = `UnsignedShort(Vec<u16>)`: 16-bit indices. (GL UNSIGNED_SHORT)
- `UnsignedInt` = `UnsignedInt(Vec<u32>)`: 32-bit indices. (GL UNSIGNED_INT)

- `pub fn len(&self) -> usize` (method, since 0.3.2): Index count.
  - returns usize: Index count.
- `pub fn is_empty(&self) -> bool` (method, since 0.3.2): Whether it is empty.
  - returns bool: true if empty.
- `pub fn get(&self, position: usize) -> usize` (method, since 0.3.2): Returns one index.
  - `position` usize: Index position. (from 0, panics if out of range)
  - returns usize: Index value at that position.
- `pub fn get_gl_component_type(&self) -> u32` (method, since 0.3.2): GL element type. (UNSIGNED_SHORT / UNSIGNED_INT)
  - returns u32: glow::UNSIGNED_SHORT or glow::UNSIGNED_INT.

## AccessorArray (enum) (Clone, Debug, PartialEq)

Accessor array. (the typed array returned by the original readAccessorArray, component type as is)

- `Byte` = `Byte(Vec<i8>)`: Signed 8-bit. (componentType 5120)
- `UnsignedByte` = `UnsignedByte(Vec<u8>)`: Unsigned 8-bit. (componentType 5121)
- `Short` = `Short(Vec<i16>)`: Signed 16-bit. (componentType 5122)
- `UnsignedShort` = `UnsignedShort(Vec<u16>)`: Unsigned 16-bit. (componentType 5123)
- `UnsignedInt` = `UnsignedInt(Vec<u32>)`: Unsigned 32-bit. (componentType 5125)
- `Float` = `Float(Vec<f32>)`: 32-bit float. (componentType 5126)

- `pub fn len(&self) -> usize` (method, since 0.3.2): Element (component) count.
  - returns usize: Component count. (element count x components per element)
- `pub fn is_empty(&self) -> bool` (method, since 0.3.2): Whether it is empty.
  - returns bool: true if empty.
- `pub fn get_component_type(&self) -> u32` (method, since 0.3.2): Component type. (5120 / 5121 / 5122 / 5123 / 5125 / 5126)
  - returns u32: glTF component type number. (constants such as COMPONENT_TYPE_UNSIGNED_BYTE)
- `pub fn to_float_list(&self) -> Vec<f64>` (method, since 0.3.2): To a float list. (the original new Float32Array(typedArray), integers are not normalized and keep their values)
  - returns Vec<f64>: A new list converted to f64.
- `pub fn to_unsigned_short_list(&self) -> Vec<u16>` (method, since 0.3.2): To a 16-bit integer list. (the original new Uint16Array(typedArray))
  - returns Vec<u16>: A new list converted to u16. (signed integers and u32 keep only the lower 16 bits, floats drop the fractional part and are clamped to 0 ~ 65535)
- `pub fn to_index_array(&self) -> IndexArray` (method, since 0.3.2): To an index array. (the original: Uint8 is widened to Uint16, the rest as is)
  - returns IndexArray: Index array. (UnsignedInt stays 32-bit, the rest 16-bit)
