Skip to content

Commit fad4ae4

Browse files
CoDEmanXCoDEmanX
CoDEmanX
authored and
CoDEmanX
committed
Added option to take vertex colors, turn them into grayscale values and export as alpha transparency. Needed to create custom models using flag waving shader.
1 parent c5a9b06 commit fad4ae4

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

blender_26/__init__.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
bl_info = {
3535
"name": "Blender-CoD - Add-On for Call of Duty modding (alpha 3)",
3636
"author": "CoDEmanX, Flybynyt",
37-
"version": (0, 3, 4),
37+
"version": (0, 3, 5),
3838
"blender": (2, 62, 3),
3939
"location": "File > Import | File > Export",
4040
"description": "Export models to *.XMODEL_EXPORT and animations to *.XANIM_EXPORT",
@@ -159,6 +159,12 @@ class ExportXmodel(bpy.types.Operator, ExportHelper):
159159
default=True
160160
)
161161

162+
use_vertex_colors_alpha = BoolProperty(
163+
name="As alpha",
164+
description="Turn RGB vertex colors into grayscale (average value) and use it as alpha transparency. White is 1 (opaque), black 0 (invisible)",
165+
default=False
166+
)
167+
162168
use_apply_modifiers = BoolProperty(
163169
name="Apply Modifiers",
164170
description="Apply all mesh modifiers except Armature (preview resolution)",
@@ -251,10 +257,6 @@ def draw(self, context):
251257
col.prop(self, "use_selection", "Selection only (%i meshes)" % meshes_selected)
252258
col.enabled = bool(meshes_selected)
253259

254-
col = layout.column(align=True)
255-
col.active = self.use_version == '6'
256-
col.prop(self, "use_vertex_colors")
257-
258260
col = layout.column(align=True)
259261
col.prop(self, "use_apply_modifiers")
260262

@@ -265,6 +267,15 @@ def draw(self, context):
265267
else:
266268
col.prop(self, "use_armature")
267269

270+
if self.use_version == '6':
271+
272+
row = layout.row(align=True)
273+
row.prop(self, "use_vertex_colors")
274+
275+
sub = row.split()
276+
sub.active = self.use_vertex_colors
277+
sub.prop(self, "use_vertex_colors_alpha")
278+
268279
col = layout.column(align=True)
269280
col.label("Advanced:")
270281

blender_26/export_xmodel.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
def save(self, context, filepath="",
3636
use_version='6',
3737
use_selection=False,
38-
use_vertex_colors=True,
3938
use_apply_modifiers=True,
4039
use_armature=True,
40+
use_vertex_colors=True,
41+
use_vertex_colors_alpha=False,
4142
use_vertex_cleanup=False,
4243
use_armature_pose=False,
4344
use_frame_start=1,
@@ -77,9 +78,10 @@ def save(self, context, filepath="",
7778
result = _write(self, context, filepath,
7879
use_version,
7980
use_selection,
80-
use_vertex_colors,
8181
use_apply_modifiers,
8282
use_armature,
83+
use_vertex_colors,
84+
use_vertex_colors_alpha,
8385
use_vertex_cleanup,
8486
use_armature_pose,
8587
use_weight_min,
@@ -117,9 +119,10 @@ def save(self, context, filepath="",
117119
result = _write(self, context, filepath_frame,
118120
use_version,
119121
use_selection,
120-
use_vertex_colors,
121122
use_apply_modifiers,
122123
use_armature,
124+
use_vertex_colors,
125+
use_vertex_colors_alpha,
123126
use_vertex_cleanup,
124127
use_armature_pose,
125128
use_weight_min,
@@ -143,9 +146,10 @@ def save(self, context, filepath="",
143146
def _write(self, context, filepath,
144147
use_version,
145148
use_selection,
146-
use_vertex_colors,
147149
use_apply_modifiers,
148150
use_armature,
151+
use_vertex_colors,
152+
use_vertex_colors_alpha,
149153
use_vertex_cleanup,
150154
use_armature_pose,
151155
use_weight_min,
@@ -568,7 +572,14 @@ def _write(self, context, filepath,
568572
else:
569573
c = col.color4
570574

571-
file.write("COLOR %.6f %.6f %.6f 1.000000\n" % (c[0], c[1], c[2]))
575+
if use_vertex_colors_alpha:
576+
577+
# Turn RGB into grayscale by calculating average value
578+
file.write("COLOR 1.000000 1.000000 1.000000 %.6f\n" % ((c[0] + c[1] + c[2]) / 3))
579+
580+
else:
581+
file.write("COLOR %.6f %.6f %.6f 1.000000\n" % (c[0], c[1], c[2]))
582+
572583
else:
573584
file.write("COLOR 1.000000 1.000000 1.000000 1.000000\n")
574585

0 commit comments

Comments
 (0)