mirror of
https://github.com/OpenFusionProject/scripts.git
synced 2024-11-21 13:50:05 +00:00
Fix vertex positioning and outfile name
This commit is contained in:
parent
3aabb35f33
commit
ef8ae1fb6e
@ -16,9 +16,12 @@ def rip_terrain_mesh(f, outpath):
|
||||
terrainData = dong.objects[k].read()
|
||||
terrain_width = terrainData['m_Heightmap']['m_Width'] - 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
|
||||
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))
|
||||
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))
|
||||
context = bpy.context
|
||||
grid = context.edit_object
|
||||
|
||||
@ -32,8 +35,16 @@ def rip_terrain_mesh(f, outpath):
|
||||
bm = bmesh.from_edit_mesh(context.edit_object.data)
|
||||
bm.verts.ensure_lookup_table()
|
||||
for index, height in enumerate(terrainData['m_Heightmap']['m_Heights']):
|
||||
height = height / terrainData['m_Heightmap']['m_Scale']['y']
|
||||
bm.verts[index].co.z = height
|
||||
# scale height
|
||||
height_norm = height / (2 ** 15 - 2)
|
||||
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 = []
|
||||
shift_amt = abs(bm.verts[0].co.x - bm.verts[1].co.x)
|
||||
@ -52,11 +63,17 @@ def rip_terrain_mesh(f, outpath):
|
||||
if flags & 0b0001: # -Y
|
||||
v.co.y -= shift_amt
|
||||
|
||||
# flip to correct orientation
|
||||
# flip diagonally
|
||||
for v in bm.verts:
|
||||
tmp = v.co.x
|
||||
v.co.x = v.co.y
|
||||
v.co.y = tmp
|
||||
|
||||
# export
|
||||
bpy.ops.object.mode_set(mode="OBJECT")
|
||||
bpy.ops.object.select_all(action='SELECT')
|
||||
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"{k}.fbx"
|
||||
name = terrainData['m_Name']
|
||||
outfile = f"{name}.fbx"
|
||||
bpy.ops.export_scene.fbx(filepath=os.path.join(outpath, outfile))
|
||||
|
||||
# select modified vertices
|
||||
|
Loading…
Reference in New Issue
Block a user