vrm-spec 0.1.0

VRM data structures
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
//! Data structures for the [`VRMC_vrm`](https://github.com/vrm-c/vrm-specification/tree/master/specification/VRMC_vrm-1.0) 1.0 glTF Extension.

pub mod expression_preset_name;
pub mod human_bone_name;

pub use expression_preset_name::ExpressionPresetName;
pub use human_bone_name::HumanBoneName;
use serde::{Deserialize, Serialize};

/// VRMC_VRM extension name
pub const VRMC_VRM: &str = "VRMC_vrm";

#[cfg(feature = "rustc_hash")]
use rustc_hash::FxHashMap as HashMap;
#[cfg(not(feature = "rustc_hash"))]
use std::collections::HashMap;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VRMCVrmSchema {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expressions: Option<Expressions>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    /// First-person perspective settings
    #[serde(skip_serializing_if = "Option::is_none")]
    pub first_person: Option<FirstPerson>,

    pub humanoid: Humanoid,

    /// Eye gaze control
    #[serde(skip_serializing_if = "Option::is_none")]
    pub look_at: Option<LookAt>,

    /// Meta informations of the VRM model
    pub meta: Meta,

    /// Specification version of VRMC_vrm
    pub spec_version: String,
}

/// Definition of expressions
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Expressions {
    /// Custom expressions
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom: Option<HashMap<String, Expression>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    /// Preset expressions
    #[serde(skip_serializing_if = "Option::is_none")]
    pub preset: Option<Preset>,
}

/// Definition of expression by weighted animation
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Expression {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    /// A value greater than 0.5 is 1.0, otherwise 0.0
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_binary: Option<bool>,

    /// Material color animation references
    #[serde(skip_serializing_if = "Option::is_none")]
    pub material_color_binds: Option<Vec<MaterialColorBind>>,

    /// Specify a morph target
    #[serde(skip_serializing_if = "Option::is_none")]
    pub morph_target_binds: Option<Vec<MorphTargetBind>>,

    /// Override values of Blink expressions when this Expression is enabled
    #[serde(skip_serializing_if = "Option::is_none")]
    pub override_blink: Option<ExpressionOverrideType>,

    /// Override values of LookAt expressions when this Expression is enabled
    #[serde(skip_serializing_if = "Option::is_none")]
    pub override_look_at: Option<ExpressionOverrideType>,

    /// Override values of Mouth expressions when this Expression is enabled
    #[serde(skip_serializing_if = "Option::is_none")]
    pub override_mouth: Option<ExpressionOverrideType>,

    /// Texture transform animation references
    #[serde(skip_serializing_if = "Option::is_none")]
    pub texture_transform_binds: Option<Vec<TextureTransformBind>>,
}

/// Material color value associated with a expression
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MaterialColorBind {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    /// target material
    #[cfg(feature = "gltf_index")]
    pub material: gltf::json::Index<gltf::json::Material>,
    #[cfg(not(feature = "gltf_index"))]
    pub material: usize,

    /// target color
    pub target_value: Vec<f64>,

    pub r#type: MaterialColorType,
}

/// Morph target value associated with a expression
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MorphTargetBind {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    /// The index of the morph target in the mesh.
    pub index: usize,

    /// The index of the node that attached to target mesh.
    #[cfg(feature = "gltf_index")]
    pub node: gltf::json::Index<gltf::json::Node>,
    #[cfg(not(feature = "gltf_index"))]
    pub node: usize,

    /// The weight value of target morph target.
    pub weight: f64,
}

/// Texture transform value associated with a expression
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TextureTransformBind {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    /// target material
    #[cfg(feature = "gltf_index")]
    pub material: gltf::json::Index<gltf::json::Node>,
    #[cfg(not(feature = "gltf_index"))]
    pub material: usize,

    /// uv offset for TEXCOORD_0
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<Vec<f64>>,

    /// uv scaling for TEXCOORD_0
    #[serde(skip_serializing_if = "Option::is_none")]
    pub scale: Option<Vec<f64>>,
}
/// Preset expressions
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Preset(pub HashMap<ExpressionPresetName, Expression>);

/// First-person perspective settings
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FirstPerson {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    /// Mesh rendering annotation for cameras.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mesh_annotations: Option<Vec<MeshAnnotation>>,
}

/// Specify how the mesh should be interpreted by the camera
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MeshAnnotation {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    /// The index of the node that attached to target mesh.
    #[cfg(feature = "gltf_index")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub node: Option<gltf::json::Index<gltf::json::Node>>,
    #[cfg(not(feature = "gltf_index"))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub node: Option<usize>,

    /// How the camera interprets the mesh.
    #[serde(rename = "type")]
    pub mesh_annotation_type: FirstPersonType,
}

/// Correspondence between nodes and human bones
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Humanoid {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    pub human_bones: HumanBones,
}

/// Represents a set of humanBones of a humanoid.
// FIXME: all bones are optional by now
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HumanBones(pub HashMap<HumanBoneName, Option<HumanBone>>);

/// Represents a single bone of a Humanoid.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HumanBone {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    /// Represents a single glTF node tied to this humanBone.
    #[cfg(feature = "gltf_index")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub node: Option<gltf::json::Index<gltf::json::Node>>,
    #[cfg(not(feature = "gltf_index"))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub node: Option<usize>,
}

