Blender V5.3
bpy_app_openvdb.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2015 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_utildefines.hh"
10#include <Python.h>
11
12#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
13
14#include "bpy_app_openvdb.hh"
15
17
18namespace blender {
19
20#ifdef WITH_OPENVDB
21# include "openvdb_capi.h"
22#endif
23
24static PyTypeObject BlenderAppOVDBType;
25
26static PyStructSequence_Field app_openvdb_info_fields[] = {
27 {"supported", "Boolean, True when Blender is built with OpenVDB support"},
28 {"version", "The OpenVDB version as a tuple of 3 numbers"},
29 {"version_string", "The OpenVDB version formatted as a string"},
30 {nullptr},
31};
32
33static PyStructSequence_Desc app_openvdb_info_desc = {
34 /*name*/ "bpy.app.openvdb",
35 /*doc*/ "This module contains information about OpenVDB blender is linked against",
36 /*fields*/ app_openvdb_info_fields,
37 /*n_in_sequence*/ ARRAY_SIZE(app_openvdb_info_fields) - 1,
38};
39
40static PyObject *make_openvdb_info()
41{
42 PyObject *openvdb_info;
43 int pos = 0;
44
45#ifdef WITH_OPENVDB
46 int curversion;
47#endif
48
49 openvdb_info = PyStructSequence_New(&BlenderAppOVDBType);
50 if (openvdb_info == nullptr) {
51 return nullptr;
52 }
53
54#ifndef WITH_OPENVDB
55# define SetStrItem(str) PyStructSequence_SET_ITEM(openvdb_info, pos++, PyUnicode_FromString(str))
56#endif
57
58#define SetObjItem(obj) PyStructSequence_SET_ITEM(openvdb_info, pos++, obj)
59
60#ifdef WITH_OPENVDB
61 curversion = OpenVDB_getVersionHex();
62 SetObjItem(PyBool_FromLong(1));
64 PyC_Tuple_Pack_I32({curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256}));
65 SetObjItem(PyUnicode_FromFormat(
66 "%2d, %2d, %2d", curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
67#else
68 SetObjItem(PyBool_FromLong(0));
70 SetStrItem("Unknown");
71#endif
72
73 if (PyErr_Occurred()) [[unlikely]] {
74 Py_DECREF(openvdb_info);
75 return nullptr;
76 }
77
78#undef SetStrItem
79#undef SetObjItem
80
81 return openvdb_info;
82}
83
85{
86 PyObject *ret;
87
88 PyStructSequence_InitType(&BlenderAppOVDBType, &app_openvdb_info_desc);
89
91
92 /* prevent user from creating new instances */
93 BlenderAppOVDBType.tp_init = nullptr;
94 BlenderAppOVDBType.tp_new = nullptr;
95 /* Without this we can't do `set(sys.modules)` #29635. */
96 BlenderAppOVDBType.tp_hash = reinterpret_cast<hashfunc>(Py_HashPointer);
97
98 return ret;
99}
100
101} // namespace blender
#define SetStrItem(str)
#define SetObjItem(obj)
BMesh Iterators.
static PyStructSequence_Field app_openvdb_info_fields[]
PyObject * PyC_Tuple_Pack_I32(const Span< int > values)
PyObject * BPY_app_openvdb_struct()
static PyTypeObject BlenderAppOVDBType
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
static PyStructSequence_Desc app_openvdb_info_desc
static PyObject * make_openvdb_info()
int OpenVDB_getVersionHex()
header-only compatibility defines.
#define Py_HashPointer