MaxScript学习笔记目录

大家好,我是阿赵。之前有网友私信问了我一个相关的问题,我发现之前漏了MaxScript里面的Shape的内容,所以补一个例子,当做一个记录吧。

一、例子说明

这里做一个关于MaxScript读取二维形状(Shape)数据的例子,可能实际应用价值不是很大,因为3DsMax本身也带有这样的工具,不过作为一个例子来看看,留个记录,也算不错。
这个例子是这样的,有一条二维线条,然后做一个金字塔形状的网格模型

然后用MaxScript写一个工具,里面可以拾取二维线条,然后拾取模型,输入需要生成的数量,还有生成模型时的角度选择

点击create按钮,工具会复制指定的模型,沿着二维线条生成指定数量的模型。
比如上面的参数,生成500个模型,并且不改变模型的角度,得到的结果是这样的:

接下来改变一下角度的选项,可以生成这样的效果:

也可以选择反过来的角度,生成出这样的效果:

二、完整代码:

(
local CreateObjWin
local OnSelectShape
local OnSelectObj
local OnCreateObj
local selectedShape
local selectedObj
local ShowMsgfn ShowMsg msg =
(MessageBox msg title:"Tips"
)fn OnSelectShape =
(if $ == undefined then(selectedShape = undefined)else(local t = superclassof $if t == shape thenselectedShape = $elseselectedShape = undefined)if selectedShape == undefined thenCreateObjWin.selectShapeTxt.text = "no selected shape"else       CreateObjWin.selectShapeTxt.text = selectedShape.name
)   fn OnSelectObj =
(if $ == undefined then(selectedObj = undefined)else(selectedObj = $)if selectedObj == undefined thenCreateObjWin.selectObjTxt.text = "no selected shape"else      CreateObjWin.selectObjTxt.text = selectedObj.name
)fn OnCreateObj num angleType =
(if selectedShape == undefined then(ShowMsg "please select shape first!"return 0)if selectedObj == undefined then(ShowMsg "please select obj first!"return 0)local space = 1.0/(num-1);for i in 1 to num do(local tempObj = copy selectedObjlocal sp = space*(i-1)local pos = lengthInterp selectedShape spif angleType >1 then(local rota = lengthTangent selectedShape sp local angleDir = -1if angleType == 3 thenangleDir = 1rota = rota * angleDirtempObj.rotation = quat rota.x rota.y rota.z 1)tempObj.pos = pos))rollout CreateObjWin "CreateObjWin" width:246 height:300
(label 'lbl1' "shape:" pos:[17,30] width:40 height:17 align:#leftlabel 'selectShapeTxt' "no selected shape" pos:[70,30] width:93 height:17 align:#leftlabel 'lbl3' "obj:" pos:[16,63] width:40 height:17 align:#leftlabel 'selectObjTxt' "no selected obj" pos:[70,63] width:93 height:17 align:#leftlabel 'lbl5' "num:" pos:[17,99] width:40 height:17 align:#leftedittext 'numInputBox' "" pos:[53,95] width:128 height:23 align:#leftbutton 'createBtn' "create" pos:[59,214] width:107 height:27 align:#leftbutton 'selectShapeBtn' "select" pos:[171,30] width:61 height:17 align:#leftbutton 'selectObjBtn' "select" pos:[171,61] width:61 height:17 align:#leftradiobuttons 'angleBtns' "angle:" pos:[17,137] width:79 height:62 labels:#("none", "positive", "negative") default:1 columns:1 align:#lefton createBtn pressed do(local str = numInputBox.textlocal val = str as numberlocal angleType = angleBtns.stateprint angleTypeif val == undefined or val<=0 thenShowMsg("please input create number")elseOnCreateObj val angleType)on selectShapeBtn pressed doOnSelectShape()on selectObjBtn pressed doOnSelectObj()
)
createDialog CreateObjWin
)

三、注意的地方:

这个代码相对不是很复杂,下面说一下用到的几个知识点:

1、判断对象属于Shape

在拾取Shape对象的时候,如果拾取的对象不是Shape,将会对后面的步骤产生影响,所以在拾取对象的时候,用superclassof 获取一下当前选择的物体的父类,看是不是 S h a p e 。这里我也是偷懒了,因为用 获取一下当前选择的物体的父类,看是不是Shape。 这里我也是偷懒了,因为用 获取一下当前选择的物体的父类,看是不是Shape。这里我也是偷懒了,因为用读取当前选择的物体,如果同时选择的物体有多个的时候,会返回一个数组,包括下面的选择网格模型也一样。按道理要先判断是否数组然后再进行类型判断的。各位有兴趣可以自己补充一下。

2、获取Shape上的某一个点的坐标

lengthInterp [ <curve_num> ] [ steps: ]
通过这个方法,可以获取某条shape上面的某个比例[0.0-1.0]的一个点的位置,比如输入0.5,就可以获取线段中间一个点的坐标

3、获取Shape上的某一个点的切线方向

lengthTangent [ <curve_num> ] [steps: ]
通过这个方法可以获取线条上某个比例的点的切线方向

4、Shape的其他方法

可以看一下官网的API说明:

pathInterp [ <curve_num> ]
Return a point3 coordinate on the numbered curve (defaults to 1) corresponding to the
parameter value (0.0 to 1.0) that matches the 3ds Max Path controller percentage (vertex-based) interpolation.

lengthInterp [ <curve_num> ] [ steps: ]
Return a point3 coordinate on the numbered curve (defaults to 1)
corresponding to the parameter value (0.0 to 1.0) that is that
fraction along the curve’s total length.

resetLengthInterp ()
Clear length interpolation cache. Use this if
the curve you are length-interpolating along might have been edited
between calls.

curveLength [ <curve_num> ]
Return the arc length of the
numbered curve. This length does not reflect any transform level
scaling performed on the shape.

pathTangent [ <curve_num> ]
Return the tangent
direction vector at the 3ds Max Path (vertex-based) interpolated point
along the specified curve. You can use this function, for example, to
set an object’s direction to follow the curve.

lengthTangent [ <curve_num> ] [steps: ]
Return the tangent direction vector at the arc-length-interpolated
point along the specified curve. You can use this function to set an
object’s direction to follow the curve.

nearestPathParam [ <curve_num> ] [steps: ]
Return the interpolation parameter value (0.0 to 1.0) corresponding to
the point along the curve that is closest to the given
coordinate. The parameter is given as a 3ds MaxPath (vertex-based)
interpolation parameter value. You can then use pathInterp with this
value to find the nearest point’s coordinates, or use one of the
following functions for converting between arc-length parameters and
3ds Max Path percentage parameters.

pathToLengthParam [ <curve_num> ] [steps:]
Return the uniform arc-length length parameter corresponding to the
given 3ds Max Path (vertex-based) parameter for this curve.

lengthToPathParam [ <curve_num> ] [steps: ]
Return the 3ds Max Path (vertex-based) parameter corresponding to
the given uniform arc-length parameter for this curve.

