// ModelTool ZScript  (MOLDY)

// Version 1.2, updated Dec 10
//   * added load button for .OBJ files (requested by Cameyo)
//   * added button with LED to select local axis rotation
//   * added  buttons to physically double size and 1/2 size model
//   * DrawAdd, DrawSub and Move now remember their individual settings for DrawSize and DrawZDepth

// Original 2002 script by Cameyo created for ZBrush 1.23b
// 2003 Modifications and updates by Svengalii for ZBrush 1.55b (thanks Cameyo)
// Also thanks to many other ZScripters at ZBCentral for sharing their Scripting methods,
// including Davey's short tutorial on SectionBegin,SectionEnd to update interface display.
//
// MOLDY: Modeling Tool is open source script in the spirit of ZBCentral sharing.
//  Perhaps a few people will find it useful.
// 
//--------------------------------------------------------------------
// INIT VARIABLES
//--------------------------------------------------------------------
[PageSetWidth,750]
[VarDef, Spacer, 6]
[VarDef,Dsize(4),30]
[VarDef,Zsize (4),4]
[VarDef,Dmode,1]

[VarDef,T1(10),0]
[VarDef,T2(10),0]
[VarDef,T3(10),0]
[VarDef,T4(10),0]

// Setup LED button
[VarDef,Light(2),""]
  [VarSet,Light(0),"LightOn.psd"]
  [VarSet,Light(1),"LightOff.psd"]

// Setup tiny LED button
[VarDef,TinyLight(2),""]
  [VarSet,TinyLight(0),"TinyLightOff.psd"]
  [VarSet,TinyLight(1),"TinyLightOn.psd"]  

// Setup LED states
[VarDef,LightSwitch(12),0] 
// Set LightSwitch(0)to Record button state
[If, ZSCRIPT:End Rec,
   [VarSet,LightSwitch(0),1], 
   [VarSet,LightSwitch(0),0]
] 
// Set Lightswitches for 3dTool Store
  [VarSet,LightSwitch (1),0]
  [VarSet,LightSwitch (2),0]
  [VarSet,LightSwitch (3),0]
  [VarSet,LightSwitch (4),0]
  
// Set LightSwitches for x,y,z
[VarSet,LightSwitch(5),0]
[If, [IExists,TRANSFORM:>X<],
  [If,[IGet,TRANSFORM:>X<],
     [VarSet,LightSwitch(5),1]
   ]
]
[VarSet,LightSwitch(6),0]
[If, [IExists,TRANSFORM:>Y<],
  [If,[IGet,TRANSFORM:>Y<],
     [VarSet,LightSwitch(6),1]
   ]
]
[VarSet,LightSwitch(7),0]
[If, [IExists,TRANSFORM:>Z<],
  [If,[IGet,TRANSFORM:>Z<],
     [VarSet,LightSwitch(7),1]
   ]
]
[VarSet,LightSwitch(8),0]
[If, [IExists,TRANSFORM:Local Transform],
  [If,[IGet,TRANSFORM:Local Transform],
     [VarSet,LightSwitch(8),1]
   ]
]

//--------------------------------------------------------------
// CREDITS TITLE
//--------------------------------------------------------------

[PenMoveCenter]
[PenMove,-260,-8]
[IButton,,"Credits",
[Note,"MOLDY is based on the source code for 'Modeling Tool' by Cameyo written for ZBrush 1.23b.  This update for ZBrush 1.55b, was posted by Svengali to ZBCentral, December 2003."]
,,,,Moldy_title_small.psd
]

//----------------------------------------------------------------
// HELP BUTTON
//----------------------------------------------------------------

[PenMove,-117,25]
[IButton,"What's Moldy?","Describes MOLDY functionality",
[Note,"\Cffa000 MOLDY\Ca0a0a0 is a tool that streamlines basic modeling, especially building of the Sphere3d-head models we all know so well.",,-1]
[Note,"It centralizes most of the controls you might use during a modeling session.",,-1]
[Note,"  The controls are clustered in four groups, right to left:  \Cffa000MODELING\Ca0a0a0, \Cffa000ORIENTATION \Ca0a0a0, \Cffa000MASKING\Ca0a0a0 AND \Cffa000HOUSEKEEPING\Ca0a0a0.",,-1]
[Note,"  The buttons labels are easy to understand and use but some of the following notes might prove helpful."]

[Note,"\Cffa000MODELING: DrawAdd, Move, DrawSub\Ca0a0a0... three buttons control draw modes to modify the polyframe.  \Cffa000DrawAdd\Ca0a0a0 lets you add volume.  \Cffa000DrawSub\Ca0a0a0 lets you remove volume.",,-1] 
[Note,"  \Cffa000Move\Ca0a0a0 lets you drag polygons to reshape the volume.  Notice that each of these modeling buttons remembers its own settings for BrushSize and BrushDepth."] 

[Note,"  The grid button toggles the Polyframe mesh lines on and off.  Two sliders, \Cffa000BrushSize\Ca0a0a0 and \Cffa000BrushDepth\Ca0a0a0 let you set size and depth for the draw modes.",,-1]
[Note,"  The  sizes are limited to usable ranges.  The BrushSize \Cffa000minus\Ca0a0a0 and \Cffa000plus\Ca0a0a0 buttons are handy; they increment and decrement by five units."]

[Note,"The Divide button subdivides the mesh by dividing each quad into four smaller quads.  The Smooth button averages the mesh surface with a default setting of 50 each time it is applied.",,-1]  
[Note,"  Apply several times to increase smoothness."]

[Note,"Inflate and Deflate buttons are normally used with masks and expand or contract by 5 each time they are pressed.",,-1]
[Note,"  The Clone button saves a copy of the current state of your model to the Tool Palette window, handy for modeling progressions or when making radical changes to the model.  X,Y and Z buttons toggle Symmetry on and off.",,-1]
[Note,"  The Axis button allows the model working area to become the axis of rotation(handy for closeup work!).  The *2 button will physically double the model's size.  The 1/2 button physically cuts by 50%."]

[Note,"\Cffa000ORIENTATION:\Ca0a0a0 There are six keys, Front, Back, Left, Right, Top and Bottom which will rotate the model to various 90 degree views.",,-1]  
[Note,"  Sometimes the Front view gets inverted (not sure why?)  Just press the\Cffa000 FixRotate\Ca0a0a0 button to RESET it (note that any existing stencil will be lost).",,-1]
[Note,"  The four Store and Retrieve keys let you store four different views of your model.  They save location, scale and rotation.  This can be useful when working close up."]

[Note,"\Cffa000MASKING:\Ca0a0a0 These mask buttons gather together the standard masking operations so they are easy to use.",,-1]  
[Note,"  Note that the HideMask button only temporarily hides the mask for 2 seconds so you won't accidently think the mask is turned off when it isn't.",,-1]
[Note,"  The SaveMask and LoadMask buttons can be very handy.  There is a special Map2Mask button which takes the current texture map, converts it to a mask AND applies it to the model with one click."]

[Note,"Handy reminders about mask making: Use the Control key while drawing masks directly to the model.  Use the Control plus Alt key to erase areas of the mask from the model.",,-1]  
[Note,"  Remember, the darkness of the painted mask depends on the value setting of the RGBIntensity slider, 100 being darkest!  Also, a small brush size can be useful in close, for masking individual polygons."]

[Note,"\Cffa000HOUSEKEEPING:\Ca0a0a0  The Setup Model button creates a sphere and orients it with the poles top and bottom and the seam at the back.  The dimensions of the sphere are 64 x 32.  The Polyframe is made visible.",,-1]
[Note,"  The next two buttons let you save and load your model to/from the disk.  A Third button loads .OBJ and .DXF models.  The New Texture button creates and applies a 2048 x 2048 map to your model.",,-1]
[Note,"  Finally, the Recording button lets you begin or terminate a Zscript at any point while you are working, though it only makes sense to start recording at the beginning of a modeling session. "]

[Note,"\Cffa000A SPECIAL CAUTION:\Ca0a0a0 When playing back a ZScript recorded by MOLDY that uses a SPHERE3D created with the SETUP MODEL BUTTON,",,-1]
[Note," you must insert a line by EDITING the resultant ZScript so the opening 90 rotation takes effect...\n",,-1]
[Note,"Find the FIRST occurance of the following line:\n",,-1]
[Note,"\Cffa000     [ISet,Tool:MODIFIERS:DEFORMATION:Rotate,90]\Ca0a0a0\n",,-1]
[Note,"Above the ISet,Tool line insert the following line:\n",,-1]
[Note,"\Cffa000     [IModSet,Tool:MODIFIERS:DEFORMATION:Rotate,1]\Ca0a0a0\n",,-1]
[Note,"For some reason the ModSet line is not included in the recorded ZScript."]

[Note,"Another reminder:  Two of the most useful keys while modeling are \Cffa000Control Z\Ca0a0a0, (the UNDO button), and the \Cffa000Shift-Control Z\Ca0a0a0 key-combo (which acts as a REDO button)."]
 
[Note,"Thanks for trying out \Cffa000MOLDY\Ca0a0a0.  Also, thanks to Cameyo for his original inspiration to create this script.  Enjoy."] 
]

