'3D Studio Max'
 
'Developing a scripted_utility'
by Sathish Shanmugasundaram


Normal:

Surface normal or normal is a vector perpendicular to the surface (Fig04).

Fig.04 - NormalExample1

Script:

Utility ObjPlacer "Object Palcer"                     
 (
       Local copyState=1,sourceObj,destinationObj


fn Align souCopy desNormal pos =      
(                                                                           

   worldUpVector = [0,0,1]                         

   rightVector = normalize (cross worldUpVector desNormal)
   upVector = normalize ( cross rightVector desNormal)        
   theMatrix = matrix3 rightVector upVector desNormal Pos

   souCopy.transform = theMatrix                                                 

)     

fn CopySource numCopies=                                      
    (
         case copyState of                                         
          (
           1:                                                       
                         souCpy = for i = 1 to numCopies  collect(copy sourceObj)                
           2:                                                       
                      souCpy = for i = 1 to numCopies  collect(instance sourceObj)    
           default:                                       
                   souCpy = for i = 1 to numCopies  collect(reference sourceObj)            
          )

              return souCpy    
            )     

rollout Abt "About"                
  (
    Label lab1 "Object Placer"         
    Label lab2 "By Sathish"   
    Label lab3 "Mail:Sathish101@gmail.com"
  )        
rollout Param "Parameters"                                                          
  (

       pickButton sourcePikBtn "Source" width:75 autoDisplay:true 
       pickButton destnationPikBtn "Destination" width:75                   

       checkBox vertexChkBox "Vertex" checked:true                                              
    checkBox polygonChkBox "Polygon"                                               

       group "Copy option"                                                                      
      (

         radioButtons copyOption labels:#("Copy", "Instance", "Reference") align:#left default:1
              )

on sourcePikBtn picked sObj do    
    (
      if  sObj != undefined then 
                sourceObj=sObj                   
            )
on destnationPikBtn picked dObj do                                                                   
    (

         if(sourceObj != undefined) and (not isDeleted sourceObj) then           
         (
         if(vertexChkBox.state == true or polygonChkBox.state == true) then   
         (   
         if dObj!= undefined then      
       (
               destinationObj=dObj      
               If ((classOf destinationObj) == Editable_poly) then      
                     (

                      if (polygonChkBox.state == true) then                           
                        (
                         numPolygon = destinationObj.getnumfaces()              


                            Source =CopySource numPolygon                            

                            for i = 1 to numPolygon do                                       
                              (
                              faceCentre= polyOp.getFaceCenter destinationObj i          
                              faceNormal = polyOp.getFaceNormal destinationObj i         


                              Align source[i] faceNormal faceCentre 
                              )   
                            )                          

                  if (vertexChkBox.state == true) then                          
                        (
                         numVertex = destinationObj.getNumVertices()    

                            source =CopySource numVertex
                   editNormalsModifier=edit_Normals()                          

                          addModifier destinationObj editNormalsModifier


                      setCommandPanelTaskMode #modify 
                             destinationVertex = #{}           
                             destinationNormalIds = #{}            

                             for i = 1 to numVertex do               
                              (
                                   select destinationObj         
                                   destinationVertex = #{i}     


                                   destinationObj.edit_Normals.convertVertexSelection &destinationVertex &destinationNormalIds   


                                normalArray = destinationNormalIds as array


                                   firstNormalValue = destinationObj.edit_Normals.getNormal normalArray[1]
                                   vertexPos= polyOp.getVert destinationObj i     


                                   Align source[i]  firstNormalValue vertexPos    
                       )

                            deleteModifier destinationObj(editNormalsModifier)        
                            )     

               )
                      else
                            messageBox "Select only Editable poly object" title:"Error"
              )       
         ) 
               else
                            messageBox "Select Vertex or/and Polygon" title:"Error"
           ) 
               else
                            messageBox "Select Source Object" title:"Error"    

            )

on copyOption changed State do   
  (
   copyState=State                           
  )

 )    

 on ObjPlacer open do    
(
 addRollout Abt                
 addRollout Param           
 )

 on ObjPlacer  close do      
 (
  removeRollout Abt           
  removeRollout Param      
 )

)

Script Explanation:

utility ObjPlacer "Object Palcer"

A Utility is created using a constructor utility with name ObjPlacer and caption Object Placer.

Local copyState=1,sourceObj,destinationObj

Local variables are alive untill we close the utility is closed.

NOTE: Align and CopyOption functions are explained below.

About rollout:

rollout Abt "About"

A rollout named Abt with caption “About” is defined.

Label lab1 "Object Placer"
Label lab2 "By Sathish"
Label lab3 "Mail:Sathish101@gmail.com"

Labels are used to display information and it could not be altered. (If u need syntax details refer MaxScript reference).