-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
719 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
|
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
|
||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | ||
|
||
class LatkFrame { | ||
|
||
constructor(frame_number) { | ||
|
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
|
||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | ||
|
||
class LatkLayer { | ||
|
||
constructor(name) { | ||
|
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
|
||
|
||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | ||
|
||
class LatkPoint { | ||
|
||
|
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
|
||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | ||
|
||
// Adapted from SharpQuill by @JoanCharmant | ||
|
||
class QuillLoader { | ||
|
||
constructor() { | ||
this.ready = false; | ||
this.json; | ||
this.bytes; | ||
this.strokes = []; | ||
this.numStrokes; | ||
} | ||
|
||
static read(url) { | ||
let ql = new QuillLoader(); | ||
|
||
JSZipUtils.getBinaryContent(url, function(err, data) { | ||
if (err) { | ||
throw err; // or handle err | ||
} | ||
|
||
let zip = new JSZip(); | ||
zip.loadAsync(data).then(function () { | ||
// https://github.com/Stuk/jszip/issues/375 | ||
let entries = Object.keys(zip.files).map(function (name) { | ||
return zip.files[name]; | ||
}); | ||
|
||
// A tilt zipfile should contain three items: thumbnail.png, data.sketch, metadata.json | ||
zip.file("Quill.json").async("string").then(function(response) { | ||
ql.json = JSON.parse(response); | ||
|
||
zip.file("Quill.qbin").async("arraybuffer").then(function(response) { | ||
ql.bytes = new Uint8Array(response); | ||
ql.parse(); | ||
//console.log("read " + ql.bytes.length + " bytes"); | ||
ql.ready = true; | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
return ql; | ||
} | ||
|
||
parse() { | ||
const data = new DataView(this.bytes.buffer); | ||
|
||
const children = this.json["Sequence"]["RootLayer"]["Implementation"]["Children"]; | ||
|
||
for (let i=0; i < children.length; i++) { | ||
const childNode = children[i]; | ||
|
||
// skip the child node if it contains no drawings | ||
let drawingCount = 0; | ||
try { | ||
drawingCount = childNode["Implementation"]["Drawings"].length; | ||
} catch (e) { | ||
continue; | ||
} | ||
|
||
for (let j=0; j < drawingCount; j++) { | ||
const drawingNode = childNode["Implementation"]["Drawings"][j]; | ||
|
||
const dataFileOffsetString = drawingNode["DataFileOffset"]; | ||
|
||
const dataFileOffset = parseInt("0x" + dataFileOffsetString); | ||
|
||
const numNodeStrokes = data.getInt32(dataFileOffset, true); | ||
this.numStrokes += numNodeStrokes; | ||
|
||
let offset = dataFileOffset + 4; | ||
|
||
for (let k = 0; k < numNodeStrokes; k++) { | ||
offset += 36; | ||
|
||
const numVertices = data.getInt32(offset, true); | ||
|
||
const positions = []; | ||
const colors = []; | ||
const widths = []; | ||
|
||
offset += 4; | ||
|
||
for (let l = 0; l < numVertices; l++) { | ||
const x = data.getFloat32(offset + 0, true); // x | ||
const y = data.getFloat32(offset + 4, true); // y | ||
const z = data.getFloat32(offset + 8, true); // z | ||
positions.push(createVector(x, y, z)); | ||
|
||
offset += 36; | ||
|
||
const r = data.getFloat32(offset + 0, true) * 255; // r | ||
const g = data.getFloat32(offset + 4, true) * 255; // g | ||
const b = data.getFloat32(offset + 8, true) * 255; // b | ||
const a = data.getFloat32(offset + 12, true) * 255; // a | ||
colors.push(color(r, g, b, a)); | ||
|
||
offset += 16; | ||
|
||
widths.push(data.getFloat32(offset + 0, true)); | ||
|
||
offset += 4; | ||
} | ||
|
||
const brushSize = widths[parseInt(widths.length/2)]; | ||
const brushColor = colors[parseInt(colors.length/2)]; | ||
const quillStroke = new QuillStroke(positions, brushSize, brushColor); | ||
this.strokes.push(quillStroke); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
class QuillStroke { | ||
|
||
constructor(_positions, _brushSize, _brushColor) { | ||
this.positions = _positions; | ||
this.brushSize = _brushSize; | ||
this.brushColor = _brushColor; | ||
} | ||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
|
||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | ||
|
||
class LatkStroke { | ||
|
||
constructor(points, color, fill_color) { | ||
|
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
|
||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | ||
|
||
// Adapted from three.js TiltLoader. | ||
|
||
class TiltLoader { | ||
|
||
constructor() { | ||
this.ready = false; | ||
this.json; | ||
this.bytes; | ||
this.strokes = []; | ||
this.numStrokes; | ||
} | ||
|
||
static read(url) { | ||
let tl = new TiltLoader(); | ||
|
||
JSZipUtils.getBinaryContent(url, function(err, data) { | ||
if (err) { | ||
throw err; // or handle err | ||
} | ||
|
||
let zip = new JSZip(); | ||
zip.loadAsync(data).then(function () { | ||
// https://github.com/Stuk/jszip/issues/375 | ||
let entries = Object.keys(zip.files).map(function (name) { | ||
return zip.files[name]; | ||
}); | ||
|
||
// A tilt zipfile should contain three items: thumbnail.png, data.sketch, metadata.json | ||
zip.file("metadata.json").async("string").then(function(response) { | ||
tl.json = JSON.parse(response); | ||
|
||
zip.file("data.sketch").async("arraybuffer").then(function(response) { | ||
tl.bytes = new Uint8Array(response); | ||
tl.parse(); | ||
//console.log("read " + tl.bytes.length + " bytes"); | ||
tl.ready = true; | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
return tl; | ||
} | ||
|
||
// https://docs.google.com/document/d/11ZsHozYn9FnWG7y3s3WAyKIACfbfwb4PbaS8cZ_xjvo/edit# | ||
parse() { | ||
const data = new DataView(this.bytes.buffer); | ||
|
||
this.numStrokes = data.getInt32(16, true); | ||
|
||
let offset = 20; | ||
|
||
for (let i = 0; i < this.numStrokes; i++) { | ||
const brushIndex = data.getInt32(offset, true); | ||
|
||
let r = data.getFloat32(offset + 4, true) * 255; | ||
let g = data.getFloat32(offset + 8, true) * 255; | ||
let b = data.getFloat32(offset + 12, true) * 255; | ||
let a = data.getFloat32(offset + 16, true) * 255; | ||
|
||
const brushColor = color(r, g, b, a); | ||
|
||
const brushSize = data.getFloat32(offset + 20, true); | ||
const strokeMask = data.getUint32(offset + 24, true); | ||
const controlPointMask = data.getUint32(offset + 28, true); | ||
|
||
let offsetStrokeMask = 0; | ||
let offsetControlPointMask = 0; | ||
|
||
for (let j = 0; j < 4; j++) { | ||
const byte = 1 << j; | ||
if ((strokeMask & byte) > 0) offsetStrokeMask += 4; | ||
if ((controlPointMask & byte) > 0) offsetControlPointMask += 4; | ||
} | ||
|
||
offset += 28 + offsetStrokeMask + 4; | ||
|
||
const numControlPoints = data.getInt32(offset, true); | ||
|
||
let positions = []; //new Float32Array(numControlPoints * 3); | ||
//let quaternions = []; //new Float32Array(numControlPoints * 4); | ||
|
||
offset += 4; | ||
|
||
for (let j = 0; j < numControlPoints; j++) { | ||
let x = data.getFloat32(offset + 0, true); | ||
let y = data.getFloat32(offset + 4, true); | ||
let z = data.getFloat32(offset + 8, true); | ||
positions.push(createVector(x, y, z)); | ||
|
||
//qw = data.getFloat32(offset + 12, true); | ||
//qx = data.getFloat32(offset + 16, true); | ||
//qy = data.getFloat32(offset + 20, true); | ||
//qz = data.getFloat32(offset + 24, true); | ||
|
||
offset += 28 + offsetControlPointMask; | ||
} | ||
|
||
let tiltStroke = new TiltStroke(positions, brushSize, brushColor); | ||
this.strokes.push(tiltStroke); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
class TiltStroke { | ||
|
||
constructor(_positions, _brushSize, _brushColor) { | ||
this.positions = _positions; | ||
this.brushSize = _brushSize; | ||
this.brushColor = _brushColor; | ||
} | ||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
class LatkUtil { | ||
|
||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | ||
|
||
class LatkUtil { | ||
|
||
// | ||
|
||
} | ||
|
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
npm install -g uglify-js | ||
sudo npm install -g uglify-js | ||
|
Binary file not shown.
Binary file not shown.
Oops, something went wrong.