Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2023-11-29 00:39:14 -08:00
parent bc3d698539
commit faaeb3a472
74 changed files with 496 additions and 1985 deletions

View File

@ -1,8 +1,6 @@
from typing import Any, Dict, Type, TypeVar, Union
from typing import Union
import attr
from pydantic import BaseModel, GetCoreSchemaHandler
from pydantic_core import CoreSchema, core_schema
from pydantic import BaseModel, RootModel
from ..models.fbx_storage import FbxStorage
from ..models.gltf_presentation import GltfPresentation
@ -78,15 +76,8 @@ class stl(BaseModel):
units: UnitLength
GY = TypeVar("GY", bound="OutputFormat")
@attr.s(auto_attribs=True)
class OutputFormat:
"""Output format specifier."""
type: Union[
OutputFormat = RootModel[
Union[
fbx,
gltf,
obj,
@ -94,79 +85,4 @@ class OutputFormat:
step,
stl,
]
def __init__(
self,
type: Union[
fbx,
gltf,
obj,
ply,
step,
stl,
],
):
self.type = type
def model_dump(self) -> Dict[str, Any]:
if isinstance(self.type, fbx):
FC: fbx = self.type
return FC.model_dump()
elif isinstance(self.type, gltf):
EI: gltf = self.type
return EI.model_dump()
elif isinstance(self.type, obj):
JE: obj = self.type
return JE.model_dump()
elif isinstance(self.type, ply):
JW: ply = self.type
return JW.model_dump()
elif isinstance(self.type, step):
AS: step = self.type
return AS.model_dump()
elif isinstance(self.type, stl):
YQ: stl = self.type
return YQ.model_dump()
raise Exception("Unknown type")
@classmethod
def from_dict(cls: Type[GY], d: Dict[str, Any]) -> GY:
if d.get("type") == "fbx":
OA: fbx = fbx(**d)
return cls(type=OA)
elif d.get("type") == "gltf":
CQ: gltf = gltf(**d)
return cls(type=CQ)
elif d.get("type") == "obj":
RD: obj = obj(**d)
return cls(type=RD)
elif d.get("type") == "ply":
KZ: ply = ply(**d)
return cls(type=KZ)
elif d.get("type") == "step":
IU: step = step(**d)
return cls(type=IU)
elif d.get("type") == "stl":
NQ: stl = stl(**d)
return cls(type=NQ)
raise Exception("Unknown type")
@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,
]
),
)
]