Scripted Plugin with spline for clipping


Hi everyone, i got stuck in my code and maybe someone can give me a hint or has a solution for a simular task.

I wrote a scripted plugin that generates a wall of bricks and i want to have a picked spline to work as clipping line, projected from the side.
The splines will be simple, but not just a single line from left to right. Any shape should be possible, the image just gives an example.
There is no need to cut the bricks, clipping entire bricks would be enough.

What would be the best solution in terms of performance ?

Critic and comments welcome.


if you’re willing to test every mesh vert against the shape it probably wont be a quick process

t1=timestamp();hf = heapfree
	max create mode
	delete objects
	p = plane lengthsegments:35 widthsegments:17 wirecolor:orange
	convertToPoly p
	select p
	max modify mode
	subObjectLevel = 2
	polyop.setEdgeSelection p #{3}
	max create mode
	polyop.splitEdges p #all
	polyop.setFaceSelection p #all
	p.outlineAmount = -0.1
	addModifier p (shell innerAmount:1 outerAmount:0)
	convertToPoly p
	format "1. Time: %sec. Mem: %\n" ((timestamp()-t1)/1000 as float) (hf-heapfree)
	move p [10,10,0]
	rotate p (EulerAngles 0 0 7)

	c = circle radius:10 wirecolor:yellow pos:[-3,7,0]
	convertToSplineShape c

	cc = copy c pos:[25,15,0] scale:[0.7,0.25,1]
	addAndWeld c cc -1
	updateShape c
	format "2. Time: %sec. Mem: %\n" ((timestamp()-t1)/1000 as float) (hf-heapfree)
	itm = inverse c.transform

	asuptr = fn asuptr val = dotNetObject "System.UIntPtr" val
	g = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
	a = g.animatable.getanimbyhandle (asuptr (getHandleByAnim c))
	r = a.ObjectRef

	vsel = #{}
	p2 = g.point2.create()
	pGetVert = polyop.getVert
	for i=1 to numSplines c do
		sp = r.Shape_.getspline (i-1)
		spSurroundsPoint = sp.SurroundsPoint
		for i=1 to polyop.getNumVerts p do
			v = (pGetVert p i) * itm
			p2.x = v.x
			p2.y = v.y
			if spSurroundsPoint p2 do vsel[i] = true
	format "3. Time: %sec. Mem: %\n" ((timestamp()-t1)/1000 as float) (hf-heapfree)
	faces = polyop.getFacesUsingVert p vsel
	elem_faces = polyop.getElementsUsingFace p faces
	polyop.deleteFaces p elem_faces


format "4. Time: %sec. Mem: %\n" ((timestamp()-t1)/1000 as float) (hf-heapfree)


generating bricks with an angled face in the right position… creating from scratch is always better than trying to edit/correct/fix/cut existing mesh… it’s “cleaner” easier to code and quicker.


Yes correct, there for i try to find the intersecting lines of bricks and do the calculations just for the center of the quads.

Absolutely. The goal is to skip the generation of the clipped bricks, so they never been generated.

When using splines with only corner vertices, it seems to come down to a 2d intersection.