1
1

Compare commits

...

268 Commits

Author SHA1 Message Date
abd2ee4a8d Attribute Compare: Use the most complex data type instead of the least 2020-12-10 09:31:42 -06:00
98b1e09d06 Optimize comparisons by squaring threshold first 2020-12-10 09:09:44 -06:00
4bdb67d5c0 Merge branch 'master' into geometry-nodes-point-separate-node 2020-12-10 08:55:44 -06:00
62953c2bf3 Geometry Nodes: Support equality operations with all data types
Testing equality of vectors can't be done properly if they are implicitly
converted to float before-hand. This adds a lot of boilerplate code to
the node, maybe that can made more elegant in the future, but it's not
so complicated anyway.
2020-12-09 16:42:23 -06:00
0e757da3b5 Geometry Nodes: Add a method to find the lowest complexity attribute
For the attribute comparison node, it makes sense to read both input
attributes implicitly converted to the same data type. But the choice
of which of the two data types to read with is somewhat arbitrary.
This commit adds a utility function to choose the least "complex" data
type as a lowest common denominator, to make that choice less arbitrary
, and to support other needs in the future.
2020-12-09 16:33:09 -06:00
200cbb6adf Geometry Nodes: Add utilities for getting an attribute's data type
With the previous helper function in this file you had to know the data
type you wanted for the input attribute before requesting it. This adds
another utility function for getting the data type without building the
attribute. The attribute's can be requested later after doing some
logic to figure out the right data type to read.

No functional changes in this commit.
2020-12-09 16:29:49 -06:00
c61c9f61c6 Use new get_input_attribute abstraction 2020-12-09 10:29:29 -06:00
9acba6f716 Merge branch 'master' into geometry-nodes-point-separate-node 2020-12-09 09:53:17 -06:00
81fb9720fe Support meshes in addition to point clouds 2020-12-09 09:43:32 -06:00
96feddd85f Use text for comparison RNA enum items 2020-12-09 09:00:24 -06:00
043926bfd2 Merge branch 'master' into geometry-nodes-point-separate-node 2020-12-09 08:35:24 -06:00
ae4afcfbee Merge branch 'master' into geometry-nodes-point-separate-node 2020-12-08 11:27:16 -06:00
e0c199a527 Review feedback: Only move pointcloud, use numbers for naming 2020-12-07 11:56:00 -06:00
d6354a7ee2 Merge branch 'master' into geometry-nodes-point-separate-node 2020-12-07 11:15:41 -06:00
e7ec68cd46 Merge branch 'master' into geometry-nodes-point-separate-node 2020-12-07 08:01:00 -06:00
e902379764 Geometry Nodes: Attribute compare node
This node reads two input attributes as floats and allows for basic
element-wise comparison operations. Like the attribute math node,
it's also possible to switch to using floats as inputs. This node can
be combined with the point separate node for more flexibility on which
points to separate out.

I used the same abstractions that the attribute math node uses in this
commit, assuming that makes sense.
2020-12-03 22:50:45 -06:00
be3bb4da03 Geometry Nodes: Refactor and change point separate node
The threshold input is unecessary with an "attribute compare"
node before this one, or with attribute rounding. So to remove some
complexity it is removed, and a boolean input attribute is used instead.

For the implementation, the existing code becomes a bit more specific
to point cloud data, because I'm realizing that mesh separate is quite a
different problem, and it doesn't make sense to force the same code
to be able to solve that too.
2020-12-03 18:31:10 -06:00
6505f9c09a Geometry Nodes: Add boolean type to random attribute node 2020-12-03 18:27:20 -06:00
d9b8ddd883 Geometry Nodes: Add a boolean attribute data type 2020-12-03 18:23:21 -06:00
f58d9d7500 Merge branch 'master' into geometry-nodes-point-separate-node 2020-12-03 11:31:18 -06:00
920edc358c Merge branch 'geometry-nodes' into geometry-nodes-point-separate-node 2020-12-03 11:31:05 -06:00
390c4efa0c Merge branch 'master' into geometry-nodes 2020-12-02 16:58:44 +01:00
2f0f269684 Point Separate Node: Change has_attribute function 2020-12-02 09:08:33 -05:00
267ba329ec Point separate node: Refactor, add comments, clean up
Make more of the logic generic so that it can more easily work on more
component types in the future. Basically anything that handles attributes
can be generic.
2020-12-01 22:33:47 -05:00
bce42fbfe4 Attribute Access: Add a "has_attribute" method 2020-12-01 22:31:00 -05:00
59414e6a6f Point Separate Node: Revert earlier change to point cloud creation
I'm not quite sure creating the "radius" attribute in here is necessary
when any other attribute can be created later, but without this the
original radius attribute didn't pass to the new point cloud components
properly.

This should be investigated though, because the "radius" attribute
of pointclouds currently exists in some "semi-built-in" space that
doesn't really make sense.
2020-12-01 22:29:55 -05:00
4eef1d2edc Geometry Nodes: Point separate node
This node takes an input geometry and ouputs two geometries, moving
some points to the first and other points to the second depending on a
mask attribute input and a threshold.

The implementation tries to be "attribute component agnostic", meaning
it should be relatively easy to add "separate" functionality for more
component types in the future when they need to support it. (Then the
node could be renamed "Separate Geometry").

There is still an error carrying over the values for some attributes to
the output geometries.
2020-12-01 16:05:35 -05:00
f14c9444c8 UI: Add new node colors for geometry nodes
During the development of the new nodes in the `geometry-nodes` branch
the color of the new nodes wasn't considered, so all of the nodes ended
up red, the color for "input" nodes. This patch introduces two new
colors, one for "Geometry" and one for "Attributes". There are only two
attribute nodes currently, but the next sprint will add two more,
attribute mix, and sample from texture. The attribute nodes are
conceptually different enough from the nodes that modify the geometry
that they deserve their own color.

Differential Revision: https://developer.blender.org/D9682
2020-12-01 10:28:29 -05:00
399e5cc069 Geometry Nodes: support swapping inputs in function nodes
This is the same fix as in rB5ae666c2cc67be0e5ffb897c1ff48fe434d7dbc6.
2020-12-01 15:11:49 +01:00
5ae666c2cc Geometry Nodes: automatically reconnect when swapping inputs
This makes it easier to swap the inputs to the Join Geometry node.
The behavior is the same as in the Math node.
2020-12-01 15:04:45 +01:00
b9525e3279 Geometry Nodes: correct modifier name when creating from node editor
The name should be the same as when the modifier is created in the
modifier tab of the properties editor.
2020-12-01 11:32:46 +01:00
1bb2c7dda3 Cleanup: Store "is_active" instead of pointer property in panel type
This is consistent with the way other panel type fields are stored.
2020-11-30 17:43:14 -05:00
a0f41a4fd1 Merge branch 'master' into geometry-nodes 2020-11-30 17:36:14 -05:00
7aa47cd6ff Merge remote-tracking branch 'origin/master' into geometry-nodes 2020-11-30 20:25:59 +01:00
1ecc2b305d Cleanup: add a comment 2020-11-30 16:43:08 +01:00
f7d9ec6a40 Merge branch 'master' into geometry-nodes 2020-11-30 16:34:16 +01:00
7c4c6809b9 Cleanup: correct function name 2020-11-30 16:33:37 +01:00
69f4088ba1 Geometry Nodes: Change modifier name
The modifier was called "Empty", which reflects the fact that the modifier
doesn't do anything when you add it. However, that is not true after you
change the modifier's node group, and the fact that the modifier uses
nodes is the one thing that distinguishes it at this point. This commit
changes the name to "Geometry Nodes", which is simple and consistent
with the "Geometry Node Editor" and the naming of the project so far.
2020-11-30 10:23:57 -05:00
eb9402996e Merge branch 'master' into geometry-nodes 2020-11-30 10:27:15 +01:00
a7680e2bcf Merge branch 'master' into geometry-nodes 2020-11-27 19:44:56 +01:00
bc3b48400d Geometry Nodes: do not create geometry depsgraph relation for empty object
This resulted in a warning.
2020-11-27 19:44:06 +01:00
659ef4938b Geometry Nodes: support muted nodes
The handling of muted nodes is handled at the derived node tree
level now. This is also where expanding node groups is handled.
Muted nodes are relinked and removed from the derived tree
during construction. The geometry node evaluation code does
not have to know about muted nodes this way.
2020-11-27 19:38:14 +01:00
683041fd48 Theme: Update shader node color to match socket color
Related to T82689

Reviewed by Brecht
2020-11-27 19:25:44 +01:00
39ee0a5484 UI: Update node socket colors
Note: This also changes the Shader socket color, to match "Shading" in the Outliner.

Theme update for shader nodes will be committed separately.

Related to T82689
2020-11-27 19:07:50 +01:00
45e2c12124 Geometry Nodes: Fix building in Mac 2020-11-27 19:06:19 +01:00
c19b363256 Geometry Nodes: Support exposing string sockets to the modifier
Create a string IDProperty in the modifier initialized with the socket's
default value.
2020-11-27 12:21:08 -05:00
abe38ee033 Geometry Nodes: fix when vertex group exists but there are no MDeformVerts yet
The `mesh->dvert` array is only allocated when needed. Just creating a new vertex
group without any vertices in it, does not trigger the allocation.
2020-11-26 22:52:16 +01:00
d40126d636 Geometry Nodes: Use ID template node group selector in the modifier
This puts the same controls as in the node editor header
in the modifier panel.
2020-11-26 12:49:09 -05:00
1bb864e40a Geometry Nodes: use attribute span api in Join Geometry node
Copying over attributes from the original geometries to the new
geometry only takes ca. a third of the time compared to before.
2020-11-26 18:37:39 +01:00
0d97c0dfa6 Geometry Nodes: use attribute span api in random attribute node
This results in a ~30% speedup. The execution time is bounded
by the random number generator here.
2020-11-26 18:22:21 +01:00
76d78c9212 Cleanup: correct comment 2020-11-26 18:20:46 +01:00
d1eec74c56 Geometry Nodes: use attribute span api in attribute math node
For a simple add operation, this results in a 3-4x speedup.
2020-11-26 18:12:31 +01:00
ac257864a6 Geometry Nodes: support accessing attributes with spans
Before, attributes could only be accessed via setter and getter functions.
While this works well, it can be cumbersome and slow.
It would be better if most code could just operate on the underlying
attribute array directly. The issue is that some attributes are currently
not stored in plain arrays (e.g. vertex positions, vertex groups, ...).

This patch implements a solution where these "special" attributes are
converted into a temporary array for easy access and then copied
back into their correct form after all modifications are done.

Attribute accessors now have a `get_span` and `apply_span` method,
which can be used exactly for that purpose. In the case of attributes
that are plain arrays internally, only small constant overhead is added.
2020-11-26 18:11:03 +01:00
6d0e92cf0a Geometry Nodes: protect object from instancing itself directly
This is not a perfect check, because it does not check instances recursivly.
However, it helps protect us from the most common mistake.
2020-11-26 18:03:10 +01:00
881e148cc5 Geometry Nodes: maintain some more data in the Join node
Material indices and smooth states are not destroyed anymore.
If the two incoming meshes use different materials, the materials of
the first input will be used. This is obviously not ideal, because the
second input might change its material.

In the future we want to handle that differently and keep both materials,
but for now this is consistent with the boolean node.
2020-11-26 15:33:59 +01:00
4a647ee188 Geometry Nodes: update normals after transforming mesh
This is not done in `BKE_mesh_transform`.
2020-11-26 13:46:50 +01:00
622b7fff15 Geometry Nodes: fix computing bounding box of evaluated point cloud
Currently, the bounding box does not include instances. This is consistent
with other object types.
2020-11-26 12:32:08 +01:00
6c241b2dd7 Geometry Nodes: Node editor header interaction with active modifier
This commit makes the way the selector in the middle of the node editor
header interacts with the active modifier much more intuitive.

 - With no active modifier, or when the active modifier is a non-node
   modifier, the "new" operator adds a new nodes modifier.
 - With an active node modifier, the drop-down affects the modifier's
   selected node group.
 - With no active object, there is no drop-down in the header.
 - The node editor's node group always updates, even when there is no
   active modifier.
 - Pinning disables the drop-down and keeps the same node group
   selected, regardless of the context.

