Blender V5.3
spz_import.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "spz_import.hh"
10
12#include "DNA_object_types.h"
14#include "DNA_scene_types.h"
15
16#include "BLI_path_utils.hh"
17#include "BLI_string.hh"
18
19#include "BKE_context.hh"
20#include "BKE_layer.hh"
21#include "BKE_library.hh"
22#include "BKE_object.hh"
23#include "BKE_pointcloud.hh"
24#include "BKE_report.hh"
25
26#include "DEG_depsgraph.hh"
28
29#include "IO_spz.hh"
30
31#include "spz_read.hh"
32
34
35void importer_main(const bContext *C, const SPZImportParams &import_params)
36{
37 PointCloud *point_cloud = read_spz_file(import_params.filepath, import_params.reports);
38 if (!point_cloud) {
39 return;
40 }
41
42 Main *bmain = CTX_data_main(C);
43 Scene *scene = CTX_data_scene(C);
44 ViewLayer *view_layer = CTX_data_view_layer(C);
45
46 /* Name used for both object and its data. */
47 char object_name[FILE_MAX];
48 STRNCPY(object_name, BLI_path_basename(import_params.filepath.c_str()));
49 BLI_path_extension_strip(object_name);
50
51 PointCloud *point_cloud_in_main = BKE_pointcloud_add(bmain, object_name);
52 BKE_pointcloud_nomain_to_pointcloud(point_cloud, point_cloud_in_main);
53
54 BKE_view_layer_base_deselect_all(*bmain, scene, view_layer);
55
56 LayerCollection *layer_collection = BKE_layer_collection_get_active_editable(view_layer);
57 if (!ID_IS_EDITABLE(layer_collection->collection)) {
58 BKE_report(import_params.reports,
60 "Could not find an editable collection in current scene, imported data will not be "
61 "instantiated");
62 }
63
64 Object *object = BKE_object_add_only_object(bmain, OB_POINTCLOUD, object_name);
65 object->data = id_cast<ID *>(point_cloud_in_main);
66 BKE_collection_object_add(bmain, layer_collection->collection, object);
67 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
68 if (Base *base = BKE_view_layer_base_find(view_layer, object)) {
69 /* `base` will be nullptr if the Object could not be instantiated in the current view layer. */
71 }
72
75 &object->id,
80}
81
83{
84 return read_spz_file(import_params.filepath, import_params.reports);
85}
86
87} // namespace blender::io::spz
General operations, lookup, etc. for blender objects.
General operations for point clouds.
#define FILE_MAX
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
#define C
Definition RandGen.cpp:29
PointCloud * read_spz_file(const StringRefNull filepath, ReportList *reports)
Definition spz_read.cc:33
void importer_main(const bContext *C, const SPZImportParams &import_params)
Definition spz_import.cc:35
PointCloud * import_point_cloud(const SPZImportParams &import_params)
Definition spz_import.cc:82
bool bool BLI_path_extension_strip(char *path) ATTR_NONNULL(1)
char * STRNCPY(char(&dst)[N], const char *src)
LayerCollection * BKE_layer_collection_get_active_editable(ViewLayer *view_layer)
void BKE_view_layer_base_select_and_set_active(ViewLayer *view_layer, Base *selbase)
@ RPT_WARNING
Definition BKE_report.hh:40
void BKE_pointcloud_nomain_to_pointcloud(PointCloud *pointcloud_src, PointCloud *pointcloud_dst)
ViewLayer * CTX_data_view_layer(const bContext *C)
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void DEG_id_tag_update_ex(Main *bmain, ID *id, unsigned int flags)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
PointCloud * BKE_pointcloud_add(Main *bmain, const char *name)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
void BKE_view_layer_base_deselect_all(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
Main * CTX_data_main(const bContext *C)
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1104
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
void DEG_relations_tag_update(Main *bmain)
Scene * CTX_data_scene(const bContext *C)
Object * BKE_object_add_only_object(Main *bmain, ObjectType type, const char *name) ATTR_RETURNS_NONNULL
Definition object.cc:2265
struct Collection * collection
std::string filepath
Definition IO_spz.hh:21
ReportList * reports
Definition IO_spz.hh:23