Compare commits
No commits in common. "2b60f0d2a6cabe0c07e297faeb98725d3bb86e23" and "d1d83d39affc7aff00902d839872baf3f3cc37aa" have entirely different histories.
2b60f0d2a6
...
d1d83d39af
@ -1,7 +1,7 @@
|
|||||||
bl_info = {
|
bl_info = {
|
||||||
'name': 'SWBF .msh Import-Export',
|
'name': 'SWBF .msh Import-Export',
|
||||||
'author': 'Will Snyder, PrismaticFlower',
|
'author': 'Will Snyder, SleepKiller',
|
||||||
"version": (1, 3, 0),
|
"version": (1, 2, 1),
|
||||||
'blender': (2, 80, 0),
|
'blender': (2, 80, 0),
|
||||||
'location': 'File > Import-Export',
|
'location': 'File > Import-Export',
|
||||||
'description': 'Export as SWBF .msh file',
|
'description': 'Export as SWBF .msh file',
|
||||||
|
@ -40,7 +40,6 @@ def model_to_mesh_object(model: Model, scene : Scene, materials_map : Dict[str,
|
|||||||
vertex_positions = []
|
vertex_positions = []
|
||||||
vertex_uvs = []
|
vertex_uvs = []
|
||||||
vertex_normals = []
|
vertex_normals = []
|
||||||
vertex_colors = []
|
|
||||||
|
|
||||||
# Keeps track of which vertices each group of weights affects
|
# Keeps track of which vertices each group of weights affects
|
||||||
# i.e. maps offset of vertices -> weights that affect them
|
# i.e. maps offset of vertices -> weights that affect them
|
||||||
@ -59,7 +58,6 @@ def model_to_mesh_object(model: Model, scene : Scene, materials_map : Dict[str,
|
|||||||
|
|
||||||
|
|
||||||
if model.geometry:
|
if model.geometry:
|
||||||
geometry_has_colors = any(segment.colors for segment in model.geometry)
|
|
||||||
|
|
||||||
for segment in model.geometry:
|
for segment in model.geometry:
|
||||||
|
|
||||||
@ -78,11 +76,6 @@ def model_to_mesh_object(model: Model, scene : Scene, materials_map : Dict[str,
|
|||||||
if segment.normals:
|
if segment.normals:
|
||||||
vertex_normals += [tuple(convert_vector_space(n)) for n in segment.normals]
|
vertex_normals += [tuple(convert_vector_space(n)) for n in segment.normals]
|
||||||
|
|
||||||
if segment.colors:
|
|
||||||
vertex_colors.extend(segment.colors)
|
|
||||||
elif geometry_has_colors:
|
|
||||||
[vertex_colors.extend([0.0, 0.0, 0.0, 1.0]) for _ in range(len(segment.positions))]
|
|
||||||
|
|
||||||
if segment.weights:
|
if segment.weights:
|
||||||
vertex_weights_offsets[polygon_index_offset] = segment.weights
|
vertex_weights_offsets[polygon_index_offset] = segment.weights
|
||||||
|
|
||||||
@ -118,6 +111,7 @@ def model_to_mesh_object(model: Model, scene : Scene, materials_map : Dict[str,
|
|||||||
blender_mesh.vertices.add(len(vertex_positions))
|
blender_mesh.vertices.add(len(vertex_positions))
|
||||||
blender_mesh.vertices.foreach_set("co", [component for vertex_position in vertex_positions for component in vertex_position])
|
blender_mesh.vertices.foreach_set("co", [component for vertex_position in vertex_positions for component in vertex_position])
|
||||||
|
|
||||||
|
|
||||||
# LOOPS
|
# LOOPS
|
||||||
|
|
||||||
flat_indices = [index for polygon in polygons for index in polygon]
|
flat_indices = [index for polygon in polygons for index in polygon]
|
||||||
@ -135,10 +129,6 @@ def model_to_mesh_object(model: Model, scene : Scene, materials_map : Dict[str,
|
|||||||
blender_mesh.uv_layers.new(do_init=False)
|
blender_mesh.uv_layers.new(do_init=False)
|
||||||
blender_mesh.uv_layers[0].data.foreach_set("uv", [component for i in flat_indices for component in vertex_uvs[i]])
|
blender_mesh.uv_layers[0].data.foreach_set("uv", [component for i in flat_indices for component in vertex_uvs[i]])
|
||||||
|
|
||||||
# Colors
|
|
||||||
if geometry_has_colors:
|
|
||||||
blender_mesh.color_attributes.new("COLOR0", "FLOAT_COLOR", "POINT")
|
|
||||||
blender_mesh.color_attributes[0].data.foreach_set("color", vertex_colors)
|
|
||||||
|
|
||||||
|
|
||||||
# POLYGONS/FACES
|
# POLYGONS/FACES
|
||||||
|
@ -179,7 +179,7 @@ def create_mesh_geometry(mesh: bpy.types.Mesh, valid_vgroup_indices: Set[int]) -
|
|||||||
vertex_remap: List[Dict[Tuple[int, int], int]] = [dict() for i in range(material_count)]
|
vertex_remap: List[Dict[Tuple[int, int], int]] = [dict() for i in range(material_count)]
|
||||||
polygons: List[Set[int]] = [set() for i in range(material_count)]
|
polygons: List[Set[int]] = [set() for i in range(material_count)]
|
||||||
|
|
||||||
if mesh.color_attributes.active_color is not None:
|
if mesh.vertex_colors.active is not None:
|
||||||
for segment in segments:
|
for segment in segments:
|
||||||
segment.colors = []
|
segment.colors = []
|
||||||
|
|
||||||
@ -215,10 +215,8 @@ def create_mesh_geometry(mesh: bpy.types.Mesh, valid_vgroup_indices: Set[int]) -
|
|||||||
yield mesh.uv_layers.active.data[loop_index].uv.y
|
yield mesh.uv_layers.active.data[loop_index].uv.y
|
||||||
|
|
||||||
if segment.colors is not None:
|
if segment.colors is not None:
|
||||||
data_type = mesh.color_attributes.active_color.data_type
|
for v in mesh.vertex_colors.active.data[loop_index].color:
|
||||||
if data_type == "FLOAT_COLOR" or data_type == "BYTE_COLOR":
|
yield v
|
||||||
for v in mesh.color_attributes.active_color.data[vertex_index].color:
|
|
||||||
yield v
|
|
||||||
|
|
||||||
if segment.weights is not None:
|
if segment.weights is not None:
|
||||||
for v in mesh.vertices[vertex_index].groups:
|
for v in mesh.vertices[vertex_index].groups:
|
||||||
@ -247,9 +245,7 @@ def create_mesh_geometry(mesh: bpy.types.Mesh, valid_vgroup_indices: Set[int]) -
|
|||||||
segment.texcoords.append(mesh.uv_layers.active.data[loop_index].uv.copy())
|
segment.texcoords.append(mesh.uv_layers.active.data[loop_index].uv.copy())
|
||||||
|
|
||||||
if segment.colors is not None:
|
if segment.colors is not None:
|
||||||
data_type = mesh.color_attributes.active_color.data_type
|
segment.colors.append(list(mesh.vertex_colors.active.data[loop_index].color))
|
||||||
if data_type == "FLOAT_COLOR" or data_type == "BYTE_COLOR":
|
|
||||||
segment.colors.append(list(mesh.color_attributes.active_color.data[vertex_index].color))
|
|
||||||
|
|
||||||
if segment.weights is not None:
|
if segment.weights is not None:
|
||||||
groups = mesh.vertices[vertex_index].groups
|
groups = mesh.vertices[vertex_index].groups
|
||||||
|
@ -39,9 +39,12 @@ def pack_color(color) -> int:
|
|||||||
return packed
|
return packed
|
||||||
|
|
||||||
def unpack_color(color: int) -> List[float]:
|
def unpack_color(color: int) -> List[float]:
|
||||||
r = (color >> 16 & 0xFF) / 255.0
|
|
||||||
g = (color >> 8 & 0xFF) / 255.0
|
mask = int(0x000000ff)
|
||||||
b = (color >> 0 & 0xFF) / 255.0
|
|
||||||
a = (color >> 24 & 0xFF) / 255.0
|
r = (color & (mask << 16)) / 255.0
|
||||||
|
g = (color & (mask << 8)) / 255.0
|
||||||
|
b = (color & mask) / 255.0
|
||||||
|
a = (color & (mask << 24)) / 255.0
|
||||||
|
|
||||||
return [r,g,b,a]
|
return [r,g,b,a]
|
||||||
|
Loading…
Reference in New Issue
Block a user