Last active
November 16, 2015 02:18
-
-
Save Saqoosha/1c5cc6b6b27a503cacac to your computer and use it in GitHub Desktop.
Revisions
-
Saqoosha revised this gist
Nov 16, 2015 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ position quaternion scale face_vertices eyemouth_vertices length 3223692 min -1.729493 max 663.247126 0 65535 -1.729493 663.247126 MAE 0.002579241523183628 -
Saqoosha created this gist
Nov 16, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ var fs = require('fs') var data = JSON.parse(fs.readFileSync('keyframes.json')) for (var key in data.user.property) { console.log(key) } // console.log(data.user.property.position) var position = data.user.property.position var vertices = [] data.user.property.face_vertices.forEach((v) => { vertices.push.apply(vertices, v) }) console.log('length', vertices.length) var min = Number.MAX_VALUE var max = Number.MIN_VALUE for (var i = 0; i < vertices.length; i++) { var v = vertices[i] if (v < min) min = v if (v > max) max = v } console.log('min', min, 'max', max) function mapToShort(v, imin, imax) { return Math.round((v - imin) / (imax - imin) * 0xffff) } console.log(mapToShort(min, min, max)) console.log(mapToShort(max, min, max)) function mapToFloat(v, imin, imax) { return (imax - imin) * (v / 0xffff) + imin } console.log(mapToFloat(mapToShort(min, min, max), min, max)) console.log(mapToFloat(mapToShort(max, min, max), min, max)) var sum = 0 var buffer = new Buffer(vertices.length * 2) for (var i = 0; i < vertices.length; i++) { var v = mapToShort(vertices[i], min, max) buffer.writeUInt16LE(mapToShort(vertices[i], min, max), i * 2) var d = vertices[i] - mapToFloat(v, min, max) sum += Math.abs(d) } sum /= vertices.length console.log('MAE', sum) // var buffer = new Buffer(vertices.length * 4) // for (var i = 0; i < vertices.length; i++) { // buffer.writeFloatLE(vertices[i], i * 4) // } // fs.writeFileSync('position.json', JSON.stringify(vertices)) fs.writeFileSync('position16.bin', buffer)