1

All definitions of glMatrix 2.2.0 seem to be undefined when included with RequireJS. However, on page inspection, it is being included in the HTML as a script tag.

However the same setup does work with glMatrix 1.3.7.

The require configuration is as follows:

require.config({
baseUrl: 'js/app',
paths: {
    jquery: '../lib/jquery',
    glm: '../lib/gl-matrix'
}
});

require(['main']);

And main.js looks like (jquery works in this instance):

define(function (require) {
var $ = require('jquery');
require('glm');

$(function () {
    var a = mat4.create();
    $('body').html("hello: " + a);
});
});

I also have the same problem with other global-namespace libraries like stats.js.

Although defining the scripts in HTML works, I would preferably like it to work with RequireJS for minimisation/concatenation.

<script src="js/lib/stats.js"></script>
<script src="js/lib/gl-matrix-min.js"></script>

Hopefully I'm missing something obvious with this one, as I'm tearing my hair.

Thanks in advance for any suggestions.

Dan0
  • 459
  • 3
  • 16

1 Answers1

0

I use glmatrix too with require.js, the most recent version has require.js support and for me it seems to work fine.

I have however I slightly different usage with require.js, my modules usually start like this:

define(['lib/glmatrix/gl-matrix'],
    function(glmatrix) {
        var myModule = function() {};
        // use glmatrix.vec3, etc here
        return myModule;
});

Does this work for you?

Andrew
  • 510
  • 5
  • 6
  • Thanks Andrew, I too came to this conclusion and it seems to be the best way of doing it. I ran into trouble as I assumed the glmatrix functions to be global eg 'vec3.create();', without a namespace like 'glmatrix.vec3.create();'. – Dan0 Jul 25 '13 at 01:36