-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlibtess2.post.js
84 lines (77 loc) · 2.89 KB
/
libtess2.post.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var _newTess = Module.cwrap('newTess', 'number', ['number']);
var _deleteTess = Module.cwrap('deleteTess', null, ['number']);
var _addContour = Module.cwrap('addContour', null, ['number', 'number', 'number', 'number', 'number']);
var _tesselate = Module.cwrap('tesselate', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
var _getVertexCount = Module.cwrap('getVertexCount', 'number', ['number']);
var _getVertices = Module.cwrap('getVertices', 'number', ['number']);
var _getVertexIndices = Module.cwrap('getVertexIndices', 'number', ['number']);
var _getElementCount = Module.cwrap('getElementCount', 'number', ['number']);
var _getElements = Module.cwrap('getElements', 'number', ['number']);
var ctor = function() {
this.tess = null;
this.polySize = 0;
this.vertexSize = 0;
};
ctor.WINDING_ODD = 0;
ctor.WINDING_NONZERO = 1;
ctor.WINDING_POSITIVE = 2;
ctor.WINDING_NEGATIVE = 3;
ctor.WINDING_ABS_GEQ_TWO = 4;
ctor.ELEMENT_POLYGONS = 0;
ctor.ELEMENT_CONNECTED_POLYGONS = 1;
ctor.ELEMENT_BOUNDARY_CONTOURS = 2;
ctor.prototype = {
newTess: function(mem) {
this.tess = _newTess(mem || 1024 * 1024) || null;
this.polySize = 0;
this.vertexSize = 0;
},
deleteTess: function() {
if (this.tess !== null) {
_deleteTess(this.tess);
this.tess = null;
} else {
throw "deleteTess: Tesselator not initialized.";
}
},
addContour: function(vertices, size, stride, count) {
if (this.tess !== null) {
var pbuf = Module._malloc(vertices.length << 2);
Module.HEAPF32.set(vertices, pbuf >> 2);
_addContour(this.tess, size, pbuf, stride, count);
Module._free(pbuf);
} else {
throw "addContour: Tesselator not initialized.";
}
},
tesselate: function(windingRule, elementType, polySize, vertexSize, normal) {
if (this.tess !== null) {
normal = normal || 0;
this.polySize = polySize;
this.vertexSize = vertexSize;
return _tesselate(this.tess, windingRule, elementType, polySize, vertexSize, normal);
} else {
throw "tesselate: Tesselator not initialized.";
}
},
getVertexCount: function() {
return _getVertexCount(this.tess);
},
getVertices: function() {
var p = _getVertices(this.tess) >> 2;
return new Float32Array(Module.HEAPF32.subarray(p, p + (this.getVertexCount() * this.vertexSize)));
},
getVertexIndices: function() {
var p = _getVertexIndices(this.tess) >> 2;
return new Int32Array(Module.HEAP32.subarray(p, p + this.getVertexCount()));
},
getElementCount: function() {
return _getElementCount(this.tess);
},
getElements: function() {
var p = _getElements(this.tess) >> 2;
return new Int32Array(Module.HEAP32.subarray(p, p + (this.getElementCount() * this.polySize)));
}
};
return ctor;
})();