Blender V4.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
9#include "BLI_utildefines.h"
10#include <Python.h>
11
12#include "bpy_app_openvdb.hh"
13
15
16#ifdef WITH_OPENVDB
17# include "openvdb_capi.h"
18#endif
19
20static PyTypeObject BlenderAppOVDBType;
21
22static PyStructSequence_Field app_openvdb_info_fields[] = {
23 {"supported", "Boolean, True when Blender is built with OpenVDB support"},
24 {"version", "The OpenVDB version as a tuple of 3 numbers"},
25 {"version_string", "The OpenVDB version formatted as a string"},
26 {nullptr},
27};
28
29static PyStructSequence_Desc app_openvdb_info_desc = {
30 /*name*/ "bpy.app.openvdb",
31 /*doc*/ "This module contains information about OpenVDB blender is linked against",
32 /*fields*/ app_openvdb_info_fields,
33 /*n_in_sequence*/ ARRAY_SIZE(app_openvdb_info_fields) - 1,
34};
35
36static PyObject *make_openvdb_info()
37{
38 PyObject *openvdb_info;
39 int pos = 0;
40
41#ifdef WITH_OPENVDB
42 int curversion;
43#endif
44
45 openvdb_info = PyStructSequence_New(&BlenderAppOVDBType);
46 if (openvdb_info == nullptr) {
47 return nullptr;
48 }
49
50#ifndef WITH_OPENVDB
51# define SetStrItem(str) PyStructSequence_SET_ITEM(openvdb_info, pos++, PyUnicode_FromString(str))
52#endif
53
54#define SetObjItem(obj) PyStructSequence_SET_ITEM(openvdb_info, pos++, obj)
55
56#ifdef WITH_OPENVDB
57 curversion = OpenVDB_getVersionHex();
58 SetObjItem(PyBool_FromLong(1));
60 PyC_Tuple_Pack_I32({curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256}));
61 SetObjItem(PyUnicode_FromFormat(
62 "%2d, %2d, %2d", curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
63#else
64 SetObjItem(PyBool_FromLong(0));
66 SetStrItem("Unknown");
67#endif
68
69 if (UNLIKELY(PyErr_Occurred())) {
70 Py_DECREF(openvdb_info);
71 return nullptr;
72 }
73
74#undef SetStrItem
75#undef SetObjItem
76
77 return openvdb_info;
78}
79
81{
82 PyObject *ret;
83
84 PyStructSequence_InitType(&BlenderAppOVDBType, &app_openvdb_info_desc);
85
87
88 /* prevent user from creating new instances */
89 BlenderAppOVDBType.tp_init = nullptr;
90 BlenderAppOVDBType.tp_new = nullptr;
91 /* Without this we can't do `set(sys.modules)` #29635. */
92 BlenderAppOVDBType.tp_hash = (hashfunc)_Py_HashPointer;
93
94 return ret;
95}
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
static PyStructSequence_Desc app_openvdb_info_desc
PyObject * BPY_app_openvdb_struct()
static PyObject * make_openvdb_info()
static PyTypeObject BlenderAppOVDBType
#define SetStrItem(str)
static PyStructSequence_Field app_openvdb_info_fields[]
#define SetObjItem(obj)
int OpenVDB_getVersionHex()
PyObject * PyC_Tuple_Pack_I32(const blender::Span< int > values)
return ret