/// Eye gaze control
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LookAt {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    /// The origin of LookAt. Position offset from the head bone
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset_from_head_bone: Option<Vec<f64>>,

    /// Horizontal inward movement. The left eye moves right. The right eye moves left.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub range_map_horizontal_inner: Option<LookAtRangeMap>,

    /// Horizontal outward movement. The left eye moves left. The right eye moves right.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub range_map_horizontal_outer: Option<LookAtRangeMap>,

    /// Vertical downward movement. Both eyes move upwards
    #[serde(skip_serializing_if = "Option::is_none")]
    pub range_map_vertical_down: Option<LookAtRangeMap>,

    /// Vertical upward movement. Both eyes move downwards
    #[serde(skip_serializing_if = "Option::is_none")]
    pub range_map_vertical_up: Option<LookAtRangeMap>,

    #[serde(rename = "type")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub look_at_type: Option<LookAtType>,
}

/// LookAt range definition
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LookAtRangeMap {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    /// Yaw and pitch angles  ( degrees )  between the head bone forward vector and the eye gaze
    /// LookAt vector
    #[serde(skip_serializing_if = "Option::is_none")]
    pub input_max_value: Option<f64>,

    /// Degree for type.bone, Weight for type.expressions
    #[serde(skip_serializing_if = "Option::is_none")]
    pub output_scale: Option<f64>,
}

/// Meta information of the VRM model
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Meta {
    /// A flag that permits to use this model in contents contain anti-social activities or hate
    /// speeches
    #[serde(skip_serializing_if = "Option::is_none")]
    pub allow_antisocial_or_hate_usage: Option<bool>,

    /// A flag that permits to use this model in excessively sexual contents
    #[serde(skip_serializing_if = "Option::is_none")]
    pub allow_excessively_sexual_usage: Option<bool>,

    /// A flag that permits to use this model in excessively violent contents
    #[serde(skip_serializing_if = "Option::is_none")]
    pub allow_excessively_violent_usage: Option<bool>,

    /// A flag that permits to use this model in political or religious contents
    #[serde(skip_serializing_if = "Option::is_none")]
    pub allow_political_or_religious_usage: Option<bool>,

    /// A flag that permits to redistribute this model
    #[serde(skip_serializing_if = "Option::is_none")]
    pub allow_redistribution: Option<bool>,

    /// Authors of the model
    pub authors: Vec<String>,

    /// A person who can perform as an avatar with this model
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar_permission: Option<AvatarPermissionType>,

    /// An option that permits to use this model in commercial products
    #[serde(skip_serializing_if = "Option::is_none")]
    pub commercial_usage: Option<CommercialUsageType>,

    /// An information that describes the contact information of the author
    #[serde(skip_serializing_if = "Option::is_none")]
    pub contact_information: Option<String>,

    /// An information that describes the copyright of the model
    #[serde(skip_serializing_if = "Option::is_none")]
    pub copyright_information: Option<String>,

    /// An option that forces or abandons to display the credit of this model
    #[serde(skip_serializing_if = "Option::is_none")]
    pub credit_notation: Option<CreditNotationType>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extensions: Option<HashMap<String, HashMap<String, Option<serde_json::Value>>>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub extras: Option<serde_json::Value>,

    /// A URL towards the license document this model refers to
    pub license_url: String,

    /// An option that controls the condition to modify this model
    #[serde(skip_serializing_if = "Option::is_none")]
    pub modification: Option<ModificationType>,

    /// The name of the model
    pub name: String,

    /// Describe the URL links of other license
    #[serde(skip_serializing_if = "Option::is_none")]
    pub other_license_url: Option<String>,

    /// References / original works of the model
    #[serde(skip_serializing_if = "Option::is_none")]
    pub references: Option<Vec<String>>,

    /// Third party licenses of the model, if required. You can use line breaks
    #[serde(skip_serializing_if = "Option::is_none")]
    pub third_party_licenses: Option<String>,

    /// The index to the thumbnail image of the model in gltf.images
    #[cfg(feature = "gltf_index")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thumbnail_image: Option<gltf::json::Index<gltf::json::Image>>,
    #[cfg(not(feature = "gltf_index"))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thumbnail_image: Option<usize>,

    /// The version of the model
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<String>,
}

#[derive(Debug, Clone, Copy, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum MaterialColorType {
    Color,
    EmissionColor,
    MatcapColor,
    OutlineColor,
    RimColor,
    ShadeColor,
}

/// Expression override types
#[derive(Debug, Clone, Copy, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum ExpressionOverrideType {
    Blend,
    Block,
    None,
}

/// How the camera interprets the mesh.
#[derive(Debug, Clone, Copy, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum FirstPersonType {
    Auto,
    Both,
    FirstPersonOnly,
    ThirdPersonOnly,
}

#[derive(Debug, Clone, Copy, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum LookAtType {
    Bone,
    Expression,
}

/// A person who can perform as an avatar with this model
#[derive(Debug, Clone, Copy, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum AvatarPermissionType {
    Everyone,
    OnlyAuthor,
    OnlySeparatelyLicensedPerson,
}

/// An option that permits to use this model in commercial products
#[derive(Debug, Clone, Copy, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum CommercialUsageType {
    Corporation,
    PersonalNonProfit,
    PersonalProfit,
}

/// An option that forces or abandons to display the credit of this model
#[derive(Debug, Clone, Copy, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum CreditNotationType {
    Required,
    Unnecessary,
}

/// An option that controls the condition to modify this model
#[derive(Debug, Clone, Copy, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum ModificationType {
    AllowModification,
    AllowModificationRedistribution,
    Prohibited,
}