Notifications
Clear all

[Closed] Progress Bar Display, why does it break my loop?

I’ve got a function that loops through 2 Edit Poly objects and transfers normal vectors from one to the other. The objective is to change the normal vectors of a tree asset so that it lights like a volume rather than a bunch of cards.

The loop works as expected, but is kind of slow so I thought I would track progress on the progress bar. I realize there are probably many ways to speed up the function, probably to the point of where I wouldn’t even need the progress bar.

Either way, I would like to use the progress bar in other scripts i’ve written but i’m hesitant because its hard to tell what its actually doing.

For instance, if you run the TransferNormalVectors function below with the 3 progressbar functions commented out, the function runs as expected. However, if you run the script so that it updates the progress bar it appears to do the loop, but the normals are not updated to a new position.

--Make a "tree" (mySphere) and a lightingObj (mybox)
Mybox = box lengthsegs:20 widthsegs:20 heightsegs:20	
convertTo Mybox editable_poly
MySphere = sphere Segments:30
convertTo MySphere editable_poly



--Ment to light trees (a bunch or randomly facing cards) like volumes, transfers normals from LightinObj (the volume to simulate) to Obj, the tree cards
function TransferNormalVectors obj lightingObj = (
	AllMyVerts = polyop.getNumVerts obj   	 	--Get Number of faces in the mesh
	AllLightObjFaces = polyop.getNumFaces lightingObj
	addmodifier obj (edit_normals())
	ProgressStart "Transfering Normals"

	For vert=1 to AllMyVerts do(					--Looping through the faces
		ClosestFace = 0
		ShortestDistance = Undefined
		PercentDone = 100*vert/AllMyVerts
		progressUpdate PercentDone		---Update Progress Bar
		For face=1 to AllLightObjFaces do (
			ThisDistance = distance (polyop.getFaceCenter lightingObj face) (polyop.getVert obj Vert)
			if ShortestDistance == Undefined or ThisDistance < ShortestDistance do (
				ShortestDistance = ThisDistance
				closestFace = face
			)
		)
		NewVector = (polyop.getFaceNormal lightingObj ClosestFace)		--get the vector
		MyVerts = #{vert}
		VertNormals = #{}
		obj.modifiers[#Edit_Normals].ConvertVertexSelection MyVerts VertNormals
		For N in VertNormals do (
			obj.modifiers[#Edit_Normals].SetNormal N NewVector
		)
	)
	progressEnd()
)


TransferNormalVectors $ Mybox  ---Select the sphere then run this line

Is the progress bar actually breaking this? Or is it the way i’m trying to use the Edit Normals modifier? I don’t have a good understanding of how to update the normal positions in max, or what max is doing while the progress bar is being update…is it disabling the UI, or turning off redraw?

Thanks Guys
SLueb

1 Reply

when progress starts it set modpanel to suspended mode. Edit_Normals modifier works only if it’s the current modpanel’s object and the editing is not suspended.

use rollout’s progressbar control and everything will be ok.

[color=lemonchiffon](but your algorithm can’t work right anyway. Poly Face normal and Edit_Normal normal are in different coord systems. You can’t just directly apply a face normal value as an edit normal). [/color]