Hi OSG-Python users.

I' m interested in using OSG from Python or other scripted languages.
After some searching and testing I found osgswig and tried that path (still unsure which is the best script wrapper for OSG to use)

Using osgswig I found some bugs and added some nodes that were missing. (see patch attached), I noticed also that it needed some tweaking to adapt to new OSG release.

My questions:

1) opinions on which route to go for wrapping, (know there are wrappers based on introspection, I' ve tried to use them but found few examples) 2) In osgswig there is a working example of a python pick handler that subclass from osgGA.GUIEventHandler, I ve tried to subclass from osg.NodeVisitor without success.
   Is this something doable in osgswig or in other wrappers?
3) are there plans for supporting wrappers into core osg?
4) is osg-users the right place to write for issues regarding script language wrappers?


Thanks in advance

Luigi Calori


René Molenaar wrote:

Nice to hear!

I just merged the files and commited the new trunk.
Readme:
---------------------------------------------------------------------
Swig wrappers for OpenSceneGraph.

This is the new trunk of osgswig.

 http://osgswig.googlecode.com/svn/trunk
 or for members: https://osgswig.googlecode.com/svn/trunk

it is a merge of the original osgswig branch and
the branch used for the VRmeer Project (python and perl).

The merge contains new cmake files, that build the
following modules;

osg
osgDB
osgFX
osgGA
osgUtil
osgViewer

There is one (new) simple test example:
examples/python/simple/simpleosg

The default cmakesetting make these modules for python.

It is most recently tested with
swig 1.3.33
OpenSceneGraph 2.3.4

The merge also still contain all the files and documentation from the original osgswig.
Revision 95 of:
 http://osgswig.googlecode.com/svn/
 or https://osgswig.googlecode.com/svn/ (for members)
contains the original osgswig.
---------------------------------------------------------------------

I think the files in the root svn folder can be deleted now,
just leaving the trunk folder.

For installing the python modules a python setup.py can be made
(look for a setup.py template).

cmake can then invoke "python setup.py install" to place the files in the site-packages dir. This file can then also be used for creating binary distributions ("python setup.py bdist_wininst")

I did not look into the splitting the osg.i file,
maybe there is some swig function for this.

Maybe cmakefiles are needed for the other languages/modules.
If you have important fixes please tell.

Good luck,

René

