Skip to content

Commit

Permalink
glTF: 3D Tiles 系 EXT_* の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscorn committed Dec 19, 2023
1 parent 2b1ad91 commit 5fd970b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 14 deletions.
48 changes: 44 additions & 4 deletions nusamai-gltf/src/models/extensions/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,28 @@ pub struct Gltf {
}

#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct ExtStructuralMetadata {
/// A dictionary object, where each key is the ID of the schema and each value is an object defining the schema.
pub schemas: Schema,
pub property_tables: Vec<PropertyTable>,
/// An object defining classes and enums.
#[serde(skip_serializing_if = "Option::is_none")]
pub schema: Option<Schema>,

/// The URI (or IRI) of the external schema file.
#[serde(skip_serializing_if = "Option::is_none")]
pub schema_uri: Option<String>,

/// An array of property table definitions, which may be referenced by index.
#[serde(skip_serializing_if = "Option::is_none")]
pub property_tables: Option<Vec<PropertyTable>>,

/// An array of indexes of property textures in the root `EXT_structural_metadata` object.
#[serde(skip_serializing_if = "Option::is_none")]
pub property_textures: Option<Vec<PropertyTexture>>,

/// An array of indexes of property attributes in the root `EXT_structural_metadata` object.
#[serde(skip_serializing_if = "Option::is_none")]
pub property_attributes: Option<Vec<PropertyAttribute>>,
}

/// Schema in EXT_structural_metadata
Expand All @@ -38,10 +55,12 @@ pub struct Schema {

/// A dictionary, where each key is a class ID and each value is an object defining the class.
#[serde(skip_serializing_if = "HashMap::is_empty")]
#[serde(default)]
pub classes: HashMap<String, Class>,

/// A dictionary, where each key is an enum ID and each value is an object defining the values for the enum.
#[serde(skip_serializing_if = "HashMap::is_empty")]
#[serde(default)]
pub enums: HashMap<String, EnumMetadata>,

/// JSON object with extension-specific objects.
Expand Down Expand Up @@ -116,6 +135,7 @@ pub enum ComponentType {
/// Class Property in EXT_structural_metadata
#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct ClassProperty {
/// The name of the property, e.g. for display purposes.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -126,7 +146,8 @@ pub struct ClassProperty {
pub description: Option<String>,

/// The element type.
pub element_type: ElementType,
#[serde(rename = "type")]
pub type_: ElementType,

/// The datatype of the element's components.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -207,6 +228,7 @@ pub enum ValueType {

/// Enum in EXT_structural_metadata
#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct EnumMetadata {
/// The name of the enum, e.g. for display purposes.
Expand Down Expand Up @@ -239,6 +261,7 @@ fn default_value_type() -> ValueType {

/// Enum Value in EXT_structural_metadata
#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct EnumValue {
/// The name of the enum value.
Expand All @@ -262,6 +285,7 @@ pub struct EnumValue {

/// Property Table in EXT_structural_metadata
#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct PropertyTable {
/// The name of the property table, e.g. for display purposes.
Expand All @@ -286,6 +310,21 @@ pub struct PropertyTable {
pub extras: Option<Value>,
}

// TODO: Implement KHR_materials_variants
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct PropertyTexture {
// FIXME: Not implemented yet.
#[serde(flatten)]
pub others: HashMap<String, Value>,
}

#[derive(Serialize, Deserialize, Debug, Default)]
pub struct PropertyAttribute {
// FIXME: Not implemented yet.
#[serde(flatten)]
pub others: HashMap<String, Value>,
}

/// OffsetType enumeration
#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "UPPERCASE")]
Expand All @@ -300,6 +339,7 @@ pub enum OffsetType {

/// Property Table Property in EXT_structural_metadata
#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct PropertyTableProperty {
/// The index of the buffer view containing property values.
Expand Down
10 changes: 6 additions & 4 deletions nusamai-gltf/src/models/extensions/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ fn default_channels() -> Vec<u32> {
#[serde(deny_unknown_fields)]
pub struct Primitive {
#[serde(skip_serializing_if = "Option::is_none", rename = "EXT_mesh_features")]
pub ext_mesh_features: Option<MeshPrimitiveExtMeshFeatures>,
pub ext_mesh_features: Option<ExtMeshFeatures>,

#[serde(
skip_serializing_if = "Option::is_none",
rename = "EXT_structural_metadata"
)]
pub ext_structural_metadata: Option<MeshPrimitiveExtStructuralMetadata>,
pub ext_structural_metadata: Option<ExtStructuralMetadata>,

#[serde(
skip_serializing_if = "Option::is_none",
rename = "KHR_materials_variants"
Expand All @@ -96,7 +98,7 @@ pub struct KhrMaterialsVariants {
#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct MeshPrimitiveExtMeshFeatures {
pub struct ExtMeshFeatures {
/// An array of feature ID sets.
pub feature_ids: Vec<FeatureId>,

Expand All @@ -109,7 +111,7 @@ pub struct MeshPrimitiveExtMeshFeatures {

/// EXT_structural_metadata glTF Mesh Primitive extension
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct MeshPrimitiveExtStructuralMetadata {
pub struct ExtStructuralMetadata {
/// An array of indexes of property textures in the root `EXT_structural_metadata` object.
#[serde(skip_serializing_if = "Option::is_none")]
pub property_textures: Option<Vec<u32>>,
Expand Down
7 changes: 2 additions & 5 deletions nusamai-gltf/src/models/extensions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
mod gltf;
mod mesh;

pub use gltf::*;
pub use mesh::*;
pub mod gltf;
pub mod mesh;
8 changes: 8 additions & 0 deletions nusamai-gltf/src/models/gltf.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::extensions;

use super::{
Accessor, Animation, Asset, Buffer, BufferView, Camera, Image, Material, Mesh, Node, Sampler,
Scene, Skin, Texture,
Expand Down Expand Up @@ -91,6 +93,12 @@ pub struct Gltf {
#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct GLTFExtensions {
#[serde(
skip_serializing_if = "Option::is_none",
rename = "EXT_structural_metadata"
)]
pub ext_structural_metadata: Option<extensions::gltf::ExtStructuralMetadata>,

#[serde(flatten)]
others: HashMap<String, Value>,
}
Expand Down
2 changes: 1 addition & 1 deletion nusamai-gltf/src/models/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct MeshPrimitive {

/// JSON object with extension-specific objects.
#[serde(skip_serializing_if = "Option::is_none")]
pub extensions: Option<extensions::Primitive>,
pub extensions: Option<extensions::mesh::Primitive>,

/// Application-specific data.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extensions" : {
"EXT_structural_metadata" : {
"schema" : {
"id": "ComplexTypesSchema",
"classes" : {
"exampleMetadataClass" : {
"name" : "Example metadata class",
Expand Down

0 comments on commit 5fd970b

Please sign in to comment.