Skip to content

Commit 483d45f

Browse files
committed
More api for viewport
1 parent ad35d85 commit 483d45f

File tree

9 files changed

+603
-2
lines changed

9 files changed

+603
-2
lines changed

source/plugins/Sea5kg/Python3Scripting/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ add_library(${current_target} SHARED
128128
${PROJECT_SOURCE_DIR}/src/python3_wrapper/pytypesobjects/python3_unigine_objectmeshdynamic.cpp
129129
${PROJECT_SOURCE_DIR}/src/python3_wrapper/pytypesobjects/python3_unigine_vec2.cpp
130130
${PROJECT_SOURCE_DIR}/src/python3_wrapper/pytypesobjects/python3_unigine_vec3.cpp
131+
${PROJECT_SOURCE_DIR}/src/python3_wrapper/pytypesobjects/python3_unigine_viewportmanager.cpp
132+
${PROJECT_SOURCE_DIR}/src/python3_wrapper/pytypesobjects/python3_unigine_player.cpp
133+
${PROJECT_SOURCE_DIR}/src/python3_wrapper/pytypesobjects/python3_unigine_viewportwindow.cpp
131134
)
132135

133136
IF (WIN32)

source/plugins/Sea5kg/Python3Scripting/src/python3_wrapper/pytypesobjects/python3_pytypeobjects.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include "python3_unigine_uguid.h"
1010
#include "python3_unigine_vec3.h"
1111
#include "python3_unigine_vec2.h"
12+
#include "python3_unigine_viewportmanager.h"
13+
#include "python3_unigine_player.h"
14+
#include "python3_unigine_viewportwindow.h"
1215

