Mogre & BulletSharp

Jeason

26-05-2011 16:27:28

Hi,

Is there a sample or a tutorial which shows how to use BulletSharp with Mogre? Especially I search for a sample / tutorial which shows how to use Mesh Collision / Mesh Shapes with Mogre and BulletSharp.

Thanks in advance :)

Jeason

Meharin

23-06-2011 19:56:32

Sorry I didn't see this until now; I was on vacation.

There is a mesh strider here you can use to load meshes:
http://www.ogre3d.org/tikiwiki/BulletMe ... e=Cookbook

I downloaded the source and compiled that into bulletsharp.

On the application side it makes it easy:


Mesh mesh = MeshManager.Singleton.Load(meshName, "General", HardwareBuffer.Usage.HBU_DYNAMIC);

var strider = new MogreMeshStrider(mesh);

IMyEntityInterface entity = ... ;
CollisionShape shape;

if (entity.IsStatic()) // (Static is mass = 0) .....I forget why I do this. Something about ability to collide, and efficiency I think. Currently I only get BvhTriangleMeshShape showing up in the debug drawer (which I had partially working).
{
shape = new BvhTriangleMeshShape(strider, true, true);
}
else
{
shape = new ConvexTriangleMeshShape(strider, true);
}


If you go ahead with this, let me know. I had to write some C++ glue code to get that mesh strider code into BulletSharp. I should upload those files somewhere.

Meharin

23-06-2011 19:59:11

Here are the files I added to BulletSharp:

MogreMeshStrider.h

#pragma once

#ifdef GRAPHICS_MOGRE

#include "StridingMeshInterface.h"
#include "btMogreMeshStrider.h"

namespace BulletSharp
{
public ref class MogreMeshStrider : StridingMeshInterface
{

public:
MogreMeshStrider(Mogre::Mesh^ m);

internal:
property btMogreMeshStrider* UnmanagedPointer
{
btMogreMeshStrider* get();
}
};
}

#endif

MogreMeshStrider.cpp:


#include "StdAfx.h"

#ifdef GRAPHICS_MOGRE

#include "MogreMeshStrider.h"

MogreMeshStrider::MogreMeshStrider( Mogre::Mesh^ m )
: StridingMeshInterface(new btMogreMeshStrider(m))
{

}

btMogreMeshStrider* MogreMeshStrider::UnmanagedPointer::get()
{
return (btMogreMeshStrider*)StridingMeshInterface::UnmanagedPointer;
}


#endif


btMogreMeshStrider.h:

#pragma once

#include "StdAfx.h"

#ifdef GRAPHICS_MOGRE

#include "OgreMesh.h"

#define ASSERT(x) assert(x) // Review this

/// Shares vertices/indexes between Ogre and Bullet
class btMogreMeshStrider : public btStridingMeshInterface {

public:
btMogreMeshStrider( Ogre::Mesh * m = 0 ):mMesh(m){}

void set( Ogre::Mesh * m ) { ASSERT(m); mMesh = m; }
// inherited interface
virtual int getNumSubParts() const;

virtual void getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0);
virtual void getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0) const;

virtual void unLockVertexBase(int subpart);
virtual void unLockReadOnlyVertexBase(int subpart) const;

virtual void preallocateVertices(int numverts);
virtual void preallocateIndices(int numindices);
private:
Ogre::Mesh * mMesh;
};

#endif


btMogreMeshStrider.cpp

#include "StdAfx.h"

#ifdef GRAPHICS_MOGRE

#include "btMogreMeshStrider.h"

#include "OgreSubMesh.h"

int btMogreMeshStrider::getNumSubParts() const
{
int ret = mMesh->getNumSubMeshes();
ASSERT( ret > 0 );
return ret;
}

void btMogreMeshStrider::getLockedReadOnlyVertexIndexBase(
const unsigned char **vertexbase,
int& numverts,
PHY_ScalarType& type,
int& stride,
const unsigned char **indexbase,
int & indexstride,
int& numfaces,
PHY_ScalarType& indicestype,
int subpart/*=0*/ ) const
{
Ogre::SubMesh* submesh = mMesh->getSubMesh(subpart);

Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mMesh->sharedVertexData : submesh->vertexData;

const Ogre::VertexElement* posElem =
vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);

Ogre::HardwareVertexBufferSharedPtr vbuf =
vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());

*vertexbase =
reinterpret_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
// There is _no_ baseVertexPointerToElement() which takes an Ogre::Real or a double
// as second argument. So make it float, to avoid trouble when Ogre::Real will
// be comiled/typedefed as double:
//Ogre::Real* pReal;
float* pReal;
posElem->baseVertexPointerToElement((void*) *vertexbase, &pReal);
*vertexbase = (unsigned char*) pReal;

stride = (int) vbuf->getVertexSize();

numverts = (int) vertex_data->vertexCount;
ASSERT( numverts );

type = PHY_FLOAT;

Ogre::IndexData* index_data = submesh->indexData;
Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;

if (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT){
indicestype = PHY_INTEGER;
}
else{
ASSERT(ibuf->getType() == Ogre::HardwareIndexBuffer::IT_16BIT);
indicestype = PHY_SHORT;
}

if ( submesh->operationType == Ogre::RenderOperation::OT_TRIANGLE_LIST ){
numfaces = (int) index_data->indexCount / 3;
indexstride = (int) ibuf->getIndexSize()*3;
}
else
if ( submesh->operationType == Ogre::RenderOperation::OT_TRIANGLE_STRIP ){
numfaces = (int) index_data->indexCount -2;
indexstride = (int) ibuf->getIndexSize();
}
else{
ASSERT( 0 ); // not supported
}

*indexbase = reinterpret_cast<unsigned char*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
}

void btMogreMeshStrider::getLockedVertexIndexBase( unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart/*=0*/ )
{
ASSERT( 0 );
}

void btMogreMeshStrider::unLockReadOnlyVertexBase( int subpart ) const
{
Ogre::SubMesh* submesh = mMesh->getSubMesh(subpart);

Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mMesh->sharedVertexData : submesh->vertexData;

const Ogre::VertexElement* posElem =
vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);

Ogre::HardwareVertexBufferSharedPtr vbuf =
vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());

vbuf->unlock();

Ogre::IndexData* index_data = submesh->indexData;
Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
ibuf->unlock();
}

void btMogreMeshStrider::unLockVertexBase( int subpart )
{
ASSERT( 0 );
}

void btMogreMeshStrider::preallocateVertices( int numverts )
{
ASSERT( 0 );
}

void btMogreMeshStrider::preallocateIndices( int numindices )
{
ASSERT( 0 );
}

#endif

Meharin

23-06-2011 20:05:41

