Skip to content

Commit 5537394

Browse files
author
Christopher Remde
committed
Merge branch 'NormalsSupport'
2 parents 852fdb0 + b1fc650 commit 5537394

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+5777
-2877
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ GSS_Showreel
99
GSS_Premium
1010
GSS_AVP_Testproject
1111
Unity_Test_Project/Assets/TextMesh Pro/
12+
13+
Unity_Test_Project/Assets/Plugins/Sirenix/
14+
15+
Unity_Test_Project/Assets/Plugins/
16+
17+
Converter/Sequence_Converter_UI.exe

Converter/Sequence_Converter.py

Lines changed: 169 additions & 109 deletions
Large diffs are not rendered by default.

Converter/Sequence_Converter_UI.py

Lines changed: 105 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from tkinter.filedialog import askdirectory
99
import dearpygui.dearpygui as dpg
1010
from Sequence_Converter import SequenceConverter
11+
from Sequence_Converter import SequenceConverterSettings
1112

1213
class ConverterUI:
1314

@@ -21,6 +22,8 @@ class ConverterUI:
2122
srgb_check_ID = 0
2223
pointcloud_decimation_ID = 0
2324
decimation_percentage_ID = 0
25+
save_normals_ID = 0
26+
generate_normals_ID = 0
2427

2528
### +++++++++++++++++++++++++ PACKAGE INTO SINGLE EXECUTABLE ++++++++++++++++++++++++++++++++++
2629
#Use this prompt in the terminal to package this script into a single executable for your system
@@ -48,7 +51,11 @@ class ConverterUI:
4851
generateASTC = True
4952
convertToSRGB = False
5053
decimatePointcloud = False
54+
generateNormals = False
55+
save_normals = False
5156
decimatePercentage = 100
57+
mergePoints = False
58+
mergeDistance = 0.001
5259

5360
validModelTypes = ["obj", "3ds", "fbx", "glb", "gltf", "obj", "ply", "ptx", "stl", "xyz", "pts"]
5461
validImageTypes = ["jpg", "jpeg", "png", "bmp", "tga"]
@@ -95,6 +102,24 @@ def set_Decimation_percentage_cb(self, sender, app_data):
95102
self.decimatePercentage = app_data
96103
self.write_settings_string("decimatePercentage", str(app_data))
97104

105+
def set_Generate_Normals_enabled_cb(self, sender, app_data):
106+
self.generateNormals = app_data
107+
self.save_normals = app_data
108+
dpg.set_value(self.save_normals_ID, app_data)
109+
self.write_settings_string("generateNormals", str(app_data))
110+
111+
def set_normals_enabled_cb(self, sender, app_data):
112+
self.save_normals = app_data
113+
self.write_settings_string("saveNormals", str(app_data))
114+
115+
def set_Merge_Points_cb(self, sender, app_data):
116+
self.mergePoints = app_data
117+
self.write_settings_string("mergePoints", str(app_data))
118+
119+
def set_Merge_Distance_cb(self, sender, app_data):
120+
self.mergeDistance = app_data
121+
self.write_settings_string("mergeDistance", str(app_data))
122+
98123
def start_conversion_cb(self):
99124

100125
if(self.isRunning):
@@ -121,7 +146,25 @@ def start_conversion_cb(self):
121146
if(self.generateASTC or self.generateDDS):
122147
self.totalFileCount += len(self.imagePathList)
123148
self.processedFileCount = 0
124-
self.converter.start_conversion(self.modelPathList, self.imagePathList, self.inputSequencePath, self.get_output_path(), self.resourcesPath, self.single_conversion_finished_cb, dpg.get_value(self.thread_count_ID), self.generateDDS, self.generateASTC, self.convertToSRGB, self.decimatePointcloud, self.decimatePercentage)
149+
150+
convertSettings = SequenceConverterSettings()
151+
convertSettings.modelPaths = self.modelPathList
152+
convertSettings.imagePaths = self.imagePathList
153+
convertSettings.inputPath = self.inputSequencePath
154+
convertSettings.outputPath = self.get_output_path()
155+
convertSettings.resourcePath = self.resourcesPath
156+
convertSettings.maxThreads = dpg.get_value(self.thread_count_ID)
157+
convertSettings.convertToDDS = self.generateDDS
158+
convertSettings.convertToASTC = self.generateASTC
159+
convertSettings.convertToSRGB = self.convertToSRGB
160+
convertSettings.decimatePointcloud = self.decimatePointcloud
161+
convertSettings.decimatePercentage = self.decimatePercentage
162+
convertSettings.saveNormals = self.save_normals
163+
convertSettings.generateNormals = self.generateNormals
164+
convertSettings.mergePoints = self.mergePoints
165+
convertSettings.mergeDistance = self.mergeDistance
166+
167+
self.converter.start_conversion(convertSettings, self.single_conversion_finished_cb)
125168

