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