Scripted Helper 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 02 February 2013   #1
Scripted Helper Plugin

thought I would post a quick template of a scripted helper plugin I use.... Apologies to those for whom this is "old hat". The build mesh code is generate by a very simple script from modelled mesh (size = 1.0 as it were) obviously the circle would be more elegant generated from sin cos loop giving segement control but inline is quick and dirty. Anyho hope it's a help to someone.

plugin Helper template
  	name:"template"
  	classID:#(0x68021915, 0x62747765)
  	category:"My Helpers"
  	extends:point
  	replaceUI:true;
  (
  	local lastSize, lastRadius, msh = trimesh();
  
  --**************************************************  ********************************	
  	
  	parameters main rollout:params
  	(
  		radius	type:#float ui:radius_spnr default:10.0;
  	)
  
  --**************************************************  ********************************	
  	
  	tool create
  	(
  		on mousePoint click do
  		(	
  			case click of
  			(
  				1: nodeTM.translation = worldPoint
  				2: #stop
  			)
  		)
  		on mouseMove click do	
  		(	
  			if click == 2 then
  			(
  				radius = distance 	nodeTM.translation worldPoint;
  			)	
  		)
  	)
  	
  --**************************************************  ********************************	
  	
  	fn mxssetedgevisflags m face flags =
  	(	
  		setEdgeVis m  face 1 flags[1];
  		setEdgeVis m  face 2 flags[2];
  		setEdgeVis m  face 3 flags[3];
  	)
  
  --**************************************************  ********************************	
  	
  	fn BuildMesh =
  	(
  		setNumVerts msh 20;
  		setNumFaces msh 18;
  		setvert msh 1 ([1,0,0] * radius);
  		setvert msh 2 ([0.921345,0.389035,0] * radius);
  		setvert msh 3 ([0.70692,0.70692,0] * radius);
  		setvert msh 4 ([0.389035,0.921345,0] * radius);
  		setvert msh 5 ([0,1,0] * radius);
  		setvert msh 6 ([-0.389035,0.921345,0] * radius);
  		setvert msh 7 ([-0.70692,0.70692,0] * radius);
  		setvert msh 8 ([-0.921345,0.389035,0]* radius);
  		setvert msh 9 ([-1,0,0] * radius);
  		setvert msh 10 ([-0.921345,-0.389035,0] * radius);
  		setvert msh 11 ([-0.70692,-0.70692,0] * radius);
  		setvert msh 12 ([-0.389035,-0.921345,0] * radius);
  		setvert msh 13 ([0,-1,0] * radius);
  		setvert msh 14 ([0.389035,-0.921345,0] * radius);
  		setvert msh 15 ([0.70692,-0.70692,0] * radius);
  		setvert msh 16 ([0.921345,-0.389035,0] * radius);
  		setvert msh 17 ([0,0,0.142481] * delegate.size);
  		setvert msh 18 ([0.100797,0,0] * delegate.size);
  		setvert msh 19 ([-0.0503983,0.0872924,0] * delegate.size);
  		setvert msh 20 ([-0.0503983,-0.0872924,0] * delegate.size);
  		setface msh 1 [12,13,14];
  		setface msh 2 [5,6,7];
  		setface msh 3 [4,5,7];
  		setface msh 4 [3,4,7];
  		setface msh 5 [2,3,7];
  		setface msh 6 [1,2,7];
  		setface msh 7 [16,1,7];
  		setface msh 8 [15,16,7];
  		setface msh 9 [15,7,8];
  		setface msh 10 [15,8,9];
  		setface msh 11 [15,9,10];
  		setface msh 12 [15,10,11];
  		setface msh 13 [14,15,11];
  		setface msh 14 [12,14,11];
  		setface msh 15 [17,18,19];
  		setface msh 16 [17,19,20];
  		setface msh 17 [17,20,18];
  		setface msh 18 [18,20,19];
  		mxssetedgevisflags msh  1 #{1..2};
  		mxssetedgevisflags msh  2 #{1..2};
  		mxssetedgevisflags msh  3 #{1};
  		mxssetedgevisflags msh  4 #{1};
  		mxssetedgevisflags msh  5 #{1};
  		mxssetedgevisflags msh  6 #{1};
  		mxssetedgevisflags msh  7 #{1};
  		mxssetedgevisflags msh  8 #{1};
  		mxssetedgevisflags msh  9 #{2};
  		mxssetedgevisflags msh  10 #{2};
  		mxssetedgevisflags msh  11 #{2};
  		mxssetedgevisflags msh  12 #{2};
  		mxssetedgevisflags msh  13 #{1};
  		mxssetedgevisflags msh  14 #{3};
  		mxssetedgevisflags msh  15 #{1..3};
  		mxssetedgevisflags msh  16 #{1..3};
  		mxssetedgevisflags msh  17 #{1..3};
  		mxssetedgevisflags msh  18 #{1..3};
  		update msh
  	)
  	
  --**************************************************  ********************************	
  -- returns this node	
  
  	fn getNode = refs.dependentnodes this firstonly:on
  	
  --**************************************************  ********************************	
  
  	rollout params "Params"
  	(
  		spinner size_spnr "Size:" range:[0, 100000000.0, delegate.size ] fieldwidth:48 type:#float align:#center;
  		on size_spnr changed val do delegate.size = val;
  		spinner radius_spnr "Radius:" range:[0, 1e9, 0] fieldwidth:48 type:#float align:#center;
  	)		
  
  --**************************************************  ********************************	
  	
  	on create do buildmesh();
  
  --**************************************************  ********************************	
  	
  	on getDisplayMesh do 
  	(
  		if delegate.size != lastSize do 
  		(
  			buildmesh();
  			lastSize = delegate.size;
  		)
  		if radius != lastRadius do 
  		(
  			buildmesh();
  			lastRadius = radius;
  		)
  		msh;
  	)
  )
  
  --**************************************************  ********************************
  