Note: this is not fully working yet (only worked for my static trangle mesh object), and I think I might have had threading issues causing occasional hangs, so I disabled it and haven't been using it, but it's a start.

Again, it is from the wiki, so check there for latest version of corresponding code:
http://www.ogre3d.org/tikiwiki/BulletDe ... e=Cookbook

How to enable in your C# code:

MogreDebugDrawer debugDrawer = new MogreDebugDrawer(this.SceneManager);
bulletDynamicsWorld.MogreDebugDraw = debugDrawer;


MogreDebugDrawer.h:

#pragma once

#ifdef GRAPHICS_MOGRE

#include "OgreDebugDrawer.h"
#include "DebugDraw.h"

namespace BulletSharp
{
public ref class MogreDebugDrawer
{

public:
MogreDebugDrawer(Mogre::SceneManager^ sceneManager);

public:

OgreDebugDrawer* ogreDebugDrawer;
/*{
OgreDebugDrawer* get();
set(OgreDebugDrawer* v);
}*/

internal:
property btIDebugDraw* UnmanagedPointer
{
btIDebugDraw* get();
}
};
}

#endif


MogreDebugDrawer.cpp

#include "StdAfx.h"

#ifdef GRAPHICS_MOGRE

#include "MogreDebugDrawer.h"

MogreDebugDrawer::MogreDebugDrawer(Mogre::SceneManager^ sceneManager)
{
ogreDebugDrawer = new OgreDebugDrawer(sceneManager);
}

btIDebugDraw* MogreDebugDrawer::UnmanagedPointer::get()
{
return ogreDebugDrawer;
}

#endif


OgreDebugDrawer.h

#pragma once

#ifdef GRAPHICS_MOGRE

#include <OgreSceneManager.h>

class OgreDebugDrawer: public btIDebugDraw
, public Ogre::FrameListener
{
public:
OgreDebugDrawer( Ogre::SceneManager *scm );
~OgreDebugDrawer ();
virtual void drawLine (const btVector3 &from, const btVector3 &to, const btVector3 &color);
virtual void drawTriangle (const btVector3 &v0, const btVector3 &v1, const btVector3 &v2, const btVector3 &color, btScalar);
virtual void drawContactPoint (const btVector3 &PointOnB, const btVector3 &normalOnB, btScalar distance, int lifeTime, const btVector3 &color);
virtual void reportErrorWarning (const char *warningString);
virtual void draw3dText (const btVector3 &location, const char *textString);
virtual void setDebugMode (int debugMode);
virtual int getDebugMode () const;

//bool frameStarted();
//bool frameEnded();

protected:
bool frameStarted(const Ogre::FrameEvent& evt);
bool frameEnded(const Ogre::FrameEvent& evt);
private:
struct ContactPoint{
Ogre::Vector3 from;
Ogre::Vector3 to;
Ogre::ColourValue color;
size_t dieTime;
};
DebugDrawModes mDebugModes;
Ogre::ManualObject *mLines;
Ogre::ManualObject *mTriangles;
std::vector< ContactPoint > *mContactPoints;
std::vector< ContactPoint > mContactPoints1;
std::vector< ContactPoint > mContactPoints2;
};

#endif


OgreDebugDrawer.cpp

#include "StdAfx.h"

#ifdef GRAPHICS_MOGRE

#include "OgreDebugDrawer.h"
//#include "OgreBulletUtils.h"

#include <OgreRoot.h>
#include <OgreManualObject.h>
#include <OgreMaterialManager.h>
#include <OgreLogManager.h>

#define ASSERT(x) assert(x)

using namespace Ogre;

inline btVector3 cvt(const Ogre::Vector3 &V){
return btVector3(V.x, V.y, V.z);
}

inline Ogre::Vector3 cvt(const btVector3&V){
return Ogre::Vector3(V.x(), V.y(), V.z());
}

inline btQuaternion cvt(const Ogre::Quaternion &Q)
{
return btQuaternion(Q.x, Q.y, Q.z, Q.w);
};

inline Ogre::Quaternion cvt(const btQuaternion &Q)
{
return Ogre::Quaternion(Q.w(), Q.x(), Q.y(), Q.z());
};


OgreDebugDrawer::OgreDebugDrawer( Ogre::SceneManager *scm )
{
mContactPoints = &mContactPoints1;
mLines = new Ogre::ManualObject("physics lines");
ASSERT( mLines );
mTriangles = new Ogre::ManualObject("physics triangles");
ASSERT( mTriangles );
mLines->setDynamic(true);
mTriangles->setDynamic(true);
//mLines->estimateVertexCount( 100000 );
//mLines->estimateIndexCount( 0 );

scm->getRootSceneNode()->attachObject( mLines );
scm->getRootSceneNode()->attachObject( mTriangles );

static const char * matName = "OgreBulletCollisionsDebugDefault";
Ogre::MaterialPtr mtl = Ogre::MaterialManager::getSingleton().getDefaultSettings()->clone(matName);
mtl->setReceiveShadows(false);
mtl->setSceneBlending( SBT_TRANSPARENT_ALPHA );
mtl->setDepthBias( 0.1f, 0 );
Ogre::TextureUnitState * tu = mtl->getTechnique(0)->getPass(0)->createTextureUnitState();
ASSERT( tu );
tu->setColourOperationEx( LBX_SOURCE1, LBS_DIFFUSE );
mtl->getTechnique(0)->setLightingEnabled(false);
//mtl->getTechnique(0)->setSelfIllumination( ColourValue::White );

mLines->begin( matName, Ogre::RenderOperation::OT_LINE_LIST );
mLines->position( Ogre::Vector3::ZERO );
mLines->colour( Ogre::ColourValue::Blue );
mLines->position( Ogre::Vector3::ZERO );
mLines->colour( Ogre::ColourValue::Blue );

mTriangles->begin( matName, Ogre::RenderOperation::OT_TRIANGLE_LIST );
mTriangles->position( Ogre::Vector3::ZERO );
mTriangles->colour( Ogre::ColourValue::Blue );
mTriangles->position( Ogre::Vector3::ZERO );
mTriangles->colour( Ogre::ColourValue::Blue );
mTriangles->position( Ogre::Vector3::ZERO );
mTriangles->colour( Ogre::ColourValue::Blue );

mDebugModes = (DebugDrawModes) DBG_DrawWireframe;
Ogre::Root::getSingleton().addFrameListener(this);
}

OgreDebugDrawer::~OgreDebugDrawer()
{
Ogre::Root::getSingleton().removeFrameListener(this);
delete mLines;
delete mTriangles;
}

void OgreDebugDrawer::drawLine( const btVector3 &from, const btVector3 &to, const btVector3 &color )
{
Ogre::ColourValue c( color.getX(), color.getY(), color.getZ() );
c.saturate();
mLines->position( cvt(from) );
mLines->colour( c );
mLines->position( cvt(to) );
mLines->colour( c );
}

