|
|
@@ -7,7 +7,7 @@ bl_info = {
|
|
|
"blender": (3, 0, 0),
|
|
|
"location": "File > Import-Export > Chair Mesh (.chr)",
|
|
|
# Crate verion 0.2.3
|
|
|
- "version": (0, 2, 4),
|
|
|
+ "version": (0, 2, 5),
|
|
|
"category": "Import-Export"
|
|
|
}
|
|
|
|
|
|
@@ -92,6 +92,9 @@ def process_scene(context, apply_modifiers, store_colours, store_normals, store_
|
|
|
if not me.loop_triangles and me.polygons:
|
|
|
me.calc_loop_triangles()
|
|
|
|
|
|
+ if store_normals:
|
|
|
+ me.calc_normals_split()
|
|
|
+
|
|
|
# TODO: find texture used by this object
|
|
|
vertices = []
|
|
|
vertex_ids = {}
|
|
|
@@ -164,9 +167,14 @@ def write_vec3_byte(f, v, scale, offset):
|
|
|
z = 128 * (v[1] - offset[1]) / scale[1]
|
|
|
f.write(bytes([int(x), int(y), int(z)]))
|
|
|
|
|
|
+tau = math.pi * 2
|
|
|
def index_normal(n):
|
|
|
+ if n == 0:
|
|
|
+ # exact mapping of 0 to 0.0 with no error
|
|
|
+ return 0
|
|
|
+
|
|
|
# asin fairly slow but this is pyton so doesnt matter
|
|
|
- return 128 + int(math.asin(n) * 255 / math.pi)
|
|
|
+ return 128 - int(math.asin(n) * 255 / tau)
|
|
|
|
|
|
def write_vec3_sin(f, v):
|
|
|
x = index_normal(v[0])
|
|
|
@@ -175,7 +183,7 @@ def write_vec3_sin(f, v):
|
|
|
z = index_normal(v[1])
|
|
|
f.write(bytes([x, y, z]))
|
|
|
|
|
|
-def write_model(path, colours, objects, indices, export_colours, export_normals, export_uvs, export_skeleton, short_pos, short_normals, short_uvs, short_weights):
|
|
|
+def write_model(path, colours, objects, indices, export_colours, export_normals, export_uvs, export_skeleton, short_pos, short_normals, short_uvs, short_weights, flip_winding):
|
|
|
f = open(path, "wb")
|
|
|
# Chair file header
|
|
|
f.write(bytes("CHAIR", "ascii"))
|
|
|
@@ -259,8 +267,15 @@ def write_model(path, colours, objects, indices, export_colours, export_normals,
|
|
|
# Indices
|
|
|
f.write(len(indices).to_bytes(4, "little"))
|
|
|
indsize = index_size(sum([len(obj[0]) for obj in objects]))
|
|
|
- for i in indices:
|
|
|
- f.write(i.to_bytes(indsize, "little"))
|
|
|
+ if flip_winding:
|
|
|
+ for i in range(0, int(len(indices) / 3)):
|
|
|
+ n = i * 3
|
|
|
+ f.write(indices[n + 1].to_bytes(indsize, "little"))
|
|
|
+ f.write(indices[n].to_bytes(indsize, "little"))
|
|
|
+ f.write(indices[n + 2].to_bytes(indsize, "little"))
|
|
|
+ else:
|
|
|
+ for i in indices:
|
|
|
+ f.write(i.to_bytes(indsize, "little"))
|
|
|
|
|
|
f.close()
|
|
|
return
|
|
|
@@ -335,10 +350,16 @@ class ModelExporter(Operator, ExportHelper):
|
|
|
default = False
|
|
|
)
|
|
|
|
|
|
+ flip_winding: BoolProperty(
|
|
|
+ name = "Flip Winding",
|
|
|
+ description = "Flip vertex winding from CCW to CW",
|
|
|
+ default = False
|
|
|
+ )
|
|
|
+
|
|
|
def execute(self, context):
|
|
|
colours, objects, indices = process_scene(context, self.apply_modifiers, self.export_colours, self.export_normals, self.export_uvs)
|
|
|
write_model(self.filepath, colours, objects, indices, self.export_colours, self.export_normals, self.export_uvs, self.export_skeleton,
|
|
|
- self.short_pos, self.short_normals, self.short_uvs, self.short_weights)
|
|
|
+ self.short_pos, self.short_normals, self.short_uvs, self.short_weights, self.flip_winding)
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
def menu_export(self, context):
|