Skip to content
Snippets Groups Projects
Commit 93f616f1 authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

wip

parent a477ed61
Branches
No related tags found
No related merge requests found
...@@ -402,12 +402,42 @@ function worker() { ...@@ -402,12 +402,42 @@ function worker() {
return([x3,y3,z3]) return([x3,y3,z3])
} }
// //
// get vars // function to draw line
//
function line(x0,y0,x1,y1) {
var ix0 = Math.floor(w*(x0-xmin)/(xmax-xmin))
var iy0 = Math.floor(h*(y0-ymin)/(ymax-ymin))
var ix1 = Math.floor(w*(x1-xmin)/(xmax-xmin))
var iy1 = Math.floor(h*(y1-ymin)/(ymax-ymin))
var dx = ix1-ix0
var dy = iy1-iy0
console.log(ix0,iy0)
buf[(h-1-iy0)*w*4+ix0*4+0] = 255
buf[(h-1-iy0)*w*4+ix0*4+1] = 255
buf[(h-1-iy0)*w*4+ix0*4+2] = 255
}
//
// get vars from buffer
// //
var endian = true var endian = true
var triangles = view.getUint32(80,endian) var triangles = view.getUint32(80,endian)
var size = 80+4+triangles*(4*12+2) var size = 80+4+triangles*(4*12+2)
// //
// initialize slice image
//
for (var row = 0; row < h; ++row) {
for (var col = 0; col < w; ++col) {
r = buf[(h-1-row)*w*4+col*4+0]
g = buf[(h-1-row)*w*4+col*4+1]
b = buf[(h-1-row)*w*4+col*4+2]
a = buf[(h-1-row)*w*4+col*4+3]
buf[(h-1-row)*w*4+col*4+0] = 0
buf[(h-1-row)*w*4+col*4+1] = 0
buf[(h-1-row)*w*4+col*4+2] = 0
buf[(h-1-row)*w*4+col*4+3] = 255
}
}
//
// find triangles crossing the slice // find triangles crossing the slice
// //
var segs = [] var segs = []
...@@ -437,12 +467,12 @@ function worker() { ...@@ -437,12 +467,12 @@ function worker() {
// rotate vertices // rotate vertices
// //
offset += 2 offset += 2
var p = [rotate(x0,y0,z0), var v = [rotate(x0,y0,z0),
rotate(x1,y1,z1),rotate(x2,y2,z2)] rotate(x1,y1,z1),rotate(x2,y2,z2)]
// //
// sort z // sort z
// //
p.sort(function(a,b) { v.sort(function(a,b) {
if (a[2] < b[2]) if (a[2] < b[2])
return -1 return -1
else if (a[2] > b[2]) else if (a[2] > b[2])
...@@ -453,60 +483,33 @@ function worker() { ...@@ -453,60 +483,33 @@ function worker() {
// //
// check for crossing // check for crossing
// //
if ((p[0][2] <= (zmax-depth)) && (p[2][2] >= (zmax-depth))) { if ((v[0][2] <= (zmax-depth)) && (v[2][2] >= (zmax-depth))) {
count += 1 count += 1
}
/*
// //
// crossing found, check for side and save // crossing found, check for side and stroke
// //
if (p[1][2] < z) { line(v[0][0],v[0][1],v[1][0],v[1][1])
line(v[1][0],v[1][1],v[2][0],v[2][1])
line(v[2][0],v[2][1],v[0][0],v[0][1])
if (v[1][2] < (zmax-depth)) {
;
} }
else if (p[1][2] > z) { else if (v[1][2] > (zmax-depth)) {
;
} }
else { else {
;
} }
} }
*/
} }
/* /*
// //
// initialize slice image // loop over scan lines and fill interior
//
for row
for col
//
// loop over scan lines
//
for row
//
// find scan line intersections with segments
//
// //
// perturb vertex intersections */
//
//
// sort and stroke intersections
//
// //
// output the slice // output the slice
// //
*/
for (var row = 0; row < h; ++row) {
for (var col = 0; col < w; ++col) {
r = buf[(h-1-row)*w*4+col*4+0]
g = buf[(h-1-row)*w*4+col*4+1]
b = buf[(h-1-row)*w*4+col*4+2]
a = buf[(h-1-row)*w*4+col*4+3]
buf[(h-1-row)*w*4+col*4+0] = row
buf[(h-1-row)*w*4+col*4+1] = col
buf[(h-1-row)*w*4+col*4+2] = row+col
buf[(h-1-row)*w*4+col*4+3] = 255
}
}
self.postMessage({count:count,buffer:buf.buffer},[buf.buffer]) self.postMessage({count:count,buffer:buf.buffer},[buf.buffer])
}) })
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment