[Bf-extensions-cvs] [dff14c58] master: Signed-off-by: Sebastian Sille <nrgsille at gmx.de>

Sebastian Sille noreply at git.blender.org
Sat Sep 26 21:28:23 CEST 2020


Commit: dff14c587a3fb06bc98e6fa3504f5881c03e9e5d
Author: Sebastian Sille
Date:   Thu Sep 24 11:18:11 2020 +0200
Branches: master
https://developer.blender.org/rBACdff14c587a3fb06bc98e6fa3504f5881c03e9e5d

Signed-off-by: Sebastian Sille <nrgsille at gmx.de>

===================================================================

M	io_scene_3ds/__init__.py
M	io_scene_3ds/export_3ds.py
M	io_scene_3ds/import_3ds.py

===================================================================

diff --git a/io_scene_3ds/__init__.py b/io_scene_3ds/__init__.py
index b6f8b4c0..af4aaa56 100644
--- a/io_scene_3ds/__init__.py
+++ b/io_scene_3ds/__init__.py
@@ -20,9 +20,9 @@
 
 bl_info = {
     "name": "Autodesk 3DS format",
-    "author": "Bob Holcomb, Campbell Barton, Andreas Atteneder",
-    "version": (2, 0, 0),
-    "blender": (2, 80, 0),
+    "author": "Bob Holcomb, Campbell Barton, Andreas Atteneder, Sebastian Schrand",
+    "version": (2, 1, 0),
+    "blender": (2, 82, 0),
     "location": "File > Import",
     "description": "Import 3DS, meshes, uvs, materials, textures, "
                    "cameras & lamps",
@@ -86,6 +86,12 @@ class Import3DS(bpy.types.Operator, ImportHelper):
             default=True,
             )
 
+    read_keyframe: bpy.props.BoolProperty(
+            name="Read Keyframe",
+            description="Read the keyframe data",
+            default=True,
+            )
+
     def execute(self, context):
         from . import import_3ds
 
@@ -147,8 +153,7 @@ def menu_func_import(self, context):
 
 def register():
     bpy.utils.register_class(Import3DS)
-#     TODO: Restore export
-#     bpy.utils.register_class(Export3DS)
+    bpy.utils.register_class(Export3DS)
 
     bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
     bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
@@ -156,8 +161,7 @@ def register():
 
 def unregister():
     bpy.utils.unregister_class(Import3DS)
-#    TODO: Restore export
-#     bpy.utils.unregister_class(Export3DS)
+    bpy.utils.unregister_class(Export3DS)
 
     bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
     bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
diff --git a/io_scene_3ds/export_3ds.py b/io_scene_3ds/export_3ds.py
index a81cd11d..d96d6651 100644
--- a/io_scene_3ds/export_3ds.py
+++ b/io_scene_3ds/export_3ds.py
@@ -19,13 +19,20 @@
 # <pep8 compliant>
 
 # Script copyright (C) Bob Holcomb
-# Contributors: Campbell Barton, Bob Holcomb, Richard Lärkäng, Damien McGinnes, Mark Stijnman
+# Contributors: Campbell Barton, Bob Holcomb, Richard Lärkäng, Damien McGinnes, Mark Stijnman, Sebastian Sille
 
 """
 Exporting is based on 3ds loader from www.gametutorials.com(Thanks DigiBen) and using information
 from the lib3ds project (http://lib3ds.sourceforge.net/) sourcecode.
 """
 
+import bpy
+import math
+import struct
+import mathutils
+import bpy_extras
+from bpy_extras import node_shader_utils
+
 ######################################################
 # Data Structures
 ######################################################
