2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2024-12-26 17:53:56 +01:00
|
|
|
#pragma once
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
#include <cstring>
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/geometry.h"
|
|
|
|
|
#include "scene/scene.h"
|
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does
this by directly adding and removing nodes from the scene data. If some node is not tagged
as used at the end of a synchronization, it then deletes the node from the scene. This poses
a problem when it comes to supporting procedural nodes who can create other nodes not known
by the Blender synchonization system, which will remove them.
Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene
for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting
nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods
found on the owners. `delete_node` will assert that the owner is the right one.
Whenever a scene level node is created or deleted, the appropriate node manager is tagged for
an update, freeing this responsability from BlenderSync or other software exporters.
Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they
only keep track of which nodes are used, employing the scene to create and delete them. To
achieve this, the ParticleSystem is now a Node, although it does not have any sockets.
This is part of T79131.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8540
2020-08-30 23:20:51 +02:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/map.h"
|
|
|
|
|
#include "util/set.h"
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
#include "RNA_blender_cpp.hh"
|
|
|
|
|
|
2020-02-02 13:09:18 +01:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
/* ID Map
|
|
|
|
|
*
|
|
|
|
|
* Utility class to map between Blender datablocks and Cycles data structures,
|
|
|
|
|
* and keep track of recalc tags from the dependency graph. */
|
|
|
|
|
|
Attribute Node: support accessing attributes of View Layer and Scene.
The attribute node already allows accessing attributes associated
with objects and meshes, which allows changing the behavior of the
same material between different objects or instances. The same idea
can be extended to an even more global level of layers and scenes.
Currently view layers provide an option to replace all materials
with a different one. However, since the same material will be applied
to all objects in the layer, varying the behavior between layers while
preserving distinct materials requires duplicating objects.
Providing access to properties of layers and scenes via the attribute
node enables making materials with built-in switches or settings that
can be controlled globally at the view layer level. This is probably
most useful for complex NPR shading and compositing. Like with objects,
the node can also access built-in scene properties, like render resolution
or FOV of the active camera. Lookup is also attempted in World, similar
to how the Object mode checks the Mesh datablock.
In Cycles this mode is implemented by replacing the attribute node with
the attribute value during sync, allowing constant folding to take the
values into account. This means however that materials that use this
feature have to be re-synced upon any changes to scene, world or camera.
The Eevee version uses a new uniform buffer containing a sorted array
mapping name hashes to values, with binary search lookup. The array
is limited to 512 entries, which is effectively limitless even
considering it is shared by all materials in the scene; it is also
just 16KB of memory so no point trying to optimize further.
The buffer has to be rebuilt when new attributes are detected in a
material, so the draw engine keeps a table of recently seen attribute
names to minimize the chance of extra rebuilds mid-draw.
Differential Revision: https://developer.blender.org/D15941
2022-09-12 00:30:58 +03:00
|
|
|
template<typename K, typename T, typename Flags = uint> class id_map {
|
2020-02-02 13:09:18 +01:00
|
|
|
public:
|
2023-03-29 16:50:54 +02:00
|
|
|
id_map(Scene *scene_) : scene(scene_) {}
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2020-10-29 14:40:29 +01:00
|
|
|
~id_map()
|
|
|
|
|
{
|
|
|
|
|
set<T *> nodes;
|
|
|
|
|
|
|
|
|
|
typename map<K, T *>::iterator jt;
|
|
|
|
|
for (jt = b_map.begin(); jt != b_map.end(); jt++) {
|
|
|
|
|
nodes.insert(jt->second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scene->delete_nodes(nodes);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 13:09:18 +01:00
|
|
|
T *find(const BL::ID &id)
|
|
|
|
|
{
|
|
|
|
|
return find(id.ptr.owner_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
T *find(const K &key)
|
|
|
|
|
{
|
|
|
|
|
if (b_map.find(key) != b_map.end()) {
|
|
|
|
|
T *data = b_map[key];
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-26 17:53:55 +01:00
|
|
|
return nullptr;
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_recalc(const BL::ID &id)
|
|
|
|
|
{
|
|
|
|
|
b_recalc.insert(id.ptr.data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_recalc(void *id_ptr)
|
|
|
|
|
{
|
|
|
|
|
b_recalc.insert(id_ptr);
|
|
|
|
|
}
|
|
|
|
|
|
Attribute Node: support accessing attributes of View Layer and Scene.
The attribute node already allows accessing attributes associated
with objects and meshes, which allows changing the behavior of the
same material between different objects or instances. The same idea
can be extended to an even more global level of layers and scenes.
Currently view layers provide an option to replace all materials
with a different one. However, since the same material will be applied
to all objects in the layer, varying the behavior between layers while
preserving distinct materials requires duplicating objects.
Providing access to properties of layers and scenes via the attribute
node enables making materials with built-in switches or settings that
can be controlled globally at the view layer level. This is probably
most useful for complex NPR shading and compositing. Like with objects,
the node can also access built-in scene properties, like render resolution
or FOV of the active camera. Lookup is also attempted in World, similar
to how the Object mode checks the Mesh datablock.
In Cycles this mode is implemented by replacing the attribute node with
the attribute value during sync, allowing constant folding to take the
values into account. This means however that materials that use this
feature have to be re-synced upon any changes to scene, world or camera.
The Eevee version uses a new uniform buffer containing a sorted array
mapping name hashes to values, with binary search lookup. The array
is limited to 512 entries, which is effectively limitless even
considering it is shared by all materials in the scene; it is also
just 16KB of memory so no point trying to optimize further.
The buffer has to be rebuilt when new attributes are detected in a
material, so the draw engine keeps a table of recently seen attribute
names to minimize the chance of extra rebuilds mid-draw.
Differential Revision: https://developer.blender.org/D15941
2022-09-12 00:30:58 +03:00
|
|
|
bool check_recalc(const BL::ID &id)
|
|
|
|
|
{
|
|
|
|
|
return id.ptr.data && b_recalc.find(id.ptr.data) != b_recalc.end();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 13:09:18 +01:00
|
|
|
bool has_recalc()
|
|
|
|
|
{
|
|
|
|
|
return !(b_recalc.empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pre_sync()
|
|
|
|
|
{
|
|
|
|
|
used_set.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
/* Add new data. */
|
|
|
|
|
void add(const K &key, T *data)
|
2020-02-02 13:09:18 +01:00
|
|
|
{
|
2024-12-26 17:53:55 +01:00
|
|
|
assert(find(key) == nullptr);
|
2020-02-02 12:04:19 +01:00
|
|
|
b_map[key] = data;
|
|
|
|
|
used(data);
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
/* Update existing data. */
|
|
|
|
|
bool update(T *data, const BL::ID &id)
|
2020-02-02 13:09:18 +01:00
|
|
|
{
|
2020-02-02 12:04:19 +01:00
|
|
|
return update(data, id, id);
|
|
|
|
|
}
|
|
|
|
|
bool update(T *data, const BL::ID &id, const BL::ID &parent)
|
|
|
|
|
{
|
|
|
|
|
bool recalc = (b_recalc.find(id.ptr.data) != b_recalc.end());
|
|
|
|
|
if (parent.ptr.data && parent.ptr.data != id.ptr.data) {
|
|
|
|
|
recalc = recalc || (b_recalc.find(parent.ptr.data) != b_recalc.end());
|
|
|
|
|
}
|
|
|
|
|
used(data);
|
|
|
|
|
return recalc;
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
/* Combined add and update as needed. */
|
2020-10-29 14:40:29 +01:00
|
|
|
bool add_or_update(T **r_data, const BL::ID &id)
|
2020-02-02 12:04:19 +01:00
|
|
|
{
|
2020-10-29 14:40:29 +01:00
|
|
|
return add_or_update(r_data, id, id, id.ptr.owner_id);
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2020-10-29 14:40:29 +01:00
|
|
|
bool add_or_update(T **r_data, const BL::ID &id, const K &key)
|
2020-02-02 12:04:19 +01:00
|
|
|
{
|
2020-10-29 14:40:29 +01:00
|
|
|
return add_or_update(r_data, id, id, key);
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2020-10-29 14:40:29 +01:00
|
|
|
bool add_or_update(T **r_data, const BL::ID &id, const BL::ID &parent, const K &key)
|
2020-02-02 13:09:18 +01:00
|
|
|
{
|
|
|
|
|
T *data = find(key);
|
|
|
|
|
bool recalc;
|
|
|
|
|
|
|
|
|
|
if (!data) {
|
2020-02-02 12:04:19 +01:00
|
|
|
/* Add data if it didn't exist yet. */
|
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does
this by directly adding and removing nodes from the scene data. If some node is not tagged
as used at the end of a synchronization, it then deletes the node from the scene. This poses
a problem when it comes to supporting procedural nodes who can create other nodes not known
by the Blender synchonization system, which will remove them.
Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene
for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting
nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods
found on the owners. `delete_node` will assert that the owner is the right one.
Whenever a scene level node is created or deleted, the appropriate node manager is tagged for
an update, freeing this responsability from BlenderSync or other software exporters.
Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they
only keep track of which nodes are used, employing the scene to create and delete them. To
achieve this, the ParticleSystem is now a Node, although it does not have any sockets.
This is part of T79131.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8540
2020-08-30 23:20:51 +02:00
|
|
|
data = scene->create_node<T>();
|
2020-02-02 12:04:19 +01:00
|
|
|
add(key, data);
|
2020-02-02 13:09:18 +01:00
|
|
|
recalc = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-02-02 12:04:19 +01:00
|
|
|
/* check if updated needed. */
|
|
|
|
|
recalc = update(data, id, parent);
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*r_data = data;
|
|
|
|
|
return recalc;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
/* Combined add or update for convenience. */
|
|
|
|
|
|
2020-02-02 13:09:18 +01:00
|
|
|
bool is_used(const K &key)
|
|
|
|
|
{
|
|
|
|
|
T *data = find(key);
|
|
|
|
|
return (data) ? used_set.find(data) != used_set.end() : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void used(T *data)
|
|
|
|
|
{
|
|
|
|
|
/* tag data as still in use */
|
|
|
|
|
used_set.insert(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_default(T *data)
|
|
|
|
|
{
|
2024-12-26 17:53:55 +01:00
|
|
|
b_map[nullptr] = data;
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-29 14:40:29 +01:00
|
|
|
void post_sync(bool do_delete = true)
|
2020-02-02 13:09:18 +01:00
|
|
|
{
|
|
|
|
|
map<K, T *> new_map;
|
2024-12-26 17:53:59 +01:00
|
|
|
using TMapPair = pair<const K, T *>;
|
2020-02-02 13:09:18 +01:00
|
|
|
typename map<K, T *>::iterator jt;
|
|
|
|
|
|
|
|
|
|
for (jt = b_map.begin(); jt != b_map.end(); jt++) {
|
|
|
|
|
TMapPair &pair = *jt;
|
|
|
|
|
|
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does
this by directly adding and removing nodes from the scene data. If some node is not tagged
as used at the end of a synchronization, it then deletes the node from the scene. This poses
a problem when it comes to supporting procedural nodes who can create other nodes not known
by the Blender synchonization system, which will remove them.
Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene
for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting
nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods
found on the owners. `delete_node` will assert that the owner is the right one.
Whenever a scene level node is created or deleted, the appropriate node manager is tagged for
an update, freeing this responsability from BlenderSync or other software exporters.
Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they
only keep track of which nodes are used, employing the scene to create and delete them. To
achieve this, the ParticleSystem is now a Node, although it does not have any sockets.
This is part of T79131.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8540
2020-08-30 23:20:51 +02:00
|
|
|
if (do_delete && used_set.find(pair.second) == used_set.end()) {
|
Attribute Node: support accessing attributes of View Layer and Scene.
The attribute node already allows accessing attributes associated
with objects and meshes, which allows changing the behavior of the
same material between different objects or instances. The same idea
can be extended to an even more global level of layers and scenes.
Currently view layers provide an option to replace all materials
with a different one. However, since the same material will be applied
to all objects in the layer, varying the behavior between layers while
preserving distinct materials requires duplicating objects.
Providing access to properties of layers and scenes via the attribute
node enables making materials with built-in switches or settings that
can be controlled globally at the view layer level. This is probably
most useful for complex NPR shading and compositing. Like with objects,
the node can also access built-in scene properties, like render resolution
or FOV of the active camera. Lookup is also attempted in World, similar
to how the Object mode checks the Mesh datablock.
In Cycles this mode is implemented by replacing the attribute node with
the attribute value during sync, allowing constant folding to take the
values into account. This means however that materials that use this
feature have to be re-synced upon any changes to scene, world or camera.
The Eevee version uses a new uniform buffer containing a sorted array
mapping name hashes to values, with binary search lookup. The array
is limited to 512 entries, which is effectively limitless even
considering it is shared by all materials in the scene; it is also
just 16KB of memory so no point trying to optimize further.
The buffer has to be rebuilt when new attributes are detected in a
material, so the draw engine keeps a table of recently seen attribute
names to minimize the chance of extra rebuilds mid-draw.
Differential Revision: https://developer.blender.org/D15941
2022-09-12 00:30:58 +03:00
|
|
|
flags.erase(pair.second);
|
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does
this by directly adding and removing nodes from the scene data. If some node is not tagged
as used at the end of a synchronization, it then deletes the node from the scene. This poses
a problem when it comes to supporting procedural nodes who can create other nodes not known
by the Blender synchonization system, which will remove them.
Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene
for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting
nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods
found on the owners. `delete_node` will assert that the owner is the right one.
Whenever a scene level node is created or deleted, the appropriate node manager is tagged for
an update, freeing this responsability from BlenderSync or other software exporters.
Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they
only keep track of which nodes are used, employing the scene to create and delete them. To
achieve this, the ParticleSystem is now a Node, although it does not have any sockets.
This is part of T79131.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8540
2020-08-30 23:20:51 +02:00
|
|
|
scene->delete_node(pair.second);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-02-02 13:09:18 +01:00
|
|
|
new_map[pair.first] = pair.second;
|
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does
this by directly adding and removing nodes from the scene data. If some node is not tagged
as used at the end of a synchronization, it then deletes the node from the scene. This poses
a problem when it comes to supporting procedural nodes who can create other nodes not known
by the Blender synchonization system, which will remove them.
Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene
for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting
nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods
found on the owners. `delete_node` will assert that the owner is the right one.
Whenever a scene level node is created or deleted, the appropriate node manager is tagged for
an update, freeing this responsability from BlenderSync or other software exporters.
Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they
only keep track of which nodes are used, employing the scene to create and delete them. To
achieve this, the ParticleSystem is now a Node, although it does not have any sockets.
This is part of T79131.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8540
2020-08-30 23:20:51 +02:00
|
|
|
}
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
used_set.clear();
|
|
|
|
|
b_recalc.clear();
|
|
|
|
|
b_map = new_map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const map<K, T *> &key_to_scene_data()
|
|
|
|
|
{
|
|
|
|
|
return b_map;
|
|
|
|
|
}
|
|
|
|
|
|
Attribute Node: support accessing attributes of View Layer and Scene.
The attribute node already allows accessing attributes associated
with objects and meshes, which allows changing the behavior of the
same material between different objects or instances. The same idea
can be extended to an even more global level of layers and scenes.
Currently view layers provide an option to replace all materials
with a different one. However, since the same material will be applied
to all objects in the layer, varying the behavior between layers while
preserving distinct materials requires duplicating objects.
Providing access to properties of layers and scenes via the attribute
node enables making materials with built-in switches or settings that
can be controlled globally at the view layer level. This is probably
most useful for complex NPR shading and compositing. Like with objects,
the node can also access built-in scene properties, like render resolution
or FOV of the active camera. Lookup is also attempted in World, similar
to how the Object mode checks the Mesh datablock.
In Cycles this mode is implemented by replacing the attribute node with
the attribute value during sync, allowing constant folding to take the
values into account. This means however that materials that use this
feature have to be re-synced upon any changes to scene, world or camera.
The Eevee version uses a new uniform buffer containing a sorted array
mapping name hashes to values, with binary search lookup. The array
is limited to 512 entries, which is effectively limitless even
considering it is shared by all materials in the scene; it is also
just 16KB of memory so no point trying to optimize further.
The buffer has to be rebuilt when new attributes are detected in a
material, so the draw engine keeps a table of recently seen attribute
names to minimize the chance of extra rebuilds mid-draw.
Differential Revision: https://developer.blender.org/D15941
2022-09-12 00:30:58 +03:00
|
|
|
bool test_flag(T *data, Flags val)
|
|
|
|
|
{
|
|
|
|
|
typename map<T *, uint>::iterator it = flags.find(data);
|
|
|
|
|
return it != flags.end() && (it->second & (1 << val)) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_flag(T *data, Flags val)
|
|
|
|
|
{
|
|
|
|
|
flags[data] |= (1 << val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clear_flag(T *data, Flags val)
|
|
|
|
|
{
|
|
|
|
|
typename map<T *, uint>::iterator it = flags.find(data);
|
|
|
|
|
if (it != flags.end()) {
|
|
|
|
|
it->second &= ~(1 << val);
|
|
|
|
|
|
|
|
|
|
if (it->second == 0) {
|
|
|
|
|
flags.erase(it);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 13:09:18 +01:00
|
|
|
protected:
|
|
|
|
|
map<K, T *> b_map;
|
|
|
|
|
set<T *> used_set;
|
Attribute Node: support accessing attributes of View Layer and Scene.
The attribute node already allows accessing attributes associated
with objects and meshes, which allows changing the behavior of the
same material between different objects or instances. The same idea
can be extended to an even more global level of layers and scenes.
Currently view layers provide an option to replace all materials
with a different one. However, since the same material will be applied
to all objects in the layer, varying the behavior between layers while
preserving distinct materials requires duplicating objects.
Providing access to properties of layers and scenes via the attribute
node enables making materials with built-in switches or settings that
can be controlled globally at the view layer level. This is probably
most useful for complex NPR shading and compositing. Like with objects,
the node can also access built-in scene properties, like render resolution
or FOV of the active camera. Lookup is also attempted in World, similar
to how the Object mode checks the Mesh datablock.
In Cycles this mode is implemented by replacing the attribute node with
the attribute value during sync, allowing constant folding to take the
values into account. This means however that materials that use this
feature have to be re-synced upon any changes to scene, world or camera.
The Eevee version uses a new uniform buffer containing a sorted array
mapping name hashes to values, with binary search lookup. The array
is limited to 512 entries, which is effectively limitless even
considering it is shared by all materials in the scene; it is also
just 16KB of memory so no point trying to optimize further.
The buffer has to be rebuilt when new attributes are detected in a
material, so the draw engine keeps a table of recently seen attribute
names to minimize the chance of extra rebuilds mid-draw.
Differential Revision: https://developer.blender.org/D15941
2022-09-12 00:30:58 +03:00
|
|
|
map<T *, uint> flags;
|
2020-02-02 13:09:18 +01:00
|
|
|
set<void *> b_recalc;
|
2020-10-29 14:40:29 +01:00
|
|
|
Scene *scene;
|
2020-02-02 13:09:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Object Key
|
|
|
|
|
*
|
|
|
|
|
* To uniquely identify instances, we use the parent, object and persistent instance ID.
|
|
|
|
|
* We also export separate object for a mesh and its particle hair. */
|
|
|
|
|
|
2020-07-06 16:52:28 +02:00
|
|
|
enum { OBJECT_PERSISTENT_ID_SIZE = 8 /* MAX_DUPLI_RECUR in Blender. */ };
|
2020-02-02 13:09:18 +01:00
|
|
|
|
|
|
|
|
struct ObjectKey {
|
|
|
|
|
void *parent;
|
|
|
|
|
int id[OBJECT_PERSISTENT_ID_SIZE];
|
|
|
|
|
void *ob;
|
|
|
|
|
bool use_particle_hair;
|
|
|
|
|
|
|
|
|
|
ObjectKey(void *parent_, int id_[OBJECT_PERSISTENT_ID_SIZE], void *ob_, bool use_particle_hair_)
|
|
|
|
|
: parent(parent_), ob(ob_), use_particle_hair(use_particle_hair_)
|
|
|
|
|
{
|
2023-09-24 14:52:38 +10:00
|
|
|
if (id_) {
|
2020-02-02 13:09:18 +01:00
|
|
|
memcpy(id, id_, sizeof(id));
|
2023-09-24 14:52:38 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2020-02-02 13:09:18 +01:00
|
|
|
memset(id, 0, sizeof(id));
|
2023-09-24 14:52:38 +10:00
|
|
|
}
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator<(const ObjectKey &k) const
|
|
|
|
|
{
|
|
|
|
|
if (ob < k.ob) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
if (ob == k.ob) {
|
2020-02-02 13:09:18 +01:00
|
|
|
if (parent < k.parent) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
if (parent == k.parent) {
|
2020-02-02 13:09:18 +01:00
|
|
|
if (use_particle_hair < k.use_particle_hair) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
if (use_particle_hair == k.use_particle_hair) {
|
2020-02-02 13:09:18 +01:00
|
|
|
return memcmp(id, k.id, sizeof(id)) < 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
/* Geometry Key
|
2020-02-02 13:09:18 +01:00
|
|
|
*
|
2020-02-10 10:33:00 +11:00
|
|
|
* We export separate geometry for a mesh and its particle hair, so key needs to
|
2020-02-02 13:09:18 +01:00
|
|
|
* distinguish between them. */
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
struct GeometryKey {
|
2020-02-02 13:09:18 +01:00
|
|
|
void *id;
|
2020-10-26 12:15:52 +01:00
|
|
|
Geometry::Type geometry_type;
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
GeometryKey(void *id, Geometry::Type geometry_type) : id(id), geometry_type(geometry_type) {}
|
2020-02-02 13:09:18 +01:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
bool operator<(const GeometryKey &k) const
|
2020-02-02 13:09:18 +01:00
|
|
|
{
|
|
|
|
|
if (id < k.id) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
if (id == k.id) {
|
2020-10-26 12:15:52 +01:00
|
|
|
if (geometry_type < k.geometry_type) {
|
2020-02-02 13:09:18 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Particle System Key */
|
|
|
|
|
|
|
|
|
|
struct ParticleSystemKey {
|
|
|
|
|
void *ob;
|
|
|
|
|
int id[OBJECT_PERSISTENT_ID_SIZE];
|
|
|
|
|
|
|
|
|
|
ParticleSystemKey(void *ob_, int id_[OBJECT_PERSISTENT_ID_SIZE]) : ob(ob_)
|
|
|
|
|
{
|
2023-09-24 14:52:38 +10:00
|
|
|
if (id_) {
|
2020-02-02 13:09:18 +01:00
|
|
|
memcpy(id, id_, sizeof(id));
|
2023-09-24 14:52:38 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2020-02-02 13:09:18 +01:00
|
|
|
memset(id, 0, sizeof(id));
|
2023-09-24 14:52:38 +10:00
|
|
|
}
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator<(const ParticleSystemKey &k) const
|
|
|
|
|
{
|
|
|
|
|
/* first id is particle index, we don't compare that */
|
2023-09-24 14:52:38 +10:00
|
|
|
if (ob < k.ob) {
|
2020-02-02 13:09:18 +01:00
|
|
|
return true;
|
2023-09-24 14:52:38 +10:00
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
if (ob == k.ob) {
|
2020-02-02 13:09:18 +01:00
|
|
|
return memcmp(id + 1, k.id + 1, sizeof(int) * (OBJECT_PERSISTENT_ID_SIZE - 1)) < 0;
|
2023-09-24 14:52:38 +10:00
|
|
|
}
|
2020-02-02 13:09:18 +01:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|