OSDN Git Service

three.jsをThirdPartyに追加
[webglgame/webgl_framework.git] / webglFramework / Thirdparty / three.js-master / utils / exporters / blender / addons / io_three / exporter / base_classes.py
1 from . import utilities
2 from .. import constants, exceptions
3
4
5 class BaseClass(constants.BASE_DICT):
6     """Base class which inherits from a base dictionary object."""
7     _defaults = {}
8
9     def __init__(self, parent=None, type=None):
10         constants.BASE_DICT.__init__(self)
11
12         self._type = type
13
14         self._parent = parent
15
16         constants.BASE_DICT.update(self, self._defaults.copy())
17         BaseClass._defaults = {}
18
19     def __setitem__(self, key, value):
20         if not isinstance(value, constants.VALID_DATA_TYPES):
21             msg = "Value is an invalid data type: %s" % type(value)
22             raise exceptions.ThreeValueError(msg)
23         constants.BASE_DICT.__setitem__(self, key, value)
24
25     @property
26     def count(self):
27         """
28
29         :return: number of keys
30         :rtype: int
31
32         """
33         return len(self.keys())
34
35     @property
36     def parent(self):
37         """
38
39         :return: parent object
40
41         """
42         return self._parent
43
44     @property
45     def type(self):
46         """
47
48         :return: the type (if applicable)
49
50         """
51         return self._type
52
53     def copy(self):
54         """Copies the items to a standard dictionary object.
55
56         :rtype: dict
57
58         """
59         data = {}
60
61         def _dict_copy(old, new):
62             """Recursive function for processing all values
63
64             :param old:
65             :param new:
66
67             """
68             for key, value in old.items():
69                 if isinstance(value, (str, list)):
70                     new[key] = value[:]
71                 elif isinstance(value, tuple):
72                     new[key] = value+tuple()
73                 elif isinstance(value, dict):
74                     new[key] = {}
75                     _dict_copy(value, new[key])
76                 else:
77                     new[key] = value
78
79         _dict_copy(self, data)
80
81         return data
82
83
84 class BaseNode(BaseClass):
85     """Base class for all nodes for the current platform."""
86     def __init__(self, node, parent, type):
87         BaseClass.__init__(self, parent=parent, type=type)
88         self._node = node
89         if node is None:
90             self[constants.UUID] = utilities.id()
91         else:
92             self[constants.NAME] = node
93             self[constants.UUID] = utilities.id()
94
95         if isinstance(parent, BaseScene):
96             scene = parent
97         elif parent is not None:
98             scene = parent.scene
99         else:
100             scene = None
101
102         self._scene = scene
103
104     @property
105     def node(self):
106         """
107
108         :return: name of the node
109
110         """
111         return self._node
112
113     @property
114     def scene(self):
115         """
116
117         :return: returns the scene point
118
119         """
120
121         return self._scene
122
123     @property
124     def options(self):
125         """
126
127         :return: export options
128         :retype: dict
129
130         """
131         return self.scene.options
132
133
134 class BaseScene(BaseClass):
135     """Base class that scenes inherit from."""
136     def __init__(self, filepath, options):
137         BaseClass.__init__(self, type=constants.SCENE)
138
139         self._filepath = filepath
140
141         self._options = options.copy()
142
143     @property
144     def filepath(self):
145         return self._filepath
146
147     @property
148     def options(self):
149         return self._options