void OgreDebugDrawer::drawTriangle( const btVector3 &v0, const btVector3 &v1, const btVector3 &v2, const btVector3 &color, btScalar alpha )
{
Ogre::ColourValue c( color.getX(), color.getY(), color.getZ(), alpha );
c.saturate();
mTriangles->position( cvt(v0) );
mTriangles->colour( c );
mTriangles->position( cvt(v1) );
mTriangles->colour( c );
mTriangles->position( cvt(v2) );
mTriangles->colour( c );
}

void OgreDebugDrawer::drawContactPoint( const btVector3 &PointOnB, const btVector3 &normalOnB, btScalar distance, int lifeTime, const btVector3 &color )
{
mContactPoints->resize( mContactPoints->size() + 1 );
ContactPoint p = mContactPoints->back();
p.from = cvt( PointOnB );
p.to = p.from + cvt( normalOnB ) * distance;
p.dieTime = Ogre::Root::getSingleton().getTimer()->getMilliseconds() + lifeTime;
p.color.r = color.x();
p.color.g = color.y();
p.color.b = color.z();
}

bool OgreDebugDrawer::frameStarted( const Ogre::FrameEvent& evt )
//bool OgreDebugDrawer::frameStarted( )
{
size_t now = Ogre::Root::getSingleton().getTimer()->getMilliseconds();
std::vector< ContactPoint > *newCP = mContactPoints == &mContactPoints1 ? &mContactPoints2 : &mContactPoints1;
for ( std::vector< ContactPoint >::iterator i = mContactPoints->begin(); i < mContactPoints->end(); i++ ){
ContactPoint &cp = *i;
mLines->position( cp.from );
mLines->colour( cp.color );
mLines->position( cp.to );
if ( now <= cp.dieTime )
newCP->push_back( cp );
}
mContactPoints->clear();
mContactPoints = newCP;

mLines->end();
mTriangles->end();

return true;
}

bool OgreDebugDrawer::frameEnded( const Ogre::FrameEvent& evt )
//bool OgreDebugDrawer::frameEnded( )
{
mLines->beginUpdate(0);
mTriangles->beginUpdate(0);
return true;
}

void OgreDebugDrawer::reportErrorWarning( const char *warningString )
{
Ogre::LogManager::getSingleton().getDefaultLog()->logMessage( warningString );
}

void OgreDebugDrawer::draw3dText( const btVector3 &location, const char *textString )
{

}

void OgreDebugDrawer::setDebugMode( int debugMode )
{
mDebugModes = (DebugDrawModes) debugMode;
}

int OgreDebugDrawer::getDebugMode() const
{
return mDebugModes;
}

#endif

Jeason

24-06-2011 19:46:13

Awesome :D I did not know that I have to implement the MeshStrider in C++ so I was a bit confused that i can not derive from btStridingMeshInterface ^^ Thanks for your code it will help me a lot (I have not much experience in C++/CLI). I test it as soon as possible :)

Jeason

Pyritie

07-08-2011 00:56:59

I'm trying to add these files into my bulletsharp as well, but I get some errors and I'm not sure how to get rid of them since I am not good with C++/CLI stuff at all

Error 1 error C1083: Cannot open include file: 'StdAfx.h': No such file or directory ...\btMogreMeshStrider.h 3 1 BulletSharp
Error 2 error C1083: Cannot open include file: 'OgreSceneManager.h': No such file or directory ...\OgreDebugDrawer.h 5 1 BulletSharp
Error 3 error C1083: Cannot open include file: 'StridingMeshInterface.h': No such file or directory ...\MogreMeshStrider.h 5 1 BulletSharp
Error 4 error C1083: Cannot open include file: 'OgreSceneManager.h': No such file or directory ...\OgreDebugDrawer.h 5 1 BulletSharp

I've tried adding OgreSceneManager.h to the project but it doesn't seem to do anything, but I'm also not sure if it's even in the right place.

Meharin

09-08-2011 16:21:47

I'm trying to add these files into my bulletsharp as well, but I get some errors and I'm not sure how to get rid of them since I am not good with C++/CLI stuff at all

Error 1 error C1083: Cannot open include file: 'StdAfx.h': No such file or directory ...\btMogreMeshStrider.h 3 1 BulletSharp
Error 2 error C1083: Cannot open include file: 'OgreSceneManager.h': No such file or directory ...\OgreDebugDrawer.h 5 1 BulletSharp
Error 3 error C1083: Cannot open include file: 'StridingMeshInterface.h': No such file or directory ...\MogreMeshStrider.h 5 1 BulletSharp
Error 4 error C1083: Cannot open include file: 'OgreSceneManager.h': No such file or directory ...\OgreDebugDrawer.h 5 1 BulletSharp

I've tried adding OgreSceneManager.h to the project but it doesn't seem to do anything, but I'm also not sure if it's even in the right place.


For OgreSceneManager, maybe try adding ogre's include directory to the C++ project's list of include directories.
I don't know why the others would have problems. I am traveling and I am not at my computer where I did this.

Pyritie

09-08-2011 17:27:34

I'm not entirely sure how to do that - I tried adding some folders to the additional include directory thingies in the project properties but it still gives me those 4 errors (and now it gives me 19360 more of them D:)

I'm pretty useless at this, sorry ._.

if it's too much trouble, I can just hand-translate the c++ mesh strider thingy into c# - it'll be a little bit slower but at least then I won't have to deal with pulling my hair out at c++ shenanigans

EDIT:

okay let me just see if I can actually compile bulletsharp first before adding stuff into it

Pyritie

09-08-2011 22:22:14

okay well XainFaith on #ogre3d showed me how to correctly set up the ogre libs and linker references and all that stuff so it compiled correctly. Hooray!

if anyone else comes across this post in the future, here's the dll I used.
http://ponykart.svn.sourceforge.net/vie ... vision=106
(mogre 1.7.1, bulletsharp 1.15.0.0)

though I disabled a bunch of the extra stuff I don't need, like soft bodies and serialization and whatnot

make sure you put these extra "glue" files in with the rest of the bullet src, that was a problem with me for a while :P
then you'll need to include ogre's /include/ directory
and boost's libs
and then add OgreMain.dll to the lib thingy (not the path, the actual file, it's Linker > Input > Additional Dependencies) (but have the path on the general Linker thing)


-----

EDIT: how do I get the debug drawer thing working?

Pyritie

11-08-2011 22:36:18

Wellll that didn't really work. Got a big fat "Could not load file or assembly 'BulletSharp.dll' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)" error.

Could... could I just have your modified DLL? D:

Meharin

12-08-2011 10:33:04

Wellll that didn't really work. Got a big fat "Could not load file or assembly 'BulletSharp.dll' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)" error.

Could... could I just have your modified DLL? D:


Ooh I hate those :)

Are you sure you're building everything in x86 (and not Mixed or x64 or whatever).

I can give you my copies once I return from traveling on Aug 20.

Pyritie

12-08-2011 12:45:34

The only option I see in the build configuration manager thingy is "Win32"

Cygon

12-08-2011 23:07:35

If you wish, the Ogre/Mogre 1.7.3 binaries if posted in my Some x64/x86 builds of Mogre 1.7.3 thread also include builds of BulletSharp (upgraded to Bullet 2.78).

I only tested that BulletSharp works through creation of a new CollisionWorld,
BulletSharp.CollisionWorld w = new BulletSharp.CollisionWorld(
new BulletSharp.CollisionDispatcher(),
new BulletSharp.SimpleBroadphase(),
new BulletSharp.DefaultCollisionConfiguration()
);


so I can't guarantee anything about whether it works like it should, only that it doesn't blow up right away ;)

Pyritie

12-08-2011 23:33:49

Should I upgrade my mogre too while I'm at it or is that not needed if all I need is your updated bulletsharp? Just wondering what mogre 1.7.3 has that my version, 1.7.1, doesn't.

(also if you're looking for something to do, I have a few other questions about bullet :P )

Cygon

19-08-2011 11:49:14

It's compiled against Mogre 1.7.3 and both assemblies are strong-named, so mix-and-match is probably not possible.

Honestly, I don't know what Mogre 1.7.3 adds over 1.7.1. Yep, I compiled it, but I haven't stepped through the Changelogs or anything - my motivation was more about obtaining .NET 4.0 builds of it. I'm completely new to Mogre/Ogre myself and BulletSharp/Bullet as well, just looking at the thread you linked leaves me with question marks above my head, sorry :)

Beauty

21-08-2011 20:24:53

One of our Mogre users created a wiki page with a visual debugging class for BulletSharp:
http://www.ogre3d.org/tikiwiki/BulletSharpDebugDrawer

Meharin

22-08-2011 00:34:25

One of our Mogre users created a wiki page with a visual debugging class for BulletSharp:
http://www.ogre3d.org/tikiwiki/BulletSharpDebugDrawer


Oh nice! I'll have to give it a shot. It might be easier to find if it was under a Mogre category.

Beauty

22-08-2011 10:56:53

I added a link to the newsbox of the Mogre wiki page.
Maybe in the future I will create a new page related to BulletSharp.
At least I added a tiny note to the BulletSharpDebugDrawer wiki page. So the people know what it is and have the links to Bullet, Mogre and BulletSharp.

update:
It might be easier to find if it was under a Mogre category
Now I understand what you mean. The wiki structure. Unfortunately I couldn't figure out how to move it. I want to have a look again later.

Beauty

09-09-2011 10:30:37

On the wiki page we got a task.
http://www.ogre3d.org/tikiwiki/BulletSharpDebugDrawer

TODO: Post the IDebugDraw interface too.
Can anybody post the code?
Then I would add it to the wiki.

Pyritie

09-09-2011 11:45:42

...the IDebugDraw is included with BulletSharp...

Beauty

09-09-2011 21:31:59

Thanks.
I found it and added the link to the wiki page.

Aralox

26-01-2012 05:29:39

Hey Pyritie, Im currently in the same boat, and am trying to create a BvhTriangleMeshShape for a test level. Did you manage to find a way to get a StridingMeshInterface to pass to the shape constructor?
Eg. using a built dll, or by converting the C++ bullet mesh strider to c#?

Any help would be appreciated :)

Thanks,
Aralox

Meharin

26-01-2012 06:14:28

It's been a while since I looked at this stuff so I'm rusty on it and I might be out of date, but I looked at my code and I am creating a BvhTriangleMeshShape:

[Edit: oops, I just rewrote my above forum posts. Read my above posts for info on how I am still doing things.]

Pyrite, did you ever get it working? I still have mine working.

Perhaps we should petition the BulletSharp maintainer to add the Mogre strider to the official codebase?

Compiling C++ sure can be a pain, with making sure everything is set to x86, making sure binary dependencies for Ogre/Mogre and Bullet are all matched up, etc., disabling unused features (with their own dependencies) in Bullet, yada yada.

(Here's another random lead I just stumbled upon, if you can somehow figure out how to use TriangleIndexVertexArray (which I believe is already part of the official BulletSharp)):
http://code.google.com/p/bulletsharp/is ... l?id=36#c4

Aralox

26-01-2012 08:59:28

Thanks for the reply Meharin :)
So you basically compiled your own version of the bulletsharp dll, including in the c++ class you wrote for the mesh strider?
I've got little to no experience with compiling stuff with c++, and dont really want to venture in that territory yet :P
Could you put up your bulletsharp dll somewhere? Is it built against mogre 1.7.1?

I checked out the post you linked, and it looks like it can be done using a TriangleIndexVertexArray, so I will give that a go now. (Im under the simple assumption that the format of the indices array is (v1,v2,v3) * polycount, and vertices (x,y,z pos) * vertexcount)

Meharin

26-01-2012 09:51:30

Yes I compiled my own bulletsharp dll.
I understand not wanting to venture into C++ compiling. It's not hard once you learn the ins and outs of C++ and static vs dynamic DLLs, and include and library paths etc., but you definitely need to be organized with source trees and understand where all the library dependencies are coming from. Thank goodness for .NET (and I guess Java) world making dependencies a little simpler.

If you get TriangleIndexVertexArray working please post your code since it might be a better approach :)
(You may be able to look at the MogreMeshStrider code from my earlier posts to see how to get vertex data from meshes.)

