Browse Source

added copyright
renamed custom Blender properties to THREE_ prefix
renamed the "round" attributes to "precision"
fixed a bug in review where it was trying load morph targets when there wasn't any

repsac 10 years ago
parent
commit
1c3025de9e

+ 49 - 28
utils/exporters/blender/addons/io_three/__init__.py

@@ -1,3 +1,21 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
 import os
 import json
 
@@ -16,14 +34,15 @@ SETTINGS_FILE_EXPORT = 'three_settings_export.js'
 
 
 bl_info = {
-    'name': 'io_three',
+    'name': 'Three.js Format',
     'author': 'Ed Caspersen (repsac)',
     'version': (1, 0, 0),
     'blender': (2, 7, 2),
     'location': 'File > Import-Export',
-    'description': 'Export ThreeJs scenes',
-    'warning': 'Importer not implemented',
-    'wiki_url': 'https://github.com/mrdoob/three.js/wiki',
+    'description': 'Export Three.js formatted JSON files.',
+    'warning': '',
+    'wiki_url': 'https://github.com/mrdoob/three.js/tree/'\
+        'master/utils/exporters/blender',
     'tracker_url':  'https://github.com/mrdoob/three.js/issues',
     'category': 'Import-Export'
 }
@@ -40,7 +59,7 @@ def _geometry_types():
 
     return types
 