Last edited by Klunk : 02 February 2013 at 07:23 PM.
 
Old 02 February 2013   #2

    plugin Helper template
 	  name:"template"
 	  classID:#(0x68021915, 0x62747765)
 	  category:"My Helpers"
 	  extends:point
 	  replaceUI:true;
 (
 	local _radius, _segs, _mesh
 	fn getNode = refs.dependentnodes this firstonly:on
 
 	parameters main rollout:params
 	(
 		radius	type:#float ui:radius_spnr default:10.0
 		segs	type:#integer ui:segs_spnr default:16
 	)
 	rollout params "Params"
 	(
 		spinner radius_spnr "Radius:" range:[0, 1e9, 0] fieldwidth:48 type:#float
 		spinner segs_spnr "Segments:" range:[3, 1e9, 16] fieldwidth:48 type:#integer
 	)		
 	tool create
 	(
 		on mousePoint click do case click of
 		(
 			1: 
 			(
 				nodeTM.translation = gridPoint
 				radius = 0
 			)
 			2: #stop
 		)
 		on mouseMove click do case click of
 		(
 			2: radius = amax (abs gridDist.x) (abs gridDist.y)
 		)
 	)
 	on create do ()
 	on getDisplayMesh do 
 	(
 		if radius == _radius and segs == _segs then _mesh else 
 		(
 			_mesh = (createinstance torus segs:(_segs = segs) radius1:(_raduis = radius) radius2:0 sides:3).mesh
 		)
 	)
 )
    


it's how i would do it

bug was fixed

Last edited by denisT : 02 February 2013 at 09:45 PM.
 
Old 02 February 2013   #3
think you need to change the logic on that denis it leaks memory something awful special if you ramp up the segments and orbit the scene.
 
Old 02 February 2013   #4
Originally Posted by Klunk: think you need to change the logic on that denis it leaks memory something awful special if you ramp up the segments and orbit the scene.

i don't have max right now... try to use copy of torus.mesh and free t after that... it must be a way to make it with no big leak.

 t = createinstance torus
 _mesh = copy t.mesh
 free t
 _mesh
 
 
Old 02 February 2013   #5
the copy has to fix the leak...

a day later:

the copy solved the problem:

plugin Helper template
	  name:"template"
	  classID:#(0x68021915, 0x62747765)
	  category:"My Helpers"
	  extends:point
	  replaceUI:true;
(
	local _radius, _segs, _mesh
	fn getNode = refs.dependentnodes this firstonly:on

	parameters main rollout:params
	(
		radius	type:#float ui:radius_spnr default:10.0
		segs	type:#integer ui:segs_spnr default:16
	)
	rollout params "Params"
	(
		spinner radius_spnr "Radius:" range:[0, 1e9, 0] fieldwidth:48 type:#float
		spinner segs_spnr "Segments:" range:[3, 1e9, 16] fieldwidth:48 type:#integer
	)		
	tool create
	(
		on mousePoint click do case click of
		(
			1: 
			(
				nodeTM.translation = gridPoint
				radius = 0
			)
			2: #stop
		)
		on mouseMove click do case click of
		(
			2: radius = amax (abs gridDist.x) (abs gridDist.y)
		)
	)
	on create do ()
	on getDisplayMesh do 
	(
		if radius == _radius and segs == _segs then _mesh else 
		(
			local t = createinstance torus segs:(_segs = segs) radius1:(_raduis = radius) radius2:0 sides:3
			_mesh = copy t.mesh
			free t
			_mesh
		)
	)
)