This is designed to work similarly to materials and material slots,
which should be familiar to any Blender user. One workflow not allowed
by this design is editing any geometry node group, regardless of the
context, but if that turns out to be an issue it should be solved in a
similar way for all node editors.
2020-11-25 15:34:29 -05:00
c1b655c06a Geometry Nodes: Improve wording of modifier error messages
- Don't use contractions
- Remove unecessary words
2020-11-25 13:32:36 -05:00
b4f3c3cca0 Geometry Nodes: Use context for active modifier operators
This adds "modifier" as a new context variable in the property editor.
It is used instead of getting the active modifier directly. This way it
displays in the breadcrumbs panel, and the variable can be set only
in the modifier tab, meaning it won't work from the shortcut even
when the modifiers aren't visible.
2020-11-25 11:46:02 -05:00
e3f8ffc482 Cleanup: avoid very generic using-namespace statements 2020-11-25 16:47:09 +01:00
559999b2f5 Cleanup: minor changes 2020-11-25 16:17:58 +01:00
257725f829 Geometry Nodes: hide domain enum from random attribute node
While we can support different domains already in this node, there is not
really anything you could do with that data yet. It can be added back when
there is a use case for it.
2020-11-25 15:57:41 +01:00
b356288a75 Geometry Nodes: change builtin attribute names based on T82693 2020-11-25 15:55:29 +01:00
d344d25b7b Geometry Nodes: simplify Attribute Math node by using a new abstraction 2020-11-25 15:40:33 +01:00
8742bbd607 Nodes: simplify Math code by using new abstraction layer 2020-11-25 15:39:42 +01:00
3576e669cb Nodes: initial abstraction to simplify math node implementations
Currently, implementing a node that supports math operations requires
you to write a long switch statement. The goal of this abstraction
is to reduce the number of these switch statements.

Note, this commit adds new such long switch cases. However, in the upcoming
commits existing math nodes are updated to use this abstraction, resulting in
less code overall.
2020-11-25 15:38:08 +01:00
044def82b9 Geometry Nodes: add utility method to create a dummy attribute reader
This can be used when instead of an actual attribute, a constant value
should be used.
2020-11-25 15:31:56 +01:00
92d12741a5 Merge branch 'master' into geometry-nodes 2020-11-25 12:27:44 +01:00
41a74159c3 Geometry Nodes: Fix missing node editor redraw for active modifier
When the active modifier changes, or when its node group changes, the
node editor should redraw, because these actions change its context.
2020-11-24 17:38:53 -05:00
8a2b329a21 Geometry Nodes: Always use the active modifier for shortcuts
Based on discussion with the team, summarized in T82691, it makes sense
to simplify the shortcut behavior and remove the way the shortcuts
currently activate on hover if there is no active modifier. This commit
also removes the behavior of clearing the active modifier when you
click on blank space in the modifier tab.
2020-11-24 16:57:45 -05:00
268508d2b0 Geometry Nodes: Make next modifier active when deleting
Previously it was the previous modifier, but this change keeps the index
of the object's active modifier consistent when deleting a modifier.
2020-11-24 13:52:20 -05:00
ce08a2bd48 Merge: fix after merge
This was part of rBe922dd7d8a307c54d49bc01649a12610b022192b.
2020-11-24 18:12:47 +01:00
7585f55a4c Merge branch 'master' into geometry-nodes 2020-11-24 18:05:31 +01:00
49f1c8ebec Geometry Nodes: remove attribute name inputs from Instancer node
The node now assumes that the data is found in the
"Position", "Rotation" and "Scale" attribute.
Those names might change soon.
2020-11-24 14:30:37 +01:00
9831362243 Geometry Nodes: rename Join to Join Geometry 2020-11-24 14:21:54 +01:00
710842cd1d Geometry Nodes: only output new data from Distribute and Instance nodes
This can be recombined with the original data using a
Join node if necessary.
2020-11-24 11:50:49 +01:00
433fcbec1a Cleanup: clang tidy 2020-11-24 11:42:57 +01:00
ef1ee262ad Fix Compilation Error
GCC showed this as a warning, MSVC as an error.
2020-11-24 08:45:32 +01:00
72386c64ef UI: Improvements to interaction with active modifier
This commit includes these improvements to operators and how they
relate to the active modifier:

 - Shortcuts performed while there is an active modifier will affect
   only that modifier.
 - Clicking anywhere on the empty space in a modifier's panel will make
   it active.
 - Clicking anywhere in the empty properties space will clear the
   active.

These changes require some refactoring of object modifier code. First
is splitting up the modifier property invoke callback, which now needs
to be able to get the active modifier separately from the hovered
modifier for the different operators. Second is a change to removing
modifiers, where there is now a separate function to remove a modifier
from an object's list, in order to handle changing the active. Finally
the panel handler neeeds a small tweak so that this "click in panel"
event can be handled afterwards.
2020-11-23 22:38:12 -05:00
e68e897077 Cleanup: Correct node name in definition function 2020-11-23 18:32:36 -05:00
52c6d36e4e Geometry Nodes: Initial implementation for attribute math node
This provide a simple implementation for basic math operations. Add,
subtract, multiple, and divide are implemented so far. Domain
interpolation is not implemented yet either.

This commit also adds two "Type" options to the node for choosing
explicitly whether to use an attribute or a float value as one of the
inputs. It is not possible to use two floats as inputs, because that
would be a regular math node.

Some cleanup to avoid some code duplication will come in a future
commit.
2020-11-23 17:01:53 -05:00
75a92d451e Geometry Nodes: new Join node
This node creates a new geometry based on two incoming geometries.
In the future the node ui can be extended to support more than two inputs.

The output geometry will have all the attributes of the inputs.
If both inputs have non-matching set of attributes, missing data is either
interpolated, type cast or zeroed.

Ref T82786.
2020-11-23 19:13:25 +01:00
d84bf961f8 Geometry Nodes: improve geometry component
* It now knows its own component type.
* Add virtual method to check if the component is empty.
* Add virtual methods to find all attribute names.
* Support adding existing components to a geometry set.
2020-11-23 19:05:27 +01:00
02d61faab0 Geometry Nodes: disable random attribute node when name is empty 2020-11-23 19:02:44 +01:00
7f4eb529c4 Geometry Nodes: duplicate referenced data layers in attribute api 2020-11-23 16:47:11 +01:00
18e768c78e Cleanup: improve naming convention for geometry node exec functions 2020-11-23 12:03:29 +01:00
26c7be27b7 Geometry Nodes: Add boilerplate code for attribute math node
This code doesn't actually do anything, but it provides a base for an
 implementation and exposes the the necessary interface to the UI.
2020-11-22 22:17:08 -05:00
e72b235fce Cleanup: Doxygen section formatting
Generally doxygen headers are title case and are styled like prose
rather than code.
2020-11-22 20:55:31 -05:00
8aea0e8ac2 Merge branch 'master' into geometry-nodes 2020-11-22 15:01:42 -05:00
2ce1b89d75 Merge branch 'master' into geometry-nodes 2020-11-20 16:01:32 -05:00
0649131be7 Geometry Nodes: Switch boolean node inputs
This changes the meaning of the order of the two geometry input sockets
to match the existing boolean modifier. The first socket is now the base
mesh and the second socket is the "cutter" geometry.
2020-11-20 15:20:03 -05:00
1bebd12eaf Cleanup: Use nullptr instead of NULL in C++ code 2020-11-20 15:10:51 -05:00
797c8f6d75 Geomtetry Nodes: Set node editor context from the active modifier
Similar to how the node editor context works for materials, this commit
makes the node group displayed in the node editor depend on the active
object and its active modifier. To keep the node group from changing,
just pin the node group in the header.

There are still missing updates when switching the modifier's node group.
2020-11-20 14:29:52 -05:00
1a67617631 Geometry Nodes: Expose the active modifier to the UI
This exposes the operator to set the active modifier as the type icon
in the header of the modifier panels. Tweaks to the widget drawing
code were necessary to use the red alert for non-emboss operator
buttons. Then, the panel for the active modifier gets a border around it
(which currently uses the property search theme color), requiring
an "active property" field in the PanelType struct.
2020-11-20 14:22:08 -05:00
c2359ff4aa Geometry Nodes: improve boolean node when not both inputs are connected
Previously, it was always outputting an empty geometry in that case.
This was confusing because e.g. the output of a union operation
with a single non-empty mesh is also non-empty.
2020-11-20 19:02:01 +01:00
763ebc3156 Geometry Nodes: use attribute name inputs in point instance node
This will probably not stay exactly like this, because it looks a bit ugly.
Adding this now, because it increases flexibility a lot and allows me
to test the attribute api a bit more.
2020-11-20 18:47:55 +01:00
f7d9bfafd9 Geometry Nodes: combine Vertex and Point domains
Originally, there were technical reasons for why two different domains
were used. Those reasons have been lost unfortunately, and there
don't seem to be any issues with combining the domains now.

This reduces confusion when users have to select the domain type
in enums.
2020-11-20 18:23:07 +01:00
088e6a5282 Geometry Nodes: initial support for implicitly type casting attributes
Those allows e.g. float attributes to be accessed as if they were vector attributes.
2020-11-20 18:10:24 +01:00
9798d68cc1 Geometry Nodes: simplify point instancer node 2020-11-20 17:45:12 +01:00
323335f076 Geometry Nodes: iterate on attributes api and improve random attribute node
Attributes can now be accessed through a GeometryComponent.
MeshComponent and PointCloudComponent implement the specific
attribute access mechanisms using virtual methods.

This simplifies code that should work on different geometry components
quite a bit, because it only has to be written once without using templates.
The Random Attribute node benefits from that a lot.
2020-11-20 17:35:45 +01:00
70d493e5ee Geometry Nodes: allow getting inputs without removing them
This is useful when one wants to get an input value multiple times.
2020-11-20 17:31:46 +01:00
87366baaed Functions: support lookup without extract in generic value map 2020-11-20 17:29:52 +01:00
8e1d7d9e8c BLI: add missing const 2020-11-20 17:29:21 +01:00
Léo Depoix
baa79dc805 Geometry Nodes: Add "Edge Angle" option to edge split node
Although disabling this option is equivalent to setting the edge angle
to 180 degrees, there is no great reason to change the settings from what
is exposed in the modifier.

Differential Revision: https://developer.blender.org/D9564
2020-11-20 09:45:45 -05:00
3736a7cadd Geometry Nodes: Add ability to clear object's active modifier
`object.modifiers.active = None` will just clear the active flag
from every modifier.
2020-11-20 09:32:46 -05:00
66ea03e908 Geometry Nodes: Add object.modifiers.active to RNA
This is a RNA only pointer property used to set and get the active
modifier without using an operator.
2020-11-20 09:25:01 -05:00
2781e51cda Fix T82762: linked but unavailable output handled incorrectly 2020-11-20 12:06:26 +01:00
1f2ce121a3 Fix T82773: node with unavailable output is handled incorrectly 2020-11-20 11:50:13 +01:00
9524019d58 Geometry Nodes: Rename category Scattering to Point and sort
The Geometry category should come before Input.
2020-11-20 00:05:13 +01:00
61e0f22945 Geometry Nodes: Hide unsupported attribute types and domains
The random attribute node currently doesn't support every attribute
domain or data type. With a bit of boilerplate code we can remove these
unsupported enum items from the UI for now, and also get a system to
remove unsupported items from the UI in the future. If all attribute
creation nodes end up always supporting all attibute types and domains,
this can be removed.
2020-11-19 17:13:56 -05:00
b7d7051dc3 Geometry Nodes: Add an operator to set the active modifer
Also make new modifiers active, and properly set the active
state when duplicating a modifier.
2020-11-19 14:47:43 -05:00
e0516d4d8e Geometry Nodes: Disallow editing and animating modifier active property
There will be an operator to access this property instead, which provides
a better name and tooltip to expose in the UI, and makes it more clear
that the property is dependent on the other modifiers.
2020-11-19 14:44:20 -05:00
097e1ca1a1 Geometry Nodes: Add the concept of an active modifier
This commit adds functions to set and get the object's active
modifier, which is stored as a flag in the ModifierData struct,
similar to constraints. This will be used to set the context in
the node editor. There are no visible changes in this commit.
2020-11-19 14:35:48 -05:00
dc628e7c38 Cleanup: use struct instead of class 2020-11-19 17:41:40 +01:00
bb960c85a5 Merge branch 'master' into geometry-nodes 2020-11-19 17:38:48 +01:00
eb25446b9d Geometry Nodes: Categories for the nodes
See T82367. There is some ongoing discussion about Attributes vs
Attribute. But it is settle to Attribute, so it matches Color, Vector
and Geometry.
2020-11-19 17:21:39 +01:00
0c7df205a5 Geometry Nodes: T82701 Name for initial Node Groups
Rename it from "Geometry Node Group" to "Geometry Nodes". This is
shorter and equality descriptive.
2020-11-19 16:59:51 +01:00
0f1fe96e0b Geometry Nodes - Internal rename + API change: NODES for anything but UI
Most of the times the nodes will be non-empty. Empty is really only what
shows in the UI.
2020-11-19 16:11:24 +01:00
417924d840 Geometry Nodes: transform geometry in Object Info node 2020-11-19 13:40:38 +01:00
a581367a2b Geometry Nodes: give nodes access to object that is being modified 2020-11-19 13:38:39 +01:00
00928f7826 Geometry Nodes: simplify attributes api and support deletion
The main difference is that the functions to access attributes have
been moved to MeshComponent and PointCloudComponent.
2020-11-19 13:17:11 +01:00
91971093bb Geometry Nodes: support controlling instance scale in point instancer node 2020-11-18 13:41:08 +01:00
96beb711e3 Geometry Nodes: support point cloud component in random attribute node 2020-11-18 13:40:28 +01:00
7e930f4e8b Geometry Nodes: support rotation and scale in instances component 2020-11-18 13:39:56 +01:00
aa780a4c17 Geometry Nodes: fix memory leak 2020-11-18 13:27:36 +01:00
5c3496f3cd Geometry Nodes: initial Random Attribute node
This adds some ui boilerplate code for the Random Attribute node and
provides an initial implementation.

Note, while the implementation can already randomize attributes, it might
not behave as expected under all circumstances yet. It's still work in progress.
2020-11-18 12:28:57 +01:00
425b15e23f Geometry Nodes: use attribute api in point instance node 2020-11-18 12:25:47 +01:00
5c2730f64d Geometry Nodes: use attribute api in point distribute node 2020-11-18 12:25:17 +01:00
866a56f76e Geometry Nodes: initial generic attribute access API
I will have to do a couple more iterations on this api in the upcoming weeks,
but for now it should be good enough.

The API adds an indirection for attribute access. That has the following benefits:
* Most code does not have to care about how an attribute is stored internally.
  This is mainly necessary, because we have to deal with "legacy" attributes
  such as vertex weights and attributes that are embedded into other structs
  such as vertex positions.
* When reading from an attribute, we generally don't care what domain the
  attribute is stored on. So we want to abstract away the interpolation that
  that adapts attributes from one domain to another domain (this is not
  actually implemented yet).

Accessing attributes through this indirection does have a performance penalty.
In later iterations of this API I want to reduce this penalty and extend the API
so that performance critical code does not have to go through the indirection
for every attribute access.

Other possible improvements for later iterations include:
* Actually implement interpolation between domains.
* Don't use inheritance for the different attribute types. A single class for read
  access and one for write access might be enough, because we know all the ways
  in which attributes are stored internally. We don't want more different internal
  structures in the future. On the contrary, ideally we can consolidate the different
  storage formats in the future to reduce the need for this indirection.
* Remove the need for heap allocations when creating attribute accessors.
2020-11-18 12:20:54 +01:00
63a286e4ce Functions: add float2 cpp type 2020-11-18 12:00:45 +01:00
15c6390960 Merge remote-tracking branch 'origin/master' into geometry-nodes 2020-11-18 02:03:02 +01:00
083cde0b43 Geometry Nodes: Unify icons -> use ICON_NODETREE for everything
Until there is a icon made specially for this, the nodetree icon is up
for grabs. Using it in the nodegroup + modifier + editor helps the users
to make a connection on where to edit those modifiers.
2020-11-18 02:02:32 +01:00
0783a9a194 Cleanup: Remove all of "#ifdef WITH_POINT_CLOUD"
Since Point Cloud was removed from experimental this is no longer needed.
2020-11-18 02:02:32 +01:00
b05f841c3a Cleanup: Remove most of "#ifdef WITH_GEOMETRY_NODES"
The ones around the simulation datablock are still there, since they are not
needed for the features planned for master yet.
2020-11-18 02:02:32 +01:00
4db4177587 Remove Point Cloud object from experimental
The point cloud object is the only one that will support instancing at
first. So we can expose it as a regular object.

It is limited since it has no edit mode. But this is not different than
the volume object.
2020-11-18 00:31:23 +01:00
c0f3d31998 Remove Geometry Nodes Editor from experimental
As part of preparing this work for master, with an initial subset of
working functionalities the Geometry Nodes Editor can be exposed for
everyone.

(it also helps people that are testing the branch)
2020-11-18 00:30:23 +01:00
b26cbb5d53 Merge branch 'master' into geometry-nodes 2020-11-16 12:03:01 -05:00
52e3608fe9 Geometry Nodes: simplify GeometrySet ownership handling
Previously, GeometrySets and GeometryComponents has reference
counters and could be shared. This commit changes it so that
only GeometryComponents are shared. A GeometrySet is a fairly
small type that is cheap to copy.

A lot of code simplifies when we can assume that GeometrySet
is cheap to copy.
2020-11-16 13:48:33 +01:00
6ba6e97407 Geometry Nodes: Move GeometrySet classes to global namespace
Brecht and I decided to move the GeometrySet classes
to the global namespace for now. This way we can use
the same type in C and C++ and don't have to use
reinterpret_cast as often.
2020-11-16 12:07:51 +01:00
4913b624d8 Merge branch 'master' into geometry-nodes 2020-11-16 11:49:14 +01:00
96ce1e9a95 Geometry Nodes: Improve node group output modifier error
More than output for the modifier's node group is fine, because the
node group may be used in other situations, but the modifier will
not work if there is no geometry output socket.
2020-11-14 20:09:27 -05:00
a3efa1d798 Merge branch 'master' into geometry-nodes 2020-11-14 15:17:46 -05:00
e50553c61a Empty Modifier: Fix build and put in the right order
Bypassing the macro that creates modifiers to allow the enum to be
referring to the Empty modifier, but the internal struct in the code to
be Nodes.

Also fix the name of the new created modifiers to be "Empty".

Fix was built with rBb458ea6b23381a9acb90dbbd73ced678e1d404c5.
2020-11-14 01:51:06 +01:00
b458ea6b23 Rename: "Nodes" modifier to "Empty" (take 2)
Leave the internal DNA data struct as "Nodes", and only rename the
modifier and user interface to Empty.

See 4a2734a835 for the original take and the reasoning
for renaming from Nodes to Empty.
2020-11-13 23:29:09 +01:00
056d7bb175 Revert "Rename: "Nodes" modifier to "Empty""
This reverts commit 4a2734a835.

Reverting this so that all we change is the UI name, not the DNA struct
and the internal variable names.
2020-11-13 23:19:40 +01:00
Léo Depoix
9769cf1ee6 Geometry Nodes : Removing "Combine Strings" and Group Instance ID from UI
This diff remove "Combine Strings" and "Group Instance ID" nodes from the UI (but keep them in the source code to be able to bring them back if needed).

