blob: b3a362fbf3e286912a1c0f4c0f8447b053d3e215 (
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
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_input_instance_scale_cc {
static void node_declare(NodeDeclarationBuilder &b)
{
b.add_output<decl::Vector>(N_("Scale")).field_source();
}
class VectorFieldInput final : public GeometryFieldInput {
public:
VectorFieldInput() : GeometryFieldInput(CPPType::get<float3>(), "Scale")
{
}
GVArray get_varray_for_context(const GeometryComponent &component,
const eAttrDomain UNUSED(domain),
IndexMask UNUSED(mask)) const final
{
if (component.type() != GEO_COMPONENT_TYPE_INSTANCES) {
return {};
}
const InstancesComponent &instance_component = static_cast<const InstancesComponent &>(
component);
auto scale_fn = [&](const int i) -> float3 {
return instance_component.instance_transforms()[i].scale();
};
return VArray<float3>::ForFunc(instance_component.instances_num(), scale_fn);
}
uint64_t hash() const override
{
return 8346343;
}
bool is_equal_to(const fn::FieldNode &other) const override
{
return dynamic_cast<const VectorFieldInput *>(&other) != nullptr;
}
};
static void node_geo_exec(GeoNodeExecParams params)
{
Field<float3> scale{std::make_shared<VectorFieldInput>()};
params.set_output("Scale", std::move(scale));
}
} // namespace blender::nodes::node_geo_input_instance_scale_cc
void register_node_type_geo_input_instance_scale()
{
namespace file_ns = blender::nodes::node_geo_input_instance_scale_cc;
static bNodeType ntype;
geo_node_type_base(&ntype, GEO_NODE_INPUT_INSTANCE_SCALE, "Instance Scale", NODE_CLASS_INPUT);
ntype.geometry_node_execute = file_ns::node_geo_exec;
ntype.declare = file_ns::node_declare;
nodeRegisterType(&ntype);
}
|