//--------------------------------------------------------------------
// INITIALIZE SPHERE MODELING
//--------------------------------------------------------------------
[PenMove,-117,18]
[IButton," Setup Model ","Initialize Basic Sphere",
  [IReset,6]
  [VarSet,docWidth,DOCUMENT:MODIFIERS:WIDTH]
  [VarSet,docHeight,DOCUMENT:MODIFIERS:HEIGHT]
  [VarSet,docMidX,docWidth/2]
  [VarSet,docMidY,docHeight/2]
  [VarSet,objRadius,docHeight/3]
  [IColorSet,150,150,150]
  [ISet,DOCUMENT:MODIFIERS:DOCUMENT BACGROUND COLOR,83.35664]
  [IColorSet,120,120,120]
  [IPress,DRAW:Mrgb]
  [IPress,DRAW:ZAdd]
  [ISet,DRAW:Rgb Intensity,100]
  [ISet,DRAW:Z Intensity,100]
  [IPress,TOOL:Sphere3D]
  [IModSet,Tool:MODIFIERS:DEFORMATION:Rotate,1]
  [ISet,TOOL:MODIFIERS:INITIALIZE:HDivide,64]
  [ISet,TOOL:MODIFIERS:INITIALIZE:VDivide,32]
  [IPress,COLOR:FillObject]
  [Delay,2]
  [CanvasClick,docMidX,docMidY,(docMidX+objRadius),(docMidY+objRadius)]
  [Delay,2]
  [ISet,Tool:MODIFIERS:DEFORMATION:Rotate,90]
  [IPress,TRANSFORM: EDIT]
  [ISet,DRAW:DRAW SIZE,20]
  [ISet,Zscript:BrushSize, 20]
  [ISet,DRAW:  Z INTENSITY,4]
  [ISet,ZScript:BrushDepth,4]
  [IPress, RENDER:Preview]
  [TransformSet,,,,,,,0,0,0]
  [IPress,TRANSFORM:MODIFIER:SYMMETRY:>X<]
  [IPress,TRANSFORM:MODIFIER:SYMMETRY:>M<]
  [If,LightSwitch(5)=0,
      [IPress,ZScript:x]
  ]  
  [IPress,TRANSFORM:Quick 3D Edit]
  [IPress,TRANSFORM:Draw Polyframe]
  [Note,"Modeling Set Up \Cffa000Completed - \Ca0a0a0 X Symmetry ON! ",,3,,450]
]

//--------------------------------------------------------------
// START Save-Load Tool
//--------------------------------------------------------------
[PenMove,-117,18]
[IButton,"   SaveTool  ","Save 3dTool ",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [IPress,TOOL:INVENTORY:SAVE AS],
      [Note,"No active 3dTool...",,1]
   ]
]
[PenMove,-117,18]
[IButton,"   LoadTool  ","Load 3dTool ",
[IPress,TOOL:INVENTORY:LOAD TOOL]
]
//--------------------------------------------------------------
// Load Object Tool
//--------------------------------------------------------------
[PenMove,-117,18]
[IButton,"  Import.OBJ ","Load Object",
[IPress,TOOL:MODIFIERS:INVENTORY:Import ]
]

//--------------------------------------------------------------
// SETUP LED REFRESH
//--------------------------------------------------------------
[PenMove,-114,19]
[SectionBegin,"",0,"",
   [IUnPress,0],
]
[SectionEnd]
//--------------------------------------------------------------
// CREATE TEXTURE MAP
//--------------------------------------------------------------
[PenMove,-6,-1]
[IButton," New Texture ","Create Texture Map 2048x2048",
  [ISet,TEXTURE:Width,2048]
  [ISet,TEXTURE:Height,2048]
  [IColorSet,120,120,120]
  [IPress,TEXTURE:New]
]
//--------------------------------------------------------------
// TOGGLE SCRIPT RECORDING
//--------------------------------------------------------------
[PenMove,-117,19]
[IButton," Recording ","Toggle record ZScript on/off",
   [If, (LightSwitch(0)),
  	[IPress,ZSCRIPT:Record]
	[VarSet,LightSwitch(0),0],
	[IPress,ZSCRIPT:End Rec]
	[VarSet,LightSwitch(0),1]
   ]
   [IPress,-2]
   ,,96
]
[PenMove,2,1]
[If, (LightSwitch(0)),
   [Image,Light(1),1],
   [Image,Light (0),1]
]

//=======================================================================
// MASKING OPERATIONS
//=======================================================================
[PenMoveCenter]
[PenMove,-141,-135]

