Exporter -> separate file, fix codegen, don't ignore .pn files

main
Cameron Murphy Reikes 2 years ago
parent fba0f0ec6d
commit 04d0719418

1
.gitattributes vendored

@ -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

@ -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")

BIN
art/art.blend (Stored with Git LFS)

Binary file not shown.

@ -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

Loading…
Cancel
Save