diff options
Diffstat (limited to 'io_scene_gltf2')
5 files changed, 52 insertions, 29 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_extract.py b/io_scene_gltf2/blender/exp/gltf2_blender_extract.py index 87c9d426..0add794a 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_extract.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_extract.py @@ -662,12 +662,16 @@ def extract_primitives(glTF, blender_mesh, blender_vertex_groups, modifiers, exp # - vertex_group_index = group_element.group - vertex_group_name = blender_vertex_groups[vertex_group_index].name + joint_weight = group_element.weight + if joint_weight <= 0.0: + continue # - joint_index = 0 + vertex_group_index = group_element.group + vertex_group_name = blender_vertex_groups[vertex_group_index].name + + joint_index = None if modifiers is not None: modifiers_dict = {m.type: m for m in modifiers} @@ -677,12 +681,12 @@ def extract_primitives(glTF, blender_mesh, blender_vertex_groups, modifiers, exp for index, j in enumerate(skin.joints): if j.name == vertex_group_name: joint_index = index - - joint_weight = group_element.weight + break # - joint.append(joint_index) - weight.append(joint_weight) + if joint_index is not None: + joint.append(joint_index) + weight.append(joint_weight) if len(joint) > 0: bone_count += 1 diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather.py index 217930e1..6a5a9947 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather.py @@ -32,7 +32,8 @@ def gather_gltf2(export_settings): animations = [] # unfortunately animations in gltf2 are just as 'root' as scenes. for blender_scene in bpy.data.scenes: scenes.append(__gather_scene(blender_scene, export_settings)) - animations += __gather_animations(blender_scene, export_settings) + if export_settings[gltf2_blender_export_keys.ANIMATIONS]: + animations += __gather_animations(blender_scene, export_settings) return scenes, animations diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py index b6131a59..a694cac3 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py @@ -115,20 +115,35 @@ def __get_image_data(sockets_or_slots, export_settings): image = None for result, socket in zip(results, sockets_or_slots): # rudimentarily try follow the node tree to find the correct image data. - channel = None + source_channel = None + target_channel = None + source_channels_length = None for elem in result.path: if isinstance(elem.from_node, bpy.types.ShaderNodeSeparateRGB): - channel = { + source_channel = { 'R': 0, 'G': 1, 'B': 2 }[elem.from_socket.name] - if channel is not None: - pixels = [split_pixels_by_channels(result.shader_node.image, export_settings)[channel]] + if source_channel is not None: + pixels = [split_pixels_by_channels(result.shader_node.image, export_settings)[source_channel]] + target_channel = source_channel + source_channel = 0 + source_channels_length = 1 else: pixels = split_pixels_by_channels(result.shader_node.image, export_settings) - channel = 0 + target_channel = 0 + source_channel = 0 + source_channels_length = len(pixels) + + # Change target channel for metallic and roughness. + if elem.to_socket.name == 'Metallic': + target_channel = 2 + source_channels_length = 1 + elif elem.to_socket.name == 'Roughness': + target_channel = 1 + source_channels_length = 1 file_name = os.path.splitext(result.shader_node.image.name)[0] @@ -137,13 +152,15 @@ def __get_image_data(sockets_or_slots, export_settings): result.shader_node.image.filepath, result.shader_node.image.size[0], result.shader_node.image.size[1], - channel, + source_channel, + target_channel, + source_channels_length, pixels) if image is None: image = image_data else: - image.add_to_image(channel, image_data) + image.add_to_image(target_channel, image_data) return image elif __is_slot(sockets_or_slots): @@ -156,6 +173,8 @@ def __get_image_data(sockets_or_slots, export_settings): texture.image.size[0], texture.image.size[1], 0, + 0, + len(pixels), pixels) return image_data else: diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py index 4fa025b2..23d51fa6 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py @@ -73,9 +73,7 @@ def __gather_indices(blender_primitive, blender_mesh, modifiers, export_settings indices = blender_primitive['indices'] max_index = max(indices) - if max_index < (1 << 8): - component_type = gltf2_io_constants.ComponentType.UnsignedByte - elif max_index < (1 << 16): + if max_index < (1 << 16): component_type = gltf2_io_constants.ComponentType.UnsignedShort elif max_index < (1 << 32): component_type = gltf2_io_constants.ComponentType.UnsignedInt diff --git a/io_scene_gltf2/io/exp/gltf2_io_image_data.py b/io_scene_gltf2/io/exp/gltf2_io_image_data.py index 92bdd09f..fb6ecb2a 100755 --- a/io_scene_gltf2/io/exp/gltf2_io_image_data.py +++ b/io_scene_gltf2/io/exp/gltf2_io_image_data.py @@ -24,34 +24,35 @@ class ImageData: # FUTURE_WORK: as a method to allow the node graph to be better supported, we could model some of # the node graph elements with numpy functions - def __init__(self, name: str, filepath: str, width: int, height: int, offset: int, channels: typing.Optional[typing.List[np.ndarray]] = []): + def __init__(self, name: str, filepath: str, width: int, height: int, source: int, target: int, source_length: int, channels: typing.Optional[typing.List[np.ndarray]] = []): if width <= 0 or height <= 0: raise ValueError("Image data can not have zero width or height") - if offset + len(channels) > 4: - raise ValueError("Image data can not have more than 4 channels") + if source + source_length > 4: + raise ValueError("Source image data can not have more than 4 channels") + if target + source_length > 4: + raise ValueError("Target image data can not have more than 4 channels") self.channels = [None, None, None, None] - channels_length = len(channels) - for index in range(offset, offset + channels_length): - self.channels[index] = channels[index - offset] + for index in range(source, source + source_length): + self.channels[target + index - source] = channels[index] self.name = name self.filepath = filepath self.width = width self.height = height - def add_to_image(self, channel, image_data): + def add_to_image(self, target: int, image_data): if self.width != image_data.width or self.height != image_data.height: raise ValueError("Image dimensions do not match") - if channel < 0 or channel > 3: - raise ValueError("Can't append image: channels out of bounds") + if target < 0 or target > 3: + raise ValueError("Can't insert image: channels out of bounds") if len(image_data.channels) != 4: - raise ValueError("Can't append image: incomplete image") + raise ValueError("Can't insert image: incomplete image") if self.name != image_data.name: self.name += image_data.name self.filepath = "" # Replace channel. - self.channels[channel] = image_data.channels[channel] + self.channels[target] = image_data.channels[target] @property def r(self): |