mel script: 2D slider control on arbitrary nurbs surface

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 12 December 2006   #1
mel script: 2D slider control on arbitrary nurbs surface

Here's a simple implementation of a generic 2D slider taken from the earlier discussion. It follows the geometry of any simple arbitrary nurbs surface centered at the origin (it makes a copy at 5000z) or uses a simple nurbs plane if no nurbs surface was selected. You can hook any arbitrary attribute to the tx, ty and tz of the 2D slider. The slider must remain oriented to the xy of the camera plane (z-plane in this case) so if you want to follow the surface "behind", you must devise a rotation control for the surface. You could experment with UV controls for the slider, etc., to get other interesting effects.

There's a potential problem with the selection algorithm for the 2D surface: The pickWalk call might somehow select a nurbs surface by accident in some weird situation, but I didn't have any problems in my simple testing.




	/* 	Copyright 2006 Lawson English
		public domain use, commercial use, etc., all allowed. Enjoy.
		
		Implements an arbitrary 2D surface slider that follows the geometry of a selected "control" nurbs surface. 
		If no nurbs surface is selected, it uses a generic nurbs plane. 
		
		Any simple nurbs surface centered at the origin, with a bounding box of 10 on a side or less, 
		should work. You can change the rotation of the control surface to get interesting effects.
		
		To hook the x, y and z translation of the slider to arbitrary  attributes,
		 add 
		 
		 "connectAttr ($sliderPane[0]+".tx") $attribute1;"
		 "connectAttr ($sliderPane[0]+".ty") $attribute2;"
		 "connectAttr ($sliderPane[0]+".tz") $attribute3;"
		 
		 
		   
		 just before the line "showWindow $window;"
		 
		 Control of multiple attributes should be doable. (Not tested).
	*/
		
		
	
	//	Create a window with a model editor
 	
 	string $window;
	if(`window -exists myTest2DSliderWindow`)
		deleteUI -window myTest2DSliderWindow;
	$window = `window -title "myTestFrameWindow" -w 200 -h 275 myTest2DSliderWindow` ;
 	string $form = `formLayout`;
 	string $editor = `modelEditor`;

	// sample fields to put current location of slider in
 	
 	string $floatField1 = `	floatFieldGrp -numberOfFields 1 
 		-label "X"
 		-value1 0.0`;
 	string $floatField2 = `	floatFieldGrp -numberOfFields 1 
 		-label "Y" 
 		-value1 0.0 `;
 		 	string $floatField3 = `	floatFieldGrp -numberOfFields 1 
 		-label "Z"
 		-value1 0.0`;


 	
 	//	Set up the window layout attachments.
 	//
 	formLayout -edit

 		-attachForm    $editor "top"    0
 		-attachForm $editor "left"   0 
 		-attachForm    $editor "bottom" 50
 		-attachForm    $editor "right"  0
 		
 		-attachControl $floatField1 "top" 1 $editor 
 		-attachForm    $floatField1 "left"  0
 		-attachNone    $floatField1 "bottom"
 		-attachNone    $floatField1 "right"
 		
 		-attachControl $floatField2 "top" 1 $editor
 		-attachControl $floatField2 "left"  1 $floatField1
 		-attachNone    $floatField2 "bottom"
 		-attachNone    $floatField2 "right"
 		
 		 -attachControl $floatField3 "top" 1 $editor
 		-attachControl $floatField3 "left"  1 $floatField2
 		-attachNone    $floatField3 "bottom"
 		-attachNone    $floatField3 "right"

 		$form;
 		
 		string $controlPane;
 		
 		// Establish the control surface or create one if none selected
 		
 		pickWalk -d down; 
 		string $test[] = `ls -sl`;
 		
 		if ($test[0] =="" || (! `objectType -isType "nurbsSurface" $test[0]`))
 		 	{string $controlNurbs[] = 	`nurbsPlane -p 0 0 5000 -ax 0 0 1 -w 10 -lr 1 -d 3 -u 9 -v 9 -ch 1`;
 		 	$controlPane = $controlNurbs[0];} 
 		 else
 		 {
 		 	string $controlNurbs[] = 	`duplicate -rr`;
 		 	move 0 0 5000;
 		 	$controlPane = $controlNurbs[0];
 		 	
 		 }
 	modelEditor -edit -vs true $editor;   // add surface to control view

 	string $sliderPane[] =	 `nurbsPlane -p 0 0 5000 -ax 0 0 1  -w .5 -lr 1 -d 3 -u 1 -v 1 -ch 1 ` ;
 	modelEditor -edit -as $editor;   // add slider to control view
 		
 	//	Create a camera for the editor. 
 	//
 	string $camera[] = `camera -centerOfInterest 15 
 		-position  0 0 5015 
 		-rotation 0 0 0
 		-worldUp 0 0 0`;
 	
 	//	Attach the camera to the model editor.
 	//
 	modelEditor -edit -camera $camera[0]  $editor;
 	
 	//	Put an slider and grid in the scene.
 	//

 	
 	// without xform call, the durned thing doesn't show the manipulator in the editor

 	xform -ws -rp 0 0 5000 $sliderPane[0] ;


 	// make it active (who knows if needed?)
 	
	modelEditor -edit -av   $editor;
	modelEditor -edit -lockMainConnection  $editor;   // all we ever show in this model editor
 	
 	 	 
	select -r $controlPane ;
	select -tgl $sliderPane[0] ;
 	  
	geometryConstraint -weight 1;

	   
	$layer = "sliderLayer";
	createDisplayLayer -noRecurse -empty -name $layer;
	editDisplayLayerMembers $layer $controlPane;
	

		
	setAttr ($layer + ".displayType") 2;   //reference layer
	
	// hook slider to float fields for 2-way feedback
	connectControl -index 2 $floatField1 ($sliderPane[0]+".tx");
	connectControl -index 2 $floatField2 ($sliderPane[0]+".ty");
	connectControl -index 2 $floatField3 ($sliderPane[0]+".tz");
	
	  select -r $sliderPane[0] ;
	  setToolTo $gMove;
	  
	  // hook arbitrary attributes to slider.
	  
	  /*
		 "connectAttr ($sliderPane[0]+".tx") $attribute1;"
		 "connectAttr ($sliderPane[0]+".ty") $attribute2;"
		 "connectAttr ($sliderPane[0]+".tz") $attribute3;"
		 
	  */


 	showWindow $window;

Last edited by sparaig : 12 December 2006 at 10:07 PM. Reason: corrected bug when no object in scene
 
Old 12 December 2006   #2
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 12:36 PM.


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