From 39d5a56f7aea283592cc7637a939e8cd1a1fbf70 Mon Sep 17 00:00:00 2001 From: mccannd Date: Sun, 29 Jan 2017 22:07:28 -0500 Subject: [PATCH 1/6] added basic implementation --- src/main.js | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 159 insertions(+), 5 deletions(-) diff --git a/src/main.js b/src/main.js index fd8fbd4..e6d529e 100755 --- a/src/main.js +++ b/src/main.js @@ -4,6 +4,80 @@ const THREE = require('three'); // older modules are imported like this. You shouldn't have to worry about this much import Framework from './framework' + +var numEdge = 20; +var numCols = 15; +var numRows = 4; +var endPt = new THREE.Vector3(5.0, 0, 1.5); + +var gradients = [new THREE.Vector2(1.0, 0), new THREE.Vector2(-1.0, 0), + new THREE.Vector2(0, 1.0), new THREE.Vector2(0, -1.0), + new THREE.Vector2(0.7071, 0.7071), new THREE.Vector2(-0.7071, 0.7071), + new THREE.Vector2(0.7071, -0.7071), new THREE.Vector2(-0.7071, -0.7071)]; + +var pHash = [151,160,137,91,90,15, + 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, + 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, + 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166, + 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, + 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196, + 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123, + 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, + 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9, + 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, + 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, + 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, + 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180]; + +function lerp(a, b, t) { + return (t * b + (1.0 - t) * a); +} + + +function bezier(c1, c2, c3, c4, t) { + var c12 = c1.lerp(c2, t); + var c23 = c2.lerp(c3, t); + var c34 = c3.lerp(c4, t); + + var c1223 = c12.lerp(c23, t); + var c2334 = c23.lerp(c34, t); + + return c1223.lerp(c2334, t); +} + +//2D perlin noise +function getNoise(u, v) { + var xs = u * 8.0; + var ys = v * 8.0; + + var xlb = Math.floor(xs); + var ylb = Math.floor(ys); + + pHash[pHash[xlb + pHash[ylb]]]; + var i = pHash[pHash[xlb + pHash[ylb]]] / 256.0; + var g = gradients[Math.floor(i * 8.0)]; + var p = new THREE.Vector2(xs - xlb, ys - ylb); + var dll = g.dot(p); + + i = pHash[pHash[xlb + 1 + pHash[ylb]]] / 256.0; + g = gradients[Math.floor(i * 8.0)]; + p = new THREE.Vector2(xs - xlb - 1.0, ys - ylb); + var dlr = g.dot(p); + + i = pHash[pHash[xlb + pHash[ylb + 1]]] / 256.0; + g = gradients[Math.floor(i * 8.0)]; + p = new THREE.Vector2(xs - xlb, ys - ylb - 1.0); + var dul = g.dot(p); + + i = pHash[pHash[xlb + 1 + pHash[ylb + 1]]] / 256.0; + g = gradients[Math.floor(i * 8.0)]; + p = new THREE.Vector2(xs - xlb - 1.0, ys - ylb - 1.0); + var dur = g.dot(p); + + return lerp(lerp(dll, dlr, xs), lerp(dul, dur, xs), ys); +} + + // called after the scene loads function onLoad(framework) { var scene = framework.scene; @@ -33,6 +107,19 @@ function onLoad(framework) { scene.background = skymap; + + var curve = new THREE.CubicBezierCurve3( + new THREE.Vector3( 0, 0, 0 ), + new THREE.Vector3( 2, 0, -0.1 ), + new THREE.Vector3(endPt.x - 0.5, 0, endPt.z - 1.0), + endPt + ); + var geom = new THREE.Geometry(); + geom.vertices = curve.getPoints(numEdge); + //var mat = new THREE.LineBasicMaterial( { color : 0xff0000 } ); + //var curveObject = new THREE.Line(geom, mat); + //scene.add(curveObject); + // load a simple obj mesh var objLoader = new THREE.OBJLoader(); objLoader.load('/geo/feather.obj', function(obj) { @@ -41,8 +128,62 @@ function onLoad(framework) { var featherGeo = obj.children[0].geometry; var featherMesh = new THREE.Mesh(featherGeo, lambertWhite); - featherMesh.name = "feather"; - scene.add(featherMesh); + var wingGroup = new THREE.Group(); + wingGroup.name = "wing"; + //featherMesh.name = "feather"; + //scene.add(featherMesh); + //featherMesh.isVisible = false; + // wing tip feathers + for (var i = 0; i < numEdge; i++) { + var t = i / (1.0 * numEdge - 1.0); + var copyGeo = new THREE.Mesh(featherGeo, lambertWhite); + copyGeo.position.copy(geom.vertices[i]); + + + var rotY = (1.0 - t * t * t) * Math.PI / 1.8; + var rotX = Math.PI / 9.0; + var rotZ = -Math.PI / 18.0; + var u = copyGeo.position.x / endPt.x; + var v = (copyGeo.position.y + 0.1) / 1.6; + + copyGeo.rotateY(rotY); + copyGeo.rotateX(Math.PI / 9.0); + copyGeo.scale.set(0.7 + 0.5 * t*t*t, 1, 1); + copyGeo.name = "tipFeather " + i; + copyGeo.userData = {xR: rotX, yR: rotY, zR: rotZ, u: u, v: v}; + wingGroup.add(copyGeo); + } + + + // grid feathers + for (var y = 0; y < numRows; y++) { + for (var x = 0; x < numCols; x++) { + var cPos = curve.getPointAt(x / (1.0 * numCols) - ((y % 2 == 0) ? 0.0 : 0.05)); + var xPos = cPos.x; + var zPos = lerp(cPos.z, 1.9, (y + 1.0)/ (numRows + 1.0)); + + var t = x / (1.0 * numCols); + var rotX = Math.PI / 9.0; + var rotY = (1.0 - t * t * t) * Math.PI / 2.0; + var rotZ = 0;//Math.PI / 18.0; + var u = copyGeo.position.x / endPt.x; + var v = (copyGeo.position.y + 0.1) / 1.6; + + var copyGeo = new THREE.Mesh(featherGeo, lambertWhite); + copyGeo.position.set(xPos, 0, zPos); + copyGeo.scale.set(0.5, 1, 2); + + copyGeo.rotateY(rotY); + copyGeo.rotateX(rotX); + copyGeo.rotateZ(rotZ); + + copyGeo.userData = {xR: rotX, yR: rotY, zR: rotZ, u: u, v: v}; + copyGeo.name = "gridFeather " + (y * 10 + x); + wingGroup.add(copyGeo); + } + } + scene.add(wingGroup); + }); // set camera position @@ -61,11 +202,24 @@ function onLoad(framework) { // called on frame updates function onUpdate(framework) { - var feather = framework.scene.getObjectByName("feather"); - if (feather !== undefined) { + var wing = framework.scene.getObjectByName("wing"); + if (wing !== undefined) { // Simply flap wing var date = new Date(); - feather.rotateZ(Math.sin(date.getTime() / 100) * 2 * Math.PI / 180); + var wRot = Math.sin(date.getTime() / 500) * Math.PI / 4.0; + wing.rotation.set(0, -0.25 * wRot, 0.5 * wRot); + var allFeathers = wing.children; + for (var i = 0; i < allFeathers.length; i++) { + var f = allFeathers[i]; + var noise = getNoise(f.userData.u, f.userData.v); + f.rotation.set(f.userData.xR, + f.userData.yR + (0.035 * Math.sin(Math.PI * noise + date.getTime() / 250)), + f.userData.zR + (0.03 * Math.sin(Math.PI * noise + date.getTime() / 100)) + + (1.0 - f.userData.yR / (Math.PI / 2.0)) * wRot * 1.5); + + // vertical displacement based on + f.position.set(f.position.x, f.position.x * f.position.x / endPt.x * wRot, f.position.z); + } } } From 05866ba9a4778cbc67ad68b42e4be2881529cbb3 Mon Sep 17 00:00:00 2001 From: mccannd Date: Tue, 31 Jan 2017 16:10:39 -0500 Subject: [PATCH 2/6] added interactions, bias --- npm-debug.log | 47 ++++++++++ src/main.js | 236 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 210 insertions(+), 73 deletions(-) create mode 100644 npm-debug.log diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 0000000..ae272d7 --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,47 @@ +0 info it worked if it ends with ok +1 verbose cli [ 'D:\\nodejs\\node.exe', +1 verbose cli 'D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', +1 verbose cli 'start' ] +2 info using npm@3.10.10 +3 info using node@v6.9.4 +4 verbose run-script [ 'prestart', 'start', 'poststart' ] +5 info lifecycle @~prestart: @ +6 silly lifecycle @~prestart: no script for prestart, continuing +7 info lifecycle @~start: @ +8 verbose lifecycle @~start: unsafe-perm in lifecycle true +9 verbose lifecycle @~start: PATH: D:\nodejs\node_modules\npm\bin\node-gyp-bin;D:\Procedural\Project2-Toolbox-Functions\node_modules\.bin;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\cmd;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\usr\bin;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\usr\share\git-tfs;C:\Users\Daniel\AppData\Local\Apps\2.0\YOA1XVNR.8H2\8AP2TGYV.2O2\gith..tion_317444273a93ac29_0003.0003_665ccbdbd3c2d8d4;C:\Users\Daniel\AppData\Local\GitHub\lfs-amd64_1.3.1;C:\Users\Daniel\AppData\Local\Apps\2.0\YOA1XVNR.8H2\8AP2TGYV.2O2\gith..tion_317444273a93ac29_0003.0003_665ccbdbd3c2d8d4\NativeBinaries\x86;C:\Users\Daniel\introcs\java\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\nodejs\;D:\MinGW\bin;C:\Users\Daniel\introcs\j3d\bin;C:\Users\Daniel\introcs\bin;C:\Users\Daniel\introcs\java\bin;D:\Qt\5.5\mingw492_32\bin;C:\Users\Daniel\AppData\Local\Microsoft\WindowsApps;C:\Users\Daniel\AppData\Roaming\npm;C:\Program Files (x86)\MSBuild\14.0\bin\;C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64;C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\ +10 verbose lifecycle @~start: CWD: D:\Procedural\Project2-Toolbox-Functions +11 silly lifecycle @~start: Args: [ '/d /s /c', 'webpack-dev-server --hot --inline' ] +12 silly lifecycle @~start: Returned: code: 3221225786 signal: null +13 info lifecycle @~start: Failed to exec start script +14 verbose stack Error: @ start: `webpack-dev-server --hot --inline` +14 verbose stack Exit status 3221225786 +14 verbose stack at EventEmitter. (D:\nodejs\node_modules\npm\lib\utils\lifecycle.js:255:16) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at EventEmitter.emit (events.js:191:7) +14 verbose stack at ChildProcess. (D:\nodejs\node_modules\npm\lib\utils\spawn.js:40:14) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at ChildProcess.emit (events.js:191:7) +14 verbose stack at maybeClose (internal/child_process.js:877:16) +14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) +15 verbose pkgid @ +16 verbose cwd D:\Procedural\Project2-Toolbox-Functions +17 error Windows_NT 10.0.14393 +18 error argv "D:\\nodejs\\node.exe" "D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" +19 error node v6.9.4 +20 error npm v3.10.10 +21 error code ELIFECYCLE +22 error @ start: `webpack-dev-server --hot --inline` +22 error Exit status 3221225786 +23 error Failed at the @ start script 'webpack-dev-server --hot --inline'. +23 error Make sure you have the latest version of node.js and npm installed. +23 error If you do, this is most likely a problem with the package, +23 error not with npm itself. +23 error Tell the author that this fails on your system: +23 error webpack-dev-server --hot --inline +23 error You can get information on how to open an issue for this project with: +23 error npm bugs +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/src/main.js b/src/main.js index e6d529e..7caeba4 100755 --- a/src/main.js +++ b/src/main.js @@ -4,17 +4,44 @@ const THREE = require('three'); // older modules are imported like this. You shouldn't have to worry about this much import Framework from './framework' +// wing control parameters +var settings = { + numEdge: 20, + numCols: 15, + numRows: 4, + noiseScale: 4.0, + noiseIntensity: 1.0, + noiseFrequency: 1.0, + cullThreshold: -0.25, + flapRange: Math.PI / 4.0, + flapSpeed: 1.0, + curveBias: 0.1, + color: [0, 128, 255] +}; -var numEdge = 20; -var numCols = 15; -var numRows = 4; var endPt = new THREE.Vector3(5.0, 0, 1.5); +var curve = new THREE.CubicBezierCurve3( + new THREE.Vector3( 0, 0, 0 ), + new THREE.Vector3( 2, 0, -0.1 ), + new THREE.Vector3(endPt.x - 0.5, 0, endPt.z - 1.0), + endPt +); + +var curve2 = new THREE.CubicBezierCurve3( + new THREE.Vector3( 0, 0, endPt.z ), + new THREE.Vector3( 2, 0, endPt.z + 0.5 ), + new THREE.Vector3(endPt.x - 1, 0, endPt.z - 0.5), + endPt +); + +// gradients for improved perlin noise var gradients = [new THREE.Vector2(1.0, 0), new THREE.Vector2(-1.0, 0), new THREE.Vector2(0, 1.0), new THREE.Vector2(0, -1.0), new THREE.Vector2(0.7071, 0.7071), new THREE.Vector2(-0.7071, 0.7071), new THREE.Vector2(0.7071, -0.7071), new THREE.Vector2(-0.7071, -0.7071)]; +// hash table for improved perlin noise var pHash = [151,160,137,91,90,15, 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, @@ -29,11 +56,25 @@ var pHash = [151,160,137,91,90,15, 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180]; + function lerp(a, b, t) { return (t * b + (1.0 - t) * a); } +function bias(b, t) { + return Math.pow(t, Math.log(b) / Math.log(0.5)); +} + +function gain(g, t) { + if (t < 0.5) { + return bias(1 - g, 2 * t) / 2; + } else { + return 1 - bias(1 - g, 2 - 2 * t) / 2; + } +} + +// currently unused function bezier(c1, c2, c3, c4, t) { var c12 = c1.lerp(c2, t); var c23 = c2.lerp(c3, t); @@ -47,13 +88,12 @@ function bezier(c1, c2, c3, c4, t) { //2D perlin noise function getNoise(u, v) { - var xs = u * 8.0; - var ys = v * 8.0; + var xs = u * settings.noiseScale; + var ys = v * settings.noiseScale; var xlb = Math.floor(xs); var ylb = Math.floor(ys); - pHash[pHash[xlb + pHash[ylb]]]; var i = pHash[pHash[xlb + pHash[ylb]]] / 256.0; var g = gradients[Math.floor(i * 8.0)]; var p = new THREE.Vector2(xs - xlb, ys - ylb); @@ -69,58 +109,36 @@ function getNoise(u, v) { p = new THREE.Vector2(xs - xlb, ys - ylb - 1.0); var dul = g.dot(p); + i = pHash[pHash[xlb + 1 + pHash[ylb + 1]]] / 256.0; g = gradients[Math.floor(i * 8.0)]; p = new THREE.Vector2(xs - xlb - 1.0, ys - ylb - 1.0); var dur = g.dot(p); - return lerp(lerp(dll, dlr, xs), lerp(dul, dur, xs), ys); -} + return lerp(lerp(dll, dlr, xs - xlb), lerp(dul, dur, xs - xlb), ys - ylb); +} -// called after the scene loads -function onLoad(framework) { +// function that ENTIRELY deletes and reloads the wing +// yes, this is quite inefficient +function loadWing(framework) { var scene = framework.scene; var camera = framework.camera; var renderer = framework.renderer; var gui = framework.gui; var stats = framework.stats; - // Basic Lambert white - var lambertWhite = new THREE.MeshLambertMaterial({ color: 0xaaaaaa, side: THREE.DoubleSide }); - - // Set light - var directionalLight = new THREE.DirectionalLight( 0xffffff, 1 ); - directionalLight.color.setHSL(0.1, 1, 0.95); - directionalLight.position.set(1, 3, 2); - directionalLight.position.multiplyScalar(10); - - // set skybox - var loader = new THREE.CubeTextureLoader(); - var urlPrefix = '/images/skymap/'; - - var skymap = new THREE.CubeTextureLoader().load([ - urlPrefix + 'px.jpg', urlPrefix + 'nx.jpg', - urlPrefix + 'py.jpg', urlPrefix + 'ny.jpg', - urlPrefix + 'pz.jpg', urlPrefix + 'nz.jpg' - ] ); - - scene.background = skymap; - + var wing = framework.scene.getObjectByName("wing"); + if (wing !== undefined) { + scene.remove(wing); + } + // basic shader + var lambertWhite = new THREE.MeshPhongMaterial({ color: 0xaaaaaa, side: THREE.DoubleSide }); - var curve = new THREE.CubicBezierCurve3( - new THREE.Vector3( 0, 0, 0 ), - new THREE.Vector3( 2, 0, -0.1 ), - new THREE.Vector3(endPt.x - 0.5, 0, endPt.z - 1.0), - endPt - ); var geom = new THREE.Geometry(); - geom.vertices = curve.getPoints(numEdge); - //var mat = new THREE.LineBasicMaterial( { color : 0xff0000 } ); - //var curveObject = new THREE.Line(geom, mat); - //scene.add(curveObject); + geom.vertices = curve.getPoints(settings.numEdge); - // load a simple obj mesh + // load the feather var objLoader = new THREE.OBJLoader(); objLoader.load('/geo/feather.obj', function(obj) { @@ -130,12 +148,10 @@ function onLoad(framework) { var featherMesh = new THREE.Mesh(featherGeo, lambertWhite); var wingGroup = new THREE.Group(); wingGroup.name = "wing"; - //featherMesh.name = "feather"; - //scene.add(featherMesh); - //featherMesh.isVisible = false; - // wing tip feathers - for (var i = 0; i < numEdge; i++) { - var t = i / (1.0 * numEdge - 1.0); + + // make all feathers along the edge of the wing + for (var i = 0; i < settings.numEdge; i++) { + var t = i / (1.0 * settings.numEdge - 1.0); var copyGeo = new THREE.Mesh(featherGeo, lambertWhite); copyGeo.position.copy(geom.vertices[i]); @@ -144,7 +160,7 @@ function onLoad(framework) { var rotX = Math.PI / 9.0; var rotZ = -Math.PI / 18.0; var u = copyGeo.position.x / endPt.x; - var v = (copyGeo.position.y + 0.1) / 1.6; + var v = (copyGeo.position.y + 0.1) / (endPt.z + 0.1); copyGeo.rotateY(rotY); copyGeo.rotateX(Math.PI / 9.0); @@ -155,36 +171,75 @@ function onLoad(framework) { } - // grid feathers - for (var y = 0; y < numRows; y++) { - for (var x = 0; x < numCols; x++) { - var cPos = curve.getPointAt(x / (1.0 * numCols) - ((y % 2 == 0) ? 0.0 : 0.05)); - var xPos = cPos.x; - var zPos = lerp(cPos.z, 1.9, (y + 1.0)/ (numRows + 1.0)); + // make the rest of the feathers + for (var y = 0; y < settings.numRows; y++) { + for (var x = 0; x < settings.numCols; x++) { + var cPos = curve.getPointAt(x / (1.0 * settings.numCols) - ((y % 2 == 0) ? 0.0 : 0.05)); + var cPos2 = curve2.getPointAt(x / (1.0 * settings.numCols) - ((y % 2 == 0) ? 0.0 : 0.05)); + var xPos = lerp(cPos.x, cPos2.x, (y + 1.0)/ (settings.numRows + 1.0)); + var zPos = lerp(cPos.z, cPos2.z, (y + 1.0)/ (settings.numRows + 1.0)); - var t = x / (1.0 * numCols); + var t = x / (1.0 * settings.numCols); var rotX = Math.PI / 9.0; var rotY = (1.0 - t * t * t) * Math.PI / 2.0; var rotZ = 0;//Math.PI / 18.0; - var u = copyGeo.position.x / endPt.x; - var v = (copyGeo.position.y + 0.1) / 1.6; + var u = xPos / endPt.x; + var v = (zPos + 0.1) / (endPt.z + 0.5); - var copyGeo = new THREE.Mesh(featherGeo, lambertWhite); - copyGeo.position.set(xPos, 0, zPos); - copyGeo.scale.set(0.5, 1, 2); + var n = getNoise(u, v); - copyGeo.rotateY(rotY); - copyGeo.rotateX(rotX); - copyGeo.rotateZ(rotZ); + // if the noise is below the threshold, the feather will not appear + if (n > settings.cullThreshold) { + var copyGeo = new THREE.Mesh(featherGeo, lambertWhite); + copyGeo.position.set(xPos, 0, zPos); + copyGeo.scale.set(0.5 * 4.0 / settings.numRows, 1, 2); + //rotateFeather(x, y, copyGeo); + copyGeo.rotateY(rotY); + copyGeo.rotateX(rotX); + copyGeo.rotateZ(rotZ); - copyGeo.userData = {xR: rotX, yR: rotY, zR: rotZ, u: u, v: v}; - copyGeo.name = "gridFeather " + (y * 10 + x); - wingGroup.add(copyGeo); + copyGeo.userData = {xR: rotX, yR: rotY, zR: rotZ, u: u, v: v}; + copyGeo.name = "gridFeather " + (y * 10 + x); + wingGroup.add(copyGeo); + } } } scene.add(wingGroup); }); +} + +// called after the scene loads +function onLoad(framework) { + var scene = framework.scene; + var camera = framework.camera; + var renderer = framework.renderer; + var gui = framework.gui; + var stats = framework.stats; + + // Basic Lambert white + var lambertWhite = new THREE.MeshLambertMaterial({ color: 0xaaaaaa, side: THREE.DoubleSide }); + + // Set light + var directionalLight = new THREE.DirectionalLight( 0xffffff, 1 ); + directionalLight.color.setHSL(0.1, 1, 0.95); + directionalLight.position.set(1, 3, 2); + directionalLight.position.multiplyScalar(10); + + // set skybox + var loader = new THREE.CubeTextureLoader(); + var urlPrefix = '/images/skymap/'; + + var skymap = new THREE.CubeTextureLoader().load([ + urlPrefix + 'px.jpg', urlPrefix + 'nx.jpg', + urlPrefix + 'py.jpg', urlPrefix + 'ny.jpg', + urlPrefix + 'pz.jpg', urlPrefix + 'nz.jpg' + ] ); + + scene.background = skymap; + + // create the wing + loadWing(framework); // set camera position camera.position.set(0, 1, 5); @@ -198,6 +253,28 @@ function onLoad(framework) { gui.add(camera, 'fov', 0, 180).onChange(function(newVal) { camera.updateProjectionMatrix(); }); + + + // add all gui options + // NOTE: I'm aware that recreating the whole wing is extremely inelegant. + // will likely change in the future, but not by the original submission + gui.add(settings, 'noiseScale', 2.0, 16.0); + gui.add(settings, 'noiseIntensity', 0.0, 10.0); + gui.add(settings, 'noiseFrequency', 0.0, 3.0); + gui.add(settings, 'cullThreshold', { None: -1.0, Low: -0.3, + Med: -0.2, High: -0.1, Half: 0.0 } ).onChange(function(newVal) { + loadWing(framework); + }); + gui.add(settings, 'flapRange', 0.0, Math.PI / 3.0); + gui.add(settings, 'flapSpeed', 0.1, 3.0); + gui.addColor(settings, 'color'); + gui.add(settings, 'numCols', 10, 20).onChange(function(newVal) { + loadWing(framework); + }); + gui.add(settings, 'numRows', 2, 6).onChange(function(newVal) { + loadWing(framework); + }); + gui.add(settings, 'curveBias', 0.1, 0.5); } // called on frame updates @@ -206,19 +283,32 @@ function onUpdate(framework) { if (wing !== undefined) { // Simply flap wing var date = new Date(); - var wRot = Math.sin(date.getTime() / 500) * Math.PI / 4.0; - wing.rotation.set(0, -0.25 * wRot, 0.5 * wRot); + var wRot = Math.sin(settings.flapSpeed * date.getTime() / 500) * settings.flapRange; + wing.rotation.set(0, -0.25 * wRot, 0.5 * wRot); + var allFeathers = wing.children; for (var i = 0; i < allFeathers.length; i++) { var f = allFeathers[i]; var noise = getNoise(f.userData.u, f.userData.v); + + // rotation: + // x stays the same + // y and z affected by noise + // z is affected by local y rot, adding wing curvature f.rotation.set(f.userData.xR, - f.userData.yR + (0.035 * Math.sin(Math.PI * noise + date.getTime() / 250)), - f.userData.zR + (0.03 * Math.sin(Math.PI * noise + date.getTime() / 100)) + + f.userData.yR + (0.035 * settings.noiseIntensity * + Math.sin(Math.PI * noise + settings.noiseFrequency * date.getTime() / 250)), + f.userData.zR + (0.03 * settings.noiseIntensity * + Math.sin(Math.PI * noise + settings.noiseFrequency * date.getTime() / 100)) + (1.0 - f.userData.yR / (Math.PI / 2.0)) * wRot * 1.5); - // vertical displacement based on - f.position.set(f.position.x, f.position.x * f.position.x / endPt.x * wRot, f.position.z); + f.material.color.setRGB(settings.color[0] / 255.0, settings.color[1] / 255.0, settings.color[2] / 255.0); + // curvature of the wing is quadratic and based on horizontal position + + var t = f.position.x / endPt.x; + t = bias(t, settings.curveBias); + + f.position.set(f.position.x, t * endPt.x * wRot, f.position.z); } } } From c43f586355f772c1ecfb25b64103ed19d2a66ec3 Mon Sep 17 00:00:00 2001 From: mccannd Date: Tue, 31 Jan 2017 16:10:59 -0500 Subject: [PATCH 3/6] 'update' --- npm-debug.log | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 npm-debug.log diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index ae272d7..0000000 --- a/npm-debug.log +++ /dev/null @@ -1,47 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ 'D:\\nodejs\\node.exe', -1 verbose cli 'D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', -1 verbose cli 'start' ] -2 info using npm@3.10.10 -3 info using node@v6.9.4 -4 verbose run-script [ 'prestart', 'start', 'poststart' ] -5 info lifecycle @~prestart: @ -6 silly lifecycle @~prestart: no script for prestart, continuing -7 info lifecycle @~start: @ -8 verbose lifecycle @~start: unsafe-perm in lifecycle true -9 verbose lifecycle @~start: PATH: D:\nodejs\node_modules\npm\bin\node-gyp-bin;D:\Procedural\Project2-Toolbox-Functions\node_modules\.bin;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\cmd;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\usr\bin;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\usr\share\git-tfs;C:\Users\Daniel\AppData\Local\Apps\2.0\YOA1XVNR.8H2\8AP2TGYV.2O2\gith..tion_317444273a93ac29_0003.0003_665ccbdbd3c2d8d4;C:\Users\Daniel\AppData\Local\GitHub\lfs-amd64_1.3.1;C:\Users\Daniel\AppData\Local\Apps\2.0\YOA1XVNR.8H2\8AP2TGYV.2O2\gith..tion_317444273a93ac29_0003.0003_665ccbdbd3c2d8d4\NativeBinaries\x86;C:\Users\Daniel\introcs\java\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\nodejs\;D:\MinGW\bin;C:\Users\Daniel\introcs\j3d\bin;C:\Users\Daniel\introcs\bin;C:\Users\Daniel\introcs\java\bin;D:\Qt\5.5\mingw492_32\bin;C:\Users\Daniel\AppData\Local\Microsoft\WindowsApps;C:\Users\Daniel\AppData\Roaming\npm;C:\Program Files (x86)\MSBuild\14.0\bin\;C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64;C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\ -10 verbose lifecycle @~start: CWD: D:\Procedural\Project2-Toolbox-Functions -11 silly lifecycle @~start: Args: [ '/d /s /c', 'webpack-dev-server --hot --inline' ] -12 silly lifecycle @~start: Returned: code: 3221225786 signal: null -13 info lifecycle @~start: Failed to exec start script -14 verbose stack Error: @ start: `webpack-dev-server --hot --inline` -14 verbose stack Exit status 3221225786 -14 verbose stack at EventEmitter. (D:\nodejs\node_modules\npm\lib\utils\lifecycle.js:255:16) -14 verbose stack at emitTwo (events.js:106:13) -14 verbose stack at EventEmitter.emit (events.js:191:7) -14 verbose stack at ChildProcess. (D:\nodejs\node_modules\npm\lib\utils\spawn.js:40:14) -14 verbose stack at emitTwo (events.js:106:13) -14 verbose stack at ChildProcess.emit (events.js:191:7) -14 verbose stack at maybeClose (internal/child_process.js:877:16) -14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) -15 verbose pkgid @ -16 verbose cwd D:\Procedural\Project2-Toolbox-Functions -17 error Windows_NT 10.0.14393 -18 error argv "D:\\nodejs\\node.exe" "D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" -19 error node v6.9.4 -20 error npm v3.10.10 -21 error code ELIFECYCLE -22 error @ start: `webpack-dev-server --hot --inline` -22 error Exit status 3221225786 -23 error Failed at the @ start script 'webpack-dev-server --hot --inline'. -23 error Make sure you have the latest version of node.js and npm installed. -23 error If you do, this is most likely a problem with the package, -23 error not with npm itself. -23 error Tell the author that this fails on your system: -23 error webpack-dev-server --hot --inline -23 error You can get information on how to open an issue for this project with: -23 error npm bugs -23 error Or if that isn't available, you can get their info via: -23 error npm owner ls -23 error There is likely additional logging output above. -24 verbose exit [ 1, true ] From cd717400a60faa029e8f0a1aaca0f5cb49fec46a Mon Sep 17 00:00:00 2001 From: mccannd Date: Tue, 31 Jan 2017 16:14:26 -0500 Subject: [PATCH 4/6] deploy fix --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index c80e8a3..b14310a 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "scripts": { - "start": "webpack-dev-server --hot --inline", - "build": "webpack", - "deploy": "rm -rf npm-debug.log && git checkout master && git commit -am 'update' && gh-pages-deploy" - }, + "start": "webpack-dev-server --hot --inline", + "build": "webpack", + "deploy": "gh-pages-deploy" +}, "gh-pages-deploy": { "prep": [ "build" From ef754eda822138eadf22614bdcb79bc05126bdd5 Mon Sep 17 00:00:00 2001 From: mccannd Date: Tue, 31 Jan 2017 16:16:37 -0500 Subject: [PATCH 5/6] path fix --- src/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index 7caeba4..7769bfe 100755 --- a/src/main.js +++ b/src/main.js @@ -140,7 +140,7 @@ function loadWing(framework) { // load the feather var objLoader = new THREE.OBJLoader(); - objLoader.load('/geo/feather.obj', function(obj) { + objLoader.load('geo/feather.obj', function(obj) { // LOOK: This function runs after the obj has finished loading var featherGeo = obj.children[0].geometry; @@ -228,7 +228,7 @@ function onLoad(framework) { // set skybox var loader = new THREE.CubeTextureLoader(); - var urlPrefix = '/images/skymap/'; + var urlPrefix = 'images/skymap/'; var skymap = new THREE.CubeTextureLoader().load([ urlPrefix + 'px.jpg', urlPrefix + 'nx.jpg', From 2e2d86f4f405bfc562486a0cded8e01301b0e821 Mon Sep 17 00:00:00 2001 From: mccannd Date: Tue, 31 Jan 2017 16:25:17 -0500 Subject: [PATCH 6/6] readme --- README.md | 87 +++++-------------------------------------------------- 1 file changed, 7 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 1410c30..1b5c3e6 100644 --- a/README.md +++ b/README.md @@ -1,82 +1,9 @@ -# [Project2: Toolbox Functions](https://github.com/CIS700-Procedural-Graphics/Project2-Toolbox-Functions) +#LINK TO THE DEMO: [HERE](https://mccannd.github.io/Project2-Toolbox-Functions/) -## Overview +Usage and features: -The objective of this assignment is to procedurally model and animate a bird wing. Let's get creative! - -Start by forking and then cloning [this repository](https://github.com/CIS700-Procedural-Graphics/Project2-Toolbox-Functions) - -## Modeling - -##### Reference images - -Search for three or more images of a bird wing (or any flying creature, really) in order to provide yourself reference material, as you're going to base your modeling and animation from these images. For the more artistic minds, feel free to sketch your own concept. - -##### Make wing curve - -Begin with a 3D curve for your basic wing shape. Three.js provides classes to create many different types of curves, so you may use whatever type of curve you prefer. - -##### Distribute feathers - -We have provided a simple feather model from which to begin. You are not required to use this model if you have others that you prefer. From this base, you must duplicate the feather to model a complete wing, and your wing should consist of at least thirty feathers. Distribute points along the curve you created previously; you will append the feather primitives to the curve at these points. Make sure that you modify the size, orientation, and color of your feathers depending on their location on the wing. - -Feel free to diversify your wings by using multiple base feather models. - -## Animation - -Add a wind force to your scene, and parameterize its direction and speed. You will use this wind force to animate the feathers of your wing by vibrating them slightly. Using Dat.GUI, allow the user to modify these wind parameters. Please note that we don't care about your feather motion being physically accurate, as long as it looks nice. - -Additionally, animate the control points of your wing curve to make the wing flap, and allow the user to control the speed of the wing flapping. - -## Interactivity - -Using Dat.GUI and the examples provided in the reference code, allow the user to adjust the following controls: - -1. The curvature of the wing's basic shape -2. Feather distribution -3. Feather size -4. Feather color -5. Feather orientation -6. Flapping speed -7. Flapping motion - -## For the Overachievers - -Suggestions: -- Make a pretty iridescent or otherwise feather appropriate shader. -- Otherwise, going the extra mile for this assignment is really in the polish! - -## Submission - -- Create a folder called `references` to include your reference images. - -- Update `README.md` to contain a solid description of your project - -- Publish your project to gh-pages. `npm run deploy`. It should now be visible at http://username.github.io/repo-name - -- Create a [pull request](https://help.github.com/articles/creating-a-pull-request/) to this repository, and in the comment, include a link to your published project. - -- Submit the link to your pull request on Canvas. - -## Getting Started - -1. [Install Node.js](https://nodejs.org/en/download/). Node.js is a JavaScript runtime. It basically allows you to run JavaScript when not in a browser. For our purposes, this is not necessary. The important part is that with it comes `npm`, the Node Package Manager. This allows us to easily declare and install external dependencies such as [three.js](https://threejs.org/), [dat.GUI](https://workshop.chromeexperiments.com/examples/gui/#1--Basic-Usage), and [glMatrix](http://glmatrix.net/). Some other packages we'll be using make it significantly easier to develop your code and create modules for better code reuse and clarity. These tools make it _signficantly_ easier to write code in multiple `.js` files without globally defining everything. - -2. Fork and clone your repository. - -3. In the root directory of your project, run `npm install`. This will download all of those dependencies. - -4. Do either of the following (but I highly recommend the first one for reasons I will explain later). - - a. Run `npm start` and then go to `localhost:7000` in your web browser - - b. Run `npm run build` and then go open `index.html` in your web browser - - You should hopefully see the framework code with a 3D cube at the center of the screen! - - -## Developing Your Code -All of the JavaScript code is living inside the `src` directory. The main file that gets executed when you load the page as you may have guessed is `main.js`. Here, you can make any changes you want, import functions from other files, etc. The reason that I highly suggest you build your project with `npm start` is that doing so will start a process that watches for any changes you make to your code. If it detects anything, it'll automagically rebuild your project and then refresh your browser window for you. Wow. That's cool. If you do it the other way, you'll need to run `npm build` and then refresh your page every time you want to test something. - -## Publishing Your Code -We highly suggest that you put your code on GitHub. One of the reasons we chose to make this course using JavaScript is that the Web is highly accessible and making your awesome work public and visible can be a huge benefit when you're looking to score a job or internship. To aid you in this process, running `npm run deploy` will automatically build your project and push it to `gh-pages` where it will be visible at `username.github.io/repo-name`. \ No newline at end of file +Feathers can be culled with perlin noise. Use the drop down menu. +Options for the find animation are controlled by options labelled as noise. Control the speed, intensity and scale of this noise with sliders. +Use the color picker to change the color. +Number of feathers can be changed with numRow and numCol. BUG: Make sure to click and not drag these sliders +The wing has a simple sinusoidal flap. Its curvature is determined by curveBias. You can use the range and speed sliders to change the flap.