|HOW TO ... FIT THE UVW MAPPING GIZMO|
|Code by Borislav "Bobo" Petrov|
|Last Edited: 2006/12/03|
|The UVW Mapping modifier has a FIT button in the UI
which fits the gizmo to the underlying geometry
by centering the gizmo the the object or selection while preserving the current orientation, resetting the scaling
of the gizmo and setting the Length, Width and Height values depending on the mapping type and axis orientation.
Unfortunately, the FIT button is not directly exposed to
MAXScript, but its functionality could be replicated because
|WHAT THE FIT FUNCTION DOES:|
|The following script describes the steps necessary to
fit the UVW Mapping gizmo to the geometry using a MAXScript function.
It is NOT based on the source code of the UVW Mapping modifier but was reverse-engineered to provide the same results.
The UVW Mapping modifier operates on the INCOMING geometry below it.
Since the script cannot acquire the geometry at an arbitrary level of the modifier stack,
it is assumed that the script will be run when the UVW Mapping modifier is the TOP modifier on the stack.
If this is not the case, chances are that the geometry on top of the modifier stack might not be the same as
the geometry coming into the UVW Mapping modifier. In these cases, the results of the script might not match
the results of the built-in FIT button.
|fn UVWMapFit theObj theMap useSel:#none=
--RESET THE GIZMO SCALE FIRST:
--Multiply the gizmo's
transformation with the inverse of a matrix created from its scale
--DEPENDING ON THE
OPTIONAL 3RD ARGUMENT, GET THE VERTICES TO OPERATE ON:
--If vertex selection
is requested, get the selection from the mesh
--if edge selection is
requested, convert the edge selection to vertex list:
--if face selection is
requested, convert the face selection to vertex list:
for v in theVerts do
--loop through all vertices in the bitarray defined above
--Record min. and max.
values for X, Y and Z:
GIZMO-ALIGNED BOX SIZE
--Set the values for
length, width and height in the general case
|CALLING THE FUNCTION|
|--Print the old gizmo
--If you hit FIT in the UI before running the script and then run this line,
--the results from the script should be identical to the result of the FIT:
--Call the funtion, specifying the object to get
the geometry from, the modifier to fit and the selection level to use:
|Want to learn more about vector and matrix operations in MAXScript?
Check out this 5 hours introduction into the world of mathematics for 3ds Max users: