From e4a3720a37211a746a4f58ba25f2cf7870016f80 Mon Sep 17 00:00:00 2001 From: repsac Date: Sat, 1 Nov 2014 00:53:41 -0700 Subject: [PATCH] updated review.js to support cameras defined in a scene updated the bone mapping logic to instead record the maps locally within the parsing method and not store to the Geometry() instance included package modules missing from import cleanup of unused imports and variables --- .../blender/addons/io_three/constants.py | 1 - .../addons/io_three/exporter/api/camera.py | 3 +-- .../addons/io_three/exporter/api/light.py | 4 ++-- .../addons/io_three/exporter/api/mesh.py | 8 ++----- .../addons/io_three/exporter/api/object.py | 6 +---- .../addons/io_three/exporter/api/texture.py | 1 - .../addons/io_three/exporter/geometry.py | 21 ++++++++--------- .../blender/addons/io_three/exporter/io.py | 2 +- .../blender/addons/io_three/exporter/scene.py | 3 --- .../blender/tests/scripts/js/review.js | 23 +++++++++++++++---- 10 files changed, 35 insertions(+), 37 deletions(-) diff --git a/utils/exporters/blender/addons/io_three/constants.py b/utils/exporters/blender/addons/io_three/constants.py index 3ea152be0c..99c4db054d 100644 --- a/utils/exporters/blender/addons/io_three/constants.py +++ b/utils/exporters/blender/addons/io_three/constants.py @@ -43,7 +43,6 @@ VERTICES = 'vertices' FACES = 'faces' NORMALS = 'normals' BONES = 'bones' -BONE_MAP = 'boneMap' UVS = 'uvs' COLORS = 'colors' MIX_COLORS = 'mixColors' diff --git a/utils/exporters/blender/addons/io_three/exporter/api/camera.py b/utils/exporters/blender/addons/io_three/exporter/api/camera.py index ff7446d592..d34f001eb6 100644 --- a/utils/exporters/blender/addons/io_three/exporter/api/camera.py +++ b/utils/exporters/blender/addons/io_three/exporter/api/camera.py @@ -1,6 +1,5 @@ -import math from bpy import data, types, context -from .. import constants, logger +from .. import logger def _camera(func): diff --git a/utils/exporters/blender/addons/io_three/exporter/api/light.py b/utils/exporters/blender/addons/io_three/exporter/api/light.py index 802a75d204..1668a6aa64 100644 --- a/utils/exporters/blender/addons/io_three/exporter/api/light.py +++ b/utils/exporters/blender/addons/io_three/exporter/api/light.py @@ -1,5 +1,5 @@ -from bpy import data, types, context -from .. import constants, utilities, logger +from bpy import data, types +from .. import utilities, logger def _lamp(func): diff --git a/utils/exporters/blender/addons/io_three/exporter/api/mesh.py b/utils/exporters/blender/addons/io_three/exporter/api/mesh.py index 6015e6c54d..183b83a51a 100644 --- a/utils/exporters/blender/addons/io_three/exporter/api/mesh.py +++ b/utils/exporters/blender/addons/io_three/exporter/api/mesh.py @@ -3,7 +3,7 @@ import mathutils from bpy import data, types, context from . import material, texture from . import object as object_ -from .. import constants, utilities, logger +from .. import constants, utilities, logger, exceptions def _mesh(func): @@ -76,10 +76,7 @@ def bones(mesh): bone_count += 1 - return { - constants.BONES: bones, - constants.BONE_MAP: bone_map - } + return (bones, bone_map) @_mesh @@ -172,7 +169,6 @@ def faces(mesh, options): vertex_normals = _normals(mesh, options) if opt_normals else None vertex_colours = vertex_colors(mesh) if opt_colours else None - MASK = constants.MASK face_data = [] logger.info('Parsing %d faces', len(mesh.tessfaces)) diff --git a/utils/exporters/blender/addons/io_three/exporter/api/object.py b/utils/exporters/blender/addons/io_three/exporter/api/object.py index 47d4bb34dc..4c4716e580 100644 --- a/utils/exporters/blender/addons/io_three/exporter/api/object.py +++ b/utils/exporters/blender/addons/io_three/exporter/api/object.py @@ -2,7 +2,7 @@ import math import mathutils import bpy from bpy import data, context, types -from .. import constants, logger, utilities +from .. import constants, logger, utilities, exceptions from .constants import ( MESH, EMPTY, @@ -13,8 +13,6 @@ from .constants import ( POINT, HEMI, AREA, - PERSP, - ORTHO, CAMERA, PERSP, ORTHO, @@ -50,7 +48,6 @@ def _object(func): def assemblies(valid_types): logger.debug('object.assemblies(%s)', valid_types) - nodes = [] for obj in data.objects: if not obj.parent and obj.type in valid_types: yield obj.name @@ -390,7 +387,6 @@ def _matrix(obj): def _on_visible_layer(obj, visible_layers): - obj_layers = [] visible = True for index, layer in enumerate(obj.layers): if layer and index not in visible_layers: diff --git a/utils/exporters/blender/addons/io_three/exporter/api/texture.py b/utils/exporters/blender/addons/io_three/exporter/api/texture.py index 66cb39c617..4f719fe892 100644 --- a/utils/exporters/blender/addons/io_three/exporter/api/texture.py +++ b/utils/exporters/blender/addons/io_three/exporter/api/texture.py @@ -1,4 +1,3 @@ -import bpy from bpy import data, types from .. import constants, logger from .constants import IMAGE, MAG_FILTER, MIN_FILTER, MAPPING diff --git a/utils/exporters/blender/addons/io_three/exporter/geometry.py b/utils/exporters/blender/addons/io_three/exporter/geometry.py index 1c3ac4c943..77706685de 100644 --- a/utils/exporters/blender/addons/io_three/exporter/geometry.py +++ b/utils/exporters/blender/addons/io_three/exporter/geometry.py @@ -230,8 +230,8 @@ class Geometry(base_classes.BaseNode): def __geometry_metadata(self, metadata): skip = (constants.TYPE, constants.FACES, constants.UUID, constants.ANIMATION, constants.SKIN_INDICES, - constants.BONE_MAP, constants.SKIN_WEIGHTS, - constants.NAME, constants.INFLUENCES_PER_VERTEX) + constants.SKIN_WEIGHTS, constants.NAME, + constants.INFLUENCES_PER_VERTEX) vectors = (constants.VERTICES, constants.NORMALS) for key in self.keys(): @@ -332,28 +332,27 @@ class Geometry(base_classes.BaseNode): if self.options.get(constants.UVS): logger.info('Parsing %s', constants.UVS) - self[constants.UVS] = api.mesh.uvs(self.node, self.options) + self[constants.UVS] = api.mesh.uvs( + self.node, self.options) if self.options.get(constants.ANIMATION): logger.info('Parsing %s', constants.ANIMATION) self[constants.ANIMATION] = api.mesh.animation( self.node, self.options) - #@TODO: wondering if bone maps should be stored with - # the object itself or only handled via a local - # variable as it doesn't seem this data has - # other users outside of the immediate logic + #@TODO: considering making bones data implied when + # querying skinning data + + bone_map = {} if self.options.get(constants.BONES): logger.info('Parsing %s', constants.BONES) - bone_data = api.mesh.bones(self.node) - self[constants.BONES] = bone_data[constants.BONES] - self[constants.BONE_MAP] = bone_data[constants.BONE_MAP] + bones, bone_map = api.mesh.bones(self.node) + self[constants.BONES] = bones if self.options.get(constants.SKINNING): logger.info('Parsing %s', constants.SKINNING) influences = self.options.get( constants.INFLUENCES_PER_VERTEX, 2) - bone_map = self.get(constants.BONE_MAP) or {} self[constants.INFLUENCES_PER_VERTEX] = influences self[constants.SKIN_INDICES] = api.mesh.skin_indices( diff --git a/utils/exporters/blender/addons/io_three/exporter/io.py b/utils/exporters/blender/addons/io_three/exporter/io.py index 426b96174e..15065da026 100644 --- a/utils/exporters/blender/addons/io_three/exporter/io.py +++ b/utils/exporters/blender/addons/io_three/exporter/io.py @@ -1,6 +1,6 @@ import shutil from .. import constants -from . import _json, logger, exceptions +from . import _json, logger def copy_registered_textures(dest, registration): diff --git a/utils/exporters/blender/addons/io_three/exporter/scene.py b/utils/exporters/blender/addons/io_three/exporter/scene.py index 278e85ac31..aed5bd8f91 100644 --- a/utils/exporters/blender/addons/io_three/exporter/scene.py +++ b/utils/exporters/blender/addons/io_three/exporter/scene.py @@ -2,11 +2,9 @@ import os from .. import constants from . import ( base_classes, - image, texture, material, geometry, - exceptions, object, logger, io, @@ -83,7 +81,6 @@ class Scene(base_classes.BaseScene): extension = constants.EXTENSIONS.get(compression, constants.EXTENSIONS[constants.JSON]) - #@TODO: test this new logic export_dir = os.path.dirname(self.filepath) for key, value in self.items(): diff --git a/utils/exporters/blender/tests/scripts/js/review.js b/utils/exporters/blender/tests/scripts/js/review.js index bd51aefc88..f8d48b6e1b 100644 --- a/utils/exporters/blender/tests/scripts/js/review.js +++ b/utils/exporters/blender/tests/scripts/js/review.js @@ -75,20 +75,33 @@ function loadObject( data ) { var loader = new THREE.ObjectLoader(); scene = loader.parse( data ); - var hasLights = false; var lights = ['AmbientLight', 'DirectionalLight', 'AreaLight', 'PointLight', 'SpotLight', 'HemisphereLight'] - for ( i = 0; i < data.object.children.length; i ++ ) { + var cameras = ['OrthographicCamera', 'PerspectiveCamera']; + + for ( i = 0; i < scene.children.length; i ++ ) { - var index = lights.indexOf( data.object.children[ i ].type ); + var lightIndex = lights.indexOf( scene.children[ i ].type ); - if ( index > -1 ) { + if ( lightIndex > -1 ) { hasLights = true; - break; + continue; + + } + + var cameraIndex = cameras.indexOf( scene.children[ i ].type ); + + if ( cameraIndex > -1 ) { + + camera = scene.children[ i ]; + var container = document.getElementById( 'viewport' ); + var aspect = container.offsetWidth / container.offsetHeight; + camera.aspect = aspect; + camera.updateProjectionMatrix(); } -- GitLab