├── .gitignore ├── .npmignore ├── LICENSE.md ├── README.md ├── build.js ├── demo.frag ├── demo.js ├── demo.vert ├── expand.js ├── index.html ├── index.js ├── load-browser.js ├── load.js ├── package.json ├── snowden-hi.obj └── snowden-lo.obj /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | .DS_Store 4 | bundle.js 5 | hi.js 6 | lo.js 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | .DS_Store 4 | bundle.js 5 | test 6 | test.js 7 | demo 8 | example 9 | .npmignore 10 | demo.* 11 | index.html 12 | snowden-hi.obj 13 | snowden-lo.obj 14 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright (c) 2014 [stackgl](http://github.com/stackgl/) contributors 5 | 6 | *stackgl contributors listed at * 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # snowden 2 | 3 | [![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges) 4 | 5 | 3D mesh of [Snowden's Bust](http://www.wired.com/2015/05/now-can-3-d-print-copy-nycs-illegal-snowden-bust/). 6 | 7 | [![snowden](http://i.imgur.com/5UQDjiK.png)](http://stack.gl/snowden/) 8 | 9 | [View demo](http://stack.gl/snowden/). 10 | 11 | [Original source](http://www.thingiverse.com/thing:815042/). 12 | 13 | ## Usage 14 | 15 | [![NPM](https://nodei.co/npm/snowden.png)](https://nodei.co/npm/snowden/) 16 | 17 | Like the [bunny](http://ghub.io/bunny) module, you can pull 18 | this in as a 19 | [simplicial complex](http://ghub.io/simplicial-complex). 20 | 21 | ### `snowden.positions` 22 | 23 | A list of positions in the mesh. 24 | 25 | ``` javascript 26 | [ [0.432908423, 1.28938290, 0.43289809], 27 | [0.448930292, 0.90342890, 0.93289402], // ... 28 | ] 29 | ``` 30 | 31 | ### `snowden.cells` 32 | 33 | A list of faces in the mesh, indexed according to 34 | `snowden.positions`. 35 | 36 | ``` javascript 37 | [ [0, 1, 2], 38 | [2, 1, 3], // ... 39 | ] 40 | ``` 41 | 42 | ## Contributing 43 | 44 | See [stackgl/contributing](https://github.com/stackgl/contributing) for details. 45 | 46 | ## License 47 | 48 | MIT. See [LICENSE.md](http://github.com/stackgl/snowden/blob/master/LICENSE.md) for details. 49 | -------------------------------------------------------------------------------- /build.js: -------------------------------------------------------------------------------- 1 | const obj = require('parse-obj') 2 | const path = require('path') 3 | const fs = require('fs') 4 | 5 | ;[path.join(__dirname, 'snowden-lo.obj') 6 | , path.join(__dirname, 'snowden-hi.obj') 7 | ].forEach(function(src) { 8 | obj(fs.createReadStream(src), function(err, result) { 9 | if (err) throw err 10 | 11 | var out = '' 12 | 13 | var positions = flatten(rotate(result.vertexPositions)) 14 | var cells = flatten(flip(result.facePositions)) 15 | 16 | positions = new Buffer(new Uint8Array(new Float32Array(positions).buffer)).toString('base64') 17 | cells = new Buffer(new Uint8Array(new Uint32Array(cells).buffer)).toString('base64') 18 | 19 | out += ';exports.positions = require("./load")(Float32Array, ' 20 | out += JSON.stringify(positions) 21 | out += ')' 22 | out += ';exports.cells = require("./load")(Uint32Array, ' 23 | out += JSON.stringify(cells) 24 | out += ')' 25 | 26 | var dst = src.replace(/snowden-(lo|hi)\.obj$/, '$1.js') 27 | 28 | fs.writeFileSync(dst, out) 29 | }) 30 | }) 31 | 32 | 33 | function flatten(arr) { 34 | var out = [] 35 | var j = 0 36 | 37 | for (var i = 0; i < arr.length; i++) { 38 | out[j++] = arr[i][0] 39 | out[j++] = arr[i][1] 40 | out[j++] = arr[i][2] 41 | } 42 | 43 | return out 44 | } 45 | 46 | function rotate(positions) { 47 | for (var i = 0; i < positions.length; i++) { 48 | var x = positions[i][0] 49 | var y = positions[i][1] 50 | var z = positions[i][2] 51 | 52 | positions[i][0] = x 53 | positions[i][1] = -z 54 | positions[i][2] = -y 55 | } 56 | 57 | return positions 58 | } 59 | 60 | function flip(cells) { 61 | for (var i = 0; i < cells.length; i++) { 62 | var x = cells[i][0] 63 | var y = cells[i][1] 64 | var z = cells[i][2] 65 | 66 | cells[i][0] = x 67 | cells[i][1] = z 68 | cells[i][2] = y 69 | } 70 | 71 | return cells 72 | } 73 | -------------------------------------------------------------------------------- /demo.frag: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | varying vec3 vnormal; 4 | varying vec3 veye; 5 | varying vec3 vpos; 6 | uniform float time; 7 | 8 | #pragma glslify: cookt = require('glsl-specular-cook-torrance') 9 | #pragma glslify: orenn = require('glsl-diffuse-oren-nayar') 10 | 11 | void main() { 12 | vec3 ldir = normalize(vec3(0, 1, 0.5)); 13 | vec3 vdir = normalize(veye - vpos); 14 | 15 | float dif = orenn(ldir, vdir, vnormal, 0.3, 1.0); 16 | float spec = cookt(ldir, vdir, vnormal, 0.2, 0.7); 17 | 18 | vec3 color = vec3(0.9, 0.5, 0.3) * dif + spec * vec3(0.9, 0.7, 0.6); 19 | 20 | color += vec3(0.005, 0.003, 0.002); 21 | color = pow(color, vec3(0.4545)); 22 | 23 | gl_FragColor = vec4(color, 1); 24 | } 25 | -------------------------------------------------------------------------------- /demo.js: -------------------------------------------------------------------------------- 1 | var canvas = document.body.appendChild(document.createElement('canvas')) 2 | var camera = require('canvas-orbit-camera')(canvas) 3 | var gl = require('gl-context')(canvas, render) 4 | var perspective = require('gl-mat4/perspective') 5 | var Geom = require('gl-geometry') 6 | var eye = require('eye-vector') 7 | var Shader = require('gl-shader') 8 | var glslify = require('glslify') 9 | var normals = require('normals') 10 | 11 | var model = require('./') 12 | var proj = new Float32Array(16) 13 | var view = new Float32Array(16) 14 | var snowden = Geom(gl) 15 | .attr('position', model) 16 | .attr('normal', normals.vertexNormals(model.cells, model.positions)) 17 | 18 | var start = Date.now() 19 | var shader = Shader(gl 20 | , glslify('./demo.vert') 21 | , glslify('./demo.frag') 22 | ) 23 | 24 | camera.distance = 12 25 | 26 | function render() { 27 | const width = gl.drawingBufferWidth 28 | const height = gl.drawingBufferHeight 29 | 30 | gl.viewport(0, 0, width, height) 31 | gl.clearColor(0, 0, 0, 1) 32 | gl.clear(gl.COLOR_BUFFER_BIT) 33 | gl.enable(gl.CULL_FACE) 34 | gl.enable(gl.DEPTH_TEST) 35 | 36 | camera.view(view) 37 | camera.tick() 38 | perspective(proj, Math.PI / 4, width / height, 0.01, 100) 39 | 40 | snowden.bind(shader) 41 | shader.uniforms.time = (Date.now() - start) / 1000 42 | shader.uniforms.proj = proj 43 | shader.uniforms.view = view 44 | shader.uniforms.eye = eye(view) 45 | snowden.draw() 46 | } 47 | 48 | window.addEventListener('resize' 49 | , require('canvas-fit')(canvas) 50 | , false 51 | ) 52 | -------------------------------------------------------------------------------- /demo.vert: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform mat4 proj; 4 | uniform mat4 view; 5 | uniform vec3 eye; 6 | 7 | attribute vec3 position; 8 | attribute vec3 normal; 9 | varying vec3 vnormal; 10 | varying vec3 veye; 11 | varying vec3 vpos; 12 | 13 | void main() { 14 | vnormal = normal; 15 | vpos = position; 16 | veye = eye; 17 | 18 | gl_Position = proj * view * vec4(position, 1); 19 | } 20 | -------------------------------------------------------------------------------- /expand.js: -------------------------------------------------------------------------------- 1 | module.exports = expand 2 | 3 | function expand(data) { 4 | var arr = [] 5 | var j = 0 6 | 7 | for (var i = 0; i < data.length; i) { 8 | arr[j++] = [ data[i++], data[i++], data[i++] ] 9 | } 10 | 11 | return arr 12 | } 13 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | snowden 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /load-browser.js: -------------------------------------------------------------------------------- 1 | var expand = require('./expand') 2 | 3 | module.exports = function(TypedArray, data) { 4 | var str = atob(data) 5 | var data = [] 6 | 7 | for (var i = 0; i < str.length; i++) { 8 | var c = str.charCodeAt(i) 9 | data.push(c) 10 | } 11 | 12 | return expand(new TypedArray(new Uint8Array(data).buffer)) 13 | } 14 | -------------------------------------------------------------------------------- /load.js: -------------------------------------------------------------------------------- 1 | var expand = require('./expand') 2 | 3 | module.exports = function(TypedArray, data) { 4 | var buffer = new Buffer(data, 'base64') 5 | var number = new Uint8Array(buffer) 6 | 7 | return expand(new TypedArray(number.buffer)) 8 | } 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "snowden", 3 | "version": "1.0.1", 4 | "description": "3D mesh of Snowden's Bust", 5 | "main": "index.js", 6 | "license": "MIT", 7 | "scripts": { 8 | "start": "budo demo.js:bundle.js --transform glslify", 9 | "bundle": "browserify demo.js --transform glslify | uglifyjs -cm > bundle.js" 10 | }, 11 | "browser": { 12 | "./load.js": "./load-browser.js" 13 | }, 14 | "author": { 15 | "name": "Hugh Kennedy", 16 | "email": "hughskennedy@gmail.com", 17 | "url": "http://hughsk.io/" 18 | }, 19 | "dependencies": { 20 | "parse-obj": "0.0.0" 21 | }, 22 | "devDependencies": { 23 | "browserify": "^10.0.0", 24 | "budo": "^4.0.0", 25 | "canvas-fit": "^1.4.0", 26 | "canvas-orbit-camera": "^1.0.2", 27 | "eye-vector": "0.0.0", 28 | "gl-context": "^0.1.1", 29 | "gl-geometry": "^1.0.3", 30 | "gl-mat4": "^1.1.2", 31 | "gl-shader": "^4.0.1", 32 | "glsl-diffuse-oren-nayar": "^1.0.2", 33 | "glsl-specular-cook-torrance": "^2.0.1", 34 | "glslify": "^2.1.2", 35 | "normals": "^1.0.1", 36 | "uglify-js": "^2.4.20" 37 | }, 38 | "repository": { 39 | "type": "git", 40 | "url": "git://github.com/stackgl/snowden.git" 41 | }, 42 | "keywords": [ 43 | "ecosystem:stackgl" 44 | ], 45 | "homepage": "https://github.com/stackgl/snowden", 46 | "bugs": { 47 | "url": "https://github.com/stackgl/snowden/issues" 48 | } 49 | } 50 | --------------------------------------------------------------------------------