skew Mod - recreate


#7

not sure why that would differ from what is being done right now…


#8

you can optimize your algorithm and do most of calculations and the case expression only one time…


#9

I not sure I can see where to optimize other than moving a few of the items out of the case other than this

theDirMatrix = rotateZMatrix -skewDirection

How do I use the modifiers bounding box?
By using extent?


#10

getModContextBBoxMin and getModContextBBoxMax


#11

I looked into your twist modifier to see if that helped explain anything.


#12

Below is a duplication of the bend Modifier from max thanks to Bobo.
What is the difference between using ‘extent’ vs ‘boundingbox’?


plugin simpleMod myMod
 name:"MyMod"
 classID:#(0x6166ee57, 0x5ac74d41)
 version:1
 ( 
	parameters main rollout:params
	(
		amount type:#float ui:spn_amount default:0
		direction type:#float ui:spn_direction default:0	
		axis type:#integer ui:rad_axis default:3
	)
	 
	rollout params "MyBend Parameters"
	(
		spinner spn_amount "Amount: " range:[-100000,100000,0] scale:1
		spinner spn_direction "Direction: " range:[-100000,100000,0] scale:1
		radiobuttons rad_axis "Axis:" labels:#("X","Y","Z")
	)

	on map i p do
	(
		if amount != 0 then
		(
			case axis of
			(
				1: (
					theDirMatrix = rotateXMatrix -direction
					theRadius = 180/amount*extent.x/Pi
					theRadiusOffset = [0,0,-theRadius] * theDirMatrix 				
					TM = rotateYMatrix (amount*p.x/extent.x) * theDirMatrix
					TM.row4 = theRadiusOffset
					(([0,p.y,p.z]-theRadiusOffset)*inverse theDirMatrix) * TM 			
					)
				2: (
					theDirMatrix = rotateYMatrix -direction
					theRadius = 180/amount*extent.y/Pi
					theRadiusOffset = [theRadius,0,0] * theDirMatrix 				
					TM = rotateZMatrix (-amount*p.y/extent.y) * theDirMatrix
					TM.row4 = theRadiusOffset
					(([p.x,0,p.z]-theRadiusOffset)*inverse theDirMatrix) * TM 
					)
				default: (
					theDirMatrix = rotateZMatrix -direction
					theRadius = 180/amount*extent.z/Pi
					theRadiusOffset = [theRadius,0,0] * theDirMatrix 				
					TM = rotateYMatrix (amount*p.z/extent.z) * theDirMatrix
					TM.row4 = theRadiusOffset
					(([p.x,p.y,0]-theRadiusOffset)*inverse theDirMatrix) * TM 
					)	
			)	
		)
		else p
	)
 )
 
delete objects
c = cylinder radius:20 height:40 heightsegs:8 sides:8 wirecolor:orange pos:[0,0,0] rotation:(eulerangles 0 0 0)
addmodifier (converttopoly c) (MyMod amount:65 axis:3) 
select c


#13

for simple modifier is better to use predefined min and max locals… i’ve just forgot about them.


#14

I cleaned up the code a bit and this is my final version.
Any improvements you may see on top of this would be something new to me and I’d be glad to see them.


delete objects
plugin simpleMod skewy
name:"skewy"
classID:#(0x6b15953d, 0xb0cf3d07)
version:1.1
( 
	parameters main rollout:main
	(
		skewAxis type:#integer ui:uiSkewAxis default:3
		skewAmount type:#worldUnits ui:uiSkewAmount default:0
		skewDirection type:#float ui:uiSkewDirection default:0
	)

	rollout main "MyBend Parameters"
	(
		group"Skew"
		(
			radiobuttons uiSkewAxis "" labels:#("X","Y","Z") columns:3 align:#center offset:[0,0]
			spinner uiSkewAmount "Amount: " type:#worldUnits range:[-1e9,1e9,0] scale:.01 offset:[0,4]
			spinner uiSkewDirection "Direction: " range:[-1e9,1e9,0] scale:1
		)
	)

	on map i p do
	(
		case skewAxis of
		(
			1: (
				theDirMatrix = rotateXMatrix -skewDirection
				skewVal = (skewAmount*p.x/extent.x)
				skewOffset = [0,0,skewVal] * theDirMatrix 		
				p += skewOffset			
			)
			2: (
				theDirMatrix = rotateYMatrix -skewDirection
				skewVal = (skewAmount*p.y/extent.y)
				skewOffset = [0,0,skewVal] * theDirMatrix 		
				p += skewOffset
			)
			default: (
				theDirMatrix = rotateZMatrix -skewDirection
				skewVal = (skewAmount*p.z/extent.z)
				skewOffset = [0,skewVal,0] * theDirMatrix 		
				p += skewOffset	
			)	
		)	
	)
)

m = cylinder height:60 heightsegs:20 radius:5 sides:4 wirecolor:yellow
addmodifier m (Skewy()) 
select m


#15

nope… it’s not right either.


#16

where did you find this sample?


#17

Ahhhh!!!

Haha. You’ll have to show me what is wrong then since I’m not seeing it .


#18

you test your code probably for cylinder only. it’s specific case where center of deformation at the bottom of the mesh and zero position. try the code for a sphere and try to mach to the built-in skew.

‘my bend’ is also not correct. it doesn’t match what the built-in bend does do.

and as i said… for both modifiers you can do ‘case’ only once.


#19

This sample was posted here on cgtalk by Bobo , answering someone making a bend mod.


#20

I’ll have to mess with it tomorrow. I do not see any problems off hand.


#21

about using only one case… it’s so obvious! how do you not see it?! you can do it JUST FOR FIRST VERTEX ONLY!


#22

attempt but failed…
I thought I was going in the right direction but not so much…


delete objects
plugin simpleMod skewy
name:"skewy"
classID:#(0x6b15953d, 0xb0cf3d07)
version:1.1
( 
	parameters main rollout:main
	(
		skewAxis type:#integer ui:uiSkewAxis default:3
		skewAmount type:#worldUnits ui:uiSkewAmount default:0
		skewDirection type:#float ui:uiSkewDirection default:0
	)

	rollout main "MyBend Parameters"
	(
		group"Skew"
		(
			radiobuttons uiSkewAxis "" labels:#("X","Y","Z") columns:3 align:#center offset:[0,0]
			spinner uiSkewAmount "Amount: " type:#worldUnits range:[-1e9,1e9,0] scale:.01 offset:[0,4]
			spinner uiSkewDirection "Direction: " range:[-1e9,1e9,0] scale:1
		)
	)

	on map i p do
	(
 		skewVal = (skewAmount*p/extent) --* theDirMatrix
		p += (case skewAxis of
			(
				1:	([0,0,skewVal[skewAxis]] * (rotateXMatrix -skewDirection))
				2:	([0,0,skewVal[skewAxis]]  * (rotateYMatrix -skewDirection))
				3:	([0,skewVal[skewAxis],0] * (rotateZMatrix -skewDirection))
			)
		)
	)
)

m = sphere radius:10-- height:60 heightsegs:20 radius:5 sides:4 wirecolor:yellow
addmodifier m (Skewy()) 
select m


#23

i cleaned up bend code… as i said there is no reason to recalculate some constants for every point.
there is away how to do it only once when any parameter changes value:


   plugin simpleMod Bend1D
   	name:"Bend1D"
   	classID:#(0x00001967, 0x001182ab)
   (
   	parameters main rollout:main 
   	(
   		angle type:#float ui:ui_angle default:0
   		axis type:#integer ui:ui_axis default:3
   		direction type:#float ui:ui_direction default:0
   	)
   	
   	rollout main "Parameters"
   	(
   		group "Bend: "
   		(
   			spinner ui_angle "Angle: " range:[-1e9,1e9,0] type:#float fieldwidth:64 align:#rigth offset:[4,0]
   			spinner ui_direction "Direction: " range:[-1e9,1e9,0] type:#float scale:0.1 fieldwidth:64 align:#rigth offset:[4,-1]
   		)
   		group "Bend Axis: "
   		(
   			radiobuttons ui_axis labels:#("X   ", "Y", "Z") columns:3 align:#left offset:[20,0]
   		)
   	)
   	local last, value, dirMatrix, factor, rotateMatrix
   	on map i p do if angle == 0 then p else
   	(
   		if value == undefined or last != [angle,direction,axis] do 
   		(
   			factor = angle/extent
   			radius = (180.0/pi/factor)[axis]
   			
   			case axis of
   			(
   				1: 
   				(
   					dirMatrix = rotateXMatrix -direction
   					value = [0,0,-radius]*dirMatrix 
   					rotateMatrix = rotateYMatrix
   				)
   				2: 
   				(
   					dirMatrix = rotateYMatrix -direction
   					value = [radius,0,0] * dirMatrix 				
   					rotateMatrix = rotateZMatrix
   					factor = -factor
   				)
   				default: 
   				(
   					dirMatrix = rotateZMatrix -direction
   					value = [radius,0,0]* dirMatrix 				
   					rotateMatrix = rotateYMatrix
   				)				
   			)
   			last = [angle,direction,axis]
   		)
   		tm = translate ((rotateMatrix (factor*p)[axis]) * dirMatrix) value
   		p[axis] = 0
   		(p - value)*(inverse dirMatrix)*tm
   	)
   )
   

PS. original Bobo’s algorithm shown above is absolutely right.

EDIT: some bug fixed


#24

Is my latest version of the skew mod closer to what you were directing me towards.


#25

Any more suggestions?


#26

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.