Results 1 to 4 of 4
  1. #1

    Two mesh split scripts

    I've recently been thinking of making a race track for a computer game (see this thread). My preferred modelling method is a plane with an array modifier and a curve modifier.

    In Blender I'd like to keep the whole track as one object to make editing easier (e.g. so I don't have to worry about the distance when using proportional editing), but the for game it's necessary to split it up into multiple segments. I decided to have a go at scripting.

    Script 1: Split by Count (splits every 3000 polys). This doesn't require any setup but the result can be a bit messy if lots of points have been added/removed and faces not sorted.
    import bpy
    import bmesh
    thing = bpy.context.active_object
    #If the first modifer is an Array modifier, apply it to create a real object.
    mods = thing.modifiers
    if(mods[0].name == "Array"):
        bpy.ops.object.modifier_apply(modifier="Array") = True
    bpy.ops.object.mode_set(mode='EDIT') #Switch to edit mode
    #Select all faces, sort them by X axis, then deselect all.
    obj = bpy.context.edit_object
    me =
    bm = bmesh.from_edit_mesh(me)
    #Split object be every 3000 faces until there are fewer than 3000 remaining.
    while(len(bm.faces) > 3000):
        i = 0
        bm.faces.ensure_lookup_table() #reqiured due to accessing faces by index
        while(i < 3000):
            face = bm.faces[i]
   = True
            i += 1
        #Separate the faces to a new mesh
        i = 0
    #Switch back to object mode
    Script 2: Split by Vertex Groups. This requires more setup work (creating and assigning) but you have more control over where the splitting occurs. This also doesn't really work with the Array modifier still applied, but once a track gains unique features like banking and bumps etc, an Array modifier is no longer relevant.
    import bpy
    bpy.ops.object.mode_set(mode='EDIT') #Switch to edit mode
    bpy.ops.mesh.select_all(action='DESELECT') #Clear any existing selection
    obj = bpy.context.edit_object
    for group in obj.vertex_groups:
        #Separate the faces to a new mesh
    #Switch back to object mode
    I hope someone finds these useful. They'll certainly make it easier for me because there will be a lot of trial and error, so being able to easily switch between a full track and a split track will make things a lot simpler.

  2. #2
    Member Meta-Androcto's Avatar
    Join Date
    Aug 2006
    thanks, not sure i'll get time to test, but looks useful & thanks for sharing.

  3. #3
    I combined the two into a single addon called MeshSplit:
    Attachment 467404

    The user can change the max number of polys. Splitting by vertex group now looks for names that start with something. By default it's "split...", and the user can change that.

  4. #4
    Here's version 1.1

    The created objects had names like thing.001, thing.002. The update replaces the . with _, which is useful for my use of this script.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts