当前位置: 首页 > news >正文

Maxscript到Python转换工具教程

Maxscript到Python转换器教程

Maxscript到Python转换器采用MAXScript程序,将其解析为语法树,然后从语法树中生成等效的Python代码。通过提供python的自动翻译,帮助python程序员理解maxscript示例。

【项目状况】

将正确解析最正确的maxcript语法

解析错误报告不足(尝试翻译无效的maxscript代码将不是一种有趣的体验)

代码生成器仍然不支持某些maxscript构造。大多数时候,当事情无法转换为python时,生成的代码中会发出警告,解释原因。

对插件、工具、自定义属性等结构进行解析,但python支持要么不存在,要么受到限制

一些生成的python构造可能是正确的,但很尴尬(因为以这种方式实现它更容易)

【实例】

下面是一段Maxscript代码:

renderers.current = Default_Scanline_Renderer()
delete $VoxelBox*
rbmp = render outputsize:[32,32] channels:#(#zdepth) vfb:off
z_d = getchannelasmask rbmp #zdepth
progressstart "Rendering Voxels..."
for y = 1 to rbmp.height do
(if not progressupdate (100.0 * y / rbmp.height) then exitpixel_line = getpixels rbmp [0,y-1] rbmp.widthz_line = getpixels z_d [0,y-1] rbmp.widthfor x = 1 to rbmp.width do(b = box width:10 length:10 height:(z_line[x].value/2)b.pos = [x*10,-y*10,0]b.wirecolor = pixel_line[x]b.name = uniquename "VoxelBox")--end x loop
)--end y loop
progressend()

将其翻译成以下python代码:(本质上与zdepthchannel相同,但进行了机械翻译)。

'''Converted from MAXScript to Python with Maxscript到Python转换器'''
from pymxs import runtime as rt
import mxsshim
rt.renderers.current = rt.default_scanline_renderer()
rt.delete(mxsshim.path("$VoxelBox*"))
rbmp = rt.render(outputsize=rt.point2(32, 32), channels=rt.array(rt.name("zdepth")), vfb=False)
z_d = rt.getchannelasmask(rbmp, rt.name("zdepth"))
rt.progressstart("Rendering Voxels...")
for y in range(int(1), 1 + int(rbmp.height)):if not rt.progressupdate(100.0 * y / rbmp.height):breakpixel_line = rt.getpixels(rbmp, rt.point2(0, y - 1), rbmp.width)z_line = rt.getpixels(z_d, rt.point2(0, y - 1), rbmp.width)for x in range(int(1), 1 + int(rbmp.width)):b = rt.box(width=10, length=10, height=(z_line[x - 1].value / 2))b.pos = rt.point3(x * 10, -y * 10, 0)b.wirecolor = pixel_line[x - 1]b.name = rt.uniquename("VoxelBox")
# end x loop
# end y loop
rt.progressend()

该代码使用parsec.将maxscript语法解析为语法树

然后,它在语法树上应用各种转换(不是以非常有效的方式,而是以相对简单的方式)

然后它从这个语法树中发出python代码

【使用方法】

from MaxscriptPython转换器 import topy
 
(output, _) = topy("rotate $ (angleaxis 90 [1,0,0])")
print(output)

这将打印:

'''Converted from MAXScript to Python with MaxscriptPython转换器'''
from pymxs import runtime as rt
import mxsshim
import pymxs
rt.rotate(mxsshim.path("$"), rt.angleaxis(90, rt.point3(1, 0, 0)))

请注意,生成的代码依赖于mxsshim.py,这是python中maxscript构造的一个非常早期且不完整的模拟层。

Maxscript到Python转换器本站下载:

https://download.csdn.net/download/mufenglaoshi/88591167

http://www.lryc.cn/news/251224.html

相关文章:

  • Spark_日期参数解析参数-spark.sql.legacy.timeParserPolicy
  • C语言之结构体
  • 【蓝桥杯软件赛 零基础备赛20周】第5周——高精度大数运算与队列
  • C#:程序发布的大小控制
  • Python中的split()、rsplit()、splitlines()的区别
  • 上位机开发框架:QT与winform/wpf对比
  • Halcon tiff 点云读取以及平面矫正
  • 详解Spring中基于注解的Aop编程以及Spring对于JDK和CGLIB代理方式的切换
  • 百度/抖音/小红书/微信搜索品牌形象优化怎么做?
  • 爬虫学习(三)用beautiful 解析html
  • OSG编程指南<十四>:OSG纹理渲染之普通纹理、多重纹理、Mipmap多级渐远纹理及TextureRectangle矩阵纹理
  • Langchain-Chatchat的安装过程
  • Windows系列:Windows Server 2012 R2 安装VMware Tools的正确姿势(实现物理机和虚拟机文件互传)
  • 最长连续递增序列
  • FreeRTOS入门--任务
  • 4个解决特定的任务的Pandas高效代码
  • 【已解决】AttributeError: module ‘gradio‘ has no attribute ‘Image‘
  • 高级软件工程15本书籍
  • 计网Lesson3 - 计算机网络评价指标与封包解包
  • 深度学习好文记录,反复学习
  • CSS浅谈动画性能
  • 万能的视频格式播放器
  • 设计模式---第五篇
  • .NET8构建统计Extreme Optimization Numerical Libraries
  • 07-原型模式-C语言实现
  • 深度学习与深度迁移学习有什么区别?
  • 创建Asp.net MVC项目Ajax实现视图页面数据与后端Json传值显示
  • 1089 Insert or Merge (插入排序,相邻归并排序,附模拟实现)
  • 基于算能的国产AI边缘计算盒子8核心A53丨17.6Tops算力
  • Eaxyx 让圆球跟随鼠标移动