Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Katana Python Manual

Katana Python Manual

This is a manual for Python using Katana, Foundry's dedicated Lighting & LookDev software.
Foundry社製のLighting & LookDev専用ソフトウェア「Katana」を使用したPythonのマニュアルです。

Oozeki.CG

July 17, 2020
Tweet

More Decks by Oozeki.CG

Other Decks in Research

Transcript

  1. Katana’s Python
 - KatanaのPython
 @dosukoi_jinsei
 3
 Display the Python Tab


    Pythonタブを表示
 In order to run Python in Katana, you need to view the Python tab.
 KatanaでPythonを実行するためには、Pythonタブを表示する必要がありま す。
 ▼ (Pane Menu)
 Python
 >

  2. Katana’s Python
 - KatanaのPython
 @dosukoi_jinsei
 4
 Import Module
 モジュールの読込み
 The

    basic module of Katana is "NodegraphAPI".
 Katanaの基本モジュールは「NodegraphAPI」になります。 
 from Katana import NodegraphAPI

  3. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 5
 Get Root Node Graph


    Root Node Graphの取得
 Get the node graph at the top level.
 It is recommended to assign the acquired node graph to a variable because it is used to create the node described below.
 一番上位階層にあるノードグラフを取得します。 
 取得したノードグラフは後述のノード作成に使用しますので、変数に 代入しておく事を推奨します。 
 NodegraphAPI.GetRootNode()
 rootNodeGraph = NodegraphAPI.GetRootNode()
 Exsample
 - 例

  4. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 6
 Create Node
 ノードの作成
 NodegraphAPI.CreateNode(Node

    Name, Node Graph)
 "Node Name" has the node name in the node parameter. "Node Graph" specifies the Node Graph of the highest level as described above or the group Specify the node, if any.
 "Node Name"は、ノードパラメータにノード名が記載されています。"Node Graph"は、前述の最上位階層のノードグラ フを指定したり、グループノードがある場合はそれを指定します。 
 Exsample
 - 例
 rootNodeGraph = NodegraphAPI.GetRootNode()
 NodegraphAPI.CreateNode("Alembic_In", rootNodeGraph)

  5. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 7
 Get Node
 ノードの取得
 NodegraphAPI.GetNode(Node

    Unique Name)
 "Node Unique Name" is the unique name given to each node.
 “Node Unique Name”は各ノードに付けられた固有の名称になります。 
 Exsample
 - 例
 rootNodeGraph = NodegraphAPI.GetRootNode()
 NodegraphAPI.CreateNode("Alembic_In", rootNodeGraph)
 NodegraphAPI.GetNode("Alembic_In")

  6. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 8
 Rename Node
 ノード名の変更
 Node.setName(Rename

    Node Name, 0)
 "Node" describes the node you created (stored in a variable). The value of "0" can be changed depending on the frame and is usually 0. "Rename Node Name" is an arbitrary name of the node.
 "Node"は、作成したノード(変数に格納した)を記載します。"0"は、フレームによっ て変化させる事が可能で、通常は0を記載します。"Rename Node Name"には、 任意のノード名を記載します。 
 Exsample
 - 例
 rootNodeGraph = NodegraphAPI.GetRootNode()
 alembic = NodegraphAPI.CreateNode("Alembic_In", rootNodeGraph)
 alembic.setName("Alembic_NodeName", 0)

  7. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 9
 Rename Node
 ノード名の変更
 Node.getParameter("name").setValue(Node.getName(),

    0)
 Some nodes cannot be changed by the above command alone. It is possible to change it by adding the above command. "getParameter" can get any parameter. The node name is acquired this time.
 By adding "setValue", you can modify the parameter while getting it. "Node.getName()" gets the node name, and then you can rename the node again. It is.
 
 一部のノードは前述のコマンドだけでは変更出来ません。上記コマンドを追加する 事で変更が可能になります。"getParameter"は、任意のパラメータを取得出来ま す。今回はノード名を取得します。"setValue"を付ける事で、パラメーターを取得し つつ変更をする事が出来ます。"Node.getName()"によりノード名を取得し、再度 ノード名変更を実行しています。 
 
 Exsample
 - 例
 rootNodeGraph = NodegraphAPI.GetRootNode()
 material = NodegraphAPI.CreateNode("Material", rootNodeGraph)
 material.setName("Material_NodeName", 0)
 material.getParameter("name").setValue(material.getName(), 0)

  8. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 10
 Get Parameter
 値の取得
 Node.getParameter(Parameter

    Name).getValue(0)
 Enter the parameter name in the “Parameter Name” field. To find out the name of the parameter, hover the mouse over it. Alternatively, you can drag and drop the parameters into the input area of the Python tab to get the parameter names or the command itself.
 「Parameter Name」には、パラメーターの名称を記載します。パラメーターの名称はパラメーターにマウスカーソ ルを合わせると分かります。もしくはパラメーターをPythonタブの入力領域にドラッグアンドドロップする事でパ ラメーター名やコマンド自体を知る事が出来ます。 
 Exsample
 - 例
 rootNodeGraph = NodegraphAPI.GetRootNode()
 alembic = NodegraphAPI.CreateNode("Alembic_In", rootNodeGraph)
 result = alembic.getParameter("name").getValue(0)
 print result
 # /root/world/geo/asset
 Drag and Drop

  9. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 11
 Set Parameter
 値の変更
 Node.getParameter(Parameter

    Name).setValue(Value, 0)
 Enter the value of the parameter in the "Value" field.
 「Value」にパラメーターの値を記載します。 
 Exsample
 - 例
 rootNodeGraph = NodegraphAPI.GetRootNode()
 alembic = NodegraphAPI.CreateNode("Alembic_In", rootNodeGraph)
 alembic.getParameter("name").setValue("/newPath/", 0)

  10. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 12
 Node Position
 ノードの配置
 NodegraphAPI.SetNodePosition(Node,

    CoordinateX, CoordinateY)
 "CoordinateX" and "CoordinateY" have the "X coordinate" and The "Y-coordinate" is described by an integer or a floating point.
 
 "CoordinateX"と"CoordinateY"にはそれぞれノードの「X座標」と「Y座標」を整数、もし くは浮動小数点で記載します。 
 Exsample
 - 例
 rootNodeGraph = NodegraphAPI.GetRootNode()
 alembic = NodegraphAPI.CreateNode("Alembic_In", rootNodeGraph)
 NodegraphAPI.SetNodePosition(alembic, (100, 200.5))

  11. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 13
 NetworkMaterialCreate
 NetworkMaterialCreateノード
 "NetworkMaterialCreate" allows

    you to put together a shading network to create a is a node that has a This section describes how to create materials and edit parameters using them.
 
 "NetworkMaterialCreate"は、シェーディングネットワークをまとめているノードです。ここでは、それを使用して のマテリアルを作成、パラメーターを編集する解説をします。 
 Shading Node
 (Material)
 Shading Node
 (Bitmap File)
 Shading Node
 (UVWGenMayaPlace2dTexture) 
 NetworkMaterialCreate
 NetworkMaterial

  12. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 14
 NetworkMaterialCreate
 NetworkMaterialCreateノード
 01
 Create

    a “NetworkMaterialCreate”.
 「NetworkMaterialCreate」ノードを作成。 
 Exsample
 - 例
 rootNodeGraph = NodegraphAPI.GetRootNode()
 nmc = NodegraphAPI.CreateNode("NetworkMaterialCreate", rootNodeGraph)
 nm = NodegraphAPI.GetNode("NetworkMaterial")
 NetworkMaterialCreate
 NetworkMaterial
 nmc
 nm

  13. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 15
 NetworkMaterialCreate
 NetworkMaterialCreateノード
 02
 Created

    a “VrayShadingNode”. 
 (The rest of this section is for “Vray”)
 “VrayShadingNode”を作成。 
 (以降は「Vray」の場合で解説) 
 Exsample
 - 例
 material = NodegraphAPI.CreateNode("VrayShadingNode", nmc)
 The destination of the node is specified in "NetworkMaterialCreate(variable nmc)" created as described above.
 ノードの作成先を、前述で作成した「NetworkMaterialCreate(変数nmc)」に指定しています。 

  14. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 16
 NetworkMaterialCreate
 NetworkMaterialCreateノード
 03
 Set

    the “nodeType” to “VRayMtl”
 「nodeType」を「VRayMtl」に指定。 
 Exsample
 - 例
 material.getParameter("nodeType").setValue("VRayMtl", 0)

  15. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 17
 NetworkMaterialCreate
 NetworkMaterialCreateノード
 04
 Connect

    "VRayMtl" to "NetworkMaterial".
 「VRayMtl」と「NetworkMaterial」を接続。 
 Exsample
 - 例
 nm.getInputPort("vraySurface").connect(material.getOutputPort("out"))
 Node.getInputPort(Input Port Name).connect(Node.getOutputPort(Output Port Name))
 The "Input Port Name" and "Output Port Name" on the left side of each node is the input name and the right side is the output name.
 「Input Port Name」と「Output Port Name」は、各ノードの左側にあるのが入力、右側にあるのが出力の名称にな ります。
 Input
 Output

  16. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 18
 NetworkMaterialCreate
 NetworkMaterialCreateノード
 05
 Change

    the parameters of the material.
 マテリアルのパラメーターを変更。 
 There are commands to be run before changing the parameters of a material.
 This is mainly for the following reasons (taken from the Katana Developer Guide).
 マテリアルのパラメータを変更する前に実行しておくコマンドがあります。 
 これは主に以下の理由です( Katana Developer Guideから抜粋)。 
 A sub-set of nodes in Katana feature “dynamic” parameters; dynamic in that their existence on a node is not fixed at node creation time, but rather is on attributes from the incoming scene or some other asynchronous process.
 For example, upon adding a shader to a Material node, Katana must query the renderer for the set of parameters the shader exposes, as well as their default values. Until these queries complete and the Parameters tab is updated, the parameters representing the various shader configuration options do not yet exist.
 Katanaのノードのサブセットには、「ダイナミック」なパラメータがあります。ダイナミックとは、ノード上のパラメータがノード作成時に固定されている のではなく、入力されるシーンやその他の非同期プロセスからのアトリビュートに基づいているという意味です。 
 例えば、マテリアルノードにシェーダを追加すると、Katanaはシェーダが公開しているパラメータのセットとデフォルト値をレンダラーに問い合わせな ければなりません。これらのクエリが完了して[パラメータ]タブが更新されるまでは、さまざまなシェーダ設定オプションを表すパラメータはまだ存在 しません。
 Shading Node
 VRayMtl
 Vray (Renderer)
 VRayMtl
 Parameter
 To summarize, this is because after creating a node, we query external programs such as Renderer and can't change it right away because of the time it takes to reflect it in the node.
 要約すると、ノード作成後にRenderer等の外部プログラムに問い合わせし、ノードに反映するまでの時間がある ので、すぐには変更出来ないためです。 

  17. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 19
 NetworkMaterialCreate
 NetworkMaterialCreateノード
 05
 Change

    the parameters of the material.
 マテリアルのパラメーターを変更。 
 After creating a node, you can change the parameters by executing "checkDynamicParameters()".
 ノード作成後「checkDynamicParameters()」を実行する事でパラメーターの変更が可能に なります。
 Node.checkDynamicParameters()
 Exsample
 - 例
 material.checkDynamicParameters()

  18. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 20
 NetworkMaterialCreate
 NetworkMaterialCreateノード
 05
 Change

    the parameters of the material.
 マテリアルのパラメーターを変更。 
 Before you can change the parameters, you need to set the editable state. That will be "enable". Then change the parameter.
 パラメーターを変更する前に、編集可能状態を設定する必要があります。それが「enable」になります。その後 パラメーターを変更します。 
 Exsample
 - 例
 material.getParameter("parameters.refraction_affect_shadows.enable").setValue(float(True), 0)
 material.getParameter("parameters.refraction_affect_shadows.value").setValue(1, 0)
 Node.getParameter("parameters.Parameter Name.enable").setValue(float(True), 0)
 Node.getParameter("parameters.Parameter Name.value").setValue(Value, 0)
 enable
 value

  19. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 21
 NetworkMaterialCreate
 NetworkMaterialCreateノード
 Exsample
 -

    例
 material.getParameter("parameters.diffuse_color.enable").setValue(float(True), 0)
 material.getParameter("parameters.diffuse_color.value.i0").setValue(0.18, 0)
 material.getParameter("parameters.diffuse_color.value.i1").setValue(0.18, 0)
 material.getParameter("parameters.diffuse_color.value.i2").setValue(0.18, 0)
 To set an RGB value, add an input name of "i0" or "i1" after "value".
 RGBの値を設定する場合は「value」の後に「i0」や「i1」の入力名を追加します。 
 i0
 i1
 i2
 i3

  20. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 22
 NetworkMaterialCreate
 NetworkMaterialCreateノード
 Exsample
 -

    例
 material_Enable = material.getParameter("parameters.refraction_affect_shadows.enable")
 material_Value = material.getParameter("parameters.refraction_affect_shadows.value")
 material_Enable.setValue(float(True), 0)
 material_Value.setValue(1, 0)
 In rare cases, it may not be possible to change the parameters as described above.
 In that case, put Value and Enable into a variable and then change the parameter.
 稀に前述の記載方法でパラメーター変更が出来ない場合があります。 
 その場合は、ValueとEnableを一旦変数に入れてから、パラメーターを変更します。 

  21. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 23
 Add Input Port
 入力ポートを追加


    Node.addInputPort("i0")
 Some nodes do not have an input port by default, such as the "Merge" node. In that case, you can add an input port and connect the node.
 
 
 「Merge」ノード等、デフォルトで入力ポートが付いていないノードがあります。その場合 は、入力ポートを追加し、ノードを接続します。 
 Exsample
 - 例
 rootNodeGraph = NodegraphAPI.GetRootNode()
 merge = NodegraphAPI.CreateNode("Merge", rootNodeGraph)
 merge.addInputPort("i0")
 merge.addInputPort("i1")
 Add Input Port

  22. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 24
 Collectively input to CEL


    CELにまとめて入力
 Node.getParameter("CEL").setValue(" ".join(List), 0)
 We'll start by creating a Python list of paths.
 You can use the Python "join" and separate the elements of the list with a "space" to register them together.
 
 
 始めにパスのPythonリスト形式を用意します。 
 Pythonの「join」を使用し、リストの要素同士を「スペース」で区切る事で、まとめて登録 する事が可能になります。 
 Exsample
 - 例
 pathList = ["/root/test/object01", "/root/test/object02"]
 rootNodeGraph = NodegraphAPI.GetRootNode()
 mAssign = NodegraphAPI.CreateNode("MaterialAssign", rootNodeGraph)
 mAssign.getParameter("CEL").setValue(" ".join(pathList), 0)

  23. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 25
 Collectively input to CEL


    CELにまとめて入力
 To add more than one CEL, separate the elements with a () and add them with a formula for processing. The formulas are "Union(+)", "Difference(-)", "Intersect (^)".
 
 
 複数のCELを追加するには、要素を()でくくり、処理の計算式を記載して追加します。計算式には 「Union(+)」「Difference(-)」「Intersect(^)」があります。 
 Exsample
 - 例
 pathList01 = ["/root/test/object01", "/root/test/object02"]
 pathList02 = ["/root/test/object03"]
 rootNodeGraph = NodegraphAPI.GetRootNode()
 mAssign = NodegraphAPI.CreateNode("MaterialAssign", rootNodeGraph)
 mAssign.getParameter("CEL").setValue(
 "(" + " ".join(pathList01) + ")" + "+" + "(" + " ".join(pathList02) + ")", 0
 )
 Node.getParameter("CEL").setValue("(Value)" + "formula" + "(Value)", 0)
 formula
 Value
 Union
 +
 Difference
 -
 Intersect
 ^

  24. Python Exsample
 - Python参考例
 @dosukoi_jinsei
 26
 Backdrop
 Backdropノード
 Backdrop =

    Node.CreateNode("Backdrop", Node Graph)
 NodegraphAPI.SetNodeShapeAttr(Backdrop, Parameter, Value)
 The "Backdrop" node, which can be placed in the background of multiple nodes, can be placed in the "Backdrop" node after the node is created. The parameters are changed by "SetNodeShapeAttr". The main parameters are as follows
 
 複数のノードの背景に設置出来る「Backdrop」ノー ドは、ノードを作成後、
 「SetNodeShapeAttr」によってパラメーターを変更し ます。主なパラメーターは以下になります。 
 Exsample
 - 例
 rootNodeGraph = NodegraphAPI.GetRootNode()
 backdrop = NodegraphAPI.CreateNode("Backdrop", rootNodeGraph)
 NodegraphAPI.SetNodeShapeAttr(backdrop, "text", "Backdrop Text Is Here")
 NodegraphAPI.SetNodeShapeAttr(backdrop, "fontScale", 3)
 NodegraphAPI.SetNodeShapeAttr(backdrop, "colorr", 0.18)
 NodegraphAPI.SetNodeShapeAttr(backdrop, "colorg", 0.18)
 NodegraphAPI.SetNodeShapeAttr(backdrop, "colorb", 0.18)
 NodegraphAPI.SetNodeShapeAttr(backdrop, "sizeX", 600)
 NodegraphAPI.SetNodeShapeAttr(backdrop, "sizeY", 1000)
 Parameter
 Value
 text
 String
 fontScale
 Int
 colorr
 float
 colorg
 float
 colorb
 float
 sizeX
 float
 sizeY
 float