TouchTerrain_for_CAGEO icon indicating copy to clipboard operation
TouchTerrain_for_CAGEO copied to clipboard

Reducing exported mesh size idea

Open ansonl opened this issue 1 year ago • 1 comments

Chris,

I noticed that the exported map models have twice as many vertices as needed due to the full resolution grid on the bottom surface. I made a Blender script to automate decreasing the vertices count by selecting all bottom vertices and applying a 1% decimate modifier.

It's probably more streamlined to avoid making the extra vertices during the TouchTerrain generation but I don't see an easy way to do that at the moment. I added some screenshots on how to run the script below if anyone else needs to decrease the size of their models. Maybe this can be added to the documentation.

step1

final

The model must be selected (highlighted in yellow) in the 3D view or object list before clicking the Run script button.

step2

The vertices of the object can be viewed by with Tab key to go to Edit mode when the object is selected.

The script to paste into Blender is below

import bpy, time

variantProcessStartTime = time.monotonic()

originalVertexCount = 0
for obj in bpy.context.scene.objects:
    originalVertexCount += len(obj.data.vertices)
    
print(f'Original vertex count {originalVertexCount}')

# Deselect everything on object
for e in [bpy.context.active_object.data.vertices, bpy.context.active_object.data.polygons, bpy.context.active_object.data.edges]:
    e.foreach_set("select", (False,)*len(e))

# Select vertices at or below Z0
for v in bpy.context.active_object.data.vertices:
   v.select = v.co.z <= 0
   
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_mode(type="VERT")
bpy.ops.mesh.select_less()
   
bpy.ops.object.vertex_group_assign_new()
bpy.context.active_object.vertex_groups[0].name = 'bottom-inner'   

bpy.ops.object.modifier_add(type='DECIMATE')
bpy.context.object.modifiers["Decimate"].vertex_group='bottom-inner'
bpy.context.object.modifiers["Decimate"].ratio=0.01
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.modifier_apply(modifier='Decimate')

bpy.ops.object.mode_set(mode='OBJECT')
print(f'select inner bottom and decimate took {time.monotonic()-variantProcessStartTime}s')

ansonl avatar Dec 08 '24 00:12 ansonl