Beam/Trail/Lightning SceneNode

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Beam/Trail/Lightning SceneNode

Post by Foaly »

This is a BeamSceneNode with many use cases. It can be used to show a static beam, a motion trail or a lightning. With a bit of code, you can make it do many other things.
It supports vertex colors, texture coordinates, shrinking, different interpolation functions, using a custom normal, time based or length based fading, etc.

It's written in C# and uses the newest IrrlichtLime from svn (http://sourceforge.net/p/irrlichtlime/code/HEAD/tree/), you have to compile IrrlichLime yourself.
It shouldn't be hard to port to C++.

You can use this node even for commercial projects without attribution.

Image
The image shows one simple lightning which fades out, many lightnings which flash and a textured motion trail.

Version 1.0, 943 lines, Download: https://dl.dropboxusercontent.com/u/572 ... neNode.zip
Zip contains two files:
BeamSceneNode.cs: The class itself and some helpers.
Interpolation.cs: Some interpolation types.

Usage:

Simple user controlled beam, aligned to view, length based, local space:

Code: Select all

 
BeamSceneNode beam = new BeamSceneNode(parent, smgr, thickness, segmentCount, false, false, false);
beam.MaximumLength = //set length
//beam.SegmentLength //or set segment length
//Add segments. You can add segments every time, old segments will fade out
beam.AddSegment(position);
beam.AddSegment(position2);
beam.AddSegment(position3);
//Set material...
beam.Material.Type = MaterialType.TransparentAlphaChannel; //For texture use
beam.Material.SetTexture(...)
beam.Drop(); //Drop if we don't need it anymore.
 
Motion trail, locked to Y-Axis rotation:

Code: Select all

 
BeamSceneNode beam = BeamSceneNode.CreateTrail(attatch, thickness, segmentCount);
beam.FadeOutTime = 1000; //1 second trail
beam.FadeMesh = false; //don't shrink mesh
beam.ClipLastSegment = true; //makes last segment follow, important for texturing
beam.LockedAxis = BeamSceneNode.Axis.Y; //only rotate around Y axis. remove this, if you want it to rotate in every direction.
 
//Setup material...
//...
 
beam.Drop();
 
Flash which appears once and fades out 250ms, with complete vertex color material:

Code: Select all

 
BeamSceneNode lightning = BeamSceneNode.CreateLightning(smgr.RootNode, startPos, endPos, 4f, 5f, 16, device.Timer.Time, 250);
lightning.SetVertexColors(new Color(255, 255, 255, 255), new Color(255, 255, 255, 0), new Color(255, 255, 255, 255), new Color(255, 255, 255, 0)); //Inside color white, outside color transparent
lightning.Material.Type = MaterialType.TransparentVertexAlpha;
lightning.Drop();
 

I hope you like it!
If you find bugs, have any questions or feature requests, please ask!
Last edited by Foaly on Fri Aug 01, 2014 9:21 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Beam/Trail/Lightning SceneNode

Post by CuteAlien »

Looks nice. But please consider using a source-control system like https://code.google.com/ or github or a similar services for posting your code. That's way easier to read and use for others than zip's and it's probably even a lot easier for you to put such code online and keep it up-to-date (at least once you are used to it - and it's really worth getting used to such tools).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Re: Beam/Trail/Lightning SceneNode

Post by Foaly »

Well, I didn't want to create a repository for a single scene node...
I think a 8KB works for now.
If I add more classes, I will host it on some project hosting site, but I don't think any special version control is necessary.
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Beam/Trail/Lightning SceneNode

Post by CuteAlien »

Ah well - we're glad about all open source. But I promise that once you get used to online repositories you won't go back ;-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply