Quote from WebGL - General/Working Group Info:
Quote Originally Posted by giles
Quote Originally Posted by Coolcat
I think I will do some performance tests over the weekend.
I'd love to see the results!
I didn't really implemented several ways to load meshes, but I thought about some time. The idea was to include meshes and shader data into one single library file. An ResourceManager class does load one or more of this library files, e.g. one default file and some specific files for the current map or level. After that you can request resources by ID, for example "defaultshader.vs".

First thing I tried was to load data from an XML file like this:
Code :
	<vertexshader id="defaultshader.vs">
		uniform mat4 uModelViewProjection;
		uniform mat4 uModelView;
		void main() {
	<fragmentshader id="defaultshader.fs">
		varying vec3 vPosition;
		varying vec3 vNormal;
		varying vec2 vTexCoord;
		void main()
			gl_FragColor = ...
	<mesh id="spheres.mesh">
This is pretty fast, because browsers are designed to parse XML data. To parse the meshdata itself I put brackets ("[...]") around the string and use the eval function, which does return an array. This is also fast, because eval is implemented in native code. I didn't try an JavaScript implementation, because even if eval is slow, it should be at least as fast as a JS implementation.

However, the problem with XML files is that getElementById() does not work out of the box. You need to specify the DTD. Because Firefox (didn't try other browsers) does not support external DTD you need to include the DTD definition in every library file. The DTD for the document above looks like this:
Code :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library [
	<!ELEMENT library (vertexshader|fragmentshader|mesh)*>
	<!ELEMENT vertexshader (#PCDATA)>
	<!ATTLIST vertexshader id ID #REQUIRED>
	<!ELEMENT fragmentshader (#PCDATA)>
	<!ATTLIST fragmentshader id ID #REQUIRED>
	<!ELEMENT mesh (vertices, indices?)>
	<!ELEMENT vertices (#PCDATA)>
	<!ATTLIST vertices type CDATA #REQUIRED>
	<!ELEMENT indices (#PCDATA)>

Because this DTD stuff is annoying, I tried to use JSON. Actually this was the idea of Jeff Chimene at GWT groups. JSON is a really simple format, it's just JavaScript code. You can parse the complete file at once with the eval function. As result you will get an JavaScript object structure.

The library file above does look like this:
Code :
"defaultshader.fs" : "varying vec3 vPosition;\nvarying vec3 vNormal;\nvarying vec2 vTexCoord;\n\nuniform vec3 uLightPos;\n\nconst float cShininess = 100.0;\nconst vec4 cAmbient = vec4(0.2,0.2,0.2,1);\nconst vec4 cDiffuse = vec4(0.5,0.5,0.5,0);\nconst vec4 cSpecular = vec4(1,1,1,0);\n\nvoid main() {\n	vec3 lightDir = normalize(uLightPos-vPosition);\n	vec3 normal = normalize(vNormal);\n	gl_FragColor = cAmbient;\n	float diffuse = max(dot(lightDir, normal), 0.0);\n	gl_FragColor += cDiffuse * diffuse;\n	//gl_FragColor = vec4(lightDir,1.0);\n	if (diffuse > 0.0) {\n		vec3 r = normalize( (2.0 * dot(normal, lightDir) * normal) - lightDir );\n		float f = dot(r, normalize(-vPosition));\n		float specular = pow(max(f, 0.0), cShininess);\n		gl_FragColor += cSpecular * specular;\n	}\n}\n",
"defaultshader.vs" : "uniform mat4 uModelViewProjection;\nuniform mat4 uModelView;\nuniform mat4 uNormalMatrix;\n\nattribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec3 aTexCoord;\n\nvarying vec3 vPosition;\nvarying vec3 vNormal;\nvarying vec2 vTexCoord;\n\nvoid main() {\n	gl_Position = uModelViewProjection * vec4(aPosition, 1.0);\n	vPosition = uModelView * vec4(aPosition, 1.0);\n	vTexCoord = aTexCoord;\n	//vNormal = normalize(uNormalMatrix * aNormal);\n	vNormal = normalize(uNormalMatrix * vec4(aNormal, 0.0)).xyz;\n}\n",
"spheres.mesh" : {
	"vertices" : [
	"indices" : [

=> result: JSON is fast and also easy to implement, since you just need to use eval which does the parsing for you. The only drawback is you need some kind of tool which does convert shader files into this format since JSON does not support multi-line strings. However, a tool that does convert newlines into "\n" is not that hard to write.

In both cases you need a tool that converts your mesh data into the required format. I wrote such a tool based on lib3ds for Linux x86_64, it does also convert shader files. I will provide the source code if some one asks for it.

If have also implemented that ResourceManager stuff, but it is integrated into an complete WebGL engine. This engine is an module for GoogleWebToolkit and provides an WebGL wrapper, the ResourceManager, some Math classes and classes for comfortable use of Shaders, Textures, Meshes and so on. Since GWT does compile Java 1.5 code into JavaScript, you don't have to bother about JavaScript. Coding in Java is much better However, it will take some weeks until I can release that engine.