Notifications
Clear all

[Closed] Please help me with my rough scripted shell modifier

Hi, since a while I’m trying to figure out the way to make a custom shell modifier, basically I need to do a “multi-layer” shell with straight corners (I have to apply it on hard surfaces and I need constant thickness) and the lack of an option to shell a selected face is forcing me to make my own tool.

I made this rough script but my knowledge on math and coding is very basic so I’m screaming for help because I really need this.

 
plugin simpleMeshMod TheShell01
	name:"ShellTEST 01"
	classID:#(0x39BBE432, 0x320D6842)
	category:"OTHERS"
	usePBValidity:true
(
	parameters main rollout:params
	(
		offSetValue type:#float ui:offValue
	)
		
	rollout params "Parameters"
	(
		Spinner offValue "Amout: " range:[1,1000,0]
	)
	
	on modifyMesh do
	(
		local theMesh = copy mesh
		
		--This copy will be used as the other face of the mesh
		local offMesh = copy mesh
		local numVerts = getNumVerts offMesh
		
		for nVert = 1 to numVerts do 
		(
			
			--------------------------------------------------------------------------------
			vertFaces = meshOp.getFacesUsingVert offMesh nVert
			Facesnormals = #()
			for i in vertFaces do
			(
				currentFace = getFaceNormal theMesh i
				/*
				I collect only unique normal values because equal vectors will affect the
				average when divided into total amount, unless I do some weighted average
				*/
				appendIfUnique FacesNormals currentFace
			)
			tNormal = [0,0,0]
			for n in FacesNormals do ( tNormal +=n )
			
			--current vertex resulting offset direction (normalized)
			CurrentVertNormal = normalize( tNormal / FacesNormals.count )
			--------------------------------------------------------------------------------
			
			VertPOS = ( meshop.getVert offMesh nVert )
			
			--Applying distance to the new direction of the current vertex
			ScaledVertNormal = CurrentVertNormal*OffsetValue
			
			--Dot product between new direction vector and any normal of a face using this vertex
			--the resulting factor should be applied to the distance of the new vertex direction 
			--(diagonal) so the the thickness of the mesh equals the OffsetValue. (I think)
			dotV = dot CurrentVertNormal FacesNormals[1]
			ScaledVertNormal = (CurrentVertNormal*OffsetValue)/dotV
			
			--Translate current vertex to the new distance at new direction
			newVertPos = ( VertPos + ScaledVertNormal ) --*theMesh.transform
			meshop.setVert offMesh nVert ( newVertPos )
		)
		
		--Adjust normals of the two meshes
		if offsetValue > 0 then
		(
			meshop.flipNormals theMesh #{1..theMesh.numfaces} 
		)else
		(
			meshop.flipNormals offMesh #{1..offMesh.numfaces}
		)
		
		--collect open edges so I can stitch them 
		openEdges1 = (meshop.getOpenEdges theMesh) as array
		edgesCount = openEdges1.count
		
		meshOp.attach theMesh offMesh
		
		openEdges2 = (meshop.getOpenEdges theMesh) as array
		for n = 1 to edgesCount do (deleteItem openEdges2 1)
		
		for nEdg = 1 to edgesCount do 
		(
			--Edge by edge loop to make the stitch
			eV1 = meshop.getVertsUsingEdge theMesh openEdges1[nEdg] as array
			eV2 = meshop.getVertsUsingEdge theMesh openEdges2[nEdg] as array
			
			meshop.createPolygon theMesh ( eV1 + #(eV2[2]) + #(eV2[1]) )
			
			--unify normals because my code is not well resolved
			meshop.unifyNormals theMesh #{1..theMesh.numfaces}
		)
		
		setMesh mesh TheMesh
	)
	
)




My question is
Could you please help me to improve the result?
Could you please help me to make it work faster?
Could you please help me to translate it into MCG (I still don’t get that stuff, I guess It would be better but I find it to disruptive for my brain)
I really really thanks you for ANY help

1 Reply

Ok, I’m guessing this is not an interesting post.
Could anyone please tell me how can I get a function similar to “meshOp.getFacesUsingVert” in MCG, or where to read about it?
If at least would be possible to have decent help file for this tool…