[Bf-extensions-cvs] [003f117c] master: io_scene_3ds: Initial update 2.8 Import Only T66329
meta-androcto
noreply at git.blender.org
Sun Aug 11 10:38:45 CEST 2019
Commit: 003f117c7dd115aa703f80bef784e485ecb9d003
Author: meta-androcto
Date: Sun Aug 11 18:38:29 2019 +1000
Branches: master
https://developer.blender.org/rBAC003f117c7dd115aa703f80bef784e485ecb9d003
io_scene_3ds: Initial update 2.8 Import Only T66329
===================================================================
M io_scene_3ds/__init__.py
M io_scene_3ds/import_3ds.py
===================================================================
diff --git a/io_scene_3ds/__init__.py b/io_scene_3ds/__init__.py
index 2d1fe520..9c6bfe1e 100644
--- a/io_scene_3ds/__init__.py
+++ b/io_scene_3ds/__init__.py
@@ -20,13 +20,13 @@
bl_info = {
"name": "Autodesk 3DS format",
- "author": "Bob Holcomb, Campbell Barton",
- "version": (1, 0, 0),
- "blender": (2, 74, 0),
- "location": "File > Import-Export",
- "description": "Import-Export 3DS, meshes, uvs, materials, textures, "
+ "author": "Bob Holcomb, Campbell Barton, Andreas Atteneder",
+ "version": (2, 0, 0),
+ "blender": (2, 80, 0),
+ "location": "File > Import",
+ "description": "Import 3DS, meshes, uvs, materials, textures, "
"cameras & lamps",
- "warning": "",
+ "warning": "Images must be in file folder",
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
"Scripts/Import-Export/Autodesk_3DS",
"category": "Import-Export"}
@@ -145,14 +145,18 @@ def menu_func_import(self, context):
def register():
- bpy.utils.register_module(__name__)
+ bpy.utils.register_class(Import3DS)
+# TODO: Restore export
+# 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)
def unregister():
- bpy.utils.unregister_module(__name__)
+ bpy.utils.unregister_class(Import3DS)
+# TODO: Restore export
+# 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/import_3ds.py b/io_scene_3ds/import_3ds.py
index a6f2e3cb..385a88d7 100644
--- a/io_scene_3ds/import_3ds.py
+++ b/io_scene_3ds/import_3ds.py
@@ -29,6 +29,8 @@ import struct
import bpy
import mathutils
+from bpy_extras.node_shader_utils import PrincipledBSDFWrapper
+
BOUNDS_3DS = []
@@ -223,53 +225,51 @@ def skip_to_end(file, skip_chunk):
skip_chunk.bytes_read += buffer_size
-def add_texture_to_material(image, texture, scale, offset, extension, material, mapto):
+def add_texture_to_material(image, scale, offset, extension, contextMaterialWrapper, mapto):
#print('assigning %s to %s' % (texture, material))
if mapto not in {'COLOR', 'SPECULARITY', 'ALPHA', 'NORMAL'}:
print(
"\tError: Cannot map to %r\n\tassuming diffuse color. modify material %r later." %
- (mapto, material.name)
+ (mapto, contextMaterialWrapper.material.name)
)
mapto = "COLOR"
- if image:
- texture.image = image
+ if mapto == 'COLOR':
+ img_wrap = contextMaterialWrapper.base_color_texture
+ elif mapto == 'SPECULARITY':
+ # TODO: Not sure if this is correct usage?
+ img_wrap = contextMaterialWrapper.specular_texture
+ elif mapto == 'ALPHA':
+ img_wrap = contextMaterialWrapper.alpha_texture
+ elif mapto == 'NORMAL':
+ img_wrap = contextMaterialWrapper.normalmap_texture
- mtex = material.texture_slots.add()
- mtex.texture = texture
- mtex.texture_coords = 'UV'
- mtex.use_map_color_diffuse = False
+ img_wrap.image = image
- mtex.scale = (scale[0], scale[1], 1.0)
- mtex.offset = (offset[0], offset[1], 0.0)
+ img_wrap.scale = scale
+ img_wrap.translation = offset
- texture.extension = 'REPEAT'
+ img_wrap.extension = 'REPEAT'
if extension == 'mirror':
# 3DS mirror flag can be emulated by these settings (at least so it seems)
- texture.repeat_x = texture.repeat_y = 2
- texture.use_mirror_x = texture.use_mirror_y = True
+ # TODO: bring back mirror
+ pass
+ # texture.repeat_x = texture.repeat_y = 2
+ # texture.use_mirror_x = texture.use_mirror_y = True
elif extension == 'decal':
# 3DS' decal mode maps best to Blenders CLIP
- texture.extension = 'CLIP'
-
- if mapto == 'COLOR':
- mtex.use_map_color_diffuse = True
- elif mapto == 'SPECULARITY':
- mtex.use_map_specular = True
- elif mapto == 'ALPHA':
- mtex.use_map_alpha = True
- elif mapto == 'NORMAL':
- mtex.use_map_normal = True
+ img_wrap.extension = 'CLIP'
-def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
+def process_next_chunk(context, file, previous_chunk, importedObjects, IMAGE_SEARCH):
from bpy_extras.image_utils import load_image
#print previous_chunk.bytes_read, 'BYTES READ'
contextObName = None
contextLamp = [None, None] # object, Data
contextMaterial = None
+ contextMaterialWrapper = None
contextMatrix_rot = None # Blender.mathutils.Matrix(); contextMatrix.identity()
#contextMatrix_tx = None # Blender.mathutils.Matrix(); contextMatrix.identity()
contextMesh_vertls = None # flat array: (verts * 3)
@@ -296,7 +296,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
object_parent = [] # index of parent in hierarchy, 0xFFFF = no parent
pivot_list = [] # pivots with hierarchy handling
- def putContextMesh(myContextMesh_vertls, myContextMesh_facels, myContextMeshMaterials):
+ def putContextMesh(context, myContextMesh_vertls, myContextMesh_facels, myContextMeshMaterials):
bmesh = bpy.data.meshes.new(contextObName)
if myContextMesh_facels is None:
@@ -318,8 +318,8 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
bmesh.loops.foreach_set("vertex_index", eekadoodle_faces)
if bmesh.polygons and contextMeshUV:
- bmesh.uv_textures.new()
- uv_faces = bmesh.uv_textures.active.data[:]
+ bmesh.uv_layers.new()
+ uv_faces = bmesh.uv_layers.active.data[:]
else:
uv_faces = None
@@ -341,7 +341,8 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
if uv_faces and img:
for fidx in faces:
bmesh.polygons[fidx].material_index = mat_idx
- uv_faces[fidx].image = img
+ # TODO: How to restore this?
+ # uv_faces[fidx].image = img
else:
for fidx in faces:
bmesh.polygons[fidx].material_index = mat_idx
@@ -366,7 +367,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
ob = bpy.data.objects.new(contextObName, bmesh)
object_dictionary[contextObName] = ob
- SCN.objects.link(ob)
+ context.view_layer.active_layer_collection.collection.objects.link(ob)
importedObjects.append(ob)
if contextMatrix_rot:
@@ -400,7 +401,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
return [float(col) / 255 for col in struct.unpack('<3B', temp_data)] # data [0,1,2] == rgb
def read_texture(new_chunk, temp_chunk, name, mapto):
- new_texture = bpy.data.textures.new(name, type='IMAGE')
+# new_texture = bpy.data.textures.new(name, type='IMAGE')
u_scale, v_scale, u_offset, v_offset = 1.0, 1.0, 0.0, 0.0
mirror = False
@@ -440,8 +441,8 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
# add the map to the material in the right channel
if img:
- add_texture_to_material(img, new_texture, (u_scale, v_scale),
- (u_offset, v_offset), extension, contextMaterial, mapto)
+ add_texture_to_material(img, (u_scale, v_scale, 1),
+ (u_offset, v_offset, 0), extension, contextMaterialWrapper, mapto)
dirname = os.path.dirname(file.name)
@@ -469,7 +470,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
elif new_chunk.ID == OBJECTINFO:
#print 'elif new_chunk.ID == OBJECTINFO:'
# print 'found an OBJECTINFO chunk'
- process_next_chunk(file, new_chunk, importedObjects, IMAGE_SEARCH)
+ process_next_chunk(context, file, new_chunk, importedObjects, IMAGE_SEARCH)
#keep track of how much we read in the main chunk
new_chunk.bytes_read += temp_chunk.bytes_read
@@ -478,7 +479,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
elif new_chunk.ID == OBJECT:
if CreateBlenderObject:
- putContextMesh(contextMesh_vertls, contextMesh_facels, contextMeshMaterials)
+ putContextMesh(context, contextMesh_vertls, contextMesh_facels, contextMeshMaterials)
contextMesh_vertls = []
contextMesh_facels = []
@@ -500,6 +501,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
#print 'elif new_chunk.ID == MATERIAL:'
contextMaterial = bpy.data.materials.new('Material')
+ contextMaterialWrapper = PrincipledBSDFWrapper(contextMaterial, is_readonly=False, use_nodes=True)
elif new_chunk.ID == MAT_NAME:
#print 'elif new_chunk.ID == MAT_NAME:'
@@ -516,30 +518,31 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
elif new_chunk.ID == MAT_AMBIENT:
#print 'elif new_chunk.ID == MAT_AMBIENT:'
read_chunk(file, temp_chunk)
- if temp_chunk.ID == MAT_FLOAT_COLOR:
- contextMaterial.mirror_color = read_float_color(temp_chunk)
+ # TODO: consider ambient term somehow. maybe add to color
+# if temp_chunk.ID == MAT_FLOAT_COLOR:
+# contextMaterial.mirror_color = read_float_color(temp_chunk)
# temp_data = file.read(struct.calcsize('3f'))
# temp_chunk.bytes_read += 12
# contextMaterial.mirCol = [float(col) for col in struct.unpack('<3f', temp_data)]
- elif temp_chunk.ID == MAT_24BIT_COLOR:
- contextMaterial.mirror_color = read_byte_color(temp_chunk)
+# elif temp_chunk.ID == MAT_24BIT_COLOR:
+# contextMaterial.mirror_color =
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list