Editor style Grid SceneNode [Updated: Sept. 27, 2009]

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Editor style Grid SceneNode [Updated: Sept. 27, 2009]

Post by Dark_Kilauea »

I needed a simple grid for my editor, so I wrote a scenenode to do it for me. This node has a few features:
  • Can be dynamically sized.
  • User settable grid spacing
  • Can accent every nth line with a different color
  • Can be scaled, rotated, ect like any other scene node.
  • Everything set in the constructor can be later changed via SetFoo() and GetFoo() functions.
  • Can Color Lines Along the Respective Axises.
  • Has a clone() method
The source is fully commented, so it should be simple to setup and use.

Notes:
Setting accentlineoffset to 0 causes accentlines to not be rendered.
If you need a grid on the XY or ZY axis, simply rotate this node by 90 degrees in the appropiate axis.
This node creates an XZ grid by default, which should be fine for normal use.

Usage:

Code: Select all

scene::CGridSceneNode* grid = new scene::CGridSceneNode(smgr->getRootSceneNode(), smgr);
grid->drop();
You can get it here:
http://darkkilauea.deathtouchstudios.co ... neNode.zip

Screenshot:
Image

Final Note:
Mohaps' Grid class was very helpful in creating this node. Big thanks goes out to him.

[Update Sept. 27, 2009]
- Disabled z-writing for the grid to fix a flickering bug (thanks to ceyron)

[Update Aug. 21, 2009]
- Added a fix to a nasty crash bug by vins

[Update Oct. 23, 2008]
- Added JP's optimizations to the rendering process
- Put the node in the irr::scene namespace
- Modifed includes to only include what is necessary (less bloat)
- Renamed Clone() to clone() to fit with ISceneNode
- Grid can be regenerated using RegenerateGrid()
- Minor bug fixes

[Update Jan. 08, 2008]
- Code Cleaned up to work with Doxygen better
- Various bug fixes with wrong types and default variable values
- Culling now defaults to EAC_FRUSTUM_BOX
- Clone() now copies the material as well

[Update Jan. 07, 2008]
- Added Clone() method
- Fixed issue with signed integers, now the size, spacing, ect fields are u32.
- Culling defaults to EAC_BOX

[Update Jan. 04, 2008]
- Added new feature: Colored axis lines.
- Fixed floating point bug with BB Box.
- Cleaned up rendering code to speed things up under stress.
Last edited by Dark_Kilauea on Sun Sep 27, 2009 3:40 pm, edited 12 times in total.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
VioletAlixe
Posts: 28
Joined: Thu Oct 04, 2007 9:03 pm

Nice work!

Post by VioletAlixe »

I tested this out in my map-editor. At a grid size greater than 1,200 and a grid spacing of 4, I still have no drop in frame rate at all. Changeable colors, simple to implement, and fully compatible as a scene node. It's so easy, no wonder it's #1. Err, wrong commercial.

Anyway, I benchmarked this all in D3D on a Vista laptop and still managed 4 FPS on a 4 spaced grid with a gridsize of ONE HUNDRED THOUSAND. Seriously. I only need 500 and it runs like a dream. I strongly recommend this to anyone who want to know where the hell something is in their map without having to move the camera every ten seconds. Great work on finally making this a scene node.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

How about posting it here :
http://www.irrlicht3d.org/wiki/index.ph ... SceneNodes


Very well coded, nice work.

Just how did you do that light in the screenshot?

Edit:
Here is my screen shot:
Image
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Posted on the wiki, MasterGod :)

The light is part of my editor, it's a simple billboard.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

I get this warning when I use your class:

Code: Select all

aabbox3df Box;
....
Box = aabbox3df(-size/2,-1,-size/2,size/2,1,size/2);
VC9 wrote: cgridscenenode.h(33) : warning C4244: 'argument' : conversion from 'int' to 'irr::f32', possible loss of data
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

Just add ".0" or "f" to the numbers in the parameter list so they're threated/converted to float - or just cast them.

Would vote for it to be included in the irrlicht source as it's something that's cery reusable imo.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Thanks.
And I really thinks adding this class would be a great idea too.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

strange error....

Thanks for the support though! :)

[edit] Problem solved, Update Uploaded!. Just download the same file in the first post. If for some reason you still need the older one, grab CGridSceneNodeOLD.zip

Added a new feature as well and cleaned up the rendering code a bit (should run a bit faster under strain, otherwise it's not noticeable). Now the node is capable of rendering colored lines along axises. Of course the colors are freely changeable using GetFoo() and SetFoo() functions.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

You might want to add http:// so it gets a clicky link? :)
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Ah, so thats what this forum looks for in highlighting links....


Thanks :)
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

There was another warning that I'd mentioned if I knew you're going to release it again so sorry bout that..
The m_size is s32 and in the loops you check it against u32, e.g:

Code: Select all

		//X-axis lines
		for(u32 x = 0; x <= m_size*2; x+= m_spacing)
		{
			core::vector3df start = leftMost;
			start.X += x ;

			core::vector3df end = rightMost;
			end.X = start.X;

			//std::cout<<"Drawing Line From : "<<start.X<<","<<start.Y<<","<<start.Z<<" to "<<end.X<<","<<end.Y<<","<<end.Z<<"\n";
			driver->draw3DLine(start,end,m_gridcolor);
		}
IMO the size should be u32 cause negative size isn't right logically..

Oh and can you post a screen shot of the new feature maybe..?

P.S
Try in VC -> Ctrl+A, Alt+F8
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

A little feature request - a Clone() method.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

I'll see what I can do about the clone() method, I need to read up on how its supposed to work.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

It would be interesting to replace the drawing of 100's or 1000's of lines (which consumer hardware may render as degenerate triangles anyway) with a single alpha-tested texture drawn as a quad, trilinear filtered, with vertex colour modulation to change the line colour. The texture would have the "grid" drawn onto it.
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

It would be faster, yes, but I'm not so comfortable with irrlicht's texture modification functions. Maybe someone else would like to take a stab at it?
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
Post Reply