a bug in the XALL tool?
ArgosSoft opened this issue · comments
Hi,
First of all thank you for all of these convenient tools :)
I'm mainly using XALL, and sometime it does random things, with the same setup:
I did a python script that build circles and a square, I select all, and I just apply XALL in edit mode:
(the script is a loop on bpy.ops.mesh.primitive_circle_add)
with this setup:
(all is (x, y, 0.0) )
sometime I got this (sounds good, and when I check it, everything looks linked as expected):
Python output:
>>>bpy.ops.tinycad.intersectall()
unselected {515, 4, 5, 6, 7, 8, 9, 10, 11, 518, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 530, 28, 29, 30, 31, 32, 33, 34, 35, 545, 632, 38, 39, 40, 41, 43, 44, 557, 46, 558, 48, 49, 50, 559, 560, 53, 54, 55, 561, 57, 562, 59, 60, 564, 62, 63, 64, 65, 66, 570, 581, 71, 72, 74, 76, 588, 78, 589, 80, 590, 82, 591, 592, 85, 593, 87, 526, 89, 594, 91, 527, 93, 597, 95, 96, 528, 601, 602, 603, 610, 102, 103, 529, 105, 613, 107, 619, 109, 620, 621, 531, 113, 622, 115, 116, 532, 118, 623, 624, 625, 122, 533, 124, 628, 126, 534, 128, 129, 130, 634, 535, 636, 134, 135, 642, 536, 139, 537, 147, 148, 160, 161, 164, 165, 166, 167, 169, 172, 180, 187, 190, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 209, 214, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 635, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 633, 563, 274, 277, 565, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 567, 568, 569, 306, 308, 309, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 332, 333, 334, 335, 336, 337, 340, 341, 342, 343, 344, 345, 346, 347, 349, 350, 351, 352, 353, 354, 355, 357, 358, 359, 361, 363, 364, 366, 367, 368, 369, 371, 374, 375, 376, 377, 379, 380, 382, 384, 385, 386, 389, 391, 626, 393, 395, 397, 399, 400, 402, 407, 408, 410, 412, 414, 416, 566, 418, 627, 420, 422, 426, 428, 430, 432, 433, 595, 435, 438, 439, 596, 441, 443, 445, 449, 598, 451, 452, 599, 600, 460, 464, 465, 629, 467, 469, 470, 471, 631, 483, 484, 491, 630, 494, 496, 497, 498, 499, 500, 501, 502, 503, 505, 508}, non intersecting edges
Info: Removed 852 vertices
{'FINISHED'}
and sometime, with the same setup, I got this:
Python output:
>>> bpy.ops.tinycad.intersectall()
unselected {515, 4, 5, 6, 7, 8, 9, 10, 11, 518, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 530, 28, 29, 30, 31, 32, 33, 34, 35, 545, 632, 38, 39, 40, 41, 43, 44, 557, 46, 558, 48, 49, 50, 559, 560, 53, 54, 55, 561, 57, 562, 59, 60, 564, 62, 63, 64, 65, 66, 570, 581, 71, 72, 74, 76, 588, 78, 589, 80, 590, 82, 591, 592, 85, 593, 87, 526, 89, 594, 91, 527, 93, 597, 95, 96, 528, 601, 602, 603, 610, 102, 103, 529, 105, 613, 107, 619, 109, 620, 621, 531, 113, 622, 115, 116, 532, 118, 623, 624, 625, 122, 533, 124, 628, 126, 534, 128, 129, 130, 634, 535, 636, 134, 135, 642, 536, 139, 537, 147, 148, 160, 161, 164, 165, 166, 167, 169, 172, 180, 187, 190, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 209, 214, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 635, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 633, 563, 274, 277, 565, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 567, 568, 569, 306, 308, 309, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 332, 333, 334, 335, 336, 337, 340, 341, 342, 343, 344, 345, 346, 347, 349, 350, 351, 352, 353, 354, 355, 357, 358, 359, 361, 363, 364, 366, 367, 368, 369, 371, 374, 375, 376, 377, 379, 380, 382, 384, 385, 386, 389, 391, 626, 393, 395, 397, 399, 400, 402, 407, 408, 410, 412, 414, 416, 566, 418, 627, 420, 422, 426, 428, 430, 432, 433, 595, 435, 438, 439, 596, 441, 443, 445, 449, 598, 451, 452, 599, 600, 460, 464, 465, 629, 467, 469, 470, 471, 631, 483, 484, 491, 630, 494, 496, 497, 498, 499, 500, 501, 502, 503, 505, 508}, non intersecting edges
Info: Removed 948 vertices
{'FINISHED'}
Additional information:
tinyCAD Version 1.3.0
Blender 2.78a (OSX)
Any idea? Maybe I'm not using your tool correctly?
Thank you again!
yep. sometimes you need to switch in and out of edit mode before running the XALL operator.
if you are a little adventurous you can try adding the following lines
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT')
into the top of the execute function in https://github.com/zeffii/mesh_tiny_cad/blob/master/XALL.py#L163-L181
def execute(self, context):
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT')
# must force edge selection mode here
bpy.context.tool_settings.mesh_select_mode = (False, True, False)
obj = context.active_object
if obj.mode == "EDIT":
bm = bmesh.from_edit_mesh(obj.data)
selected_edges = [edge for edge in bm.edges if edge.select]
edge_indices = [i.index for i in selected_edges]
d = get_intersection_dictionary(bm, edge_indices)
unselect_nonintersecting(bm, d.keys(), edge_indices)
update_mesh(obj, d)
else:
print('must be in edit mode')
return {'FINISHED'}
@ArgosSoft if you do that.. let me know how it goes. If it tames the Mesh, then i'm tempted to add those lines to the version distributed with Blender too.
Ok , thanks for checking. I recently wrote replacement code for that function for sverchok. Maybe you would provide a simple script I can test your scenario with. I hope to get around to this in 2 days
Here is a minimal example of my script:
import bpy
# new object
me = bpy.data.meshes.new('myMesh')
ob = bpy.data.objects.new('myObject', me)
bpy.context.scene.objects.link(ob)
# selection and EDIT mode
bpy.context.scene.objects.active = ob
ob.select = True
bpy.ops.object.mode_set(mode='EDIT')
# circles part 1
center = (0, 0.5, 0)
step = 0.2
radiusMax = 2
r = 0
while r < radiusMax:
r = r + step
bpy.ops.mesh.primitive_circle_add(vertices=32, radius=r, location=center)
# circles part 2
center = (0, -0.5, 0)
step = 0.2
radiusMax = 2
r = 0
while r < radiusMax:
r = r + step
bpy.ops.mesh.primitive_circle_add(vertices=32, radius=r, location=center)
# edit mode switch
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT')
# XALL call
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.tinycad.intersectall()
@ArgosSoft excellent! i'm eager to fix this btw, it has bugged me for the longest time - I get so few reports about XALL
my own experiments in the past have shown that the problem isn't really any specific type of geometry, but rather an index shuffling upon initialization.. First i hope my replacement code will solve this (it is the least invasive edit i'd like to try first), then ..well.. i don't really want to think about that yet.
for good measure i'll add a feature that let's you specify remove doubles / and doubles distance - the call would become:
bpy.ops.tinycad.intersectall()
# or
bpy.ops.tinycad.intersectall(rm_doubles=True, distance=0.0001)
(but in this case that doesn't seem to matter)
This might come down to a problem of limited precision in 32-bit float numbers and my rather crude algorithm that assumes very little shared vertex geometry ( like.. no verts located on the same 3d locations)
but won't dance on its grave just yet.
no ETA btw.. it's not a small change.
With a small change in my script: center = (0, 0.52, 0)
And center = (0, -0.52, 0)
No more vertex are located on the same location (bpy.ops.mesh.remove_doubles
return Info: Removed 0 vertices {'FINISHED'}
)
And I still got the same issue, maybe a floating precision problem as you said?
No, I think i've already been able to confirm that "co-location" wasn't the problem i reasoned it might be, and with that finding i'm not considering floating point the real problem either.
A small rewrite will happen as soon as i have some free time (and silence around me)
I have a different branch to test this in, if you are comfortable with such things:
#57
I'm trying #57, it seems to be better, after few execution the result looks good :)
that's all I can do for now, without going deeper.
- as you can see on the screenshot, there is some extra geometry generated where two edges run almost parallel.
this seems to be caused by the code that does the initial "deselection of non-intersecting edges"
i've pushed this to master and to blender/addons repo.
closing unless @ArgosSoft reopens.