@antv/g-webgpu 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -25
- package/dist/gwebgpu.js +1 -0
- package/es/Kernel.d.ts +21 -0
- package/es/Kernel.js +26 -83
- package/es/Kernel.js.map +1 -1
- package/es/World.d.ts +13 -0
- package/es/World.js +13 -196
- package/es/World.js.map +1 -1
- package/es/index.d.ts +3 -0
- package/es/index.js +1 -3
- package/es/index.js.map +1 -1
- package/es/utils/canvas.d.ts +1 -0
- package/es/utils/canvas.js.map +1 -1
- package/es/utils/typedarray.d.ts +1 -0
- package/es/utils/typedarray.js +28 -0
- package/es/utils/typedarray.js.map +1 -0
- package/lib/Kernel.js +24 -94
- package/lib/Kernel.js.map +1 -1
- package/lib/World.js +11 -212
- package/lib/World.js.map +1 -1
- package/lib/index.js +0 -18
- package/lib/index.js.map +1 -1
- package/lib/utils/canvas.js +0 -1
- package/lib/utils/canvas.js.map +1 -1
- package/lib/utils/typedarray.js +34 -0
- package/lib/utils/typedarray.js.map +1 -0
- package/package.json +5 -14
- package/es/Renderer.js +0 -310
- package/es/Renderer.js.map +0 -1
- package/es/Scene.js +0 -39
- package/es/Scene.js.map +0 -1
- package/es/View.js +0 -86
- package/es/View.js.map +0 -1
- package/es/camera/Camera.js +0 -801
- package/es/camera/Camera.js.map +0 -1
- package/es/camera/Landmark.js +0 -86
- package/es/camera/Landmark.js.map +0 -1
- package/es/renderable/Renderable.js +0 -132
- package/es/renderable/Renderable.js.map +0 -1
- package/es/renderable/line/Line.js +0 -164
- package/es/renderable/line/Line.js.map +0 -1
- package/es/renderable/point/Point.js +0 -203
- package/es/renderable/point/Point.js.map +0 -1
- package/es/utils/math.js +0 -23
- package/es/utils/math.js.map +0 -1
- package/es/utils/picking.js +0 -4
- package/es/utils/picking.js.map +0 -1
- package/es/utils/polyline-normals.js +0 -127
- package/es/utils/polyline-normals.js.map +0 -1
- package/lib/Renderer.js +0 -325
- package/lib/Renderer.js.map +0 -1
- package/lib/Scene.js +0 -49
- package/lib/Scene.js.map +0 -1
- package/lib/View.js +0 -99
- package/lib/View.js.map +0 -1
- package/lib/camera/Camera.js +0 -870
- package/lib/camera/Camera.js.map +0 -1
- package/lib/camera/Landmark.js +0 -95
- package/lib/camera/Landmark.js.map +0 -1
- package/lib/renderable/Renderable.js +0 -141
- package/lib/renderable/Renderable.js.map +0 -1
- package/lib/renderable/line/Line.js +0 -182
- package/lib/renderable/line/Line.js.map +0 -1
- package/lib/renderable/point/Point.js +0 -221
- package/lib/renderable/point/Point.js.map +0 -1
- package/lib/utils/math.js +0 -36
- package/lib/utils/math.js.map +0 -1
- package/lib/utils/picking.js +0 -11
- package/lib/utils/picking.js.map +0 -1
- package/lib/utils/polyline-normals.js +0 -135
- package/lib/utils/polyline-normals.js.map +0 -1
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.Point = void 0;
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
|
-
var _initializerDefineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerDefineProperty"));
|
|
13
|
-
|
|
14
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
19
|
-
|
|
20
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
-
|
|
22
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
23
|
-
|
|
24
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
25
|
-
|
|
26
|
-
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
|
|
27
|
-
|
|
28
|
-
var _initializerWarningHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerWarningHelper"));
|
|
29
|
-
|
|
30
|
-
var _gWebgpuCore = require("@antv/g-webgpu-core");
|
|
31
|
-
|
|
32
|
-
var _inversify = require("inversify");
|
|
33
|
-
|
|
34
|
-
var _picking = require("../../utils/picking");
|
|
35
|
-
|
|
36
|
-
var _Renderable2 = require("../Renderable");
|
|
37
|
-
|
|
38
|
-
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _temp;
|
|
39
|
-
|
|
40
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
41
|
-
|
|
42
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
43
|
-
|
|
44
|
-
/* babel-plugin-inline-import './shaders/webgl.point.frag.glsl' */
|
|
45
|
-
var pointFrag = "uniform float u_blur;\nuniform float u_opacity;\nuniform float u_stroke_width;\nuniform vec4 u_stroke_color;\nuniform float u_stroke_opacity;\n\nvarying vec4 v_color;\nvarying vec4 v_data;\nvarying float v_radius;\n\n#pragma include \"sdf2d\"\n#pragma include \"picking\"\n\nvoid main() {\n int shape = int(floor(v_data.w + 0.5));\n\n float antialiasblur = v_data.z;\n float antialiased_blur = -max(u_blur, antialiasblur);\n float r = v_radius / (v_radius + u_stroke_width);\n\n float outer_df;\n float inner_df;\n // 'circle', 'triangle', 'square', 'pentagon', 'hexagon', 'octogon', 'hexagram', 'rhombus', 'vesica'\n if (shape == 0) {\n outer_df = sdCircle(v_data.xy, 1.0);\n inner_df = sdCircle(v_data.xy, r);\n } else if (shape == 1) {\n outer_df = sdEquilateralTriangle(1.1 * v_data.xy);\n inner_df = sdEquilateralTriangle(1.1 / r * v_data.xy);\n } else if (shape == 2) {\n outer_df = sdBox(v_data.xy, vec2(1.));\n inner_df = sdBox(v_data.xy, vec2(r));\n } else if (shape == 3) {\n outer_df = sdPentagon(v_data.xy, 0.8);\n inner_df = sdPentagon(v_data.xy, r * 0.8);\n } else if (shape == 4) {\n outer_df = sdHexagon(v_data.xy, 0.8);\n inner_df = sdHexagon(v_data.xy, r * 0.8);\n } else if (shape == 5) {\n outer_df = sdOctogon(v_data.xy, 1.0);\n inner_df = sdOctogon(v_data.xy, r);\n } else if (shape == 6) {\n outer_df = sdHexagram(v_data.xy, 0.52);\n inner_df = sdHexagram(v_data.xy, r * 0.52);\n } else if (shape == 7) {\n outer_df = sdRhombus(v_data.xy, vec2(1.0));\n inner_df = sdRhombus(v_data.xy, vec2(r));\n } else if (shape == 8) {\n outer_df = sdVesica(v_data.xy, 1.1, 0.8);\n inner_df = sdVesica(v_data.xy, r * 1.1, r * 0.8);\n }\n\n float opacity_t = smoothstep(0.0, antialiased_blur, outer_df);\n\n float color_t = u_stroke_width < 0.01 ? 0.0 : smoothstep(\n antialiased_blur,\n 0.0,\n inner_df\n );\n vec4 strokeColor = u_stroke_color == vec4(0) ? v_color : u_stroke_color;\n\n gl_FragColor = mix(vec4(v_color.rgb, v_color.a * u_opacity), strokeColor * u_stroke_opacity, color_t);\n gl_FragColor.a = gl_FragColor.a * opacity_t;\n\n gl_FragColor = filterColor(gl_FragColor);\n}";
|
|
46
|
-
|
|
47
|
-
/* babel-plugin-inline-import './shaders/webgl.point.vert.glsl' */
|
|
48
|
-
var pointVert = "attribute vec2 position;\nattribute vec4 color;\nattribute float shape;\nattribute vec2 offset;\nattribute float size;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelViewMatrix;\n\nuniform float u_stroke_width;\nuniform float u_device_pixel_ratio;\nuniform vec2 u_viewport;\n\nvarying vec4 v_color;\nvarying vec4 v_data;\nvarying float v_radius;\n\n#pragma include \"picking\"\n\nvoid main() {\n v_color = color;\n v_radius = size;\n\n lowp float antialiasblur = 1.0 / u_device_pixel_ratio * (size + u_stroke_width);\n\n // construct point coords\n v_data = vec4(position, antialiasblur, shape);\n\n gl_Position = projectionMatrix * modelViewMatrix\n * vec4(position * size + offset, 0.0, 1.0);\n\n setPickingColor(a_PickingColor);\n}";
|
|
49
|
-
var pointShapes = ['circle', 'triangle', 'square', 'pentagon', 'hexagon', 'octogon', 'hexagram', 'rhombus', 'vesica'];
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Use SDF to draw 2D point with stroke.
|
|
53
|
-
*/
|
|
54
|
-
var Point = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inversify.inject)(_gWebgpuCore.IDENTIFIER.Systems), _dec3 = (0, _inversify.named)(_gWebgpuCore.IDENTIFIER.MaterialSystem), _dec4 = (0, _inversify.inject)(_gWebgpuCore.IDENTIFIER.Systems), _dec5 = (0, _inversify.named)(_gWebgpuCore.IDENTIFIER.GeometrySystem), _dec(_class = (_class2 = (_temp = /*#__PURE__*/function (_Renderable) {
|
|
55
|
-
(0, _inherits2.default)(Point, _Renderable);
|
|
56
|
-
|
|
57
|
-
var _super = _createSuper(Point);
|
|
58
|
-
|
|
59
|
-
function Point() {
|
|
60
|
-
var _this;
|
|
61
|
-
|
|
62
|
-
(0, _classCallCheck2.default)(this, Point);
|
|
63
|
-
|
|
64
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
65
|
-
args[_key] = arguments[_key];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
69
|
-
(0, _initializerDefineProperty2.default)(_this, "materialSystem", _descriptor, (0, _assertThisInitialized2.default)(_this));
|
|
70
|
-
(0, _initializerDefineProperty2.default)(_this, "geometrySystem", _descriptor2, (0, _assertThisInitialized2.default)(_this));
|
|
71
|
-
return _this;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
(0, _createClass2.default)(Point, [{
|
|
75
|
-
key: "afterEntityCreated",
|
|
76
|
-
value: function afterEntityCreated() {
|
|
77
|
-
var material = this.materialSystem.createShaderMaterial({
|
|
78
|
-
vertexShader: pointVert,
|
|
79
|
-
fragmentShader: pointFrag,
|
|
80
|
-
cull: {
|
|
81
|
-
enable: false
|
|
82
|
-
},
|
|
83
|
-
depth: {
|
|
84
|
-
enable: false
|
|
85
|
-
},
|
|
86
|
-
blend: {
|
|
87
|
-
enable: true,
|
|
88
|
-
func: {
|
|
89
|
-
srcRGB: _gWebgpuCore.gl.SRC_ALPHA,
|
|
90
|
-
dstRGB: _gWebgpuCore.gl.ONE_MINUS_SRC_ALPHA,
|
|
91
|
-
srcAlpha: 1,
|
|
92
|
-
dstAlpha: 1
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}); // TODO: support define stroke-relative props per point
|
|
96
|
-
|
|
97
|
-
material.setUniform({
|
|
98
|
-
u_stroke_width: 0.01,
|
|
99
|
-
u_device_pixel_ratio: window.devicePixelRatio,
|
|
100
|
-
u_stroke_color: [0, 0, 0, 0],
|
|
101
|
-
u_stroke_opacity: 1,
|
|
102
|
-
u_opacity: 0.35,
|
|
103
|
-
u_blur: 0
|
|
104
|
-
});
|
|
105
|
-
var attributes = this.buildAttributes();
|
|
106
|
-
var geometry = this.geometrySystem.createInstancedBufferGeometry({
|
|
107
|
-
maxInstancedCount: attributes.instancedOffsets.length / 2,
|
|
108
|
-
vertexCount: 6
|
|
109
|
-
});
|
|
110
|
-
geometry.setIndex([0, 2, 1, 0, 3, 2]);
|
|
111
|
-
geometry.setAttribute('position', Float32Array.from(attributes.positions), {
|
|
112
|
-
arrayStride: 4 * 2,
|
|
113
|
-
stepMode: 'vertex',
|
|
114
|
-
attributes: [{
|
|
115
|
-
shaderLocation: 0,
|
|
116
|
-
offset: 0,
|
|
117
|
-
format: 'float2'
|
|
118
|
-
}]
|
|
119
|
-
});
|
|
120
|
-
geometry.setAttribute('offset', Float32Array.from(attributes.instancedOffsets), {
|
|
121
|
-
arrayStride: 4 * 2,
|
|
122
|
-
stepMode: 'instance',
|
|
123
|
-
attributes: [{
|
|
124
|
-
shaderLocation: 1,
|
|
125
|
-
offset: 0,
|
|
126
|
-
format: 'float2'
|
|
127
|
-
}]
|
|
128
|
-
});
|
|
129
|
-
geometry.setAttribute('color', Float32Array.from(attributes.instancedColors), {
|
|
130
|
-
arrayStride: 4 * 4,
|
|
131
|
-
stepMode: 'instance',
|
|
132
|
-
attributes: [{
|
|
133
|
-
shaderLocation: 2,
|
|
134
|
-
offset: 0,
|
|
135
|
-
format: 'float4'
|
|
136
|
-
}]
|
|
137
|
-
});
|
|
138
|
-
geometry.setAttribute('size', Float32Array.from(attributes.instancedSizes), {
|
|
139
|
-
arrayStride: 4,
|
|
140
|
-
stepMode: 'instance',
|
|
141
|
-
attributes: [{
|
|
142
|
-
shaderLocation: 3,
|
|
143
|
-
offset: 0,
|
|
144
|
-
format: 'float'
|
|
145
|
-
}]
|
|
146
|
-
});
|
|
147
|
-
geometry.setAttribute('shape', Float32Array.from(attributes.instancedShapes), {
|
|
148
|
-
arrayStride: 4,
|
|
149
|
-
stepMode: 'instance',
|
|
150
|
-
attributes: [{
|
|
151
|
-
shaderLocation: 4,
|
|
152
|
-
offset: 0,
|
|
153
|
-
format: 'float'
|
|
154
|
-
}]
|
|
155
|
-
});
|
|
156
|
-
geometry.setAttribute('a_PickingColor', Float32Array.from(attributes.instancedPickingColors), {
|
|
157
|
-
arrayStride: 4 * 3,
|
|
158
|
-
stepMode: 'instance',
|
|
159
|
-
attributes: [{
|
|
160
|
-
shaderLocation: 6,
|
|
161
|
-
offset: 0,
|
|
162
|
-
format: 'float3'
|
|
163
|
-
}]
|
|
164
|
-
});
|
|
165
|
-
this.setMaterial(material);
|
|
166
|
-
this.setGeometry(geometry);
|
|
167
|
-
}
|
|
168
|
-
}, {
|
|
169
|
-
key: "buildAttribute",
|
|
170
|
-
value: function buildAttribute(config, attributes, index) {
|
|
171
|
-
var _attributes$instanced, _attributes$instanced2, _attributes$instanced3, _attributes$instanced4;
|
|
172
|
-
|
|
173
|
-
(_attributes$instanced = attributes.instancedPickingColors).push.apply(_attributes$instanced, (0, _toConsumableArray2.default)((0, _picking.encodePickingColor)(config.id || index)));
|
|
174
|
-
|
|
175
|
-
attributes.instancedShapes.push(pointShapes.indexOf(config.shape || 'circle'));
|
|
176
|
-
|
|
177
|
-
(_attributes$instanced2 = attributes.instancedColors).push.apply(_attributes$instanced2, (0, _toConsumableArray2.default)(config.color || [1, 0, 0, 1]));
|
|
178
|
-
|
|
179
|
-
(_attributes$instanced3 = attributes.instancedOffsets).push.apply(_attributes$instanced3, (0, _toConsumableArray2.default)(config.position || [0, 0]));
|
|
180
|
-
|
|
181
|
-
(_attributes$instanced4 = attributes.instancedSizes).push.apply(_attributes$instanced4, (0, _toConsumableArray2.default)(config.size || [0.2, 0.2]));
|
|
182
|
-
}
|
|
183
|
-
}, {
|
|
184
|
-
key: "buildAttributes",
|
|
185
|
-
value: function buildAttributes() {
|
|
186
|
-
var _this2 = this;
|
|
187
|
-
|
|
188
|
-
var attributes = {
|
|
189
|
-
positions: [1, 1, 1, -1, -1, -1, -1, 1],
|
|
190
|
-
instancedOffsets: [],
|
|
191
|
-
instancedColors: [],
|
|
192
|
-
instancedSizes: [],
|
|
193
|
-
instancedShapes: [],
|
|
194
|
-
instancedPickingColors: []
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
if (Array.isArray(this.config)) {
|
|
198
|
-
this.config.forEach(function (config, i) {
|
|
199
|
-
_this2.buildAttribute(config, attributes, i);
|
|
200
|
-
});
|
|
201
|
-
} else {
|
|
202
|
-
this.buildAttribute(this.config, attributes, 0);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return attributes;
|
|
206
|
-
}
|
|
207
|
-
}]);
|
|
208
|
-
return Point;
|
|
209
|
-
}(_Renderable2.Renderable), _temp), (_descriptor = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "materialSystem", [_dec2, _dec3], {
|
|
210
|
-
configurable: true,
|
|
211
|
-
enumerable: true,
|
|
212
|
-
writable: true,
|
|
213
|
-
initializer: null
|
|
214
|
-
}), _descriptor2 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "geometrySystem", [_dec4, _dec5], {
|
|
215
|
-
configurable: true,
|
|
216
|
-
enumerable: true,
|
|
217
|
-
writable: true,
|
|
218
|
-
initializer: null
|
|
219
|
-
})), _class2)) || _class);
|
|
220
|
-
exports.Point = Point;
|
|
221
|
-
//# sourceMappingURL=Point.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/renderable/point/Point.ts"],"names":["pointShapes","Point","IDENTIFIER","Systems","MaterialSystem","GeometrySystem","material","materialSystem","createShaderMaterial","vertexShader","pointVert","fragmentShader","pointFrag","cull","enable","depth","blend","func","srcRGB","gl","SRC_ALPHA","dstRGB","ONE_MINUS_SRC_ALPHA","srcAlpha","dstAlpha","setUniform","u_stroke_width","u_device_pixel_ratio","window","devicePixelRatio","u_stroke_color","u_stroke_opacity","u_opacity","u_blur","attributes","buildAttributes","geometry","geometrySystem","createInstancedBufferGeometry","maxInstancedCount","instancedOffsets","length","vertexCount","setIndex","setAttribute","Float32Array","from","positions","arrayStride","stepMode","shaderLocation","offset","format","instancedColors","instancedSizes","instancedShapes","instancedPickingColors","setMaterial","setGeometry","config","index","push","id","indexOf","shape","color","position","size","Array","isArray","forEach","i","buildAttribute","Renderable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAMA;;AACA;;AACA;;;;;;;;;;;;;AAIA,IAAMA,WAAW,GAAG,CAClB,QADkB,EAElB,UAFkB,EAGlB,QAHkB,EAIlB,UAJkB,EAKlB,SALkB,EAMlB,SANkB,EAOlB,UAPkB,EAQlB,SARkB,EASlB,QATkB,CAApB;;AA0CA;AACA;AACA;IAEaC,K,WADZ,4B,UAIE,uBAAOC,wBAAWC,OAAlB,C,UACA,sBAAMD,wBAAWE,cAAjB,C,UAGA,uBAAOF,wBAAWC,OAAlB,C,UACA,sBAAMD,wBAAWG,cAAjB,C;;;;;;;;;;;;;;;;;;;;;;yCAG8B;AAC7B,UAAMC,QAAQ,GAAG,KAAKC,cAAL,CAAoBC,oBAApB,CAAyC;AACxDC,QAAAA,YAAY,EAAEC,SAD0C;AAExDC,QAAAA,cAAc,EAAEC,SAFwC;AAGxDC,QAAAA,IAAI,EAAE;AACJC,UAAAA,MAAM,EAAE;AADJ,SAHkD;AAMxDC,QAAAA,KAAK,EAAE;AACLD,UAAAA,MAAM,EAAE;AADH,SANiD;AASxDE,QAAAA,KAAK,EAAE;AACLF,UAAAA,MAAM,EAAE,IADH;AAELG,UAAAA,IAAI,EAAE;AACJC,YAAAA,MAAM,EAAEC,gBAAGC,SADP;AAEJC,YAAAA,MAAM,EAAEF,gBAAGG,mBAFP;AAGJC,YAAAA,QAAQ,EAAE,CAHN;AAIJC,YAAAA,QAAQ,EAAE;AAJN;AAFD;AATiD,OAAzC,CAAjB,CAD6B,CAqB7B;;AACAlB,MAAAA,QAAQ,CAACmB,UAAT,CAAoB;AAClBC,QAAAA,cAAc,EAAE,IADE;AAElBC,QAAAA,oBAAoB,EAAEC,MAAM,CAACC,gBAFX;AAGlBC,QAAAA,cAAc,EAAE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP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AAZ,CAAoB,UAACX,MAAD,EAASY,CAAT,EAAe;AACjC,UAAA,MAAI,CAACC,cAAL,CAAoBb,MAApB,EAA4BzB,UAA5B,EAAwCqC,CAAxC;AACD,SAFD;AAGD,OAJD,MAIO;AACL,aAAKC,cAAL,CAAoB,KAAKb,MAAzB,EAAiCzB,UAAjC,EAA6C,CAA7C;AACD;;AAED,aAAOA,UAAP;AACD;;;EAvLwBuC,uB","sourcesContent":["import {\n GeometrySystem,\n gl,\n IDENTIFIER,\n MaterialSystem,\n} from '@antv/g-webgpu-core';\nimport { inject, injectable, named } from 'inversify';\nimport { encodePickingColor } from '../../utils/picking';\nimport { Renderable } from '../Renderable';\nimport pointFrag from './shaders/webgl.point.frag.glsl';\nimport pointVert from './shaders/webgl.point.vert.glsl';\n\nconst pointShapes = [\n 'circle',\n 'triangle',\n 'square',\n 'pentagon',\n 'hexagon',\n 'octogon',\n 'hexagram',\n 'rhombus',\n 'vesica',\n];\n\ninterface IPointConfig {\n id: number;\n shape:\n | 'circle'\n | 'triangle'\n | 'square'\n | 'pentagon'\n | 'hexagon'\n | 'octogon'\n | 'hexagram'\n | 'rhombus'\n | 'vesica';\n position: [number, number];\n size: [number, number];\n color: [number, number, number, number]; // sRGB\n opacity: number;\n strokeWidth: number;\n strokeOpacity: number;\n strokeColor: [number, number, number, number]; // sRGB\n}\n\ninterface IInstanceAttributes {\n positions: number[];\n instancedOffsets: number[];\n instancedColors: number[];\n instancedSizes: number[];\n instancedShapes: number[];\n instancedPickingColors: number[];\n}\n\n/**\n * Use SDF to draw 2D point with stroke.\n */\n@injectable()\nexport class Point extends Renderable<\n Partial<IPointConfig> | Array<Partial<IPointConfig>>\n> {\n @inject(IDENTIFIER.Systems)\n @named(IDENTIFIER.MaterialSystem)\n private readonly materialSystem: MaterialSystem;\n\n @inject(IDENTIFIER.Systems)\n @named(IDENTIFIER.GeometrySystem)\n private readonly geometrySystem: GeometrySystem;\n\n protected afterEntityCreated() {\n const material = this.materialSystem.createShaderMaterial({\n vertexShader: pointVert,\n fragmentShader: pointFrag,\n cull: {\n enable: false,\n },\n depth: {\n enable: false,\n },\n blend: {\n enable: true,\n func: {\n srcRGB: gl.SRC_ALPHA,\n dstRGB: gl.ONE_MINUS_SRC_ALPHA,\n srcAlpha: 1,\n dstAlpha: 1,\n },\n },\n });\n\n // TODO: support define stroke-relative props per point\n material.setUniform({\n u_stroke_width: 0.01,\n u_device_pixel_ratio: window.devicePixelRatio,\n u_stroke_color: [0, 0, 0, 0],\n u_stroke_opacity: 1,\n u_opacity: 0.35,\n u_blur: 0,\n });\n\n const attributes = this.buildAttributes();\n\n const geometry = this.geometrySystem.createInstancedBufferGeometry({\n maxInstancedCount: attributes.instancedOffsets.length / 2,\n vertexCount: 6,\n });\n\n geometry.setIndex([0, 2, 1, 0, 3, 2]);\n\n geometry.setAttribute('position', Float32Array.from(attributes.positions), {\n arrayStride: 4 * 2,\n stepMode: 'vertex',\n attributes: [\n {\n shaderLocation: 0,\n offset: 0,\n format: 'float2',\n },\n ],\n });\n\n geometry.setAttribute(\n 'offset',\n Float32Array.from(attributes.instancedOffsets),\n {\n arrayStride: 4 * 2,\n stepMode: 'instance',\n attributes: [\n {\n shaderLocation: 1,\n offset: 0,\n format: 'float2',\n },\n ],\n },\n );\n\n geometry.setAttribute(\n 'color',\n Float32Array.from(attributes.instancedColors),\n {\n arrayStride: 4 * 4,\n stepMode: 'instance',\n attributes: [\n {\n shaderLocation: 2,\n offset: 0,\n format: 'float4',\n },\n ],\n },\n );\n\n geometry.setAttribute(\n 'size',\n Float32Array.from(attributes.instancedSizes),\n {\n arrayStride: 4,\n stepMode: 'instance',\n attributes: [\n {\n shaderLocation: 3,\n offset: 0,\n format: 'float',\n },\n ],\n },\n );\n\n geometry.setAttribute(\n 'shape',\n Float32Array.from(attributes.instancedShapes),\n {\n arrayStride: 4,\n stepMode: 'instance',\n attributes: [\n {\n shaderLocation: 4,\n offset: 0,\n format: 'float',\n },\n ],\n },\n );\n\n geometry.setAttribute(\n 'a_PickingColor',\n Float32Array.from(attributes.instancedPickingColors),\n {\n arrayStride: 4 * 3,\n stepMode: 'instance',\n attributes: [\n {\n shaderLocation: 6,\n offset: 0,\n format: 'float3',\n },\n ],\n },\n );\n\n this.setMaterial(material);\n this.setGeometry(geometry);\n }\n\n private buildAttribute(\n config: Partial<IPointConfig>,\n attributes: IInstanceAttributes,\n index: number,\n ) {\n attributes.instancedPickingColors.push(\n ...encodePickingColor(config.id || index),\n );\n\n attributes.instancedShapes.push(\n pointShapes.indexOf(config.shape || 'circle'),\n );\n attributes.instancedColors.push(...(config.color || [1, 0, 0, 1]));\n attributes.instancedOffsets.push(...(config.position || [0, 0]));\n attributes.instancedSizes.push(...(config.size || [0.2, 0.2]));\n }\n\n private buildAttributes() {\n const attributes: IInstanceAttributes = {\n positions: [1, 1, 1, -1, -1, -1, -1, 1],\n instancedOffsets: [],\n instancedColors: [],\n instancedSizes: [],\n instancedShapes: [],\n instancedPickingColors: [],\n };\n\n if (Array.isArray(this.config)) {\n this.config.forEach((config, i) => {\n this.buildAttribute(config, attributes, i);\n });\n } else {\n this.buildAttribute(this.config, attributes, 0);\n }\n\n return attributes;\n }\n}\n"],"file":"Point.js"}
|
package/lib/utils/math.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.getAngle = getAngle;
|
|
9
|
-
exports.createVec3 = createVec3;
|
|
10
|
-
|
|
11
|
-
var _glMatrix = require("gl-matrix");
|
|
12
|
-
|
|
13
|
-
var _isNumber = _interopRequireDefault(require("lodash/isNumber"));
|
|
14
|
-
|
|
15
|
-
function getAngle(angle) {
|
|
16
|
-
if (angle === undefined) {
|
|
17
|
-
return 0;
|
|
18
|
-
} else if (angle > 360 || angle < -360) {
|
|
19
|
-
return angle % 360;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return angle;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function createVec3(x, y, z) {
|
|
26
|
-
if ((0, _isNumber.default)(x)) {
|
|
27
|
-
return _glMatrix.vec3.fromValues(x, y, z);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (x.length === 3) {
|
|
31
|
-
return _glMatrix.vec3.clone(x);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return _glMatrix.vec3.fromValues(x[0], x[1], x[2]);
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=math.js.map
|
package/lib/utils/math.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/math.ts"],"names":["getAngle","angle","undefined","createVec3","x","y","z","vec3","fromValues","length","clone"],"mappings":";;;;;;;;;;AAAA;;AACA;;AAEO,SAASA,QAAT,CAAkBC,KAAlB,EAA6C;AAClD,MAAIA,KAAK,KAAKC,SAAd,EAAyB;AACvB,WAAO,CAAP;AACD,GAFD,MAEO,IAAID,KAAK,GAAG,GAAR,IAAeA,KAAK,GAAG,CAAC,GAA5B,EAAiC;AACtC,WAAOA,KAAK,GAAG,GAAf;AACD;;AACD,SAAOA,KAAP;AACD;;AAEM,SAASE,UAAT,CAAoBC,CAApB,EAA6CC,CAA7C,EAAyDC,CAAzD,EAAqE;AAC1E,MAAI,uBAASF,CAAT,CAAJ,EAAiB;AACf,WAAOG,eAAKC,UAAL,CAAgBJ,CAAhB,EAAmBC,CAAnB,EAAgCC,CAAhC,CAAP;AACD;;AAED,MAAKF,CAAD,CAAYK,MAAZ,KAAuB,CAA3B,EAA8B;AAC5B,WAAOF,eAAKG,KAAL,CAAWN,CAAX,CAAP;AACD;;AAED,SAAOG,eAAKC,UAAL,CAAgBJ,CAAC,CAAC,CAAD,CAAjB,EAAsBA,CAAC,CAAC,CAAD,CAAvB,EAA4BA,CAAC,CAAC,CAAD,CAA7B,CAAP;AACD","sourcesContent":["import { vec3, vec4 } from 'gl-matrix';\nimport isNumber from 'lodash/isNumber';\n\nexport function getAngle(angle: number | undefined) {\n if (angle === undefined) {\n return 0;\n } else if (angle > 360 || angle < -360) {\n return angle % 360;\n }\n return angle;\n}\n\nexport function createVec3(x: number | vec3 | vec4, y?: number, z?: number) {\n if (isNumber(x)) {\n return vec3.fromValues(x, y as number, z as number);\n }\n\n if ((x as vec3).length === 3) {\n return vec3.clone(x as vec3);\n }\n\n return vec3.fromValues(x[0], x[1], x[2]);\n}\n"],"file":"math.js"}
|
package/lib/utils/picking.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.encodePickingColor = encodePickingColor;
|
|
7
|
-
|
|
8
|
-
function encodePickingColor(featureIdx) {
|
|
9
|
-
return [featureIdx + 1 & 255, featureIdx + 1 >> 8 & 255, featureIdx + 1 >> 8 >> 8 & 255];
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=picking.js.map
|
package/lib/utils/picking.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/picking.ts"],"names":["encodePickingColor","featureIdx"],"mappings":";;;;;;;AAAO,SAASA,kBAAT,CACLC,UADK,EAEqB;AAC1B,SAAO,CACJA,UAAU,GAAG,CAAd,GAAmB,GADd,EAEHA,UAAU,GAAG,CAAd,IAAoB,CAArB,GAA0B,GAFrB,EAGFA,UAAU,GAAG,CAAd,IAAoB,CAArB,IAA2B,CAA5B,GAAiC,GAH5B,CAAP;AAKD","sourcesContent":["export function encodePickingColor(\n featureIdx: number,\n): [number, number, number] {\n return [\n (featureIdx + 1) & 255,\n ((featureIdx + 1) >> 8) & 255,\n (((featureIdx + 1) >> 8) >> 8) & 255,\n ];\n}\n"],"file":"picking.js"}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = _default;
|
|
7
|
-
|
|
8
|
-
var _glVec = require("gl-vec2");
|
|
9
|
-
|
|
10
|
-
var _polylineMiterUtil = require("polyline-miter-util");
|
|
11
|
-
|
|
12
|
-
function extrusions(positions, out, point, normal, scale) {
|
|
13
|
-
addNext(out, normal, -scale);
|
|
14
|
-
addNext(out, normal, scale);
|
|
15
|
-
positions.push(point);
|
|
16
|
-
positions.push(point);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function addNext(out, normal, length) {
|
|
20
|
-
out.push([[normal[0], normal[1]], length]);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function _default(points, closed, indexOffset) {
|
|
24
|
-
var lineA = [0, 0];
|
|
25
|
-
var lineB = [0, 0];
|
|
26
|
-
var tangent = [0, 0];
|
|
27
|
-
var miter = [0, 0];
|
|
28
|
-
|
|
29
|
-
var _lastFlip = -1;
|
|
30
|
-
|
|
31
|
-
var _started = false;
|
|
32
|
-
var _normal = null;
|
|
33
|
-
var tmp = (0, _glVec.create)();
|
|
34
|
-
var count = indexOffset || 0;
|
|
35
|
-
var miterLimit = 3;
|
|
36
|
-
var out = [];
|
|
37
|
-
var attrPos = [];
|
|
38
|
-
var attrIndex = [];
|
|
39
|
-
var attrCounters = [0, 0];
|
|
40
|
-
|
|
41
|
-
if (closed) {
|
|
42
|
-
points = points.slice();
|
|
43
|
-
points.push(points[0]);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
var total = points.length;
|
|
47
|
-
|
|
48
|
-
for (var i = 1; i < total; i++) {
|
|
49
|
-
var index = count;
|
|
50
|
-
var last = points[i - 1];
|
|
51
|
-
var cur = points[i];
|
|
52
|
-
var next = i < points.length - 1 ? points[i + 1] : null;
|
|
53
|
-
attrCounters.push(i / total, i / total);
|
|
54
|
-
(0, _polylineMiterUtil.direction)(lineA, cur, last);
|
|
55
|
-
|
|
56
|
-
if (!_normal) {
|
|
57
|
-
_normal = [0, 0];
|
|
58
|
-
(0, _polylineMiterUtil.normal)(_normal, lineA);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (!_started) {
|
|
62
|
-
_started = true;
|
|
63
|
-
extrusions(attrPos, out, last, _normal, 1);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
attrIndex.push([index + 0, index + 1, index + 2]);
|
|
67
|
-
|
|
68
|
-
if (!next) {
|
|
69
|
-
// no miter, simple segment
|
|
70
|
-
(0, _polylineMiterUtil.normal)(_normal, lineA); // reset normal
|
|
71
|
-
|
|
72
|
-
extrusions(attrPos, out, cur, _normal, 1);
|
|
73
|
-
attrIndex.push(_lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]);
|
|
74
|
-
count += 2;
|
|
75
|
-
} else {
|
|
76
|
-
// miter with last
|
|
77
|
-
// get unit dir of next line
|
|
78
|
-
(0, _polylineMiterUtil.direction)(lineB, next, cur); // stores tangent & miter
|
|
79
|
-
|
|
80
|
-
var miterLen = (0, _polylineMiterUtil.computeMiter)(tangent, miter, lineA, lineB, 1); // get orientation
|
|
81
|
-
|
|
82
|
-
var flip = (0, _glVec.dot)(tangent, _normal) < 0 ? -1 : 1;
|
|
83
|
-
var bevel = miterLen > miterLimit; // 处理相邻线段重叠的情况
|
|
84
|
-
|
|
85
|
-
if (!isFinite(miterLen)) {
|
|
86
|
-
(0, _polylineMiterUtil.normal)(_normal, lineA); // reset normal
|
|
87
|
-
|
|
88
|
-
extrusions(attrPos, out, cur, _normal, 1);
|
|
89
|
-
attrIndex.push(_lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]);
|
|
90
|
-
count += 2;
|
|
91
|
-
_lastFlip = flip;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (bevel) {
|
|
96
|
-
miterLen = miterLimit;
|
|
97
|
-
attrCounters.push(i / total); // next two points in our first segment
|
|
98
|
-
|
|
99
|
-
addNext(out, _normal, -flip);
|
|
100
|
-
attrPos.push(cur);
|
|
101
|
-
addNext(out, miter, miterLen * flip);
|
|
102
|
-
attrPos.push(cur);
|
|
103
|
-
attrIndex.push(_lastFlip !== -flip ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]); // now add the bevel triangle
|
|
104
|
-
|
|
105
|
-
attrIndex.push([index + 2, index + 3, index + 4]);
|
|
106
|
-
(0, _polylineMiterUtil.normal)(tmp, lineB);
|
|
107
|
-
(0, _glVec.copy)(_normal, tmp); // store normal for next round
|
|
108
|
-
|
|
109
|
-
addNext(out, _normal, -flip);
|
|
110
|
-
attrPos.push(cur); // the miter is now the normal for our next join
|
|
111
|
-
|
|
112
|
-
count += 3;
|
|
113
|
-
} else {
|
|
114
|
-
// miter
|
|
115
|
-
// next two points for our miter join
|
|
116
|
-
extrusions(attrPos, out, cur, miter, miterLen);
|
|
117
|
-
attrIndex.push(_lastFlip === 1 ? [index, index + 2, index + 3] : [index + 2, index + 1, index + 3]);
|
|
118
|
-
flip = -1; // the miter is now the normal for our next join
|
|
119
|
-
|
|
120
|
-
(0, _glVec.copy)(_normal, miter);
|
|
121
|
-
count += 2;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
_lastFlip = flip;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
normals: out,
|
|
130
|
-
attrIndex: attrIndex,
|
|
131
|
-
attrPos: attrPos,
|
|
132
|
-
attrCounters: attrCounters
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
//# sourceMappingURL=polyline-normals.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/polyline-normals.ts"],"names":["extrusions","positions","out","point","normal","scale","addNext","push","length","points","closed","indexOffset","lineA","lineB","tangent","miter","_lastFlip","_started","_normal","tmp","count","miterLimit","attrPos","attrIndex","attrCounters","slice","total","i","index","last","cur","next","miterLen","flip","bevel","isFinite","normals"],"mappings":";;;;;;;AAAA;;AACA;;AAEA,SAASA,UAAT,CACEC,SADF,EAEEC,GAFF,EAGEC,KAHF,EAIEC,MAJF,EAKEC,KALF,EAME;AACAC,EAAAA,OAAO,CAACJ,GAAD,EAAME,MAAN,EAAc,CAACC,KAAf,CAAP;AACAC,EAAAA,OAAO,CAACJ,GAAD,EAAME,MAAN,EAAcC,KAAd,CAAP;AACAJ,EAAAA,SAAS,CAACM,IAAV,CAAeJ,KAAf;AACAF,EAAAA,SAAS,CAACM,IAAV,CAAeJ,KAAf;AACD;;AAED,SAASG,OAAT,CAAiBJ,GAAjB,EAA+BE,MAA/B,EAAiDI,MAAjD,EAAiE;AAC/DN,EAAAA,GAAG,CAACK,IAAJ,CAAS,CAAC,CAACH,MAAM,CAAC,CAAD,CAAP,EAAYA,MAAM,CAAC,CAAD,CAAlB,CAAD,EAAyBI,MAAzB,CAAT;AACD;;AAEc,kBACbC,MADa,EAEbC,MAFa,EAGbC,WAHa,EAIb;AACA,MAAMC,KAAK,GAAG,CAAC,CAAD,EAAI,CAAJ,CAAd;AACA,MAAMC,KAAK,GAAG,CAAC,CAAD,EAAI,CAAJ,CAAd;AACA,MAAMC,OAAO,GAAG,CAAC,CAAD,EAAI,CAAJ,CAAhB;AACA,MAAMC,KAAK,GAAG,CAAC,CAAD,EAAI,CAAJ,CAAd;;AACA,MAAIC,SAAS,GAAG,CAAC,CAAjB;;AACA,MAAIC,QAAQ,GAAG,KAAf;AACA,MAAIC,OAAY,GAAG,IAAnB;AACA,MAAMC,GAAG,GAAG,oBAAZ;AACA,MAAIC,KAAK,GAAGT,WAAW,IAAI,CAA3B;AACA,MAAMU,UAAU,GAAG,CAAnB;AAEA,MAAMnB,GAAQ,GAAG,EAAjB;AACA,MAAMoB,OAAmB,GAAG,EAA5B;AACA,MAAMC,SAAS,GAA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AACY,KAAD,EAAQA,KAAK,GAAG,CAAhB,EAAmBA,KAAK,GAAG,CAA3B,CADJ,GAEI,CAACA,KAAK,GAAG,CAAT,EAAYA,KAAK,GAAG,CAApB,EAAuBA,KAAK,GAAG,CAA/B,CAHN;AAMAK,QAAAA,IAAI,GAAG,CAAC,CAAR,CAVK,CAYL;;AACA,yBAAKf,OAAL,EAAcH,KAAd;AACAK,QAAAA,KAAK,IAAI,CAAT;AACD;;AACDJ,MAAAA,SAAS,GAAGiB,IAAZ;AACD;AACF;;AAED,SAAO;AACLG,IAAAA,OAAO,EAAElC,GADJ;AAELqB,IAAAA,SAAS,EAATA,SAFK;AAGLD,IAAAA,OAAO,EAAPA,OAHK;AAILE,IAAAA,YAAY,EAAZA;AAJK,GAAP;AAMD","sourcesContent":["import { copy, create, dot } from 'gl-vec2';\nimport { computeMiter, direction, normal } from 'polyline-miter-util';\n\nfunction extrusions(\n positions: number[][],\n out: any,\n point: number[],\n normal: number[],\n scale: number,\n) {\n addNext(out, normal, -scale);\n addNext(out, normal, scale);\n positions.push(point);\n positions.push(point);\n}\n\nfunction addNext(out: any[][], normal: number[], length: number) {\n out.push([[normal[0], normal[1]], length]);\n}\n\nexport default function(\n points: number[][],\n closed: boolean,\n indexOffset?: number,\n) {\n const lineA = [0, 0];\n const lineB = [0, 0];\n const tangent = [0, 0];\n const miter = [0, 0];\n let _lastFlip = -1;\n let _started = false;\n let _normal: any = null;\n const tmp = create();\n let count = indexOffset || 0;\n const miterLimit = 3;\n\n const out: any = [];\n const attrPos: number[][] = [];\n const attrIndex = [];\n const attrCounters: number[] = [0, 0];\n if (closed) {\n points = points.slice();\n points.push(points[0]);\n }\n\n const total = points.length;\n for (let i = 1; i < total; i++) {\n const index = count;\n const last = points[i - 1];\n const cur = points[i];\n const next = i < points.length - 1 ? points[i + 1] : null;\n\n attrCounters.push(i / total, i / total);\n\n direction(lineA, cur, last);\n\n if (!_normal) {\n _normal = [0, 0];\n normal(_normal, lineA);\n }\n\n if (!_started) {\n _started = true;\n extrusions(attrPos, out, last, _normal, 1);\n }\n\n attrIndex.push([index + 0, index + 1, index + 2]);\n\n if (!next) {\n // no miter, simple segment\n normal(_normal, lineA); // reset normal\n extrusions(attrPos, out, cur, _normal, 1);\n attrIndex.push(\n _lastFlip === 1\n ? [index, index + 2, index + 3]\n : [index + 2, index + 1, index + 3],\n );\n\n count += 2;\n } else {\n // miter with last\n // get unit dir of next line\n direction(lineB, next, cur);\n\n // stores tangent & miter\n let miterLen = computeMiter(tangent, miter, lineA, lineB, 1);\n\n // get orientation\n let flip = dot(tangent, _normal) < 0 ? -1 : 1;\n\n const bevel = miterLen > miterLimit;\n\n // 处理相邻线段重叠的情况\n if (!isFinite(miterLen)) {\n normal(_normal, lineA); // reset normal\n extrusions(attrPos, out, cur, _normal, 1);\n attrIndex.push(\n _lastFlip === 1\n ? [index, index + 2, index + 3]\n : [index + 2, index + 1, index + 3],\n );\n\n count += 2;\n _lastFlip = flip;\n continue;\n }\n\n if (bevel) {\n miterLen = miterLimit;\n attrCounters.push(i / total);\n\n // next two points in our first segment\n addNext(out, _normal, -flip);\n attrPos.push(cur);\n addNext(out, miter, miterLen * flip);\n attrPos.push(cur);\n\n attrIndex.push(\n _lastFlip !== -flip\n ? [index, index + 2, index + 3]\n : [index + 2, index + 1, index + 3],\n );\n\n // now add the bevel triangle\n attrIndex.push([index + 2, index + 3, index + 4]);\n\n normal(tmp, lineB);\n copy(_normal, tmp); // store normal for next round\n\n addNext(out, _normal, -flip);\n attrPos.push(cur);\n\n // the miter is now the normal for our next join\n count += 3;\n } else {\n // miter\n // next two points for our miter join\n extrusions(attrPos, out, cur, miter, miterLen);\n attrIndex.push(\n _lastFlip === 1\n ? [index, index + 2, index + 3]\n : [index + 2, index + 1, index + 3],\n );\n\n flip = -1;\n\n // the miter is now the normal for our next join\n copy(_normal, miter);\n count += 2;\n }\n _lastFlip = flip;\n }\n }\n\n return {\n normals: out,\n attrIndex,\n attrPos,\n attrCounters,\n };\n}\n"],"file":"polyline-normals.js"}
|