Skip to content

Commit cf8a87c

Browse files
committed
Merge pull request #62 from travnick/release/v4.13
Release/v4.13
2 parents 874d7db + c69af56 commit cf8a87c

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

io_export_cryblend/__init__.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -683,15 +683,28 @@ class FindWeightless(bpy.types.Operator):
683683
bl_label = "Find Weightless Vertices"
684684
bl_idname = "mesh.find_weightless"
685685

686+
# Minimum net weight to be considered non-weightless
687+
weight_epsilon = 0.0001
688+
689+
# Weightless: a vertex not belonging to any groups or with a net weight of 0
686690
def execute(self, context):
687691
obj = bpy.context.active_object
688-
if obj.type == 'MESH':
692+
bpy.ops.object.mode_set(mode="EDIT")
693+
bpy.ops.mesh.select_all(action="DESELECT")
694+
bpy.ops.object.mode_set(mode="OBJECT")
695+
if obj.type == "MESH":
689696
for v in obj.data.vertices:
690-
v.select = True
691-
for g in v.groups:
692-
v.select = False
693-
break
694-
return {'FINISHED'}
697+
if (not v.groups):
698+
v.select = True
699+
else:
700+
weight = 0
701+
for g in v.groups:
702+
weight += g.weight
703+
if (weight < self.weight_epsilon):
704+
v.select = True
705+
obj.data.update()
706+
bpy.ops.object.mode_set(mode="EDIT")
707+
return {"FINISHED"}
695708

696709

697710
class RemoveAllWeight(bpy.types.Operator):

io_export_cryblend/dds_converter.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,40 @@ def __call__(self, images_to_convert, refresh_rc, save_tiff):
5555

5656
tiff_image_for_rc = utils.get_absolute_path_for_rc(tiff_image_path)
5757

58+
try:
59+
create_normal_texture()
60+
except:
61+
cbPrint("Failed to invert green channel")
62+
5863
rc_process = utils.run_rc(self.__rc_exe,
5964
tiff_image_for_rc,
6065
rc_params)
6166

67+
# re-save the original image after running the RC to
68+
# prevent the original one from getting lost
69+
try:
70+
if ("_ddn" in image.name):
71+
image.save()
72+
except:
73+
cbPrint("Failed to invert green channel")
74+
6275
rc_process.wait()
63-
cbPrint("RC return code %s" % rc_process.returncode)
6476

6577
if save_tiff:
6678
self.__save_tiffs()
6779

6880
self.__remove_tmp_files()
6981

82+
def create_normal_texture():
83+
if ("_ddn" in image.name):
84+
# make a copy to prevent editing the original image
85+
temp_normal_image = image.copy()
86+
self.__invert_green_channel(temp_normal_image)
87+
# save to file and delete the temporary image
88+
new_normal_image_path = "%s_cb_normal.%s" % (os.path.splitext(temp_normal_image.filepath_raw)[0], os.path.splitext(temp_normal_image.filepath_raw)[1])
89+
temp_normal_image.save_render(filepath=new_normal_image_path)
90+
bpy.data.images.remove(temp_normal_image)
91+
7092
def __get_rc_params(self, refresh_rc, destination_path):
7193
rc_params = ["/verbose", "/threads=cores", "/userdialog=1"]
7294
if refresh_rc:
@@ -79,7 +101,20 @@ def __get_rc_params(self, refresh_rc, destination_path):
79101

80102
return rc_params
81103

104+
def __invert_green_channel(self, image):
105+
override = {'edit_image': bpy.data.images[image.name]}
106+
bpy.ops.image.invert(override, invert_g=True)
107+
image.update()
108+
82109
def __get_temp_tiff_image_path(self, image):
110+
# check if the image already is a .tif
111+
image_extension = utils.get_extension_from_path(image.filepath)
112+
cbPrint(image_extension)
113+
114+
if ".tif" == image_extension:
115+
cbPrint("Image {!r} is already a tif, not converting".format(image.name), 'debug')
116+
return image.filepath
117+
83118
tiff_image_path = utils.get_path_with_new_extension(image.filepath,
84119
"tif")
85120
tiff_image_absolute_path = utils.get_absolute_path(tiff_image_path)

io_export_cryblend/export.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,9 +1280,13 @@ def __export_library_geometries(self, parent_element):
12801280
if uvlay:
12811281
cbPrint("Found UV map.")
12821282
elif (object_.type == "MESH"):
1283-
cbPrint("Your UV map is missing, adding.")
12841283
override = {'object': object_}
1285-
bpy.ops.mesh.uv_texture_add(override)
1284+
bpy.ops.object.mode_set(override, mode='EDIT')
1285+
bpy.ops.mesh.select_all(override, action='SELECT')
1286+
bpy.ops.uv.smart_project(override, angle_limit=66, island_margin=0.03, user_area_weight=0)
1287+
bpy.ops.object.mode_set(override, mode='OBJECT')
1288+
object_.data.update(calc_tessface=1)
1289+
cbPrint("Missing UV map. Mesh unwrapped using smart UV project", message_type='warning')
12861290

12871291
for uvindex, uvlayer in enumerate(uvlay):
12881292
mapslot = uvindex

io_export_cryblend/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def get_guid():
8585

8686

8787
def random_hex_sector(length):
88-
fixed_lenght_hex_format = "%0" + str(length) + "x"
89-
return fixed_lenght_hex_format % random.randrange(16 ** length)
88+
fixed_length_hex_format = "%0" + str(length) + "x"
89+
return fixed_length_hex_format % random.randrange(16 ** length)
9090

9191

9292
# borrowed from obj exporter
@@ -232,6 +232,9 @@ def run_rc(rc_path, files_to_process, params=None):
232232
def get_path_with_new_extension(image_path, extension):
233233
return "%s.%s" % (os.path.splitext(image_path)[0], extension)
234234

235+
def get_extension_from_path(image_path):
236+
return "%s" % (os.path.splitext(image_path)[1])
237+
235238

236239
# this is needed if you want to access more than the first def
237240
if __name__ == "__main__":

0 commit comments

Comments
 (0)