Permalink
Browse files

three.js now works (in some capacity)

  • Loading branch information...
1 parent 80eb5c1 commit 5ee0fa1c4f88677bddb09b65b5d1e80a5802f0de @tmpvar committed Aug 31, 2011
Showing with 93 additions and 86 deletions.
  1. +14 −5 example/threejs/cube.js
  2. +59 −72 example/threejs/getting-started.js
  3. +20 −9 lib/webgl.js
View
19 example/threejs/cube.js
@@ -29,20 +29,17 @@ var windowHalfY = 150;
camera = new THREE.Camera( 70, w / h, 1, 1000 );
camera.position.y = 150;
-camera.position.z = 500;
+camera.position.z = 100;
camera.target.position.y = 150;
scene = new THREE.Scene();
var sphereMaterial = new THREE.MeshLambertMaterial(
{
- color: 0xCC0000
+ color: 0xFFFFFF
});
-// set up the sphere vars
-var radius = 50, segments = 16, rings = 16;
-
// create a new mesh with sphere geometry -
// we will cover the sphereMaterial next!
var sphere = new THREE.Mesh(
@@ -56,6 +53,18 @@ scene.addChild(sphere);
sphere.position.y = 150;
+// create a point light
+var pointLight = new THREE.PointLight( 0xFF0000 );
+
+// set its position
+pointLight.position.x = 10;
+pointLight.position.y = 50;
+pointLight.position.z = 100;
+
+// add to the scene
+scene.addLight(pointLight);
+
+
renderer = new THREE.WebGLRenderer();
renderer.setSize( w, h );
var a = 1000;
View
131 example/threejs/getting-started.js
@@ -21,80 +21,67 @@ var WebGLRenderingContext = require('../lib/webgl.js').WebGLRenderingContext;
var THREE = require('../example/threejs/three.js');
THREE.WebGLRenderer.prototype = {};
-// set the scene size
-var WIDTH = 400,
- HEIGHT = 300;
-
-// set some camera attributes
-var VIEW_ANGLE = 45,
- ASPECT = WIDTH / HEIGHT,
- NEAR = 0.1,
- FAR = 10000;
-
-// get the DOM element to attach to
-// - assume we've got jQuery to hand
-//var $container = $('#container');
-
-// create a WebGL renderer, camera
-// and a scene
-var renderer = new THREE.WebGLRenderer();
-var camera = new THREE.Camera( VIEW_ANGLE,
- ASPECT,
- NEAR,
- FAR );
-var scene = new THREE.Scene();
-
-// the camera starts at 0,0,0 so pull it back
-camera.position.z = 300;
-
-// start the renderer
-renderer.setSize(WIDTH, HEIGHT);
-
-// attach the render-supplied DOM element
-//$container.append(renderer.domElement);
-
-// create the sphere's material
-var sphereMaterial = new THREE.MeshLambertMaterial(
-{
- color: 0xCC0000
-});
-
-// set up the sphere vars
-var radius = 50, segments = 16, rings = 16;
-
-// create a new mesh with sphere geometry -
-// we will cover the sphereMaterial next!
-var sphere = new THREE.Mesh(
- new THREE.SphereGeometry(radius, segments, rings),
- sphereMaterial);
-
-// add the sphere to the scene
-scene.addChild(sphere);
-
-// create a point light
-var pointLight = new THREE.PointLight( 0xFFFFFF );
-
-// set its position
-pointLight.position.x = 10;
-pointLight.position.y = 50;
-pointLight.position.z = 130;
-
-// add to the scene
-scene.addLight(pointLight);
-
-function render() {
- renderer.render(scene, camera);
-}
+
+
+ // set the scene size
+ var WIDTH = 300,
+ HEIGHT = 300;
+
+ // set some camera attributes
+ var VIEW_ANGLE = 45,
+ ASPECT = WIDTH / HEIGHT,
+ NEAR = 0.1,
+ FAR = 10000;
+
+
+ // create a WebGL renderer, camera
+ // and a scene
+ var renderer = new THREE.WebGLRenderer();
+ var camera = new THREE.Camera( VIEW_ANGLE,
+ ASPECT,
+ NEAR,
+ FAR );
+ var scene = new THREE.Scene();
+
+ // the camera starts at 0,0,0 so pull it back
+ camera.position.z = 300;
+
+ // start the renderer
+ renderer.setSize(WIDTH, HEIGHT);
+
+
+ // create the sphere's material
+ var sphereMaterial = new THREE.MeshLambertMaterial(
+ {
+ color: 0xCC0000
+ });
+
+ // set up the sphere vars
+ var radius = 50, segments = 16, rings = 16;
+
+ // create a new mesh with sphere geometry -
+ // we will cover the sphereMaterial next!
+ var sphere = new THREE.Mesh(
+ new THREE.SphereGeometry(radius, segments, rings),
+ sphereMaterial);
+
+ // add the sphere to the scene
+ scene.addChild(sphere);
+
+ // create a point light
+ var pointLight = new THREE.PointLight( 0xFFFFFF );
+
+ // set its position
+ pointLight.position.x = 10;
+ pointLight.position.y = 50;
+ pointLight.position.z = 130;
+
+ // add to the scene
+ scene.addLight(pointLight);
// draw!
-var a = 30;
+var a = 1000;
while(a--) {
- try {
- render();
- } catch (e) {
- console.log(e.stack);
- fail();
- }
+ renderer.render(scene, camera);
webgl_rendering_context_flush();
- webgl_rendering_context_finish();
}
View
29 lib/webgl.js
@@ -35,9 +35,9 @@ interface WebGLActiveInfo {
} else if (result === -1) {
console.log(name, '\nFAILURE! result code was -1 (' + ex +')');
} else if (result && typeof result !== 'function') {
- //console.log(name, '\nOK (' + JSON.stringify(result, null, ' ') + ')');
+ console.log(name, '\nOK (' + JSON.stringify(result, null, ' ') + ')\n');
} else {
- //console.log(name, '\nOK', (new Error()).stack.split('\n')[2]);
+ console.log(name, '\nOK', (new Error()).stack.split('\n')[2], '\n');
}
return result;
};
@@ -100,7 +100,6 @@ interface WebGLActiveInfo {
}
}
that[method] = function() {
- console.log(method)
try {
var args = convertArguments(arguments);
@@ -600,25 +599,31 @@ WebGLRenderingContext.prototype = {
},
getUniformLocation : function getUniformLocation (program, name) {
var ret = webgl_rendering_context_getUniformLocation(program.id, name);
- return (ret >= 0) ? ret : null;
+ return (ret > -1) ? new WebGLUniformLocation(ret) : null;
},
uniform1i : function uniform1i (location, x) {
- webgl_rendering_context_uniform1i(location, x);
+ webgl_rendering_context_uniform1i(location.id, x);
+ },
+ uniform1f : function uniform1f (location, x) {
+ webgl_rendering_context_uniform1f(location.id, x);
},
uniform1fv : function uniform1fv (location, v) {
- webgl_rendering_context_uniform1fv(location, new Float32Array(v));
+ webgl_rendering_context_uniform1fv(location.id, new Float32Array(v));
+ },
+ uniform3f : function uniform3fv(location, x, y, z) {
+ return webgl_rendering_context_uniform3f(location.id, x, y, z);
},
uniform3fv : function uniform3fv(location, array) {
- return webgl_rendering_context_uniform3fv(location, new Float32Array(array));
+ return webgl_rendering_context_uniform3fv(location.id, new Float32Array(array));
},
texParameteri : function texParameteri (target, pname, param) {
webgl_rendering_context_texParameteri(target, pname, param);
},
uniformMatrix3fv : function(location, transpose, value) {
- webgl_rendering_context_uniformMatrix3fv(location, transpose, new Float32Array(value));
+ webgl_rendering_context_uniformMatrix3fv(location.id, transpose, new Float32Array(value));
},
uniformMatrix4fv : function(location, transpose, value) {
- webgl_rendering_context_uniformMatrix4fv(location, transpose, value);
+ webgl_rendering_context_uniformMatrix4fv(location.id, transpose, value);
},
/***************************
@@ -745,6 +750,11 @@ WebGLBuffer.prototype = {
}
};
+function WebGLUniformLocation(id) {
+ this.id = id;
+}
+WebGLUniformLocation.prototype = {};
+
function DOMImage() {
};
@@ -767,5 +777,6 @@ DOMImage.prototype = {
module.exports = {
WebGLRenderingContext : WebGLRenderingContext,
WebGLProgram : WebGLProgram,
+ WebGLUniformLocation : WebGLUniformLocation,
DOMImage : DOMImage
}

1 comment on commit 5ee0fa1

@RH2

best news of the day

Please sign in to comment.