使用MAXScript脚本编写圣诞树建模插件教程

news/2024/10/30 13:26:01/

一、前言

2022年圣诞节到来啦,很高兴这次我们又能一起度过~
今年的圣诞节为大家分享用MAXScript脚本编写圣诞树建模插件的技术创意,喜欢的同学别忘记在下面点个赞!

二、创意名

一键圣诞树插件

三、效果展示

 

四、实现步骤

1.制作圣诞树的设计稿(模型)。

2.功能参数设定。在这个插件设计中我们设定两部分模块:参数和关于。

主要功能是“参数”部份,有4个简单的功能参数。

a.圣诞树的长度

b.圣诞树的宽度

c.圣诞树的高度

d.平滑组开关

“关于”部分显示版本及作者信息等。

我们将把它制作成3dMax命令面板中的标准命令,而不是浮动窗口。

3.根据功能参数设计插件界面:

4.代码编写。代码编写可以分两步进行。

第1步:插件界面的代码实现。

第2步:插件功能的代码实现。

5. 代码的调试和修改。

五、编码实现

第一步:编写插件要出现在3dMax命令面板中的位置。

plugin simpleObject ChristmasTree
name:"ChristmasTree"
category:"Christmas"
classID:#(1102622742,1376421417)

以上代码定义了插件的名称、分类、ID等信息。

