mirror of
https://github.com/OpenFusionProject/scripts.git
synced 2024-11-22 14:10:04 +00:00
Compare commits
5 Commits
20d5f6231c
...
7af28d8e70
Author | SHA1 | Date | |
---|---|---|---|
|
7af28d8e70 | ||
|
3bb3df7a2d | ||
|
f6dc2d690f | ||
|
af2988e062 | ||
|
03a3e21532 |
@ -8,7 +8,14 @@ dongpath = r'C:\Users\gents\AppData\LocalLow\Unity\Web Player\Cache\Fusionfall'
|
|||||||
env = UnityEnvironment(base_path=dongpath)
|
env = UnityEnvironment(base_path=dongpath)
|
||||||
outpath = r'C:\Users\gents\3D Objects\FFTerrainMeshes'
|
outpath = r'C:\Users\gents\3D Objects\FFTerrainMeshes'
|
||||||
|
|
||||||
def rip_terrain_mesh(f, outpath):
|
def uvs_from_vert(uv_layer, v):
|
||||||
|
uvs = []
|
||||||
|
for l in v.link_loops:
|
||||||
|
uv_data = l[uv_layer]
|
||||||
|
uvs.append(uv_data.uv)
|
||||||
|
return uvs
|
||||||
|
|
||||||
|
def rip_terrain_mesh(f, outpath, clear=False):
|
||||||
dong = Asset.from_file(f, environment=env)
|
dong = Asset.from_file(f, environment=env)
|
||||||
|
|
||||||
for k, v in dong.objects.items():
|
for k, v in dong.objects.items():
|
||||||
@ -25,12 +32,6 @@ def rip_terrain_mesh(f, outpath):
|
|||||||
context = bpy.context
|
context = bpy.context
|
||||||
grid = context.edit_object
|
grid = context.edit_object
|
||||||
|
|
||||||
# apply triangulate modifier
|
|
||||||
mod = grid.modifiers.new("Triangulate", 'TRIANGULATE')
|
|
||||||
mod.quad_method = 'FIXED' # triangle orientation
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
|
||||||
bpy.ops.object.modifier_apply(modifier="Triangulate")
|
|
||||||
|
|
||||||
bpy.ops.object.mode_set(mode='EDIT')
|
bpy.ops.object.mode_set(mode='EDIT')
|
||||||
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()
|
||||||
@ -48,6 +49,8 @@ def rip_terrain_mesh(f, outpath):
|
|||||||
|
|
||||||
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)
|
||||||
|
uv_layer = bm.loops.layers.uv.active
|
||||||
|
uv_shift_amt = 1 / 256
|
||||||
# gather m_Shifts positions
|
# gather m_Shifts positions
|
||||||
for shift in terrainData['m_Heightmap']['m_Shifts']:
|
for shift in terrainData['m_Heightmap']['m_Shifts']:
|
||||||
shift_index = shift['y'] + shift['x'] * 129
|
shift_index = shift['y'] + shift['x'] * 129
|
||||||
@ -56,12 +59,30 @@ def rip_terrain_mesh(f, outpath):
|
|||||||
flags = shift['flags'] # bits: +X -X +Y -Y
|
flags = shift['flags'] # bits: +X -X +Y -Y
|
||||||
if flags & 0b1000: # +X
|
if flags & 0b1000: # +X
|
||||||
v.co.x += shift_amt
|
v.co.x += shift_amt
|
||||||
|
for uv in uvs_from_vert(uv_layer, v):
|
||||||
|
uv.x += uv_shift_amt
|
||||||
if flags & 0b0100: # -X
|
if flags & 0b0100: # -X
|
||||||
v.co.x -= shift_amt
|
v.co.x -= shift_amt
|
||||||
|
for uv in uvs_from_vert(uv_layer, v):
|
||||||
|
uv.x -= uv_shift_amt
|
||||||
if flags & 0b0010: # +Y
|
if flags & 0b0010: # +Y
|
||||||
v.co.y += shift_amt
|
v.co.y += shift_amt
|
||||||
|
for uv in uvs_from_vert(uv_layer, v):
|
||||||
|
uv.y += uv_shift_amt
|
||||||
if flags & 0b0001: # -Y
|
if flags & 0b0001: # -Y
|
||||||
v.co.y -= shift_amt
|
v.co.y -= shift_amt
|
||||||
|
for uv in uvs_from_vert(uv_layer, v):
|
||||||
|
uv.y -= uv_shift_amt
|
||||||
|
|
||||||
|
# apply triangulate modifier
|
||||||
|
mod = grid.modifiers.new("Triangulate", 'TRIANGULATE')
|
||||||
|
mod.quad_method = 'FIXED' # triangle orientation
|
||||||
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
|
bpy.ops.object.modifier_apply(modifier="Triangulate")
|
||||||
|
|
||||||
|
bpy.ops.object.mode_set(mode="EDIT")
|
||||||
|
bm = bmesh.from_edit_mesh(context.edit_object.data)
|
||||||
|
bm.verts.ensure_lookup_table()
|
||||||
|
|
||||||
# flip diagonally
|
# flip diagonally
|
||||||
for v in bm.verts:
|
for v in bm.verts:
|
||||||
@ -73,24 +94,44 @@ def rip_terrain_mesh(f, outpath):
|
|||||||
for f in bm.faces:
|
for f in bm.faces:
|
||||||
f.normal_flip()
|
f.normal_flip()
|
||||||
|
|
||||||
# export
|
# select vertex chunks and separate
|
||||||
|
verts = {}
|
||||||
|
for x in range(129):
|
||||||
|
for y in range(129):
|
||||||
|
idx = y + x * 129
|
||||||
|
v = bm.verts[idx]
|
||||||
|
verts[idx] = v
|
||||||
|
v.select = False
|
||||||
|
for f in v.link_faces:
|
||||||
|
f.select = False
|
||||||
|
chunk_size = 8
|
||||||
|
for x in range(128 // chunk_size):
|
||||||
|
for y in range(128 // chunk_size):
|
||||||
|
for i in range(x * chunk_size, x * chunk_size + chunk_size + 1):
|
||||||
|
for j in range(y * chunk_size, y * chunk_size + chunk_size + 1):
|
||||||
|
idx = j + i * 129
|
||||||
|
v = verts[idx]
|
||||||
|
v.select = True
|
||||||
|
bm.select_mode = {'VERT', 'EDGE', 'FACE'}
|
||||||
|
bm.select_flush_mode()
|
||||||
|
bpy.context.tool_settings.mesh_select_mode = (False, False, True)
|
||||||
|
bpy.ops.mesh.duplicate()
|
||||||
|
bpy.ops.mesh.separate(type='SELECTED')
|
||||||
|
bpy.ops.mesh.select_all(action='DESELECT')
|
||||||
|
|
||||||
|
# delete main
|
||||||
bpy.ops.object.mode_set(mode="OBJECT")
|
bpy.ops.object.mode_set(mode="OBJECT")
|
||||||
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
|
grid.select_set(True)
|
||||||
|
bpy.ops.object.delete()
|
||||||
|
|
||||||
|
# export
|
||||||
bpy.ops.object.select_all(action='SELECT')
|
bpy.ops.object.select_all(action='SELECT')
|
||||||
name = terrainData['m_Name']
|
name = terrainData['m_Name']
|
||||||
outfile = f"{name}.obj"
|
outfile = f"{name}.obj"
|
||||||
bpy.ops.export_scene.obj(filepath=os.path.join(outpath, outfile))
|
bpy.ops.export_scene.obj(filepath=os.path.join(outpath, outfile))
|
||||||
|
|
||||||
# select modified vertices
|
if(clear):
|
||||||
#bpy.ops.object.mode_set(mode="EDIT")
|
|
||||||
#bm = bmesh.from_edit_mesh(context.edit_object.data)
|
|
||||||
#bm.verts.ensure_lookup_table()
|
|
||||||
#for v in bm.verts:
|
|
||||||
# v.select = False
|
|
||||||
#for shift_index in indices:
|
|
||||||
# v = bm.verts[shift_index]
|
|
||||||
# v.select = True
|
|
||||||
|
|
||||||
# clear the scene
|
|
||||||
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')
|
||||||
bpy.ops.object.delete()
|
bpy.ops.object.delete()
|
||||||
|
Loading…
Reference in New Issue
Block a user