Ogre CSG Boolean Library (Lib + Source)

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!
CyberCop
Gnoblar
Posts: 5
Joined: Sat Jan 03, 2009 7:48 am
x 1

Ogre CSG Boolean Library (Lib + Source)

Post by CyberCop »

Hi everyone,

First of all, I'm not good at English, please bare with me. :wink:

This is a small CSG(Constructive Solid Geometry) Boolean Operation library for Ogre mesh.
A week ago, I found small C++ CSG demo from here
It was converted C++ sources from original Java CSG Boolean code.
I decide to port this code to work with Ogre Mesh and somehow manage to work.
The C++ code license is GNU GPL V3, so here it's ported version of lib.
This lib has no demo or example program. And no documents...

Download :
develoment version (*.h + *.lib)
full source (*.h + *.cpp + vc2005 project file) * Include some Korean remarks. Feel free to remove it if you have a problem.

Features: Entity Boolean Operation : Union, Intersection, Difference

Changed from Original: add UV Texture coordinate support, Memory leak bug fix, remove OpenGL dependency and some data management code.

Known Issue: Newly generated face will have same UV coordinate. I can't figure out how to assign UV for new faces. :oops:
Not fully tested under various situation. It will not work on mesh with more than 10000 vertex.

Usage:
#include "cvCSGOgreWrapper.h"
void cvEntityBoolean(const std::string& MeshName, Ogre::Entity *Ent1, Ogre::Entity *Ent2, evCSG_OPER Op);
or
void cvEntityUnion(const std::string& MeshName, Ogre::Entity *Ent1, Ogre::Entity *Ent2);
void cvEntityIntersection(const std::string& MeshName, Ogre::Entity *Ent1, Ogre::Entity *Ent2);
void cvEntityDifference(const std::string& MeshName, Ogre::Entity *Ent1, Ogre::Entity *Ent2);

The result mesh will be created by given name. You can create entity with newly generated mesh name.

Screen Shot:
Difference example
SS_Difference1.jpg
SS_Difference2.jpg
SS_Difference3.jpg
Hopefully some of you find it useful!
CyberCop
You do not have the required permissions to view the files attached to this post.
User avatar
aguru
Goblin
Posts: 236
Joined: Tue Feb 26, 2008 5:48 pm
x 3

Re: Ogre CSG Boolean Library (Lib + Source)

Post by aguru »

Thank you for sharing this - very interesting. Maybe this could be used for destructible entities? Not sure about the performance impact though.

May you want to add it to the wiki? In the forums, sometimes things get lost - in this case it would be a shame. :D
User avatar
PolyVox
OGRE Contributor
OGRE Contributor
Posts: 1316
Joined: Tue Nov 21, 2006 11:28 am
Location: Groningen, The Netherlands
x 18

Re: Ogre CSG Boolean Library (Lib + Source)

Post by PolyVox »

Excellent stuff, that's very cool. I know the original UnrealEd allowed you to build levels by using CSG. I haven't done any level editing for many years but I guess the same principles apply. So this stuff could definatly be useful.
kajjjak
Kobold
Posts: 26
Joined: Tue Mar 28, 2006 5:56 pm

Re: Ogre CSG Boolean Library (Lib + Source)

Post by kajjjak »

Cool, creating world using CSG would (in theory) minimize the "level size" requirements. And allow users to create their own levels. That would be a cool feature in a game.
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16

Re: Ogre CSG Boolean Library (Lib + Source)

Post by KungFooMasta »

Is there an easy way to get this working with heightmap generated terrain? Yesterday it dawned on me that this functionality would enable creation of rivers pretty easily, if you take the intersection region of a plane against terrain, and make a mesh out of it. Pretty cool idea if I say so myself! 8)
Creator of QuickGUI!
CyberCop
Gnoblar
Posts: 5
Joined: Sat Jan 03, 2009 7:48 am
x 1

Re: Ogre CSG Boolean Library (Lib + Source)

Post by CyberCop »

Here are some basic primitive CSG boolean performance result on my PC. (Core2Quad, + GeForce 8800)
As you can see below result, doing boolean operation on the fly could be a performance problem.
Saving the result mesh by mesh serializer is quite easy, so I would say this is something for design time.

Debug Mode - Box intersect with Sphere
15:07:12: CSG:Mesh2Sold Msh=Sphere1, VertexCount=289, IndexCount=1632
15:07:12: CSG:Mesh2Sold Msh=Box1, VertexCount=14, IndexCount=36
15:07:16: CSG:Intersection
15:07:16: CSG:Solid2Mesh SubMesh=2, VertexCount=2067, IndexCount=2067
15:07:16: CSG:Elapsed(ms)=4723, Start=41889, End=46612

Release Mode - Box intersect with Sphere
15:16:30: CSG:Mesh2Sold Msh=Sphere1, VertexCount=289, IndexCount=1632
15:16:30: CSG:Mesh2Sold Msh=Box1, VertexCount=14, IndexCount=36
15:16:30: CSG:Intersection
15:16:30: CSG:Solid2Mesh SubMesh=2, VertexCount=2067, IndexCount=2067
15:16:30: CSG:Elapsed(ms)=730, Start=37064, End=37794
B^S.jpg
Debug Mode - Sphere + Cylinder + Sphere = Capsule
15:19:46: CSG:Mesh2Sold Msh=Sphere1, VertexCount=289, IndexCount=1632
15:19:46: CSG:Mesh2Sold Msh=Cylinder1, VertexCount=68, IndexCount=306
15:19:46: CSG:Union
15:19:46: CSG:Solid2Mesh SubMesh=2, VertexCount=1020, IndexCount=1020
15:19:46: CSG:Elapsed(ms)=373, Start=25091, End=25464
15:20:19: CSG:Mesh2Sold Msh=Union1, VertexCount=1020, IndexCount=1020
15:20:19: CSG:Mesh2Sold Msh=Sphere2, VertexCount=289, IndexCount=1632
15:20:20: CSG:Union
15:20:20: CSG:Solid2Mesh SubMesh=3, VertexCount=2652, IndexCount=2652
15:20:20: CSG:Elapsed(ms)=1033, Start=57952, End=58985

Release Mode - Sphere + Cylinder + Sphere = Capsule
15:22:09: CSG:Mesh2Sold Msh=Sphere1, VertexCount=289, IndexCount=1632
15:22:09: CSG:Mesh2Sold Msh=Cylinder1, VertexCount=68, IndexCount=306
15:22:09: CSG:Union
15:22:09: CSG:Solid2Mesh SubMesh=2, VertexCount=1020, IndexCount=1020
15:22:09: CSG:Elapsed(ms)=70, Start=19735, End=19805
15:22:22: CSG:Mesh2Sold Msh=Union1, VertexCount=1020, IndexCount=1020
15:22:22: CSG:Mesh2Sold Msh=Sphere2, VertexCount=289, IndexCount=1632
15:22:22: CSG:Union
15:22:22: CSG:Solid2Mesh SubMesh=3, VertexCount=2652, IndexCount=2652
15:22:22: CSG:Elapsed(ms)=646, Start=32959, End=33605
SuCuS.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
Nargil
Greenskin
Posts: 124
Joined: Thu Feb 15, 2007 8:47 pm

Re: Ogre CSG Boolean Library (Lib + Source)

Post by Nargil »

Nice. Decapitation is on the way ;)
Does it also cut skeletons ?
Hardcore libertarian, hardcore programmer.
Dell M6300: T9300, 4GB, Quadro FX1600M, 17" 1920x1200p non-glare, OCZ Vertex 120 + external Seagate 120GB 7200.3
Use the power of 2 - literally. Non 2^n texture sizes may crash your graphic driver
dudeabot
Gnome
Posts: 334
Joined: Thu Jun 28, 2007 2:12 pm
Location: Brazil
x 5

Re: Ogre CSG Boolean Library (Lib + Source)

Post by dudeabot »

i tried run the code, it didnt work when i did this:

Code: Select all

		
                Ogre::Entity* ent1=mSceneMgr->createEntity("ent1","cube.1m.mesh");
		Ogre::Entity* ent2=mSceneMgr->createEntity("ent2","sphere.mesh");
		Ogre::SceneNode* node1=mSceneMgr->getRootSceneNode()->createChildSceneNode();
		Ogre::SceneNode* node2=mSceneMgr->getRootSceneNode()->createChildSceneNode();
		node1->attachObject(ent1);
		node2->attachObject(ent2);
		node1->setPosition(0.5f,0.0f,0.0f);// it works for (0,0,0), (0.7,0,0).. strange
		cvEntityIntersection("resultMesh", ent1, ent2);
funny thing it works for setposition(0,0,0) and (0.7,0,0) - the ones i tested also.

it crashes here

Code: Select all

