io_scene_3ds: Update for Blender 3.x #5
@ -647,8 +647,8 @@ def make_material_chunk(material, image):
|
|||||||
|
|
||||||
name_str = material.name if material else "None"
|
name_str = material.name if material else "None"
|
||||||
|
|
||||||
if image:
|
#if image:
|
||||||
name_str += image.name
|
# name_str += image.name
|
||||||
|
|
||||||
name.add_variable("name", _3ds_string(sane_name(name_str)))
|
name.add_variable("name", _3ds_string(sane_name(name_str)))
|
||||||
material_chunk.add_subchunk(name)
|
material_chunk.add_subchunk(name)
|
||||||
@ -672,6 +672,7 @@ def make_material_chunk(material, image):
|
|||||||
material_chunk.add_subchunk(make_percent_subchunk(MATSHIN2, wrap.specular))
|
material_chunk.add_subchunk(make_percent_subchunk(MATSHIN2, wrap.specular))
|
||||||
material_chunk.add_subchunk(make_percent_subchunk(MATSHIN3, wrap.metallic))
|
material_chunk.add_subchunk(make_percent_subchunk(MATSHIN3, wrap.metallic))
|
||||||
material_chunk.add_subchunk(make_percent_subchunk(MATTRANS, 1 - wrap.alpha))
|
material_chunk.add_subchunk(make_percent_subchunk(MATTRANS, 1 - wrap.alpha))
|
||||||
|
material_chunk.add_subchunk(make_percent_subchunk(MATSELFILPCT, wrap.emission_strength))
|
||||||
material_chunk.add_subchunk(shading)
|
material_chunk.add_subchunk(shading)
|
||||||
|
|
||||||
if wrap.base_color_texture:
|
if wrap.base_color_texture:
|
||||||
@ -706,13 +707,10 @@ def make_material_chunk(material, image):
|
|||||||
normal = [wrap.normalmap_texture]
|
normal = [wrap.normalmap_texture]
|
||||||
bump = wrap.normalmap_strength
|
bump = wrap.normalmap_strength
|
||||||
b_pct = min(bump, 1)
|
b_pct = min(bump, 1)
|
||||||
bumpval = min(999, (bump * 100)) # 3ds max bump = 999
|
|
||||||
strength = _3ds_chunk(MAT_BUMP_PERCENT)
|
|
||||||
strength.add_variable("bump_pct", _3ds_ushort(int(bumpval)))
|
|
||||||
matmap = make_material_texture_chunk(MAT_BUMPMAP, normal, b_pct)
|
matmap = make_material_texture_chunk(MAT_BUMPMAP, normal, b_pct)
|
||||||
if matmap:
|
if matmap:
|
||||||
material_chunk.add_subchunk(matmap)
|
material_chunk.add_subchunk(matmap)
|
||||||
material_chunk.add_subchunk(strength)
|
material_chunk.add_subchunk(make_percent_subchunk(MAT_BUMP_PERCENT, b_pct))
|
||||||
|
|
||||||
if wrap.roughness_texture:
|
if wrap.roughness_texture:
|
||||||
roughness = [wrap.roughness_texture]
|
roughness = [wrap.roughness_texture]
|
||||||
@ -722,7 +720,7 @@ def make_material_chunk(material, image):
|
|||||||
material_chunk.add_subchunk(matmap)
|
material_chunk.add_subchunk(matmap)
|
||||||
|
|
||||||
if wrap.emission_color_texture:
|
if wrap.emission_color_texture:
|
||||||
e_pct = sum(wrap.emission_color[:]) * .25
|
e_pct = wrap.emission_strength
|
||||||
emission = [wrap.emission_color_texture]
|
emission = [wrap.emission_color_texture]
|
||||||
matmap = make_material_texture_chunk(MAT_SELFIMAP, emission, e_pct)
|
matmap = make_material_texture_chunk(MAT_SELFIMAP, emission, e_pct)
|
||||||
if matmap:
|
if matmap:
|
||||||
@ -909,8 +907,8 @@ def make_faces_chunk(tri_list, mesh, materialDict):
|
|||||||
context_face_array = unique_mats[ma, img][1]
|
context_face_array = unique_mats[ma, img][1]
|
||||||
except:
|
except:
|
||||||
name_str = ma if ma else "None"
|
name_str = ma if ma else "None"
|
||||||
if img:
|
#if img:
|
||||||
name_str += img
|
# name_str += img
|
||||||
|
|
||||||
context_face_array = _3ds_array()
|
context_face_array = _3ds_array()
|
||||||
unique_mats[ma, img] = _3ds_string(sane_name(name_str)), context_face_array
|
unique_mats[ma, img] = _3ds_string(sane_name(name_str)), context_face_array
|
||||||
@ -1171,7 +1169,7 @@ def save(operator,
|
|||||||
):
|
):
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from bpy_extras.io_utils import create_derived_objects, free_derived_objects
|
#from bpy_extras.io_utils import create_derived_objects, free_derived_objects
|
||||||
|
|
||||||
"""Save the Blender scene to a 3ds file."""
|
"""Save the Blender scene to a 3ds file."""
|
||||||
|
|
||||||
@ -1187,7 +1185,7 @@ def save(operator,
|
|||||||
|
|
||||||
scene = context.scene
|
scene = context.scene
|
||||||
layer = context.view_layer
|
layer = context.view_layer
|
||||||
#depsgraph = context.evaluated_depsgraph_get()
|
depsgraph = context.evaluated_depsgraph_get()
|
||||||
|
|
||||||
# Initialize the main chunk (primary):
|
# Initialize the main chunk (primary):
|
||||||
primary = _3ds_chunk(PRIMARY)
|
primary = _3ds_chunk(PRIMARY)
|
||||||
@ -1235,7 +1233,9 @@ def save(operator,
|
|||||||
|
|
||||||
for ob in objects:
|
for ob in objects:
|
||||||
# get derived objects
|
# get derived objects
|
||||||
free, derived = create_derived_objects(scene, ob)
|
#free, derived = create_derived_objects(scene, ob)
|
||||||
|
derived_dict = bpy_extras.io_utils.create_derived_objects(depsgraph, [ob])
|
||||||
|
derived = derived_dict.get(ob)
|
||||||
|
|
||||||
if derived is None:
|
if derived is None:
|
||||||
continue
|
continue
|
||||||
@ -1244,7 +1244,6 @@ def save(operator,
|
|||||||
if ob.type not in {'MESH', 'CURVE', 'SURFACE', 'FONT', 'META'}:
|
if ob.type not in {'MESH', 'CURVE', 'SURFACE', 'FONT', 'META'}:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
#ob_derived_eval = ob_derived.evaluated_get(depsgraph)
|
|
||||||
try:
|
try:
|
||||||
data = ob_derived.to_mesh()
|
data = ob_derived.to_mesh()
|
||||||
except:
|
except:
|
||||||
@ -1288,8 +1287,8 @@ def save(operator,
|
|||||||
|
|
||||||
# ob_derived_eval.to_mesh_clear()
|
# ob_derived_eval.to_mesh_clear()
|
||||||
|
|
||||||
if free:
|
#if free:
|
||||||
free_derived_objects(ob)
|
# free_derived_objects(ob)
|
||||||
|
|
||||||
# Make material chunks for all materials used in the meshes:
|
# Make material chunks for all materials used in the meshes:
|
||||||
for ma_image in materialDict.values():
|
for ma_image in materialDict.values():
|
||||||
|
Reference in New Issue
Block a user