Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reducing exported mesh size idea #99

Open
ansonl opened this issue Dec 8, 2024 · 1 comment
Open

Reducing exported mesh size idea #99

ansonl opened this issue Dec 8, 2024 · 1 comment

Comments

@ansonl
Copy link
Contributor

ansonl commented Dec 8, 2024

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')
@ChHarding
Copy link
Owner

ChHarding commented Dec 10, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants