Notifications
Clear all

[Closed] Simple Plane Tool…

Well, thank you Dave for the tests, but unfortunately I still don’t have a clue. I’ll try it on another system as soon as I have a chance.

  • Enrico

Alright got the bug, but not the cause: if a single click is performed, case 2 in mouseMove is completely skipped, while on my machine is executed once (the odd thing). If case 2 is skipped, secondClick is not initialized, throwing the error. I changed again the clause for tool to stop on a single click and seems to work. Please let me know if it still has issues. Thanks.

tool bldgLot
(
    local thePlane, firstClick, secondClick, secondPos, tempTransform

    local lineNorm, pointVector, normCross, planeShift

    local theWidthSegs = 1
    local theLengthSegs = 1

    on mousePoint click do
    (
        if click == 1 then 
        (
            thePlane = Plane pos:gridPoint length:0 width:0 lengthSegs:1 widthSegs:1
            firstClick = [gridPoint.x, gridPoint.y, 0]
        )
    )

    on mouseMove click do
    (
        case click of
        (
            2: (
                secondClick = [gridPoint.x, gridPoint.y, 0]

                tempTransform = matrix3 1
                tempTransform = rotateZmatrix gridAngle.z
                tempTransform.row4 = (firstClick + secondClick) / 2
                
                thePlane.width = length [gridDist.x, gridDist.y]
                thePlane.transform = tempTransform
                
                secondPos = thePlane.pos
            )
            3: (
                -- stop the tool if a single click is performed
                if ( (thePlane.width == 0) or (secondClick == undefined) ) then
                (
                    delete thePlane
                    return #stop
                )
                
                -- set length as distance between line through first and second click pos
                -- and current mouse pos on grid 
                lineNorm = normalize(firstClick - secondClick)
                pointVector = gridPoint - secondClick
                thePlane.length = length(cross pointVector lineNorm)
                
                -- get vector perpendicular to line through first and second click pos
                -- and set plane pos as half the current mouse pos on grid projected on it
                normCross = normalize(cross lineNorm (cross pointVector lineNorm))
                planeShift = (normCross * (dot pointVector normCross)) / 2
                thePlane.pos = secondPos + planeShift
                
                theWidthSegs = int(thePlane.width / thePlane.length)
                if (theWidthSegs == 0) then
                    theWidthSegs = 1
                
                theLengthSegs = int(thePlane.length / thePlane.width)
                if (theLengthSegs == 0) then
                    theLengthSegs = 1
                
                thePlane.widthSegs = theWidthSegs
                thePlane.lengthSegs = theLengthSegs
            )
            4: (
               #stop
            )
        )
    )
)

startTool bldgLot
  • Enrico

Ah yeah, forgot to mention that bit. Yeah works now, cool!

I converted the script to a scripted plugin (extending the plane primitive). Put it in your plugin folder, then access it from create/geometry/fellers…


  Plugin geometry BldgLot
 	name:"BldgLot"
 	classID:#(0x701dedea, 0x795a2845)
 	category:"Fellers"
 	extends:Plane
 (
 	tool create
 	(
 		local startPoint, secondPoint, secondPos
 		on mousePoint click do
 			case click of
 			(
 				1: startPoint = nodeTM.translation = gridPoint
 				3: #stop
 			)
 		
 		on mouseMove click do
 			case click of
 			(
 				2:
 				(
 					delegate.width = abs(distance startPoint gridPoint)
 					nodeTM = rotateZMatrix gridAngle.z
 					nodeTM.translation = secondPos = (startPoint + gridPoint)/2
 					secondPoint = gridPoint
 				)
 				3: 
 				(
 					-- set length as distance between line through first and second click pos
 					-- and current mouse pos on grid 
 					lineNorm = normalize(startPoint - secondPoint)
 					pointVector = gridPoint - secondPoint
 					delegate.length = length(cross pointVector lineNorm)
 					
 					-- get vector perpendicular to line through first and second click pos
 					-- and set plane pos as half the current mouse pos on grid projected on it
 					normCross = normalize(cross lineNorm (cross pointVector lineNorm))
 					planeShift = (normCross * (dot pointVector normCross)) / 2
 					nodeTM.translation = secondPos + planeShift
 					
 					-- set subdivisions to be regular
 					if mod(delegate.width/delegate.length) 1 > .5 then (
 						theWidthSegs = int(delegate.width / delegate.length)+1
 					) else (
 						theWidthSegs = int(delegate.width / delegate.length)
 					)
 					if (theWidthSegs == 0) then theWidthSegs = 1
 					
 					if mod(delegate.length/delegate.width) 1 > .5 then (
 						theLengthSegs = int(delegate.length / delegate.width)+1
 					) else (
 						theLengthSegs = int(delegate.length / delegate.width)
 						--theLengthSegs = 10
 					)
 					if (theLengthSegs == 0) then theLengthSegs = 1
 					
 					delegate.widthSegs = theWidthSegs
 					delegate.lengthSegs = theLengthSegs
 				)
 			)
 	)--end tool
 )--end plugin

I am still new to maxscript, so let me know if you have any problems with it…

Page 2 / 2