Maxscript到Python转换工具教程

Maxscript到Python转换器教程

Maxscript到Python转换工具教程_第1张图片

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 exit
 pixel_line = getpixels rbmp [0,y-1] rbmp.width
 z_line = getpixels z_d [0,y-1] rbmp.width
 for 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):
        break
    pixel_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()

Maxscript到Python转换工具教程_第2张图片

该代码使用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

你可能感兴趣的:(Python编程,3DMAX,python,maxscript,mxs2py,3dmax插件,3dmax)