Blender V5.3
bpy_app_alembic.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 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_alembic.hh"
15
17
18#ifdef WITH_ALEMBIC
19# include "ABC_alembic.h"
20#endif
21
22namespace blender {
23
24static PyTypeObject BlenderAppABCType;
25
26static PyStructSequence_Field app_alembic_info_fields[] = {
27 {"supported", "Boolean, True when Blender is built with Alembic support"},
28 {"version", "The Alembic version as a tuple of 3 numbers"},
29 {"version_string", "The Alembic version formatted as a string"},
30 {nullptr},
31};
32
33static PyStructSequence_Desc app_alembic_info_desc = {
34 /*name*/ "bpy.app.alembic",
35 /*doc*/ "This module contains information about Alembic blender is linked against",
36 /*fields*/ app_alembic_info_fields,
37 /*n_in_sequence*/ ARRAY_SIZE(app_alembic_info_fields) - 1,
38};
39
40static PyObject *make_alembic_info()
41{
42 PyObject *alembic_info = PyStructSequence_New(&BlenderAppABCType);
43
44 if (alembic_info == nullptr) {
45 return nullptr;
46 }
47
48 int pos = 0;
49
50#ifndef WITH_ALEMBIC
51# define SetStrItem(str) PyStructSequence_SET_ITEM(alembic_info, pos++, PyUnicode_FromString(str))
52#endif
53
54#define SetObjItem(obj) PyStructSequence_SET_ITEM(alembic_info, pos++, obj)
55
56#ifdef WITH_ALEMBIC
57 const int curversion = ABC_get_version();
58 const int major = curversion / 10000;
59 const int minor = (curversion / 100) - (major * 100);
60 const int patch = curversion - ((curversion / 100) * 100);
61
62 SetObjItem(PyBool_FromLong(1));
63 SetObjItem(PyC_Tuple_Pack_I32({major, minor, patch}));
64 SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d", major, minor, patch));
65#else
66 SetObjItem(PyBool_FromLong(0));
68 SetStrItem("Unknown");
69#endif
70
71 if (PyErr_Occurred()) [[unlikely]] {
72 Py_DECREF(alembic_info);
73 return nullptr;
74 }
75
76#undef SetStrItem
77#undef SetObjItem
78
79 return alembic_info;
80}
81
83{
84 PyStructSequence_InitType(&BlenderAppABCType, &app_alembic_info_desc);
85
86 PyObject *ret = make_alembic_info();
87
88 /* prevent user from creating new instances */
89 BlenderAppABCType.tp_init = nullptr;
90 BlenderAppABCType.tp_new = nullptr;
91 /* Without this we can't do `set(sys.modules)` #29635. */
92 BlenderAppABCType.tp_hash = reinterpret_cast<hashfunc>(Py_HashPointer);
93
94 return ret;
95}
96
97} // namespace blender
#define SetStrItem(str)
#define SetObjItem(obj)
BMesh Iterators.
static PyTypeObject BlenderAppABCType
static PyStructSequence_Desc app_alembic_info_desc
static PyObject * make_alembic_info()
PyObject * PyC_Tuple_Pack_I32(const Span< int > values)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
PyObject * BPY_app_alembic_struct()
int ABC_get_version()
static PyStructSequence_Field app_alembic_info_fields[]
header-only compatibility defines.
#define Py_HashPointer