scripted eye plugin

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 03 March 2013   #1
scripted eye plugin

I was thinking up some ideas on things to create in maxscript and here is my latest one. I've not spent a ton of time developing it yet. But just as a start feel free to check out what I have. Just run the script and then in the modify panel change one of the spinners.

You'll see it changes the geo to represent the inside of an eye.
There are many things that are obviously missing but like I mentioned it's just a start.

Once I get the inside working I'll add the outside shell part.
For now I need to do the following.

Take the modifier and turn it into a geometry plugin.
Give options for the user to chose segments and radius.
Options for adjusting the size of the inner black hole of the eye called the 'Pupil' which gives users the ability to adjust Dilation of the eye. Secondly give users the option to adjust the size of the 'Iris' the colored part of the eye.

wiki eye
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 03 March 2013   #2
Now that I've turned it into an actual geo plugin I'm going to first figure out how to create a sphere via maxscript with buildMesh



plugin simpleObject Eye name:"Eye"
category:"Standard Primitives"
classID:#(0x4184ae78, 0x4d53bef8)
version:1
(
	local eyeObject 
	
	parameters main rollout:params
	(	
		sides type:#integer default:16 ui:uiSides		
		segs type:#integer default:32 ui:uiSegments
		radius1 type:#float ui:uiEyeRadius1 default:0
		
		irisSize type:#float ui:uiIrisSize default:0
		pupilSize type:#float ui:uiPupilSize default:0
		pupilDepth type:#float ui:uiPupilDepth default:0
		dilation type:#float ui:uiDilation default:.5
	)
	
	rollout params "Parameters"
	(
		spinner uiSides "Sides" range:[2,100,16] type:#integer
		spinner uiSegments "Segments" range:[2,100,32] type:#integer
		spinner uiEyeRadius1 "Eye Radius:" range:[0,1e9,0] type:#worldunits
		spinner uiIrisSize "Iris Size:" range:[0,1e9,0] offset:[0,4] type:#worldunits
		spinner uiPupilSize "Pupil Size:" range:[0,1e9,0] type:#worldunits
		spinner uiPupilDepth "Pupil Depth:" range:[0,1e9,0] type:#worldunits
		spinner uiDilation "Dilation:" range:[0,1.0,.50] scale:.01 type:#float
	)
	
	fn genMesh = 
	(
	)
	
	on buildmesh do genMesh()

	tool create
	(
		on mousePoint click do case click of
		(
			1: coordsys grid (nodeTM.translation = gridPoint)
		)
		on mouseMove click do case click of
		(
			2: radius1 = amax (abs gridDist.x) (abs gridDist.y)
			3: (#stop)
		)
	)
	on update do genMesh()
)--end plugin

__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com

Last edited by JokerMartini : 03 March 2013 at 11:28 PM.
 
Old 03 March 2013   #3
generate verts to create sphere

The first part would be to generate the verts to create a sphere.

I'm not quite there yet.


(
	local segs = 10
	local sides = 8
	local radius1 = 20

	clearlistener()
	local zPos = 0.0
	
	for s = 0.0 to segs-1 do
	(
		for k = 0.0 to sides-1 do
		(
			ang = (360.0/sides) * k
			rad = 0 + (radius1 - 0)
			tm = rotateZ (transmatrix [rad,0,zPos]) ang
			pos = (tm * (matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0])).pos
			p = point pos:pos size:5 centermarker:true axistripod:false cross:false box:false wirecolor:yellow
		)
		zPos += (radius1/segs as float)*2
	)
)
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 03 March 2013   #4
ported from the sdk

