[Solved] Passing a Vec3 from python to c++

I just wrote my first c++ extension for my app … it is working fine, but I can’t pass a Vec3 (LVecBase3) or NodePath (basically, any Panda3d class) to my c++ class. My code for it currently looks like (I attached also the source code):

float ChunkGenerator::SomeDemo(LVecBase3 * param1) {
	// LVecBase3* testVec = (LVecBase3*)param1;
	float x_val = param1->get_x();

        // Outputs: The x value is 0.0000, but it should output 10.000
	printf("The x value is %f\n", x_val); 
	return x_val;
}

And my python code like:

g = DemoModule.ChunkGenerator()
result = g.SomeDemo(LVecBase3(10,20,30));

I’m using SWIG to generate a wrapper, and include it as a .pyd file. When I pass an int (and multiply it with 10 for example), everything works.

Thanks in advance …
Tobias
Source Code.zip (30 KB)

It doesn’t work because SWIG uses a completely different mechanism to wrap the LVecBase3 than Panda3D does, since Panda uses Interrogate to generate the wrappers. I don’t think that the Panda wrapped version of LVecBase3 is interchangeable with the SWIG based version.
So, you’ll either have to use interrogate instead of SWIG, or you’ll simply have to pass three floats. (A third alternative is to let SWIG wrap the LVecBase3 class as well, but then you’d not be able to interchange it with Panda.)

Passing three floats is not an option because later I want to pass a NodePath for example :slight_smile: So if SWIG is not supported, is boost.python supported? Or what would be the best solution for a small extension (I don’t want to recompile panda3d for a few functions)?

Thanks in advance
Tobias

I think that it is best to use interrogate for extension modules if you want the best interoperability with Panda3D.

Are there any tutorials for it? Or some documentation (I just found panda3d.org/manual/index.php/Interrogate)?

Thanks in advance
Tobias

You can try running makepanda to compile Panda3D and look at how it calls “interrogate”. You can also call “interrogate -h” which explains more about the various options. Finally, if you have specific issues with interrogate, we’d be happy to help you.

Are you on windows?
If so I could provide a small sample project for an extension, with say one dummy class and everything else needed (e. g. proper export symbols).
I use such projects all the time to develop my own extensions, e. g. PhysX 3 or Bullet.

Yeah I’m on windows … but I now got it to work (finally!) … after some trouble :slight_smile:

Thanks for your help!
Tobias