Pārlūkot izejas kodu

Merge pull request #6131 from mese79/dev

ObjectLoader add support for normal/bump scale + io_three enhancement
Mr.doob 10 gadi atpakaļ
vecāks
revīzija
4283f5d74a

+ 8 - 1
src/loaders/ObjectLoader.js

@@ -5,6 +5,7 @@
 THREE.ObjectLoader = function ( manager ) {
 
 	this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
+	this.texturePath = '';
 
 };
 
@@ -14,7 +15,7 @@ THREE.ObjectLoader.prototype = {
 
 	load: function ( url, onLoad, onProgress, onError ) {
 
-		if ( this.texturePath === undefined ) {
+		if ( this.texturePath === '' ) {
 
 			this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
 
@@ -245,6 +246,9 @@ THREE.ObjectLoader.prototype = {
 				if ( data.bumpMap !== undefined ) {
 
 					material.bumpMap = getTexture( data.bumpMap );
+					if ( data.bumpScale ) {
+						material.bumpScale = new THREE.Vector2( data.bumpScale, data.bumpScale );
+					}
 
 				}
 
@@ -263,6 +267,9 @@ THREE.ObjectLoader.prototype = {
 				if ( data.normalMap !== undefined ) {
 
 					material.normalMap = getTexture( data.normalMap );
+					if ( data.normalScale ) {
+						material.normalScale = new THREE.Vector2( data.normalScale, data.normalScale );
+					}
 
 				}
 

+ 13 - 1
utils/exporters/blender/addons/io_three/__init__.py

@@ -26,7 +26,8 @@ from bpy.props import (
     EnumProperty,
     BoolProperty,
     FloatProperty,
-    IntProperty
+    IntProperty,
+    StringProperty
 )
 
 from . import constants
@@ -295,6 +296,7 @@ def save_settings_export(properties):
         constants.COMPRESSION: properties.option_compression,
         constants.INDENT: properties.option_indent,
         constants.COPY_TEXTURES: properties.option_copy_textures,
+        constants.TEXTURE_FOLDER: properties.option_texture_folder,
 
         constants.SCENE: properties.option_export_scene,
         #constants.EMBED_GEOMETRY: properties.option_embed_geometry,
@@ -420,6 +422,10 @@ def restore_settings_export(properties):
         constants.COPY_TEXTURES,
         constants.EXPORT_OPTIONS[constants.COPY_TEXTURES])
 
+    properties.option_texture_folder = settings.get(
+        constants.TEXTURE_FOLDER,
+        constants.EXPORT_OPTIONS[constants.TEXTURE_FOLDER])
+
     properties.option_embed_animation = settings.get(
         constants.EMBED_ANIMATION,
         constants.EXPORT_OPTIONS[constants.EMBED_ANIMATION])
@@ -617,6 +623,9 @@ class ExportThree(bpy.types.Operator, ExportHelper):
         description="Copy textures",
         default=constants.EXPORT_OPTIONS[constants.COPY_TEXTURES])
 
+    option_texture_folder = StringProperty(name="Texture folder",
+        description="add this folder to textures path", default="")
+
     option_lights = BoolProperty(
         name="Lights",
         description="Export default scene lights",
@@ -812,6 +821,9 @@ class ExportThree(bpy.types.Operator, ExportHelper):
         row = layout.row()
         row.prop(self.properties, 'option_copy_textures')
 
+        row = layout.row()
+        row.prop(self.properties, "option_texture_folder")
+
         row = layout.row()
         row.prop(self.properties, 'option_scale')
 

+ 4 - 2
utils/exporters/blender/addons/io_three/constants.py

@@ -63,6 +63,7 @@ LIGHTS = 'lights'
 FACE_MATERIALS = 'faceMaterials'
 SKINNING = 'skinning'
 COPY_TEXTURES = 'copyTextures'
+TEXTURE_FOLDER = "textureFolder"
 ENABLE_PRECISION = 'enablePrecision'
 PRECISION = 'precision'
 DEFAULT_PRECISION = 6
@@ -91,8 +92,8 @@ INFLUENCES_PER_VERTEX = 'influencesPerVertex'
 EXPORT_OPTIONS = {
     FACES: True,
     VERTICES: True,
-    NORMALS: False,
-    UVS: False,
+    NORMALS: True,
+    UVS: True,
     COLORS: False,
     MATERIALS: False,
     FACE_MATERIALS: False,
@@ -110,6 +111,7 @@ EXPORT_OPTIONS = {
     CAMERAS: False,
     LIGHTS: False,
     COPY_TEXTURES: True,
+    TEXTURE_FOLDER: "",
     LOGGING: DEBUG,
     ENABLE_PRECISION: True,
     PRECISION: DEFAULT_PRECISION,

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

@@ -71,12 +71,12 @@ def export_geometry(filepath, options, node=None):
             logger.error(msg)
             exception = exceptions.GeometryError
     
-    if exception is not None:
-        if api.batch_mode():
-            raise exception(msg)
-        else:
-            dialogs.error(msg)
-            return
+        if exception is not None:
+            if api.batch_mode():
+                raise exception(msg)
+            else:
+                dialogs.error(msg)
+                return
 
     mesh = api.object.mesh(node, options)
     parent = base_classes.BaseScene(filepath, options)

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

@@ -18,10 +18,10 @@ def batch_mode():
 
     :return: Whether or not the session is interactive
     :rtype: bool
-
+       
     """
     return bpy.context.area is None
-
+      
 
 def init():
     """Initializing the api module. Required first step before

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

@@ -380,7 +380,7 @@ def _valid_textures(material):
     for texture in material.texture_slots:
         if not texture:
             continue
-        if texture.texture.type != IMAGE:
+        if texture.texture.type != IMAGE or not texture.use:
             continue
         logger.debug("Valid texture found %s", texture)
         yield texture

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

@@ -170,6 +170,9 @@ def textures():
 
     """
     logger.debug("texture.textures()")
-    for texture in data.textures:
-        if texture.type == IMAGE:
-            yield texture.name
+    for mat in data.materials:
+        if mat.users == 0:
+            continue
+        for slot in mat.texture_slots:
+            if slot and slot.use and slot.texture.type == IMAGE:
+                yield slot.texture.name

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

@@ -135,7 +135,7 @@ class Geometry(base_classes.BaseNode):
 
         return data
 
-    def copy_textures(self):
+    def copy_textures(self, texture_folder=""):
         """Copy the textures to the destination directory."""
         logger.debug("Geometry().copy_textures()")
         if self.options.get(constants.COPY_TEXTURES):
@@ -143,7 +143,7 @@ class Geometry(base_classes.BaseNode):
             if texture_registration:
                 logger.info("%s has registered textures", self.node)
                 io.copy_registered_textures(
-                    os.path.dirname(self.scene.filepath),
+                    os.path.join(os.path.dirname(self.scene.filepath), texture_folder),
                     texture_registration)
 
     def parse(self):

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

@@ -11,7 +11,8 @@ class Image(base_classes.BaseNode):
         logger.debug("Image().__init__(%s)", node)
         base_classes.BaseNode.__init__(self, node, parent, constants.IMAGE)
 
-        self[constants.URL] = api.image.file_name(self.node)
+        texture_folder = self.scene.options.get(constants.TEXTURE_FOLDER, "")
+        self[constants.URL] = os.path.join(texture_folder, api.image.file_name(self.node))
 
     @property
     def destination(self):

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

@@ -14,6 +14,7 @@ def copy_registered_textures(dest, registration):
 
     """
     logger.debug("io.copy_registered_textures(%s, %s)", dest, registration)
+    os.makedirs(dest, exist_ok=True)
     for value in registration.values():
         copy(value['file_path'], dest)
 

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

@@ -159,9 +159,10 @@ class Scene(base_classes.BaseScene):
         io.dump(self.filepath, data, options=self.options)
 
         if self.options.get(constants.COPY_TEXTURES):
+            texture_folder = self.options.get(constants.TEXTURE_FOLDER)
             for geo in self[constants.GEOMETRIES]:
                 logger.info("Copying textures from %s", geo.node)
-                geo.copy_textures()
+                geo.copy_textures(texture_folder)
 
     def _parse_geometries(self):
         """Locate all geometry nodes and parse them"""