fn mxssetedgevisflags m face flags =
  (	
  	setEdgeVis m  face 1 flags[1];
  	setEdgeVis m  face 2 flags[2];
  	setEdgeVis m  face 3 flags[3];
  )
  
  fn CreateSphere segs radius =
  (
	if segs < 4 then segs = 4; 

  	local rows	= segs/2 - 1;
  	local nverts = rows * segs + 2;
  	local nfaces = rows * segs * 2;
  	local delta = 360.0 / segs;
  	
  	msh = mesh numverts:nverts numfaces:nfaces;
  
  -- create the verts	
  	
  	local verti = 1;	-- vert index
  	setVert msh verti 0 0 radius; -- Top vertex 
  	verti += 1;
  	
  -- middle verts
  
  	alt = delta;	
  	for i = 1 to rows do 
  	(
  		a = (cos alt) * radius;		
  		secrad = (sin alt) * radius;
  		secang = 0.0; 
  		for j = 0 to segs - 1 do
  		(
  			b = (cos secang) * secrad;
  			c = (sin secang) * secrad;
  			setVert msh verti  b c a;
  			verti += 1;
  			secang += delta;
  		)
  		alt += delta;		
  	)
  	setVert msh verti 0 0 -radius; -- bottom vert
  
  
  -- create the faces	
  -- top cap
  
  	local facei = 1;	-- face index
  	for i =	1 to segs do
  	(
  		local nc = (if i == segs then 1 else i + 1)
  		mxssetedgevisflags msh facei #{1,2,3} 
  		setface msh facei [1,i + 1,nc + 1];
  		facei += 1;
  	)
  	
  -- middle faces	
  	
  	local lastseg = segs - 1;
  	for i = 1 to rows - 1 do
  	(
  		j = (i - 1) * segs + 1;
  		for k = 0 to segs - 1 do
  		(
  			na = j + k;
  			nb = na + segs;
  			nc = (if k == lastseg then j + segs else nb + 1);
  			nd = (if k == lastseg then j  else na + 1);
  			
  			mxssetedgevisflags msh facei #{1,2};
  			setface msh facei [na + 1,nb + 1,nc + 1];
  			facei += 1;
  			mxssetedgevisflags msh facei #{2,3};
  			setface msh facei [na + 1,nc + 1,nd + 1];
  			facei += 1;
  		)
  	)
  	
 -- bottom cap
 
  	na = nverts - 1;
  	j = (rows - 1)* segs + 1;
  	lastseg = segs - 1;
  
  	for i = 0 to segs - 1  do
  	(
  		nc = i + j;
  		nb = (if i == lastseg then j else nc + 1);
  		mxssetedgevisflags msh facei #{1,2,3};
  		setface msh facei [na + 1,nb + 1,nc + 1];
  		facei += 1;
  	)
  	
  	update msh;
  	msh
  )	
  
  CreateSphere 32 10

Last edited by Klunk : 03 March 2013 at 04:02 PM.
 
Old 03 March 2013   #5
with uv coords

-- how to create a sphere with maxscript, ported from the sdk

fn mxssetedgevisflags m face flags =
(	
	setEdgeVis m  face 1 flags[1];
	setEdgeVis m  face 2 flags[2];
	setEdgeVis m  face 3 flags[3];
)

