Skip to content

Commit

Permalink
Blender Exporter: Refactored geometry.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Dec 8, 2016
1 parent a8cc2a2 commit 767e68b
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions utils/exporters/blender/addons/io_three/exporter/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def register_textures(self):

def write(self, filepath=None):
"""Write the geometry definitions to disk. Uses the
desitnation path of the scene.
destination path of the scene.
:param filepath: optional output file path
(Default value = None)
Expand Down Expand Up @@ -234,13 +234,18 @@ def _component_data(self):
logger.debug("Geometry()._component_data()")

if self[constants.TYPE] != constants.GEOMETRY.title():
return self[constants.ATTRIBUTES]
data = {}
index = self.get(constants.INDEX)
if index is not None:
data[constants.INDEX] = index
data[constants.ATTRIBUTES] = self.get(constants.ATTRIBUTES)
return {constants.DATA: data}

components = [constants.VERTICES, constants.FACES,
constants.UVS, constants.COLORS,
constants.NORMALS, constants.BONES,
constants.SKIN_WEIGHTS,
constants.SKIN_INDICES, constants.NAME,
constants.SKIN_INDICES,
constants.INFLUENCES_PER_VERTEX,
constants.INDEX]

Expand Down Expand Up @@ -281,21 +286,13 @@ def _geometry_format(self):
:rtype: dict
"""
data = self._component_data()

if self[constants.TYPE] != constants.GEOMETRY.title():
data = {
constants.DATA: {constants.ATTRIBUTES: data}
data = {
constants.METADATA: {
constants.TYPE: self[constants.TYPE]
}
index = self.get(constants.INDEX)
if index is not None:
data[constants.DATA][constants.INDEX] = index

data[constants.METADATA] = {
constants.TYPE: self[constants.TYPE]
}

data[constants.METADATA].update(self.metadata)
data.update(self._component_data())

draw_calls = self.get(constants.DRAW_CALLS)
if draw_calls is not None:
Expand Down Expand Up @@ -350,32 +347,19 @@ def _scene_format(self):
"""
data = {
constants.NAME: self[constants.NAME],
constants.UUID: self[constants.UUID],
constants.TYPE: self[constants.TYPE]
}

component_data = self._component_data()
if self[constants.TYPE] == constants.GEOMETRY.title():
data[constants.DATA] = component_data
data[constants.DATA].update({
constants.METADATA: self.metadata
})
data[constants.DATA] = self._component_data()
else:
geometry_data = data
if self.options.get(constants.EMBED_GEOMETRY, True):
data[constants.DATA] = geometry_data = {}

geometry_data[constants.ATTRIBUTES] = component_data
index = self.get(constants.INDEX)
if index is not None:
geometry_data[constants.INDEX] = index
data.update(self._component_data())
draw_calls = self.get(constants.DRAW_CALLS)
if draw_calls is not None:
geometry_data[constants.DRAW_CALLS] = draw_calls

data[constants.METADATA] = self.metadata
data[constants.NAME] = self[constants.NAME]

return data

def _parse_buffer_geometry(self):
Expand Down

0 comments on commit 767e68b

Please sign in to comment.