Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 58 additions & 15 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const vvgl = (function(canvas, options={}) {



const JSZip = require('jszip');

const msgpack = require("msgpack-lite");
Expand Down Expand Up @@ -291,11 +289,13 @@ const vvgl = (function(canvas, options={}) {

class Contour {

constructor(path, start){
constructor(path, start, xy){

this.length = 0;
this.curves = [];

this.xy = xy;


let i = 0;
let x,y;
Expand Down Expand Up @@ -386,25 +386,42 @@ const vvgl = (function(canvas, options={}) {
let offset= 0;
let start = [0, 0];

this.contour_offsets = [0];


for (let i=0; i < contours.length; i++){


let contour = new Contour(contours[i], start);
let contour = new Contour(contours[i], start, this.xy);

contour.offset = offset;
// contour.offset = offset;

this.contours.push(contour);

offset+=contour.length;

this.contour_offsets.push(offset);


}

return offset;

// if(!data.foreground) this.size = offset;

}

push(contour){

let offset = this.contour_offsets[this.contour_offsets.length-1];

this.contours.push(contour);

offset+=contour.length;

this.contour_offsets.push(offset);

this.size +=contour.length;


}
Expand Down Expand Up @@ -433,8 +450,10 @@ const vvgl = (function(canvas, options={}) {
getBufferData(){

const data = new Float32Array(this.size*13);

const shape = this;


// if(this.hidden) return data;

let offset = 0;
Expand All @@ -444,11 +463,13 @@ const vvgl = (function(canvas, options={}) {

let contour = this.contours[i];



for (let j = 0; j < contour.length; j++){


data.set(contour.curves.slice(j*8, (j+1)*8), offset);
data.set(shape.xy, offset+8);
data.set(contour.xy, offset+8);
data.set(shape.color, offset+10);


Expand All @@ -475,24 +496,47 @@ const vvgl = (function(canvas, options={}) {

constructor(shapes){


this.shapes = [];
this.index = {};

this.errors = {};

let size = 0;

for (let i=0; i < shapes.length; i++){


let shape = new Shape(shapes[i]);
shape.offset = size;

this.shapes.push(shape);


}

for (let i=0; i < shapes.length; i++){


let shape = this.shapes[i];

if(shapes[i].children){


for (const child_index of shapes[i].children){

let child = this.shapes[child_index];
let child_contour = child.contours[0];

console.log(`Shape ${i} has child at index ${child_index}`);
shape.push(child_contour);


}



}


shape.offset = size;
size += shape.size;

this.index[shape.id] = shape;
this.shapes.push(shape);


}
Expand Down Expand Up @@ -822,8 +866,7 @@ const vvgl = (function(canvas, options={}) {

if(shape.size > 0 && shape.contours[i].length > 0){


gl.drawArrays(gl.TRIANGLE_FAN, shape.offset + shape.contours[i].offset, shape.contours[i].length);
gl.drawArrays(gl.TRIANGLE_FAN, shape.offset + shape.contour_offsets[i], shape.contours[i].length);
}


Expand Down