From ac1d3ed555be32f964554988d0e8109cf244cdb1 Mon Sep 17 00:00:00 2001 From: ichuang Date: Fri, 4 Apr 2014 10:40:47 -0400 Subject: [PATCH 1/9] add Label.js (from https://github.com/fourplusone/MathBox.js), extended to add tangent direction for label; update README --- README.md | 18 +++++++++++ build.sh | 1 + src/primitives/Label.js | 68 +++++++++++++++++++++++++++++++++++++++++ vendor/ShaderGraph.js | 2 +- 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/primitives/Label.js diff --git a/README.md b/README.md index 78a5003..8505197 100644 --- a/README.md +++ b/README.md @@ -358,6 +358,7 @@ Axis tickScale: 10, // Integer denoting the base for recursive division. 2 = binary, 10 = decimal arrow: true, // Whether to include an arrow on the axis size: .07, // Size of the arrow relative to the stage + formatter: null // Function which takes index of axis label as argument, and returns text label }) ``` @@ -422,6 +423,16 @@ Grid }) ``` +Label +```javascript +.label({ + position: [0, 0, 0], // location of label + text: 'hello', // text to be displayed + distance: 15, // text sprite anchor point offset + facing: 1 // which axis tangent direction the label should be facing towards +}) +``` + Surface ```javascript .surface({ @@ -455,6 +466,13 @@ Vector }) ``` +Dependencies +------------ + +* vendor/ThreeBox.js -- https://github.com/unconed/ThreeBox.js (use commit tag ff838075a7bea4ba59719f845f466b9c4b2cbafe) +* vendor/ThreeRTT.js -- https://github.com/unconed/ThreeRTT.js +* vendor/ShaderGraph.js -- https://github.com/unconed/ShaderGraph.js + Contributions ------------- diff --git a/build.sh b/build.sh index a5657c7..eb4e208 100755 --- a/build.sh +++ b/build.sh @@ -36,6 +36,7 @@ src/primitives/Vector.js src/primitives/Surface.js src/primitives/BezierSurface.js src/primitives/Platonic.js +src/primitives/Label.js src/renderables/Renderable.js src/renderables/Mesh.js diff --git a/src/primitives/Label.js b/src/primitives/Label.js new file mode 100644 index 0000000..e9e31c5 --- /dev/null +++ b/src/primitives/Label.js @@ -0,0 +1,68 @@ +/** + * Text label at specified position + */ +MathBox.Label = function (options) { + // Allow inheritance constructor + if (options === null) return; + + MathBox.Primitive.call(this, options); +}; + +MathBox.Label.prototype = _.extend(new MathBox.Primitive(null), { + + defaults: function () { + return { + position: [0, 0, 0], + facing: 1, + distance: 15, + style: { + color: new THREE.Color(0x707070), + }, + text: "" + }; + }, + + renderables: function () { + return [ this.labels ]; + }, + + type: function () { + return 'label'; + }, + + adjust: function (viewport, camera) { + var options = this.get(), + // Axis vector direction for labels + p = [0, 0, 0]; + p[options.facing] = 1; + var labelTangent = this.labelTangent; + labelTangent.set.apply(labelTangent, p); + this.labels.show(true); + }, + + make: function () { + var options = this.get(), + position = options.position, + text = options.text, + distance = options.distance, + style = this.style, + labelTangent = this.labelTangent = new THREE.Vector3(); + + var labelOptions = { dynamic: true, distance: distance }; + var labelPoint = new THREE.Vector3(); + labelPoint.set.apply(labelPoint, position) + // label text callback + var callback = function (i) { + return text; + }.bind(this); + + this.labels = new MathBox.Renderable.Labels([labelPoint], labelTangent, callback, labelOptions, style); + }, + +}); + +MathBox.Label.validateArgs = function (options) { + return options; +}; + +MathBox.Primitive.types.label = MathBox.Label; diff --git a/vendor/ShaderGraph.js b/vendor/ShaderGraph.js index 43134b2..6985664 160000 --- a/vendor/ShaderGraph.js +++ b/vendor/ShaderGraph.js @@ -1 +1 @@ -Subproject commit 43134b212f161bfdbd71185d33bb7cc7aaa0f96f +Subproject commit 69856649bd1c5760a2be1f387481cbab3cb8fddf From 8f635f61efe98ab673a7c22837fbeba47bbd8197 Mon Sep 17 00:00:00 2001 From: ichuang Date: Fri, 4 Apr 2014 10:45:10 -0400 Subject: [PATCH 2/9] newly built files --- build/MathBox-bundle.js | 384 ++++++++++++++++++++++++------------ build/MathBox-bundle.min.js | 70 +++---- build/MathBox-core.js | 68 +++++++ build/MathBox-core.min.js | 133 ++++++------- build/MathBox.glsl.html | 28 +++ build/MathBox.js | 384 ++++++++++++++++++++++++------------ build/MathBox.min.js | 70 +++---- 7 files changed, 749 insertions(+), 388 deletions(-) diff --git a/build/MathBox-bundle.js b/build/MathBox-bundle.js index d9695f6..449247d 100644 --- a/build/MathBox-bundle.js +++ b/build/MathBox-bundle.js @@ -40197,26 +40197,14 @@ ThreeBox.preload.html = function (file, name, callback) { var match; // Insert javascript directly - while (match = res.match(/^(|]*type=['"]text\/javascript['"][^>]*>)([\s\S]+?)<\/script>$/m)) { - try { - /* - var script = document.createElement('script'); - script.type = 'text/javascript'; - script.innerHTML = match[2]; - document.body.appendChild(script); - */ - eval('(function () {' + match[2] + '})()'); - } - catch (e) { - console.error(e); - console.error('While evaluating: ' + match[2]); - } - - res = res.replace(match[0], ''); + if (match = res.match(/^]*type=['"]text\/javascript['"][^>]*>([\s\S]+?)<\/script>$/m)) { + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.innerHTML = match[1]; + document.body.appendChild(script); } - // Insert HTML via div - if (res.replace(/\s*/g) != '') { + else { var div = document.createElement('div'); div.innerHTML = res; document.body.appendChild(div); @@ -40264,12 +40252,13 @@ ThreeBox.preload.audio = function (file, name, callback) { // Namespace window.ThreeRTT = window.ThreeRTT || {}; +ThreeRTT.World = function () {}; // Fetch shader from + + \ No newline at end of file diff --git a/build/MathBox.js b/build/MathBox.js index 97efc30..c5c31ef 100644 --- a/build/MathBox.js +++ b/build/MathBox.js @@ -569,26 +569,14 @@ ThreeBox.preload.html = function (file, name, callback) { var match; // Insert javascript directly - while (match = res.match(/^(|]*type=['"]text\/javascript['"][^>]*>)([\s\S]+?)<\/script>$/m)) { - try { - /* - var script = document.createElement('script'); - script.type = 'text/javascript'; - script.innerHTML = match[2]; - document.body.appendChild(script); - */ - eval('(function () {' + match[2] + '})()'); - } - catch (e) { - console.error(e); - console.error('While evaluating: ' + match[2]); - } - - res = res.replace(match[0], ''); + if (match = res.match(/^]*type=['"]text\/javascript['"][^>]*>([\s\S]+?)<\/script>$/m)) { + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.innerHTML = match[1]; + document.body.appendChild(script); } - // Insert HTML via div - if (res.replace(/\s*/g) != '') { + else { var div = document.createElement('div'); div.innerHTML = res; document.body.appendChild(div); @@ -636,12 +624,13 @@ ThreeBox.preload.audio = function (file, name, callback) { // Namespace window.ThreeRTT = window.ThreeRTT || {}; +ThreeRTT.World = function () {}; // Fetch shader from