1316
Python3PyTypeObjectAll::Python3PyTypeObjectAll() {
1417
m_vPyTypesObjects.push_back(new PyUnigine::Python3UnigineUGUID());
@@ -20,6 +23,9 @@ Python3PyTypeObjectAll::Python3PyTypeObjectAll() {
2023
m_vPyTypesObjects.push_back(new PyUnigine::Python3UnigineAssetManager());
2124
m_vPyTypesObjects.push_back(new PyUnigine::Python3UnigineObjectMeshDynamic());
2225
m_vPyTypesObjects.push_back(new PyUnigine::Python3UnigineMesh());
26+
m_vPyTypesObjects.push_back(new PyUnigine::Python3UnigineViewportManager());
27+
m_vPyTypesObjects.push_back(new PyUnigine::Python3UniginePlayer());
28+
m_vPyTypesObjects.push_back(new PyUnigine::Python3UnigineViewportWindow());
2329
}
2430

2531
bool Python3PyTypeObjectAll::isReady() {

source/plugins/Sea5kg/Python3Scripting/src/python3_wrapper/pytypesobjects/python3_unigine_node.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include <iostream>
1111

12+
#include "python3_unigine_vec3.h"
13+
1214
namespace PyUnigine {
1315

1416
// ------------------------------------------------------------------------------------------
@@ -67,6 +69,67 @@ static PyObject * unigine_Node_get_name(unigine_Node* self) {
6769
return PyUnicode_FromFormat("%S", pName);
6870
}
6971

72+
// public : getWorldPosition
73+
static PyObject * unigine_Node_get_world_position(unigine_Node* self) {
74+
PyErr_Clear();
75+
PyObject *ret = NULL;
76+
// parse args:
77+
78+
class LocalRunner : public Python3Runner {
79+
public:
80+
virtual void run() override {
81+
retOriginal = unigine_object_ptr->getWorldPosition();
82+
};
83+
Unigine::Ptr<Unigine::Node> unigine_object_ptr;
84+
// return
85+
Unigine::Math::Vec3 retOriginal;
86+
};
87+
auto *pRunner = new LocalRunner();
88+
pRunner->unigine_object_ptr = self->unigine_object_ptr;
89+
Python3Runner::runInMainThread(pRunner);
90+
while (!pRunner->mutexAsync.tryLock(5)) { // milliseconds
91+
}
92+
pRunner->mutexAsync.unlock();
93+
Unigine::Math::Vec3 retOriginal = pRunner->retOriginal;
94+
delete pRunner;
95+
Unigine::Math::vec3 *retOriginal2 = new Unigine::Math::vec3(retOriginal);
96+
ret = PyUnigine::vec3::NewObject(retOriginal2);
97+
98+
// end
99+
// return: Unigine::Math::Vec3
100+
return ret;
101+
};
102+
103+
// // public : getWorldRotation
104+
// static PyObject * unigine_Node_get_world_rotation(unigine_Node* self) {
105+
// PyErr_Clear();
106+
// PyObject *ret = NULL;
107+
// // parse args:
108+
109+
// class LocalRunner : public Python3Runner {
110+
// public:
111+
// virtual void run() override {
112+
// retOriginal = unigine_object_ptr->getWorldRotation();
113+
// };
114+
// Unigine::Ptr<Unigine::Node> unigine_object_ptr;
115+
// // return
116+
// Unigine::Math::quat retOriginal;
117+
// };
118+
// auto *pRunner = new LocalRunner();
119+
// pRunner->unigine_object_ptr = self->unigine_object_ptr;
120+
// Python3Runner::runInMainThread(pRunner);
121+
// while (!pRunner->mutexAsync.tryLock(5)) { // milliseconds
122+
// }
123+
// pRunner->mutexAsync.unlock();
124+
// Unigine::Math::quat retOriginal = pRunner->retOriginal;
125+
// delete pRunner;
126+
// ret = PyLong_FromLong(retOriginal);
127+
128+
// // end
129+
// // return: Unigine::Math::quat
130+
// return ret;
131+
// };
132+
70133
// public : rotate
71134
static PyObject * unigine_Node_rotate(unigine_Node* self, PyObject *args) {
72135
PyErr_Clear();
@@ -123,6 +186,14 @@ static PyMethodDef unigine_Node_methods[] = {
123186
"get_name", (PyCFunction)unigine_Node_get_name, METH_NOARGS,
124187
"public : getName"
125188
},
189+
{
190+
"get_world_position", (PyCFunction)unigine_Node_get_world_position, METH_NOARGS,
191+
"public : getWorldPosition"
192+
},
193+
// {
194+
// "get_world_rotation", (PyCFunction)unigine_Node_get_world_rotation, METH_NOARGS,
195+
// "public : getWorldRotation"
196+
// },
126197
{
127198
"rotate", (PyCFunction)unigine_Node_rotate, METH_VARARGS,
128199
"public : rotate"
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
// this file automaticly generated from UniginePlayer.h
2+
#include "python3_unigine_player.h"
3+
4+
#include <string>
5+
#include <UniginePlayers.h>
6+
#include <UnigineLog.h>
7+
#include <Python.h>
8+
#include <structmember.h>
9+
10+
#include <iostream>
11+
12+
#include "python3_unigine_vec3.h"
13+
14+
namespace PyUnigine {
15+
16+
// ------------------------------------------------------------------------------------------
17+
// unigine_Player
18+
19+
typedef struct {
20+
PyObject_HEAD
21+
// Type-specific fields go here.
22+
Unigine::Ptr<Unigine::Player> unigine_object_ptr;
23+
} unigine_Player;
24+
25+
static void unigine_Player_dealloc(unigine_Player* self) {
26+
// Unigine::Log::message("unigine_Player_dealloc\n");
27+
Py_TYPE(self)->tp_free((PyObject*)self);
28+
}
29+
30+
static PyObject *unigine_Player_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
31+
// Unigine::Log::message("unigine_Player_new\n");
32+
unigine_Player *self;
33+
self = (unigine_Player *)type->tp_alloc(type, 0);
34+
self->unigine_object_ptr = nullptr;
35+
return (PyObject *)self;
36+
}
37+
38+
static int unigine_Player_init(unigine_Player *self, PyObject *args, PyObject *kwds) {
39+
return 0;
40+
}
41+
42+
// public (inherit from Node): getWorldPosition
43+
static PyObject * unigine_Player_get_world_position(unigine_Player* self) {
44+
PyErr_Clear();
45+
PyObject *ret = NULL;
46+
// parse args:
47+
48+
class LocalRunner : public Python3Runner {
49+
public:
50+
virtual void run() override {
51+
retOriginal = unigine_object_ptr->getWorldPosition();
52+
};
53+
Unigine::Ptr<Unigine::Player> unigine_object_ptr;
54+
// return
55+
Unigine::Math::Vec3 retOriginal;
56+
};
57+
auto *pRunner = new LocalRunner();
58+
pRunner->unigine_object_ptr = self->unigine_object_ptr;
59+
Python3Runner::runInMainThread(pRunner);
60+
while (!pRunner->mutexAsync.tryLock(5)) { // milliseconds
61+
}
62+
pRunner->mutexAsync.unlock();
63+
Unigine::Math::Vec3 retOriginal = pRunner->retOriginal;
64+
delete pRunner;
65+
Unigine::Math::vec3 *retOriginal2 = new Unigine::Math::vec3(retOriginal);
66+
ret = PyUnigine::vec3::NewObject(retOriginal2);
67+
68+
// end
69+
// return: Unigine::Math::Vec3
70+
return ret;
71+
};
72+
73+
static PyMethodDef unigine_Player_methods[] = {
74+
{
75+
"get_world_position", (PyCFunction)unigine_Player_get_world_position, METH_NOARGS,
76+
"public : getWorldPosition"
77+
},
78+
{NULL} /* Sentinel */
79+
};
80+
81+
static PyTypeObject unigine_PlayerType = {
82+
PyVarObject_HEAD_INIT(NULL, 0)
83+
"unigine.Player", // tp_name
84+
sizeof(unigine_Player) + 256, // tp_basicsize (TODO magic 256 bytes!!!)
85+
0, // tp_itemsize
86+
(destructor)unigine_Player_dealloc, // tp_dealloc
87+
0, // tp_vectorcall_offset
88+
0, // tp_getattr
89+
0, // tp_setattr
90+
0, // tp_as_async
91+
0, // tp_repr
92+
0, // tp_as_number
93+
0, // tp_as_sequence
94+
0, // tp_as_mapping
95+
0, // tp_hash
96+
0, // tp_call
97+
0, // tp_str
98+
0, // tp_getattro
99+
0, // tp_setattro
100+
0, // tp_as_buffer
101+
Py_TPFLAGS_DEFAULT, // tp_flags
102+
"Player Object", // tp_doc
103+
0, // traverseproc tp_traverse
104+
0, // inquiry tp_clear
105+
0, // richcmpfunc tp_richcompare
106+
0, // Py_ssize_t tp_weaklistoffset
107+
0, // getiterfunc tp_iter
108+
0, // iternextfunc tp_iternext
109+
unigine_Player_methods, // tp_methods
110+
0, // tp_members
111+
0, // tp_getset
112+
0, // tp_base
113+
0, // tp_dict
114+
0, // tp_descr_get
115+
0, // tp_descr_set
116+
0, // tp_dictoffset
117+
(initproc)unigine_Player_init, // tp_init
118+
0, // tp_alloc
119+
unigine_Player_new, // tp_new
120+
};
121+
122+
123+
// UniginePyTypeObjectPlayer
124+
125+
bool Python3UniginePlayer::isReady() {
126+
// Initialize tp_dict with empty dictionary
127+
if (!unigine_PlayerType.tp_dict) {
128+
unigine_PlayerType.tp_dict = PyDict_New();
129+
130+
}
131+
if (PyType_Ready(&unigine_PlayerType) < 0) {
132+
return false;
133+
}
134+
return true;
135+
}
136+
137+
bool Python3UniginePlayer::addClassDefinitionToModule(PyObject* pModule) {
138+
Py_INCREF(&unigine_PlayerType);
139+
if (PyModule_AddObject(pModule, "Player", (PyObject *)&unigine_PlayerType) < 0) {
140+
Py_DECREF(&unigine_PlayerType);
141+
return false;
142+
}
143+
return true;
144+
}
145+
146+
PyObject * Player::NewObject(Unigine::Ptr<Unigine::Player> unigine_object_ptr) {
147+
// std::cout << "sizeof(unigine_Player) = " << sizeof(unigine_Player) << std::endl;
148+
unigine_Player *pInst = PyObject_New(unigine_Player, &unigine_PlayerType);
149+
pInst->unigine_object_ptr = unigine_object_ptr;
150+
// Py_INCREF(pInst);
151+
return (PyObject *)pInst;
152+
}
153+
154+
Unigine::Ptr<Unigine::Player> Player::Convert(PyObject *pObject) {
155+
if (Py_IS_TYPE(pObject, &unigine_PlayerType) == 0) {
156+
Unigine::Log::error("Invalid type, expected 'Unigine::Ptr<Unigine::Player>', but got some another");
157+
}
158+
unigine_Player *pInst = (unigine_Player *)pObject;
159+
return pInst->unigine_object_ptr;
160+
}
161+
162+
}; // namespace PyUnigine

source/plugins/Sea5kg/Python3Scripting/src/python3_wrapper/pytypesobjects/python3_unigine_player.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Python3UniginePlayer : public Python3PyTypeObjectBase {
1414

1515
class Player {
1616
public:
17-
static PyObject * NewObject(Unigine::Player * unigine_object_ptr);
18-
static Unigine::Player * Convert(PyObject *pObject);
17+
static PyObject * NewObject(Unigine::Ptr<Unigine::Player> unigine_object_ptr);
18+
static Unigine::Ptr<Unigine::Player> Convert(PyObject *pObject);
1919
};
2020

2121
}; // namespace PyUnigine

0 commit comments

Comments
 (0)