This is part of "Cleanup 1st Sprint Nodes" (https://developer.blender.org/T82370).

Differential Revision: https://developer.blender.org/D9558
2020-11-13 22:23:37 +01:00
4a2734a835 Rename: "Nodes" modifier to "Empty"
This introduces a regression. Users need to re-create their modifiers
and set their values again. The NodeGroups are intact so all they need
is to create new "Empty" modifiers and set the node group.

---

Original problem: Eventually most modifiers will be node-based, so naming
this new modifier "Nodes" will get outdated pretty quickly.

Calling it "Empty" it's fairly descriptive, since the node tree simply connects
the modifier Input to an Output, without any effect.

There is a potential problem, that it could be associated with the
Empty object type. Like some sort of Hook.

This is the task T82700, and the design task T82537.
2020-11-13 22:16:28 +01:00
1ddd717803 Geometry Nodes: Improve error messages for property mismatches
Related to T82438. This adds some basic checks for common errors and
currently unsupported socket types in the modifier.
2020-11-13 12:35:10 -05:00
0066e59f2d Merge branch 'master' into geometry-nodes 2020-11-13 11:54:29 -05:00
ec7fffb033 Cleanup: Remove unused variable 2020-11-12 20:38:51 -05:00
956cf9a48d Cleanup: Clang Tidy 2020-11-12 16:06:12 -05:00
c27095b5cb Cleanup: Spelling
Also move some input extraction after the special case check.
2020-11-12 16:04:45 -05:00
Léo Depoix
8ef8cb7e34 Geometry Nodes: Add method enums to mesh triangulate node
This commit adds the remaining "method" enums from the triangulate modifier.

Differential Revision: https://developer.blender.org/D9502
2020-11-12 15:49:59 -05:00
0f6bee8e54 Merge branch 'master' into geometry-nodes 2020-11-12 15:19:09 -05:00
3093f89498 Geometry Nodes: Add null check for modifier property UI functions
An ID IDProperty exposed to the modifier  (object, material, etc) does not
have min, max, etc. values, so they should not be required.
2020-11-12 14:47:17 -05:00
f211030344 Cleanup: Fix typo 2020-11-12 12:19:44 -05:00
b277025d8e Geometry Nodes: Add modifier disabled check 2020-11-12 12:16:32 -05:00
94572a4e30 Geometry Nodes: use density attribute name instead of index as node input
This implements a workaround for the issue that (for historical reasons)
the names of vertex groups are stored on the object while the actual vertex
group data is stored on the mesh.

The solution is to copy the vertex group names from the object into
the `MeshComponent` so that the information is not lost, when the
object cannot be accessed.
2020-11-12 16:58:30 +01:00
bc2230df71 Geometry Nodes: cleanup geometry node interface
Previously, the execution function of a geometry node has three parameters.
Now it has only one. This makes it easier to pass more information to the
execution function, that might only be used by a few nodes, because we
don't have to add more parameters that are unused in most cases.
2020-11-12 16:31:32 +01:00
caa942b033 Geometry Nodes: actually create instances in Point Instance node 2020-11-12 13:28:33 +01:00
5dff952b67 Geometry Nodes: support instances in Transform node 2020-11-12 13:27:56 +01:00
5877e34eb4 Geometry Nodes: new DupliGenerator for instances component
With this, instances generated in a node tree can be rendered.
2020-11-12 13:27:20 +01:00
770bcfac9b Geometry Nodes: improve point distribute node
* Support vertex weights to control density.
* O(n) performance instead of O(n^2).
* More stable when density weights are changed.

The vertex group has to be specified using an index for now.
This is a technical limitation that will resolved a bit later.
2020-11-12 13:24:46 +01:00
b081108819 Geometry Nodes: support geometry components in depsgraph object iterator
Objects can evaluate to a geometry set instead of a single ID (only point cloud
objects for now). In the depsgraph object iterator, those geometry components
are expanded into temporary objects.

It's important to note that instanced objects can also contain geometry
components. Therefore, they have to be split up into multiple objects
as well in some cases.

At a high level the iterator works like so:
```
for object in depsgraph:
    for component in object:
        yield object_from_component(component)
    for dupli in make_duplis_list(object):
        for component in dupli:
            yield object_from_component(component)
```

DEG_iterator_objects_next has been cleaned up, to make this structure
a bit more apparent.
2020-11-12 13:20:23 +01:00
2be7b2aaf9 Geometry Nodes: better handle link cycles 2020-11-12 12:58:27 +01:00
912b38001f Geometry Nodes: use GeometrySet when evaluating pointcloud modifiers
This changes the signature of the modifyPointCloud function.
I'm doing that instead of making a new callback, because it requires
changes to significantly fewer files. Eventually it would be good
combine modifyMesh, modifyHair, modifyPointCloud and modifyVolume
into one modifyGeometrySet.

I temporarily disabled the displacement only modifiers for point clouds.
Support can be added back a bit later. I assume those have not been
used anywhere anyway.

The output of point cloud modifiers can not only be another point cloud,
but also a mesh and/or some instances. I added a new geometry_set_eval
field to Object_Runtime. For point cloud objects, the final geometry is
now referenced by that pointer instead of data_eval. The data_eval field
is still initialized after modifier evaluation to make some other code happy.

The evaluated geometry set is not yet passed to the renderer, so a point
cloud is currently rendered empty.
2020-11-12 12:57:52 +01:00
c4352f44bc Geometry Nodes: initial Object Info node
This node takes an object as input and outputs its location, rotation,
scale and geometry. Right now the loc/rot/scale are extracted from the
objects `obmat`. The geometry is just the mesh in the local space of the
source object.

We will likely need some more control over space transformations
using enums in the node, but those can be added a bit later.
2020-11-12 12:24:07 +01:00
0feca5f07d Geometry Nodes: initial object socket support
The fundamental difference between object sockets and the
other existing data sockets is that an object is an ID data block.
Changing the value of an object socket also changes the depsgraph.

The modifier has to analyse the node tree to figure out which other
objects it depends on. Currently, this is done very simply by just
looping over all sockets and collecting the objects. In the future
this can be improved by also figuring out what components of
an object are needed.

Instead of passing object pointers around in the node tree, we actually
use a handle. This handle is just a number internally that identifies
a specific object. The conversion between handles and object pointers
is done using a map that is provided by the modifier.

This approach has a couple of benefits. It protects us a bit from passing
around pointers that are not known to the modifier and therefore are
not in the depsgraph. Furthermore, the object pointer can change
while the handle stays the same. This is not important right now, but
is not unlikely to become useful in the future.

The API for how nodes access object pointers is not ideal yet and
will be improved in the future.
2020-11-12 12:20:59 +01:00
2984fb2b49 Geometry Nodes: crash when using Vector Math node 2020-11-12 11:51:12 +01:00
9e6553c0d4 Geometry Nodes: change color of object socket 2020-11-12 11:50:23 +01:00
107a0894cc Geometry Nodes: improve GeometrySet
This commits implements multiple changes:
* Adds a simple C API.
* Improves the ownership handling by introducing GeometryOwnershipType.
* Adds an InstancesComponent that stores positions and Object pointers.
2020-11-12 11:47:48 +01:00
8ecc1bea4c Nodes: add utility to check for link cycles in derived node trees 2020-11-12 11:35:46 +01:00
91ad33ef8f Merge branch 'master' into geometry-nodes 2020-11-12 11:25:25 +01:00
fa5190e742 fix after merge 2020-11-09 15:55:24 +01:00
74ed591f62 Merge branch 'master' into geometry-nodes 2020-11-09 15:48:18 +01:00
3d5efb4335 Geometry Nodes: rename Geometry type to GeometrySet
This should not change any functionality.

After talking to Brecht, we agreed that it might be good
not to have a class called Geometry for now. In the future
we might want to use a Geometry class as base class for
meshes, curves, etc.

This commit renames the Geometry class to GeometrySet,
because it is essentially a container that can contain
multiple geometries of different types.
2020-11-09 13:08:17 +01:00
Léo Depoix
140b7cfe0d Geometry Nodes: cleanup Subdivision Surface node inputs
Ref T82370.

Differential Revision: https://developer.blender.org/D9487
2020-11-09 12:49:33 +01:00
af7cc3f8bb Fix merge issues 2020-11-09 12:46:04 +01:00
d2c4af9865 Merge branch 'master' into geometry-nodes 2020-11-09 12:44:45 +01:00
e5c637f5fe Merge remote-tracking branch 'origin/master' into geometry-nodes 2020-11-06 18:22:36 +01:00
11d12d543d Fix build error on windows: Don't use designated initializers in C++ 2020-11-02 08:20:54 -06:00
2c6114b238 Merge branch 'master' into geometry-nodes 2020-11-02 08:15:15 -06:00
152bd43ae1 Merge branch 'master' into geometry-nodes 2020-11-02 11:44:46 +01:00
45012c3309 Geometry Nodes: Fix property values reset when input socket is added
The names of the IDProperties are the socket identifiers, not their names.
2020-10-31 23:24:06 -05:00
5177c35498 Merge branch 'master' into geometry-nodes 2020-10-31 22:58:39 -05:00
49c8042f29 Merge branch 'master' into geometry-nodes 2020-10-31 14:21:14 +01:00
Léo Depoix
f8c52590c0 Geometry Nodes: new Subdivision Surface node
This node is similar to the subdivision surface modifier. It subdivides
the mesh component of a geometry. The options have the same meaning
as in the modifier.

Differential Revision: https://developer.blender.org/D9364
2020-10-31 10:51:09 +01:00
0b897e0308 Merge branch 'master' into geometry-nodes 2020-10-31 10:43:52 +01:00
c34438dd78 Geometry Nodes: Rename node category based on functionality
Naming based on supported geometry components only works in some cases.
For nodes that work with multiple data types, it's better to categorize
them based on their functionality.
2020-10-31 00:37:04 -05:00
e0a4dc9396 Merge branch 'master' into geometry-nodes 2020-10-31 00:30:10 -05:00
51fa44522f Geometry Nodes: Add errors for out of sync sockets and properties
Theoretically the modifier's properties could be changed or removed by
Python, so it may be useful to have errors printed and added to the
modifier in that case.

I kept the check as a separate step from the `compute_geometry`
pass because the object is needed to set the modifier error message.
But it could easily be moved there in the future.
2020-10-30 11:42:11 -05:00
343e13f464 Geometry Nodes: change geometry socket color
Ref T81848.
2020-10-30 17:29:36 +01:00
1103809fab Merge branch 'master' into geometry-nodes 2020-10-30 16:40:41 +01:00
5b89d49b0d Geometry Nodes: Allow node group inputs with the same name
If we add the "name" label manually with uiItemR, we can use the socket
identifier instead of the name for the IDProperty name. This will also
allow us more flexibility in how to draw the settings in the future, and
removes the empty _RNA_UI proprety that was drawn before.
2020-10-30 09:57:54 -05:00
e805bfc768 Cleanup: Return early in edge split node 2020-10-29 15:53:32 -05:00
67cb4fdbdc Cleanup: Don't use unsupported struct initialization
Although this worked for me, it appears this isn't supported until C++20.
2020-10-29 15:48:38 -05:00
8ed74c9daf Geometry Nodes: Use UI settings for properties in modifier
The system for exposing property settings like min, max, default, subtype,
etc. for ID properties is quite convoluted currently, so I won't give a
full description here, but this commit creates the tree of ID properties
needed to store that information. This means that property subtypes like
"angle" or "XYZ" will affect the display in the modifier.

Limitations:
 - The _RNA_UI property is displayed in the modifier. This may require a
   modification to uiDefAutoButsRNA to fix.
 - IDProperties must have unique names, but node sockets don't have
   that limitation. This can be solved by adding a "UI name" field to
   IDProperties.
2020-10-29 14:11:32 -05:00
d7cb25e028 Fixup for cmake header cleanup
Issue introduced on f73a420e5a.
2020-10-29 18:27:31 +01:00
e3395093ff Geometry Nodes: Create the node group when adding a new Nodes modifier 2020-10-29 17:36:16 +01:00
f73a420e5a Cleanup: Nodes Modifier header to its proper location 2020-10-29 17:36:16 +01:00
b8b240b329 Geometry Nodes: do not reference custom data layers when copying mesh
We can't use that for now, because the original mesh might be freed
before the new copied mesh. When the original mesh is freed, the shared
layers will be freed as well.

This can probably be improved in the future, so that we can actually
share attribute arrays between meshes. An approach similar to how
geometries and components are shared should work as well.
2020-10-29 15:47:19 +01:00
ae2827bb52 Geometry Nodes: add comment mentioning that custom data might be shared 2020-10-29 15:42:01 +01:00
bb97284f8a Geometry Nodes: refactor Geometry type
A geometry now contains zero or more geometry components.
A geometry component is a subclass off GeometryComponent.
Currently, there is a MeshComponent and PointCloudComponent.

A geometry contains at most one component of each type.
Individual components can be shared between multiple geometries
to avoid unnecessary copies. For that, each component has a user
count that determines when the component will be freed and whether
it is mutable.

Code working with geometries can either work with the components
directly, or use the utility functions on the geometry that cover the
most common operations.

In the future, additional component types can be added. For example,
we'll probably need components for curves and volumes.
Furthermore, something like an InstancesComponent can be added,
which contains points with attributes and references a geometry/object/collection
that is instanced on all the points.
2020-10-29 15:38:15 +01:00
209e82da45 Merge branch 'master' into geometry-nodes 2020-10-29 15:22:59 +01:00
e63d43e6b9 Merge branch 'master' into geometry-nodes 2020-10-29 11:31:55 +01:00
802ba35654 Geometry Nodes: make default group output node active
Otherwise some updates were missing when sockets are changed.
2020-10-28 20:27:57 +01:00
79c9c11b35 Merge branch 'master' into geometry-nodes 2020-10-28 20:21:52 +01:00
e1d0ab2dbc Geometry Nodes: fix missing update when inserting a node between two nodes 2020-10-28 14:53:06 +01:00
687f994251 Geometry Nodes: improve api for nodes
The execute callback of a geometry node gets more domain specific
types as parameters now: GeoNodeInputs and GeoNodeOutputs.

Those types are also aware of what node is being executed and can
provide better error messages when they are used incorrectly.
2020-10-28 14:05:07 +01:00
5c7767e0e0 Merge branch 'master' into geometry-nodes 2020-10-28 14:01:05 +01:00
af9ee8e2bc Merge branch 'master' into geometry-nodes 2020-10-28 10:40:35 +01:00
562f2e604a Merge branch 'master' into geometry-nodes 2020-10-27 21:21:03 -05:00
84e81b8cc3 Merge branch 'master' into geometry-nodes 2020-10-27 14:01:48 -05:00
5ae9527770 Geometry Nodes: Support pointcloud in transform node
This is likely not the final implementation of the transform node, but
it's  a good trivial case for supporting multiple geometry data types.
2020-10-27 12:59:58 -05:00
082c17a2d2 Fix group input is resetting in modifier 2020-10-27 17:01:03 +01:00
09677d737c Fix missing null check in recent commit 2020-10-27 15:53:17 +01:00
bec7248178 Cleanup: Use proper C++ types 2020-10-27 09:43:38 -05:00
0103cb2051 Geometry Nodes: initial support for bool group inputs
Still need to work on the uilayout inside the modifier.
2020-10-27 14:59:26 +01:00
9f38ebefcb Geometry Nodes: support vector inputs to geometry group 2020-10-27 14:54:41 +01:00
8f934852f0 Geometry Nodes: initial support for displaying group inputs in modifier
This uses the previously added id properties on the nodes modifier
to store values that are passed into the geometry node group.
2020-10-27 13:44:46 +01:00
cb16db7803 Geometry Nodes: enable nodes modifier in edit mode 2020-10-27 12:09:13 +01:00
f8965f12a1 Geometry Nodes: Fix memory leak 2020-10-26 23:15:05 -05:00
7f2a20f89b Merge branch 'master' into geometry-nodes 2020-10-26 23:12:45 -05:00
5566818603 Geometry Nodes: Add initial scattering nodes
The first is a "Point Distribute" node, which takes a mesh and outputs a
pointcloud, scattering points randomly on the surface based on the input
density. The distribution algorithm is extremely basic at this point, and
doesn't take into account an attribute weight at each vertex.

The second node is a "Point Instance" node, which is mainly a placeholder
until the engineering design for how to work with instancing in geometry
nodes is decided. For now it just runs the same code that the convert
pointcloud to mesh operator uses.
2020-10-26 23:00:31 -05:00
9a06c6a040 Geometry Nodes: Add function to create a temporary pointcloud
We needed a "nomain" funciton similar to the one we have for meshes in
order to add a working pointcloud for the geometry nodes.
2020-10-26 22:54:55 -05:00
e097116072 Geometry Nodes: Add utility to position point randomly on 3D triangle 2020-10-26 22:44:35 -05:00
b844caca6d Geometry Nodes: Add pointcloud support to geometry class
This adds another set of the same mesh functions but for pointclouds.
There are probably better ways to generalize this functionality, but that
may have to be rethought in the future anyway if we want to store
multiple of each type. And anyway it's handy to have a specific set of
"pointcloud" functions available in the node implementations.
2020-10-26 22:41:57 -05:00
046ac5fccd Geometry Nodes: Initial mesh boolean node
This uses the code from the rewritten boolean modifier from 2.91 as a node.
The implementation is about as minimal as it can get, since for now the use
case of this node is mostly to test multiple geometry outputs and inputs.

The boolean code requires a BMesh, so the node converts the input meshes
to BMesh, so the bmesh is added as a dependency to the nodes module.
2020-10-26 14:27:19 -05:00
ef4fbba596 Cleanup: remove unused modifier property 2020-10-26 18:27:44 +01:00
aa8360d0fa Geometry Nodes: initial test trying to use id properties to initialize group inputs
The settings can only be set via Python currently. The matching between properties
and group inputs is based on the socket identifier (which is e.g. `Input_5`).
Maybe we'll have to use a different matching strategy in the future, will see.
2020-10-26 18:23:51 +01:00
76c356c12e Geometry Nodes: store id properties in nodes modifier
The properties are not used yet, but can already be accessed with Python
using `modifier.settings['setting name']`.

The plan is to use id properties to store the parameters that the modifier
passes into the geometry node group.
2020-10-26 17:53:51 +01:00
e04491073d Geometry Nodes: support evaluation with more than one group input
Group inputs are not yet exposed in the modifier. For now I just added
a simple float setting that will be passed to every float input of the group.
Inputs of other types have some default value.
2020-10-26 14:16:26 +01:00
a5dda5996e Geometry Nodes: connect group input and output by default 2020-10-26 13:29:03 +01:00
c48e4b7a44 Geometry Nodes: improve node tree evaluation
This change reduces the number of unnecessary copies of data
and avoids computing the same value more than once.
2020-10-26 13:27:02 +01:00
4ae2d6206a Geometry Nodes: initial Transform node
Most of this code has been written by @HooglyBoogly.
I just changed the exec funtion so that it does not have to make
a copy of the mesh.
2020-10-26 12:27:51 +01:00
47f5a635da Geometry Nodes: add utility method to check if a geometry has a mesh 2020-10-26 12:25:46 +01:00
eb8574bc8b Merge branch 'master' into geometry-nodes 2020-10-26 12:10:12 +01:00
bc4e31afb6 Merge branch 'master' into geometry-nodes 2020-10-24 14:38:00 +02:00
9d7672be71 Merge branch 'master' into geometry-nodes 2020-10-23 15:18:20 +02:00
994e7178bb Geometry Nodes: make some function nodes available
We might not want to have all those nodes in a final version.
Some of them have been added with particle nodes in mind.
However, to test the evaluation system it is useful to have a
couple of nodes available.

Those nodes should "just" work, because their implementation
is reused from the particle nodes project.
2020-10-23 15:13:19 +02:00
1719743066 Geometry Nodes: improve node group evaluation
This adds support for nodes that have a multi-function implementation.
That includes various function nodes like Math, Combine Vector, ...

Furthermore, there is support for implicit conversions now. So it should
work when one connects e.g. a float to an integer and vice versa.
2020-10-23 15:09:55 +02:00
8910033f57 Nodes: add utility methods 2020-10-23 15:05:01 +02:00
2a4c6c612a Functions: add utility method 2020-10-23 15:01:07 +02:00
b062b922f9 Geometry Nodes: Resolve some missing 3D viewport updates
These two functions "snode_notify" and "ED_node_tag_update_id" appear to
be mostly duplicates. However, there is already a case for each type of
built-in node tree, so it makes sense to add one for the geometry node
tree as well. This doesn't solve the update issues for changing number
in buttons, that must be handled somewhere else.
2020-10-22 22:59:40 -05:00
895f4620a0 Merge branch 'master' into geometry-nodes 2020-10-22 22:03:28 -05:00
fafed6234b Geometry Nodes: Add edge split node functionality 2020-10-22 13:48:56 -05:00
7ff8094a8b Geometry Nodes: expose minimum vertices input of Triangulate node 2020-10-22 18:24:05 +02:00
5aabf67a9c Fix error in previous commit
That should not have happened -.-
2020-10-22 18:23:39 +02:00
ab8c7fe946 Fix previous comment 2020-10-22 18:20:17 +02:00
a05012d500 Geometry Nodes: simplify and deduplicate callbacks on sockets
This adds a layer of abstraction between the code calling callbacks
on sockets and the implementation of those callbacks.
This abstraction layer allows some sockets to not implement all
callbacks when those can be derived from some other callback.
2020-10-22 18:08:27 +02:00
97a93566e9 Geometry Nodes: change "Node Tree" to "Node Group" 2020-10-22 15:52:15 +02:00
da4d697772 Geometry Nodes: initial support for evaluating geometry node groups
This is still very basic and does quite a few unnecessary computations.
Also the error handling is quite weak currently, so when invalid things are
connected, it will probably just crash.

Also the interface that individual nodes have to implement will have to change,
but the current solution is a good starting point.

Only the triangulate node is implemented for now.
2020-10-22 15:05:41 +02:00
87218899be Geometry Nodes: add an initial geometry class 2020-10-22 15:02:27 +02:00
ffa0a6df9d Functions: add generic pointer class
This class represents a pointer whose type is only known at runtime.
2020-10-22 15:01:31 +02:00
706fa5ad76 Functions: add move operations to CPPType 2020-10-22 15:00:07 +02:00
b7f6de490d Geometry Nodes: Add initial node definition for edge split
This is just based on rBa7dba81aab22, and contains no funcionality at all.
2020-10-21 16:11:09 -05:00
7e485b4620 Merge branch 'master' into geometry-nodes 2020-10-21 08:54:39 -05:00
a7dba81aab Nodes: add initial UI for Triangulate node 2020-10-21 14:14:09 +02:00
4606e83a75 Merge branch 'master' into geometry-nodes 2020-10-21 14:00:32 +02:00
1d28de57a4 Nodes: improve dependency between modifier and node group 2020-10-21 13:16:19 +02:00
3cfcfb938d Nodes: support creating geometry node groups 2020-10-21 12:32:02 +02:00
bcdc6910a0 Nodes: show header in geometry node editor 2020-10-21 12:16:57 +02:00
7793e8c884 Modifiers: add node_tree to NodesModifierData 2020-10-21 12:13:13 +02:00
05d9bd7c4a Modifiers: rename Simulation to Nodes modifier 2020-10-21 12:03:06 +02:00
9255ce9247 Nodes: rename Simulation to Geometry node tree 2020-10-21 11:39:42 +02:00
a0ce0154e7 Merge branch 'master' into geometry-nodes 2020-10-21 11:11:16 +02:00
0cd7f7ddd1 Nodes: add geometry socket type
We still have to pick a color for this socket.

Ref T81848.
2020-10-20 15:31:59 +02:00
25 changed files with 898 additions and 25 deletions

View File

@@ -483,6 +483,7 @@ geometry_node_categories = [
GeometryNodeCategory("GEO_ATTRIBUTE", "Attribute", items=[
NodeItem("GeometryNodeRandomAttribute"),
NodeItem("GeometryNodeAttributeMath"),
NodeItem("GeometryNodeAttributeCompare"),
NodeItem("GeometryNodeAttributeFill"),
]),
GeometryNodeCategory("GEO_COLOR", "Color", items=[
@@ -508,6 +509,7 @@ geometry_node_categories = [
GeometryNodeCategory("GEO_POINT", "Point", items=[
NodeItem("GeometryNodePointDistribute"),
NodeItem("GeometryNodePointInstance"),
NodeItem("GeometryNodePointSeparate"),
]),
GeometryNodeCategory("GEO_UTILITIES", "Utilities", items=[
NodeItem("ShaderNodeMapRange"),

View File

@@ -266,9 +266,11 @@ template<typename T> class TypedWriteAttribute {
}
};
using BooleanReadAttribute = TypedReadAttribute<bool>;
using FloatReadAttribute = TypedReadAttribute<float>;
using Float3ReadAttribute = TypedReadAttribute<float3>;
using Color4fReadAttribute = TypedReadAttribute<Color4f>;
using BooleanWriteAttribute = TypedWriteAttribute<bool>;
using FloatWriteAttribute = TypedWriteAttribute<float>;
using Float3WriteAttribute = TypedWriteAttribute<float3>;
using Color4fWriteAttribute = TypedWriteAttribute<Color4f>;

View File

@@ -88,6 +88,8 @@ class GeometryComponent {
GeometryComponentType type() const;
bool attribute_exists(const blender::StringRef attribute_name) const;
/* Returns true when the geometry component supports this attribute domain. */
virtual bool attribute_domain_supported(const AttributeDomain domain) const;
/* Returns true when the given data type is supported in the given domain. */

View File

@@ -1351,6 +1351,8 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
#define GEO_NODE_ATTRIBUTE_MATH 1009
#define GEO_NODE_JOIN_GEOMETRY 1010
#define GEO_NODE_ATTRIBUTE_FILL 1011
#define GEO_NODE_POINT_SEPARATE 1012
#define GEO_NODE_ATTRIBUTE_COMPARE 1013
/** \} */

View File

@@ -392,6 +392,8 @@ const blender::fn::CPPType *custom_data_type_to_cpp_type(const CustomDataType ty
return &CPPType::get<int>();
case CD_PROP_COLOR:
return &CPPType::get<Color4f>();
case CD_PROP_BOOL:
return &CPPType::get<bool>();
default:
return nullptr;
}
@@ -415,6 +417,9 @@ CustomDataType cpp_type_to_custom_data_type(const blender::fn::CPPType &type)
if (type.is<Color4f>()) {
return CD_PROP_COLOR;
}
if (type.is<bool>()) {
return CD_PROP_BOOL;
}
return static_cast<CustomDataType>(-1);
}
@@ -449,6 +454,9 @@ static ReadAttributePtr read_attribute_from_custom_data(const CustomData &custom
case CD_PROP_COLOR:
return std::make_unique<ArrayReadAttribute<Color4f>>(
domain, Span(static_cast<Color4f *>(layer.data), size));
case CD_PROP_BOOL:
return std::make_unique<ArrayReadAttribute<bool>>(
domain, Span(static_cast<bool *>(layer.data), size));
}
}
}
@@ -490,6 +498,9 @@ static WriteAttributePtr write_attribute_from_custom_data(
case CD_PROP_COLOR:
return std::make_unique<ArrayWriteAttribute<Color4f>>(
domain, MutableSpan(static_cast<Color4f *>(layer.data), size));
case CD_PROP_BOOL:
return std::make_unique<ArrayWriteAttribute<bool>>(
domain, MutableSpan(static_cast<bool *>(layer.data), size));
}
}
}
@@ -590,6 +601,15 @@ Set<std::string> GeometryComponent::attribute_names() const
return {};
}
bool GeometryComponent::attribute_exists(const blender::StringRef attribute_name) const
{
ReadAttributePtr attribute = this->attribute_try_get_for_read(attribute_name);
if (attribute) {
return true;
}
return false;
}
static ReadAttributePtr try_adapt_data_type(ReadAttributePtr attribute,
const blender::fn::CPPType &to_type)
{
@@ -742,6 +762,7 @@ bool PointCloudComponent::attribute_domain_with_type_supported(
const AttributeDomain domain, const CustomDataType data_type) const
{
return domain == ATTR_DOMAIN_POINT && ELEM(data_type,
CD_PROP_BOOL,
CD_PROP_FLOAT,
CD_PROP_FLOAT2,
CD_PROP_FLOAT3,
@@ -865,8 +886,13 @@ bool MeshComponent::attribute_domain_with_type_supported(const AttributeDomain d
if (!this->attribute_domain_supported(domain)) {
return false;
}
return ELEM(
data_type, CD_PROP_FLOAT, CD_PROP_FLOAT2, CD_PROP_FLOAT3, CD_PROP_INT32, CD_PROP_COLOR);
return ELEM(data_type,
CD_PROP_BOOL,
CD_PROP_FLOAT,
CD_PROP_FLOAT2,
CD_PROP_FLOAT3,
CD_PROP_INT32,
CD_PROP_COLOR);
}
int MeshComponent::attribute_domain_size(const AttributeDomain domain) const

View File

@@ -1837,6 +1837,21 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
layerMultiply_propfloat2,
NULL,
layerAdd_propfloat2},
/* 50: CD_PROP_POOL */
{sizeof(bool),
"bool",
1,
N_("Boolean"),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL},
};
static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
@@ -1892,6 +1907,7 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
"CDPropCol",
"CDPropFloat3",
"CDPropFloat2",
"CDPropBoolean",
};
const CustomData_MeshMasks CD_MASK_BAREMESH = {

View File

@@ -4694,6 +4694,8 @@ static void registerGeometryNodes(void)
register_node_type_geo_random_attribute();
register_node_type_geo_attribute_math();
register_node_type_geo_join_geometry();
register_node_type_geo_point_separate();
register_node_type_geo_attribute_compare();
}
static void registerFunctionNodes(void)

View File

@@ -3149,6 +3149,15 @@ static void node_geometry_buts_boolean_math(uiLayout *layout, bContext *UNUSED(C
uiItemR(layout, ptr, "operation", DEFAULT_FLAGS, "", ICON_NONE);
}
static void node_geometry_buts_attribute_compare(uiLayout *layout,
bContext *UNUSED(C),
PointerRNA *ptr)
{
uiItemR(layout, ptr, "operation", DEFAULT_FLAGS, "", ICON_NONE);
uiItemR(layout, ptr, "input_type_a", DEFAULT_FLAGS, IFACE_("Type A"), ICON_NONE);
uiItemR(layout, ptr, "input_type_b", DEFAULT_FLAGS, IFACE_("Type B"), ICON_NONE);
}
static void node_geometry_buts_subdivision_surface(uiLayout *layout,
bContext *UNUSED(C),
PointerRNA *UNUSED(ptr))
@@ -3208,6 +3217,9 @@ static void node_geometry_set_butfunc(bNodeType *ntype)
case GEO_NODE_ATTRIBUTE_MATH:
ntype->draw_buttons = node_geometry_buts_attribute_math;
break;
case GEO_NODE_ATTRIBUTE_COMPARE:
ntype->draw_buttons = node_geometry_buts_attribute_compare;
break;
case GEO_NODE_ATTRIBUTE_FILL:
ntype->draw_buttons = node_geometry_buts_attribute_fill;
break;

View File

@@ -75,8 +75,7 @@ typedef struct CustomData {
* MUST be >= CD_NUMTYPES, but we cant use a define here.
* Correct size is ensured in CustomData_update_typemap assert().
*/
int typemap[50];
char _pad[4];
int typemap[51];
/** Number of layers, size of layers array. */
int totlayer, maxlayer;
/** In editmode, total size of all data layers. */
@@ -156,7 +155,9 @@ typedef enum CustomDataType {
CD_PROP_FLOAT3 = 48,
CD_PROP_FLOAT2 = 49,
CD_NUMTYPES = 50,
CD_PROP_BOOL = 50,
CD_NUMTYPES = 51,
} CustomDataType;
/* Bits for CustomDataMask */
@@ -208,6 +209,7 @@ typedef enum CustomDataType {
#define CD_MASK_PROP_COLOR (1ULL << CD_PROP_COLOR)
#define CD_MASK_PROP_FLOAT3 (1ULL << CD_PROP_FLOAT3)
#define CD_MASK_PROP_FLOAT2 (1ULL << CD_PROP_FLOAT2)
#define CD_MASK_PROP_BOOL (1ULL << CD_PROP_BOOL)
/** Multires loop data. */
#define CD_MASK_MULTIRES_GRIDS (CD_MASK_MDISPS | CD_GRID_PAINT_MASK)

View File

@@ -1059,6 +1059,17 @@ typedef struct NodeDenoise {
char _pad[7];
} NodeDenoise;
typedef struct NodeAttributeCompare {
/* e.g. NODE_FLOAT_COMPARE_LESS_THAN. */
uint8_t operation;
/* GeometryNodeAttributeInputMode */
uint8_t input_type_a;
uint8_t input_type_b;
char _pad[5];
} NodeAttributeCompare;
/* script node mode */
#define NODE_SCRIPT_INTERNAL 0
#define NODE_SCRIPT_EXTERNAL 1
@@ -1336,14 +1347,14 @@ enum {
};
/* Float compare node operations. */
enum {
typedef enum FloatCompareOperation {
NODE_FLOAT_COMPARE_LESS_THAN = 0,
NODE_FLOAT_COMPARE_LESS_EQUAL = 1,
NODE_FLOAT_COMPARE_GREATER_THAN = 2,
NODE_FLOAT_COMPARE_GREATER_EQUAL = 3,
NODE_FLOAT_COMPARE_EQUAL = 4,
NODE_FLOAT_COMPARE_NOT_EQUAL = 5,
};
} FloatCompareOperation;
/* Clamp node types. */
enum {
@@ -1469,6 +1480,7 @@ typedef enum GeometryNodeAttributeInputMode {
GEO_NODE_ATTRIBUTE_INPUT_FLOAT = 1,
GEO_NODE_ATTRIBUTE_INPUT_VECTOR = 2,
GEO_NODE_ATTRIBUTE_INPUT_COLOR = 3,
GEO_NODE_ATTRIBUTE_INPUT_BOOLEAN = 4,
} GeometryNodeAttributeInputMode;
#ifdef __cplusplus

View File

@@ -44,6 +44,7 @@ const EnumPropertyItem rna_enum_attribute_type_items[] = {
{CD_PROP_COLOR, "FLOAT_COLOR", 0, "Float Color", "RGBA color with floating-point precisions"},
{CD_MLOOPCOL, "BYTE_COLOR", 0, "Byte Color", "RGBA color with 8-bit precision"},
{CD_PROP_STRING, "STRING", 0, "String", "Text string"},
{CD_PROP_BOOL, "BOOLEAN", 0, "Boolean", "True or false"},
{0, NULL, 0, NULL, NULL},
};

View File

@@ -272,32 +272,32 @@ const EnumPropertyItem rna_enum_node_float_compare_items[] = {
{NODE_FLOAT_COMPARE_LESS_THAN,
"LESS_THAN",
0,
"A < B",
"Less Than",
"True when the first input is smaller than second input"},
{NODE_FLOAT_COMPARE_LESS_EQUAL,
"LESS_EQUAL",
0,
"A <= B",
"Less Than or Equal",
"True when the first input is smaller than the second input or equal"},
{NODE_FLOAT_COMPARE_GREATER_THAN,
"GREATER_THAN",
0,
"A > B",
"Greater Than",
"True when the first input is greater than the second input"},
{NODE_FLOAT_COMPARE_GREATER_EQUAL,
"GREATER_EQUAL",
0,
"A >= B",
"Greater Than or Equal",
"True when the first input is greater than the second input or equal"},
{NODE_FLOAT_COMPARE_EQUAL,
"EQUAL",
0,
"A = B",
"Equal",
"True when both inputs are approximately equal"},
{NODE_FLOAT_COMPARE_NOT_EQUAL,
"NOT_EQUAL",
0,
"A != B",
"Not Equal",
"True when both inputs are not approximately equal"},
{0, NULL, 0, NULL, NULL},
};
@@ -435,6 +435,14 @@ static const EnumPropertyItem rna_node_geometry_attribute_input_b_items[] = {
{0, NULL, 0, NULL, NULL},
};
static const EnumPropertyItem rna_node_geometry_attribute_input_type_items[] = {
{GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE, "ATTRIBUTE", 0, "Attribute", ""},
{GEO_NODE_ATTRIBUTE_INPUT_FLOAT, "FLOAT", 0, "Float", ""},
{GEO_NODE_ATTRIBUTE_INPUT_VECTOR, "VECTOR", 0, "Vector", ""},
{GEO_NODE_ATTRIBUTE_INPUT_COLOR, "COLOR", 0, "Color", ""},
{GEO_NODE_ATTRIBUTE_INPUT_BOOLEAN, "BOOLEAN", 0, "Boolean", ""},
{0, NULL, 0, NULL, NULL},
};
#endif
#ifdef RNA_RUNTIME
@@ -1859,7 +1867,7 @@ static const EnumPropertyItem *itemf_function_check(
static bool attribute_random_type_supported(const EnumPropertyItem *item)
{
return ELEM(item->value, CD_PROP_FLOAT, CD_PROP_FLOAT3);
return ELEM(item->value, CD_PROP_FLOAT, CD_PROP_FLOAT3, CD_PROP_BOOL);
}
static const EnumPropertyItem *rna_GeometryNodeAttributeRandom_type_itemf(
bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
@@ -8399,6 +8407,29 @@ static void def_geo_attribute_math(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
}
static void def_geo_attribute_attribute_compare(StructRNA *srna)
{
PropertyRNA *prop;
RNA_def_struct_sdna_from(srna, "NodeAttributeCompare", "storage");
prop = RNA_def_property(srna, "operation", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, rna_enum_node_float_compare_items);
RNA_def_property_enum_default(prop, NODE_MATH_ADD);
RNA_def_property_ui_text(prop, "Operation", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
prop = RNA_def_property(srna, "input_type_a", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, rna_node_geometry_attribute_input_type_items);
RNA_def_property_ui_text(prop, "Input Type A", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
prop = RNA_def_property(srna, "input_type_b", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, rna_node_geometry_attribute_input_type_items);
RNA_def_property_ui_text(prop, "Input Type B", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
}
/* -------------------------------------------------------------------------- */
static void rna_def_shader_node(BlenderRNA *brna)

View File

@@ -138,6 +138,7 @@ set(SRC
function/nodes/node_fn_switch.cc
function/node_function_util.cc
geometry/nodes/node_geo_attribute_compare.cc
geometry/nodes/node_geo_attribute_fill.cc
geometry/nodes/node_geo_attribute_math.cc
geometry/nodes/node_geo_common.cc
@@ -148,6 +149,7 @@ set(SRC
geometry/nodes/node_geo_subdivision_surface.cc
geometry/nodes/node_geo_point_distribute.cc
geometry/nodes/node_geo_point_instance.cc
geometry/nodes/node_geo_point_separate.cc
geometry/nodes/node_geo_random_attribute.cc
geometry/nodes/node_geo_transform.cc
geometry/nodes/node_geo_triangulate.cc

View File

@@ -38,6 +38,8 @@ void register_node_type_geo_object_info(void);
void register_node_type_geo_random_attribute(void);
void register_node_type_geo_attribute_math(void);
void register_node_type_geo_join_geometry(void);
void register_node_type_geo_point_separate(void);
void register_node_type_geo_attribute_compare(void);
#ifdef __cplusplus
}

View File

@@ -26,6 +26,8 @@
namespace blender::nodes {
using bke::BooleanReadAttribute;
using bke::BooleanWriteAttribute;
using bke::Color4fReadAttribute;
using bke::Color4fWriteAttribute;
using bke::Float3ReadAttribute;
@@ -168,10 +170,21 @@ class GeoNodeExecParams {
return this->get_input_attribute(name, component, domain, type, &default_value);
}
/**
* Get the type of an input property or the associated constant socket types.
* Fall back to the default value if no attribute exists with the name.
*/
CustomDataType get_input_attribute_data_type(const StringRef name,
const GeometryComponent &component,
const CustomDataType default_type) const;
private:
/* Utilities for detecting common errors at when using this class. */
void check_extract_input(StringRef identifier, const CPPType *requested_type = nullptr) const;
void check_set_output(StringRef identifier, const CPPType &value_type) const;
/* Finds a socket with the name (not identifier) that is currently active. */
const bNodeSocket *find_available_socket(const StringRef name) const;
};
} // namespace blender::nodes

View File

@@ -36,6 +36,7 @@ struct FloatMathOperationInfo {
};
const FloatMathOperationInfo *get_float_math_operation_info(const int operation);
const FloatMathOperationInfo *get_float_compare_operation_info(const int operation);
/**
* This calls the `callback` with two arguments:
@@ -197,4 +198,37 @@ inline bool try_dispatch_float_math_fl_fl_fl_to_fl(const int operation, Callback
return false;
}
/**
* This is similar to try_dispatch_float_math_fl_to_fl, just with a different callback signature.
*/
template<typename Callback>
inline bool try_dispatch_float_math_fl_fl_to_bool(const FloatCompareOperation operation,
Callback &&callback)
{
const FloatMathOperationInfo *info = get_float_compare_operation_info(operation);
if (info == nullptr) {
return false;
}
/* This is just an utility function to keep the individual cases smaller. */
auto dispatch = [&](auto math_function) -> bool {
callback(math_function, *info);
return true;
};
switch (operation) {
case NODE_FLOAT_COMPARE_LESS_THAN:
return dispatch([](float a, float b) { return a < b; });
case NODE_FLOAT_COMPARE_LESS_EQUAL:
return dispatch([](float a, float b) { return a <= b; });
case NODE_FLOAT_COMPARE_GREATER_THAN:
return dispatch([](float a, float b) { return a > b; });
case NODE_FLOAT_COMPARE_GREATER_EQUAL:
return dispatch([](float a, float b) { return a >= b; });
default:
return false;
}
return false;
}
} // namespace blender::nodes

View File

@@ -278,6 +278,8 @@ DefNode(GeometryNode, GEO_NODE_RANDOM_ATTRIBUTE, def_geo_random_attribute, "RAND
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_MATH, def_geo_attribute_math, "ATTRIBUTE_MATH", AttributeMath, "Attribute Math", "")
DefNode(GeometryNode, GEO_NODE_JOIN_GEOMETRY, 0, "JOIN_GEOMETRY", JoinGeometry, "Join Geometry", "")
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_FILL, def_geo_attribute_fill, "ATTRIBUTE_FILL", AttributeFill, "Attribute Fill", "")
DefNode(GeometryNode, GEO_NODE_POINT_SEPARATE, 0, "POINT_SEPARATE", PointSeparate, "Point Separate", "")
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_COMPARE, def_geo_attribute_attribute_compare, "ATTRIBUTE_COMPARE", AttributeCompare, "Attribute Compare", "")
/* undefine macros */
#undef DefNode

View File

@@ -36,6 +36,48 @@ void update_attribute_input_socket_availabilities(bNode &node,
}
}
static int attribute_data_type_complexity(const CustomDataType data_type)
{
switch (data_type) {
case CD_PROP_BOOL:
return 0;
case CD_PROP_FLOAT:
return 2;
case CD_PROP_FLOAT3:
return 4;
case CD_PROP_COLOR:
return 5;
#if 0 /* Attribute types are not supported yet. */
case CD_PROP_INT32:
return 1;
case CD_MLOOPCOL:
return 3;
case CD_PROP_STRING:
return 6;
#endif
default:
/* Only accept "generic" custom data types used by the attribute system. */
BLI_assert(false);
return 0;
}
}
CustomDataType attribute_domain_highest_complexity(Span<CustomDataType> data_types)
{
int highest_complexity = INT_MIN;
CustomDataType most_complex_type = CD_PROP_COLOR;
for (const CustomDataType data_type : data_types) {
const int complexity = attribute_data_type_complexity(data_type);
if (complexity > highest_complexity) {
highest_complexity = complexity;
most_complex_type = data_type;
}
}
return most_complex_type;
}
} // namespace blender::nodes
bool geo_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree)

View File

@@ -42,4 +42,7 @@ namespace blender::nodes {
void update_attribute_input_socket_availabilities(bNode &node,
const StringRef name,
const GeometryNodeAttributeInputMode mode);
}
CustomDataType attribute_domain_highest_complexity(Span<CustomDataType>);
} // namespace blender::nodes

View File

@@ -0,0 +1,362 @@
/*
* 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 "node_geometry_util.hh"
#include "BKE_attribute.h"
#include "BKE_attribute_access.hh"
#include "BLI_array.hh"
#include "BLI_math_base_safe.h"
#include "BLI_rand.hh"
#include "DNA_mesh_types.h"
#include "DNA_pointcloud_types.h"
#include "NOD_math_functions.hh"
static bNodeSocketTemplate geo_node_attribute_compare_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{SOCK_STRING, N_("A")},
{SOCK_FLOAT, N_("A"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
{SOCK_VECTOR, N_("A"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
{SOCK_RGBA, N_("A"), 0.5, 0.5, 0.5, 1.0},
{SOCK_STRING, N_("B")},
{SOCK_FLOAT, N_("B"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
{SOCK_VECTOR, N_("B"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
{SOCK_RGBA, N_("B"), 0.5, 0.5, 0.5, 1.0},
{SOCK_FLOAT, N_("Threshold"), 0.01f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX},
{SOCK_STRING, N_("Result")},
{-1, ""},
};
static bNodeSocketTemplate geo_node_attribute_compare_out[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{-1, ""},
};
static void geo_node_attribute_compare_init(bNodeTree *UNUSED(tree), bNode *node)
{
NodeAttributeCompare *data = (NodeAttributeCompare *)MEM_callocN(sizeof(NodeAttributeCompare),
"attribute mix node");
data->operation = NODE_FLOAT_COMPARE_GREATER_THAN;
data->input_type_a = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE;
data->input_type_b = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE;
node->storage = data;
}
static bool operation_is_equality(const NodeAttributeCompare &node_storage)
{
return ELEM(node_storage.operation, NODE_FLOAT_COMPARE_EQUAL, NODE_FLOAT_COMPARE_NOT_EQUAL);
}
namespace blender::nodes {
static void geo_node_attribute_compare_update(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeAttributeCompare *node_storage = (NodeAttributeCompare *)node->storage;
update_attribute_input_socket_availabilities(
*node, "A", (GeometryNodeAttributeInputMode)node_storage->input_type_a);
update_attribute_input_socket_availabilities(
*node, "B", (GeometryNodeAttributeInputMode)node_storage->input_type_b);
bNodeSocket *socket_epsilon = (bNodeSocket *)BLI_findlink(&node->inputs, 9);
nodeSetSocketAvailability(socket_epsilon, operation_is_equality(*node_storage));
}
static void do_math_operation(const FloatReadAttribute &input_a,
const FloatReadAttribute &input_b,
const FloatCompareOperation operation,
MutableSpan<bool> span_result)
{
const int size = input_a.size();
Span<float> span_a = input_a.get_span();
Span<float> span_b = input_b.get_span();
if (try_dispatch_float_math_fl_fl_to_bool(
operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) {
for (const int i : IndexRange(size)) {
const float a = span_a[i];
const float b = span_b[i];
const bool out = math_function(a, b);
span_result[i] = out;
}
})) {
return;
}
/* The operation is not supported by this node currently. */
BLI_assert(false);
}
static void do_equal_operation(const FloatReadAttribute &input_a,
const FloatReadAttribute &input_b,
const float threshold,
MutableSpan<bool> span_result)
{
const int size = input_a.size();
for (const int i : IndexRange(size)) {
const float a = input_a[i];
const float b = input_b[i];
span_result[i] = compare_ff(a, b, threshold);
}
}
static void do_equal_operation(const Float3ReadAttribute &input_a,
const Float3ReadAttribute &input_b,
const float threshold,
MutableSpan<bool> span_result)
{
const float threshold_squared = pow2f(threshold);
const int size = input_a.size();
for (const int i : IndexRange(size)) {
const float3 a = input_a[i];
const float3 b = input_b[i];
span_result[i] = len_squared_v3v3(a, b) < threshold_squared;
}
}
static void do_equal_operation(const Color4fReadAttribute &input_a,
const Color4fReadAttribute &input_b,
const float threshold,
MutableSpan<bool> span_result)
{
const float threshold_squared = pow2f(threshold);
const int size = input_a.size();
for (const int i : IndexRange(size)) {
const Color4f a = input_a[i];
const Color4f b = input_b[i];
span_result[i] = len_squared_v4v4(a, b) < threshold_squared;
}
}
static void do_equal_operation(const BooleanReadAttribute &input_a,
const BooleanReadAttribute &input_b,
const float UNUSED(threshold),
MutableSpan<bool> span_result)
{
const int size = input_a.size();
for (const int i : IndexRange(size)) {
const bool a = input_a[i];
const bool b = input_b[i];
span_result[i] = a == b;
}
}
static void do_not_equal_operation(const FloatReadAttribute &input_a,
const FloatReadAttribute &input_b,
const float threshold,
MutableSpan<bool> span_result)
{
const int size = input_a.size();
for (const int i : IndexRange(size)) {
const float a = input_a[i];
const float b = input_b[i];
span_result[i] = !compare_ff(a, b, threshold);
}
}
static void do_not_equal_operation(const Float3ReadAttribute &input_a,
const Float3ReadAttribute &input_b,
const float threshold,
MutableSpan<bool> span_result)
{
const float threshold_squared = pow2f(threshold);
const int size = input_a.size();
for (const int i : IndexRange(size)) {
const float3 a = input_a[i];
const float3 b = input_b[i];
span_result[i] = len_squared_v3v3(a, b) >= threshold_squared;
}
}
static void do_not_equal_operation(const Color4fReadAttribute &input_a,
const Color4fReadAttribute &input_b,
const float threshold,
MutableSpan<bool> span_result)
{
const float threshold_squared = pow2f(threshold);
const int size = input_a.size();
for (const int i : IndexRange(size)) {
const Color4f a = input_a[i];
const Color4f b = input_b[i];
span_result[i] = len_squared_v4v4(a, b) >= threshold_squared;
}
}
static void do_not_equal_operation(const BooleanReadAttribute &input_a,
const BooleanReadAttribute &input_b,
const float UNUSED(threshold),
MutableSpan<bool> span_result)
{
const int size = input_a.size();
for (const int i : IndexRange(size)) {
const bool a = input_a[i];
const bool b = input_b[i];
span_result[i] = a != b;
}
}
static CustomDataType get_data_type(GeometryComponent &component,
const GeoNodeExecParams &params,
const NodeAttributeCompare &node_storage)
{
if (operation_is_equality(node_storage)) {
CustomDataType data_type_a = params.get_input_attribute_data_type(
"A", component, CD_PROP_FLOAT);
CustomDataType data_type_b = params.get_input_attribute_data_type(
"B", component, CD_PROP_FLOAT);
/* Convert the input attributes to the same data type for the equality tests. Use the higher
* complexity attribute type, otherwise information necessary to the comparison may be lost. */
return attribute_domain_highest_complexity({data_type_a, data_type_b});
}
/* Use float compare for every operation besides equality. */
return CD_PROP_FLOAT;
}
static void attribute_compare_calc(GeometryComponent &component, const GeoNodeExecParams &params)
{
const bNode &node = params.node();
NodeAttributeCompare *node_storage = (NodeAttributeCompare *)node.storage;
const FloatCompareOperation operation = static_cast<FloatCompareOperation>(
node_storage->operation);
/* The result type of this node is always float. */
const CustomDataType result_type = CD_PROP_BOOL;
/* The result domain is always point for now. */
const AttributeDomain result_domain = ATTR_DOMAIN_POINT;
/* Get result attribute first, in case it has to overwrite one of the existing attributes. */
const std::string result_name = params.get_input<std::string>("Result");
WriteAttributePtr attribute_result = component.attribute_try_ensure_for_write(
result_name, result_domain, result_type);
if (!attribute_result) {
return;
}
const CustomDataType input_data_type = get_data_type(component, params, *node_storage);
ReadAttributePtr attribute_a = params.get_input_attribute(
"A", component, result_domain, input_data_type, nullptr);
ReadAttributePtr attribute_b = params.get_input_attribute(
"B", component, result_domain, input_data_type, nullptr);
if (!attribute_a || !attribute_b) {
/* Attribute wasn't found. */
return;
}
BooleanWriteAttribute attribute_result_bool = std::move(attribute_result);
MutableSpan<bool> result_span = attribute_result_bool.get_span();
/* Use specific types for correct equality operations, but for other operations we use implicit
* conversions and float comparison. In other words, the comparison is not element-wise. */
if (operation_is_equality(*node_storage)) {
const float threshold = params.get_input<float>("Threshold");
if (operation == NODE_FLOAT_COMPARE_EQUAL) {
if (input_data_type == CD_PROP_FLOAT) {
FloatReadAttribute attribute_a_float = std::move(attribute_a);
FloatReadAttribute attribute_b_float = std::move(attribute_b);
do_equal_operation(
std::move(attribute_a_float), std::move(attribute_b_float), threshold, result_span);
}
else if (input_data_type == CD_PROP_FLOAT3) {
Float3ReadAttribute attribute_a_float3 = std::move(attribute_a);
Float3ReadAttribute attribute_b_float3 = std::move(attribute_b);
do_equal_operation(
std::move(attribute_a_float3), std::move(attribute_b_float3), threshold, result_span);
}
else if (input_data_type == CD_PROP_COLOR) {
Color4fReadAttribute attribute_a_color = std::move(attribute_a);
Color4fReadAttribute attribute_b_color = std::move(attribute_b);
do_equal_operation(
std::move(attribute_a_color), std::move(attribute_b_color), threshold, result_span);
}
else if (input_data_type == CD_PROP_BOOL) {
BooleanReadAttribute attribute_a_bool = std::move(attribute_a);
BooleanReadAttribute attribute_b_bool = std::move(attribute_b);
do_equal_operation(
std::move(attribute_a_bool), std::move(attribute_b_bool), threshold, result_span);
}
}
else if (operation == NODE_FLOAT_COMPARE_NOT_EQUAL) {
if (input_data_type == CD_PROP_FLOAT) {
FloatReadAttribute attribute_a_float = std::move(attribute_a);
FloatReadAttribute attribute_b_float = std::move(attribute_b);
do_not_equal_operation(
std::move(attribute_a_float), std::move(attribute_b_float), threshold, result_span);
}
else if (input_data_type == CD_PROP_FLOAT3) {
Float3ReadAttribute attribute_a_float3 = std::move(attribute_a);
Float3ReadAttribute attribute_b_float3 = std::move(attribute_b);
do_not_equal_operation(
std::move(attribute_a_float3), std::move(attribute_b_float3), threshold, result_span);
}
else if (input_data_type == CD_PROP_COLOR) {
Color4fReadAttribute attribute_a_color = std::move(attribute_a);
Color4fReadAttribute attribute_b_color = std::move(attribute_b);
do_not_equal_operation(
std::move(attribute_a_color), std::move(attribute_b_color), threshold, result_span);
}
else if (input_data_type == CD_PROP_BOOL) {
BooleanReadAttribute attribute_a_bool = std::move(attribute_a);
BooleanReadAttribute attribute_b_bool = std::move(attribute_b);
do_not_equal_operation(
std::move(attribute_a_bool), std::move(attribute_b_bool), threshold, result_span);
}
}
}
else {
do_math_operation(std::move(attribute_a), std::move(attribute_b), operation, result_span);
}
attribute_result_bool.apply_span();
}
static void geo_node_attribute_compare_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
if (geometry_set.has<MeshComponent>()) {
attribute_compare_calc(geometry_set.get_component_for_write<MeshComponent>(), params);
}
if (geometry_set.has<PointCloudComponent>()) {
attribute_compare_calc(geometry_set.get_component_for_write<PointCloudComponent>(), params);
}
params.set_output("Geometry", geometry_set);
}
} // namespace blender::nodes
void register_node_type_geo_attribute_compare()
{
static bNodeType ntype;
geo_node_type_base(
&ntype, GEO_NODE_ATTRIBUTE_COMPARE, "Attribute Compare", NODE_CLASS_ATTRIBUTE, 0);
node_type_socket_templates(
&ntype, geo_node_attribute_compare_in, geo_node_attribute_compare_out);
ntype.geometry_node_execute = blender::nodes::geo_node_attribute_compare_exec;
node_type_update(&ntype, blender::nodes::geo_node_attribute_compare_update);
node_type_storage(
&ntype, "NodeAttributeCompare", node_free_standard_storage, node_copy_standard_storage);
node_type_init(&ntype, geo_node_attribute_compare_init);
nodeRegisterType(&ntype);
}

View File

@@ -0,0 +1,212 @@
/*
* 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 "BKE_mesh.h"
#include "BKE_persistent_data_handle.hh"
#include "BKE_pointcloud.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_pointcloud_types.h"
#include "node_geometry_util.hh"
static bNodeSocketTemplate geo_node_point_instance_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{SOCK_STRING, N_("Mask")},
{-1, ""},
};
static bNodeSocketTemplate geo_node_point_instance_out[] = {
{SOCK_GEOMETRY, N_("Geometry 1")},
{SOCK_GEOMETRY, N_("Geometry 2")},
{-1, ""},
};
namespace blender::nodes {
static void fill_new_attribute_from_input(ReadAttributePtr input_attribute,
WriteAttributePtr out_attribute_a,
WriteAttributePtr out_attribute_b,
Span<bool> a_or_b)
{
fn::GSpan in_span = input_attribute->get_span();
int i_a = 0;
int i_b = 0;
for (int i_in = 0; i_in < in_span.size(); i_in++) {
const bool move_to_b = a_or_b[i_in];
if (move_to_b) {
out_attribute_b->set(i_b, in_span[i_in]);
i_b++;
}
else {
out_attribute_a->set(i_a, in_span[i_in]);
i_a++;
}
}
}
/**
* Move the original attribute values to the two output components.
*
* \note This assumes a consistent ordering of indices before and after the split,
* which is true for points and a simple vertex array.
*/
static void move_split_attributes(const GeometryComponent &in_component,
GeometryComponent &out_component_a,
GeometryComponent &out_component_b,
Span<bool> a_or_b)
{
Set<std::string> attribute_names = in_component.attribute_names();
for (const std::string &name : attribute_names) {
ReadAttributePtr attribute = in_component.attribute_try_get_for_read(name);
BLI_assert(attribute);
/* Since this node only creates points and vertices, don't copy other attributes. */
if (attribute->domain() != ATTR_DOMAIN_POINT) {
continue;
}
const CustomDataType data_type = bke::cpp_type_to_custom_data_type(attribute->cpp_type());
const AttributeDomain domain = attribute->domain();
/* Don't try to create the attribute on the new component if it already exists. Built-in
* attributes will already exist on new components by definition. It should always be possible
* to recreate the attribute on the same component type. Also, if one of the new components
* has the attribute the other one should have it too, but check independently to be safe. */
if (!out_component_a.attribute_exists(name)) {
if (!out_component_a.attribute_try_create(name, domain, data_type)) {
BLI_assert(false);
continue;
}
}
if (!out_component_b.attribute_exists(name)) {
if (!out_component_b.attribute_try_create(name, domain, data_type)) {
BLI_assert(false);
continue;
}
}
WriteAttributePtr out_attribute_a = out_component_a.attribute_try_get_for_write(name);
WriteAttributePtr out_attribute_b = out_component_b.attribute_try_get_for_write(name);
if (!out_attribute_a || !out_attribute_b) {
BLI_assert(false);
continue;
}
fill_new_attribute_from_input(
std::move(attribute), std::move(out_attribute_a), std::move(out_attribute_b), a_or_b);
}
}
/**
* Find total in each new set and find which of the output sets each point will belong to.
*/
static Array<bool> count_point_splits(const GeometryComponent &component,
const GeoNodeExecParams &params,
int *r_a_total,
int *r_b_total)
{
const BooleanReadAttribute mask_attribute = params.get_input_attribute<bool>(
"Mask", component, ATTR_DOMAIN_POINT, false);
Array<bool> masks = mask_attribute.get_span();
const int in_total = masks.size();
*r_b_total = 0;
for (const bool mask : masks) {
if (mask) {
*r_b_total += 1;
}
}
*r_a_total = in_total - *r_b_total;
return masks;
}
static void separate_mesh(const MeshComponent &in_component,
const GeoNodeExecParams &params,
MeshComponent &out_component_a,
MeshComponent &out_component_b)
{
const int size = in_component.attribute_domain_size(ATTR_DOMAIN_POINT);
if (size == 0) {
return;
}
int a_total;
int b_total;
Array<bool> a_or_b = count_point_splits(in_component, params, &a_total, &b_total);
out_component_a.replace(BKE_mesh_new_nomain(a_total, 0, 0, 0, 0));
out_component_b.replace(BKE_mesh_new_nomain(b_total, 0, 0, 0, 0));
move_split_attributes(in_component, out_component_a, out_component_b, a_or_b.as_span());
}
static void separate_point_cloud(const PointCloudComponent &in_component,
const GeoNodeExecParams &params,
PointCloudComponent &out_component_a,
PointCloudComponent &out_component_b)
{
const int size = in_component.attribute_domain_size(ATTR_DOMAIN_POINT);
if (size == 0) {
return;
}
int a_total;
int b_total;
Array<bool> a_or_b = count_point_splits(in_component, params, &a_total, &b_total);
out_component_a.replace(BKE_pointcloud_new_nomain(a_total));
out_component_b.replace(BKE_pointcloud_new_nomain(b_total));
move_split_attributes(in_component, out_component_a, out_component_b, a_or_b.as_span());
}
static void geo_node_point_separate_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
GeometrySet out_set_a(geometry_set);
GeometrySet out_set_b;
if (geometry_set.has<PointCloudComponent>()) {
separate_point_cloud(*geometry_set.get_component_for_read<PointCloudComponent>(),
params,
out_set_a.get_component_for_write<PointCloudComponent>(),
out_set_b.get_component_for_write<PointCloudComponent>());
}
if (geometry_set.has<MeshComponent>()) {
separate_mesh(*geometry_set.get_component_for_read<MeshComponent>(),
params,
out_set_a.get_component_for_write<MeshComponent>(),
out_set_b.get_component_for_write<MeshComponent>());
}
params.set_output("Geometry 1", std::move(out_set_a));
params.set_output("Geometry 2", std::move(out_set_b));
}
} // namespace blender::nodes
void register_node_type_geo_point_separate()
{
static bNodeType ntype;
geo_node_type_base(&ntype, GEO_NODE_POINT_SEPARATE, "Point Separate", NODE_CLASS_GEOMETRY, 0);
node_type_socket_templates(&ntype, geo_node_point_instance_in, geo_node_point_instance_out);
ntype.geometry_node_execute = blender::nodes::geo_node_point_separate_exec;
nodeRegisterType(&ntype);
}

View File

@@ -59,6 +59,16 @@ static void geo_node_random_attribute_update(bNodeTree *UNUSED(ntree), bNode *no
namespace blender::nodes {
static void randomize_attribute(BooleanWriteAttribute &attribute, RandomNumberGenerator &rng)
{
MutableSpan<bool> attribute_span = attribute.get_span();
for (const int i : IndexRange(attribute.size())) {
const bool value = rng.get_float() > 0.5f;
attribute_span[i] = value;
}
attribute.apply_span();
}
static void randomize_attribute(FloatWriteAttribute &attribute,
float min,
float max,
@@ -121,6 +131,11 @@ static void randomize_attribute(GeometryComponent &component,
randomize_attribute(float3_attribute, min_value, max_value, rng);
break;
}
case CD_PROP_BOOL: {
BooleanWriteAttribute boolean_attribute = std::move(attribute);
randomize_attribute(boolean_attribute, rng);
break;
}
default:
break;
}

View File

@@ -114,4 +114,34 @@ const FloatMathOperationInfo *get_float_math_operation_info(const int operation)
return nullptr;
}
const FloatMathOperationInfo *get_float_compare_operation_info(const int operation)
{
#define RETURN_OPERATION_INFO(title_case_name, shader_name) \
{ \
static const FloatMathOperationInfo info{title_case_name, shader_name}; \
return &info; \
} \
((void)0)
switch (operation) {
case NODE_FLOAT_COMPARE_LESS_THAN:
RETURN_OPERATION_INFO("Less Than", "math_less_than");
case NODE_FLOAT_COMPARE_LESS_EQUAL:
RETURN_OPERATION_INFO("Less Than or Equal", "math_less_equal");
case NODE_FLOAT_COMPARE_GREATER_THAN:
RETURN_OPERATION_INFO("Greater Than", "math_greater_than");
case NODE_FLOAT_COMPARE_GREATER_EQUAL:
RETURN_OPERATION_INFO("Greater Than or Equal", "math_greater_equal");
case NODE_FLOAT_COMPARE_EQUAL:
RETURN_OPERATION_INFO("Equal", "math_equal");
case NODE_FLOAT_COMPARE_NOT_EQUAL:
RETURN_OPERATION_INFO("Not Equal", "math_not_equal");
}
#undef RETURN_OPERATION_INFO
return nullptr;
}
} // namespace blender::nodes

