mirror of
https://github.com/OpenFusionProject/scripts.git
synced 2024-11-26 07:10:06 +00:00
Compare commits
No commits in common. "20d5f6231c9ebab50302fefe3a6e3710fc4fa0cc" and "3aabb35f332abe370e7b096d088ffc48f0204460" have entirely different histories.
20d5f6231c
...
3aabb35f33
@ -16,12 +16,9 @@ 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=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
|
||||
grid = context.edit_object
|
||||
|
||||
@ -35,16 +32,8 @@ 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']):
|
||||
# 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}")
|
||||
height = height / terrainData['m_Heightmap']['m_Scale']['y']
|
||||
bm.verts[index].co.z = height
|
||||
|
||||
indices = []
|
||||
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
|
||||
v.co.y -= shift_amt
|
||||
|
||||
# flip diagonally
|
||||
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
|
||||
# flip to correct orientation
|
||||
bpy.ops.object.mode_set(mode="OBJECT")
|
||||
bpy.ops.object.select_all(action='SELECT')
|
||||
name = terrainData['m_Name']
|
||||
outfile = f"{name}.obj"
|
||||
bpy.ops.export_scene.obj(filepath=os.path.join(outpath, outfile))
|
||||
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"
|
||||
bpy.ops.export_scene.fbx(filepath=os.path.join(outpath, outfile))
|
||||
|
||||
# select modified vertices
|
||||
#bpy.ops.object.mode_set(mode="EDIT")
|
||||
|
Loading…
Reference in New Issue
Block a user