PyObject* VRPyTransform::animate(VRPyTransform* self, PyObject *args) { VRPyPath* path; float t; float o; int b; int l = 0; if (pySize(args) == 4) if (! PyArg_ParseTuple(args, "Offi", &path, &t, &o, &b)) return NULL; if (pySize(args) == 5) if (! PyArg_ParseTuple(args, "Offii", &path, &t, &o, &b, &l)) return NULL; if (self->obj == 0) { PyErr_SetString(err, "VRPyTransform::animate: C Object is invalid"); return NULL; } self->obj->startPathAnimation(path->obj, t, o, b, l); Py_RETURN_TRUE; }
PyObject* VRPyTransform::animate(VRPyTransform* self, PyObject *args) { if (!self->valid()) return NULL; VRPyPath* path = 0; float t; float o; int b; int l = 0; if (pySize(args) == 4) if (! PyArg_ParseTuple(args, "Offi", &path, &t, &o, &b)) return NULL; if (pySize(args) == 5) if (! PyArg_ParseTuple(args, "Offii", &path, &t, &o, &b, &l)) return NULL; if (path == 0) { PyErr_SetString(err, "VRPyTransform::animate: path is invalid"); return NULL; } auto anim = self->objPtr->startPathAnimation(path->obj, t, o, b, l); return VRPyAnimation::fromPtr(anim); }
OSG::Vec3i VRPyBase::parseVec3i(PyObject *args) { if (pySize(args) == 1) return parseVec3iList( parseObject(args) ); int x,y,z; x=y=z=0; if (! PyArg_ParseTuple(args, "iii", &x, &y, &z)) return OSG::Vec3i(); return OSG::Vec3i(x,y,z); }
OSG::Vec4d VRPyBase::parseVec4d(PyObject *args) { if (pySize(args) == 1) return parseVec4dList( parseObject(args) ); float x,y,z,w; x=y=z=w=0; if (! PyArg_ParseTuple(args, "ffff", &x, &y, &z, &w)) return OSG::Vec4d(); return OSG::Vec4d(x,y,z,w); }
OSG::Vec2d VRPyBase::parseVec2f(PyObject *args) { if (pySize(args) == 1) return parseVec2dList( parseObject(args) ); float x,y; x=y=0; if (! PyArg_ParseTuple(args, "ff", &x, &y)) return OSG::Vec2d(); return OSG::Vec2d(x,y); }
PyObject* VRPyAnimation::start(VRPyAnimation* self, PyObject* args) { if (self->obj == 0) { PyErr_SetString(err, "VRPyAnimation::start - Object is invalid"); return NULL; } float offset = 0; if (pySize(args) == 1) offset = parseFloat(args); self->obj->start(offset); Py_RETURN_TRUE; }
PyObject* VRPyPathtool::clear(VRPyPathtool* self, PyObject* args) { if (self->obj == 0) { PyErr_SetString(err, "VRPyPathtool::clear - Object is invalid"); return NULL; } VRPyPath* p = 0; if (pySize(args) == 1) if (! PyArg_ParseTuple(args, "O", &p)) return NULL; OSG::path* pa = 0; if (p) pa = p->obj; self->obj->clear(pa); Py_RETURN_TRUE; }
PyObject* VRPyPathtool::newPath(VRPyPathtool* self, PyObject* args) { if (self->obj == 0) { PyErr_SetString(err, "VRPyPathtool::newPath - Object is invalid"); return NULL; } VRPyDevice* dev; VRPyObject* obj; int res = 10; if (pySize(args) == 2) { if (! PyArg_ParseTuple(args, "OO", &dev, &obj)) return NULL; } else if (! PyArg_ParseTuple(args, "OOi", &dev, &obj, &res)) return NULL; OSG::VRDevice* d = 0; if (!isNone((PyObject*)dev)) d = dev->obj; OSG::path* p = self->obj->newPath( d, obj->obj, res ); return VRPyPath::fromPtr(p); }
PyObject* VRPyMaterial::setTexture(VRPyMaterial* self, PyObject* args) { if (self->objPtr == 0) { PyErr_SetString(err, "VRPyMaterial::setTexture, C obj is invalid"); return NULL; } int aN = pySize(args); if (aN == 1) { PyObject* o = parseObject(args); if (PyString_Check(o)) self->objPtr->setTexture( PyString_AsString(o) ); // load a file else if (VRPyImage::check(o)) { VRPyImage* img = (VRPyImage*)o; self->objPtr->setTexture( img->objPtr, 0 ); } } if (aN > 1) { PyObject *data, *dims; int doFl; if (! PyArg_ParseTuple(args, "OOi", &data, &dims, &doFl)) return NULL; if (pySize(data) == 0) Py_RETURN_TRUE; vector<PyObject*> _data = pyListToVector(data); int dN = _data.size(); int vN = pySize(_data[0]); if (doFl) { vector<float> buf(vN*dN, 0); for (int i=0; i<dN; i++) { PyObject* dObj = _data[i]; vector<PyObject*> vec = pyListToVector(dObj); for (int j=0; j<vN; j++) buf[i*vN+j] = PyFloat_AsDouble(vec[j]); } self->objPtr->setTexture( (char*)&buf[0], vN, parseVec3iList(dims), true ); } else { vector<char> buf(vN*dN, 0); for (int i=0; i<dN; i++) { vector<PyObject*> vec = pyListToVector(_data[i]); for (int j=0; j<vN; j++) buf[i*vN+j] = PyInt_AsLong(vec[j]); } self->objPtr->setTexture( &buf[0], vN, parseVec3iList(dims), false ); } } Py_RETURN_TRUE; }
PyObject* VRPyCSG::markEdges(VRPyCSG* self, PyObject* args) { if (self->objPtr == 0) { PyErr_SetString(err, "VRPyCSG::markEdges, Object is invalid"); return NULL; } PyObject* vec; if (! PyArg_ParseTuple(args, "O", &vec)) return NULL; if (pySize(vec) == 0) Py_RETURN_TRUE; vector<OSG::Vec2i> edges; pyListToVector<vector<OSG::Vec2i>, OSG::Vec2i>(vec, edges); self->objPtr->markEdges(edges); Py_RETURN_TRUE; }
PyObject* VRPyTransform::setPose(VRPyTransform* self, PyObject* args) { if (!self->valid()) return NULL; if (pySize(args) == 1) { VRPyPose* p; if (! PyArg_ParseTuple(args, "O", &p)) return NULL; if (p->objPtr) self->objPtr->setPose( *p->objPtr ); Py_RETURN_TRUE; } PyObject *fl, *dl, *ul; if (! PyArg_ParseTuple(args, "OOO", &fl, &dl, &ul)) return NULL; self->objPtr->setPose( parseVec3fList(fl), parseVec3fList(dl), parseVec3fList(ul)); Py_RETURN_TRUE; }
PyObject* VRPyPathtool::getHandles(VRPyPathtool* self, PyObject* args) { if (self->obj == 0) { PyErr_SetString(err, "VRPyPathtool::getHandles - Object is invalid"); return NULL; } VRPyPath* p = 0; if (pySize(args) == 1) if (! PyArg_ParseTuple(args, "O", &p)) return NULL; OSG::path* pa = 0; if (p) pa = p->obj; vector<OSG::VRGeometry*> objs = self->obj->getHandles(pa); PyObject* li = PyList_New(objs.size()); for (uint i=0; i<objs.size(); i++) { PyList_SetItem(li, i, VRPyGeometry::fromPtr(objs[i])); } return li; }
PyObject* VRPyBase::getItem(PyObject* v, int i) { if (i < 0 || i >= pySize(v)) return 0; if (isList(v)) return PyList_GetItem(v,i); if (isTuple(v)) return PyTuple_GetItem(v,i); return 0; }
vector<PyObject*> VRPyBase::pyListToVector(PyObject *v) { vector<PyObject*> res; if(isList(v)) for (int i=0; i<pySize(v); i++) res.push_back(PyList_GetItem(v, i)); if(isTuple(v)) for (int i=0; i<pySize(v); i++) res.push_back(PyTuple_GetItem(v, i)); return res; }