MaxScript Object_Oriented_Struct 使用strut 模拟面向对像编程中的 Class

class   是面向对像编程的基本概念. 是把处理的问题抽象为一个物体. 物体有属性 有方法 等等 . 在开发大型的软件上 组织代码的结构上 是非常好的一种方式.

Struct 主要是做用其实是打包一些数据及方法 . 也是管理代码的. 只是他更 趋向数据的管理上. 

maxscript 中只支持struct . 我们也可以试着来模拟一下 CLass.. 实现面向对像编程. 将问题抽象成一个物体

这个例子是.简单的实现一个BOX Class:

 1 struct BoxStruct
 2 (
 3     -- Fields
 4     w,l,h,meshobj,
 5 
 6     -- initialize Function
 7     fn init = (
 8         if w == undefined then w = 10
 9         if l == undefined then l = 10
10         if h == undefined then h = 10
11         Box w length:l height:h
12     ),
13 
14     -- Do initialize FIRST!!!
15     meshobj = init(),
16     
17     -- NEXT Define the EditFunctions.
18     -- set the width
19     fn setw v = (
20         meshobj.width = w = v
21     ),
22     -- set the length
23     fn setl v = (
24         meshobj.length = l = v
25     ),
26     -- set the height
27     fn seth v = (
28         meshobj.height = h = v
29     )
30 )
31 
32 BoxObj2 = BoxStruct w:20 h:39
原文地址:https://www.cnblogs.com/easyfrog/p/2487305.html