MaxPlus Python API Reference
Python3/pymxs/render.py
1 """
2  Demonstrate scene rendering with pymxs.
3 """
4 import os
5 import math
6 import pymxs # pylint: disable=import-error
7 from pymxs import runtime as rt # pylint: disable=import-error
8 
9 INST = rt.Name("instance")
10 
11 def create_spheres():
12  '''Create a scene made of spiralling spheres.'''
13  sphere = rt.sphere(radius=6.0)
14  revolutions = 9 * 360
15  radius = 40.0
16  z_sphere = 0.0
17  # cloning the original sphere to create the spiral effect
18  for i in range(0, revolutions, 20):
19  # the maxscript CloneNodes method accepts a named argument called 'newNodes'
20  # the argument must be sent by reference as it serves as an output argument
21  # since the argument is not also an input argument, we can simply initialize
22  # the byref() object as 'None'
23  # the output argument along with the call result is then returned in a tuple
24  # note: 'newNodes' returns an array of cloned nodes
25  # in the current case, only one element is cloned
26  result, nodes = rt.MaxOps.CloneNodes(sphere, cloneType=INST, newNodes=pymxs.byref(None))
27  radians = math.radians(i)
28  x_sphere = radius * math.cos(radians)
29  y_sphere = radius * math.sin(radians)
30  # note: 'newNodes' returned an array of cloned nodes
31  # in the current case, only one element is cloned
32  nodes[0].Position = rt.Point3(x_sphere, y_sphere, z_sphere)
33  z_sphere += 1.0
34  radius -= 0.20
35 
36 def maximize_perspective():
37  '''Setup perspective for the render'''
38  rt.viewport.setLayout(rt.Name('layout_1'))
39  rt.viewport.setType(rt.Name('view_persp_user'))
40  rt.viewport.setTM(
41  rt.matrix3(
42  rt.point3(0.707107, 0.353553, -0.612372),
43  rt.point3(-0.707107, 0.353553, -0.612372),
44  rt.point3(0, 0.866025, 0.5),
45  rt.point3(-0.00967026,-70.3466,-552.481)
46  )
47  )
48 
49 def render():
50  '''Render in the renderoutput directory.'''
51  output_path = os.path.join(rt.getDir(rt.Name("renderoutput")), 'foo.jpg')
52  if os.path.exists(output_path):
53  os.remove(output_path)
54  rt.render(outputFile=output_path)
55 
56 def demo_render():
57  '''Create a demo scene, adjust the perspective and render the scene'''
58  rt.resetMaxFile(rt.Name('noPrompt'))
59  create_spheres()
60  maximize_perspective()
61  render()
62 
63 demo_render()