-bpy.types.Mesh.three_geometry_type = EnumProperty(
+bpy.types.Mesh.THREE_geometry_type = EnumProperty(
     name='Geometry type',
     description='Geometry type',
     items=_geometry_types(),
@@ -56,7 +75,7 @@ class MESH_PT_hello(bpy.types.Panel):
     def draw(self, context):
         row = self.layout.row()
         if context.mesh:
-            row.prop(context.mesh, 'three_geometry_type', text='Type')
+            row.prop(context.mesh, 'THREE_geometry_type', text='Type')
 
 def _blending_types(index):
     types = (
@@ -68,14 +87,14 @@ def _blending_types(index):
         constants.BLENDING_TYPES.CUSTOM)
     return (types[index], types[index], types[index])
 
-bpy.types.Material.three_blending_type = EnumProperty(
+bpy.types.Material.THREE_blending_type = EnumProperty(
     name='Blending type', 
     description='Blending type', 
     items=[_blending_types(x) for x in range(5)], 
     default=constants.BLENDING_TYPES.NORMAL)
 
-bpy.types.Material.three_depth_write = BoolProperty(default=True)
-bpy.types.Material.three_depth_test = BoolProperty(default=True)
+bpy.types.Material.THREE_depth_write = BoolProperty(default=True)
+bpy.types.Material.THREE_depth_test = BoolProperty(default=True)
 
 class MATERIAL_PT_hello(bpy.types.Panel):
 
@@ -93,15 +112,15 @@ class MATERIAL_PT_hello(bpy.types.Panel):
             row.label(text='Selected material: %s' % mat.name )
 
             row = layout.row()
-            row.prop(mat, 'three_blending_type', 
+            row.prop(mat, 'THREE_blending_type', 
                 text='Blending type' )
 
             row = layout.row()
-            row.prop(mat, 'three_depth_write', 
+            row.prop(mat, 'THREE_depth_write', 
                 text='Enable depth writing' )
 
             row = layout.row()
-            row.prop(mat, 'three_depth_test', 
+            row.prop(mat, 'THREE_depth_test', 
                 text='Enable depth testing' )
 
 def _mag_filters(index):
@@ -109,7 +128,7 @@ def _mag_filters(index):
         constants.NEAREST_FILTERS.NEAREST)
     return (types[index], types[index], types[index])
 
-bpy.types.Texture.three_mag_filter = EnumProperty(
+bpy.types.Texture.THREE_mag_filter = EnumProperty(
     name='Mag Filter',
     items = [_mag_filters(x) for x in range(2)],
     default=constants.LINEAR_FILTERS.LINEAR)
@@ -123,7 +142,7 @@ def _min_filters(index):
         constants.NEAREST_FILTERS.MIP_MAP_LINEAR)
     return (types[index], types[index], types[index])
 
-bpy.types.Texture.three_min_filter = EnumProperty(
+bpy.types.Texture.THREE_min_filter = EnumProperty(
     name='Min Filter',
     items = [_min_filters(x) for x in range(6)],
     default=constants.LINEAR_FILTERS.MIP_MAP_LINEAR)
@@ -136,7 +155,7 @@ def _mapping(index):
         constants.MAPPING_TYPES.SPHERICAL_REFRACTION)
     return (types[index], types[index], types[index])
 
-bpy.types.Texture.three_mapping = EnumProperty(
+bpy.types.Texture.THREE_mapping = EnumProperty(
     name='Mapping',
     items = [_mapping(x) for x in range(5)],
     default=constants.MAPPING_TYPES.UV)
@@ -154,15 +173,15 @@ class TEXTURE_PT_hello(bpy.types.Panel):
 
         if tex is not None:
             row = layout.row()
-            row.prop(tex, 'three_mapping', text='Mapping')
+            row.prop(tex, 'THREE_mapping', text='Mapping')
 
             row = layout.row()
-            row.prop(tex, 'three_mag_filter', text='Mag Filter')
+            row.prop(tex, 'THREE_mag_filter', text='Mag Filter')
 
             row = layout.row()
-            row.prop(tex, 'three_min_filter', text='Min Filter')
+            row.prop(tex, 'THREE_min_filter', text='Min Filter')
 
-bpy.types.Object.three_export = bpy.props.BoolProperty(default=True)
+bpy.types.Object.THREE_export = bpy.props.BoolProperty(default=True)
 
 class OBJECT_PT_hello(bpy.types.Panel):
     bl_label = 'THREE'
@@ -175,7 +194,7 @@ class OBJECT_PT_hello(bpy.types.Panel):
         obj = context.object
 
         row = layout.row()
-        row.prop(obj, 'three_export', text='Export')
+        row.prop(obj, 'THREE_export', text='Export')
 
 def get_settings_fullpath():
     return os.path.join(bpy.app.tempdir, SETTINGS_FILE_EXPORT)
@@ -199,8 +218,8 @@ def save_settings_export(properties):
         constants.MIX_COLORS: properties.option_mix_colors,
 
         constants.SCALE: properties.option_scale,
-        constants.ROUND_OFF: properties.option_round_off,
-        constants.ROUND_VALUE: properties.option_round_value,
+        constants.ENABLE_PRECISION: properties.option_round_off,
+        constants.PRECISION: properties.option_round_value,
         constants.LOGGING: properties.option_logging,
         constants.COMPRESSION: properties.option_compression,
         constants.COPY_TEXTURES: properties.option_copy_textures,
@@ -269,9 +288,11 @@ def restore_settings_export(properties):
     properties.option_scale = settings.get(
         constants.SCALE, constants.EXPORT_OPTIONS[constants.SCALE])
     properties.option_round_off = settings.get(
-        constants.ROUND_OFF, constants.EXPORT_OPTIONS[constants.ROUND_OFF])
+        constants.ENABLE_PRECISION, 
+        constants.EXPORT_OPTIONS[constants.ENABLE_PRECISION])
     properties.option_round_value = settings.get(
-        constants.ROUND_VALUE, constants.EXPORT_OPTIONS[constants.ROUND_VALUE])
+        constants.PRECISION, 
+        constants.EXPORT_OPTIONS[constants.PRECISION])
     properties.option_logging = settings.get(
         constants.LOGGING, constants.EXPORT_OPTIONS[constants.LOGGING])
     properties.option_compression = settings.get(
@@ -392,16 +413,16 @@ class ExportThree(bpy.types.Operator, ExportHelper):
         default=constants.EXPORT_OPTIONS[constants.SCALE])
 
     option_round_off = BoolProperty(
-        name='Round Off',
-        description='Round of floating point values',
-        default=constants.EXPORT_OPTIONS[constants.ROUND_OFF])
+        name='Enable Precision',
+        description='Round off floating point values',
+        default=constants.EXPORT_OPTIONS[constants.ENABLE_PRECISION])
 
     option_round_value = IntProperty(
         name='Precision',
         min=0,
         max=16,
         description='Floating point precision',
-        default=constants.EXPORT_OPTIONS[constants.ROUND_VALUE])
+        default=constants.EXPORT_OPTIONS[constants.PRECISION])
 
     logging_types = [
         (constants.DEBUG, constants.DEBUG, constants.DEBUG),

+ 5 - 9
utils/exporters/blender/addons/io_three/constants.py

@@ -60,9 +60,9 @@ LIGHTS = 'lights'
 FACE_MATERIALS = 'faceMaterials'
 SKINNING = 'skinning'
 COPY_TEXTURES = 'copyTextures'
-ROUND_OFF = 'roundOff'
-ROUND_VALUE = 'roundValue'
-ROUND = 6
+ENABLE_PRECISION = 'enablePrecision'
+PRECISION = 'precision'
+DEFAULT_PRECISION = 6
 EMBED_GEOMETRY = 'embedGeometry'
 EMBED_ANIMATION = 'embedAnimation'
 
@@ -104,8 +104,8 @@ EXPORT_OPTIONS = {
     LIGHTS: False,
     COPY_TEXTURES: True,
     LOGGING: DEBUG,
-    ROUND_OFF: False,
-    ROUND_VALUE: ROUND,
+    ENABLE_PRECISION: False,
+    PRECISION: DEFAULT_PRECISION,
     EMBED_GEOMETRY: True,
     EMBED_ANIMATION: True,
     GEOMETRY_TYPE: GEOMETRY
@@ -119,10 +119,6 @@ GENERATOR = 'generator'
 SOURCE_FILE = 'sourceFile'
 VALID_DATA_TYPES = (str, int, float, bool, list, tuple, dict)
 
-ROUND = 6
-ROUND_VALUE = 'roundValue'
-ROUND_OFF = 'roundOff'
-
 JSON = 'json'
 GZIP = 'gzip'
 

+ 1 - 1
utils/exporters/blender/addons/io_three/exporter/_json.py

@@ -1,7 +1,7 @@
 import json
 from .. import constants
 
-ROUND = constants.ROUND
+ROUND = constants.DEFAULT_PRECISION
 
 ## THREE override function
 def _json_floatstr(o):

+ 8 - 8
utils/exporters/blender/addons/io_three/exporter/api/material.py

@@ -30,9 +30,9 @@ def ambient_color(material):
 def blending(material):
     logger.debug('material.blending(%s)', material)
     try:
-        blend = material.three_blending_type
+        blend = material.THREE_blending_type
     except AttributeError:
-        logger.debug('No three_blending_type attribute found')
+        logger.debug('No THREE_blending_type attribute found')
         blend = constants.NORMAL_BLENDING 
     return blend
 
@@ -55,9 +55,9 @@ def bump_scale(material):
 def depth_test(material):
     logger.debug('material.depth_test(%s)', material)
     try:
-        test = material.three_depth_test
+        test = material.THREE_depth_test
     except AttributeError:
-        logger.debug('No three_depth_test attribute found')
+        logger.debug('No THREE_depth_test attribute found')
         test = True
     return test
 
@@ -66,9 +66,9 @@ def depth_test(material):
 def depth_write(material):
     logger.debug('material.depth_write(%s)', material)
     try:
-        write = material.three_depth_write
+        write = material.THREE_depth_write
     except AttributeError:
-        logger.debug('No three_depth_write attribute found')
+        logger.debug('No THREE_depth_write attribute found')
         write = True
     return write
 
@@ -199,9 +199,9 @@ def used_materials():
 def visible(material):
     logger.debug('material.visible(%s)', material)
     try:
-        vis = material.three_visible
+        vis = material.THREE_visible
     except AttributeError:
-        logger.debug('No three_visible attribute found')
+        logger.debug('No THREE_visible attribute found')
         vis = True
 
     return vis

+ 4 - 4
utils/exporters/blender/addons/io_three/exporter/api/object.py

@@ -161,7 +161,7 @@ def nodes(valid_types, options):
         if not _on_visible_layer(obj, visible_layers): 
             continue
         try:
-            export = obj.three_export
+            export = obj.THREE_export
         except AttributeError:
             export = True
 
@@ -253,14 +253,14 @@ def extract_mesh(obj, options, recalculate=False):
     mesh = obj.to_mesh(context.scene, True, RENDER)
 
     # transfer the geometry type to the extracted mesh
-    mesh.three_geometry_type = obj.data.three_geometry_type
+    mesh.THREE_geometry_type = obj.data.THREE_geometry_type
 
     # now determine whether or not to export using the geometry type
     # set globally from the exporter's options or to use the local
     # override on the mesh node itself
     opt_buffer = options.get(constants.GEOMETRY_TYPE) 
     opt_buffer = opt_buffer == constants.BUFFER_GEOMETRY
-    prop_buffer = mesh.three_geometry_type == constants.BUFFER_GEOMETRY
+    prop_buffer = mesh.THREE_geometry_type == constants.BUFFER_GEOMETRY
 
     # if doing buffer geometry it is imperative to triangulate the mesh
     if opt_buffer or prop_buffer:
@@ -352,7 +352,7 @@ def prep_meshes(options):
             continue
 
         # if someone really insists on a visible node not being exportable
-        if not obj.three_export: 
+        if not obj.THREE_export: 
             logger.info('%s export is disabled', obj.name)
             continue
 

+ 6 - 6
utils/exporters/blender/addons/io_three/exporter/api/texture.py

@@ -49,9 +49,9 @@ def image_node(texture):
 def mag_filter(texture):
     logger.debug('texture.mag_filter(%s)', texture)
     try:
-        val = texture.three_mag_filter
+        val = texture.THREE_mag_filter
     except AttributeError:
-        logger.debug('No three_mag_filter attribute found')
+        logger.debug('No THREE_mag_filter attribute found')
         val = MAG_FILTER
 
     return val
@@ -61,9 +61,9 @@ def mag_filter(texture):
 def mapping(texture):
     logger.debug('texture.mapping(%s)', texture)
     try:
-        val = texture.three_mapping
+        val = texture.THREE_mapping
     except AttributeError:
-        logger.debug('No three_mapping attribute found')
+        logger.debug('No THREE_mapping attribute found')
         val = MAPPING
 
     return val
@@ -71,9 +71,9 @@ def mapping(texture):
 def min_filter(texture):
     logger.debug('texture.min_filter(%s)', texture)
     try:
-        val = texture.three_min_filter
+        val = texture.THREE_min_filter
     except AttributeError:
-        logger.debug('No three_min_filter attribute found')
+        logger.debug('No THREE_min_filter attribute found')
         val = MIN_FILTER 
 
     return val

+ 2 - 2
utils/exporters/blender/addons/io_three/exporter/io.py

@@ -30,9 +30,9 @@ def dump(filepath, data, options=None):
         func = lambda x,y: msgpack.dump(x, y)
         mode = 'wb'
     else:
-        round_off = options.get(constants.ROUND_OFF)
+        round_off = options.get(constants.ENABLE_PRECISION)
         if round_off:
-            _json.ROUND = options[constants.ROUND_VALUE]
+            _json.ROUND = options[constants.PRECISION]
         else:
             _json.ROUND = None
 

+ 3 - 3
utils/exporters/blender/addons/io_three/exporter/utilities.py

@@ -4,7 +4,7 @@ import hashlib
 from .. import constants
 
 
-ROUND = constants.ROUND
+ROUND = constants.DEFAULT_PRECISION
 
 
 def bit_mask(flags):
@@ -55,9 +55,9 @@ def round_off(value, ndigits=ROUND):
 
 
 def rounding(options):
-    round_off = options.get(constants.ROUND_OFF)
+    round_off = options.get(constants.ENABLE_PRECISION)
     if round_off:
-        round_val = options[constants.ROUND_VALUE]
+        round_val = options[constants.PRECISION]
     else:
         round_val = None
 

+ 1 - 1
utils/exporters/blender/tests/scripts/js/review.js

@@ -131,7 +131,7 @@ function loadGeometry( data, url ) {
 
         mesh = new THREE.Mesh( data.geometry, material );
 
-        if ( data.geometry.morphTargets !== undefined ) {
+        if ( data.geometry.morphTargets.length > 0 ) {
 
             console.log( 'loading morph targets' );
             data.materials[ 0 ].morphTargets = true;

+ 2 - 2
utils/exporters/blender/tests/scripts/test_scene_instancing.bash

@@ -4,6 +4,6 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 source "$DIR/setup_test_env.bash"
 
 blender --background $BLEND/scene_instancing.blend --python $PYSCRIPT -- \
-    $JSON --vertices --faces --scene --materials --roundOff \
-    --roundValue 4 --embedGeometry
+    $JSON --vertices --faces --scene --materials --enablePrecision \
+    --precision 4 --embedGeometry
 makereview $@ --tag $(tagname)

+ 2 - 2
utils/exporters/blender/tests/scripts/test_scene_no_embed.bash

@@ -4,6 +4,6 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 source "$DIR/setup_test_env.bash"
 
 blender --background $BLEND/scene_instancing.blend --python $PYSCRIPT -- \
-    $JSON --vertices --faces --scene --materials --roundOff \
-    --roundValue 4
+    $JSON --vertices --faces --scene --materials --enablePrecision \
+    --precision 4
 makereview $@ --tag $(tagname)