// Copyright (C) 2002-2003 Gideon May (gideon@computer.org) // // Permission to copy, use, sell and distribute this software is granted // provided this copyright notice appears in all copies. // Permission to modify the code and to distribute modified code is granted // provided this copyright notice appears in all copies, and a notice // that the code was modified is included with the copyright notice. // // This software is provided "as is" without express or implied warranty, // and with no claim as to its suitability for any purpose. bah! #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "held_ptr.hpp" #include "Math.hpp" #include "Math_NumArray.hpp" #include "Drawable.hpp" using namespace boost::python; using namespace PyOSG; namespace { class Geometry : public osg::Geometry { public: Geometry(PyObject * p) : osg::Geometry(), _self(p) { std::cerr << "Creating Geometry, self : " << _self << std::endl; std::cerr << "refcount = " << _self->ob_refcnt << std::endl; Py_XINCREF(_self); } ~Geometry() { std::cerr << "Deleting Geometry, self : " << _self << std::endl; std::cerr << "refcount = " << _self->ob_refcnt << std::endl; Py_XDECREF(_self); } PyObject* self() { std::cerr << "Geometry, Returning self : " << _self << std::endl; std::cerr << "refcount = " << _self->ob_refcnt << std::endl; Py_XINCREF(_self); return _self; } private: PyObject * _self; }; void osgGeometry_setVertexArray(osg::Geometry * self, object vertices) { if (check_numarray(vertices)) { const numeric::array& tvert = extract(vertices); osg::ref_ptr array = PyOSG::toNumArray(tvert); if (array.valid()) { self->setVertexArray(array.get()); return; } } else if (check_tuple(vertices)) { const tuple& tvert = extract(vertices); osg::ref_ptr array = PyOSG::toArray(tvert); if (array.valid()) { self->setVertexArray(array.get()); return; } } else if (check_Vec3Array(vertices)) { self->setVertexArray(extract(vertices)); return; } // fall through on error, bad match PyErr_SetString(PyExc_ValueError, "Unexpected argument in setVertexArray, expected numeric or Vec3Array"); throw_error_already_set(); } void osgGeometry_setNormalArray(osg::Geometry * self, object normals) { if (check_numarray(normals)) { const numeric::array& tnormals = extract(normals); osg::ref_ptr array = PyOSG::toNumArray(tnormals); if (array.valid()) { osg::Vec3Array * coords = dynamic_cast (array.get()); self->setNormalArray(coords); return; } } else if (check_tuple(normals)) { const tuple& tnormals = extract(normals); osg::ref_ptr array = PyOSG::toArray(tnormals); if (array.valid()) { osg::Vec3Array * coords = dynamic_cast (array.get()); self->setNormalArray(coords); return; } } else if (check_Vec3Array(normals)) { self->setNormalArray(extract(normals)); return; } // fall through on error, bad match PyErr_SetString(PyExc_ValueError, "Unexpected argument in setNormalArray, expected numeric or Vec3Array"); throw_error_already_set(); } void osgGeometry_setColorArray(osg::Geometry * self, object colors) { if (check_numarray(colors)) { const numeric::array& tcol = extract(colors); osg::ref_ptr array = PyOSG::toNumArray(tcol); if (array.valid()) { self->setColorArray(array.get()); return; } } else if (check_tuple(colors)) { const tuple& tcol = extract(colors); osg::ref_ptr array = PyOSG::toArray(tcol); if (array.valid()) { self->setColorArray(array.get()); return; } } else if (check_Array(colors)) { self->setColorArray(extract(colors)); return; } // fall through on error, bad match PyErr_SetString(PyExc_ValueError, "Unexpected argument in setColorArray, expected numeric or Array"); throw_error_already_set(); } void osgGeometry_setTexCoordArray(osg::Geometry * self, int idx, object texcoords) { if (check_numarray(texcoords)) { const numeric::array& ttex = extract(texcoords); osg::ref_ptr array = PyOSG::toNumArray(ttex); if (array.valid()) { self->setTexCoordArray(idx, array.get()); return; } } else if (check_tuple(texcoords)) { const tuple& ttex = extract(texcoords); osg::ref_ptr array = PyOSG::toArray(ttex); if (array.valid()) { self->setTexCoordArray(idx, array.get()); return; } } else if (check_Array(texcoords)) { self->setTexCoordArray(idx, extract(texcoords)); return; } // fall through on error, bad match PyErr_SetString(PyExc_ValueError, "Unexpected argument in setTexCoordArray, expected numeric or Array"); throw_error_already_set(); } osg::Geometry * asGeometry(osg::Drawable * self) { return dynamic_cast(self); } } // namespace namespace PyOSG { void init_Geometry() { register_castDrawable("asGeometry", &asGeometry); { class_, bases > geometry("Geometry", no_init); scope geometry_scope(geometry); geometry .def(init<>()) .def("setVertexArray", &osgGeometry_setVertexArray) // accepts a numeric as array .def("getVertexArray", (osg::Array *(osg::Geometry::*)()) &osg::Geometry::getVertexArray, return_value_policy()) .def("setVertexIndices", &osg::Geometry::setVertexIndices) .def("getVertexIndices", (osg::IndexArray *(osg::Geometry::*)())&osg::Geometry::getVertexIndices, return_value_policy()) .def("setNormalBinding", &osg::Geometry::setNormalBinding) .def("getNormalBinding", &osg::Geometry::getNormalBinding) .def("setNormalArray", &osgGeometry_setNormalArray) // accepts a numeric as array .def("getNormalArray", (osg::Array *(osg::Geometry::*)()) &osg::Geometry::getNormalArray, return_value_policy()) .def("setNormalIndices", &osg::Geometry::setNormalIndices) .def("getNormalIndices", (osg::IndexArray *(osg::Geometry::*)()) &osg::Geometry::getNormalIndices, return_value_policy()) .def("setColorBinding", &osg::Geometry::setColorBinding) .def("getColorBinding", &osg::Geometry::getColorBinding) .def("setColorArray", &osgGeometry_setColorArray) // accepts a numeric as array .def("getColorArray", (osg::Array *(osg::Geometry::*)()) &osg::Geometry::getColorArray, return_value_policy()) .def("setColorIndices", &osg::Geometry::setColorIndices) .def("getColorIndices", (osg::IndexArray *(osg::Geometry::*)())&osg::Geometry::getColorIndices, return_value_policy()) .def("setSecondaryColorBinding", &osg::Geometry::setSecondaryColorBinding) .def("getSecondaryColorBinding", &osg::Geometry::getSecondaryColorBinding) .def("setSecondaryColorArray", &osg::Geometry::setSecondaryColorArray) .def("getSecondaryColorArray", (osg::Array *(osg::Geometry::*)()) &osg::Geometry::getSecondaryColorArray, return_value_policy()) .def("setSecondaryColorIndices", &osg::Geometry::setSecondaryColorIndices) .def("getSecondaryColorIndices", (osg::IndexArray *(osg::Geometry::*)()) &osg::Geometry::getSecondaryColorIndices, return_value_policy()) .def("setFogCoordBinding", &osg::Geometry::setFogCoordBinding) .def("getFogCoordBinding", &osg::Geometry::getFogCoordBinding) .def("setFogCoordArray", &osg::Geometry::setFogCoordArray) .def("getFogCoordArray", (osg::Array *(osg::Geometry::*)()) &osg::Geometry::getFogCoordArray, return_value_policy()) .def("setFogCoordIndices", &osg::Geometry::setFogCoordIndices) .def("getFogCoordIndices", (osg::IndexArray *(osg::Geometry::*)()) &osg::Geometry::getFogCoordIndices, return_value_policy()) .def("setTexCoordArray", &osgGeometry_setTexCoordArray) // accepts a numeric as array .def("getTexCoordArray", (osg::Array *(osg::Geometry::*)(unsigned int)) &osg::Geometry::getTexCoordArray, return_value_policy()) .def("setTexCoordIndices", &osg::Geometry::setTexCoordIndices) .def("getTexCoordIndices", (osg::IndexArray *(osg::Geometry::*)(unsigned int))&osg::Geometry::getTexCoordIndices, return_value_policy()) .def("getNumTexCoordArrays", &osg::Geometry::getNumTexCoordArrays) // getTexCoordArrayList // setPrimitiveSetList // getPrimitiveSetList .def("getNumPrimitiveSets", &osg::Geometry::getNumPrimitiveSets) .def("getPrimitiveSet", (osg::PrimitiveSet *(osg::Geometry::*)(unsigned int))&osg::Geometry::getPrimitiveSet, return_value_policy()) .def("addPrimitiveSet", &osg::Geometry::addPrimitiveSet) .def("setPrimitiveSet", &osg::Geometry::setPrimitiveSet) .def("insertPrimitiveSet", &osg::Geometry::insertPrimitiveSet) .def("removePrimitiveSet", &osg::Geometry::removePrimitiveSet) .def("getPrimitiveSetIndex", &osg::Geometry::getPrimitiveSetIndex) .def("setFastPathHint", &osg::Geometry::setFastPathHint) .def("getFastPathHint", &osg::Geometry::getFastPathHint) .def("areFastPathsUsed", &osg::Geometry::areFastPathsUsed) .def("computeFastPathsUsed", &osg::Geometry::computeFastPathsUsed) .def("verifyBindings", (bool(osg::Geometry::*)()const) &osg::Geometry::verifyBindings) .def("computeCorrectBindingsAndArraySizes", (void(osg::Geometry::*)()) &osg::Geometry::computeCorrectBindingsAndArraySizes) ; # define OSG_ENUM_BINDING(VALUE) \ (binding.value(#VALUE, osg::Geometry::VALUE), \ geometry.def(#VALUE, object(osg::Geometry::VALUE))) enum_ binding("AttributeBinding"); OSG_ENUM_BINDING(BIND_OFF); OSG_ENUM_BINDING(BIND_OVERALL); OSG_ENUM_BINDING(BIND_PER_PRIMITIVE_SET); OSG_ENUM_BINDING(BIND_PER_PRIMITIVE); OSG_ENUM_BINDING(BIND_PER_VERTEX); } { class_, bases, boost::noncopyable> geometry("Geometry_base", no_init); geometry .def(init<>()) .def("self", &Geometry::self) ; } /** Convenience function to be used for creating quad geometry with texture coords. * Tex coords go from left bottom (l,b) to right top (r,t). */ def("createTexturedQuadGeometry", (osg::Geometry *(*)(const osg::Vec3&,const osg::Vec3&,const osg::Vec3&, float, float, float, float)) &osg::createTexturedQuadGeometry, return_value_policy()); /** Convenience function to be used for creating quad geometry with texture coords. * Tex coords go from bottom left (0,0) to top right (s,t). */ def("createTexturedQuadGeometry", (osg::Geometry *(*)(const osg::Vec3&,const osg::Vec3&,const osg::Vec3&, float, float)) &osg::createTexturedQuadGeometry, return_value_policy()); } } // namespace PyOSG