View File

@@ -19,23 +19,31 @@
namespace blender::nodes {
const bNodeSocket *GeoNodeExecParams::find_available_socket(const StringRef name) const
{
LISTBASE_FOREACH (const bNodeSocket *, socket, &node_.inputs) {
if ((socket->flag & SOCK_UNAVAIL) != 0) {
continue;
}
if (name == socket->name) {
return socket;
}
}
return nullptr;
}
ReadAttributePtr GeoNodeExecParams::get_input_attribute(const StringRef name,
const GeometryComponent &component,
const AttributeDomain domain,
const CustomDataType type,
const void *default_value) const
{
const bNodeSocket *found_socket = nullptr;
LISTBASE_FOREACH (const bNodeSocket *, socket, &node_.inputs) {
if ((socket->flag & SOCK_UNAVAIL) != 0) {
continue;
}
if (name == socket->name) {
found_socket = socket;
break;
}
const bNodeSocket *found_socket = this->find_available_socket(name);
BLI_assert(found_socket != nullptr); /* There should always be available socket for the name. */
if (found_socket == nullptr) {
return component.attribute_get_constant_for_read(domain, type, default_value);
}
BLI_assert(found_socket != nullptr);
if (found_socket->type == SOCK_STRING) {
const std::string name = this->get_input<std::string>(found_socket->identifier);
@@ -60,6 +68,42 @@ ReadAttributePtr GeoNodeExecParams::get_input_attribute(const StringRef name,
return component.attribute_get_constant_for_read(domain, type, default_value);
}
CustomDataType GeoNodeExecParams::get_input_attribute_data_type(
const StringRef name,
const GeometryComponent &component,
const CustomDataType default_type) const
{
const bNodeSocket *found_socket = this->find_available_socket(name);
BLI_assert(found_socket != nullptr); /* There should always be available socket for the name. */
if (found_socket == nullptr) {
return default_type;
}
if (found_socket->type == SOCK_STRING) {
const std::string name = this->get_input<std::string>(found_socket->identifier);
ReadAttributePtr attribute = component.attribute_try_get_for_read(name);
if (!attribute) {
return default_type;
}
return attribute->custom_data_type();
}
if (found_socket->type == SOCK_FLOAT) {
return CD_PROP_FLOAT;
}
if (found_socket->type == SOCK_VECTOR) {
return CD_PROP_FLOAT3;
}
if (found_socket->type == SOCK_RGBA) {
return CD_PROP_COLOR;
}
if (found_socket->type == SOCK_BOOLEAN) {
return CD_PROP_BOOL;
}
BLI_assert(false);
return default_type;
}
void GeoNodeExecParams::check_extract_input(StringRef identifier,
const CPPType *requested_type) const
{

View File

@@ -208,6 +208,8 @@ static DataTypeConversions create_implicit_conversions()
conversions, "float to Color4f", [](float a) { return Color4f(a, a, a, 1.0f); });
add_implicit_conversion<Color4f, float>(
conversions, "Color4f to float", [](Color4f a) { return rgb_to_grayscale(a); });
add_implicit_conversion<float3, bool>(
conversions, "float3 to boolean", [](float3 a) { return a.length() == 0.0f; });
return conversions;
}