Welcome to mirror list, hosted at ThFree Co, Russian Federation.

node_geo_collection_info.cc « nodes « geometry « nodes « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e731b4c0cdc66d3ec4711f444802ed3615125055 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "BLI_math_matrix.h"

#include "DNA_collection_types.h"

#include "UI_interface.h"
#include "UI_resources.h"

#include "node_geometry_util.hh"

namespace blender::nodes {

static void geo_node_collection_info_declare(NodeDeclarationBuilder &b)
{
  b.add_input<decl::Collection>("Collection").hide_label(true);
  b.add_output<decl::Geometry>("Geometry");
}

static void geo_node_collection_info_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
  uiItemR(layout, ptr, "transform_space", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}

static void geo_node_collection_info_node_init(bNodeTree *UNUSED(tree), bNode *node)
{
  NodeGeometryCollectionInfo *data = (NodeGeometryCollectionInfo *)MEM_callocN(
      sizeof(NodeGeometryCollectionInfo), __func__);
  data->transform_space = GEO_NODE_TRANSFORM_SPACE_ORIGINAL;
  node->storage = data;
}

static void geo_node_collection_info_exec(GeoNodeExecParams params)
{
  Collection *collection = params.get_input<Collection *>("Collection");

  GeometrySet geometry_set_out;

  if (collection == nullptr) {
    params.set_output("Geometry", geometry_set_out);
    return;
  }

  const bNode &bnode = params.node();
  NodeGeometryCollectionInfo *node_storage = (NodeGeometryCollectionInfo *)bnode.storage;
  const bool transform_space_relative = (node_storage->transform_space ==
                                         GEO_NODE_TRANSFORM_SPACE_RELATIVE);

  InstancesComponent &instances = geometry_set_out.get_component_for_write<InstancesComponent>();

  float transform_mat[4][4];
  unit_m4(transform_mat);
  const Object *self_object = params.self_object();

  if (transform_space_relative) {
    copy_v3_v3(transform_mat[3], collection->instance_offset);

    mul_m4_m4_pre(transform_mat, self_object->imat);
  }

  const int handle = instances.add_reference(*collection);
  instances.add_instance(handle, transform_mat, -1);

  params.set_output("Geometry", geometry_set_out);
}

}  // namespace blender::nodes

void register_node_type_geo_collection_info()
{
  static bNodeType ntype;

  geo_node_type_base(&ntype, GEO_NODE_COLLECTION_INFO, "Collection Info", NODE_CLASS_INPUT, 0);
  ntype.declare = blender::nodes::geo_node_collection_info_declare;
  node_type_init(&ntype, blender::nodes::geo_node_collection_info_node_init);
  node_type_storage(&ntype,
                    "NodeGeometryCollectionInfo",
                    node_free_standard_storage,
                    node_copy_standard_storage);
  ntype.geometry_node_execute = blender::nodes::geo_node_collection_info_exec;
  ntype.draw_buttons = blender::nodes::geo_node_collection_info_layout;
  nodeRegisterType(&ntype);
}