[Solved]How to wrap btOgre for python Topic is solved

Problems building or running the engine, queries about how to use features etc.
Post Reply
niubaty
Kobold
Posts: 27
Joined: Thu Jan 10, 2019 2:19 pm
x 2

[Solved]How to wrap btOgre for python

Post by niubaty »

Code: Select all

https://github.com/OGRECave/btogre
I thought it might be possible to write a wrap.CXX to wrap the c++ class and functions of btogre, but in the end I have to deal with the Entity and SceneNode which are python object. I don't know how to deal with python object of Entity and SceneNode in my own wrap file.
Is there any way to convert the python object to Entity/SceneNode or better advices?

Code: Select all

Entity------------------>btCollsionShape----+
                                            +------------>btRigidBody---------->add to phyworld
SceneNode------------>RigidBodyState--------+
The phyworld only need to read Entity's VertexData, but have to read/write SceneNode


These are the key part of dealing with Entity and SceneNode, you can see more in https://github.com/OGRECave/btogre

Code: Select all

// main.cpp of bgOgre
	    BtOgre::StaticMeshToShapeConverter converter(mNinjaEntity);
//...
//this is the defination of StaticMeshToShapeConverter 
//StaticMeshToShapeConverter(Ogre::Entity *entity,   const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
//...
	StaticMeshToShapeConverter::StaticMeshToShapeConverter(Entity *entity,  const Matrix4 &transform) :
		VertexIndexToShape(transform),
		mEntity (0),
		mNode (0)
	{
		addEntity(entity, transform);
	}

Code: Select all

// main.cpp of bgOgre
	    //Create BtOgre MotionState (connects Ogre and Bullet).
	    BtOgre::RigidBodyState *ninjaState = new BtOgre::RigidBodyState(mNinjaBtNode);
//...
//this is the defination of RigidBodyState
         RigidBodyState(Ogre::SceneNode *node)
            : mTransform(((node != NULL) ? BtOgre::Convert::toBullet(node->getOrientation()) : btQuaternion(0,0,0,1)),
                         ((node != NULL) ? BtOgre::Convert::toBullet(node->getPosition())    : btVector3(0,0,0))),
              mCenterOfMassOffset(btTransform::getIdentity()),
              mNode(node)
        {
        }
Last edited by niubaty on Mon Feb 18, 2019 1:03 pm, edited 1 time in total.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Is there any easy way to wrap btogre as a python module

Post by paroj »

take a look at https://github.com/OGRECave/ogre-imgui for how to wrap external modules.
niubaty
Kobold
Posts: 27
Joined: Thu Jan 10, 2019 2:19 pm
x 2

Re: Is there any easy way to wrap btogre as a python module

Post by niubaty »

paroj wrote: Sun Feb 17, 2019 2:08 pm take a look at https://github.com/OGRECave/ogre-imgui for how to wrap external modules.
Thank you
niubaty
Kobold
Posts: 27
Joined: Thu Jan 10, 2019 2:19 pm
x 2

Re: Is there any easy way to wrap btogre as a python module

Post by niubaty »

Here is my solution:
Write a btOgreLayer class to wrap the btOgre Stuff, and btOgreLayer has functions to accept OgreEntity and OgreSceneNode parameters.
Just like ogre-IMGUI, using swig to generate wrap.CXX for btOgreLayer class and compile the python pyd.

More details see https://github.com/niubaty/btOgreLayer.

Note:
There are newdemo, python directories and btOgreLayer.cpp, btOgreLayer.h, btOgreLayer.i CMakeLists.txt files.
create 'btogre' directory and clone the https://github.com/OGRECave/btogre.git
'newdemo' directory has a main2.cpp which is c++ demo using btOgreLayer
'python' directory has btogre_sample.py which is the python demo using btOgreLayer
Using CMake to generate project and compile the _btOgreLayer.pyd
(Only test on win10 with vs2015)
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: [Solved]How to wrap btOgre for python

Post by paroj »

niubaty wrote: Mon Feb 18, 2019 1:01 pm Here is my solution:
would you like to create a pull-request against btogre? so we can have everything in one place?
niubaty
Kobold
Posts: 27
Joined: Thu Jan 10, 2019 2:19 pm
x 2

Re: [Solved]How to wrap btOgre for python

Post by niubaty »

paroj wrote: Mon Feb 18, 2019 2:26 pm would you like to create a pull-request against btogre? so we can have everything in one place?
Honstly, my solution is not the best. It's more like a temporary or a compromised solution for users themselves.
I'm not sure is it worth to create a pull-request.
The best solution may be exporting all the interface of btogre directly and it involved bullet source files.
I don't know how to make that work, so I have to write a user's class(btOgreLayer in this case) and only export this user's class for python.
This method of the solution should also work on terrain or other c++ class which can not be exported as python interfaces theoretically.
I would figure out how to create a pull-request in a few days.
Post Reply