Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_object_info.cc
| Show All 32 Lines | static bNodeSocketTemplate geo_node_object_info_out[] = { | ||||
| {SOCK_VECTOR, N_("Scale")}, | {SOCK_VECTOR, N_("Scale")}, | ||||
| {SOCK_GEOMETRY, N_("Geometry")}, | {SOCK_GEOMETRY, N_("Geometry")}, | ||||
| {-1, ""}, | {-1, ""}, | ||||
| }; | }; | ||||
| namespace blender::nodes { | namespace blender::nodes { | ||||
| static void geo_node_object_info_exec(GeoNodeExecParams params) | static void geo_node_object_info_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| const bNode &bnode = params.node(); | |||||
| NodeGeometryObjectInfo *node_storage = (NodeGeometryObjectInfo *)bnode.storage; | |||||
| const bool transform_space_relative = (node_storage->transform_space == | |||||
| GEO_NODE_TRANSFORM_SPACE_RELATIVE); | |||||
| bke::PersistentObjectHandle object_handle = params.extract_input<bke::PersistentObjectHandle>( | bke::PersistentObjectHandle object_handle = params.extract_input<bke::PersistentObjectHandle>( | ||||
| "Object"); | "Object"); | ||||
| Object *object = params.handle_map().lookup(object_handle); | Object *object = params.handle_map().lookup(object_handle); | ||||
| float3 location = {0, 0, 0}; | float3 location = {0, 0, 0}; | ||||
| float3 rotation = {0, 0, 0}; | float3 rotation = {0, 0, 0}; | ||||
| float3 scale = {0, 0, 0}; | float3 scale = {0, 0, 0}; | ||||
| GeometrySet geometry_set; | GeometrySet geometry_set; | ||||
| const Object *self_object = params.self_object(); | const Object *self_object = params.self_object(); | ||||
| if (object != nullptr) { | if (object != nullptr) { | ||||
| float transform[4][4]; | float transform[4][4]; | ||||
| mul_m4_m4m4(transform, self_object->imat, object->obmat); | mul_m4_m4m4(transform, self_object->imat, object->obmat); | ||||
| float quaternion[4]; | float quaternion[4]; | ||||
| if (transform_space_relative) { | |||||
| mat4_decompose(location, quaternion, scale, transform); | mat4_decompose(location, quaternion, scale, transform); | ||||
| } | |||||
| else { | |||||
| mat4_decompose(location, quaternion, scale, object->obmat); | |||||
| } | |||||
| quat_to_eul(rotation, quaternion); | quat_to_eul(rotation, quaternion); | ||||
| if (object != self_object) { | if (object != self_object) { | ||||
| if (object->type == OB_MESH) { | if (object->type == OB_MESH) { | ||||
| Mesh *mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(object, false); | Mesh *mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(object, false); | ||||
| if (mesh != nullptr) { | if (mesh != nullptr) { | ||||
| BKE_mesh_wrapper_ensure_mdata(mesh); | BKE_mesh_wrapper_ensure_mdata(mesh); | ||||
| /* Make a copy because the life time of the other mesh might be shorter. */ | /* Make a copy because the life time of the other mesh might be shorter. */ | ||||
| Mesh *copied_mesh = BKE_mesh_copy_for_eval(mesh, false); | Mesh *copied_mesh = BKE_mesh_copy_for_eval(mesh, false); | ||||
| if (transform_space_relative) { | |||||
| /* Transform into the local space of the object that is being modified. */ | /* Transform into the local space of the object that is being modified. */ | ||||
| BKE_mesh_transform(copied_mesh, transform, true); | BKE_mesh_transform(copied_mesh, transform, true); | ||||
| } | |||||
| MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>(); | MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>(); | ||||
| mesh_component.replace(copied_mesh); | mesh_component.replace(copied_mesh); | ||||
| mesh_component.copy_vertex_group_names_from_object(*object); | mesh_component.copy_vertex_group_names_from_object(*object); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| params.set_output("Location", location); | params.set_output("Location", location); | ||||
| params.set_output("Rotation", rotation); | params.set_output("Rotation", rotation); | ||||
| params.set_output("Scale", scale); | params.set_output("Scale", scale); | ||||
| params.set_output("Geometry", geometry_set); | params.set_output("Geometry", geometry_set); | ||||
| } | } | ||||
| static void geo_node_object_info_node_init(bNodeTree *UNUSED(tree), bNode *node) | |||||
| { | |||||
| NodeGeometryObjectInfo *data = (NodeGeometryObjectInfo *)MEM_callocN( | |||||
| sizeof(NodeGeometryObjectInfo), __func__); | |||||
| data->transform_space = GEO_NODE_TRANSFORM_SPACE_ORIGINAL; | |||||
| node->storage = data; | |||||
| } | |||||
| } // namespace blender::nodes | } // namespace blender::nodes | ||||
| void register_node_type_geo_object_info() | void register_node_type_geo_object_info() | ||||
| { | { | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| geo_node_type_base(&ntype, GEO_NODE_OBJECT_INFO, "Object Info", NODE_CLASS_INPUT, 0); | geo_node_type_base(&ntype, GEO_NODE_OBJECT_INFO, "Object Info", NODE_CLASS_INPUT, 0); | ||||
| node_type_socket_templates(&ntype, geo_node_object_info_in, geo_node_object_info_out); | node_type_socket_templates(&ntype, geo_node_object_info_in, geo_node_object_info_out); | ||||
| node_type_init(&ntype, blender::nodes::geo_node_object_info_node_init); | |||||
| node_type_storage( | |||||
| &ntype, "NodeGeometryObjectInfo", node_free_standard_storage, node_copy_standard_storage); | |||||
| ntype.geometry_node_execute = blender::nodes::geo_node_object_info_exec; | ntype.geometry_node_execute = blender::nodes::geo_node_object_info_exec; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||