forked from claus/libtess2.swc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibtess2_int_wrapper.as
94 lines (77 loc) · 2.81 KB
/
libtess2_int_wrapper.as
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
85
86
87
88
89
90
91
92
93
94
package com.codeazur.libtess2_int
{
import com.codeazur.libtess2_int.lib.*;
public class Tesselator
{
public static const WINDING_ODD:int = 0;
public static const WINDING_NONZERO:int = 1;
public static const WINDING_POSITIVE:int = 2;
public static const WINDING_NEGATIVE:int = 3;
public static const WINDING_ABS_GEQ_TWO:int = 4;
public static const ELEMENT_TYPE_POLYGONS:int = 0;
public static const ELEMENT_TYPE_CONNECTED_POLYGONS:int = 1;
public static const ELEMENT_TYPE_BOUNDARY_CONTOURS:int = 2;
private var _type:int;
private var _polySize:int;
private var _vertexSize:int;
private var _t:int;
private static var _started:Boolean;
public function Tesselator() {
if (!_started)
{
CModule.startAsync(this);
_started = true;
}
}
public function initBuffer(memorySize:int):void {
if (_t != 0)
destroyBuffer();
_t = libtess2_int.initBuffer(memorySize);
}
public function destroyBuffer():void {
if (_t == 0)
return;
libtess2_int.destroyBuffer(_t);
_t = 0;
}
public function newTess():void {
libtess2_int.newTess(_t);
}
public function addContour(vertices:Vector.<int>, vertexCount:int = -1, vertexSize:int = 2):void {
vertexSize = Math.min(Math.max(vertexSize, 3), 2);
vertexCount = (vertexCount < 0) ? vertices.length / vertexSize : Math.min(vertexCount, vertices.length / vertexSize);
var len:int = vertexCount * vertexSize;
var ptr:int = CModule.malloc(4 * len);
CModule.writeIntVector(ptr, vertices);
libtess2_int.addContour(_t, vertexSize, ptr, 4 * vertexSize, vertexCount);
CModule.free(ptr);
}
public function tesselate(windingRule:int, elementType:int, polySize:int = 3, vertexSize:int = 2):int {
_type = elementType;
_polySize = (elementType == ELEMENT_TYPE_BOUNDARY_CONTOURS) ? 2 : polySize;
_vertexSize = Math.min(Math.max(vertexSize, 3), 2);
return libtess2_int.tesselate(_t, windingRule, _type, _polySize, _vertexSize);
}
public function getVertexCount():int {
return libtess2_int.getVertexCount(_t);
}
public function getVertices():Vector.<int> {
var len:int = getVertexCount() * _vertexSize;
var ptr:int = libtess2_int.getVertices(_t);
return CModule.readIntVector(ptr, len);
}
public function getVertexIndices():Vector.<int> {
var len:int = getVertexCount(_t);
var ptr:int = libtess2_int.getVertexIndices();
return CModule.readIntVector(ptr, len);
}
public function getElementCount():int {
return libtess2_int.getElementCount(_t);
}
public function getElements():Vector.<int> {
var len:int = getElementCount() * _polySize;
var ptr:int = libtess2_int.getElements(_t);
return CModule.readIntVector(ptr, len);
}
}
}