diff options
author | Rajesh Advani <rajeshja> | 2021-08-30 06:08:57 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-08-30 06:08:57 +0300 |
commit | b44406f9634a35ebe0b4fd334715d63e75af08a0 (patch) | |
tree | 490b61de96e341c5c5eb66621e2e36c7ea5cc34d /source/blender/blenloader | |
parent | b42354672e804be79315315855d105e7d9e11899 (diff) |
Geometry Nodes: Enhance the cube mesh primitive as a cuboid
This mesh primitive enhances the Cube mesh primitive and allows the
creation of a cuboid with a configurable size and number of vertices
in all 3 directions. The Cube primitive is now similar to the Grid
primitive except that it works in 3 dimensions.
Previously it was possible to create a cube and scale it arbitrarily
along each axis. You could also subdivide the mesh, but the number of
subdivisions was equal along all axes. This meant that making the basic
frame for something like modular buildings wasn't trivial.
Inspired by tutorials and files for modular building creation.
The cuboid is created as a `Mesh` so that large meshes with millions of
faces are created quickly. Though edge calculation could be faster if
implemented here, edges are calculated using `BKE_mesh_calc_edges`
to reduce complexity, and in hopes that they may be calculated lazily
for `Mesh` in the future like vertex normals.
See the differential revision for more information.
Differential Revision: https://developer.blender.org/D11810
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r-- | source/blender/blenloader/intern/versioning_300.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c index 2456b22f046..136ea786903 100644 --- a/source/blender/blenloader/intern/versioning_300.c +++ b/source/blender/blenloader/intern/versioning_300.c @@ -636,6 +636,20 @@ static void do_version_constraints_spline_ik_joint_bindings(ListBase *lb) } } +static bNodeSocket *do_version_replace_float_size_with_vector(bNodeTree *ntree, + bNode *node, + bNodeSocket *socket) +{ + const bNodeSocketValueFloat *socket_value = (const bNodeSocketValueFloat *)socket->default_value; + const float old_value = socket_value->value; + nodeRemoveSocket(ntree, node, socket); + bNodeSocket *new_socket = nodeAddSocket( + ntree, node, SOCK_IN, nodeStaticSocketType(SOCK_VECTOR, PROP_TRANSLATION), "Size", "Size"); + bNodeSocketValueVector *value_vector = (bNodeSocketValueVector *)new_socket->default_value; + copy_v3_fl(value_vector->value, old_value); + return new_socket; +} + /* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) { @@ -1052,6 +1066,43 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) } } + if (!MAIN_VERSION_ATLEAST(bmain, 300, 20)) { + /* Use new vector Size socket in Cube Mesh Primitive node. */ + LISTBASE_FOREACH (bNodeTree *, ntree, &bmain->nodetrees) { + if (ntree->type != NTREE_GEOMETRY) { + continue; + } + + LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) { + if (link->tonode->type == GEO_NODE_MESH_PRIMITIVE_CUBE) { + bNode *node = link->tonode; + if (STREQ(link->tosock->identifier, "Size") && link->tosock->type == SOCK_FLOAT) { + bNode *link_fromnode = link->fromnode; + bNodeSocket *link_fromsock = link->fromsock; + bNodeSocket *socket = link->tosock; + BLI_assert(socket); + + bNodeSocket *new_socket = do_version_replace_float_size_with_vector( + ntree, node, socket); + nodeAddLink(ntree, link_fromnode, link_fromsock, node, new_socket); + } + } + } + + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + if (node->type != GEO_NODE_MESH_PRIMITIVE_CUBE) { + continue; + } + LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) { + if (STREQ(socket->identifier, "Size") && (socket->type == SOCK_FLOAT)) { + do_version_replace_float_size_with_vector(ntree, node, socket); + break; + } + } + } + } + } + /** * Versioning code until next subversion bump goes here. * |