126169
self.info_text_set("Converting...")
127170
self.set_progressbar(0)
@@ -255,6 +298,10 @@ def load_config(self):
255298
self.config['Settings']['ASTC'] = "true"
256299
self.config['Settings']['decimatePointcloud'] = "false"
257300
self.config['Settings']['decimatePercentage'] = "100"
301+
self.config['Settings']['saveNormals'] = "false"
302+
self.config['Settings']['generateNormals'] = "false"
303+
self.config['Settings']['mergePoints'] = "false"
304+
self.config['Settings']['mergeDistance'] = "0.001"
258305
self.save_config()
259306

260307
self.config.read(self.configPath)
@@ -356,9 +403,24 @@ def output_path_label_set(self, output_path):
356403
def set_SRGB_enabled(self, enabled):
357404
dpg.set_value(self.srgb_check_ID, enabled)
358405

406+
def set_viewport_height(self, pointcloud_settings, texture_settings):
407+
default_viewport_height = 450
408+
pointcloud_settings_height = 70
409+
textures_settings_height = 70
410+
411+
height = default_viewport_height
412+
if(pointcloud_settings):
413+
height += pointcloud_settings_height
414+
if(texture_settings):
415+
height += textures_settings_height
416+
417+
dpg.set_viewport_height(height)
418+
359419

360420
def RunUI(self):
361421

422+
dpg.create_context()
423+
362424
self.InitDefaultPaths()
363425
self.config = configparser.ConfigParser()
364426
self.load_config()
@@ -367,58 +429,83 @@ def RunUI(self):
367429
self.decimatePointcloud = self.read_config_bool("decimatePointcloud")
368430
self.decimatePercentage = int(self.read_settings_string("decimatePercentage"))
369431

370-
dpg.create_context()
371432
dpg.configure_app(manual_callback_management=True)
372-
dpg.create_viewport(height=480, width=500, title="Geometry Sequence Converter")
433+
dpg.create_viewport(height=500, width=500, title="Geometry Sequence Converter")
373434
dpg.setup_dearpygui()
374-
435+
375436
with dpg.window(label="Geometry Sequence Converter", tag="main_window", min_size= [500, 500]):
376-
437+
377438
dpg.add_button(label="Select Input Directory", callback=lambda:self.open_input_dir_cb())
378439
self.text_input_Dir_ID = dpg.add_text(self.inputSequencePath, wrap=450)
440+
379441
dpg.add_spacer(height=40)
380442

381443
dpg.add_button(label="Select Output Directory", callback=lambda:self.open_output_dir_cb())
382444
self.text_output_Dir_ID = dpg.add_text(self.outputSequencePath, wrap=450)
383445

384446
dpg.add_spacer(height=30)
385447

386-
dpg.add_checkbox(label="Generate textures for desktop devices (DDS)", default_value=self.generateDDS, callback=self.set_DDS_enabled_cb)
387-
dpg.add_checkbox(label="Generate textures mobile devices (ASTC)", default_value=self.generateASTC, callback=self.set_ASTC_enabled_cb)
388-
self.srgb_check_ID = dpg.add_checkbox(label="Convert to SRGB profile", default_value=self.convertToSRGB, callback=self.set_SRGB_enabled_cb)
448+
dpg.add_text("General settings:")
449+
self.save_normals_ID = dpg.add_checkbox(label="Save normals", default_value=self.save_normals, callback=self.set_normals_enabled_cb)
450+
451+
dpg.add_spacer(height=5)
389452

