WorldViz User Forum  

Go Back   WorldViz User Forum > Plug-in development

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 04-23-2009, 03:16 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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:
Code:
#include "modifier.h"
#include "Python.h"

// DO NOT MODIFY THESE DECLARATIONS----------------
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");
	Py_RETURN_NONE;
}

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:
Code:
import viz
viz.go()

#Treat DLL as Python module
import modifier
modifier.do_something()

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


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Inheritence with node3d dan12345 Vizard 1 05-23-2008 06:14 PM
Passing sensor data to C++ GUI vizmaster Vizard 2 10-05-2006 11:37 AM
passing data to viz.director vadrian Vizard 1 05-18-2005 03:30 PM
Passing arguments to vizard script hotspur1 Vizard 7 05-02-2003 02:03 PM


All times are GMT -7. The time now is 02:18 AM.


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