Blender V5.0
procedural.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "graph/node.h"
8
10
12
13class Progress;
14class Scene;
15
16/* A Procedural is a Node which can create other Nodes before rendering starts.
17 *
18 * The Procedural is supposed to be the owner of any nodes that it creates. It can also create
19 * Nodes directly in the Scene (through Scene.create_node), it should still be set as the owner of
20 * those Nodes.
21 */
22class Procedural : public Node, public NodeOwner {
23 public:
25
26 explicit Procedural(const NodeType *type);
27 ~Procedural() override;
28
29 /* Called each time the ProceduralManager is tagged for an update, this function is the entry
30 * point for the data generated by this Procedural. */
31 virtual void generate(Scene *scene, Progress &progress) = 0;
32
33 /* Create a node and set this Procedural as the owner. */
34 template<typename T> T *create_node()
35 {
36 unique_ptr<T> node = make_unique<T>();
37 T *node_ptr = node.get();
38 node->set_owner(this);
39 nodes.push_back(std::move(node));
40 return node_ptr;
41 }
42
43 /* Delete a Node created and owned by this Procedural. */
44 template<typename T> void delete_node(T *node)
45 {
46 assert(node->get_owner() == this);
47 nodes.erase(node);
48 }
49
50 protected:
52};
53
55 bool need_update_;
56
57 public:
60
61 void update(Scene *scene, Progress &progress);
62
63 void tag_update();
64
65 bool need_update() const;
66};
67
bool need_update() const
void update(Scene *scene, Progress &progress)
~Procedural() override
unique_ptr_vector< Node > nodes
Definition procedural.h:51
T * create_node()
Definition procedural.h:34
virtual void generate(Scene *scene, Progress &progress)=0
void delete_node(T *node)
Definition procedural.h:44
NODE_ABSTRACT_DECLARE Procedural(const NodeType *type)
#define CCL_NAMESPACE_END
#define assert(assertion)
#define T
#define NODE_ABSTRACT_DECLARE
Definition node_type.h:171
const NodeType * type
Definition graph/node.h:178
Node(const NodeType *type, ustring name=ustring())