Blender  V3.3
bpy_app_usd.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 
8 #include "BLI_utildefines.h"
9 #include <Python.h>
10 
11 #include "bpy_app_usd.h"
12 
13 #include "../generic/py_capi_utils.h"
14 
15 #ifdef WITH_USD
16 # include "usd.h"
17 #endif
18 
19 static PyTypeObject BlenderAppUSDType;
20 
21 static PyStructSequence_Field app_usd_info_fields[] = {
22  {"supported", "Boolean, True when Blender is built with USD support"},
23  {"version", "The USD version as a tuple of 3 numbers"},
24  {"version_string", "The USD version formatted as a string"},
25  {NULL},
26 };
27 
28 static PyStructSequence_Desc app_usd_info_desc = {
29  "bpy.app.usd", /* name */
30  "This module contains information about the Universal Scene Description library Bender is "
31  "linked against", /* doc */
32  app_usd_info_fields, /* fields */
34 };
35 
36 static PyObject *make_usd_info(void)
37 {
38  PyObject *usd_info = PyStructSequence_New(&BlenderAppUSDType);
39 
40  if (usd_info == NULL) {
41  return NULL;
42  }
43 
44  int pos = 0;
45 
46 #ifndef WITH_USD
47 # define SetStrItem(str) PyStructSequence_SET_ITEM(usd_info, pos++, PyUnicode_FromString(str))
48 #endif
49 
50 #define SetObjItem(obj) PyStructSequence_SET_ITEM(usd_info, pos++, obj)
51 
52 #ifdef WITH_USD
53  const int curversion = USD_get_version();
54  const int major = curversion / 10000;
55  const int minor = (curversion / 100) % 100;
56  const int patch = curversion % 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(usd_info);
69  return NULL;
70  }
71 
72 #undef SetStrItem
73 #undef SetObjItem
74 
75  return usd_info;
76 }
77 
78 PyObject *BPY_app_usd_struct(void)
79 {
80  PyStructSequence_InitType(&BlenderAppUSDType, &app_usd_info_desc);
81 
82  PyObject *ret = make_usd_info();
83 
84  /* prevent user from creating new instances */
85  BlenderAppUSDType.tp_init = NULL;
86  BlenderAppUSDType.tp_new = NULL;
87  BlenderAppUSDType.tp_hash = (hashfunc)
88  _Py_HashPointer; /* without this we can't do set(sys.modules) T29635. */
89 
90  return ret;
91 }
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
static PyStructSequence_Desc app_usd_info_desc
Definition: bpy_app_usd.c:28
static PyTypeObject BlenderAppUSDType
Definition: bpy_app_usd.c:19
PyObject * BPY_app_usd_struct(void)
Definition: bpy_app_usd.c:78
static PyObject * make_usd_info(void)
Definition: bpy_app_usd.c:36
static PyStructSequence_Field app_usd_info_fields[]
Definition: bpy_app_usd.c:21
#define SetStrItem(str)
#define SetObjItem(obj)
uint pos
#define PyC_Tuple_Pack_I32(...)
Definition: py_capi_utils.h:88
return ret
int USD_get_version()