SpyCG.com provides search for CG related information

Developing A Scripted Utility In 3ds Max-9

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
 )

)

1 | 2 | 3 | 4
3DM3.com
Copyright © Sathish Shanmugasundaram
Edit by Stryker
Source: http://www.3dm3.com