Blender Git Commit Log

Git Commits -> Revision cdc764d

October 28, 2020, 11:28 (GMT)
Cycles API: use getters and setters for accessing Node sockets

Introduce a set of macros to define getters and setters for accessing or modifying socket data. This is needed to detect data changes.

For each socket the macros define the following methods:

```
get_x()
set_x()
is_x_modified()
```

where x is the name of the socket.

is_x_modified() is a convenience to access the state of the underlying socket's update_flag.

Since the macros define the methods in header files, and use the Node API, we run into a few issues:

* some Node have a member called `type`, e.g. in Geometry to discriminate between Mesh, Volume, or Hair, which conflicts with Node::type, so those members were renamed (to `geometry_type`, `wave_type`, etc.)

* we have to include header files defining nodes if a pointer to the node is used. This is because Node::set has multiple overload but the C++ type system will cast the pointer to bool and use Node::set(bool) instead of Node::set(Node*) if it cannot know the pointer derives from Node. This will lead to a runtime error, most likely a crash, perhaps we can make some changes to have a compile time error instead.

* properties that are arrays of typed Nodes (like Geometry::used_shaders) were converted to array<Node *> so they can be used with Node::set(array<Node *>)

Class members corresponding to sockets are now `protected` (so derived classes can access them), and other members who were accessed in the Blender exporter but were not sockets were transformed into sockets where it made sense.

For the Mesh node, the structures containing subdivision data were split into array sockets; added a convenience method for accessing the data as structure (`SubdFace` and `SubdEdgeCrease`). In some cases, this seems to improve cache coherency as only one of the array is accessed.

The interface to export Blender data to Cycles does not play well with the idea of updating sockets in one go. Mesh and Hair classes have convenience methods to set their data which modifies multiple sockets simultaneously (e.g. Mesh::add_triangle modifies the `triangle`, `smooth` and `shader` sockets), but ideally we would need to set the (new) data at once to detect changes. I am not sure what the best approach is for that, so I have simply modified the exporter to use temporary Mesh and Hair node to accumulate the data and update the original objects in one go, which will set the update flags appropriately. This is not so nice as the API that modify multiple sockets is still present on the Mesh or Hair class, and might confuse API clients. One idea would be to introduce the concept of `{Mesh|Hair}Builder` to accumulate the data; this would require to change the way Attributes are allocated (which is accessing the Geometry for knowing the data size) and also refactor the exporter a bit more.

Reviewed By: brecht

Maniphest Tasks: T79174

Differential Revision: https://developer.blender.org/D8544

Commit Details:

Full Hash: cdc764d329474c01ee63bed7bf7f5fbb17e0d1b8
Parent Commit: d6180dd
Lines Changed: +2366, -1789

61 Modified Paths:

/intern/cycles/blender/blender_camera.cpp (+75, -66) (Diff)
/intern/cycles/blender/blender_curves.cpp (+38, -33) (Diff)
/intern/cycles/blender/blender_geometry.cpp (+6, -5) (Diff)
/intern/cycles/blender/blender_light.cpp (+53, -53) (Diff)
/intern/cycles/blender/blender_mesh.cpp (+82, -73) (Diff)
/intern/cycles/blender/blender_object.cpp (+48, -60) (Diff)
/intern/cycles/blender/blender_object_cull.cpp (+3, -3) (Diff)
/intern/cycles/blender/blender_particles.cpp (+8, -6) (Diff)
/intern/cycles/blender/blender_session.cpp (+17, -16) (Diff)
/intern/cycles/blender/blender_shader.cpp (+223, -201) (Diff)
/intern/cycles/blender/blender_sync.cpp (+93, -97) (Diff)
/intern/cycles/blender/blender_sync.h (+4, -4) (Diff)
/intern/cycles/blender/blender_volume.cpp (+6, -8) (Diff)
/intern/cycles/bvh/bvh.cpp (+10, -10) (Diff)
/intern/cycles/bvh/bvh_build.cpp (+18, -18) (Diff)
/intern/cycles/bvh/bvh_embree.cpp (+29, -28) (Diff)
/intern/cycles/bvh/bvh_optix.cpp (+8, -8) (Diff)
/intern/cycles/bvh/bvh_split.cpp (+10, -9) (Diff)
/intern/cycles/bvh/bvh_unaligned.cpp (+4, -4) (Diff)
/intern/cycles/device/device_optix.cpp (+39, -34) (Diff)
/intern/cycles/graph/node.cpp (+80, -5) (Diff)
/intern/cycles/graph/node.h (+61, -0) (Diff)
/intern/cycles/render/attribute.cpp (+18, -18) (Diff)
/intern/cycles/render/background.cpp (+4, -10) (Diff)
/intern/cycles/render/background.h (+10, -13) (Diff)
/intern/cycles/render/bake.cpp (+8, -7) (Diff)
/intern/cycles/render/camera.cpp (+40, -36) (Diff)
/intern/cycles/render/camera.h (+60, -43) (Diff)
/intern/cycles/render/film.cpp (+47, -18) (Diff)
/intern/cycles/render/film.h (+28, -24) (Diff)
/intern/cycles/render/geometry.cpp (+77, -65) (Diff)
/intern/cycles/render/geometry.h (+29, -5) (Diff)
/intern/cycles/render/graph.cpp (+11, -11) (Diff)
/intern/cycles/render/hair.cpp (+3, -2) (Diff)
/intern/cycles/render/hair.h (+4, -4) (Diff)
/intern/cycles/render/image.cpp (+1, -1) (Diff)
/intern/cycles/render/image.h (+1, -1) (Diff)
/intern/cycles/render/integrator.cpp (+5, -11) (Diff)
/intern/cycles/render/integrator.h (+34, -37) (Diff)
/intern/cycles/render/light.cpp (+48, -50) (Diff)
/intern/cycles/render/light.h (+33, -27) (Diff)
/intern/cycles/render/mesh.cpp (+140, -25) (Diff)
/intern/cycles/render/mesh.h (+66, -14) (Diff)
/intern/cycles/render/mesh_displace.cpp (+10, -9) (Diff)
/intern/cycles/render/mesh_subdivision.cpp (+38, -31) (Diff)
/intern/cycles/render/nodes.cpp (+77, -70) (Diff)
/intern/cycles/render/nodes.h (+380, -281) (Diff)
/intern/cycles/render/object.cpp (+44, -31) (Diff)
/intern/cycles/render/object.h (+23, -18) (Diff)
/intern/cycles/render/osl.cpp (+5, -5) (Diff)
/intern/cycles/render/scene.cpp (+21, -19) (Diff)
/intern/cycles/render/session.cpp (+12, -15) (Diff)
/intern/cycles/render/shader.cpp (+27, -24) (Diff)
/intern/cycles/render/shader.h (+12, -12) (Diff)
/intern/cycles/render/svm.cpp (+5, -5) (Diff)
/intern/cycles/render/volume.cpp (+10, -8) (Diff)
/intern/cycles/render/volume.h (+3, -3) (Diff)
/intern/cycles/subd/subd_dice.cpp (+3, -3) (Diff)
/intern/cycles/subd/subd_split.cpp (+6, -6) (Diff)
/intern/cycles/test/render_graph_finalize_test.cpp (+88, -86) (Diff)
/intern/cycles/util/util_array.h (+20, -0) (Diff)
By: Miika HämäläinenLast update: Nov-07-2014 14:18MiikaHweb | 2003-2021