Notifications
Clear all

[Closed] innacuracies with intersectray for mesh cleanup

Hi Folks,

I’m working on a job at the moment with obj files of a car from the makers – I haven’t gotten any iges files and I’ve no way to deal with them. The mesh itself is fairly dirty and since the ad i’m working on is completely based around very close up shots of the car with the footage being reflected in its surface, it’s looking very bumped and broken in places due to the nasty triangulation of the cad model. What i’ve done is written a script where I can model an ideal quad layout in a side view and then use my script to project its vertices along a selected axis to wrap it over the car surface so I get the accurate shape of the car but with a mesh I can turbosmooth easily. What I’m finding though is that in some cases the intersect isn’t that accurate – here’s my mesh before:

and after:

As you can see even though the verts line up and should hit the mesh along the x axis, they aren’t going into place correctly. Any thoughts on why this might be?

Here’s the code, any other suggestions are appreciated – I’m not a full time coder, just mash stuff together as needed.

macroScript ProjectMesh category:"Johns bits (snigger)" tooltip:"Project the verts of one mesh to another"
 (
 
 	------------------------------------------------------------- Set up globals 
 	
 	global theDir = undefined
 	
 	print thedir
 
 
 	------------------------------------------------------------- Function Bits 
 	
 	fn MeshFilter obj = classof obj == Editable_mesh
 	fn GeomFilter obj = superClassof obj == GeometryClass
 	
 	fn MeshProject Obj Target Dir = (
 	
 		
 		-- Get a count of the vertices in the object
 		
 		theVertCount = meshop.getNumVerts Obj
 		
 		-- Make a loop for the amount of vertices
 		
 		disableSceneRedraw()
 		
 		-- Begin progress bar
 		
 		progressStart "Moving vertices"
 		escapeEnable = false
 		itemnum = theVertCount
 		curitem = 0
 		
 		for i = 1 to theVertCount do (
 		
 			-- Loop for each vertex and fire a ray from the position of the current vert to the target surface
 			
 			theVertPos = meshop.getvert Obj i
 			theRay = ray theVertPos Dir
 			
 			theIntersect = intersectRay Target theRay
 			
 			if (theIntersect != undefined) then (
 			
 				print (theIntersect.pos)
 				
 				-- Set the position of the vert to the intersection of the ray
 				
 				meshop.setvert theObj i theIntersect.pos
 			
 			) else (
 			
 				Print ("Vertex " + i as string + " hasn't intersected along axis " + Dir as string)
 			
 			)
 			
 			-- Update progress bar
 			
 			curitem += 1
 			
 			total_progress = ((curitem as float)/(itemnum as float))*100
 			
 			gc()
 			progressUpdate total_progress
 		
 		)
 		
 		progressEnd()
 		
 		enableSceneRedraw()			
 		completeRedraw()
 	
 	-- Done
 	
 	)
 	
 	-- End Function
 	
 	------------------------------------------------------------- Test Bits 
 	
 	/*
 	
 	theObj = $
 	
 	-- Assign a target object
 	
 	theTarget = $sphere01
 	
 	-- Assign a vector to trace along (negative z here)
 	
 	theDir = [0,0,-1]
 	
 	-- test the function
 	
 	MeshProject theObj theTarget theDir
 	
 	*/
 	
 	------------------------------------------------------------- Ui Bits
 	
 	rollout ProjectMesh "Mesh Projection"
 	(
 		
 		group "Object Setup"
 		(
 			PickButton projObj "Projection object" width:200 filter:MeshFilter align:#left
 			PickButton targetObj "Target Object" width:200 filter:GeomFilter align:#left 
 		)
 		
 		group "Axis Setup"
 		(
 			dropDownList axisType "Axis Type" items:#("World Coordinate","Objects local X Axis") align:#left			
 			radioButtons projDir "Projection Direction" labels:#("X","Y","Z","-X","-Y","-Z") width:150 default:0 align:#left
 			PickButton axisRefObj "Objects Local X" width:200 align:#left enabled:false
 		)
 		
 		
 		
 		Button projMesh "Project Mesh" align:#left width:200 enabled:false
 		
 		-- Picking the object to mess up
 		
 		on projObj picked obj do
 		(
 			if targetObj.object != undefined do
 			(
 				projMesh.enabled = true
 			)
 			
 			projObj.text = projObj.object.name
 			
 			global theObj = projObj.object
 		)
 		
 		-- Picking the object to target
 		
 		on targetObj picked obj do
 		(
 			if projObj.object != undefined do
 			(
 				projMesh.enabled = true
 			)
 			
 			targetObj.text = targetObj.object.name
 			
 			global theTarget = targetObj.object
 		)
 		
 		-- Projection direction bumph
 		
 		on axisType selected axis do
 		(
 			case axis of
 			(
 				1:(
 					projdir.enabled = true
 					axisRefObj.enabled = false
 				)
 				2:(	
 					projdir.enabled = false
 					axisRefObj.enabled = true
 				)
 			
 			
 			)
 		)
 		
 		on projDir changed state do (
 		
 			case projdir.state of 			
 			(
 				1: (global theDir = [1,0,0])
 				2: (global theDir = [0,1,0])
 				3: (global theDir = [0,0,1])
 				4: (global theDir = [-1,0,0])
 				5: (global theDir = [0,-1,0])
 				6: (global theDir = [0,0,-1])
 			)
 			
 			print ("The projection direction is set to " + theDir as string)
 		)
 		
 		-- 
 		
 		on axisRefObj picked obj do
 		(		
 			axisRefObj.text = axisRefObj.object.name
 			global theDir = axisRefObj.object.transform[1]
 		)
 		
 		-- Run script
 		
 		on projMesh pressed do
 		(	
 			if (theDir == defined) then
 			(
 			
 				messageBox "Pick a direction to project along first!" title:"Axis not defined"
 				
 			) else (
 			
 				print ("projecting along " + theDir as string)
 				MeshProject projObj.object targetObj.object theDir
 				
 			)
 		)
 		
 	)
 	
 	createDialog ProjectMesh width:300
 	
 	
 )
 
2 Replies

False alarm, there was more mesh hidden and i’m an idiot

yay, something to do with mesh optimization. I can always approve to that. here is my tool for just such thing (yeh ok it’s incomplete). Just recently added similar feature there too. Works on active viewport z axis.