2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2020-04-20 10:58:43 +02:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
BLI: Refactor vector types & functions to use templates
This patch implements the vector types (i.e:`float2`) by making heavy
usage of templating. All vector functions are now outside of the vector
classes (inside the `blender::math` namespace) and are not vector size
dependent for the most part.
In the ongoing effort to make shaders less GL centric, we are aiming
to share more code between GLSL and C++ to avoid code duplication.
####Motivations:
- We are aiming to share UBO and SSBO structures between GLSL and C++.
This means we will use many of the existing vector types and others
we currently don't have (uintX, intX). All these variations were
asking for many more code duplication.
- Deduplicate existing code which is duplicated for each vector size.
- We also want to share small functions. Which means that vector
functions should be static and not in the class namespace.
- Reduce friction to use these types in new projects due to their
incompleteness.
- The current state of the `BLI_(float|double|mpq)(2|3|4).hh` is a
bit of a let down. Most clases are incomplete, out of sync with each
others with different codestyles, and some functions that should be
static are not (i.e: `float3::reflect()`).
####Upsides:
- Still support `.x, .y, .z, .w` for readability.
- Compact, readable and easilly extendable.
- All of the vector functions are available for all the vectors types
and can be restricted to certain types. Also template specialization
let us define exception for special class (like mpq).
- With optimization ON, the compiler unroll the loops and performance
is the same.
####Downsides:
- Might impact debugability. Though I would arge that the bugs are
rarelly caused by the vector class itself (since the operations are
quite trivial) but by the type conversions.
- Might impact compile time. I did not saw a significant impact since
the usage is not really widespread.
- Functions needs to be rewritten to support arbitrary vector length.
For instance, one can't call `len_squared_v3v3` in
`math::length_squared()` and call it a day.
- Type cast does not work with the template version of the `math::`
vector functions. Meaning you need to manually cast `float *` and
`(float *)[3]` to `float3` for the function calls.
i.e: `math::distance_squared(float3(nearest.co), positions[i]);`
- Some parts might loose in readability:
`float3::dot(v1.normalized(), v2.normalized())`
becoming
`math::dot(math::normalize(v1), math::normalize(v2))`
But I propose, when appropriate, to use
`using namespace blender::math;` on function local or file scope to
increase readability.
`dot(normalize(v1), normalize(v2))`
####Consideration:
- Include back `.length()` method. It is quite handy and is more C++
oriented.
- I considered the GLM library as a candidate for replacement. It felt
like too much for what we need and would be difficult to extend / modify
to our needs.
- I used Macros to reduce code in operators declaration and potential
copy paste bugs. This could reduce debugability and could be reverted.
- This touches `delaunay_2d.cc` and the intersection code. I would like
to know @howardt opinion on the matter.
- The `noexcept` on the copy constructor of `mpq(2|3)` is being removed.
But according to @JacquesLucke it is not a real problem for now.
I would like to give a huge thanks to @JacquesLucke who helped during this
and pushed me to reduce the duplication further.
Reviewed By: brecht, sergey, JacquesLucke
Differential Revision: https://developer.blender.org/D13791
2022-01-12 12:57:07 +01:00
|
|
|
#include "BLI_math_vec_types.hh"
|
2020-04-20 10:58:43 +02:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_node_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_node.h"
|
|
|
|
|
|
|
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
#include "NOD_geometry.h"
|
|
|
|
|
#include "NOD_geometry_exec.hh"
|
2021-08-30 17:13:46 +02:00
|
|
|
#include "NOD_socket_declarations.hh"
|
2021-10-26 20:00:03 +02:00
|
|
|
#include "NOD_socket_declarations_geometry.hh"
|
2020-04-20 10:58:43 +02:00
|
|
|
|
|
|
|
|
#include "node_util.h"
|
|
|
|
|
|
2022-01-03 19:32:33 -05:00
|
|
|
void geo_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass);
|
2021-04-12 18:43:23 +02:00
|
|
|
bool geo_node_poll_default(struct bNodeType *ntype,
|
|
|
|
|
struct bNodeTree *ntree,
|
|
|
|
|
const char **r_disabled_hint);
|
2020-12-09 16:20:48 +01:00
|
|
|
|
|
|
|
|
namespace blender::nodes {
|
2020-12-18 16:00:45 +01:00
|
|
|
|
2021-10-15 14:20:53 -05:00
|
|
|
void transform_mesh(Mesh &mesh,
|
2021-03-16 17:35:12 -04:00
|
|
|
const float3 translation,
|
|
|
|
|
const float3 rotation,
|
|
|
|
|
const float3 scale);
|
|
|
|
|
|
2021-10-15 14:20:53 -05:00
|
|
|
void transform_geometry_set(GeometrySet &geometry,
|
|
|
|
|
const float4x4 &transform,
|
|
|
|
|
const Depsgraph &depsgraph);
|
|
|
|
|
|
2022-01-07 11:38:08 +11:00
|
|
|
Mesh *create_line_mesh(const float3 start, const float3 delta, int count);
|
2021-08-29 22:08:57 -05:00
|
|
|
|
2022-01-07 11:38:08 +11:00
|
|
|
Mesh *create_grid_mesh(int verts_x, int verts_y, float size_x, float size_y);
|
2021-08-29 22:08:57 -05:00
|
|
|
|
2021-11-03 20:20:15 +01:00
|
|
|
struct ConeAttributeOutputs {
|
|
|
|
|
StrongAnonymousAttributeID top_id;
|
|
|
|
|
StrongAnonymousAttributeID bottom_id;
|
|
|
|
|
StrongAnonymousAttributeID side_id;
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-07 11:38:08 +11:00
|
|
|
Mesh *create_cylinder_or_cone_mesh(float radius_top,
|
|
|
|
|
float radius_bottom,
|
|
|
|
|
float depth,
|
|
|
|
|
int circle_segments,
|
|
|
|
|
int side_segments,
|
|
|
|
|
int fill_segments,
|
2022-01-12 12:49:36 +01:00
|
|
|
GeometryNodeMeshCircleFillType fill_type,
|
2021-11-03 20:20:15 +01:00
|
|
|
ConeAttributeOutputs &attribute_outputs);
|
2021-03-16 17:35:12 -04:00
|
|
|
|
2021-08-29 22:08:57 -05:00
|
|
|
Mesh *create_cuboid_mesh(float3 size, int verts_x, int verts_y, int verts_z);
|
2021-04-06 16:02:55 -05:00
|
|
|
|
2021-06-01 17:32:03 -04:00
|
|
|
/**
|
|
|
|
|
* Copies the point domain attributes from `in_component` that are in the mask to `out_component`.
|
|
|
|
|
*/
|
|
|
|
|
void copy_point_attributes_based_on_mask(const GeometryComponent &in_component,
|
|
|
|
|
GeometryComponent &result_component,
|
|
|
|
|
Span<bool> masks,
|
2022-01-07 11:38:08 +11:00
|
|
|
bool invert);
|
2021-10-11 08:38:02 -05:00
|
|
|
/**
|
|
|
|
|
* Returns the parts of the geometry that are on the selection for the given domain. If the domain
|
|
|
|
|
* is not applicable for the component, e.g. face domain for point cloud, nothing happens to that
|
|
|
|
|
* component. If no component can work with the domain, then `error_message` is set to true.
|
|
|
|
|
*/
|
|
|
|
|
void separate_geometry(GeometrySet &geometry_set,
|
2022-01-07 11:38:08 +11:00
|
|
|
AttributeDomain domain,
|
|
|
|
|
GeometryNodeDeleteGeometryMode mode,
|
2021-10-11 08:38:02 -05:00
|
|
|
const Field<bool> &selection_field,
|
2022-01-07 11:38:08 +11:00
|
|
|
bool invert,
|
2021-10-11 16:07:57 +02:00
|
|
|
bool &r_is_error);
|
2021-06-01 17:32:03 -04:00
|
|
|
|
2021-12-15 09:51:57 -06:00
|
|
|
std::optional<CustomDataType> node_data_type_to_custom_data_type(eNodeSocketDatatype type);
|
|
|
|
|
std::optional<CustomDataType> node_socket_to_custom_data_type(const bNodeSocket &socket);
|
|
|
|
|
|
2022-03-30 10:37:39 -05:00
|
|
|
class SplineLengthFieldInput final : public GeometryFieldInput {
|
|
|
|
|
public:
|
|
|
|
|
SplineLengthFieldInput();
|
|
|
|
|
GVArray get_varray_for_context(const GeometryComponent &component,
|
|
|
|
|
AttributeDomain domain,
|
|
|
|
|
IndexMask mask) const final;
|
|
|
|
|
uint64_t hash() const override;
|
|
|
|
|
bool is_equal_to(const fn::FieldNode &other) const override;
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-16 16:59:30 +01:00
|
|
|
} // namespace blender::nodes
|