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!
Post Reply
CyberCop
Gnoblar
Posts: 5
Joined: Sat Jan 03, 2009 7:48 am

Ogre CSG Boolean Library (Lib + Source)

Post by CyberCop » Thu Feb 19, 2009 10:14 am

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_Difference1.jpg (112.33 KiB) Viewed 12482 times
SS_Difference2.jpg
SS_Difference2.jpg (113.14 KiB) Viewed 12478 times
SS_Difference3.jpg
SS_Difference3.jpg (124.81 KiB) Viewed 12480 times
Hopefully some of you find it useful!
CyberCop
0 x

User avatar
aguru
Goblin
Posts: 236
Joined: Tue Feb 26, 2008 5:48 pm

Re: Ogre CSG Boolean Library (Lib + Source)

Post by aguru » Thu Feb 19, 2009 10:43 am

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

User avatar
PolyVox
OGRE Contributor
OGRE Contributor
Posts: 1316
Joined: Tue Nov 21, 2006 11:28 am
Location: Groningen, The Netherlands
Contact:

Re: Ogre CSG Boolean Library (Lib + Source)

Post by PolyVox » Thu Feb 19, 2009 7:47 pm

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

kajjjak
Kobold
Posts: 26
Joined: Tue Mar 28, 2006 5:56 pm

Re: Ogre CSG Boolean Library (Lib + Source)

Post by kajjjak » Fri Feb 20, 2009 8:32 pm

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

User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
Contact:

Re: Ogre CSG Boolean Library (Lib + Source)

Post by KungFooMasta » Fri Feb 27, 2009 10:48 pm

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)
0 x
Creator of QuickGUI!

CyberCop
Gnoblar
Posts: 5
Joined: Sat Jan 03, 2009 7:48 am

Re: Ogre CSG Boolean Library (Lib + Source)

Post by CyberCop » Sat Feb 28, 2009 7:40 am

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
B^S.jpg (122.85 KiB) Viewed 11456 times
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
SuCuS.jpg (140.3 KiB) Viewed 11447 times
0 x

User avatar
Nargil
Greenskin
Posts: 124
Joined: Thu Feb 15, 2007 8:47 pm

Re: Ogre CSG Boolean Library (Lib + Source)

Post by Nargil » Sat Feb 28, 2009 2:31 pm

Nice. Decapitation is on the way ;)
Does it also cut skeletons ?
0 x
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
Contact:

Re: Ogre CSG Boolean Library (Lib + Source)

Post by dudeabot » Sun Mar 08, 2009 3:29 pm

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)
Attachments
media.rar
(34.24 KiB) Downloaded 190 times
0 x

CyberCop
Gnoblar
Posts: 5
Joined: Sat Jan 03, 2009 7:48 am

Re: Ogre CSG Boolean Library (Lib + Source)

Post by CyberCop » Mon Mar 09, 2009 1:44 am

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

dudeabot
Gnome
Posts: 334
Joined: Thu Jun 28, 2007 2:12 pm
Location: Brazil
Contact:

Re: Ogre CSG Boolean Library (Lib + Source)

Post by dudeabot » Mon Mar 09, 2009 2:40 am

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

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

Re: Ogre CSG Boolean Library (Lib + Source)

Post by novant » Thu Apr 16, 2009 2:12 am

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

LinuxInside
Kobold
Posts: 30
Joined: Sun Dec 11, 2011 6:00 pm

Re: Ogre CSG Boolean Library (Lib + Source)

Post by LinuxInside » Sat Dec 24, 2011 5:01 pm

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

Post Reply