Compare commits
3 Commits
geometry-n
...
geometry-n
Author | SHA1 | Date | |
---|---|---|---|
bf4b31468e | |||
f5de32562e | |||
065dfdc529 |
@@ -488,6 +488,7 @@ geometry_node_categories = [
|
||||
GeometryNodeCategory("GEO_MESH", "Mesh", items=[
|
||||
NodeItem("GeometryNodeTriangulate"),
|
||||
NodeItem("GeometryNodeEdgeSplit"),
|
||||
NodeItem("GeometryNodeTransform"),
|
||||
]),
|
||||
GeometryNodeCategory("GEO_MATH", "Misc", items=[
|
||||
NodeItem("ShaderNodeMapRange"),
|
||||
|
@@ -1342,6 +1342,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
|
||||
|
||||
#define GEO_NODE_TRIANGULATE 1000
|
||||
#define GEO_NODE_EDGE_SPLIT 1001
|
||||
#define GEO_NODE_TRANSFORM 1002
|
||||
|
||||
/** \} */
|
||||
|
||||
|
@@ -4661,6 +4661,7 @@ static void registerGeometryNodes(void)
|
||||
|
||||
register_node_type_geo_triangulate();
|
||||
register_node_type_geo_edge_split();
|
||||
register_node_type_geo_transform();
|
||||
}
|
||||
|
||||
static void registerFunctionNodes(void)
|
||||
|
@@ -139,6 +139,7 @@ set(SRC
|
||||
|
||||
geometry/nodes/node_geo_common.cc
|
||||
geometry/nodes/node_geo_edge_split.cc
|
||||
geometry/nodes/node_geo_transform.cc
|
||||
geometry/nodes/node_geo_triangulate.cc
|
||||
geometry/node_geometry_exec.cc
|
||||
geometry/node_geometry_tree.cc
|
||||
|
@@ -28,6 +28,7 @@ void register_node_type_geo_group(void);
|
||||
|
||||
void register_node_type_geo_triangulate(void);
|
||||
void register_node_type_geo_edge_split(void);
|
||||
void register_node_type_geo_transform(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -268,6 +268,7 @@ DefNode(FunctionNode, FN_NODE_RANDOM_FLOAT, 0, "RANDOM_FLOAT",
|
||||
|
||||
DefNode(GeometryNode, GEO_NODE_TRIANGULATE, 0, "TRIANGULATE", Triangulate, "Triangulate", "")
|
||||
DefNode(GeometryNode, GEO_NODE_EDGE_SPLIT, 0, "EDGE_SPLIT", EdgeSplit, "Edge Split", "")
|
||||
DefNode(GeometryNode, GEO_NODE_TRANSFORM, 0, "TRANSFORM", Transform, "Transform", "")
|
||||
|
||||
|
||||
/* undefine macros */
|
||||
|
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "BLI_float3.hh"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
83
source/blender/nodes/geometry/nodes/node_geo_transform.cc
Normal file
83
source/blender/nodes/geometry/nodes/node_geo_transform.cc
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 "BLI_math_matrix.h"
|
||||
|
||||
#include "node_geometry_util.hh"
|
||||
|
||||
static bNodeSocketTemplate geo_node_transform_in[] = {
|
||||
{SOCK_GEOMETRY, N_("Geometry")},
|
||||
{SOCK_VECTOR, N_("Translation"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION},
|
||||
{SOCK_VECTOR, N_("Rotation"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_EULER},
|
||||
{SOCK_VECTOR, N_("Scale"), 1.0f, 1.0f, 1.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_XYZ},
|
||||
{-1, ""},
|
||||
};
|
||||
|
||||
static bNodeSocketTemplate geo_node_transform_out[] = {
|
||||
{SOCK_GEOMETRY, N_("Geometry")},
|
||||
{-1, ""},
|
||||
};
|
||||
|
||||
namespace blender::nodes {
|
||||
static void geo_transform_exec(bNode *UNUSED(node), GValueByName &inputs, GValueByName &outputs)
|
||||
{
|
||||
GeometryPtr geometry_in = inputs.extract<GeometryPtr>("Geometry");
|
||||
GeometryPtr geometry_out;
|
||||
|
||||
if (!geometry_in.has_value()) {
|
||||
outputs.move_in("Geometry", std::move(geometry_out));
|
||||
return;
|
||||
}
|
||||
|
||||
Mesh *mesh_in = geometry_in->mesh_get_for_read();
|
||||
if (mesh_in == nullptr) {
|
||||
outputs.move_in("Geometry", std::move(geometry_out));
|
||||
return;
|
||||
}
|
||||
|
||||
const float3 translation = inputs.extract<float3>("Translation");
|
||||
const float3 rotation = inputs.extract<float3>("Rotation");
|
||||
const float3 scale = inputs.extract<float3>("Scale");
|
||||
|
||||
geometry_out = GeometryPtr{new Geometry()};
|
||||
Mesh *mesh_out = BKE_mesh_copy_for_eval(mesh_in, false);
|
||||
|
||||
/* Use only translation if rotation and scale are zero. */
|
||||
if (translation.length() > 0.0f && rotation.length() == 0.0f && scale.length() == 0.0f) {
|
||||
BKE_mesh_translate(mesh_out, translation, true);
|
||||
}
|
||||
else {
|
||||
float mat[4][4];
|
||||
loc_eul_size_to_mat4(mat, translation, rotation, scale);
|
||||
BKE_mesh_transform(mesh_out, mat, true);
|
||||
}
|
||||
|
||||
geometry_out->mesh_set_and_transfer_ownership(mesh_out);
|
||||
|
||||
outputs.move_in("Geometry", std::move(geometry_out));
|
||||
}
|
||||
} // namespace blender::nodes
|
||||
|
||||
void register_node_type_geo_transform()
|
||||
{
|
||||
static bNodeType ntype;
|
||||
|
||||
geo_node_type_base(&ntype, GEO_NODE_TRANSFORM, "Transform", 0, 0);
|
||||
node_type_socket_templates(&ntype, geo_node_transform_in, geo_node_transform_out);
|
||||
ntype.geometry_node_execute = blender::nodes::geo_transform_exec;
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
Reference in New Issue
Block a user