1
$\begingroup$

I have a mesh with millions of densely packed vertices, and I what I want to do is be able to bisect them into separate objects. What I struggle with is selecting the vertices I want to be separated from the original mesh.

Trying with the solution given to this question gives me odd results, with either selected vertices not being within the given coordinates or selecting no vertices at all. Naturally, when I then separate the selected vertices I only separate the ones still selected from when I bisected the original object.

What am I missing here? Is there another way of selecting vertices that works better with my intentions or have I just slipped somewhere and can't see it myself?

This is the current structure of my code:

# centers the median point to center of mesh
def CenterMedianPoint():
    filepath = bpy.path.abspath("//space_view3d_move_origin.py")
    exec(compile(open(filepath).read(), filepath, 'exec'))

# deselects all objects
def DeselectObjects():
    for obj in bpy.data.objects:
        obj.select = False

# bisects object based on coordinates and direction
def BisectObject(coX, coY, coZ, noX, noY, noZ):
    bpy.ops.mesh.bisect(plane_co=(coX, coY, coZ), plane_no=(noX, noY, noZ))

# get the dimensions of active object
dimensionX, dimensionY, dimensionZ = bpy.context.active_object.dimensions

# calculate dimensions and cell structure
cutObjectDimensionX = dimensionX / 5
cutObjectDimensionY = dimensionY / 5
cutObjectDimensionZ = dimensionZ / 5
objectStartX = (dimensionX * (-1)) / 2
objectStartY = (dimensionY * (-1)) / 2
objectStartZ = (dimensionZ * (-1)) / 2
objectEndX = dimensionX / 2
objectEndY = dimensionY / 2
objectEndZ = dimensionZ / 2

cellCount = 1
parentCellCount = 1

# first cut iteration
for i in range(0, 4):
    # selects object, enters EDIT mode and centers median point for easier coordinate calculation
    bpy.context.scene.objects.active = bpy.data.objects['objectToBisect']
    bpy.ops.object.mode_set(mode = 'EDIT')
    bpy.ops.mesh.select_all(action='TOGGLE')
    CenterMedianPoint()
    # bisects objcet and selects bisected vertices
    BisectObject(0, (cutObjectDimensionZ-(cutObjectDimensionZ*i)), 0, 0, 1, 0)
    SelectVerticesInBound(bpy.data.objects['objectToBisect'], Vector((objectStartX, (cutObjectDimensionY-(cutObjectDimensionY*i)), objectStartZ)), Vector((objectEndX, objectEndY, objectEndZ)))
    # separates selected vertices into new object
    bpy.ops.mesh.separate(type='SELECTED')
    bpy.ops.object.mode_set(mode = 'OBJECT')
    DeselectObjects() 

CenterMedianPoint script can be found here

$\endgroup$
  • $\begingroup$ Just an observation: BisectObject expects coX, coY, coZ as the first three params. But you are calling with 0, (cutObjectDimensionZ-(cutObjectDimensionZ*i)), 0. Any particular reason for using z dimension in place of y? $\endgroup$ – Blender Dadaist Nov 17 '18 at 10:40
  • $\begingroup$ Yes; the file I worked with at first worked with the x, y and z dimensions Blender uses, but the object was so large I later decided to use a downscaled version, but when I imported that .obj file it seems to have confused the Y and Z axis, so it interprets Z as Y and vice versa. Doesn't help, but the reduced process time for each command is significant enough to make me withstand it. $\endgroup$ – Lycan Nov 18 '18 at 16:24
-1
$\begingroup$

Just found out through testing that there is nothing faulty with my code, nor any of the methods I'm using. Instead, there was some issue with the coordinate system that formed during or after I had imported the .obj file that I used to test with, resulting in the code not having the same effect as it normally would have.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.