2008/2/14, Luigi Calori <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>:

    Thank you very much... it worked!!

      either

    %inline %{
    osg::Geode *NodeToGeode2(osg::Node *b) {
       return dynamic_cast<osg::Geode*>(b);
    }
    %}

    or

    %extend osg::Node {
        virtual osg::Geode* asGeode() {return
    dynamic_cast<osg::Geode*>(self);}
    };

    The Cmake projects worked fine (just some mods to standard FindOSG), I
    spent some time to find out how to install correctly into
    site_packages
    If I' m correct, the dll must be renamed .pyd and the generated py
    must
    be copied inside the site_packages
    I noticed the compile time of the _osg project is quite slow (at least
    on my machine) do you think it would be possible to split the big osg
    wrapper into smaller pieces to
    both speed up build time and separate original (yours) and added
    (mine)

    Do you plan to insert your CMake files into the osgswig svn?
    Having things in svn will really help a lot the development
    I' m planning to experiment further and then try to  add site_packages
    installation to cmake if do not find a better way to work

    thanks again
                         Luigi

    René Molenaar wrote:

    > I read this in the swig manual:
    >
    > If you need to cast a pointer or change its value, consider writing
    > some helper functions instead.
    > see: http://www.swig.org/Doc1.3/Python.html
    >
    >%inline %{
    >
    >/* C++-style cast */
    >Foo *BarToFoo(Bar *b) {
    >   return dynamic_cast<Foo*>(b);
    >}
    >
    >%}
    >
    >
    >
    > You can also create the member function node.asGeode() in a similar
    > way with swig. This is a safe and handy method. There might be other
    > options... this way you would need to use swig, and can't use the
    > binary version.
    >
    > René
    >
    >
    >

    > 2008/2/13, Luigi Calori <[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]> <mailto:[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>>>:

    >
    >     René Molenaar wrote:
    >
    >     > Swig wrappers for OpenSceneGraph Python and Perl
    >     >
    >     > These files are part of: The VRmeer Library - Delft
    University of
    >     > Technology
    >     >
    >     > The files are based on osgswig
    (http://code.google.com/p/osgswig/)
    >     > with some additions and CMake files.
    >     >
    >     Thanks for the post, I' ll try them as soon as possible, I' m
    >     currently
    >     try to learn python and osgswig using the binary version under
    >     windows XP
    >     I stumbled upon a problem:
    >
    >     I would like to parse the one scene, so willing to
    use  something
    >     like:
    >
    >
    >     node = osgDB.readNodeFile('cow.osg')
    >
    >     while node.className() == 'Group':
    >         print node.className()
    >         node = node.asGroup().getChild(0)
    >     print node.className()
    >
    >     The problem arise when getChild() returns a Geode.
    >     There is no  --- node.asGeode() ---- method so I have no idea of
    >     how to
    >     get the handle of a Geode in the scene.
    >
    >     Sorry for my dumbness, any help really appreciated,
    >
    >     Luigi
    >     _______________________________________________
    >     osg-users mailing list
    >     [email protected]
    <mailto:[email protected]>

    >     <mailto:[email protected]
    <mailto:[email protected]>>

> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
    >
    >

    >------------------------------------------------------------------------

    >
    >_______________________________________________
    >osg-users mailing list
    >[email protected]
    <mailto:[email protected]>
    >http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
    >
    >

    _______________________________________________
    osg-users mailing list
    [email protected]
    <mailto:[email protected]>
    http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------------------------------------------------------------

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Index: CMakeModules/FindOSG.cmake
===================================================================
--- CMakeModules/FindOSG.cmake  (revision 109)
+++ CMakeModules/FindOSG.cmake  (working copy)
@@ -1,16 +1,17 @@
 # Locate gdal
 # This module defines
 # OSG_LIBRARY
-# OSG_FOUND, if false, do not try to link to osg 
+# OSG_FOUND, if false, do not try to link to gdal 
 # OSG_INCLUDE_DIR, where to find the headers
 #
 # $OSG_DIR is an environment variable that would
 # correspond to the ./configure --prefix=$OSG_DIR
 #
 # Created by Robert Osfield. 
-# Edited By R.C.Molenaar to include debug versions
+SET(OSG_DIR "" CACHE PATH "set to base osg install path")
 
 FIND_PATH(OSG_INCLUDE_DIR osg/Node
+    ${OSG_DIR}/include
     $ENV{OSG_DIR}/include
     $ENV{OSG_DIR}
     $ENV{OSGDIR}/include
@@ -24,38 +25,40 @@
     /opt/local/include # DarwinPorts
     /opt/csw/include # Blastwave
     /opt/include
-    /cygdrive/c/Program Files/OpenSceneGraph/include
     [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ 
Manager\\Environment;OSG_ROOT]/include
     /usr/freeware/include
 )
-
 MACRO(FIND_OSG_LIBRARY MYLIBRARY MYLIBRARYNAME)
 
-    FIND_LIBRARY(${MYLIBRARY}
-        NAMES ${MYLIBRARYNAME}
+    FIND_LIBRARY("${MYLIBRARY}_DEBUG"
+        NAMES "${MYLIBRARYNAME}d"
         PATHS
+        ${OSG_DIR}/lib/Debug
+        ${OSG_DIR}/lib
+        $ENV{OSG_DIR}/lib/debug
         $ENV{OSG_DIR}/lib
-        $ENV{OSG_DIR}/bin
         $ENV{OSG_DIR}
         $ENV{OSGDIR}/lib
         $ENV{OSGDIR}
         $ENV{OSG_ROOT}/lib
         ~/Library/Frameworks
         /Library/Frameworks
+        /usr/local/lib
+        /usr/lib
         /sw/lib
         /opt/local/lib
         /opt/csw/lib
         /opt/lib
-        /cygdrive/c/Program\ Files/OpenSceneGraph/lib
-        /cygdrive/c/Program\ Files/OpenSceneGraph/bin
-        /cygdrive/c/Projects/OpenSceneGraph/Build/lib/release
         [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ 
Manager\\Environment;OSG_ROOT]/lib
         /usr/freeware/lib64
     )
 
-    FIND_LIBRARY(${MYLIBRARY}_DEBUG
-        NAMES ${MYLIBRARYNAME}d
+    FIND_LIBRARY(${MYLIBRARY}
+        NAMES ${MYLIBRARYNAME}
         PATHS
+        ${OSG_DIR}/lib/Release
+        ${OSG_DIR}/lib
+        $ENV{OSG_DIR}/lib/Release
         $ENV{OSG_DIR}/lib
         $ENV{OSG_DIR}
         $ENV{OSGDIR}/lib
@@ -63,46 +66,84 @@
         $ENV{OSG_ROOT}/lib
         ~/Library/Frameworks
         /Library/Frameworks
+        /usr/local/lib
+        /usr/lib
         /sw/lib
         /opt/local/lib
         /opt/csw/lib
         /opt/lib
-        /cygdrive/c/Program\ Files/OpenSceneGraph/lib
-        /cygdrive/c/Program\ Files/OpenSceneGraph/bin
-        /cygdrive/c/Projects/OpenSceneGraph/Build/lib/release
         [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ 
Manager\\Environment;OSG_ROOT]/lib
         /usr/freeware/lib64
     )
+#    MESSAGE("-->${${MYLIBRARY}}<-->${${MYLIBRARY}_DEBUG}<--")
+    IF( NOT ${MYLIBRARY}_DEBUG)
+       IF(${MYLIBRARY})
+               SET(${MYLIBRARY}_DEBUG ${${MYLIBRARY}})
+       ENDIF(${MYLIBRARY})
+    ENDIF( NOT ${MYLIBRARY}_DEBUG)
+    IF( NOT ${MYLIBRARY})
+#    MESSAGE("d1-->${${MYLIBRARY}}<-->${${MYLIBRARY}_DEBUG}<--")
+       IF(${MYLIBRARY}_DEBUG)
+#    MESSAGE("d2-->${${MYLIBRARY}}<-->${${MYLIBRARY}_DEBUG}<--")
+               SET(${MYLIBRARY} ${${MYLIBRARY}_DEBUG})
+       ENDIF(${MYLIBRARY}_DEBUG)
+    ENDIF( NOT ${MYLIBRARY})
+#    MESSAGE("d3-->${${MYLIBRARY}}<-->${${MYLIBRARY}_DEBUG}<--")
+#              IF(${MYLIBRARY})
+#      IF(${MYLIBRARY}_DEBUG)
+#                              SET( "${MYLIBRARYNAME}" "optimized 
${${MYLIBRARY}} debug ${${MYLIBRARY}_DEBUG}" )
+#      ELSE (${MYLIBRARY}_DEBUG)
+#                              SET( "${MYLIBRARYNAME}" ${${MYLIBRARY}} )
+#      ENDIF(${MYLIBRARY}_DEBUG)
+#              ENDIF(${MYLIBRARY})
+               MARK_AS_ADVANCED(${MYLIBRARY} ${MYLIBRARY}_DEBUG)               
+ENDMACRO(FIND_OSG_LIBRARY LIBRARY LIBRARYNAME)
 
-   IF  (NOT ${MYLIBRARY})
-       MESSAGE("-- Warning ${MYLIBRARYNAME} not found, ${MYLIBRARY} tring to 
use: ${MYLIBRARY}_DEBUG")
-   ENDIF  (NOT ${MYLIBRARY})
+FIND_OSG_LIBRARY(OSG_LIBRARY osg)
+FIND_OSG_LIBRARY(OSGUTIL_LIBRARY osgUtil)
+FIND_OSG_LIBRARY(OSGDB_LIBRARY osgDB)
+FIND_OSG_LIBRARY(OSGGA_LIBRARY osgGA)
+FIND_OSG_LIBRARY(OSGTEXT_LIBRARY osgText)
+FIND_OSG_LIBRARY(OSGTERRAIN_LIBRARY osgTerrain)
+FIND_OSG_LIBRARY(OSGFX_LIBRARY osgFX)
+FIND_OSG_LIBRARY(OSGSIM_LIBRARY osgSim)
+FIND_OSG_LIBRARY(OSGMANIPULATOR_LIBRARY osgManipulator)
+FIND_OSG_LIBRARY(OSGVIEWER_LIBRARY osgViewer)
+FIND_OSG_LIBRARY(OSGINTROSPECTION_LIBRARY osgIntrospection)
+FIND_OSG_LIBRARY(OPENTHREADS_LIBRARY OpenThreads)
 
+#GET_FILENAME_COMPONENT(tmp ${OSG_LIBRARY} PATH)
+#GET_FILENAME_COMPONENT(tmp ${tmp} PATH)
 
-    IF(${MYLIBRARY}_DEBUG)
-        IF   (NOT ${MYLIBRARY})
-            MESSAGE("-- Warning ${MYLIBRARYNAME} not found, ${MYLIBRARY} 
using: ${${MYLIBRARY}_DEBUG}")
-            SET(${MYLIBRARY} "${${MYLIBRARY}_DEBUG}" CACHE FILEPATH "Release 
version of OpenSceneGraph ${MYLIBRARYNAME} Library (use debug version if not 
available)" FORCE)
-        ENDIF(NOT ${MYLIBRARY})
-    ENDIF(${MYLIBRARY}_DEBUG)    
+#IF(EXISTS ${tmp}/bin
+FIND_PATH(OSG_BIN_DIR 
+               NAMES 
+#              "osg${CMAKE_SHARED_LIBRARY_SUFFIX}"
+#              "osgd${CMAKE_SHARED_LIBRARY_SUFFIX}"
+               "osgVersion${CMAKE_EXECUTABLE_SUFFIX}" 
+               "osgVersiond${CMAKE_EXECUTABLE_SUFFIX}" 
+               PATHS
+    ${OSG_DIR}/bin
+    $ENV{OSG_DIR}/bin
+    $ENV{OSG_DIR}
+    $ENV{OSGDIR}/bin
+    $ENV{OSGDIR}
+    $ENV{OSG_ROOT}/bin
+    ~/Library/Frameworks
+    /Library/Frameworks
+    /usr/local/bin
+    /usr/bin
+    /sw/bin # Fink
+    /opt/local/bin # DarwinPorts
+    /opt/csw/bin # Blastwave
+    /opt/bin
+    [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ 
Manager\\Environment;OSG_ROOT]/bin
+    /usr/freeware/bin
+)
+MARK_AS_ADVANCED(OSG_INCLUDE_DIR OSG_BIN_DIR)
 
-    IF(${MYLIBRARY})
-        IF   (NOT ${MYLIBRARY}_DEBUG)
-            MESSAGE("-- Warning Debug ${MYLIBRARYNAME} not found, 
${MYLIBRARY}_DEBUG using: ${MYLIBRARY}")
-            #SET(OSG_LIBRARY_DEBUG "${OSG_LIBRARY}")
-            SET(${MYLIBRARY}_DEBUG "${${MYLIBRARY}}" CACHE FILEPATH "Debug 
version of OpenSceneGraph ${MYLIBRARYNAME} Library (use regular version if not 
available)" FORCE)
-        ENDIF(NOT ${MYLIBRARY}_DEBUG)
-    ENDIF(${MYLIBRARY})
 
-
-ENDMACRO(FIND_OSG_LIBRARY MYLIBRARY MYLIBRARYNAME)
-
-FOREACH(MYOSGLIBRARY osg osgUtil osgDB osgText osgTerrain osgFX osgViewer 
osgGA osgSim osgShadow osgManipulator osgParticle )
-    STRING(TOUPPER ${MYOSGLIBRARY} MYOSGUPPER )
-    FIND_OSG_LIBRARY( ${MYOSGUPPER}_LIBRARY ${MYOSGLIBRARY}) 
-ENDFOREACH(MYOSGLIBRARY)
- 
 SET(OSG_FOUND "NO")
-IF(OSG_LIBRARY AND OSG_INCLUDE_DIR)
+IF(OSG_LIBRARY AND OSG_INCLUDE_DIR AND OSG_BIN_DIR)
     SET(OSG_FOUND "YES")
-ENDIF(OSG_LIBRARY AND OSG_INCLUDE_DIR)
+ENDIF(OSG_LIBRARY AND OSG_INCLUDE_DIR AND OSG_BIN_DIR)
Index: src/osg.i
===================================================================
--- src/osg.i   (revision 109)
+++ src/osg.i   (working copy)
@@ -40,6 +40,9 @@
 typedef unsigned int GLuint;
 typedef float GL_FLOAT;
 typedef double GL_DOUBLE;
+typedef int GLsizei;
+typedef int GLint;
+typedef unsigned char GLboolean;
 #endif
 
 %{
@@ -64,6 +67,9 @@
 #include <osg/Node>
 #include <osg/Group>
 #include <osg/Switch>
+#include <osg/LOD>
+#include <osg/PagedLOD>
+#include <osg/ProxyNode>
 #include <osg/MatrixTransform>
 #include <osg/Projection>
 #include <osg/CullSettings>
@@ -306,6 +312,12 @@
 %ignore osg::Camera::getPostDrawCallback;
 %ignore osg::Camera::setPreDrawCallback;
 %ignore osg::Camera::getPreDrawCallback;
+%ignore osg::Camera::getInitialDrawCallback;
+%ignore osg::Camera::setInitialDrawCallback;
+%ignore osg::Camera::getIntialDrawCallback;
+%ignore osg::Camera::setIntialDrawCallback;
+%ignore osg::Camera::getFinalDrawCallback;
+%ignore osg::Camera::setFinalDrawCallback;
 %ignore osg::CameraNode::Attachment;
 %ignore osg::CameraNode::BufferAttachmentMap;
 
@@ -539,7 +551,7 @@
 %template(vectorVec3) std::vector<osg::Vec3f>;
 %template(vectorVec4) std::vector<osg::Vec4f>;
 %template(vectorUInt) std::vector<GLuint>;
-%template(Vec2Array) 
osg::TemplateArray<osg::Vec2f,osg::Array::Vec3ArrayType,2,0x1406>;
+%template(Vec2Array) 
osg::TemplateArray<osg::Vec2f,osg::Array::Vec2ArrayType,2,0x1406>;
 %template(Vec3Array) 
osg::TemplateArray<osg::Vec3f,osg::Array::Vec3ArrayType,3,0x1406>;
 %template(Vec4Array) 
osg::TemplateArray<osg::Vec4f,osg::Array::Vec4ArrayType,4,0x1406>;
 %template(UIntArray) 
osg::TemplateIndexArray<GLuint,osg::Array::UIntArrayType,1,0x1405>;
@@ -556,6 +568,9 @@
 %include osg/Billboard
 %include osg/Group
 %include osg/Switch
+%include osg/LOD
+%include osg/PagedLOD
+%include osg/ProxyNode
 %include osg/NodeVisitor
 %include osg/Projection
 %include osg/Transform
@@ -602,6 +617,9 @@
 %template(GeodeRef) osg::ref_ptr<osg::Geode>;
 %template(BillboardRef) osg::ref_ptr<osg::Billboard>;
 %template(SwitchRef) osg::ref_ptr<osg::Switch>;
+%template(LODRef) osg::ref_ptr<osg::LOD>;
+%template(PagedLODRef) osg::ref_ptr<osg::PagedLOD>;
+%template(ProxyNodeRef) osg::ref_ptr<osg::ProxyNode>;
 %template(ProjectionRef) osg::ref_ptr<osg::Projection>;
 %template(LightRef) osg::ref_ptr<osg::Light>;
 %template(MatrixTransformRef) osg::ref_ptr<osg::MatrixTransform>;
@@ -651,4 +669,10 @@
 osg::MatrixTransform *NodeToMatrixTransform(osg::Node *b) {
   return dynamic_cast<osg::MatrixTransform*>(b);
 }
+%}
+
+%inline %{
+osg::Texture *StateAttributeToTexture(osg::StateAttribute *b) {
+  return dynamic_cast<osg::Texture*>(b);
+}
 %}
\ No newline at end of file
Index: src/osgText.i
===================================================================
--- src/osgText.i       (revision 109)
+++ src/osgText.i       (working copy)
@@ -22,11 +22,13 @@
 %{
 
 #include <osgText/Export>
+#include <osgText/TextBase>
 #include <osgText/FadeText>
 #include <osgText/Font>
 #include <osgText/String>
 #include <osgText/Text>
 #include <osgText/Version>
+#include <osgText/KerningType>
 
 
 // using namespace osg;
@@ -45,6 +47,8 @@
 
 %ignore osgText::Text::getGlyphQuads;
 %ignore osgText::Text::getTextureGlyphQuadMap;
+%ignore osgText::Font::getKerning;
+%ignore osgText::Font::getGlyph;
 
 /* include the actual headers */
 
@@ -56,4 +60,3 @@
 %include osgText/Version
 
 
-
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to