Page MenuHome

Add importer code in Cycles Standalone XML API
AbandonedPublic

Authored by Lin (nilram) on Mar 16 2016, 4:30 PM.

Details

Reviewers
None
Group Reviewers
Cycles
Summary

Added the importer code fir RGBCurvesNode in xml_read_shader_graph() function
Changed the way to read shader, support reading from different places

Diff Detail

Event Timeline

Lin (nilram) retitled this revision from to Add importer code in Cycles Standalone XML API.
Lin (nilram) updated this object.
Lin (nilram) added a reviewer: Cycles.
Lin (nilram) set the repository for this revision to rC Cycles.

The rgbcurvesnode is a subnode under the <shader></shader> tag and cannot be loaded like the mesh data. It's not elegant to add a line in the xml_read_scene() specially for rgbcurvesnode. I feel it would be better to change the import code of xml_read_shader(): Check if the name already existed in the state.scene->shaders. So the nodes in a shader can be imported from different places.

For example

File 1

<cycles>
<shader name="name_1">

<certain_node />

</shader>

<include src="//File 2.xml" />
</cycles>

File 2

<cycles>
<shader name="name_1">

<certain_node />

</shader>
</cycles>

Martijn Berger (juicyfruit) added inline comments.
E:\LinM\blender\cycles\src\app\cycles_xml.cpp
1305 ↗(On Diff #6262)

I am assuming this is a debug print?

Also we do have a proper logging infrastructure in cycles, so please use that

Lin (nilram) removed rC Cycles as the repository for this revision.

To allow import the <shader></shader> with same name need to cache the node map. This may require new variable in the XMLReadState.
So currently the importer code of rgb curves node open a new XML document and process the data within the function xml_read_shader_graph()

This comment was removed by Lin (nilram).

Hi Martijn

I'm sorry this is my first time try to submit a patch so I might make some mistakes. And I also updated the code for the reason I wrote in my last comment.

In the xml file the rgb curves node now would be like
<rgb_curves name="test_rgb_curves" src="./objects/curves_data.xml"/>

and in the curves_data.xml, the curves data will be like
<cycles>

<curves_data name="curves_data" size="256" rcurve="... " gcurve="... " bcurve="... "/>

</cycles>

Sergey Sharybin (sergey) added inline comments.
src/app/cycles_xml.cpp
403

We should avoid having such a direct linkage, this is something <include> is intended to do. Benefits:

  • Gives ability to inline (or bake if you wish) everything in a single file which is always handy for interchange pipeline.
  • Uses single linkage mechanism.

Surely some changes will need to be done in xml_read_include() or something like that.

Perhaps easiest way to go would be to:

  • Split xml_read_shader_graph() so the loop calls xml_read_shader_node()
  • Make xml_read_scene() aware of <node>, which will then add that node to a current shader
  • Instead of linking just a node data, link will happen to a full node definition.
412

Code style: should be no space between keyword and brace.

413

You're reporting error here, but still keep reading the node. Straight way to either write pass the array boundaries or to have uninitialized values.

415

Why's that int and why not to use array of vectors instead?

420

Please always use parenthesis.

421

Code style.

423

Why is that?

Hi Martijn

I'm sorry this is my first time try to submit a patch so I might make some mistakes.

That is not a problem. You cannot learn without that, we just try to give the best possible feedback :)

Hi Sergey,

To support inline node, the xml file would be like

scene.xml
<cycles>
<shader name="shader_1">
<include src="node.xml">
</shader>
</cycles>

node.xml
<cycles>
<noise_texture name="tex" scale="2.0"/>
</cycles>

  1. I think an extra variable map<string, ShaderNode*> currentnodemap is needed in XMLReadState.
  2. There are different kinds of shader nodes, to make the xml_read_scene() aware of shader node
    • change the shader node definition to <shader_node type="type_shader_node(e.g. rgbcurvesnode)" name="rgb_curves(for connect)">

Do you think this is the proper way? Thanks

Lin (nilram) updated this revision to Diff 6268.EditedMar 18 2016, 5:23 AM

Load shader node from different places.

scene.xml
<cycles>
<background>
<shader_node type="sky_texture" name="tex" />
<include src="./shader_node.xml" />
<shader_node type="connect" from="tex color" to="bg color" />
<shader_node type="connect" from="bg background" to="output surface" />
</background>
</cycles>

shader_node.xml
<cycles>
<shader_node type="background" name="bg" strength="8.0" />
</cycles>

No longer necessary now that there is generic code for importing all shader nodes and sockets.