Developing a Scripted Utility in 3ds Max 9by Sathish Shanmugasundaram, India


Before using this utility

Actually this tool is not the final one, as I said earlier I added only basic coding. But here I gave you technique of developing the utility and manipulating objects through script. You can extend this script at your own way (At your own risk).
  1. Object positioning is based on local normal of a polygon or vertex in destination object and world up axis. So u needs to adjust rotation manually in some places.
  2. Scale Source object in Sub-object selection mode (in polygon, edge or vertex).
  3. Source must be geometry object. Before selecting destination object, collapse it into Editable Poly.
  4. Modify Source objects pivot for different type of arrangement. 
  5. When you use Vertex positioning, command panels may blink because it jumps between create and modify panels.
Normal

Surface normal or normal is a vector perpendicular to the surface.



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      
 )

)


Page 1 | Page 2 | Page 3 | Page 4

 
 
 
  Copyright © 2005-2008. All Rights Reserved