第二步:界面的代码实现:

	rollout params "Parameters" (spinner length "Length" range:[0,10000,49.4051] align:#right fieldwidth:60spinner width "Width" range:[0,10000,49.4051] align:#right fieldwidth:60spinner height "Height" range:[0,10000,84.37] align:#right fieldwidth:60checkbox check_smooth "Smoothing Groups")

以上代码定义一个“Parameters”卷展栏,并在卷展栏内定义了四个参数的输入界面。

“About”卷展栏定义方法同上。

第三步:功能代码编写。

圣诞树模型的实现,我们是通过脚本还原设计稿中圣诞树的模型来实现。

首先采集圣诞树模型数据:

		-- Vertex data (165 verts)-----------------------vp = #(		[10,0,0],[9.2388,3.82683,1.5],[7.07107,7.07107,0],[3.82683,9.2388,1.5],[-4.37114e-07,10,0],[-3.82684,9.2388,1.5],[-7.07107,7.07107,0],[-9.2388,3.82683,1.5],[-10,1.50996e-06,0],[-9.2388,-3.82683,1.5],
......

根据数据还原模型:

		-- Create mesh for buildMeshsetMesh mesh vertices:vp faces:fl

调节长宽高参数功能:

		-- scaling vertex positionsfor i = 1 to 165 do (oldpos = vp[i]vp[i] = point3 (oldpos.x * (width/49.4051)) (oldpos.y * (length/49.4051)) (oldpos.z * (height/84.37)))

平滑组功能实现:

		for i = 1 to 308 do (if not use_smooth then setFaceSmoothGroup mesh i fs[i])

最后完整代码:

plugin simpleObject ChristmasTree
name:"ChristmasTree"
category:"Christmas"
classID:#(1102622742,1376421417)
(parameters main rollout:params (length type:#float ui:length default:49.4051width type:#float ui:width default:49.4051height type:#float ui:height default:84.37use_smooth type:#boolean ui:check_smooth default:false)rollout params "Parameters" (spinner length "Length" range:[0,10000,49.4051] align:#right fieldwidth:60spinner width "Width" range:[0,10000,49.4051] align:#right fieldwidth:60spinner height "Height" range:[0,10000,84.37] align:#right fieldwidth:60checkbox check_smooth "Smoothing Groups")rollout aboutRO "About" (label l1 "ChristmasTree"label l2 "v1.0.0"label l3 "WeChat:fengqicongrong")on buildMesh do (-- Vertex data (165 verts)-----------------------vp = #(		[10,0,0],[9.2388,3.82683,1.5],[7.07107,7.07107,0],[3.82683,9.2388,1.5],[-4.37114e-07,10,0],[-3.82684,9.2388,1.5],[-7.07107,7.07107,0],[-9.2388,3.82683,1.5],[-10,1.50996e-06,0],[-9.2388,-3.82683,1.5],[-7.07107,-7.07107,0],[-3.82684,-9.2388,1.5],[1.19249e-07,-10,0],[3.82684,-9.23879,1.5],[7.07107,-7.07107,0],[9.2388,-3.82683,1.5],[0,0,16.6343],[7.03397,2.91357,1.5],[7.61351,-3.73761e-07,1.5],[7.03397,-2.91356,1.5],[5.38357,-5.38356,1.5],[2.91357,-7.03397,1.5],[-1.52687e-07,-7.61351,1.5],[-2.91357,-7.03397,1.5],[-5.38357,-5.38356,1.5],[-7.03397,-2.91356,1.5],[-7.61351,1.1362e-06,1.5],[-7.03397,2.91357,1.5],[-5.38357,5.38357,1.5],[-2.91357,7.03397,1.5],[-4.37114e-07,7.61351,1.5],[2.91356,7.03397,1.5],[5.38357,5.38357,1.5],[14.6139,6.05326,-15],[15.8179,2.89962e-07,-13],[14.6139,-6.05326,-15],[11.185,-11.185,-13],[6.05327,-14.6139,-15],[9.69169e-07,-15.8179,-13],[-6.05327,-14.6139,-15],[-11.185,-11.185,-13],[-14.6139,-6.05326,-15],[-15.8179,1.92457e-06,-13],[-14.6139,6.05326,-15],[-11.185,11.185,-13],[-6.05327,14.6139,-15],[-4.37114e-07,15.8179,-13],[6.05326,14.6139,-15],[11.185,11.185,-13],[12.1071,5.01491,-13],[13.1046,0,-13],[12.1071,-5.01491,-13],[9.26635,-9.26634,-13],[5.01491,-12.1071,-13],[7.21824e-07,-13.1046,-13],[-5.01491,-12.1071,-13],[-9.26635,-9.26635,-13],[-12.1071,-5.01491,-13],[-13.1046,1.92457e-06,-13],[-12.1071,5.01491,-13],[-9.26635,9.26635,-13],[-5.01491,12.1071,-13],[-2.30993e-07,13.1046,-13],[5.01491,12.1071,-13],[9.26635,9.26635,-13],[22.0224,9.12197,-32.146],[23.8369,1.18779e-06,-34.646],[22.0224,-9.12196,-32.146],[16.8552,-16.8552,-34.646],[9.12197,-22.0224,-32.146],[1.95184e-06,-23.8369,-34.646],[-9.12197,-22.0224,-32.146],[-16.8552,-16.8552,-34.646],[-22.0224,-9.12197,-32.146],[-23.8369,2.26918e-06,-34.646],[-22.0224,9.12197,-32.146],[-16.8552,16.8552,-34.646],[-9.12197,22.0224,-32.146],[-7.8726e-07,23.8369,-34.646],[9.12197,22.0224,-32.146],[16.8552,16.8552,-34.646],[16.2695,6.73906,-32.146],[17.61,5.3289e-07,-32.146],[16.2695,-6.73906,-32.146],[12.4522,-12.4522,-32.146],[6.73906,-16.2695,-32.146],[1.24133e-06,-17.61,-32.146],[-6.73906,-16.2695,-32.146],[-12.4522,-12.4522,-32.146],[-16.2695,-6.73906,-32.146],[-17.61,1.78059e-06,-32.146],[-16.2695,6.73906,-32.146],[-12.4522,12.4522,-32.146],[-6.73906,16.2695,-32.146],[-4.20499e-07,17.61,-32.146],[6.73906,16.2695,-32.146],[12.4522,12.4522,-32.146],[22.8222,9.45326,-45.2459],[24.7026,1.87139e-06,-42.2459],[22.8222,-9.45326,-45.2459],[17.4674,-17.4673,-42.2459],[9.45327,-22.8222,-45.2459],[1.42615e-06,-24.7026,-42.2459],[-9.45327,-22.8222,-45.2459],[-17.4674,-17.4673,-42.2459],[-22.8222,-9.45326,-45.2459],[-24.7026,2.57905e-06,-42.2459],[-22.8222,9.45326,-45.2459],[-17.4674,17.4674,-42.2459],[-9.45327,22.8222,-45.2459],[-1.24236e-06,24.7026,-42.2459],[9.45326,22.8222,-45.2459],[17.4674,17.4674,-42.2459],[6.71316,2.78068,-42.2459],[7.26627,-5.79391e-07,-42.2459],[6.71316,-2.78068,-42.2459],[5.13803,-5.13803,-42.2459],[2.78068,-6.71316,-42.2459],[1.39228e-06,-7.26627,-42.2459],[-2.78068,-6.71316,-42.2459],[-5.13803,-5.13803,-42.2459],[-6.71316,-2.78068,-42.2459],[-7.26627,1.40376e-06,-42.2459],[-6.71316,2.78068,-42.2459],[-5.13803,5.13803,-42.2459],[-2.78068,6.71316,-42.2459],[1.86788e-06,7.26627,-42.2459],[2.78068,6.71316,-42.2459],[5.13803,5.13803,-42.2459],[8.44957,3.49993,-58.4307],[9.14575,0,-58.4307],[8.44957,-3.49992,-58.4307],[6.46702,-6.46702,-58.4307],[3.49993,-8.44957,-58.4307],[1.53506e-06,-9.14575,-58.4307],[-3.49993,-8.44957,-58.4307],[-6.46702,-6.46702,-58.4307],[-8.44957,-3.49992,-58.4307],[-9.14575,1.59201e-06,-58.4307],[-8.44957,3.49993,-58.4307],[-6.46702,6.46702,-58.4307],[-3.49993,8.44957,-58.4307],[1.66799e-06,9.14575,-58.4307],[3.49992,8.44957,-58.4307],[6.46702,6.46702,-58.4307],[3.80423,0.999998,23.1754],[1.17557,0.999998,23.5574],[1.95106e-06,0.999997,25.9393],[-1.17557,0.999998,23.5574],[-3.80422,0.999998,23.1754],[-1.90211,0.999998,21.3213],[-2.35114,0.999998,18.7032],[2.60671e-06,0.999998,19.9393],[2.35114,0.999999,18.7032],[1.90211,0.999998,21.3213],[3.80423,-1,23.1754],[1.17557,-1,23.5574],[2.05175e-06,-1,25.9393],[-1.17557,-1,23.5574],[-3.80422,-1,23.1754],[-1.90211,-1,21.3213],[-2.35114,-1,18.7032],[2.7074e-06,-1,19.9393],[2.35114,-1,18.7032],[1.90211,-1,21.3213])-- Face data (308 faces) ---------------------------fl = #(		[1,2,17],[2,3,17],[3,4,17],[4,5,17],[5,6,17],[6,7,17],[7,8,17],[8,9,17],[9,10,17],[10,11,17],[11,12,17],[12,13,17],[13,14,17],[14,15,17],[15,16,17],[16,1,17],[19,18,2],[2,1,19],[19,1,16],[16,20,19],[21,20,16],[16,15,21],[21,15,14],[14,22,21],[23,22,14],[14,13,23],[23,13,12],[12,24,23],[25,24,12],[12,11,25],[25,11,10],[10,26,25],[27,26,10],[10,9,27],[27,9,8],[8,28,27],[29,28,8],[8,7,29],[29,7,6],[6,30,29],[31,30,6],[6,5,31],[31,5,4],[4,32,31],[33,32,4],[4,3,33],[33,3,2],[2,18,33],[34,18,19],[19,35,34],[36,35,19],[19,20,36],[36,20,21],[21,37,36],[38,37,21],[21,22,38],[38,22,23],[23,39,38],[40,39,23],[23,24,40],[40,24,25],[25,41,40],[42,41,25],[25,26,42],[42,26,27],[27,43,42],[44,43,27],[27,28,44],[44,28,29],[29,45,44],[46,45,29],[29,30,46],[46,30,31],[31,47,46],[48,47,31],[31,32,48],[48,32,33],[33,49,48],[34,49,33],[33,18,34],[50,34,35],[35,51,50],[52,51,35],[35,36,52],[52,36,37],[37,53,52],[54,38,39],[39,55,54],[56,55,39],[39,40,56],[56,40,41],[41,57,56],[58,57,41],[41,42,58],[58,42,43],[43,59,58],[60,59,43],[43,44,60],[60,44,45],[45,61,60],[62,61,45],[45,46,62],[62,46,47],[47,63,62],[64,63,47],[47,48,64],[64,48,49],[49,65,64],[50,65,49],[49,34,50],[67,66,50],[50,51,67],[67,51,52],[52,68,67],[69,68,52],[52,53,69],[69,53,54],[54,70,69],[71,70,54],[54,55,71],[71,55,56],[56,72,71],[73,72,56],[56,57,73],[73,57,58],[58,74,73],[75,74,58],[58,59,75],[75,59,60],[60,76,75],[77,76,60],[60,61,77],[77,61,62],[62,78,77],[79,78,62],[62,63,79],[79,63,64],[64,80,79],[81,80,64],[64,65,81],[81,65,50],[50,66,81],[83,82,66],[66,67,83],[83,67,68],[68,84,83],[85,84,68],[68,69,85],[85,69,70],[70,86,85],[87,86,70],[70,71,87],[87,71,72],[72,88,87],[89,88,72],[72,73,89],[89,73,74],[74,90,89],[91,90,74],[74,75,91],[91,75,76],[76,92,91],[93,92,76],[76,77,93],[93,77,78],[78,94,93],[95,94,78],[78,79,95],[95,79,80],[80,96,95],[97,96,80],[80,81,97],[97,81,66],[66,82,97],[98,82,83],[83,99,98],[100,99,83],[83,84,100],[100,84,85],[85,101,100],[102,101,85],[85,86,102],[102,86,87],[87,103,102],[104,103,87],[87,88,104],[104,88,89],[89,105,104],[106,105,89],[89,90,106],[106,90,91],[91,107,106],[108,107,91],[91,92,108],[108,92,93],[93,109,108],[110,109,93],[93,94,110],[110,94,95],[95,111,110],[112,111,95],[95,96,112],[112,96,97],[97,113,112],[98,113,97],[97,82,98],[114,98,99],[99,115,114],[116,115,99],[99,100,116],[116,100,101],[101,117,116],[118,117,101],[101,102,118],[118,102,103],[103,119,118],[120,119,103],[103,104,120],[120,104,105],[105,121,120],[122,121,105],[105,106,122],[122,106,107],[107,123,122],[124,123,107],[107,108,124],[124,108,109],[109,125,124],[126,125,109],[109,110,126],[126,110,111],[111,127,126],[111,112,128],[128,127,111],[128,112,113],[113,129,128],[114,129,113],[113,98,114],[131,130,114],[114,115,131],[132,131,115],[115,116,132],[133,132,116],[116,117,133],[134,133,117],[117,118,134],[135,134,118],[118,119,135],[136,135,119],[119,120,136],[137,136,120],[120,121,137],[138,137,121],[121,122,138],[139,138,122],[122,123,139],[140,139,123],[123,124,140],[141,140,124],[124,125,141],[142,141,125],[125,126,142],[143,142,126],[126,127,143],[144,143,127],[127,128,144],[145,144,128],[128,129,145],[130,145,129],[129,114,130],[54,53,37],[37,38,54],[146,147,157],[146,157,156],[147,148,158],[147,158,157],[148,149,159],[148,159,158],[149,150,160],[149,160,159],[150,151,161],[150,161,160],[151,152,162],[151,162,161],[152,153,163],[152,163,162],[153,154,164],[153,164,163],[154,155,165],[154,165,164],[155,146,156],[155,156,165],[153,155,154],[149,151,150],[155,147,146],[151,153,152],[147,149,148],[149,153,151],[147,153,149],[155,153,147],[163,164,165],[159,160,161],[165,156,157],[161,162,163],[157,158,159],[159,161,163],[157,159,163],[165,157,163])-- Smoothing data (308) ---------------------------fs = #(		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,4,4,2,2,4,4,2,2,4,4,2,2,4,4,2,2,4,4,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16)-- scaling vertex positionsfor i = 1 to 165 do (oldpos = vp[i]vp[i] = point3 (oldpos.x * (width/49.4051)) (oldpos.y * (length/49.4051)) (oldpos.z * (height/84.37)))-- Create mesh for buildMeshsetMesh mesh vertices:vp faces:fl-- Apply additional face datafor i = 1 to 308 do (if not use_smooth then setFaceSmoothGroup mesh i fs[i])) -- end on buildmeshtool create prompt:"Click and drag to begin creation process. Hold Ctrl for original object proportions." (on mousePoint click do (case click of (1: nodeTM.translation = gridPoint3: #stop))on mouseMove click do (case click of (2: (if ctrlKey then (width = abs gridDist.xlength = abs gridDist.y) else (old_width = 49.4051width = sqrt ((gridDist.y)^2+(gridDist.x)^2)length = (width/old_width)*49.4051height = (width/old_width)*84.37))3: if ctrlKey then height = abs gridDist.z else #stop) -- end on case) -- end on mouseMove) -- end create tool
) -- end Plug-O-Matic plugin

测试使用方法:

复制完整代码到文本编辑器,保存为.ms文件,将.ms文件拖动到3dMax窗口执行,然后,点击3dMax命令面板->创建->几何体,从下拉列表中可以看到“Christmas”分类,选择后,可以看到“ChristmasTree”命令按钮,按下后,在视口中单击或按下拖动鼠标,从而创建圣诞树模型。

 

选择已创建的圣诞树模型,切换到“修改”面板,可以通过参数面板,重设选择的圣诞树的参数值。

 

结束语:

一个简单的MAXScript脚本编写的圣诞树建模插件就完成了,大家如果喜欢别忘记点赞哟!


http://www.ppmy.cn/news/6092.html

相关文章

MySQL的数据类型和存储引擎介绍

一. MySQL数据类型 1. 整数类型 注:MySQL可以为整数类型指定宽度,比如 int(3)、int(5),这个限制不是限制value的合法范围,所以对绝大数应用没有任何意义,对于存储而言,int(3) 和 int(5) 是相同的&#xff…

垃圾回收机制

1.什么场景下该使用什么垃圾回收策略? (1).对内存要求苛刻的场景 想办法提高对象的回收效率,尽可能的多回收一些对象,腾出更多内存 (2).在CPU使用率较高的情况下 降低高并发时垃圾回收频率,让CPU更多地去执行业务而不是垃圾回收 …

某鱼兼职并不是那么好做,钱也不是漫天要价

文章目录一、背景二、雇主的期望2.1、jinja2代码三、题主的期望3.1、删除功能3.2、前端体现3.3、留言列表实现降序3.4、效果显示四、总结一、背景 上周某鱼推送过来的单子多到题主应接不暇,不得已拒绝了几单,但是接下来的单子呢又不那么顺利,…

InnoDB详解2

文章目录InnoDB详解21 行格式1 Compact行格式详解1 变长字段长度列表(两个字节)2 NULL值列表(1个字节)3 记录头信息 (重点)2 Dynamic行格式2 页的上层结构InnoDB详解2 1 行格式 规定每条记录是怎么存储的…

不同截止高度角BDS/GPS/Galileo单历元RTK定位性能分析

摘要 【目的】为探究北斗卫星导航系统(BeiDou Navigation Satellite System, BDS)、GPS(Global Positioning System)、Galileo单系统及组合系统在中国地区不同截止高度角下单历元双频RTK(Real-Time Kinematic)定位性能,对武汉境内一条短基线进行分析研究。【方法】采用双…

Linux tracepoint 简介

文章目录前言一、跟踪点的目的二、跟踪点的使用三、DECLARE_TRACE四、sched_switch例程五、TRACE_EVENT六、跟踪点的开销参考资料前言 跟踪点是放置在内核代码中较重要位置的硬编码检测点。例如,在系统调用、调度程序事件、文件系统操作和磁盘I/O的开始和结束处都有…

Three JS 调研

0. 结论 three.js是使用WebGL来绘制三维效果的,核心数据是3D对象和三维模型,更多的是关注如何通过webgl更精细而美的渲染数据 three.js相当于封装了webgl,但还是很底层,并不是一个类似于cesium或者mapbox这样的成熟地图框架&…

jQuery 插件开发

文章目录jQuery 插件开发插件概述常用插件文本溢出:dotdotdot.js单行文本省略多行文本省略延迟加载:lazyload.js插件编写方法类插件函数类插件jQuery 插件开发 插件概述 jQuery插件可以理解成是使用jQuery来封装的一个功能或特效。 一般来说&#xff…