I put up a snapshot of my entire set of release mode binaries here: (If you need PDBs, or debug mode, or upgrade to the most current version of Mogre, let me know -- my hard drive hasn't crashed recently so I still have the source ready to build.) I can't even remember what version of Mogre/Ogre I'm using but from my signature it might be 1.7.1 [Update: yes it does seem to be 1.7.1].

http://www.box.com/s/lyka7fglhdd6lkt3bflj

[UPDATE: I see people are still downloading this every once in a while thanks to box sending me emails. I would also like to suggest you consider going to http://www.craftworkgames.com/blog/buil ... re-part-4/ and downloading from the bottom link 'Download Mogre 1.7.4 binaries with Terrain and Paging'. It was more carefully put together and is a more recent version, and I no longer need a custom bulletsharp dll. I may switch to that myself soon.]

Pyritie

26-01-2012 10:52:10

Hey Pyritie, Im currently in the same boat, and am trying to create a BvhTriangleMeshShape for a test level. Did you manage to find a way to get a StridingMeshInterface to pass to the shape constructor?
Eg. using a built dll, or by converting the C++ bullet mesh strider to c#?

Any help would be appreciated :)

Thanks,
Aralox

I found a workaround that doesn't need you to change the BulletSharp DLL at all - first you convert the ogre mesh to a TriangleMesh, then you pass that in the constructor of the BvhTriangleMeshShape

GetMeshInformation is from the wiki
/// <summary>
/// Class to convert a ogre mesh to a bullet mesh
/// </summary>
public class OgreToBulletMesh {


/// <summary>
/// Give it a mesh and it'll create a BulletSharp.TriangleMesh out of it
/// </summary>
/// <param name="mesh">The mesh you're converting</param>
/// <returns>A bullet trimesh</returns>
public static TriangleMesh Convert(MeshPtr mesh, Vector3 pos, Quaternion orientation, Vector3 scale) {

// get our two main objects
TriangleMesh BulletMesh = new TriangleMesh(true, false);

Launch.Log("[Loading] Converting " + mesh.Name + " to a BulletSharp.TriangleMesh");

uint vertex_count = default(uint);
Vector3[] vertices = default(Vector3[]);
uint index_count = default(uint);
uint[] indices = default(uint[]);

GetMeshInformation(mesh, ref vertex_count, ref vertices, ref index_count, ref indices, pos, orientation, scale);

BulletMesh.PreallocateIndexes((int) index_count);
BulletMesh.PreallocateVertices((int) vertex_count);
//BulletMesh.WeldingThreshold = 0.1f;

for (int a = 0; a < index_count; a += 3) {
BulletMesh.AddTriangle(vertices[indices[a]], vertices[indices[a + 1]], vertices[indices[a + 2]], true);
}

return BulletMesh;
}

/// <summary>
/// Give it an entity and it'll create a BulletSharp.TriangleMesh out of it
/// </summary>
/// <param name="ent">The entity to convert. It'll grab its mesh and use all of its submeshes</param>
/// <param name="node">The node the entity is attached to. We aren't modifying it, but we'll use its transforms</param>
/// <returns>A bullet trimesh</returns>
public static TriangleMesh Convert(Entity ent, SceneNode node) {
return Convert(ent.GetMesh(), node._getDerivedPosition(), node._getDerivedOrientation(), node._getDerivedScale());
}

public unsafe static void GetMeshInformation(MeshPtr mesh, ref uint vertex_count, ref Vector3[] vertices, ref uint index_count, ref uint[] indices,
Vector3 position, Quaternion orientation, Vector3 scale)
{
bool added_shared = false;
uint current_offset = 0;
uint shared_offset = 0;
uint next_offset = 0;
uint index_offset = 0;

vertex_count = index_count = 0;

for (ushort i = 0; i < mesh.NumSubMeshes; ++i) {
SubMesh submesh = mesh.GetSubMesh(i);
if (submesh.useSharedVertices) {
if (!added_shared) {
vertex_count += mesh.sharedVertexData.vertexCount;
added_shared = true;
}
}
else {
vertex_count += submesh.vertexData.vertexCount;
}

index_count += submesh.indexData.indexCount;
}

vertices = new Vector3[vertex_count];
indices = new uint[index_count];
added_shared = false;

for (ushort i = 0; i < mesh.NumSubMeshes; ++i) {
SubMesh submesh = mesh.GetSubMesh(i);
VertexData vertex_data = submesh.useSharedVertices ? mesh.sharedVertexData : submesh.vertexData;

if (!submesh.useSharedVertices || (submesh.useSharedVertices && !added_shared)) {
if (submesh.useSharedVertices) {
added_shared = true;
shared_offset = current_offset;
}

VertexElement posElem = vertex_data.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.VES_POSITION);
HardwareVertexBufferSharedPtr vbuf = vertex_data.vertexBufferBinding.GetBuffer(posElem.Source);

byte* vertex = (byte*) vbuf.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY);
float* pReal;

for (int j = 0; j < vertex_data.vertexCount; ++j, vertex += vbuf.VertexSize) {
posElem.BaseVertexPointerToElement(vertex, &pReal);
Vector3 pt = new Vector3(pReal[0], pReal[1], pReal[2]);
vertices[current_offset + j] = (orientation * (pt * scale)) + position;
}
vbuf.Unlock();
next_offset += vertex_data.vertexCount;
}

IndexData index_data = submesh.indexData;
uint numTris = index_data.indexCount / 3;
HardwareIndexBufferSharedPtr ibuf = index_data.indexBuffer;

bool use32bitindexes = (ibuf.Type == HardwareIndexBuffer.IndexType.IT_32BIT);

uint* pLong = (uint*) ibuf.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY);
ushort* pShort = (ushort*) pLong;
uint offset = submesh.useSharedVertices ? shared_offset : current_offset;
if (use32bitindexes) {
for (int k = 0; k < index_data.indexCount; ++k) {
indices[index_offset++] = pLong[k] + offset;
}
}
else {
for (int k = 0; k < index_data.indexCount; ++k) {
indices[index_offset++] = (uint) pShort[k] + (uint) offset;
}
}
ibuf.Unlock();
current_offset = next_offset;
}

}
}


then all you have to do is this!

shape = new BvhTriangleMeshShape(OgreToBulletMesh.Convert(ent, node), true, true);

Oh, and make sure you give it the DisableVisualiseObject flag, since when I tried to put a vehicle on top of that the whole thing went to shit - the kart flew off and everything crashed. NO idea why adding that flag fixes it, but... hey now you know.

Beauty

26-01-2012 12:16:47

trying to create a BvhTriangleMeshShape for a test level.
[...] find a way to get a StridingMeshInterface to pass to the shape constructor?

I'm not shure what you mean.
If you need to grabb the vertex and polygon structure from a mesh or ManualObject, then it would be useful to have a look to the source code, which is used for raycasting.
An older (and buggy) code snippet for polygon raycasting you find on this wiki page.
If such kind of code is what you need, let me know. Then I will give you more precise/useful links.

mesh strider
What is it?
I don't find the word strider in the dictionary.

TriangleIndexVertexArray
Well, this sounds like a task as I wrote above.
I can give you useful code snippets to grabb the content of Mesh/Entity/ManualObject.
It's not ready to use, but shows to way how to do it.
Wait ... here is my published demo code for that topic:
Read raw data from ManualObject - MOGRE

how to get vertex data from meshes.
Ok, first I sould read, then answer.
My latest version of the polygon raycasting code I published in this post.
It contains much code, but it shows how to extract the data from both, ManualObject and Mesh.

