Skip to content

Commit 7a843ac

Browse files
Merge pull request #9 from mattedicksoncom/dev
UI and ease of use updates
2 parents cf24af6 + 9a071a0 commit 7a843ac

File tree

2 files changed

+178
-23
lines changed

2 files changed

+178
-23
lines changed

addons/blender_xatlas/__init__.py

Lines changed: 157 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"author": "mattedickson",
1919
"wiki_url": "https://github.com/mattedicksoncom/blender-xatlas/",
2020
"tracker_url": "https://github.com/mattedicksoncom/blender-xatlas/issues",
21-
"version": (0, 0, 4),
21+
"version": (0, 0, 5),
2222
"blender": (2, 83, 0),
2323
"location": "3D View > Toolbox",
2424
"category": "Object",
@@ -196,14 +196,14 @@ class PG_ChartProperties (PropertyGroup):
196196

197197

198198
def get_collectionNames(self, context):
199-
colllectionNames = [];
199+
colllectionNames = []
200200
for collection in bpy.data.collections:
201201
colllectionNames.append((collection.name, collection.name, ""))
202-
return colllectionNames;
202+
return colllectionNames
203203

204204
class PG_SharedProperties (PropertyGroup):
205205

206-
unwrapSelection = EnumProperty(
206+
unwrapSelection : EnumProperty(
207207
name="",
208208
description="Which Objects to unwrap",
209209
items=[ ('SELECTED', "Selection", ""),
@@ -212,26 +212,64 @@ class PG_SharedProperties (PropertyGroup):
212212
]
213213
)
214214

215-
atlasLayout = EnumProperty(
215+
atlasLayout : EnumProperty(
216216
name="",
217217
description="How to Layout the atlases",
218218
items=[ ('OVERLAP', "Overlap", "Overlap all the atlases"),
219-
('SPREADX', "Spread x", "Seperate each atlas along the x-axis"),
219+
('SPREADX', "Spread X", "Seperate each atlas along the x-axis"),
220220
]
221221
)
222222

223-
selectedCollection = EnumProperty(
223+
selectedCollection : EnumProperty(
224224
name="",
225225
items = get_collectionNames
226-
)
226+
)
227227

228228
mainUVIndex : IntProperty(
229-
name = "Main UV Index",
229+
name = "",
230230
description="The index of the primary none lightmap uv",
231231
default = 0,
232232
min = 0,
233233
max = 1000
234-
)
234+
)
235+
236+
lightmapUVIndex : IntProperty(
237+
name = "",
238+
description="The index of the lightmap uv",
239+
default = 0,
240+
min = 0,
241+
max = 1000
242+
)
243+
244+
245+
mainUVChoiceType : EnumProperty(
246+
name="",
247+
description="The method to obtain the main UV",
248+
items=[ ('NAME', "By Name", ""),
249+
('INDEX', "By Index", ""),
250+
]
251+
)
252+
253+
mainUVName : StringProperty(
254+
name = "",
255+
description="The name of the main (non-lightmap) UV",
256+
default = "UVMap",
257+
)
258+
259+
260+
lightmapUVChoiceType : EnumProperty(
261+
name="",
262+
description="The method to obtain the lightmap UV",
263+
items=[ ('NAME', "By Name", ""),
264+
('INDEX', "By Index", ""),
265+
]
266+
)
267+
268+
lightmapUVName : StringProperty(
269+
name = "",
270+
description="The name of the lightmap UV (If it doesn't exist it will be created)",
271+
default = "UVMap_Lightmap",
272+
)
235273

236274

237275
# end PropertyGroups---------------------------
@@ -325,12 +363,21 @@ def execute(self, context):
325363
if obj.data.users > 1:
326364
obj.data = obj.data.copy() #make single user copy
327365
uv_layers = obj.data.uv_layers
328-
if not "UVMap_Lightmap" in uv_layers:
329-
uvmap = uv_layers.new(name="UVMap_Lightmap")
366+
367+
#setup the lightmap uvs
368+
uvName = "UVMap_Lightmap"
369+
if sharedProperties.lightmapUVChoiceType == "NAME":
370+
uvName = sharedProperties.lightmapUVName
371+
elif sharedProperties.lightmapUVChoiceType == "INDEX":
372+
if sharedProperties.lightmapUVIndex < len(uv_layers):
373+
uvName = uv_layers[sharedProperties.lightmapUVIndex].name
374+
375+
if not uvName in uv_layers:
376+
uvmap = uv_layers.new(name=uvName)
330377
uv_layers.active_index = len(uv_layers) - 1
331378
else:
332379
for i in range(0, len(uv_layers)):
333-
if uv_layers[i].name == 'UVMap_Lightmap':
380+
if uv_layers[i].name == uvName:
334381
uv_layers.active_index = i
335382
obj.select_set(True)
336383

@@ -347,7 +394,9 @@ def execute(self, context):
347394
export_obj_simple.save(
348395
context=bpy.context,
349396
filepath=fakeFile,
397+
mainUVChoiceType=sharedProperties.mainUVChoiceType,
350398
uvIndex=sharedProperties.mainUVIndex,
399+
uvName=sharedProperties.mainUVName,
351400
use_selection=True,
352401
use_animation=False,
353402
use_mesh_modifiers=True,
@@ -563,7 +612,28 @@ class OBJECT_PT_xatlas_panel (Panel):
563612
bl_label = "Xatlas Tools"
564613
bl_space_type = "VIEW_3D"
565614
bl_region_type = "UI"
566-
bl_category = "Tool"
615+
bl_category = "Xatlas"
616+
bl_context = ""
617+
618+
@classmethod
619+
def poll(self,context):
620+
return context.object is not None
621+
622+
def draw(self, context):
623+
layout = self.layout
624+
scene = context.scene
625+
packtool = scene.pack_tool
626+
mytool = scene.chart_tool
627+
628+
629+
630+
class OBJECT_PT_pack_panel (Panel):
631+
bl_idname = "OBJECT_PT_pack_panel"
632+
bl_label = "Pack Options"
633+
bl_space_type = "VIEW_3D"
634+
bl_region_type = "UI"
635+
bl_category = "Xatlas"
636+
bl_parent_id = 'OBJECT_PT_xatlas_panel'
567637
bl_context = ""
568638

569639
@classmethod
@@ -578,25 +648,88 @@ def draw(self, context):
578648

579649
#add the pack options
580650
box = layout.box()
581-
label = box.label(text="Pack Options")
651+
# label = box.label(text="Pack Options")
582652
for tool in packtool.__annotations__.keys():
583653
box.prop( packtool, tool)
584654

655+
class OBJECT_PT_chart_panel (Panel):
656+
bl_idname = "OBJECT_PT_chart_panel"
657+
bl_label = "Chart Options"
658+
bl_space_type = "VIEW_3D"
659+
bl_region_type = "UI"
660+
bl_category = "Xatlas"
661+
bl_parent_id = 'OBJECT_PT_xatlas_panel'
662+
bl_context = ""
663+
664+
@classmethod
665+
def poll(self,context):
666+
return context.object is not None
667+
668+
def draw(self, context):
669+
layout = self.layout
670+
scene = context.scene
671+
packtool = scene.pack_tool
672+
mytool = scene.chart_tool
673+
585674
#add the chart options
586675
box = layout.box()
587-
label = box.label(text="Chart Options")
588676
for tool in mytool.__annotations__.keys():
589677
box.prop( mytool, tool)
590678

679+
class OBJECT_PT_run_panel (Panel):
680+
bl_idname = "OBJECT_PT_run_panel"
681+
bl_label = "Run Xatlas"
682+
bl_space_type = "VIEW_3D"
683+
bl_region_type = "UI"
684+
bl_category = "Xatlas"
685+
bl_parent_id = 'OBJECT_PT_xatlas_panel'
686+
bl_context = ""
687+
688+
@classmethod
689+
def poll(self,context):
690+
return context.object is not None
691+
692+
def draw(self, context):
693+
layout = self.layout
694+
scene = context.scene
695+
packtool = scene.pack_tool
696+
mytool = scene.chart_tool
697+
591698
box = layout.box()
592-
label = box.label(text="Run")
593-
box.prop( scene.shared_properties, 'unwrapSelection')
594-
box.prop( scene.shared_properties, 'mainUVIndex')
595-
box.prop( scene.shared_properties, 'atlasLayout')
699+
# label = box.label(text="Run")
700+
row = box.row()
701+
row.label(text="Unwrap")
702+
row.prop( scene.shared_properties, 'unwrapSelection')
596703
if scene.shared_properties.unwrapSelection == "COLLECTION":
597704
box.prop( scene.shared_properties, 'selectedCollection')
598-
box.operator("object.setup_unwrap", text="Run Xatlas")
599705

706+
box = layout.box()
707+
row = box.row()
708+
row.label(text="Lightmap UV")
709+
row.prop( scene.shared_properties, 'lightmapUVChoiceType')
710+
if scene.shared_properties.lightmapUVChoiceType == "NAME":
711+
box.prop( scene.shared_properties, 'lightmapUVName')
712+
elif scene.shared_properties.lightmapUVChoiceType == "INDEX":
713+
box.prop( scene.shared_properties, 'lightmapUVIndex')
714+
715+
box = layout.box()
716+
row = box.row()
717+
row.label(text="Main UV")
718+
row.prop( scene.shared_properties, 'mainUVChoiceType')
719+
if scene.shared_properties.mainUVChoiceType == "NAME":
720+
box.prop( scene.shared_properties, 'mainUVName')
721+
elif scene.shared_properties.mainUVChoiceType == "INDEX":
722+
box.prop( scene.shared_properties, 'mainUVIndex')
723+
# box.prop( scene.shared_properties, 'mainUVName')
724+
725+
# box.prop( scene.shared_properties, 'mainUVIndex')
726+
727+
box = layout.box()
728+
row = box.row()
729+
row.label(text="Atlas Layout")
730+
row.prop( scene.shared_properties, 'atlasLayout')
731+
732+
box.operator("object.setup_unwrap", text="Run Xatlas")
600733
# end panels------------------------------
601734

602735

@@ -612,6 +745,9 @@ def draw(self, context):
612745
Setup_Unwrap,
613746
Unwrap_Lightmap_Group_Xatlas_2,
614747
OBJECT_PT_xatlas_panel,
748+
OBJECT_PT_pack_panel,
749+
OBJECT_PT_chart_panel,
750+
OBJECT_PT_run_panel,
615751
)
616752

617753
def register():

addons/blender_xatlas/export_obj_simple.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def mesh_triangulate(me):
4949

5050

5151
def write_file(filepath, objects, scene,
52+
mainUVChoiceType,
5253
uvIndex,
54+
uvName,
5355
EXPORT_TRI=False,
5456
EXPORT_EDGES=False,
5557
EXPORT_SMOOTH_GROUPS=False,
@@ -153,8 +155,17 @@ def findVertexGroupName(face, vWeightMap):
153155
faceuv = len(me.uv_layers) > 0
154156
if faceuv:
155157
# uv_layer = me.uv_layers.active.data[:]
156-
if uvIndex < len(me.uv_layers):
157-
uv_layer = me.uv_layers[uvIndex].data[:]
158+
objUVindex = 0
159+
if mainUVChoiceType == "NAME":
160+
for i in range(0, len(me.uv_layers)):
161+
if me.uv_layers[i].name == uvName:
162+
objUVindex = i
163+
elif mainUVChoiceType == "INDEX":
164+
if uvIndex < len(me.uv_layers):
165+
objUVindex = uvIndex
166+
167+
if objUVindex < len(me.uv_layers):
168+
uv_layer = me.uv_layers[objUVindex].data[:]
158169
else:
159170
uv_layer = me.uv_layers[0].data[:]
160171
else:
@@ -400,7 +411,9 @@ def findVertexGroupName(face, vWeightMap):
400411
def _write(
401412
context,
402413
filepath,
414+
mainUVChoiceType,
403415
uvIndex,
416+
uvName,
404417
EXPORT_TRI, # ok
405418
EXPORT_EDGES,
406419
EXPORT_SMOOTH_GROUPS,
@@ -436,7 +449,9 @@ def _write(
436449
filepath,
437450
objects,
438451
scene,
452+
mainUVChoiceType,
439453
uvIndex,
454+
uvName,
440455
EXPORT_TRI,
441456
EXPORT_EDGES,
442457
EXPORT_SMOOTH_GROUPS,
@@ -466,7 +481,9 @@ def _write(
466481
def save(
467482
context,
468483
filepath,
484+
mainUVChoiceType,
469485
uvIndex,
486+
uvName,
470487
*,
471488
use_triangles=False,
472489
use_edges=True,
@@ -490,7 +507,9 @@ def save(
490507
):
491508

492509
_write(context,filepath,
510+
mainUVChoiceType,
493511
uvIndex,
512+
uvName,
494513
EXPORT_TRI=use_triangles,
495514
EXPORT_EDGES=use_edges,
496515
EXPORT_SMOOTH_GROUPS=use_smooth_groups,

0 commit comments

Comments
 (0)