WorldViz User Forum

WorldViz User Forum (
-   Plug-in development (
-   -   passing node3d to c++ (

jdoerr 04-23-2009 05:51 AM

passing node3d to c++

xabbu already asked to access the underlaying osg::Node of a node3d object. We own a vizard developer license and could use the modifier plugin, but we'll like to pass a node3d object to c++ using a .dll/.pyd file.
We're able to use PyArg_ParseTuple to parse the according PyObject*. We don't know the implementation of ob_type of node3d.
Is it possible to reach the pointer to the underlaying osg::Node?

Many Thanks for your advice

farshizzo 04-23-2009 03:16 PM

You cannot extract the underlying osg::Node object from the PyObject. You have to use a modifier plugin to get access to the osg::Node object. However, there is nothing stopping you from combining a modifier plugin and a python plugin into a single DLL. Here is the C++ code for a plugin that works both as a Python plugin and a modifier plugin:

#include "modifier.h"
#include "Python.h"

extern "C" __declspec(dllexport) void InitModifier(void *);
extern "C" __declspec(dllexport) void PerformModifier(void *);
extern "C" __declspec(dllexport) void TextureModifier(void *);
extern "C" __declspec(dllexport) void SceneModifier(void *);
extern "C" __declspec(dllexport) void CommandModifier(void *);
extern "C" __declspec(dllexport) void CloseModifier(void *);

void InitModifier(void *modifier)
        strcpy(((VizModifierObj*)modifier)->version,"Modifier Example v1.0");
        ((VizModifierObj*)modifier)->dataSize = 0;
        ((VizModifierObj*)modifier)->status = 1;

void PerformModifier(void *modifier)
        fprintf(stdout,"modifiying node\n");
        ((VizModifierObj*)modifier)->status = 1;

void TextureModifier(void *modifier)
        ((VizModifierObj*)modifier)->status = 1;

void SceneModifier(void *modifier)
        ((VizModifierObj*)modifier)->status = 1;

void CommandModifier(void *modifier)

void CloseModifier(void *modifier)

PyObject* py_do_something(PyObject *self, PyObject *args)
        fprintf(stdout,"doing something\n");

static PyMethodDef ModifierMethods[] = {
        {"do_something", py_do_something, METH_VARARGS},
        {NULL, NULL}

extern "C" __declspec(dllexport) void initmodifier()
        Py_InitModule("modifier", ModifierMethods);

You would then use the following code in your Vizard script to access the plugin:

import viz

#Treat DLL as Python module
import modifier

#Treat DLL as modifier plugin
mod = viz.addModifier('modifier.dll')
node = viz.add('gallery.ive')

All times are GMT -7. The time now is 03:04 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC