Build a scene ============= This example covers all the steps to build a scene. Add geometries -------------- Let's add a plane, a sphere and an Alembic reference (could be an OBJ) .. code-block:: python from guerilla import Document, Modifier doc = Document() doc.new(warn=False) # add a plane pn = doc.loadfile('$(LIBRARY)/primitives/plane.glocator') planeNode = pn[0] # add a sphere sn = doc.loadfile('$(LIBRARY)/primitives/sphere.glocator') sphereNode = sn[0] # add a reference with Modifier() as mod: refNode, topNodes = mod.createref('ref1', '${SAMPLES}/helix.abc') Note that the guerilla.Modifier.createref function supports several options, like loading the reference with prefix, loading referenced node as children or sibblings of the reference, or filtering the referenced nodes. Prepare geometries ------------------ Moving or scaling is easy: connect a Transform node to object and tweak the corresponding plugs .. code-block:: python from guerilla import Modifier with Modifier() as mod: t1 = Node.create('eulerPlane', 'TransformEuler') planeNode.Transform.connect(t1.Out) # scale plane t1.SX.set(15.0) t1.SY.set(15.0) t1.SZ.set(15.0) t2 = Node.create('eulerSphere', 'TransformEuler') sphereNode.Transform.connect(t2.Out) # move sphere t2.TX.set(5.0) t2.TY.set(1.0) Add materials ------------- So here, we will add a custom material for our sphere and our referenced model. For each, it requires a RenderGraphNodePath node and a Shader node. Then to add everything together, we use some 'binop' node (union and override). .. code-block:: python from guerilla import pynode rg = pynode('RenderGraph'); print rg # add a shader to our sphere path1 = rg.loadfile('$(LIBRARY)/rendergraph/path.gnode') # RenderGraphNodePath path1[0].Path.set('Sphere') sh1 = rg.loadfile('$(LIBRARY)/rendergraph/shader.gnode') # Surface Shader sh1[0].Shader.set('Surface') sh1[0].Input1.Plug.connect(path1[0].Output1.Plug) # connect path and shader # add a shader to our reference model path2 = rg.loadfile('$(LIBRARY)/rendergraph/path.gnode') # RenderGraphNodePath path2[0].Path.set('^ref1:Shape$') sh2 = rg.loadfile('$(LIBRARY)/rendergraph/presets/varnish_wood.gnode') # Surface Shader sh2[0].Shader.set('Surface') sh2[0].Input1.Plug.connect(path2[0].Output1.Plug) # connect path and shader # union the two new Shader binop1 = rg.loadfile('$(LIBRARY)/rendergraph/binop.gnode') # union node binop1[0].Input1.Plug.connect(sh1[0].Output1.Plug) binop1[0].Input2.Plug.connect(sh2[0].Output1.Plug) # disconnect Surface and Trace nodes rgs = pynode('RenderGraph|Surface'); print rgs rgt = pynode('RenderGraph|Trace'); print rgt rgt.Input1.Plug.disconnect(rgs.Output1.Plug) # add an override to smooth our Sphere path3 = rg.loadfile('$(LIBRARY)/rendergraph/path.gnode') # RenderGraphNodePath path3[0].Path.set('Sphere') attr1 = rg.loadfile('$(LIBRARY)/rendergraph/attributes.gnode') attr1[0].Input1.Plug.connect(path3[0].Output1.Plug) # connect path and shader binop2 = rg.loadfile('$(LIBRARY)/rendergraph/binop.gnode') # override node binop2[0].Mode.set('override') binop2[0].Input1.Plug.connect(rgs.Output1.Plug) binop2[0].Input2.Plug.connect(attr1[0].Output1.Plug) # union everything binop3 = rg.loadfile('$(LIBRARY)/rendergraph/binop.gnode') # union node binop3[0].Input1.Plug.connect(binop1[0].Output1.Plug) binop3[0].Input2.Plug.connect(binop2[0].Output1.Plug) rgt.Input1.Plug.connect(binop3[0].Output1.Plug) # add a texture to our sphere from guerilla import Modifier, Plug with Modifier() as mod: attrSh1 = mod.createnode('DiffuseColor', type='AttributeShader', parent=sh1[0]) attrSh1.Shader.set('Texture') p = attrSh1.createplug('File', 'user', 'texture', Plug.Dynamic) p.set('$(SAMPLES)/cloudnormalmap.png') Add a light ----------- At last, we need to add a light. .. code-block:: python # add a point light, tweak it a bit from guerilla import Modifier with Modifier() as mod: ln = mod.doc.loadfile('$(LIBRARY)/lights/pointlight.glight')[0] ln.LightType.set('point') ln.Exponent.set(2.5) lt1 = Node.create('eulerLight', 'TransformEuler') ln.Transform.connect(lt1.Out) # move sphere lt1.TX.set(2.7) lt1.TY.set(1.5) Congrats, your scene is now ready to render :). Going further ------------- * Try the next example in :doc:`index` * Explore the API documentation * :class:`~guerilla.Modifier` * :class:`~guerilla.Document` * :class:`~guerilla.Node` * :class:`~guerilla.Plug` * :meth:`~guerilla.pynode`