@@ -35,11 +42,13 @@ from the lib3ds project (http://lib3ds.sourceforge.net/) sourcecode.
 PRIMARY = 0x4D4D
 
 #------ Main Chunks
-OBJECTINFO = 0x3D3D  # This gives the version of the mesh and is found right before the material and object information
 VERSION = 0x0002  # This gives the version of the .3ds file
 KFDATA = 0xB000  # This is the header for all of the key frame info
 
 #------ sub defines of OBJECTINFO
+OBJECTINFO = 0x3D3D  # Main mesh object chunk before the material and object information
+MESHVERSION = 0x3D3E  # This gives the version of the mesh
+AMBIENTLIGHT = 0x2100  # The color of the ambient light
 MATERIAL = 45055  # 0xAFFF // This stored the texture info
 OBJECT = 16384  # 0x4000 // This stores the faces, vertices, etc...
 
@@ -47,40 +56,64 @@ OBJECT = 16384  # 0x4000 // This stores the faces, vertices, etc...
 MATNAME = 0xA000  # This holds the material name
 MATAMBIENT = 0xA010  # Ambient color of the object/material
 MATDIFFUSE = 0xA020  # This holds the color of the object/material
-MATSPECULAR = 0xA030  # SPecular color of the object/material
-MATSHINESS = 0xA040  # ??
+MATSPECULAR = 0xA030  # Specular color of the object/material
+MATSHINESS = 0xA040  # Specular intensity of the object/material (percent)
+MATSHIN2 = 0xA041  # Reflection of the object/material (percent)
+MATSHIN3 = 0xA042  # metallic/mirror of the object/material (percent)
+MATTRANS = 0xA050  # Transparency value (100-OpacityValue) (percent)
+MATSELFILPCT = 0xA084  # Self illumination strength (percent)
+MATSHADING = 0xA100  # Material shading method
 
 MAT_DIFFUSEMAP = 0xA200  # This is a header for a new diffuse texture
+MAT_SPECMAP = 0xA204  # head for specularity map
 MAT_OPACMAP = 0xA210  # head for opacity map
-MAT_BUMPMAP = 0xA230  # read for normal map
-MAT_SPECMAP = 0xA204  # read for specularity map
-
-#>------ sub defines of MAT_???MAP
+MAT_REFLMAP = 0xA220  # head for reflect map
+MAT_BUMPMAP = 0xA230  # head for normal map
+MAT_BUMP_PERCENT = 0xA252  # Normalmap strength (percent)
+MAT_TEX2MAP = 0xA33A  # head for secondary texture
+MAT_SHINMAP = 0xA33C  # head for roughness map
+MAT_SELFIMAP = 0xA33D  # head for emission map
+
+#>------ sub defines of MAT_MAP
 MATMAPFILE = 0xA300  # This holds the file name of a texture
-
 MAT_MAP_TILING = 0xa351   # 2nd bit (from LSB) is mirror UV flag
+MAT_MAP_TEXBLUR = 0xA353  # Texture blurring factor
 MAT_MAP_USCALE = 0xA354   # U axis scaling
 MAT_MAP_VSCALE = 0xA356   # V axis scaling
 MAT_MAP_UOFFSET = 0xA358  # U axis offset
 MAT_MAP_VOFFSET = 0xA35A  # V axis offset
 MAT_MAP_ANG = 0xA35C      # UV rotation around the z-axis in rad
-
-RGB1 = 0x0011
-RGB2 = 0x0012
+MAP_COL1 = 0xA360  # Tint Color1
+MAP_COL2 = 0xA362  # Tint Color2
+MAP_RCOL = 0xA364  # Red tint
+MAP_GCOL = 0xA366  # Green tint
+MAP_BCOL = 0xA368  # Blue tint
+
+RGB = 0x0010  # RGB float
+RGB1 = 0x0011  # RGB Color1
+RGB2 = 0x0012  # RGB Color2
+PCT = 0x0030  # Percent chunk
+MASTERSCALE = 0x0100  # Master scale factor
 
 #>------ sub defines of OBJECT
 OBJECT_MESH = 0x4100  # This lets us know that we are reading a new object
-OBJECT_LIGHT = 0x4600  # This lets un know we are reading a light object
-OBJECT_CAMERA = 0x4700  # This lets un know we are reading a camera object
+OBJECT_LIGHT = 0x4600  # This lets us know we are reading a light object
+OBJECT_CAMERA = 0x4700  # This lets us know we are reading a camera object
+
+#>------ Sub defines of LIGHT
+LIGHT_MULTIPLIER = 0x465B  # The light energy factor
+LIGHT_SPOTLIGHT = 0x4610  # The target of a spotlight
+LIGHT_SPOTROLL = 0x4656  # The roll angle of the spot
 
 #>------ sub defines of CAMERA
-OBJECT_CAM_RANGES = 0x4720      # The camera range values
+OBJECT_CAM_RANGES = 0x4720  # The camera range values
 
 #>------ sub defines of OBJECT_MESH
 OBJECT_VERTICES = 0x4110  # The objects vertices
 OBJECT_FACES = 0x4120  # The objects faces
 OBJECT_MATERIAL = 0x4130  # This is found if the object has a material, either texture map or color
 OBJECT_UV = 0x4140  # The UV texture coordinates
+OBJECT_SMOOTH = 0x4150  # The objects smooth groups
 OBJECT_TRANS_MATRIX = 0x4160  # The Object Matrix
 
 #>------ sub defines of KFDATA
@@ -98,7 +131,6 @@ POS_TRACK_TAG = 0xB020
 ROT_TRACK_TAG = 0xB021
 SCL_TRACK_TAG = 0xB022
 
-import struct
 
 # So 3ds max can open files, limit names to 12 in length
 # this is very annoying for filenames!
@@ -202,9 +234,9 @@ class _3ds_string(object):
         file.write(struct.pack(binary_format, self.value))
 
     def __str__(self):
-        return self.value
-
+        return str(self.value)
 
+    
 class _3ds_point_3d(object):
     """Class representing a three-dimensional point for a 3ds file."""
     __slots__ = "x", "y", "z"
@@ -258,6 +290,23 @@ class _3ds_point_uv(object):
     def __str__(self):
         return '(%g, %g)' % self.uv
 
+    
+class _3ds_float_color(object):
+    """Class representing a rgb float color for a 3ds file."""
+    __slots__ = "r", "g", "b"
+
+    def __init__(self, col):
+        self.r, self.g, self.b = col
+
+    def get_size(self):
+        return 3 * SZ_FLOAT
+
+    def write(self, file):
+        file.write(struct.pack('3f', self.r, self.g, self.b))
+
+    def __str__(self):
+        return '{%f, %f, %f}' % (self.r, self.g, self.b)
+
 
 class _3ds_rgb_color(object):
     """Class representing a (24-bit) rgb color for a 3ds file."""
@@ -436,24 +485,25 @@ class _3ds_chunk(object):
 # EXPORT
 ######################################################
 
-def get_material_image_texslots(material):
-    # blender utility func.
+def get_material_image(material):
+    """ Get images from paint slots."""
     if material:
-        return [s for s in material.texture_slots if s and s.texture.type == 'IMAGE' and s.texture.image]
-
-    return []
-
-    """
-    images = []
-    if material:
-        for mtex in material.getTextures():
-            if mtex and mtex.tex.type == Blender.Texture.Types.IMAGE:
-                image = mtex.tex.image
-                if image:
-                    images.append(image) # maye want to include info like diffuse, spec here.
-    return images
-    """
-
+        pt = material.paint_active_slot
+        tex = material.texture_paint_images
+        if pt < len(tex):
+            slot = tex[pt]
+            if slot.type == 'IMAGE':
+                return slot
+
+def get_uv_image(ma):
+    """ Get image from material wrapper."""
+    if ma and ma.use_nodes:
+        ma_wrap = node_shader_utils.PrincipledBSDFWrapper(ma)
+        ma_tex = ma_wrap.base_color_texture
+        if ma_tex and ma_tex.image is not None:
+            return ma_tex.image
+    else:
+        return get_material_image(ma)
 
 def make_material_subchunk(chunk_id, color):
     """Make a material subchunk.
@@ -469,83 +519,123 @@ def make_material_subchunk(chunk_id, color):
     #mat_sub.add_subchunk(col2)
     return mat_sub
 
+def make_percent_subchunk(chunk_id, percent):
+    """Make a percentage based subchunk."""
+    pct_sub = _3ds_chunk(chunk_id)
+    pcti = _3ds_chunk(PCT)
+    pcti.add_variable("percent", _3ds_ushort(int(round(percent * 100,0))))
+    pct_sub.add_subchunk(pcti)
+    return pct_sub
+
+def make_texture_chunk(chunk_id, images):
+    """Make Material Map texture chunk."""
+    # Add texture percentage value (100 = 1.0)
+    ma_sub = make_percent_subchunk(chunk_id, 1)
+    has_entry = False
 
-def make_material_texture_chunk(chunk_id, texslots, tess_uv_image=None):
-    """Make Material Map texture chunk given a seq. of `MaterialTextureSlot`'s
-
-        `tess_uv_image` is optionally used as image source if the slots are
-        empty. No additional filtering for mapping modes is done,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list