MaxScript的Shape相关操作例子相关推荐

  1. cv2入门函数imread及其相关操作

    写于2021.04.21 23时 目录 1.dlib.cv2的安装 2.imread()相关参数,及其操作 3.修改图片大小 4如何处理中文路径问题 小声提醒一句:干货在后面! 安装 这里我们使用到的 ...

  2. jQuery学习笔记--JqGrid相关操作 方法列表 备忘 重点讲解(超重要)

    JqGrid相关操作备忘 方法列表 特别推荐:怎样获取某一方某一列的值: [html] view plaincopy var rowdata=jQuery("#list").jqG ...

  3. Python基础教程:list相关操作

    list相关操作小例子 获取list的下标和值 >>> mylist = ['a', 'b', 'c', 'd'] >>> for index, value in ...

  4. python 计时_Python计时相关操作详解【time,datetime】

    本文实例讲述了Python计时相关操作.分享给大家供大家参考,具体如下: 内容目录: 1. 时间戳 2. 当前时间 3. 时间差 4. python中时间日期格式化符号 5. 例子 一.时间戳 时间戳 ...

  5. JQuery属性、事件相关操作

    JQuery属性相关操作 文章目录 JQuery属性相关操作 一.尺寸相关.滚动事件 1.获取和设置元素的尺寸 2.获取元素相对页面的绝对位置 3.获取浏览器可视区宽度高度 4.获取页面文档的宽度高度 ...

  6. java ip地址相关操作

    java ip地址相关操作 @(JAVA)[scala] 参考CORE JAVA. 在JAVA中,InetAddress类用于操作与IP地址相关的内容,常用方法如下: java.net.InetAdd ...

  7. python输出举例_python字符串格式化输出及相关操作代码举例

    字符串的格式化 Python 支持格式化字符串的输出 .尽管这样可能会用到非常复杂的表达式,但最基本的用法是将一个值插入到一个有字符串格式符 %s 的字符串中.在   Python 中,字符串格式化使 ...

  8. php aes 128位加密,php实现AES 128位加密的相关操作技巧分享

    php实现AES 128位加密的相关操作技巧是什么?这篇文章主要介绍了PHP实现的AES 128位加密算法,结合实例形式分析了AES 128位加密的相关概念.原理及php实现AES 128位加密的相关 ...

  9. 厚积薄发,丰富的公用类库积累,助你高效进行系统开发(11)---各种线程相关操作类...

    俗话说,一个好汉十个帮,众人拾柴火焰高等都说明一个道理,有更多的资源,更丰富的积累,都是助你走向成功,走向顶峰的推动力. 本篇的公用类库的介绍主题是程序开发中多线程操作环境中,常用到的线程相关类,本篇 ...

最新文章

  1. openGL学习笔记(1)——常用方法原型解释
  2. 美多后台管理和项目环境搭建
  3. Realm的简单使用
  4. aspx页面事件执行顺序
  5. python 中用什么键缩进 —— tab 还是空格?
  6. Google准备开始新一年的大扩张
  7. Android自定义View构造函数详解
  8. Android——适配器其他组件(AutoCompleteTextView:自动完成文本编辑框;Spinner:下拉列表)...
  9. 如何安装python3.6_python3.6环境下如何安装freetype库和基本使用方法
  10. java clone数组_Java中的数组有对应的类么,为什么数组可以直接调用clone()方法?...
  11. OpenStack温哥华峰会Day2日记:大数据带你看峰会热点
  12. jbutton如何实现点击_Java Swing JButton按钮的实现示例
  13. unexpected error while obtaining UI hierarchy
  14. 基于翻译模型(Trans系列)的知识表示学习
  15. 微信小程序获取公众号code以及openId
  16. Unity修改批量修改名字工具
  17. 电子词典(tcp多进程模型)
  18. go操作MongoDB
  19. UDP-B-L-阿拉伯糖二钠盐,UDP-b-L-arabinopyranose disodium salt,15839-78-8
  20. volatile,wait,notify关键字

热门文章

  1. 程序流程图是什么?基本流程图讲解
  2. 小网站 php,王学集:phpwind与中小网站共同成长
  3. python apriori算法 sklearn_sklearn(九)apriori 关联规则算法,以及FP-growth 算法
  4. Verilog中阻塞赋值和非阻塞赋值的区别
  5. 【分享】“简道云“ 在集简云平台集成应用的常见问题与解决方案
  6. coupang批量上传产品遇到的问题
  7. 电子设计大赛作品_赛事“暨”忆录|重大比赛介绍第二期——电子设计大赛省赛比赛介绍...
  8. 关于maven配置不成功的问题
  9. 中国再生金属行业占有率分析与营销战略研究报告2022-2028年
  10. 用python实现钉钉Outgoing机器人(企业内部机器人)全过程