diff --git a/.gitattributes b/.gitattributes index d16a064..6158505 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,2 @@ *.blend filter=lfs diff=lfs merge=lfs -text -*.pn filter=lfs diff=lfs merge=lfs -text *.png filter=lfs diff=lfs merge=lfs -text diff --git a/art/Exporter.py b/art/Exporter.py new file mode 100644 index 0000000..0e399e2 --- /dev/null +++ b/art/Exporter.py @@ -0,0 +1,60 @@ +import bpy +import bmesh +import os +import struct +from mathutils import *; from math import * +from bpy_extras.io_utils import (axis_conversion) + +C = bpy.context +D = bpy.data + +EXPORT_DIRECTORY = "exported" + +if not os.path.exists(bpy.path.abspath(f"//{EXPORT_DIRECTORY}")): + os.makedirs(bpy.path.abspath(f"//{EXPORT_DIRECTORY}")) + + +def write_f32(f, number: float): + f.write(bytes(struct.pack("f", number))) + +def write_u64(f, number: int): + f.write(bytes(struct.pack("Q", number))) + +for o in D.objects: + mapping = axis_conversion( + from_forward = "Y", + from_up = "Z", + to_forward = "-Z", + to_up = "Y", + ) + mapping.resize_4x4() + print(mapping) + output_filepath = bpy.path.abspath(f"//{EXPORT_DIRECTORY}/{o.name}.bin") + print(f"\n\nExporting {output_filepath}") + with open(output_filepath, "wb") as f: + bm = bmesh.new() + mesh = o.to_mesh() + bm.from_mesh(mesh) + bmesh.ops.triangulate(bm, faces=bm.faces) + bm.transform(mapping) + bm.to_mesh(mesh) + + + vertices = [] + + for polygon in mesh.polygons: + if len(polygon.loop_indices) == 3: + for loopIndex in polygon.loop_indices: + loop = mesh.loops[loopIndex] + position = mesh.vertices[loop.vertex_index].undeformed_co + uv = mesh.uv_layers.active.data[loop.index].uv + normal = loop.normal + + vertices.append(position) + + write_u64(f, len(vertices)) + for v in vertices: + write_f32(f, v.x) + write_f32(f, v.y) + write_f32(f, v.z) + print(f"Wrote {len(vertices)} vertices") \ No newline at end of file diff --git a/art/art.blend b/art/art.blend index 5730634..1c822ac 100644 --- a/art/art.blend +++ b/art/art.blend @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:31d12b0ddc3eb2909994163a30548a90b61628ffb502d0e84330ee68acbdad79 -size 916880 +oid sha256:6728eb4f6670636037e45663ee8eb1c97ebdea68adb937444a3c7855316d1504 +size 924500 diff --git a/run_codegen.bat b/run_codegen.bat index be1bec0..6fbd9f3 100644 --- a/run_codegen.bat +++ b/run_codegen.bat @@ -29,7 +29,7 @@ copy "rpgpt_private_assets\knight_run_start.png" "assets\copyrighted\knight_run_ rmdir /S /q "assets\exported_3d" mkdir "assets\exported_3d" || goto :error -copy "rpgpt_private_assets\exported\*" "assets\exported_3d\" || goto :error +copy "art\exported\*" "assets\exported_3d\" || goto :error @echo off rmdir /S /q gen