Compare commits

..

No commits in common. "20d5f6231c9ebab50302fefe3a6e3710fc4fa0cc" and "3aabb35f332abe370e7b096d088ffc48f0204460" have entirely different histories.

View File

@ -16,12 +16,9 @@ def rip_terrain_mesh(f, outpath):
terrainData = dong.objects[k].read() terrainData = dong.objects[k].read()
terrain_width = terrainData['m_Heightmap']['m_Width'] - 1 terrain_width = terrainData['m_Heightmap']['m_Width'] - 1
terrain_height = terrainData['m_Heightmap']['m_Height'] - 1 terrain_height = terrainData['m_Heightmap']['m_Height'] - 1
scale_x = terrainData['m_Heightmap']['m_Scale']['x']
scale_z = terrainData['m_Heightmap']['m_Scale']['z']
scale_y = terrainData['m_Heightmap']['m_Scale']['y']
# create the terrain # create the terrain
bpy.ops.mesh.primitive_grid_add(x_subdivisions=terrain_width, y_subdivisions=terrain_height, size=128, enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) bpy.ops.mesh.primitive_grid_add(x_subdivisions=terrain_width, y_subdivisions=terrain_height, size=40, enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
context = bpy.context context = bpy.context
grid = context.edit_object grid = context.edit_object
@ -35,16 +32,8 @@ def rip_terrain_mesh(f, outpath):
bm = bmesh.from_edit_mesh(context.edit_object.data) bm = bmesh.from_edit_mesh(context.edit_object.data)
bm.verts.ensure_lookup_table() bm.verts.ensure_lookup_table()
for index, height in enumerate(terrainData['m_Heightmap']['m_Heights']): for index, height in enumerate(terrainData['m_Heightmap']['m_Heights']):
# scale height height = height / terrainData['m_Heightmap']['m_Scale']['y']
height_norm = height / (2 ** 15 - 2) bm.verts[index].co.z = height
bm.verts[index].co.z = height_norm * scale_y
# pivot and scale x
bm.verts[index].co.x += terrain_width / 2
bm.verts[index].co.x *= scale_x
# pivot and scale z
bm.verts[index].co.y += terrain_height / 2
bm.verts[index].co.y *= scale_z
#print(f"{bm.verts[index].co.x}, {bm.verts[index].co.y}, {bm.verts[index].co.z}")
indices = [] indices = []
shift_amt = abs(bm.verts[0].co.x - bm.verts[1].co.x) shift_amt = abs(bm.verts[0].co.x - bm.verts[1].co.x)
@ -63,22 +52,12 @@ def rip_terrain_mesh(f, outpath):
if flags & 0b0001: # -Y if flags & 0b0001: # -Y
v.co.y -= shift_amt v.co.y -= shift_amt
# flip diagonally # flip to correct orientation
for v in bm.verts:
tmp = v.co.x
v.co.x = v.co.y
v.co.y = tmp
# flip normals
for f in bm.faces:
f.normal_flip()
# export
bpy.ops.object.mode_set(mode="OBJECT") bpy.ops.object.mode_set(mode="OBJECT")
bpy.ops.object.select_all(action='SELECT') bpy.ops.object.select_all(action='SELECT')
name = terrainData['m_Name'] bpy.ops.transform.mirror(orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False))
outfile = f"{name}.obj" outfile = f"{k}.fbx"
bpy.ops.export_scene.obj(filepath=os.path.join(outpath, outfile)) bpy.ops.export_scene.fbx(filepath=os.path.join(outpath, outfile))
# select modified vertices # select modified vertices
#bpy.ops.object.mode_set(mode="EDIT") #bpy.ops.object.mode_set(mode="EDIT")