Boolean script question

Hello. I need help with boolean script. I want to write a tool that makes a chamfer to those edges that appears when two boolean objects intersects. Something like "Modo Meshfusion" functionality, but simplier. So, there are two main question.

Question number one - how to catch those edges? The problem is that bollean operation automatically selects not all of those edges, but all of those vertices. How to convert the selection of vertices to the selection of edges that lies between vertices?

Question number two - how to avoid mesh overlapping when I do the chamfer? Maybe there is a way to weld a vertices if the distance between them is too short? And if I want to make a chamfer smaller, how to return a welded vertices? Is there a way to make a script more dynamic, so the chamfer will stay even if I move one of the source objects and the number of edges/vertices will change?

AttachmentSize
ttt.jpg150.57 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
TsveTan's picture

I understand the problem,

but 3ds max does not make very clear chamfers, when the edges are not perpendicular to the chamfer line. Also you may need to reed the boolean's requirements in 3ds max reference. There are some restrictions. Also examine the proBoolean and proCuter objects, they are more powerful.

chooj's picture

.

thanks

TsveTan's picture

Ready

(
fn fnGetEdgesByVerts obj = (
 verts_array = polyop.getVertSelection obj
 edges = polyop.getEdgesUsingVert obj verts_array
 edges1 = copy edges
 For edge in edges1 Do (
  v = polyop.getVertsUsingEdge obj #{edge}
  For vert in v Do (
   If (findItem verts_array vert) == 0 Then (edges[edge] = false)
  )
 )
 return (edges) -- As bitArray
)
 
fn fnChamferByEdgeSelection obj /*chamfer_value*/ weld_threshold = (
 obj.weldThreshold = weld_threshold
 polyop.weldVertsByThreshold obj (polyop.getvertselection obj)
 polyop.setEdgeSelection obj (fnGetEdgesByVerts obj)
 select obj
 max modify mode
 subobjectlevel = 2
 --obj.edgeChamfer chamfer_value
 obj.popupDialog #chamfer
)
 
local obj_a, obj_b, result
 
rollout r "BooleanAdv" width:200 height:250 (
 
	pickbutton pick_objA "Pick Operand A" offset:[0,0]
	pickbutton pick_objB "Pick Operand B" offset:[0,0]
	on pick_objA picked obj do (
		obj_a = obj
		pick_objA.text = obj.name
	)
	on pick_objB picked obj do (
		obj_b = obj
		pick_objB.text = obj.name
	)
	radiobuttons rb labels:#("union", "subtraction a - b", "subtraction b - a", "intersection") offset:[0,0]
	spinner weld_threshold "Weld Threshold" offset:[0,0] range:[0,100,0.1] type:#float
	button boolean_btn "Create Boolean" offset:[0,0]
	button delete_btn "Delete the boolean" enabled:false offset:[0,0]
	on boolean_btn pressed do (
		result = undefined
		case r.rb.state of (
		(1):(result = (copy obj_a) + obj_b)
		(2):(result = (copy obj_a) - obj_b)
		(3):(result = (copy obj_b) - obj_a)
		(4):(result = (copy obj_a) * obj_b)
		default:(messageBox "Select the appropriate boolean's type.")
		)
		if result != undefined do (convertto result editable_poly; r.delete_btn.enabled = true;completeRedraw())
	)
	button chamfer_btn "Weld verts and Chamfer Borders" offset:[0,0]
	on chamfer_btn pressed do (
		fnChamferByEdgeSelection result (r.weld_threshold.value)
	)
	on delete_btn pressed do (try (delete result; r.delete_btn.enabled = false) catch ())
	label lab "BooleanAdv, 2016, Tsvetan St."
)
createDialog r
)
chooj's picture

Script

I've tried this, but the chamfer is still messy, especially when I try to make chamfer bigger..

TsveTan's picture

Continued from my previous post...

fn fnChamferByEdgeSelection obj chamfer_value = (
 polyop.setEdgeSelection obj (fnGetEdgesByVerts obj)
 obj.edgeChamfer chamfer_value
)
 
rollout r "boolean" width:200 height:200 (
 spinner chamfer_val "Chamfer value" range:[0,19,1] type:#float
 button apply_btn "Apply"
 -- select the boolean and press the Apply button
 on apply_btn pressed do (
  undo "test" on (
   convertTo $ editable_poly
   fnChamferByEdgeSelection $ (r.chamfer_val.value)
  )
 )
)

You need to work with editable poly, so the script converts to.
I wrote this without testing it.
You can weld vertices, but what do you mean with mesh overlapping?

chooj's picture

Mesh Overlapping

Did you saw Modo "Meshfusion" in action? You can see it on Youtube. The tool is producing clean dynamic booleans with the ability to change chamfer radius on the fly. The mesh is welding to the borders of chamfer, so there in no mess. In 3d Max, even if I catch the border of boolean and try to do big chamfer, the mesh becomes very messy and unclean. So, I'm searching a way to solve this problem in maxscript.

TsveTan's picture

About the wanted edges...

To get the edges by vertices:

fn fnGetEdgesByVerts obj = (
 verts_array = polyop.getVertSelection obj
 edges = polyop.getEdgesUsingVert obj verts_array
 edges1 = copy edges
 For edge in edges1 Do (
  v = polyop.getVertsUsingEdge obj #{edge}
  For vert in v Do (
   If (findItem verts_array vert) == 0 Then (edges[edge] = false)
  )
 )
 return (edges) -- As bitArray
)
chooj's picture

thanks

Thanks, I will try this. Any thoughts about the second question?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.