//--------------------------------------------------------------------
// MASK 3dTOOL
//--------------------------------------------------------------------
[IButton," Mask All  ","Mask All 3dTool ",
  [IPress,TOOL:MODIFIERS:SELECTION:MaskAll]
]
//--------------------------------------------------------------------
// CLEAR 3dTOOL MASK
//--------------------------------------------------------------------
[PenMove,-99,17]
[IButton," ClearMask ","Clear Mask ",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [If, [IGet,TOOL:MODIFIERS:SELECTION:ViewMask],
         [IPress,TOOL:MODIFIERS:SELECTION:Clear],
      [Note,"No active Mask",,1]
      ],
   [Note,"No active 3dTool...",,1]   
   ]
]
//--------------------------------------------------------------------
// INVERT 3dTOOL MASK
//--------------------------------------------------------------------
[PenMove,-99,17]
[IButton,"Invert Mask","Invert Mask ",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
     [If, [IGet,TOOL:MODIFIERS:SELECTION:ViewMask],
       [IPress,TOOL:MODIFIERS:SELECTION:Inverse],
     [Note,"No active Mask",,1]
     ],
   [Note,"No active 3dTool...",,1]   
   ]
]

//--------------------------------------------------------------------
// HIDE/SHOW 3dTOOL MASK
//--------------------------------------------------------------------
[PenMove,-99,17]
[IButton," HideMask  ","Temporarily Hide Mask ",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
     [If, [IGet,TOOL:MODIFIERS:SELECTION:ViewMask],
        [IUnPress,TOOL:MODIFIERS:SELECTION:ViewMask]
        [Note,"- unmasked for 2 seconds -",0,2]
        [IPress,TOOL:MODIFIERS:SELECTION:ViewMask],
     [Note,"No active Mask",,1]
     ],
   [Note,"No active 3dTool...",,1]
   ]
]

//--------------------------------------------------------------------
// SAVE MASK FROM 3dTOOL
//--------------------------------------------------------------------
[PenMove,-99,20]
[IButton," SaveMask  ","Save current Mask to Alpha",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [If,[IGet,TOOL:MODIFIERS:SELECTION:ViewMask],
	   [IPress,TOOL:MODIFIERS:SELECTION:Create Alpha Bitmap]
         [Note,"Mask copied to Alpha Palette",,2],
         [Note,"No active Mask",,1]
      ],
   [Note,"No active 3dTool...",,1]
   ]
]
//-------------------------------------------------------------------
// LOAD MASK TO 3dTOOL
//-------------------------------------------------------------------
[PenMove,-99,17]
[IButton," LoadMask  ","Load current Alpha as Mask",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
	[IPress,TOOL:MODIFIERS:SELECTION:Alp]
      [Note,"Alpha copied to 3dTool as mask",,2],
   [Note,"No active 3dTool...",,1]
   ]
]
//-------------------------------------------------------------------
// CONVERT TEXTURE ON 3dTOOL TO MASK
//-------------------------------------------------------------------
[PenMove,-99,20]
[IButton," Map2Mask  ","Convert Texture to Mask and Apply to current 3dTool",
  [If, TEXTURE:ItemInfo=00,
	[Note,"No texture is currently assigned...",,1],	
	[IPress,TEXTURE:MakeAlpha]
	[IPress,Texture:Txtr00]
	[IPress,TOOL:MODIFIERS:SELECTION:Alp]
	[Note, "Texture converted to Alpha - applied to 3dTool",,1]
  ]
]

//========================================================================
// TOOLS FOR VIEWING MODEL
//========================================================================
[PenMoveCenter]
[PenMove,-40,-108]

//--------------------------------------------------------------------
//BEGIN Rotate model
//----Top----------------------------------------------------------
[FontSetSize,2]
[IButton,"     Top     ","Top View ",
  [TransformSet,,,,,,,-90,0,0]
]
//---Front---------------------------------------------------------
[PenMove,-117,17]
[IButton,"    Front    ","Front View",
  [TransformSet,,,,,,,0,0,0]
]
//--Left-----------------------------------------------------------
[PenMove,-117,17]
[IButton," Left ","View Left Side ",
  [TransformSet,,,,,,,0,90,180]
  ,,55
]
//---Right---------------------------------------------------------
[PenMove,-1,0]
[IButton," Right ","View Right Side ",
  [TransformSet,,,,,,,0,-90,180]
]
//----Bottom-------------------------------------------------------
[PenMove,-117,17]
[IButton,"    Bottom   ","Bottom View ",
 [TransformSet,,,,,,,90,0,0]
]
//----Back---------------------------------------------------------
[PenMove,-117,17]
[IButton,"     Back    ","Rear (back)View ",
  [TransformSet,,,,,,,0,-180,-180]
]
//-----Fix Rotation Orientation-----------------------------
[PenMove,-117,19]
[IButton,"  Fix Rotate ","Repair Rotation Orientation",
  [Note,"This FIX option re-orients the active 3d \n Tool to match the Object Preview Window, \n so rotations will work properly. Note any \n existing Stencils will be lost if you answer yes...",,3]
  [If,[IReset,6],
  [TransformSet,,,,,,,0,0,0],
  ]
]