to free the instance is not really necessary. i do it just in case...

Last edited by denisT : 02 February 2013 at 02:09 PM.
 
Old 02 February 2013   #6
nice way of generating a circle though it misses the point i was trying to illustrate, without the radius this time.....

plugin Helper template2
 	name:"template2"
 	classID:#(0x68021919, 0x62747761)
 	category:"My Helpers"
 	extends:point
 	replaceUI:true;
 (
 	local lastSize, lastRadius, msh = trimesh();
 	
 	parameters main rollout:params
 	(
 		radius	type:#float ui:radius_spnr default:10.0;
 	)
 
 	tool create
 	(
 		 on mousePoint click do case click of
 		 (
 			 1: 
 			 (
 				 nodeTM.translation = gridPoint
 				 delegate.size = 0
 			 )
 			 2: #stop
 		 )
 		 on mouseMove click do case click of
 		 (
 			 2: delegate.size = amax (abs gridDist.x) (abs gridDist.y)
 		 )
 	)
 		
 	fn mxssetedgevisflags m face flags =
 	(	
 		setEdgeVis m  face 1 flags[1];
 		setEdgeVis m  face 2 flags[2];
 		setEdgeVis m  face 3 flags[3];
 	)
 
 	fn BuildMesh =
 	(
 		setNumVerts msh 56
 		setNumFaces msh 52
 		setvert msh 1 ([0,0,1] * delegate.size)
 		setvert msh 2 ([0.259966,0,0.839472] * delegate.size)
 		setvert msh 3 ([0,0,0.77661] * delegate.size)
 		setvert msh 4 ([0.283523,0,0.64452] * delegate.size)
 		setvert msh 5 ([0.142368,0,0.92025] * delegate.size)
 		setvert msh 6 ([0.140065,0,0.694395] * delegate.size)
 		setvert msh 7 ([0.0791382,0,0.962519] * delegate.size)
 		setvert msh 8 ([0.0784301,0,0.751616] * delegate.size)
 		setvert msh 9 ([0.192126,0,0.859105] * delegate.size)
 		setvert msh 10 ([0.230047,0,0.749865] * delegate.size)
 		setvert msh 11 ([0.210155,0,0.656004] * delegate.size)
 		setvert msh 12 ([0.237055,0,0.801571] * delegate.size)
 		setvert msh 13 ([0.255556,0,0.691986] * delegate.size)
 		setvert msh 14 ([0.1,0,0] * delegate.size)
 		setvert msh 15 ([0.0948972,0.0315886,0] * delegate.size)
 		setvert msh 16 ([0.0806915,0.0590372,0] * delegate.size)
 		setvert msh 17 ([0.0590372,0.0806914,0] * delegate.size)
 		setvert msh 18 ([0.0315886,0.0948972,0] * delegate.size)
 		setvert msh 19 ([0,0.1,0] * delegate.size)
 		setvert msh 20 ([-0.0315886,0.0948972,0] * delegate.size)
 		setvert msh 21 ([-0.0590372,0.0806915,0] * delegate.size)
 		setvert msh 22 ([-0.0806914,0.0590372,0] * delegate.size)
 		setvert msh 23 ([-0.0948972,0.0315886,0] * delegate.size)
 		setvert msh 24 ([-0.1,0,0] * delegate.size)
 		setvert msh 25 ([-0.0948972,-0.0315886,0] * delegate.size)
 		setvert msh 26 ([-0.0806914,-0.0590372,0] * delegate.size)
 		setvert msh 27 ([-0.0590371,-0.0806914,0] * delegate.size)
 		setvert msh 28 ([-0.0315886,-0.0948972,0] * delegate.size)
 		setvert msh 29 ([0,-0.1,0] * delegate.size)
 		setvert msh 30 ([0.0315886,-0.0948972,0] * delegate.size)
 		setvert msh 31 ([0.0590372,-0.0806915,0] * delegate.size)
 		setvert msh 32 ([0.0806914,-0.0590372,0] * delegate.size)
 		setvert msh 33 ([0.0948972,-0.0315886,0] * delegate.size)
 		setvert msh 34 ([-0.00618996,-0.017963,0.00419626] * delegate.size)
 		setvert msh 35 ([0,-0.0189629,0.00419626] * delegate.size)
 		setvert msh 36 ([0.00619,-0.017963,0.00419626] * delegate.size)
 		setvert msh 37 ([0.0112444,-0.0153471,0.00419626] * delegate.size)
 		setvert msh 38 ([0.0153471,-0.0112445,0.00419626] * delegate.size)
 		setvert msh 39 ([0.017963,-0.00618997,0.00419626] * delegate.size)
 		setvert msh 40 ([0.0189629,0,0.00419626] * delegate.size)
 		setvert msh 41 ([0.017963,0.00618999,0.00419626] * delegate.size)
 		setvert msh 42 ([0.0153471,0.0112444,0.00419626] * delegate.size)
 		setvert msh 43 ([0.0112444,0.0153471,0.00419626] * delegate.size)
 		setvert msh 44 ([0.00618996,0.017963,0.00419626] * delegate.size)
 		setvert msh 45 ([0,0.0189629,0.00419626] * delegate.size)
 		setvert msh 46 ([-0.00618999,0.017963,0.00419626] * delegate.size)
 		setvert msh 47 ([-0.0112444,0.0153471,0.00419626] * delegate.size)
 		setvert msh 48 ([-0.0153471,0.0112444,0.00419626] * delegate.size)
 		setvert msh 49 ([-0.017963,0.00618997,0.00419626] * delegate.size)
 		setvert msh 50 ([-0.0189629,0,0.00419626] * delegate.size)
 		setvert msh 51 ([-0.017963,-0.00618998,0.00419626] * delegate.size)
 		setvert msh 52 ([-0.0153471,-0.0112444,0.00419626] * delegate.size)
 		setvert msh 53 ([-0.0112444,-0.0153471,0.00419626] * delegate.size)
 		setvert msh 54 ([0,0,1] * delegate.size)
 		setvert msh 55 ([0,0,0] * delegate.size)
 		setvert msh 56 ([0,0,0] * delegate.size)
 		setface msh 1 [8,7,6]
 		setface msh 2 [9,12,10]
 		setface msh 3 [6,7,5]
 		setface msh 4 [8,1,7]
 		setface msh 5 [3,1,8]
 		setface msh 6 [11,9,10]
 		setface msh 7 [11,13,4]
 		setface msh 8 [5,9,11]
 		setface msh 9 [6,5,11]
 		setface msh 10 [9,2,12]
 		setface msh 11 [11,10,13]
 		setface msh 12 [26,27,53]
 		setface msh 13 [26,53,52]
 		setface msh 14 [25,26,52]
 		setface msh 15 [25,52,51]
 		setface msh 16 [24,25,51]
 		setface msh 17 [24,51,50]
 		setface msh 18 [23,24,50]
 		setface msh 19 [23,50,49]
 		setface msh 20 [22,23,49]
 		setface msh 21 [22,49,48]
 		setface msh 22 [21,22,48]
 		setface msh 23 [21,48,47]
 		setface msh 24 [20,21,47]
 		setface msh 25 [20,47,46]
 		setface msh 26 [19,20,46]
 		setface msh 27 [19,46,45]
 		setface msh 28 [18,19,45]
 		setface msh 29 [18,45,44]
 		setface msh 30 [17,18,44]
 		setface msh 31 [17,44,43]
 		setface msh 32 [16,17,43]
 		setface msh 33 [16,43,42]
 		setface msh 34 [15,16,42]
 		setface msh 35 [15,42,41]
 		setface msh 36 [14,15,41]
 		setface msh 37 [14,41,40]
 		setface msh 38 [33,14,40]
 		setface msh 39 [33,40,39]
 		setface msh 40 [32,33,39]
 		setface msh 41 [32,39,38]
 		setface msh 42 [31,32,38]
 		setface msh 43 [31,38,37]
 		setface msh 44 [30,31,37]
 		setface msh 45 [30,37,36]
 		setface msh 46 [29,30,36]
 		setface msh 47 [29,36,35]
 		setface msh 48 [28,29,35]
 		setface msh 49 [28,35,34]
 		setface msh 50 [27,28,34]
 		setface msh 51 [27,34,53]
 		setface msh 52 [56,55,54]
 		mxssetedgevisflags msh  1 #{3}
 		mxssetedgevisflags msh  2 #{2}
 		mxssetedgevisflags msh  3 #{2}
 		mxssetedgevisflags msh  4 #{2}
 		mxssetedgevisflags msh  5 #{3}
 		mxssetedgevisflags msh  6 #{}
 		mxssetedgevisflags msh  7 #{2..3}
 		mxssetedgevisflags msh  8 #{1}
 		mxssetedgevisflags msh  9 #{3}
 		mxssetedgevisflags msh  10 #{1..2}
 		mxssetedgevisflags msh  11 #{2}
 		mxssetedgevisflags msh  12 #{1}
 		mxssetedgevisflags msh  13 #{2}
 		mxssetedgevisflags msh  14 #{1}
 		mxssetedgevisflags msh  15 #{2}
 		mxssetedgevisflags msh  16 #{1}
 		mxssetedgevisflags msh  17 #{2}
 		mxssetedgevisflags msh  18 #{1}
 		mxssetedgevisflags msh  19 #{2}
 		mxssetedgevisflags msh  20 #{1}
 		mxssetedgevisflags msh  21 #{2}
 		mxssetedgevisflags msh  22 #{1}
 		mxssetedgevisflags msh  23 #{2}
 		mxssetedgevisflags msh  24 #{1}
 		mxssetedgevisflags msh  25 #{2}
 		mxssetedgevisflags msh  26 #{1}
 		mxssetedgevisflags msh  27 #{2}
 		mxssetedgevisflags msh  28 #{1}
 		mxssetedgevisflags msh  29 #{2}
 		mxssetedgevisflags msh  30 #{1}
 		mxssetedgevisflags msh  31 #{2}
 		mxssetedgevisflags msh  32 #{1}
 		mxssetedgevisflags msh  33 #{2}
 		mxssetedgevisflags msh  34 #{1}
 		mxssetedgevisflags msh  35 #{2}
 		mxssetedgevisflags msh  36 #{1}
 		mxssetedgevisflags msh  37 #{2}
 		mxssetedgevisflags msh  38 #{1}
 		mxssetedgevisflags msh  39 #{2}
 		mxssetedgevisflags msh  40 #{1}
 		mxssetedgevisflags msh  41 #{2}
 		mxssetedgevisflags msh  42 #{1}
 		mxssetedgevisflags msh  43 #{2}
 		mxssetedgevisflags msh  44 #{1}
 		mxssetedgevisflags msh  45 #{2}
 		mxssetedgevisflags msh  46 #{1}
 		mxssetedgevisflags msh  47 #{2}
 		mxssetedgevisflags msh  48 #{1}
 		mxssetedgevisflags msh  49 #{2}
 		mxssetedgevisflags msh  50 #{1}
 		mxssetedgevisflags msh  51 #{2}
 		mxssetedgevisflags msh  52 #{3}
 		update msh
 	)
 	
 	fn getNode = refs.dependentnodes this firstonly:on
 	
 	rollout params "Params"
 	(
 		spinner size_spnr "Size:" range:[0, 100000000.0, delegate.size ] fieldwidth:48 type:#float align:#center;
 		on size_spnr changed val do delegate.size = val;
 		spinner radius_spnr "Radius:" range:[0, 1e9, 0] fieldwidth:48 type:#float align:#center;
 	)		
 	
 	on create do ();
 
 	on getDisplayMesh do 
 	(
 		if delegate.size != lastSize  do 
 		(
 			buildmesh();
 			lastSize = delegate.size;
 		)
 		msh;
 	)
 )



the build mesh is looks ugly and painfully slow but once built it should be no different to any other wireframe in the scene.


the make mesh script is pretty trivial

fn mxsgetedgevisflags obj f = 
(
	flags = #{}
	for i = 1 to 3 do flags[i] = getEdgeVis obj f i; 	
	flags;
)	

fn MeshtoMXS obj = if classof obj == editable_mesh do
(	
	numverts = getNumVerts obj;
	numfaces = getNumFaces obj;
	
	format "setNumVerts msh %\n" numverts;
	format "setNumFaces msh %\n" numfaces;
	
	for v = 1 to numverts do format "setvert msh % (% * delegate.size)\n" v (getVert obj v);
	for f = 1 to numfaces do format "setface msh % %\n" f (getFace obj f);
	for f = 1 to numfaces do format "mxssetedgevisflags msh  % %\n" f (mxsgetedgevisflags obj f);
)

Last edited by Klunk : 02 February 2013 at 07:42 PM.
 
Old 02 February 2013   #7
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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
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 08:58 AM.


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