I can't even remember what version of Mogre/Ogre I'm using
In Visual Studio perform a right click to the DLL file in the reference. Then you see the version number in the properties.

Here is a tiny class how to read out the Mogre DLL version by code:

public static class MogreVersion
{
/// <summary>Query all parts of the Mogre version number</summary>
public static Version AssemblyVersion
{
get { return typeof(Mogre.Root).Assembly.GetName().Version; }
}


/// <summary>Return version about Mogre as String. (e.g. "1.6")</summary>
public static String MajorMinor
{
get { return String.Format("{0}.{1}", AssemblyVersion.Major, AssemblyVersion.Minor); }
}

} // class MogreVersion


TriangleMesh BulletMesh = new TriangleMesh(true, false);
Very interesting. I didn't know this method before.

Aralox

26-01-2012 15:25:28

Thanks for the replies guys! :)

@Meharin: Thanks for releasing those dlls, they will definitely help - i love seeing the components of other programmers' engines

@Pyritie: Sweet, I had something rudimentary like that going, by using that same class released on the wiki! Yours is alot cleaner, thanks for putting it up mate.
Ill keep the tip about the DisableVisualiseObject in mind, if I encounter anything weird ill try that first.

But for now, I managed to hack the BulletSharp Debug Drawer (http://www.ogre3d.org/tikiwiki/BulletSharpDebugDrawer&comzone=show) into a workable state (The current one on the wiki does not work properly, even when his custom 'get component' calls are replaced). Its really really slow, but it does its job in debug drawing the world so im happy :P

//original: http://www.ogre3d.org/tikiwiki/BulletSharpDebugDrawer
//Modified slightly by aralox
//Problems with IDisposable
//Error with lines begin and end. Workaround - call begin and end in the functions hooked up framestarted and frameended

using BulletSharp;
using Mogre;

namespace Bullet_Physics_Test
{
public class BulletDebugDrawer : IDebugDraw //, IDisposable
{
SceneManager sceneMgr;
ManualObject lines;
ManualObject triangles;
string matName;
CollisionWorld colWorld;
public DebugDrawModes DebugMode { get; set; }

bool begin = false;

public BulletDebugDrawer(Root root, SceneManager sceneManager, CollisionWorld colWorld)
{
sceneMgr = sceneManager;
this.colWorld = colWorld;

lines = new ManualObject("physics lines");
triangles = new ManualObject("physics triangles");
lines.Dynamic = true;
triangles.Dynamic = true;

sceneMgr.RootSceneNode.AttachObject(lines);
sceneMgr.RootSceneNode.AttachObject(triangles);

matName = "OgreBulletCollisionsDebugDefault";
MaterialPtr mtl = MaterialManager.Singleton.GetDefaultSettings().Clone(matName);
mtl.ReceiveShadows = false;
mtl.SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);
mtl.SetDepthBias(0.1f, 0);

TextureUnitState tu = mtl.GetTechnique(0).GetPass(0).CreateTextureUnitState();
tu.SetColourOperationEx(LayerBlendOperationEx.LBX_SOURCE1, LayerBlendSource.LBS_DIFFUSE);
mtl.GetTechnique(0).SetLightingEnabled(false);

lines.Begin(matName, RenderOperation.OperationTypes.OT_LINE_LIST);
begin = true;
lines.Position(Vector3.ZERO);
lines.Colour(ColourValue.Blue);
lines.Position(Vector3.ZERO);
lines.Colour(ColourValue.Blue);
lines.End();

triangles.Begin(matName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
triangles.Position(Vector3.ZERO);
triangles.Colour(ColourValue.Blue);
triangles.Position(Vector3.ZERO);
triangles.Colour(ColourValue.Blue);
triangles.Position(Vector3.ZERO);
triangles.Colour(ColourValue.Blue);
triangles.End();
begin = false;

DebugMode = DebugDrawModes.DrawWireframe | DebugDrawModes.DrawAabb | DebugDrawModes.DrawContactPoints;

// I have two events, one that fires right before we call bullet's simulate method, and one that runs right afterwards. That's what these are. You could probably replace these with FrameStarted and FrameEnded if you wanted to
root.FrameStarted += PreSimulate;
root.FrameEnded += PostSimulate;

// tell the physics world to use this as the debug drawer
colWorld.DebugDrawer = this;
}

bool PreSimulate(FrameEvent evt)
{
//lines.BeginUpdate(0);
lines.Begin(matName, RenderOperation.OperationTypes.OT_LINE_LIST);
//triangles.BeginUpdate(0);
triangles.Begin(matName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
return true;
}

bool PostSimulate(FrameEvent evt)
{
//lines.Clear(); //somehow need to clear the object, as it is saving every line

lines.End();
triangles.End();
return true;
}

public void Dispose() {
// unhook from these events
//root.FrameStarted -= PreSimulate;
//root.FrameEnded -= PostSimulate;
lines.Dispose();
triangles.Dispose();
}

/// <summary>
/// How many "steps" when we draw circles
/// </summary>
private const int numIter = 12;
/// <summary>
/// radian amount to increase the angle by when drawing circles
/// </summary>
private const float increaseAmount = (360f / numIter) * (Math.TWO_PI / 360f);
/// <summary>
/// maximum angle to draw circles with
/// </summary>
private const float limit = Math.TWO_PI + increaseAmount;





public void Draw3dText(Vector3 location, string textString) { }

/// <summary>
/// Draws an axis-aligned bounding box
/// </summary>
/// <param name="colour">I override this and make it white with 30% opacity</param>
public void DrawAabb(Vector3 from, Vector3 to, ColourValue colour) {
if (!begin)
return;

colour = new ColourValue(1, 1, 1, 0.3f);

// I'm sure there's a better way of doing this
Vector3 loo = new Vector3(to.x, from.y, from.z);
Vector3 olo = new Vector3(from.x, to.y, from.z);
Vector3 ool = new Vector3(from.x, from.y, to.z);
Vector3 llo = new Vector3(to.x, to.y, from.z);
Vector3 lol = new Vector3(to.x, from.y, to.z);
Vector3 oll = new Vector3(from.x, to.y, to.z);

lines.Position(from); lines.Colour(colour);
lines.Position(loo); lines.Colour(colour);
lines.Position(from); lines.Colour(colour);
lines.Position(olo); lines.Colour(colour);
lines.Position(from); lines.Colour(colour);
lines.Position(ool); lines.Colour(colour);

lines.Position(to); lines.Colour(colour);
lines.Position(llo); lines.Colour(colour);
lines.Position(to); lines.Colour(colour);
lines.Position(lol); lines.Colour(colour);
lines.Position(to); lines.Colour(colour);
lines.Position(oll); lines.Colour(colour);

lines.Position(loo); lines.Colour(colour);
lines.Position(lol); lines.Colour(colour);
lines.Position(lol); lines.Colour(colour);
lines.Position(ool); lines.Colour(colour);
lines.Position(ool); lines.Colour(colour);
lines.Position(oll); lines.Colour(colour);
lines.Position(oll); lines.Colour(colour);
lines.Position(olo); lines.Colour(colour);
lines.Position(olo); lines.Colour(colour);
lines.Position(llo); lines.Colour(colour);
lines.Position(llo); lines.Colour(colour);
lines.Position(loo); lines.Colour(colour);
}

public void DrawArc(Vector3 center, Vector3 normal, Vector3 axis, float radiusA, float radiusB, float minAngle, float maxAngle, ColourValue colour, bool drawSect, float stepDegrees) {

}

public void DrawArc(Vector3 center, Vector3 normal, Vector3 axis, float radiusA, float radiusB, float minAngle, float maxAngle, ColourValue colour, bool drawSect) {

}

public void DrawBox(Vector3 bbMin, Vector3 bbMax, Matrix4 trans, ColourValue colour) {

}

public void DrawBox(Vector3 bbMin, Vector3 bbMax, ColourValue colour) {

}

public void DrawCapsule(float radius, float halfHeight, int upAxis, Matrix4 transform, ColourValue colour) {
DrawCylinder(radius, halfHeight, upAxis, transform, colour);

Vector3 previousXYPos = transform * new Vector3(radius, halfHeight, 0);
Vector3 previousYZPos = transform * new Vector3(0, halfHeight, radius);
Vector3 previousNXYPos = transform * new Vector3(radius, -halfHeight, 0);
Vector3 previousNYZPos = transform * new Vector3(0, -halfHeight, radius);

float capsuleLimit = limit * 0.5f;

// y-x circle
for (float a = 0; a <= capsuleLimit; a += increaseAmount) {
float y = Math.Sin(a) * radius;
float x = Math.Cos(a) * radius;

// xy
Vector3 xyPos = transform * new Vector3(x, y + halfHeight, 0);
lines.Position(previousXYPos);
lines.Colour(colour);
lines.Position(xyPos);
lines.Colour(colour);
previousXYPos = xyPos;

// yz
float z = Math.Cos(a) * radius;

Vector3 yzPos = transform * new Vector3(0, y + halfHeight, z);
lines.Position(previousYZPos);
lines.Colour(colour);
lines.Position(yzPos);
lines.Colour(colour);
previousYZPos = yzPos;

// -xy
Vector3 nxyPos = transform * new Vector3(x, -y - halfHeight, 0);
lines.Position(previousNXYPos);
lines.Colour(colour);
lines.Position(nxyPos);
lines.Colour(colour);
previousNXYPos = nxyPos;

// -yz
Vector3 nyzPos = transform * new Vector3(0, -y - halfHeight, z);
lines.Position(previousNYZPos);
lines.Colour(colour);
lines.Position(nyzPos);
lines.Colour(colour);
previousNYZPos = nyzPos;
}
}

/// <summary>
/// Draws a cone
/// </summary>
/// <param name="upAxis">ignored for now</param>
public void DrawCone(float radius, float height, int upAxis, Matrix4 transform, ColourValue colour) {
float halfHeight = height / 2f;
Vector3 previousPos = transform * new Vector3(0, -halfHeight, radius);
Vector3 tip = transform * new Vector3(0, halfHeight, 0);

for (float a = 0; a <= limit; a += increaseAmount) {
float z = Math.Cos(a) * radius;
float x = Math.Sin(a) * radius;

// the circle
Vector3 pos = transform * new Vector3(x, -halfHeight, z);
lines.Position(previousPos);
lines.Colour(colour);
lines.Position(pos);
lines.Colour(colour);
previousPos = pos;

// the sides
lines.Position(pos);
lines.Colour(colour);
lines.Position(tip);
lines.Colour(colour);
}
}

public void DrawContactPoint(Vector3 pointOnB, Vector3 normalOnB, float distance, int lifeTime, ColourValue colour) {

lines.Position(pointOnB);
lines.Colour(colour);
lines.Position(pointOnB + normalOnB * distance);
lines.Colour(colour);
}

/// <summary>
/// Draws a cylinder
/// </summary>
/// <param name="upAxis">ignored for now</param>
public void DrawCylinder(float radius, float halfHeight, int upAxis, Matrix4 transform, ColourValue colour) {
Vector3 previousPos = transform * new Vector3(0, halfHeight, radius);
Vector3 previousNPos = transform * new Vector3(0, -halfHeight, radius);

for (float a = 0; a <= limit; a += increaseAmount) {
float z = Math.Cos(a) * radius;
float x = Math.Sin(a) * radius;

// positive
Vector3 pos = transform * new Vector3(x, halfHeight, z);
lines.Position(previousPos);
lines.Colour(colour);
lines.Position(pos);
lines.Colour(colour);
previousPos = pos;

// negative
Vector3 npos = transform * new Vector3(x, -halfHeight, z);
lines.Position(previousNPos);
lines.Colour(colour);
lines.Position(npos);
lines.Colour(colour);
previousNPos = npos;

// the sides
lines.Position(pos);
lines.Colour(colour);
lines.Position(npos);
lines.Colour(colour);
}
}

public void DrawLine(Vector3 from, Vector3 to, ColourValue colour) {
lines.Position(from);
lines.Colour(colour);
lines.Position(to);
lines.Colour(colour);
}

public void DrawLine(Vector3 from, Vector3 to, ColourValue fromcolour, ColourValue tocolour) {
lines.Position(from);
lines.Colour(fromcolour);
lines.Position(to);
lines.Colour(tocolour);
}

public void DrawPlane(Vector3 planeNormal, float planeConst, Matrix4 transform, ColourValue colour) {

}

/// <summary>
/// Draws a sphere that doesn't rotate
/// </summary>
public void DrawSphere(Vector3 p, float radius, ColourValue colour) {
Vector3 previousXYPos = p + new Vector3(0, radius, 0);
Vector3 previousYZPos = p + new Vector3(0, radius, 0);
Vector3 previousXZPos = p + new Vector3(0, 0, radius);

for (float a = 0; a <= limit; a += increaseAmount) {
float y = Math.Cos(a) * radius;
float x = Math.Sin(a) * radius;

// xy
Vector3 xyPos = p + new Vector3(x, y, 0);
lines.Position(previousXYPos);
lines.Colour(colour);
lines.Position(xyPos);
lines.Colour(colour);
previousXYPos = xyPos;

// yz
float z = Math.Sin(a) * radius;

Vector3 yzPos = p + new Vector3(0, y, z);
lines.Position(previousYZPos);
lines.Colour(colour);
lines.Position(yzPos);
lines.Colour(colour);
previousYZPos = yzPos;

// xz
z = Math.Cos(a) * radius;

Vector3 xzPos = p + new Vector3(x, 0, z);
lines.Position(previousXZPos);
lines.Colour(colour);
lines.Position(xzPos);
lines.Colour(colour);
previousXZPos = xzPos;

}

}

/// <summary>
/// Draws a sphere that does rotate
/// </summary>
public void DrawSphere(float radius, Matrix4 transform, ColourValue colour) {

Vector3 previousXYPos = transform * new Vector3(0, radius, 0);
Vector3 previousYZPos = transform * new Vector3(0, radius, 0);
Vector3 previousXZPos = transform * new Vector3(0, 0, radius);

for (float a = 0; a <= limit; a += increaseAmount) {
float y = Math.Cos(a) * radius;
float x = Math.Sin(a) * radius;

// xy
Vector3 xyPos = transform * new Vector3(x, y, 0);
lines.Position(previousXYPos);
lines.Colour(colour);
lines.Position(xyPos);
lines.Colour(colour);
previousXYPos = xyPos;

// yz
float z = Math.Sin(a) * radius;

Vector3 yzPos = transform * new Vector3(0, y, z);
lines.Position(previousYZPos);
lines.Colour(colour);
lines.Position(yzPos);
lines.Colour(colour);
previousYZPos = yzPos;

// xz
z = Math.Cos(a) * radius;

Vector3 xzPos = transform * new Vector3(x, 0, z);
lines.Position(previousXZPos);
lines.Colour(colour);
lines.Position(xzPos);
lines.Colour(colour);
previousXZPos = xzPos;


}


}

public void DrawSpherePatch(Vector3 center, Vector3 up, Vector3 axis, float radius, float minTh, float maxTh, float minPs, float maxPs, ColourValue colour, float stepDegrees) {

}

public void DrawSpherePatch(Vector3 center, Vector3 up, Vector3 axis, float radius, float minTh, float maxTh, float minPs, float maxPs, ColourValue colour) {

}

public void DrawTransform(Matrix4 transform, float orthoLen) {

}

/// <param name="__unnamed004">alpha?</param>
public void DrawTriangle(Vector3 v0, Vector3 v1, Vector3 v2, ColourValue colour, float __unnamed004) {
triangles.Position(v0);
triangles.Colour(colour);
triangles.Position(v1);
triangles.Colour(colour);
triangles.Position(v2);
triangles.Colour(colour);
}

/// <param name="__unnamed003">no idea</param>
/// <param name="__unnamed004">no idea</param>
/// <param name="__unnamed005">no idea</param>
public void DrawTriangle(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 __unnamed003, Vector3 __unnamed004, Vector3 __unnamed005, ColourValue colour, float alpha) {
DrawTriangle(v0, v1, v2, colour, alpha);
}

public void ReportErrorWarning(string warningString) {
// replace this with your own logging thing
System.Windows.Forms.MessageBox.Show("[WARNING] (BulletDebugManager): " + warningString, "Debug Drawer Error");
}
}
}


If anyone knows of/ is capable of writing a better class, (or just optimizing it) It would be appreciated by many people (including me!)

@Beauty: Yup, that raycasting to the polygon level wiki page has helped me many times now! Thanks for that.
To be honest, I dont know why it is called a mesh strider. The only thing i can think of is that the class metaphorically 'walks' over the mesh and extracts info, but even that doesnt really make sense...... :P


Anyway, I have some spheres falling and rolling around my little level!
It makes me very happy, so I'll just post up a screenie here for kicks :)


Thanks,
Aralox

Pyritie

26-01-2012 15:30:43

But for now, I managed to hack the BulletSharp Debug Drawer (http://www.ogre3d.org/tikiwiki/BulletSharpDebugDrawer&comzone=show) into a workable state (The current one on the wiki does not work properly, even when his custom 'get component' calls are replaced). Its really really slow, but it does its job in debug drawing the world so im happy :P
I did that too! What's wrong with it?

Though admittedly putting it up on the wiki with a whole bunch of unrelated code was probably not the best idea

Beauty

26-01-2012 19:11:19

Yes I compiled my own bulletsharp dll.
[...]
http://www.box.com/s/lyka7fglhdd6lkt3bflj

It would be nice, when you add this link to the wiki page and write some notes about.

... Oh, now I see that there is no wiki page about BulletSharp ...


... 1 hour of work ...

Now I created a wiki page for BulletSharp.
http://www.ogre3d.org/tikiwiki/BulletSharp

If you want to make additions or corrections, just do it. :wink:


But for now, I managed to hack the BulletSharp Debug Drawer (http://www.ogre3d.org/tikiwiki/BulletSh ... mzone=show) into a workable state (The current one on the wiki does not work properly, even when his custom 'get component' calls are replaced). Its really really slow, but it does its job in debug drawing the world so im happy :P
It would be nice when you update the code of the wiki page. So it's useful for others, too. (It's nice that you share your code here, but in the forum it's a little bit hidden.)

Aralox

27-01-2012 00:44:14

Thanks for that Beauty :)

Just a few notes: The link you posted is the OgreBullet wiki, the one you probably meant to post is http://www.ogre3d.org/tikiwiki/BulletSharp&highlight=bulletsharp

And under the binary downloads, I'll just put up the official downloads too

Meharin

27-01-2012 00:45:31


shape = new BvhTriangleMeshShape(OgreToBulletMesh.Convert(ent, node), true, true);


@Pyritie Awesome, thanks for providing your code! I tried it and it works, although I still need to do "shape = new ConvexTriangleMeshShape(triangleMesh, true);" instead for dynamic objects for some reason.

I would rather not have to lug around modified BulletSharp to accomplish the same thing (and for all I know it doesn't work as well), so I see no reason to keep that approach (MogreMeshStrider) and it is now #ifdef'ed out from my codebase.

@Beauty - thanks for putting up all the mesh info extracting info up recently!


Oh, and make sure you give it the DisableVisualiseObject flag, since when I tried to put a vehicle on top of that the whole thing went to shit - the kart flew off and everything crashed. NO idea why adding that flag fixes it, but... hey now you know.


I don't seem to need DisableVisualiseObject at the moment but I'll keep that in mind.

@Aralox, thanks for posting your DebugDrawer code. I've got to try that next.

Beauty

28-01-2012 12:36:59

Now I recognized, that BulletSharp is also available in the Cygon builds of Mogre.
Look to topic Some x64/x86 builds of Mogre 1.7.3.
There is the download link to the binary bundle (or maybe further download links for further versions).
Also Cygon published his code in his repository.
Perhaps it's easy to use his work as starting point to recompile everything.