fn CreateSphere segs radius genUVs =
(
	if segs < 4 then segs = 4; 
	
	local rows	= segs/2 - 1;
	local nverts = rows * segs + 2;
	local nfaces = rows * segs * 2;
	local delta = 360.0 / segs;
	local lastseg = segs - 1;
	
	msh = mesh numverts:nverts numfaces:nfaces;

-- create the verts	
	
	local verti = 1;	-- vert index
	setVert msh verti 0 0 radius; -- Top vertex 
	verti += 1;
	
-- middle verts

	alt = delta;	
	for i = 1 to rows do 
	(
		a = (cos alt) * radius;		
		secrad = (sin alt) * radius;
		secang = 0.0; 
		for j = 0 to lastseg do
		(
			b = (cos secang) * secrad;
			c = (sin secang) * secrad;
			setVert msh verti  b c a;
			verti += 1;
			secang += delta;
		)
		alt += delta;		
	)
	setVert msh verti 0 0 -radius; -- bottom vert

-- create the faces	
-- top cap

	local facei = 1;	-- face index
	for i =	1 to segs do
	(
		nc = (if i == segs then 1 else i + 1)
		mxssetedgevisflags msh facei #{1,2,3} 
		setface msh facei [1,i + 1,nc + 1];
		facei += 1;
	)
	
-- middle faces	
	
	for i = 1 to rows - 1 do
	(
		j = (i - 1) * segs + 1;
		for k = 0 to lastseg do
		(
			na = j + k;
			nb = na + segs;
			nc = (if k == lastseg then j + segs else nb + 1);
			nd = (if k == lastseg then j  else na + 1);
			
			mxssetedgevisflags msh facei #{1,2};
			setface msh facei [na + 1,nb + 1,nc + 1];
			facei += 1;
			mxssetedgevisflags msh facei #{2,3};
			setface msh facei [na + 1,nc + 1,nd + 1];
			facei += 1;
		)
	)
	
-- bottom cap	
	
	na = nverts - 1;
	j = (rows - 1) * segs + 1;
	for i = 0 to lastseg  do
	(
		nc = i + j;
		nb = (if i == lastseg then j else nc + 1);
		mxssetedgevisflags msh facei #{1,2,3};
		setface msh facei [na + 1,nb + 1,nc + 1];
		facei += 1;
	)
	
	if genUVs then
	(	
		meshop.defaultMapFaces msh 1
		
		local tvsegs = segs;
		local tvpts = segs; 
		local ntverts = (rows + 2) * (tvpts + 1);
		meshop.setNumMapVerts msh 1 ntverts;
		meshop.setNumMapFaces msh 1 nfaces; 
		alt = 0.0; 
		m1 = segs + 1;
		t1 = tvpts + 1;

-- create tverts
		
		mverti = 1;
		for i = 0 to rows + 1 do
		(
			secang = 0.0; --angle;
			yang = 1.0 - alt/180.0;
			for j = 0 to segs do
			(
				meshop.setMapVert msh 1 mverti [(secang/360.0), yang, 0.0];
				mverti += 1;
				secang += delta;
			)
			alt += delta;		
		)
		
-- top cap uvfaces
		
		mfacei = 1;
		for i = 0 to segs - 1 do
		(
			meshop.setMapFace msh 1 mfacei [i + 1,i + t1 + 1, i + t1 + 2] 
			mfacei += 1;
		) 
		
		local cpt;
-- Make midsection uv faces
		for i = 1 to rows - 1 do
		(
			cpt = i * t1;
			for k = 0 to segs - 1 do
			(
				if k == segs then cpt += 1;
				na = cpt + k;
				nb = na + t1;
				nc = nb + 1;
				nd = na + 1;
				meshop.setMapFace msh 1 mfacei [na + 1,nb + 1,nc + 1] 
				mfacei += 1;
				meshop.setMapFace msh 1 mfacei [na + 1,nc + 1,nd + 1] 
				mfacei += 1;
			)
		)

-- end cap uvfaces
		
		lastv = rows * t1;
		j = lastv + t1;
		for k = lastv to lastv + segs - 1 do
		(
			meshop.setMapFace msh 1 mfacei [j + 1,k + 2,k + 1] 
			mfacei += 1;
			j += 1;
		)
	)	
	
	update msh;
	msh
)	

CreateSphere 12 10 true
 
Old 03 March 2013   #6
I've got a much cleaner and simpler version coming soon.
Later today.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 03 March 2013   #7
Sphere

This creates a sphere of verts. Just go to the display panel and turn on ticks.
I'm working on getting the Meshing of the faces to work properly.


