[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 1

[Solved]How to wrap btOgre for python

Post by niubaty » Sun Feb 17, 2019 12:42 pm

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.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 774
Joined: Sun Mar 30, 2014 2:51 pm
x 120
Contact:

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

Post by paroj » Sun Feb 17, 2019 2:08 pm

take a look at https://github.com/OGRECave/ogre-imgui for how to wrap external modules.
0 x

niubaty
Kobold
Posts: 27
Joined: Thu Jan 10, 2019 2:19 pm
x 1

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

Post by niubaty » Mon Feb 18, 2019 12:14 pm

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
0 x

niubaty
Kobold
Posts: 27
Joined: Thu Jan 10, 2019 2:19 pm
x 1

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

Post by niubaty » Mon Feb 18, 2019 1:01 pm

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)
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 774
Joined: Sun Mar 30, 2014 2:51 pm
x 120
Contact:

Re: [Solved]How to wrap btOgre for python

Post by paroj » Mon Feb 18, 2019 2:26 pm

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?
0 x

niubaty
Kobold
Posts: 27
Joined: Thu Jan 10, 2019 2:19 pm
x 1

Re: [Solved]How to wrap btOgre for python

Post by niubaty » Tue Feb 19, 2019 5:42 am

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.
0 x

Post Reply