2023-11-28 23:50:50 -08:00
from typing import Any , Dict , Type , TypeVar , Union
2023-07-07 19:22:51 -07:00
import attr
2023-11-28 23:50:50 -08:00
from pydantic import BaseModel , GetCoreSchemaHandler
from pydantic_core import CoreSchema , core_schema
2023-07-07 19:22:51 -07:00
2023-08-30 15:59:51 -07:00
from . . models . fbx_storage import FbxStorage
from . . models . gltf_presentation import GltfPresentation
from . . models . gltf_storage import GltfStorage
from . . models . ply_storage import PlyStorage
2023-11-27 16:01:20 -08:00
from . . models . selection import Selection
2023-08-30 15:59:51 -07:00
from . . models . stl_storage import StlStorage
2023-07-07 19:22:51 -07:00
from . . models . system import System
2023-09-29 15:51:03 -07:00
from . . models . unit_length import UnitLength
2023-07-07 19:22:51 -07:00
2023-11-27 16:01:20 -08:00
2023-11-28 23:50:50 -08:00
class fbx ( BaseModel ) :
""" Autodesk Filmbox (FBX) format. """
2023-08-30 15:59:51 -07:00
2023-11-28 23:50:50 -08:00
storage : FbxStorage
2023-08-30 15:59:51 -07:00
2023-11-27 16:01:20 -08:00
type : str = " fbx "
2023-08-30 15:59:51 -07:00
2023-11-28 23:50:50 -08:00
class gltf ( BaseModel ) :
""" glTF 2.0. We refer to this as glTF since that is how our customers refer to it, although by default it will be in binary format and thus technically (glb). If you prefer ascii output, you can set that option for the export. """
2023-08-30 15:59:51 -07:00
2023-11-28 23:50:50 -08:00
presentation : GltfPresentation
2023-08-30 15:59:51 -07:00
2023-11-28 23:50:50 -08:00
storage : GltfStorage
2023-08-30 15:59:51 -07:00
2023-11-27 16:01:20 -08:00
type : str = " gltf "
2023-07-07 19:22:51 -07:00
2023-11-28 23:50:50 -08:00
class obj ( BaseModel ) :
""" Wavefront OBJ format. """
2023-07-07 19:22:51 -07:00
2023-11-28 23:50:50 -08:00
coords : System
2023-07-07 19:22:51 -07:00
2023-11-27 16:01:20 -08:00
type : str = " obj "
2023-07-07 19:22:51 -07:00
2023-11-28 23:50:50 -08:00
units : UnitLength
2023-07-07 19:22:51 -07:00
2023-11-28 23:50:50 -08:00
class ply ( BaseModel ) :
""" The PLY Polygon File Format. """
2023-07-07 19:22:51 -07:00
2023-11-28 23:50:50 -08:00
coords : System
2023-07-07 19:22:51 -07:00
2023-11-28 23:50:50 -08:00
selection : Selection
2023-07-31 12:50:30 -07:00
2023-11-28 23:50:50 -08:00
storage : PlyStorage
2023-07-31 12:50:30 -07:00
2023-11-27 16:01:20 -08:00
type : str = " ply "
2023-11-28 23:50:50 -08:00
units : UnitLength
2023-11-27 16:01:20 -08:00
2023-11-28 23:50:50 -08:00
class step ( BaseModel ) :
""" ISO 10303-21 (STEP) format. """
2023-11-27 16:01:20 -08:00
2023-11-28 23:50:50 -08:00
coords : System
2023-07-31 12:50:30 -07:00
2023-11-27 16:01:20 -08:00
type : str = " step "
2023-07-07 19:22:51 -07:00
2023-11-28 23:50:50 -08:00
class stl ( BaseModel ) :
""" *ST**ereo**L**ithography format. """
2023-07-07 19:22:51 -07:00
2023-11-28 23:50:50 -08:00
coords : System
2023-07-07 19:22:51 -07:00
2023-11-28 23:50:50 -08:00
selection : Selection
2023-07-07 19:22:51 -07:00
2023-11-28 23:50:50 -08:00
storage : StlStorage
2023-07-07 19:22:51 -07:00
2023-11-27 16:01:20 -08:00
type : str = " stl "
2023-11-28 23:50:50 -08:00
units : UnitLength
2023-11-27 16:01:20 -08:00
2023-07-07 19:22:51 -07:00
2023-11-28 14:29:16 -08:00
GY = TypeVar ( " GY " , bound = " OutputFormat " )
@attr.s ( auto_attribs = True )
2023-11-28 14:16:05 -08:00
class OutputFormat :
""" Output format specifier. """
type : Union [
fbx ,
gltf ,
obj ,
ply ,
step ,
stl ,
2023-11-28 14:29:16 -08:00
]
2023-11-28 14:16:05 -08:00
def __init__ (
self ,
type : Union [
2023-11-28 14:29:16 -08:00
fbx ,
gltf ,
obj ,
ply ,
step ,
stl ,
2023-11-28 14:16:05 -08:00
] ,
) :
self . type = type
2023-11-28 23:50:50 -08:00
def model_dump ( self ) - > Dict [ str , Any ] :
2023-11-28 14:16:05 -08:00
if isinstance ( self . type , fbx ) :
2023-11-28 23:50:50 -08:00
FC : fbx = self . type
return FC . model_dump ( )
2023-11-28 14:16:05 -08:00
elif isinstance ( self . type , gltf ) :
2023-11-28 23:50:50 -08:00
EI : gltf = self . type
return EI . model_dump ( )
2023-11-28 14:16:05 -08:00
elif isinstance ( self . type , obj ) :
2023-11-28 23:50:50 -08:00
JE : obj = self . type
return JE . model_dump ( )
2023-11-28 14:16:05 -08:00
elif isinstance ( self . type , ply ) :
2023-11-28 23:50:50 -08:00
JW : ply = self . type
return JW . model_dump ( )
2023-11-28 14:16:05 -08:00
elif isinstance ( self . type , step ) :
2023-11-28 23:50:50 -08:00
AS : step = self . type
return AS . model_dump ( )
2023-11-28 14:16:05 -08:00
elif isinstance ( self . type , stl ) :
2023-11-28 23:50:50 -08:00
YQ : stl = self . type
return YQ . model_dump ( )
2023-11-28 14:16:05 -08:00
raise Exception ( " Unknown type " )
2023-11-28 14:29:16 -08:00
@classmethod
def from_dict ( cls : Type [ GY ] , d : Dict [ str , Any ] ) - > GY :
2023-11-28 14:16:05 -08:00
if d . get ( " type " ) == " fbx " :
2023-11-28 23:50:50 -08:00
OA : fbx = fbx ( * * d )
return cls ( type = OA )
2023-11-28 14:16:05 -08:00
elif d . get ( " type " ) == " gltf " :
2023-11-28 23:50:50 -08:00
CQ : gltf = gltf ( * * d )
return cls ( type = CQ )
2023-11-28 14:16:05 -08:00
elif d . get ( " type " ) == " obj " :
2023-11-28 23:50:50 -08:00
RD : obj = obj ( * * d )
return cls ( type = RD )
2023-11-28 14:16:05 -08:00
elif d . get ( " type " ) == " ply " :
2023-11-28 23:50:50 -08:00
KZ : ply = ply ( * * d )
return cls ( type = KZ )
2023-11-28 14:16:05 -08:00
elif d . get ( " type " ) == " step " :
2023-11-28 23:50:50 -08:00
IU : step = step ( * * d )
return cls ( type = IU )
2023-11-28 14:16:05 -08:00
elif d . get ( " type " ) == " stl " :
2023-11-28 23:50:50 -08:00
NQ : stl = stl ( * * d )
return cls ( type = NQ )
2023-11-28 14:16:05 -08:00
raise Exception ( " Unknown type " )
2023-11-28 23:50:50 -08:00
@classmethod
def __get_pydantic_core_schema__ (
cls , source_type : Any , handler : GetCoreSchemaHandler
) - > CoreSchema :
return core_schema . no_info_after_validator_function (
cls ,
handler (
Union [
fbx ,
gltf ,
obj ,
ply ,
step ,
stl ,
]
) ,
)