453+
with dpg.collapsing_header(label="Pointcloud settings", default_open=False) as header_pcSettings_ID:
454+
455+
with dpg.group(horizontal=True):
456+
self.pointcloud_decimation_ID = dpg.add_checkbox(label="Decimate Pointcloud", default_value=self.decimatePointcloud, callback=self.set_Decimation_enabled_cb)
457+
self.decimation_percentage_ID = dpg.add_input_int(label=" %", default_value=self.decimatePercentage, min_value=0, max_value=100, width=80, callback=self.set_Decimation_percentage_cb)
458+
459+
with dpg.group(horizontal=True):
460+
self.pointcloud_merge_ID = dpg.add_checkbox(label= "Merge Points by Distance: ", default_value=self.mergePoints, callback=self.set_Merge_Points_cb)
461+
self.merge_distance_ID = dpg.add_input_float(label= " ", default_value=self.mergeDistance , callback=self.set_Merge_Distance_cb, min_value=0, width= 200)
462+
463+
self.generate_normals_ID = dpg.add_checkbox(label= "Estimate normals", default_value=self.generateNormals, callback=self.set_Generate_Normals_enabled_cb)
464+
390465
dpg.add_spacer(height=5)
391466

392-
self.pointcloud_decimation_ID = dpg.add_checkbox(label="Decimate Pointcloud", default_value=self.decimatePointcloud, callback=self.set_Decimation_enabled_cb)
393-
dpg.add_same_line()
394-
self.decimation_percentage_ID = dpg.add_input_int(label=" %", default_value=self.decimatePercentage, min_value=0, max_value=100, width=80, callback=self.set_Decimation_percentage_cb)
467+
with dpg.collapsing_header(label="Texture settings", default_open=False) as header_textureSettings_ID:
468+
dpg.add_checkbox(label="Generate textures for desktop devices (DDS)", default_value=self.generateDDS, callback=self.set_DDS_enabled_cb)
469+
dpg.add_checkbox(label="Generate textures mobile devices (ASTC)", default_value=self.generateASTC, callback=self.set_ASTC_enabled_cb)
470+
self.srgb_check_ID = dpg.add_checkbox(label="Convert to SRGB profile", default_value=self.convertToSRGB, callback=self.set_SRGB_enabled_cb)
395471

396472
self.text_error_log_ID = dpg.add_text("", color=[255, 0, 0], wrap=450)
397473
self.text_info_log_ID = dpg.add_text("", color=[255, 255, 255], wrap=450)
398-
474+
399475
self.progress_bar_ID = dpg.add_progress_bar(default_value=0, width=470)
400476
dpg.add_spacer(height=5)
401-
dpg.add_button(label="Start Conversion", callback=lambda:self.start_conversion_cb())
402-
dpg.add_same_line()
403-
dpg.add_button(label="Cancel", callback=lambda:self.cancel_processing_cb())
404-
dpg.add_same_line()
405-
self.thread_count_ID = dpg.add_input_int(label="Thread count", default_value=8, min_value=0, max_value=64, width=100, tag="threadCount")
406477

478+
with dpg.group(horizontal=True):
479+
dpg.add_button(label="Start Conversion", callback=lambda:self.start_conversion_cb())
480+
dpg.add_button(label="Cancel", callback=lambda:self.cancel_processing_cb())
481+
self.thread_count_ID = dpg.add_input_int(label="Thread count", default_value=8, min_value=0, max_value=64, width=100, tag="threadCount")
407482

408483
dpg.show_viewport()
409484
dpg.set_primary_window("main_window", True)
485+
self.set_viewport_height(False, False)
410486

411487
self.set_input_files(self.read_path_string("input"))
412488

489+
pointcloud_header_open = False
490+
texture_header_open = False
491+
413492
while dpg.is_dearpygui_running():
414493
dpg.render_dearpygui_frame()
415494
jobs = dpg.get_callback_queue()
416495
dpg.run_callbacks(jobs)
496+
497+
if(dpg.is_item_left_clicked(header_pcSettings_ID)):
498+
pointcloud_header_open = not pointcloud_header_open
499+
self.set_viewport_height(pointcloud_header_open, texture_header_open)
500+
501+
if(dpg.is_item_left_clicked(header_textureSettings_ID)):
502+
texture_header_open = not texture_header_open
503+
self.set_viewport_height(pointcloud_header_open, texture_header_open)
417504

418505
if(self.conversionFinished):
419506
self.finish_conversion()
420507
self.conversionFinished = False
421-
508+
422509
# Shutdown threads when they are still running
423510
self.cancel_processing_cb()
424511
self.save_config()

Converter/Sequence_Metadata.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ class MetaData():
1818
DDS = False
1919
ASTC = False
2020
hasUVs = False
21+
hasNormals = False
2122
maxVertexCount = 0
2223
maxIndiceCount = 0
23-
maxBounds = [0,0,0,0,0,0]
24+
minMaxBounds = [0,0,0,0,0,0]
2425
textureWidth = 0
2526
textureHeight = 0
2627
textureSizeDDS = 0
@@ -40,9 +41,10 @@ def get_as_dict(self):
4041
"DDS" : self.DDS,
4142
"ASTC" : self.ASTC,
4243
"hasUVs" : self.hasUVs,
44+
"hasNormals" : self.hasNormals,
4345
"maxVertexCount": self.maxVertexCount,
4446
"maxIndiceCount" : self.maxIndiceCount,
45-
"maxBounds" : self.maxBounds,
47+
"maxBounds" : self.minMaxBounds,
4648
"textureWidth" : self.textureWidth,
4749
"textureHeight" : self.textureHeight,
4850
"textureSizeDDS" : self.textureSizeDDS,
@@ -54,12 +56,13 @@ def get_as_dict(self):
5456

5557
return asDict
5658

57-
def set_metadata_Model(self, vertexCount, indiceCount, headerSize, bounds, geometryType, hasUV, listIndex):
59+
def set_metadata_Model(self, vertexCount, indiceCount, headerSize, bounds, geometryType, hasUV, hasNormals, listIndex):
5860

5961
self.metaDataLock.acquire()
6062

6163
self.geometryType = geometryType
6264
self.hasUVs = hasUV
65+
self.hasNormals = hasNormals
6366

6467
if(vertexCount > self.maxVertexCount):
6568
self.maxVertexCount = vertexCount
@@ -68,12 +71,16 @@ def set_metadata_Model(self, vertexCount, indiceCount, headerSize, bounds, geome
6871
self.maxIndiceCount = indiceCount
6972

7073
for maxBound in range(3):
71-
if self.maxBounds[maxBound] < bounds.max()[maxBound]:
72-
self.maxBounds[maxBound] = bounds.max()[maxBound]
74+
if abs(self.minMaxBounds[maxBound]) < abs(bounds.max()[maxBound]):
75+
self.minMaxBounds[maxBound] = bounds.max()[maxBound]
7376

7477
for minBound in range(3):
75-
if self.maxBounds[minBound + 3] > bounds.min()[minBound]:
76-
self.maxBounds[minBound + 3] = bounds.min()[minBound]
78+
if abs(self.minMaxBounds[minBound + 3]) < abs(bounds.min()[minBound]):
79+
self.minMaxBounds[minBound + 3] = bounds.min()[minBound]
80+
81+
# Flip bounds x axis, as we also flip the model's x axis to match Unity's coordinate system
82+
self.minMaxBounds[0] *= -1 # Min X
83+
self.minMaxBounds[3] *= -1 # Max X
7784

7885
self.headerSizes[listIndex] = headerSize
7986
self.verticeCounts[listIndex] = vertexCount

0 commit comments

Comments
 (0)