//-----Four Store Buttons-----------------------------
[PenMove,-113,24]
//-----This code is what permits live update of interface display
[SectionBegin,"",0,"",
   [IUnPress,0]
]
[SectionEnd]

// Position One
[PenMove,-5,-4]
[IButton,"1","Store 3dTool postion 1",
   [If,[IGet,TRANSFORM:EDIT OBJECT] =0,
      [Note,"No active 3dTool...",,1],
      [If,T1(0)= 0,
         [TransformGet,T1(1),T1(2),T1(3),T1(4),T1(5),T1(6),T1(7),T1(8),T1(9)]
         [Note,"Position 1 stored",,.5]
         [VarSet,T1(0),1],
         [If,[MessageYesNo,"Another position already stored.  Do you want to overwrite?","WARNING"],
             [TransformGet,T1(1),T1(2),T1(3),T1(4),T1(5),T1(6),T1(7),T1(8),T1(9)]
             [Note,"New Postion 1 stored",,1],            
             [Note,"Stored Postion 1 retained",,1]
         ]
      ]
   ]
[IPress,-1] // look back 1 object
]
[PenMove,,1]
[If, T1(0)= 1,
   [Image,TinyLight(1),1],
   [Image,TinyLight(0),1]
]
[PenMove,-28,18]
[IButton,"g1","Load stored 3dTool Position 1",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [If,T1(0),
	   [TransformSet,T1(1),T1(2),T1(3),T1(4),T1(5),T1(6),T1(7),T1(8),T1(9)]
	   [Note, "Position 1 retrieved",,1],
	   [Note,"No postion 1 stored",,1]
      ],
   [Note,"No active 3dTool...",,1]
   ]
]

// Position Two
[PenMove,2,-19]
[IButton,"2","Store 3dTool postion 2",
   [If,[IGet,TRANSFORM:EDIT OBJECT] = 0,
      [Note,"No active 3dTool...",,1],
      [If,T2(0)= 0,
         [TransformGet,T2(1),T2(2),T2(3),T2(4),T2(5),T2(6),T2(7),T2(8),T2(9)]
         [Note,"Postion 2 stored",,.5]
         [VarSet,T2(0),1],
         [If,[MessageYesNo,"Another position already stored.  Do you want to overwrite?","WARNING"],
             [TransformGet,T2(1),T2(2),T2(3),T2(4),T2(5),T2(6),T2(7),T2(8),T2(9)]
             [Note,"New Position 2 stored",,1],            
             [Note,"Stored Postion 2 retained",,1]
         ]
      ]
   ]
   [IPress,-3] // look back three objects
]
[PenMove,1,1]
[If, T2(0)=1,
   [Image,TinyLight(1),1],
   [Image,TinyLight(0),1]
]
[PenMove,-28,18]
[IButton,"g2","Load stored 3dTool postion 2",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [If,T2(0),
	   [TransformSet,T2(1),T2(2),T2(3),T2(4),T2(5),T2(6),T2(7),T2(8),T2(9)]
	   [Note, "Position 2 retrieved",,1],
	   [Note,"No postion 2 stored",,1]
      ],
   [Note,"No active 3dTool...",,1]
   ]
]

// Position Three
[PenMove,2,-19]
[IButton,"3","Store 3dTool position 3",
   [If,[IGet,TRANSFORM:EDIT OBJECT] = 0,
      [Note,"No active 3dTool...",,1],
      [If,T3(0)= 0,
         [TransformGet,T3(1),T3(2),T3(3),T3(4),T3(5),T3(6),T3(7),T3(8),T3(9)]
         [Note,"Postion 3 stored",,.5]
         [VarSet,T3(0),1],
         [If,[MessageYesNo,"Another position already stored.  Do you want to overwrite?","WARNING"],
             [TransformGet,T3(1),T3(2),T3(3),T3(4),T3(5),T3(6),T3(7),T3(8),T3(9)]
             [Note,"New Postion 3 stored",,1],            
             [Note,"Stored Postion 3 retained",,1]
         ]
      ]
   ]
   [IPress,-5]
]
[PenMove,1,1]
[If, T3(0)=1,
   [Image,TinyLight(1),1],
   [Image,TinyLight(0),1]
]
[PenMove,-28,18]
[IButton,"g3","Load stored 3dTool position 3",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [If,T3(0),
	   [TransformSet,T3(1),T3(2),T3(3),T3(4),T3(5),T3(6),T3(7),T3(8),T3(9)]
	   [Note, "Position 3 retrieved",,1],
	   [Note,"No postion 3 stored",,1]
	],
   [Note,"No active 3dTool...",,1]
   ]
]
// Position Four
[PenMove,2,-19]

