Code Cleanup

Did some much-needed code cleanup. Moved a bunch of global variables that I was experimenting with into the objects where they belong. Now, for example, each moving object has its own “velocity” member and each object that can fire a projectile owns its array of “bullet” objects, and so on. Not glamorous, but work that eventually has to be done. The thing I’m most happy about is that I didn’t overthink it. I just put things where they made sense, without trying to architect a complicated solution for any possible thing that I might want to add in the future. That’s a bad habit that I have, but I’m doing it less often.

Version 0.0.1.1 here.

Latest version here.

Shots Fired

I added code to handle mouse click events. Clicking now fires, which is cool enough that I thought it was worth calling it version 0.0.1.0. It feels much more like the beginnings of a game now. I just had to work out some math for rotations and learn about how BabylonJS’s coordinate system deals with parent/child meshes. Pretty straightforward, which is refreshing.

Check out version 0.0.1.0 here.

Latest version here.

Materials

Got some simple materials working. Struggled for a while because nothing I changed seemed to have any effect. Finally figured out that the problem was that I’m using mesh “instances” instead of actual meshes for each individual object on the screen, and instances can’t have their own unique material. Instances are a technique used to draw lots of copies of the same mesh without hurting performance. Each one can be moved, rotated, etc, but certain things (like the material) is the same for all instances of a mesh.

Here’s an example of BablyonJS drawing a thousand instances of a single cube.

In the image at the top of this post, you can see some transparent materials on those little dots. Those are my bullet meshes. I want them to be much brighter and have a glowy effect. Just need to learn a little more about the material system. It can do just about anything, with one notable exception being lots of independent lights. You’re only allowed eight lights in a scene, which is a really old-school restriction. That was a limitation of graphics cards in the 1990s. Modern engines allow you to have thousands of lights with barely any performance loss. BabylonJS claims to support 16 (on some systems) but it crashes for me if I try to go beyond eight.

Also added pause/unpause via the escape key.

Version 0.0.0.4 here.

Latest version here.