Skip to content

Commit d45a14f

Browse files
Merge pull request #2065 from KhronosGroup/fix_2063_vc_without_material
Fix #2063 export VC without material
2 parents 230985d + 24473ec commit d45a14f

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives_extract.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,15 @@ def manage_material_info(self):
456456
vc_color_name = material_info['vc_info']['color']
457457
elif material_info['vc_info']['color_type'] == "active":
458458
# Get active (render) Vertex Color
459-
vc_color_name = self.blender_mesh.color_attributes[self.blender_mesh.color_attributes.render_color_index].name
459+
if self.blender_mesh.color_attributes.render_color_index != -1:
460+
vc_color_name = self.blender_mesh.color_attributes[self.blender_mesh.color_attributes.render_color_index].name
460461

461462
if material_info['vc_info']['alpha_type'] == "name":
462463
vc_alpha_name = material_info['vc_info']['alpha']
463464
elif material_info['vc_info']['alpha_type'] == "active":
464465
# Get active (render) Vertex Color
465-
vc_alpha_name = self.blender_mesh.color_attributes[self.blender_mesh.color_attributes.render_color_index].name
466+
if self.blender_mesh.color_attributes.render_color_index != -1:
467+
vc_alpha_name = self.blender_mesh.color_attributes[self.blender_mesh.color_attributes.render_color_index].name
466468

467469
if vc_color_name is not None:
468470

@@ -482,7 +484,7 @@ def manage_material_info(self):
482484
# We need to check if we need to add alpha
483485
add_alpha = vc_alpha_name is not None
484486
mat = get_material_from_idx(material_idx, self.materials, self.export_settings)
485-
add_alpha = add_alpha and not (mat.blend_method is None or mat.blend_method == 'OPAQUE')
487+
add_alpha = mat is not None and add_alpha and not (mat.blend_method is None or mat.blend_method == 'OPAQUE')
486488
# Manage Vertex Color (RGB and Alpha if needed)
487489
self.__manage_color_attribute(vc_color_name, vc_alpha_name if add_alpha else None)
488490
else:
@@ -960,6 +962,33 @@ def __manage_color_attribute(self, attr_name, attr_name_alpha):
960962
# Must calculate the type of the field : FLOAT_COLOR or BYTE_COLOR
961963
additional_fields.append(('COLOR_0' + str(i), gltf2_blender_conversion.get_numpy_type('FLOAT_COLOR' if max_index == 3 else 'BYTE_COLOR')))
962964

965+
966+
if self.export_settings['gltf_loose_edges']:
967+
additional_fields_edges = []
968+
for i in range(max_index):
969+
# Must calculate the type of the field : FLOAT_COLOR or BYTE_COLOR
970+
additional_fields_edges.append(('COLOR_0' + str(i), gltf2_blender_conversion.get_numpy_type('FLOAT_COLOR' if max_index == 3 else 'BYTE_COLOR')))
971+
972+
new_dt = np.dtype(self.dots_edges.dtype.descr + additional_fields_edges)
973+
dots_edges = np.zeros(self.dots_edges.shape, dtype=new_dt)
974+
for f in self.dots_edges.dtype.names:
975+
dots_edges[f] = self.dots_edges[f]
976+
977+
self.dots_edges = dots_edges
978+
979+
if self.export_settings['gltf_loose_points']:
980+
additional_fields_points = []
981+
for i in range(max_index):
982+
# Must calculate the type of the field : FLOAT_COLOR or BYTE_COLOR
983+
additional_fields_points.append(('COLOR_0' + str(i), gltf2_blender_conversion.get_numpy_type('FLOAT_COLOR' if max_index == 3 else 'BYTE_COLOR')))
984+
985+
new_dt = np.dtype(self.dots_points.dtype.descr + additional_fields_points)
986+
dots_points = np.zeros(self.dots_points.shape, dtype=new_dt)
987+
for f in self.dots_points.dtype.names:
988+
dots_points[f] = self.dots_points[f]
989+
990+
self.dots_points = dots_points
991+
963992
# Keep the existing custom attribute
964993
# Data will be exported twice, one for COLOR_O, one for the custom attribute
965994
new_dt = np.dtype(self.dots.dtype.descr + additional_fields)
@@ -974,7 +1003,7 @@ def __manage_color_attribute(self, attr_name, attr_name_alpha):
9741003
self.dots['COLOR_0' +str(i)] = data_dots[:, i]
9751004
if self.export_settings['gltf_loose_edges'] and attr.domain == "POINT":
9761005
self.dots_edges['COLOR_0' + str(i)] = data_dots_edges[:, i]
977-
if self.export_settings['gltf_loose_points'] and attr['blender_domain'] == "POINT":
1006+
if self.export_settings['gltf_loose_points'] and attr.domain == "POINT":
9781007
self.dots_points['COLOR_0' + str(i)] = data_dots_points[:, i]
9791008

9801009
# Add COLOR_0 in attribute list

addons/io_scene_gltf2/blender/exp/material/gltf2_blender_gather_materials.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,12 @@ def get_base_material(material_idx, materials, export_settings):
555555
mat,
556556
export_settings
557557
)
558+
559+
if material is None:
560+
# If no material, the mesh can still have vertex color
561+
# So, retrieving it
562+
material_info["vc_info"] = {"color_type": "active", "alpha_type": "active"}
563+
558564
return material, material_info
559565

560566
def get_all_textures(idx=0):

0 commit comments

Comments
 (0)