plugin simpleObject SpherePlus name:"Sphere Plus"
category:"Standard Primitives"
classID:#(0x68b2b559, 0x7b555bd2)
version:1
(
	local eyeObject 
	
	parameters main rollout:params
	(	
		rows type:#integer default:8 ui:uiRows		
		columns type:#integer default:12 ui:uiColumns
		radius1 type:#float ui:uiRadius1 default:0
		radius2 type:#float ui:uiRadius2 default:0
		radius3 type:#float ui:uiRadius3 default:0
	)
	
	rollout params "Parameters"
	(
		spinner uiRows "Rows" range:[1,100,16] type:#integer
		spinner uiColumns "Columns" range:[3,100,32] type:#integer
		spinner uiRadius1 "Radius X:" range:[0,1e9,0] type:#worldunits
		spinner uiRadius2 "Radius Y:" range:[0,1e9,0] type:#worldunits
		spinner uiRadius3 "Radius Z:" range:[0,1e9,0] type:#worldunits
	)
	
	-- function for creating faces
	-- OPTIONS: mesh, face index, vertices as point3, material id
	fn createface msh fcndx vrts edgvis faceid = 
	(	
		local edg
		setface msh fcndx [vrts.x, vrts.y, vrts.z]
		if edgvis.x == 1 then edg = true else edg = false
		setedgevis msh fcndx 1 edg
		if edgvis.y == 1 then edg = true else edg = false
		setedgevis msh fcndx 2 edg
		if edgvis.z == 1 then edg = true else edg = false
		setedgevis msh fcndx 3 edg
		setfacesmoothgroup msh fcndx 0
		setfacematid msh fcndx faceid
	)
	
	fn genMesh = 
	(
		local vertCount = (rows+2 )* columns
		local facesCount = rows * columns + columns
		local spherical = #()
		local rowAngle = 180.0 / (rows+1)
		local columnAngle = 360.0 / columns
		
		tmesh = trimesh()
		setmesh tmesh numverts:vertCount numfaces:facesCount
		
		/*Set Verts*/
		local varVertCount = 1
		for h = 1 to (rows+2) do
		(
			for v = 1 to columns do
			(									
				calcX = radius1 * cos((v-1) * columnAngle) * sin((h-1)*rowAngle)
				calcY = radius2 * sin((v-1)* columnAngle) * sin((h-1)*rowAngle)
				calcZ = radius3 * cos((h-1) * rowAngle)
				
				pos = [calcX,calcY,calcZ] + [0,0,0] --include nodes matrix
				
				setvert tmesh varVertCount pos
				varVertCount += 1
			)
		)
		
		/*Set Faces*/
-- 		local curVert = 1
-- 		local curFace
-- 		local colCheck = 1
-- 		
-- 		for curFace = 1 to facesCount by 2 do 
-- 		(		
-- 			if colCheck == columns then 
-- 			(
-- 				colCheck = 0
-- 				conVert = curVert - (colCheck - 1)
-- 				createface tmesh curFace [curVert, curVert + colCheck, conVert + colCheck] [1, 1, 0] 1
-- 				createface tmesh (curFace + 1) [conVert + colCheck, conVert, curVert] [1, 1, 0] 1
-- 			) 
-- 			else 
-- 			(
-- 				createface tmesh curFace [curVert, curVert + colCheck, curVert + colCheck + 1] [1, 1, 0] 1
-- 				createface tmesh (curFace + 1) [curVert + colCheck + 1, curVert + 1, curVert] [1, 1, 0] 1
-- 			)
-- 			curVert += 1
-- 			colCheck += 1
-- 		)
		
		/*Set Mesh*/
		setmesh mesh tmesh
		
		/*Weld Polars*/
		local weldBottomVerts = for i = vertCount to (vertCount - columns) by -1 collect i
		meshop.weldvertset mesh weldBottomVerts --weld end verts first because it changes the vert count
		local weldTopVerts = for i = 1 to columns collect i
		meshop.weldvertset mesh weldTopVerts
	)
	
	on buildmesh do genMesh()

	tool create
	(
		on mousePoint click do case click of
		(
			1: coordsys grid (nodeTM.translation = gridPoint)
		)
		on mouseMove click do case click of
		(
			2: radius1 = radius2 = radius3 = amax (abs gridDist.x) (abs gridDist.y)
			3: (#stop)
		)
	)
)--end plugin
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 03 March 2013   #8
you can have cleaner code but not such a clean result.

 if genUVs then
	(
		meshop.applyUVWMap msh #spherical
	)	
 
Old 03 March 2013   #9
I meant cleaner in regards to what I had written earlier that I was going to post. Not what you had.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 03 March 2013   #10
Thread automatically closed

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.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:56 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.