Idea for doing a laser beam.

So I’ve been working on figuring out hos to create a laser beam in panda3d. While the general consensus for creating a laser beam seems to be to use particle simulation to generate the beam, I’ve recently thought up a way of using a mesh in stead.

More or less you create a simple polymesh, either procedurally or in a seperate program(i.e. blender or max). you make it like a cylinder or cube that is one unit long(I know that blender units are equal to Panda3d units, dunno about any other programs), but very thin. Then you reparent the mesh to the ‘beam’ object to the thing which is shooting it.

You also attach a collision ray to the beam generator. The collisionray does all the work of determining the collision.

So you shoot the laser beam from the object, and the collision ray checks for a collision. If there is one, you get the location of the collision, deteremine the distance between the beam emitter and the location, then scale the ‘beam mesh’ to that length. Since you made the beam mesh one unit long, this part is easy, merely scale it by a number equal to the distance, a collision ten units away scales the beam mesh by ten which makes it ten units long. If there is no collision, then you just make it really long depending on how big your game world is (maybe 200 units or something like that).

Finally, the mesh is given some kind of basic material that just displays an absolute color which of course will be very bright. Then to make it look more ‘lasery’, just apply a glow filter to it.

For added effect you can also0 just place a point light or glowing sphere at the location of the collision, or a lens flare(can you do a lens flare in panda3d?).

Thoughts anyone?

I’m at work now, but when I get home I’ll start work on a program and then post the code.

I figure that this could be useful if you are trying to get around using particles for whatever reason(for me I’ve been having some trouble with meshdrawer and pyro). Or maybe you want to free up space in the quad or triangle cap for other things.

Didn’t try it, and I am kinda(kinda=absolute beginner) new and interested in this topic, because I am making space invaders clone. But, doesn’t scaling make the object longer on both sides? Eg. it will shoot through the ship player’s controling too. Although there is an easy workaround for this(if it really happens): scale it by distance and move it a bit.

PS There is a big possibility that I am talking nonsense here. I am sorry if that is the case.

I think I forgot to mention that you need move the geometry of the mesh but not the mesh itself all the way over so that its center/pivot point is at one end of it, that way all the scaling goes in only one direction.

panda3d.org/showss.php?shot= … /antarean1

My lazer beams are done with MeshDrawer and blur similar to the Tron demo.

well. I’ve got it working, however I’ve encountered a snag of sorts, for some reason the beam mesh just stops after a certain distance from the camera, or at least it stops being visible. I checked from different viewpoints and while the mesh most definitely is as long as I want it to be, you just cant see the part of the mesh that is too far from the camera. It seems to cut out at a distance of 20 units. there is also a weird aliasing effect too:

Anybody have any thoughts?

It looks like at this distance it became infinity thin where its not showing. Projecting a beam from FPS view like this will not make it look good. I suggest some sort of modeled tube for this.

ok, well it appears that the problem is related to the size of the mesh. I went and scaled up the width of the beam mesh and it was able to stretch further. I’m guessing that the problem is related to panda3d having a problem with rendering really small geometry.

Any ideas how to get around that?

I think the problem is that any graphics card has a problem rendering very small geometry. I suggest making your beam bigger if you want to see it. I also suggest making alpha texture for your beam so that edges are fuzzy, this way you could still see it even if it was small because the texture unit would do its mipmapping magic.

I would suggest modeling various beam meshes, at various tapers for lengths, pointing the larger end at the target.

thanks for the replies guys.

I wound up sort of using your idea treeform.

What I ended up doing was I made a poly mesh in blender out of two polygons that were sandwitched together and their normals pointed in different direction, more or less a double sided polygon. Then I put a laser beam looking texture on it that used transparency.

Now since that only works when the beam is viewed from certain angles, I had two choices. I could have either tried a billboard trick by getting the beam to change its orientation using setR() so that it is always facing the camera. But this would require adding in a complex script. My other choice was to take the mesh and duplicate its geometry three more times, rotating each iteration around the center to make sort of a ‘star’ configuration. I went with the second option. Here is the result:

if you look closely you can see the ‘star’ shape at the end of the beam, but that can be remedied by putting in some kind of effect to simulate a lens flare at the point of the collision. I haven’t put that together yet though.

But you can make it a axial billboard using two lines of code. Check the manual for billboard effects.