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