Blender V4.3
bpy_app_usd.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 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_usd.hh"
13
15
16#ifdef WITH_USD
17# include "usd.hh"
18#endif
19
20static PyTypeObject BlenderAppUSDType;
21
22static PyStructSequence_Field app_usd_info_fields[] = {
23 {"supported", "Boolean, True when Blender is built with USD support"},
24 {"version", "The USD version as a tuple of 3 numbers"},
25 {"version_string", "The USD version formatted as a string"},
26 {nullptr},
27};
28
29static PyStructSequence_Desc app_usd_info_desc = {
30 /*name*/ "bpy.app.usd",
31 /*doc*/
32 "This module contains information about the Universal Scene Description library Bender is "
33 "linked against",
34 /*fields*/ app_usd_info_fields,
35 /*n_in_sequence*/ ARRAY_SIZE(app_usd_info_fields) - 1,
36};
37
38static PyObject *make_usd_info()
39{
40 PyObject *usd_info = PyStructSequence_New(&BlenderAppUSDType);
41
42 if (usd_info == nullptr) {
43 return nullptr;
44 }
45
46 int pos = 0;
47
48#ifndef WITH_USD
49# define SetStrItem(str) PyStructSequence_SET_ITEM(usd_info, pos++, PyUnicode_FromString(str))
50#endif
51
52#define SetObjItem(obj) PyStructSequence_SET_ITEM(usd_info, pos++, obj)
53
54#ifdef WITH_USD
55 const int curversion = blender::io::usd::USD_get_version();
56 const int major = curversion / 10000;
57 const int minor = (curversion / 100) % 100;
58 const int patch = curversion % 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(usd_info);
71 return nullptr;
72 }
73
74#undef SetStrItem
75#undef SetObjItem
76
77 return usd_info;
78}
79
81{
82 PyStructSequence_InitType(&BlenderAppUSDType, &app_usd_info_desc);
83
84 PyObject *ret = make_usd_info();
85
86 /* prevent user from creating new instances */
87 BlenderAppUSDType.tp_init = nullptr;
88 BlenderAppUSDType.tp_new = nullptr;
89 /* Without this we can't do `set(sys.modules)` #29635. */
90 BlenderAppUSDType.tp_hash = (hashfunc)_Py_HashPointer;
91
92 return ret;
93}
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
static PyStructSequence_Desc app_usd_info_desc
static PyTypeObject BlenderAppUSDType
static PyObject * make_usd_info()
PyObject * BPY_app_usd_struct()
static PyStructSequence_Field app_usd_info_fields[]
#define SetStrItem(str)
#define SetObjItem(obj)
PyObject * PyC_Tuple_Pack_I32(const blender::Span< int > values)
return ret