Bound Face::getBound()
{
	return Bound(v1->getPosition(),v2->getPosition(),v3->getPosition());
}
called by

Code: Select all

if(face1->getBound().overlap(face2->getBound()))
which was called by facesplit

im uploading the mesh files i used for testing (a sphere and a cube)
You do not have the required permissions to view the files attached to this post.
CyberCop
Gnoblar
Posts: 5
Joined: Sat Jan 03, 2009 7:48 am
x 1

Re: Ogre CSG Boolean Library (Lib + Source)

Post by CyberCop »

Nargil // No, It just cut the mesh only...I can't imagine that the decapitated body working around with old skeleton :shock:

dudeabot // I try several times with your mesh and your position, I can't make same error you had.
For me, it works fine...Strange enough. :roll:
As you know, this is wrapper lib of someone else's code. What I did here is a making conversion from ogre mesh to solid (Original format)
and vice versa. My knowledge about CSG is not good enough to find an answer of your problem. :oops:
dudeabot
Gnome
Posts: 334
Joined: Thu Jun 28, 2007 2:12 pm
Location: Brazil
x 5

Re: Ogre CSG Boolean Library (Lib + Source)

Post by dudeabot »

hmm perhaps its the version im using, when i compile i get a different file size

i believe you are using visual studio for compiling it, bc i cant use it on my 2009 project (only recompiling it, but then i get this error)

here is my config:

ogreshoggot 1.6.1 (not the head)
visual studio 2009

thanks!
novant
Gnoblar
Posts: 12
Joined: Wed Dec 10, 2008 7:26 pm

Re: Ogre CSG Boolean Library (Lib + Source)

Post by novant »

hi every body, i think that this library is fantastic, but i have problems when i compile it,

my code:

entE=mgr->createEntity("ent_tmpMuro","Puerta_1.mesh");
entE2=mgr->createEntity("ent_tmpCil","sphere.mesh");
nodoEnt=mgr->getRootSceneNode()->createChildSceneNode("nodo_ent_tmpMuro");
nodoEnt2=mgr->getRootSceneNode()->createChildSceneNode("nodo_ent_tmpMuro2");
nodoDif=mgr->getRootSceneNode()->createChildSceneNode("nodoDif2");
nodoEnt->attachObject(entE);
nodoEnt->attachObject(entE2);
nodoEnt->scale(30,30,30);
nodoEnt->setPosition(Ogre::Vector3(0,0,0));
cvEntityBoolean("entDif",entE,entE2,evCSG_OPER::CSG_DIFFERENCE);
dif3=mgr->createEntity("tmpDif","entDif");
nodoDif->attachObject(dif3);
nodoDif->scale(1,1,1);
nodoDif->setPosition(10,40,10);
nodoEnt->setVisible(false);

Whe i run my application and this code is executed i have a exception in this line:

mlVector3D Vertex::getPosition()
{
return mlVector3D(x, y, z); <-- violation access
}

can somebody help me ?
LinuxInside
Kobold
Posts: 30
Joined: Sun Dec 11, 2011 6:00 pm

Re: Ogre CSG Boolean Library (Lib + Source)

Post by LinuxInside »

novant wrote:hi every body, i think that this library is fantastic, but i have problems when i compile it,

my code:

entE=mgr->createEntity("ent_tmpMuro","Puerta_1.mesh");
entE2=mgr->createEntity("ent_tmpCil","sphere.mesh");
nodoEnt=mgr->getRootSceneNode()->createChildSceneNode("nodo_ent_tmpMuro");
nodoEnt2=mgr->getRootSceneNode()->createChildSceneNode("nodo_ent_tmpMuro2");
nodoDif=mgr->getRootSceneNode()->createChildSceneNode("nodoDif2");
nodoEnt->attachObject(entE);
nodoEnt->attachObject(entE2);
nodoEnt->scale(30,30,30);
nodoEnt->setPosition(Ogre::Vector3(0,0,0));
cvEntityBoolean("entDif",entE,entE2,evCSG_OPER::CSG_DIFFERENCE);
dif3=mgr->createEntity("tmpDif","entDif");
nodoDif->attachObject(dif3);
nodoDif->scale(1,1,1);
nodoDif->setPosition(10,40,10);
nodoEnt->setVisible(false);

Whe i run my application and this code is executed i have a exception in this line:

mlVector3D Vertex::getPosition()
{
return mlVector3D(x, y, z); <-- violation access
}

can somebody help me ?
I have the same problem!