Source code for py3dtiles.tileset.root_property

from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Generic, TYPE_CHECKING, TypeVar

from py3dtiles.typing import ExtraDictType, RootPropertyDictType

if TYPE_CHECKING:
    from py3dtiles.tileset.extension import BaseExtension
    from typing_extensions import Self

_JsonDictT = TypeVar("_JsonDictT", bound=RootPropertyDictType)


[docs] class RootProperty(ABC, Generic[_JsonDictT]): """ One the 3DTiles notions defined as an abstract data model through a schema of the 3DTiles specifications (either core of extensions). """ def __init__(self) -> None: self.extensions: dict[str, BaseExtension] = {} self.extras: ExtraDictType = {}
[docs] @classmethod @abstractmethod def from_dict(cls, data_dict: _JsonDictT) -> Self: ...
[docs] @abstractmethod def to_dict(self) -> _JsonDictT: ...
[docs] def add_root_properties_to_dict(self, dict_data: _JsonDictT) -> _JsonDictT: # we cannot merge root_property_data without mypy issues if self.extensions: dict_data["extensions"] = { name: extension.to_dict() for name, extension in self.extensions.items() } if self.extras: dict_data["extras"] = self.extras return dict_data
[docs] def set_properties_from_dict( self, dict_data: _JsonDictT, ) -> None: self.extensions = {} # TODO not yet implemented if "extras" in dict_data: self.extras = dict_data["extras"]