Saturday, June 2, 2012

Modular Gladius

‹prev | My Chain | next›

I was able to get the "old-develop" branch of Gladius working last night. Tonight, I hope to get the newer stuff working. Per comments from Alan Kligman, Gladius is undergoing a major rewrite so the new "develop" branch will not work quite the same. Still, I hope to get it working tonight.

Much of the current effort in Gladius is focused on modularizing the engine, which should make swapping parts in and out much easier. I have very little idea what those parts might be, but I will find out. Anyhow, some of the stuff that used to be in "old-develop" has moved into separate GitHub repositories. There is also a common repository, plain-old "gladius", which has some example code. In fact, I think that might include the example code that I used last night, rewritten for the newer Gladius.

To find out, I checkout the git repository:
git clone
There is a "cube" example in there, which sounds suspiciously like the example I got working last night. I try that again by copying the HTML into my express.js server:
➜  public git:(master) ✗ pwd
➜  public git:(master) cp ../../gladius/examples/cube/index.html .
I edit the HTML to reflect the location of the Javascript files in my application:
<!DOCTYPE html>
    <script src="/scripts/gladius-core.js"></script>
    <script src="/scripts/gladius-cubicvr.js"></script>
    <script src="/scripts/cube.js"></script>
    <title>Gladius Cube Example</title>
    <canvas style="float: left; margin: 10px"
      id="test-canvas" width="500" height="500">
I already have a gladius-core.js that I compiled the other night. But I will need gladius-cubicvr.js and cube.js:
➜  public git:(master) ✗ cp ../../gladius/gladius-cubicvr.js scripts
➜  public git:(master) ✗ cp ../../gladius/examples/cube/cube.js scripts
It seems that something is hard-coding procedural-material.js and procedural-mesh.js in the server's /assets directory so I move that in as well:
➜  public git:(master) ✗ mkdir assets
➜  public git:(master) ✗ cp ../../gladius/examples/assets/procedural-* assets
With that I am ready to access the example cube:

Ooh, neat! That is a much more interesting example than the one from last night. The cube in the middle spins around while a smaller cube orbits around it.

Dang, that was really easy. I could have saved myself some work and angst had I started there. Ah, who am I kidding? I love the pain of messing about with things that don't quite work. Anyhow....

I would like to convert that to require.js since that is how Gladius code is supposed to be developed. So I remove all of the <script> tags, replacing them with the usual require.js <script> tag and the actual require statement:
  <script src='/scripts/require.js'></script>
  baseUrl: 'scripts'
require(['gladius-core', 'gladius-cubicvr'],
  function(Gladius, cubicvrExtension){

    // copy cube.js here

  <body><!-- canvas here --></body>
I configure require.js to look for its scripts under the /scripts path. Then I require 'gladius-core' and 'gladius-cubicvr'. With that, I copy the contents of cube.js directly in my page's <script> tag—with one change. Instead of registering the cubicvr extension from a global object:
engine.registerExtension( Gladius["gladius-cubicvr"], cubicvrOptions );
I can use the cubicvrExtension variable corresponding to the gladius-cubicvr library:
engine.registerExtension( cubicvrExtension, cubicvrOptions );
And it just works!

Tomorrow, I think I'll figure out what a "cubic vr" is. Or maybe what a "procedural mesh" is. There is a lot I do not know, which should make for a fun adventure.

Day #405

No comments:

Post a Comment