- 帖子
- 222
- 精华
- 0
- 积分
- 201
- 金钱
- 674
- 贝壳
- 4
|
1#
发表于 2008-4-21 14:03
| 只看该作者
(3dsmax)'Developing a Scripted Utility'-开发一个脚本工具
'Developing a Scripted Utility'--开发一个脚本工具
'Developing a Scripted Utility'
by Sathish Shanmugasundaram (Email: Sathish101@gmail.com)
原文链接:http://www.3dtotal.com/team/Tutorials_3/scripted_utility/scripted_utility01.asp
Hello everyone, this tutorial will guide you to develop a scripted utility in 3DS MAX 9. This tutorial is for users with basic knowledge in max script or any other object oriented language. Here I explained everything step by step. Actually this coding is a part in my plug-in. Due to coding complexity, I cut short some and added only a few things. If time permits I will explain the rest.
(大家好,这篇教程将引导你在3dsmax9中开发一个脚本工具。这个教程需要使用者具有基本的max脚本知识或是其他任何计算机语言基础。这里我将一步步的进行讲解。事实上,这段代码是我写的插件的一部分。因为代码很复杂,我删减了一些,只添加了很少的东西。如果时间允许我将解释剩下的部分。)It covers:
(它包括)
How to develop a tool (with rollouts, buttons, check boxes etc) in 3ds Max.
(如何在3dsmax中扩展一个工具(如卷展栏,按钮,点击框等等)。)
How to position an object over another objects vertex or polygon.
(如果在另一个物体的顶点或面上放置物体。)
Calculating local normals of vertex and polygons in an object and positioning another object according to it.
(获取一个物体的顶点和多边形面的自身法线,并据此放置其他物体。)
By using basic coding, making copies of an object according to user selection (may be Instance, Copy or references).
(使用基本的代码,创建使用者选中的物体的复制体(也可以是关联复制或是参考复制)。)
What is Scripted Utility?
(脚本工具集是什么?)
--------------------------------------------------------------------------------
Max Script allows us to create our own Tools for specific purpose and embed them into existing max interface. The Scripted Utilities are tools appear in Utility panel > Max Script Utility. Scripted utility is an easiest way of developing tools, since they are special kind of rollouts that saves the developer some UI management work.
(max的脚本允许我们为特定的目的创建自己的工具,并将其纳入已存在的max的交互界面中。脚本工具集显示在Utility panel > Max Script Utility下的一个工具。脚本功能集是一个很容易扩展的工具,因为它们有特殊类型的卷展栏,这将节省开发者的界面管理工作。)
Creating and running Scripted Utility:
(创建和运行脚本工具)
--------------------------------------------------------------------------------
To create new script go to MaxScript menu->New (or)
Open Utility panel -> MaxScript->New script.
(要创建一个新的脚本,你可以选择MaxScript menu->New 或是打开工具面板,Utility panel -> MaxScript->New script.)
To run a script, go to MaxScript menu->Run Script (or) Utility panel
MaxScript-> Run Script and choose script to be run.
(要运行一个脚本,你可以进入菜单 MaxScript menu->Run Script 或是通过工具面板Utility panel -> MaxScript-> Run Script ,然后选择你要运行的脚本即可。)
When we put the Script file into \Scripts\Startup folder then it will automatically executed when 3DMax starts.
(如果我们将脚本文件放到目录\Scripts\Startup 下,那么当我们打开max时,这些脚本将会自动加载。)
After execution our utility is available at Utilities panel -> maxScript -> Utility dropdown list (See Fig01). When we select Object Placer the rollout will appear below dropdown list as shown below.
(在加载之后,我们在工具面板Utilities panel -> maxScript -> Utility 下拉菜单下的工具 就变的可用了(如图1)。当我们选择了Object Placer 工具,下拉列表下面会出现一个卷展栏。)
Fig.01 - OpeningTheScript(图1——打开脚本)
Purpose of our utility – Object Placer:
(我们的目标脚本工具——Object Placer)
--------------------------------------------------------------------------------
Object placer allow us to place copies of source object into the destination object‘s vertices and/or polygon’s centre, Also aligned with local normal.
(Object placer工具允许我们放置源物体的拷贝到目标物体的顶点或多边面的中心,当然还要跟它们自身的法线方向对齐。)
Fig.02 shows the final object placer utility. The contents are: +nU',E
(图2显示了完全展开的object placer工具。其内容包括:) 4#TnXxL
w(aUEWYL
About rollout with Labels. Parameter rollout with following:
(带标签的about卷展栏。属性卷展栏内容如下)
- Two Pick buttons for Source and Destination object selection.
(两个分别用于拾取源物体和目标物体的按钮)
- Two Check boxes for selecting Vertex and /or Polygon.
(两个分别定义是否选择顶点或是多边面的勾选框。)
- A Group named Copy option with three Radio buttons for selecting copy type.
(一组命名为拷贝选项的用于确定复制类型的3个圆形按钮。)
Fig.02 - ObjectPlacerUtility(图2——物体放置工具)
Fig.03 shows, source object Cone copied and aligned to Geosphere‘s polygons and another object box copied and aligned with vertices of Geosphere.
(如图3所示,源物体圆锥被复制对齐到几何球体的多边面上,另一些方盒子则被复制对齐到几何球体的顶点上。)
Fig.03 - ObjectWithConeandBox(图3——被圆锥和立方体附着的几何球体)
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. <&6u]uKrW
(物体的位置是基于目标物体表面的顶点和面的自身法线和世界空间向上的轴线确定的。所以在某些位置你需要手动调整旋转。)
2. Scale Source object in Sub-object selection mode (in polygon, edge or vertex).Better use vertex mode for similar result as normal scaling.
(在次物体选择模式下缩放源物体。最好使用顶点模式来进行缩放。)
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 (Fig04).
(表面法线或者说法线是垂直于表面的一个矢量。如图4)
Fig.04 - NormalExample1(图4——法线实例)
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 faceNormal faceCentre bHH}
)
)
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 firstNormalValue vertexPos
)
deleteModifier destinationObj(editNormalsModifier)
)
)
else
messageBox "Select only Editable poly object" title:"Error"
)
)
messageBox "Select Vertex or/and Polygon" title:"Error"
)
messageBox "Select Source Object" title:"Error"
)
on copyOption changed State do B
(
copyState=State
)
)
on ObjPlacer open do
(
addRollout Abt
addRollout Param
)
on ObjPlacer close do
(
removeRollout Abt
removeRollout Param
)
)
[ 本帖最后由 火柴盒 于 2008-4-21 14:27 编辑 ] |
|