[IButton,"4","Store 3dTool postion 4",
   [If,[IGet,TRANSFORM:EDIT OBJECT] = 0,
      [Note,"No active 3dTool...",,1],
      [If,T4(0)= 0,
         [TransformGet,T4(1),T4(2),T4(3),T4(4),T4(5),T4(6),T4(7),T4(8),T4(9)]
         [Note,"Postion 4 stored",,.5]
         [VarSet,T4(0),1],
         [If,[MessageYesNo,"Another position already stored.  Do you want to overwrite?","WARNING"],
             [TransformGet,T4(1),T4(2),T4(3),T4(4),T4(5),T4(6),T4(7),T4(8),T4(9)]
             [Note,"New Postion 4 stored",,1],            
             [Note,"Stored Postion 4 retained",,1]
         ]
      ]
   ]
   [IPress,-7]
]
[PenMove,1,1]
[If, T4(0)=1,
   [Image,TinyLight(1),1],
   [Image,TinyLight(0),1]
]
[PenMove,-28,18]
[IButton,"g4","Load stored 3dTool position 4",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [If,T4(0),
	   [TransformSet,T4(1),T4(2),T4(3),T4(4),T4(5),T4(6),T4(7),T4(8),T4(9)]
	   [Note, "Position 4 retrieved",,1],
	   [Note,"No postion 4 stored",,1]
	],
   [Note,"No active 3dTool...",,1]
   ]
]


//======================================================================
// DRAWING TOOLS
//======================================================================
[PenMoveCenter]
[PenMove,79,-126]

//-------------------------------------------------------------------
//  DRAW ADD
//-------------------------------------------------------------------
[IButton," DrawAdd ","Select Draw Mode",
  [If,[IGet,TRANSFORM:EDIT OBJECT],
      [IPress,TRANSFORM: Draw Pointer]
	[IUnPress,DRAW:Z sub]
      [IPress,DRAW: Z add]
      [VarSet,Dmode, 1]
	[RoutineCall,UpdateDraw_and_Zdepth],
	[Note,"No active 3dTool...",,1]
  ]
]
//-------------------------------------------------------------------
//  MOVE DRAG
[PenMove,2]
//-------------------------------------------------------------------
[IButton,"  Move   ","Select Move Mode",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
 	[IPress,TRANSFORM:Move]
	[IPress,DRAW:Z Add]
      [VarSet,Dmode, 2]
	[RoutineCall,UpdateDraw_and_Zdepth],
	[Note,"No active 3dTool...",,1]
  ]
]
//-------------------------------------------------------------------
//  DRAW NEG
[PenMove,-164,19]
//-------------------------------------------------------------------
[IButton," DrawSub ","Select Negative Draw Mode",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
 	[IPress,TRANSFORM:Draw Pointer]
	[IUnPress,DRAW: Z add]
      [IPress,DRAW: Z sub]
      [VarSet,Dmode, 3]
	[RoutineCall,UpdateDraw_and_Zdepth],

	[Note,"No active 3dTool...",,1]
   ]
]
//-------------------------------------------------------------------
//  TOGGLE POLYFRAME
[PenMove,2]
//-------------------------------------------------------------------
[IButton,"  Grid   ","Toggle Polyframe on/off",
  [If,[IGet,TRANSFORM:EDIT OBJECT],
      [If,[IGet,TRANSFORM:Draw PolyFrame],
         [IUnPress,TRANSFORM:Quick 3D Edit]
         [IUnPress,TRANSFORM:Draw Polyframe],
         [IPress,TRANSFORM:Quick 3D Edit]
         [IPress,TRANSFORM:Draw Polyframe]
      ],
 	[Note,"No active 3dTool...",,1]
   ]
]
//-------------------------------------------------------------------
//  CHANGE BRUSH SIZE
[PenMove,-164,19]
//-------------------------------------------------------------------

[VarDef, IncrDraw, 5]
[VarDef, NewSizeDraw,[IGet, DRAW:DrawSize]]

//----- MINUS DRAWSIZE BUTTON -----
[IButton,"-","Decrease DrawSize by 5",
   [VarSet,NewSizeDraw,DRAW:DrawSize]
   [VarSet,NewSizeDraw,(INT (NewSizeDraw+4/5)*5)-IncrDraw]
   [If,NewSizeDraw < 1,
      [VarSet,NewSizeDraw,1]
   ]
   [VarSet, Dsize(Dmode),NewSizeDraw]   
   [ISet,Draw:DrawSize,NewSizeDraw]
   [ISet,ZScript:BrushSize,NewSizeDraw]
]
//----- SLIDER DRAWSIZE -----
[PenMove,1]
[ISlider,"BrushSize",30,1,1,65,"Draw Size of Brush",
   [VarSet,NewSizeDraw,[IGet,ZScript:BrushSize]]
   [if,NewSizeDraw > 65,
      [VarSet, NewSizeDraw, 65]
   ]
   [VarSet, Dsize(Dmode),NewSizeDraw]   
   [ISet, Draw: DrawSize, NewSizeDraw]
   ,0,[TextCalcWidth,"12345678901234"]
]
//----- PLUS BRUSH SIZE BUTTON
[PenMove,1]
[IButton,"+","Increase Draw Size by 5",
   [VarSet,NewSizeDraw,DRAW:DrawSize]
   [VarSet,NewSizeDraw, (INT(NewSizeDraw/5)*5)+IncrDraw]
   [If,NewSizeDraw > 65,
      [VarSet,NewSizeDraw,65]
   ]
   [VarSet, Dsize(Dmode),NewSizeDraw]   
   [ISet,DRAW:DrawSize,NewSizeDraw]
   [ISet,ZScript:BrushSize,NewSizeDraw]
]

//-------------------------------------------------------------------
//  CHANGE BRUSH DEPTH BUTTON
[PenMove,-164,19]
//-------------------------------------------------------------------
[VarDef, IncrZ, 1]
[VarDef, NewSizeZ, [IGet, DRAW: Z Intensity]]

//----- MINUS DRAWDEPTH -----
[IButton, "-", "Decrease Brush Depth",
   [VarSet, NewSizeZ,  DRAW: Z Intensity - IncrZ]
   [if,NewSizeZ < 1,
      [VarSet, NewSizeZ, 1]
   ]
   [VarSet, Zsize(Dmode),NewSizeZ]   
   [ISet, DRAW: Z Intensity, NewSizeZ]
   [ISet, ZScript: BrushDepth, NewSizeZ]
]
//----- SLIDER DRAWDEPTH -----
[PenMove,1]
[ISlider, "BrushDepth",4,1,1,15, "Draw Depth of Brush",
   [VarSet, NewSizeZ, [IGet, ZScript: BrushDepth]]
   [If,NewSizeZ > 15,
      [VarSet, NewSizeZ, 15]
   ]
   [VarSet, Zsize(Dmode),NewSizeZ]   
   [ISet, DRAW:Z Intensity,NewSizeZ]
   ,0,[TextCalcWidth,"12345678901234"]
]
//----- PLUS DRAWDEPTH -----
[PenMove,1]
[IButton,"+","Increase Brush Depth",
   [VarSet, NewSizeZ, DRAW: Z Intensity + IncrZ]
   [if, NewSizeZ > 15,
      [VarSet, NewSizeZ,15]
   ]
   [VarSet, Zsize(Dmode),NewSizeZ]   
   [ISet, DRAW: Z Intensity, NewSizeZ]
   [ISet, ZScript: BrushDepth, NewSizeZ]
]

//-------------------------------------------------------------------
//  DIVIDE TOOL
[PenMove,-164,20]
//-------------------------------------------------------------------
[IButton,"  Divide ","SubDivide Object Mesh",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [IPress,TOOL:MODIFIERS:DEFORMATION:Divide],
	[Note,"No active 3dTool...",,1]
   ]
]
//-------------------------------------------------------------------
//  SMOOTH TOOL
[PenMove,2]
//-------------------------------------------------------------------
[IButton," Smooth  ","Smooth (50)",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [ISet,TOOL:MODIFIERS:DEFORMATION:Smooth,50],
	[Note,"No active 3dTool...",,1]
   ]
]
//-------------------------------------------------------------------
//  INFLATE TOOL
[PenMove,-164,19]
//-------------------------------------------------------------------
[IButton," Inflate ","Inflate model (5)",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [ISet,TOOL:MODIFIERS:DEFORMATION:INflat,5],
	[Note,"No active 3dTool...",,1]
   ]
]
//-------------------------------------------------------------------
//  DeFLATE TOOL
[PenMove,2]
//-------------------------------------------------------------------
[IButton," Deflate ","Inflate model (-5)",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [ISet,TOOL:MODIFIERS:DEFORMATION:INflat,-5],
	[Note,"No active 3dTool...",,1]
   ]
]
//-------------------------------------------------------------------
//  CLONE TOOL
[PenMove,-164,19]
//-------------------------------------------------------------------
[IButton,"  Clone  ","Copies current 3dTool",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [IPress,TOOL:INVENTORY:Clone]
      [Note,"Copy of 3dTool saved to the Tool Group.",,1],
	[Note,"No active 3dTool...",,1]
   ]
]
//-------------------------------------------------------------------
//  XYZ SYMMETRY BUTTONS
[PenMove,4]
//-------------------------------------------------------------------
[SectionBegin,"",0,"",
   [IUnPress,0],
]
[SectionEnd]

[PenMove,-4]
[iButton,"x","toggle x symmetry",
   [If,[IExists,TRANSFORM:>X<],
      [If,(LightSwitch(5)),
         [iUnPress,TRANSFORM:>X<]
         [VarSet,LightSwitch(5),0],
         [iPress,TRANSFORM:>M<]
         [iPress,TRANSFORM:>X<]
         [VarSet,LightSwitch (5),1]
      ]
   ]
   [IPress,-1]
   ,,16
]
[PenMove,1,1]
[If, (LightSwitch(5)),
   [Image,TinyLight(1),1],
   [Image,TinyLight(0),1]
]

[PenMove,1,-1]
[iButton,"y","toggle y symmetry",
   [If,[IExists,TRANSFORM:>Y<],
      [If, (LightSwitch(6)),
         [iUnPress,TRANSFORM:>Y<]
         [VarSet,LightSwitch(6),0],
         [iPress,TRANSFORM:>M<]
         [iPress,TRANSFORM:>Y<]
         [VarSet,LightSwitch(6),1]
      ]
   ]
   [IPress,-2]
   ,,16
]
[PenMove,1,1]
[If, (LightSwitch(6)),
   [Image,TinyLight(1),1],
   [Image,TinyLight(0),1]
]

[PenMove,1,-1]
[iButton,"z","toggle z symmetry",
   [If,[IExists,TRANSFORM:>Z<],
      [If,(LightSwitch(7)),
         [iUnPress,TRANSFORM:>Z<]
         [VarSet,LightSwitch(7),0],
         [iPress,TRANSFORM:>M<]
         [iPress,TRANSFORM:>Z<]
         [VarSet,LightSwitch(7),1]
      ]
   ]
   [IPress,-3]
   ,,16
]
[PenMove,1,1]
[If, (LightSwitch(7)),
   [Image,TinyLight(1),1],
   [Image,TinyLight(0),1]
]
//-------------------------------------------------------------------
//  LOCALAXIS TOOL
[PenMove,-165,19]
//-------------------------------------------------------------------
[PenMove,1,-1]
[iButton,"  Axis  ","use modeling location as rotation point",
   [If,[IExists,TRANSFORM:Local Transform],
      [If,(LightSwitch(8)),
         [iUnPress,TRANSFORM:Local Transform]
         [VarSet,LightSwitch(8),0],
         [iPress,TRANSFORM:Local Transform]
         [VarSet,LightSwitch(8),1]
      ]
   ]
   [IPress,-4]
   ,,71
]
[PenMove,1,1]
[If, (LightSwitch(8)),
   [Image,TinyLight(1),1],
   [Image,TinyLight(0),1]
]
//-------------------------------------------------------------------
//  DOUBLE SIZE TOOL
[PenMove,2,-1]
//-------------------------------------------------------------------
[iButton," *2","Physically double size",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [IModSet,Tool:MODIFIERS:DEFORMATION:Size,7]
      [ISet,Tool:MODIFIERS:DEFORMATION:Size,100]
      [Note,"Model physically doubled in size size",,1],
 	[Note,"No active 3dTool...",,1]
   ]
   ,,38
]
//-------------------------------------------------------------------
//  HALF SIZE TOOL
[PenMove,2]
//-------------------------------------------------------------------
[iButton,"1/2","Physically reduce size to half ",
   [If,[IGet,TRANSFORM:EDIT OBJECT],
      [IModSet,Tool:MODIFIERS:DEFORMATION:Size,7]
      [ISet,Tool:MODIFIERS:DEFORMATION:Size,-50]
      [Note,"Model physically scaled to 1/2 it's size",,1],
	[Note,"No active 3dTool...",,1]
   ]
   ,,41
]


//=========================================================================
// ROUTINE DEFINITIONS
//=========================================================================

[RoutineDef,UpdateDraw_and_Zdepth,
   [ISet,Draw:DrawSize,Dsize(Dmode)]
   [ISet,ZScript:BrushSize,Dsize(Dmode)]
   [ISet, DRAW: Z Intensity, Zsize(Dmode)]
   [ISet, ZScript: BrushDepth, Zsize(Dmode)]
] 

