@realsee/dnalogel 2.0.0-alpha.52 → 2.0.0-alpha.53
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/dist/CruisePlugin/index.js +188 -5
- package/dist/GuideLinePlugin/index.js +188 -5
- package/dist/index.es.js +188 -2
- package/dist/index.js +188 -3
- package/dist/index.umd.js +192 -6
- package/docs/classes/CruisePluginController.html +14 -14
- package/docs/classes/Magnifier.html +4 -4
- package/docs/classes/ModelRoomLabelController.html +4 -4
- package/docs/enums/CameraMovementEffect.html +2 -2
- package/docs/enums/DIRECTION.html +1 -1
- package/docs/enums/DISPLAY_STRATEGY_TYPE.html +1 -1
- package/docs/enums/FLOOR_PLAN_ATTACHED_TO.html +1 -1
- package/docs/enums/ITEM_LABEL_PLUGIN_DISPLAY_STRATEGY_TYPE.html +1 -1
- package/docs/enums/Rotation.html +2 -2
- package/docs/index.html +1 -1
- package/docs/interfaces/CSS3DRenderPluginExportType.html +2 -2
- package/docs/interfaces/CameraMovementPluginExportType.html +2 -2
- package/docs/interfaces/FloorplanBounding.html +4 -4
- package/docs/interfaces/FloorplanData.html +2 -2
- package/docs/interfaces/FloorplanEntrance.html +7 -7
- package/docs/interfaces/FloorplanExtraObject.html +3 -3
- package/docs/interfaces/FloorplanExtraObject3D.html +2 -2
- package/docs/interfaces/FloorplanFloorData.html +2 -2
- package/docs/interfaces/FloorplanImagePosition.html +2 -2
- package/docs/interfaces/FloorplanObserver.html +2 -2
- package/docs/interfaces/FloorplanOutlineItem.html +2 -2
- package/docs/interfaces/FloorplanPosition.html +2 -2
- package/docs/interfaces/FloorplanRoomItem.html +6 -6
- package/docs/interfaces/FloorplanRoomLabelItem.html +3 -3
- package/docs/interfaces/FloorplanServerBounding.html +4 -4
- package/docs/interfaces/FloorplanServerComputedData.html +1 -1
- package/docs/interfaces/FloorplanServerData.html +2 -2
- package/docs/interfaces/FloorplanServerDoorItem.html +1 -1
- package/docs/interfaces/FloorplanServerDoorPosition.html +1 -1
- package/docs/interfaces/FloorplanServerEntrance.html +7 -7
- package/docs/interfaces/FloorplanServerFloorData.html +2 -2
- package/docs/interfaces/FloorplanServerImagePosition.html +2 -2
- package/docs/interfaces/FloorplanServerObserver.html +2 -2
- package/docs/interfaces/FloorplanServerOutlineItem.html +2 -2
- package/docs/interfaces/FloorplanServerPosition.html +2 -2
- package/docs/interfaces/FloorplanServerRoomItem.html +7 -7
- package/docs/interfaces/FloorplanServerRoomLabelItem.html +3 -3
- package/docs/interfaces/ItemLabelPluginData.html +1 -1
- package/docs/interfaces/ItemLabelPluginExportReturnsType.html +1 -1
- package/docs/interfaces/ItemLabelPluginParametersType.html +1 -1
- package/docs/interfaces/LineJson.html +1 -1
- package/docs/interfaces/ModelChassisCompassPluginData.html +1 -1
- package/docs/interfaces/ModelChassisCompassPluginExportType.html +1 -1
- package/docs/interfaces/ModelChassisCompassPluginParameterType.html +1 -1
- package/docs/interfaces/ModelEntryDoorGuidePluginData.html +1 -1
- package/docs/interfaces/ModelEntryDoorGuidePluginExportType.html +1 -1
- package/docs/interfaces/ModelItemLabelPluginData.html +1 -1
- package/docs/interfaces/ModelItemLabelPluginExportReturnsType.html +1 -1
- package/docs/interfaces/ModelItemLabelPluginParametersType.html +1 -1
- package/docs/interfaces/ModelRoomLabelPluginData.html +1 -1
- package/docs/interfaces/ModelTVVideoPluginData.html +1 -1
- package/docs/interfaces/ModelTVVideoPluginExportType.html +1 -1
- package/docs/interfaces/ModelTVVideoPluginParameterType.html +1 -1
- package/docs/interfaces/ModelViewPluginExportType.html +1 -1
- package/docs/interfaces/OpenParameter.html +2 -2
- package/docs/interfaces/PanoCursorRaycasterPluginExportType.html +6 -6
- package/docs/interfaces/PanoCursorRaycasterPluginParameterType.html +1 -1
- package/docs/interfaces/PanoMeasureParameterType.html +1 -1
- package/docs/interfaces/PanoRulerPluginExportType.html +1 -1
- package/docs/interfaces/PanoRulerPluginOptions.html +1 -1
- package/docs/interfaces/PanoRulerPluginParameterType.html +1 -1
- package/docs/interfaces/PanoRulerProPluginExportType.html +1 -1
- package/docs/interfaces/PanoRulerProPluginOptions.html +1 -1
- package/docs/interfaces/PanoRulerProPluginParameterType.html +1 -1
- package/docs/interfaces/PanoRulerProPluginState.html +1 -1
- package/docs/interfaces/PanoSpatialTagPluginContentEvent.html +1 -1
- package/docs/interfaces/PanoSpatialTagPluginContentReplacement.html +1 -1
- package/docs/interfaces/PanoSpatialTagPluginData.html +1 -1
- package/docs/interfaces/PanoSpatialTagPluginDataElement.html +1 -1
- package/docs/interfaces/PanoSpatialTagPluginExportType.html +1 -1
- package/docs/interfaces/PanoSpatialTagPluginOriginElement.html +1 -1
- package/docs/interfaces/PanoSpatialTagPluginParameterType.html +1 -1
- package/docs/interfaces/PanoSpatialTagPluginPointElement.html +1 -1
- package/docs/interfaces/PanoSpatialTagPluginTagElement.html +1 -1
- package/docs/interfaces/Point.html +1 -1
- package/docs/interfaces/PointJson.html +1 -1
- package/docs/interfaces/Room.html +1 -1
- package/docs/interfaces/RoomInfo.html +1 -1
- package/docs/interfaces/RoomLabel.html +7 -7
- package/docs/interfaces/RoomRules.html +1 -1
- package/docs/interfaces/Rooms.html +1 -1
- package/docs/modules.html +18 -18
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -15,7 +15,6 @@ var FBXLoader = require('three/examples/jsm/loaders/FBXLoader');
|
|
|
15
15
|
var TWEEN = require('@tweenjs/tween.js');
|
|
16
16
|
var Hammer = require('hammerjs');
|
|
17
17
|
var classNames = require('classnames');
|
|
18
|
-
var getNormals = require('polyline-normals');
|
|
19
18
|
|
|
20
19
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
21
20
|
|
|
@@ -42,7 +41,6 @@ var TWEEN__namespace = /*#__PURE__*/_interopNamespace(TWEEN);
|
|
|
42
41
|
var TWEEN__default = /*#__PURE__*/_interopDefaultLegacy(TWEEN);
|
|
43
42
|
var Hammer__default = /*#__PURE__*/_interopDefaultLegacy(Hammer);
|
|
44
43
|
var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
|
|
45
|
-
var getNormals__default = /*#__PURE__*/_interopDefaultLegacy(getNormals);
|
|
46
44
|
|
|
47
45
|
/**
|
|
48
46
|
* Five 模型插件
|
|
@@ -18116,6 +18114,193 @@ const PanoDoorLabelPlugin = (five) => {
|
|
|
18116
18114
|
return new PanoDoorLabelPluginController(five);
|
|
18117
18115
|
};
|
|
18118
18116
|
|
|
18117
|
+
var polylineMiterUtil = {};
|
|
18118
|
+
|
|
18119
|
+
var add_1 = add$1;
|
|
18120
|
+
|
|
18121
|
+
/**
|
|
18122
|
+
* Adds two vec2's
|
|
18123
|
+
*
|
|
18124
|
+
* @param {vec2} out the receiving vector
|
|
18125
|
+
* @param {vec2} a the first operand
|
|
18126
|
+
* @param {vec2} b the second operand
|
|
18127
|
+
* @returns {vec2} out
|
|
18128
|
+
*/
|
|
18129
|
+
function add$1(out, a, b) {
|
|
18130
|
+
out[0] = a[0] + b[0];
|
|
18131
|
+
out[1] = a[1] + b[1];
|
|
18132
|
+
return out
|
|
18133
|
+
}
|
|
18134
|
+
|
|
18135
|
+
var set_1 = set$1;
|
|
18136
|
+
|
|
18137
|
+
/**
|
|
18138
|
+
* Set the components of a vec2 to the given values
|
|
18139
|
+
*
|
|
18140
|
+
* @param {vec2} out the receiving vector
|
|
18141
|
+
* @param {Number} x X component
|
|
18142
|
+
* @param {Number} y Y component
|
|
18143
|
+
* @returns {vec2} out
|
|
18144
|
+
*/
|
|
18145
|
+
function set$1(out, x, y) {
|
|
18146
|
+
out[0] = x;
|
|
18147
|
+
out[1] = y;
|
|
18148
|
+
return out
|
|
18149
|
+
}
|
|
18150
|
+
|
|
18151
|
+
var normalize_1 = normalize$1;
|
|
18152
|
+
|
|
18153
|
+
/**
|
|
18154
|
+
* Normalize a vec2
|
|
18155
|
+
*
|
|
18156
|
+
* @param {vec2} out the receiving vector
|
|
18157
|
+
* @param {vec2} a vector to normalize
|
|
18158
|
+
* @returns {vec2} out
|
|
18159
|
+
*/
|
|
18160
|
+
function normalize$1(out, a) {
|
|
18161
|
+
var x = a[0],
|
|
18162
|
+
y = a[1];
|
|
18163
|
+
var len = x*x + y*y;
|
|
18164
|
+
if (len > 0) {
|
|
18165
|
+
//TODO: evaluate use of glm_invsqrt here?
|
|
18166
|
+
len = 1 / Math.sqrt(len);
|
|
18167
|
+
out[0] = a[0] * len;
|
|
18168
|
+
out[1] = a[1] * len;
|
|
18169
|
+
}
|
|
18170
|
+
return out
|
|
18171
|
+
}
|
|
18172
|
+
|
|
18173
|
+
var subtract_1 = subtract$1;
|
|
18174
|
+
|
|
18175
|
+
/**
|
|
18176
|
+
* Subtracts vector b from vector a
|
|
18177
|
+
*
|
|
18178
|
+
* @param {vec2} out the receiving vector
|
|
18179
|
+
* @param {vec2} a the first operand
|
|
18180
|
+
* @param {vec2} b the second operand
|
|
18181
|
+
* @returns {vec2} out
|
|
18182
|
+
*/
|
|
18183
|
+
function subtract$1(out, a, b) {
|
|
18184
|
+
out[0] = a[0] - b[0];
|
|
18185
|
+
out[1] = a[1] - b[1];
|
|
18186
|
+
return out
|
|
18187
|
+
}
|
|
18188
|
+
|
|
18189
|
+
var dot_1 = dot$1;
|
|
18190
|
+
|
|
18191
|
+
/**
|
|
18192
|
+
* Calculates the dot product of two vec2's
|
|
18193
|
+
*
|
|
18194
|
+
* @param {vec2} a the first operand
|
|
18195
|
+
* @param {vec2} b the second operand
|
|
18196
|
+
* @returns {Number} dot product of a and b
|
|
18197
|
+
*/
|
|
18198
|
+
function dot$1(a, b) {
|
|
18199
|
+
return a[0] * b[0] + a[1] * b[1]
|
|
18200
|
+
}
|
|
18201
|
+
|
|
18202
|
+
var add = add_1;
|
|
18203
|
+
var set = set_1;
|
|
18204
|
+
var normalize = normalize_1;
|
|
18205
|
+
var subtract = subtract_1;
|
|
18206
|
+
var dot = dot_1;
|
|
18207
|
+
|
|
18208
|
+
var tmp = [0, 0];
|
|
18209
|
+
|
|
18210
|
+
polylineMiterUtil.computeMiter = function computeMiter(tangent, miter, lineA, lineB, halfThick) {
|
|
18211
|
+
//get tangent line
|
|
18212
|
+
add(tangent, lineA, lineB);
|
|
18213
|
+
normalize(tangent, tangent);
|
|
18214
|
+
|
|
18215
|
+
//get miter as a unit vector
|
|
18216
|
+
set(miter, -tangent[1], tangent[0]);
|
|
18217
|
+
set(tmp, -lineA[1], lineA[0]);
|
|
18218
|
+
|
|
18219
|
+
//get the necessary length of our miter
|
|
18220
|
+
return halfThick / dot(miter, tmp)
|
|
18221
|
+
};
|
|
18222
|
+
|
|
18223
|
+
polylineMiterUtil.normal = function normal(out, dir) {
|
|
18224
|
+
//get perpendicular
|
|
18225
|
+
set(out, -dir[1], dir[0]);
|
|
18226
|
+
return out
|
|
18227
|
+
};
|
|
18228
|
+
|
|
18229
|
+
polylineMiterUtil.direction = function direction(out, a, b) {
|
|
18230
|
+
//get unit dir of two lines
|
|
18231
|
+
subtract(out, a, b);
|
|
18232
|
+
normalize(out, out);
|
|
18233
|
+
return out
|
|
18234
|
+
};
|
|
18235
|
+
|
|
18236
|
+
var util = polylineMiterUtil;
|
|
18237
|
+
|
|
18238
|
+
var lineA = [0, 0];
|
|
18239
|
+
var lineB = [0, 0];
|
|
18240
|
+
var tangent = [0, 0];
|
|
18241
|
+
var miter = [0, 0];
|
|
18242
|
+
|
|
18243
|
+
var polylineNormals = function(points, closed) {
|
|
18244
|
+
var curNormal = null;
|
|
18245
|
+
var out = [];
|
|
18246
|
+
if (closed) {
|
|
18247
|
+
points = points.slice();
|
|
18248
|
+
points.push(points[0]);
|
|
18249
|
+
}
|
|
18250
|
+
|
|
18251
|
+
var total = points.length;
|
|
18252
|
+
for (var i=1; i<total; i++) {
|
|
18253
|
+
var last = points[i-1];
|
|
18254
|
+
var cur = points[i];
|
|
18255
|
+
var next = i<points.length-1 ? points[i+1] : null;
|
|
18256
|
+
|
|
18257
|
+
util.direction(lineA, cur, last);
|
|
18258
|
+
if (!curNormal) {
|
|
18259
|
+
curNormal = [0, 0];
|
|
18260
|
+
util.normal(curNormal, lineA);
|
|
18261
|
+
}
|
|
18262
|
+
|
|
18263
|
+
if (i === 1) //add initial normals
|
|
18264
|
+
addNext(out, curNormal, 1);
|
|
18265
|
+
|
|
18266
|
+
if (!next) { //no miter, simple segment
|
|
18267
|
+
util.normal(curNormal, lineA); //reset normal
|
|
18268
|
+
addNext(out, curNormal, 1);
|
|
18269
|
+
} else { //miter with last
|
|
18270
|
+
//get unit dir of next line
|
|
18271
|
+
util.direction(lineB, next, cur);
|
|
18272
|
+
|
|
18273
|
+
//stores tangent & miter
|
|
18274
|
+
var miterLen = util.computeMiter(tangent, miter, lineA, lineB, 1);
|
|
18275
|
+
addNext(out, miter, miterLen);
|
|
18276
|
+
}
|
|
18277
|
+
}
|
|
18278
|
+
|
|
18279
|
+
//if the polyline is a closed loop, clean up the last normal
|
|
18280
|
+
if (points.length > 2 && closed) {
|
|
18281
|
+
var last2 = points[total-2];
|
|
18282
|
+
var cur2 = points[0];
|
|
18283
|
+
var next2 = points[1];
|
|
18284
|
+
|
|
18285
|
+
util.direction(lineA, cur2, last2);
|
|
18286
|
+
util.direction(lineB, next2, cur2);
|
|
18287
|
+
util.normal(curNormal, lineA);
|
|
18288
|
+
|
|
18289
|
+
var miterLen2 = util.computeMiter(tangent, miter, lineA, lineB, 1);
|
|
18290
|
+
out[0][0] = miter.slice();
|
|
18291
|
+
out[total-1][0] = miter.slice();
|
|
18292
|
+
out[0][1] = miterLen2;
|
|
18293
|
+
out[total-1][1] = miterLen2;
|
|
18294
|
+
out.pop();
|
|
18295
|
+
}
|
|
18296
|
+
|
|
18297
|
+
return out
|
|
18298
|
+
};
|
|
18299
|
+
|
|
18300
|
+
function addNext(out, normal, length) {
|
|
18301
|
+
out.push([[normal[0], normal[1]], length]);
|
|
18302
|
+
}
|
|
18303
|
+
|
|
18119
18304
|
// 定义常量
|
|
18120
18305
|
const TRIANGLE_NUMBER_OF_RECTANGLE = 2; // 每个矩形有两个三角形
|
|
18121
18306
|
const VERTEX_NUMBER_OF_TRIANGLE = 3; // 每个三角形有三个顶点
|
|
@@ -18135,7 +18320,7 @@ function getLineGeometry(positionList) {
|
|
|
18135
18320
|
const divisions = Math.ceil(curve.getLength()); // 曲线切片数
|
|
18136
18321
|
const curvePoints = curve.getPoints(divisions);
|
|
18137
18322
|
const curvePointsLength = curvePoints.length;
|
|
18138
|
-
const normals =
|
|
18323
|
+
const normals = polylineNormals(curvePoints.map((p) => [p.x, p.z])); // curvePoints:每个点切线的向量「二维」
|
|
18139
18324
|
const rectangleNumber = curvePoints.length - 1; // 曲线上 N 个点,构成了 N - 1 个矩形
|
|
18140
18325
|
const indexNumber = rectangleNumber * TRIANGLE_NUMBER_OF_RECTANGLE * VERTEX_NUMBER_OF_TRIANGLE;
|
|
18141
18326
|
const verticesNumber = 2 * curvePointsLength; // 顶点数量(包含公用):每个曲线点对应两个顶点,N 个 点有 2N 个顶点
|
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('three'), require('three/examples/jsm/renderers/CSS3DRenderer'), require('@realsee/five/line'), require('svelte/internal'), require('svelte'), require('svelte/easing'), require('svelte/transition'), require('svelte/store'), require('@realsee/five'), require('three/examples/jsm/loaders/FBXLoader'), require('@tweenjs/tween.js'), require('hammerjs'), require('classnames')
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'three', 'three/examples/jsm/renderers/CSS3DRenderer', '@realsee/five/line', 'svelte/internal', 'svelte', 'svelte/easing', 'svelte/transition', 'svelte/store', '@realsee/five', 'three/examples/jsm/loaders/FBXLoader', '@tweenjs/tween.js', 'hammerjs', 'classnames'
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.dnalogel = {}, global.THREE, global.CSS3DRenderer, global.FiveSDK_Line, global.internal, global.svelte, global.easing, global.transition, global.store, global.five, global.FBXLoader, global.TWEEN, global.Hammer, global.classNames
|
|
5
|
-
})(this, (function (exports, THREE, CSS3DRenderer, line, internal, svelte, easing, transition, store, five, FBXLoader, TWEEN, Hammer, classNames
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('three'), require('three/examples/jsm/renderers/CSS3DRenderer'), require('@realsee/five/line'), require('svelte/internal'), require('svelte'), require('svelte/easing'), require('svelte/transition'), require('svelte/store'), require('@realsee/five'), require('three/examples/jsm/loaders/FBXLoader'), require('@tweenjs/tween.js'), require('hammerjs'), require('classnames')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'three', 'three/examples/jsm/renderers/CSS3DRenderer', '@realsee/five/line', 'svelte/internal', 'svelte', 'svelte/easing', 'svelte/transition', 'svelte/store', '@realsee/five', 'three/examples/jsm/loaders/FBXLoader', '@tweenjs/tween.js', 'hammerjs', 'classnames'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.dnalogel = {}, global.THREE, global.CSS3DRenderer, global.FiveSDK_Line, global.internal, global.svelte, global.easing, global.transition, global.store, global.five, global.FBXLoader, global.TWEEN, global.Hammer, global.classNames));
|
|
5
|
+
})(this, (function (exports, THREE, CSS3DRenderer, line, internal, svelte, easing, transition, store, five, FBXLoader, TWEEN, Hammer, classNames) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
var TWEEN__default = /*#__PURE__*/_interopDefaultLegacy(TWEEN);
|
|
30
30
|
var Hammer__default = /*#__PURE__*/_interopDefaultLegacy(Hammer);
|
|
31
31
|
var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
|
|
32
|
-
var getNormals__default = /*#__PURE__*/_interopDefaultLegacy(getNormals);
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
34
|
* Five 模型插件
|
|
@@ -18103,6 +18102,193 @@ void main() {
|
|
|
18103
18102
|
return new PanoDoorLabelPluginController(five);
|
|
18104
18103
|
};
|
|
18105
18104
|
|
|
18105
|
+
var polylineMiterUtil = {};
|
|
18106
|
+
|
|
18107
|
+
var add_1 = add$1;
|
|
18108
|
+
|
|
18109
|
+
/**
|
|
18110
|
+
* Adds two vec2's
|
|
18111
|
+
*
|
|
18112
|
+
* @param {vec2} out the receiving vector
|
|
18113
|
+
* @param {vec2} a the first operand
|
|
18114
|
+
* @param {vec2} b the second operand
|
|
18115
|
+
* @returns {vec2} out
|
|
18116
|
+
*/
|
|
18117
|
+
function add$1(out, a, b) {
|
|
18118
|
+
out[0] = a[0] + b[0];
|
|
18119
|
+
out[1] = a[1] + b[1];
|
|
18120
|
+
return out
|
|
18121
|
+
}
|
|
18122
|
+
|
|
18123
|
+
var set_1 = set$1;
|
|
18124
|
+
|
|
18125
|
+
/**
|
|
18126
|
+
* Set the components of a vec2 to the given values
|
|
18127
|
+
*
|
|
18128
|
+
* @param {vec2} out the receiving vector
|
|
18129
|
+
* @param {Number} x X component
|
|
18130
|
+
* @param {Number} y Y component
|
|
18131
|
+
* @returns {vec2} out
|
|
18132
|
+
*/
|
|
18133
|
+
function set$1(out, x, y) {
|
|
18134
|
+
out[0] = x;
|
|
18135
|
+
out[1] = y;
|
|
18136
|
+
return out
|
|
18137
|
+
}
|
|
18138
|
+
|
|
18139
|
+
var normalize_1 = normalize$1;
|
|
18140
|
+
|
|
18141
|
+
/**
|
|
18142
|
+
* Normalize a vec2
|
|
18143
|
+
*
|
|
18144
|
+
* @param {vec2} out the receiving vector
|
|
18145
|
+
* @param {vec2} a vector to normalize
|
|
18146
|
+
* @returns {vec2} out
|
|
18147
|
+
*/
|
|
18148
|
+
function normalize$1(out, a) {
|
|
18149
|
+
var x = a[0],
|
|
18150
|
+
y = a[1];
|
|
18151
|
+
var len = x*x + y*y;
|
|
18152
|
+
if (len > 0) {
|
|
18153
|
+
//TODO: evaluate use of glm_invsqrt here?
|
|
18154
|
+
len = 1 / Math.sqrt(len);
|
|
18155
|
+
out[0] = a[0] * len;
|
|
18156
|
+
out[1] = a[1] * len;
|
|
18157
|
+
}
|
|
18158
|
+
return out
|
|
18159
|
+
}
|
|
18160
|
+
|
|
18161
|
+
var subtract_1 = subtract$1;
|
|
18162
|
+
|
|
18163
|
+
/**
|
|
18164
|
+
* Subtracts vector b from vector a
|
|
18165
|
+
*
|
|
18166
|
+
* @param {vec2} out the receiving vector
|
|
18167
|
+
* @param {vec2} a the first operand
|
|
18168
|
+
* @param {vec2} b the second operand
|
|
18169
|
+
* @returns {vec2} out
|
|
18170
|
+
*/
|
|
18171
|
+
function subtract$1(out, a, b) {
|
|
18172
|
+
out[0] = a[0] - b[0];
|
|
18173
|
+
out[1] = a[1] - b[1];
|
|
18174
|
+
return out
|
|
18175
|
+
}
|
|
18176
|
+
|
|
18177
|
+
var dot_1 = dot$1;
|
|
18178
|
+
|
|
18179
|
+
/**
|
|
18180
|
+
* Calculates the dot product of two vec2's
|
|
18181
|
+
*
|
|
18182
|
+
* @param {vec2} a the first operand
|
|
18183
|
+
* @param {vec2} b the second operand
|
|
18184
|
+
* @returns {Number} dot product of a and b
|
|
18185
|
+
*/
|
|
18186
|
+
function dot$1(a, b) {
|
|
18187
|
+
return a[0] * b[0] + a[1] * b[1]
|
|
18188
|
+
}
|
|
18189
|
+
|
|
18190
|
+
var add = add_1;
|
|
18191
|
+
var set = set_1;
|
|
18192
|
+
var normalize = normalize_1;
|
|
18193
|
+
var subtract = subtract_1;
|
|
18194
|
+
var dot = dot_1;
|
|
18195
|
+
|
|
18196
|
+
var tmp = [0, 0];
|
|
18197
|
+
|
|
18198
|
+
polylineMiterUtil.computeMiter = function computeMiter(tangent, miter, lineA, lineB, halfThick) {
|
|
18199
|
+
//get tangent line
|
|
18200
|
+
add(tangent, lineA, lineB);
|
|
18201
|
+
normalize(tangent, tangent);
|
|
18202
|
+
|
|
18203
|
+
//get miter as a unit vector
|
|
18204
|
+
set(miter, -tangent[1], tangent[0]);
|
|
18205
|
+
set(tmp, -lineA[1], lineA[0]);
|
|
18206
|
+
|
|
18207
|
+
//get the necessary length of our miter
|
|
18208
|
+
return halfThick / dot(miter, tmp)
|
|
18209
|
+
};
|
|
18210
|
+
|
|
18211
|
+
polylineMiterUtil.normal = function normal(out, dir) {
|
|
18212
|
+
//get perpendicular
|
|
18213
|
+
set(out, -dir[1], dir[0]);
|
|
18214
|
+
return out
|
|
18215
|
+
};
|
|
18216
|
+
|
|
18217
|
+
polylineMiterUtil.direction = function direction(out, a, b) {
|
|
18218
|
+
//get unit dir of two lines
|
|
18219
|
+
subtract(out, a, b);
|
|
18220
|
+
normalize(out, out);
|
|
18221
|
+
return out
|
|
18222
|
+
};
|
|
18223
|
+
|
|
18224
|
+
var util = polylineMiterUtil;
|
|
18225
|
+
|
|
18226
|
+
var lineA = [0, 0];
|
|
18227
|
+
var lineB = [0, 0];
|
|
18228
|
+
var tangent = [0, 0];
|
|
18229
|
+
var miter = [0, 0];
|
|
18230
|
+
|
|
18231
|
+
var polylineNormals = function(points, closed) {
|
|
18232
|
+
var curNormal = null;
|
|
18233
|
+
var out = [];
|
|
18234
|
+
if (closed) {
|
|
18235
|
+
points = points.slice();
|
|
18236
|
+
points.push(points[0]);
|
|
18237
|
+
}
|
|
18238
|
+
|
|
18239
|
+
var total = points.length;
|
|
18240
|
+
for (var i=1; i<total; i++) {
|
|
18241
|
+
var last = points[i-1];
|
|
18242
|
+
var cur = points[i];
|
|
18243
|
+
var next = i<points.length-1 ? points[i+1] : null;
|
|
18244
|
+
|
|
18245
|
+
util.direction(lineA, cur, last);
|
|
18246
|
+
if (!curNormal) {
|
|
18247
|
+
curNormal = [0, 0];
|
|
18248
|
+
util.normal(curNormal, lineA);
|
|
18249
|
+
}
|
|
18250
|
+
|
|
18251
|
+
if (i === 1) //add initial normals
|
|
18252
|
+
addNext(out, curNormal, 1);
|
|
18253
|
+
|
|
18254
|
+
if (!next) { //no miter, simple segment
|
|
18255
|
+
util.normal(curNormal, lineA); //reset normal
|
|
18256
|
+
addNext(out, curNormal, 1);
|
|
18257
|
+
} else { //miter with last
|
|
18258
|
+
//get unit dir of next line
|
|
18259
|
+
util.direction(lineB, next, cur);
|
|
18260
|
+
|
|
18261
|
+
//stores tangent & miter
|
|
18262
|
+
var miterLen = util.computeMiter(tangent, miter, lineA, lineB, 1);
|
|
18263
|
+
addNext(out, miter, miterLen);
|
|
18264
|
+
}
|
|
18265
|
+
}
|
|
18266
|
+
|
|
18267
|
+
//if the polyline is a closed loop, clean up the last normal
|
|
18268
|
+
if (points.length > 2 && closed) {
|
|
18269
|
+
var last2 = points[total-2];
|
|
18270
|
+
var cur2 = points[0];
|
|
18271
|
+
var next2 = points[1];
|
|
18272
|
+
|
|
18273
|
+
util.direction(lineA, cur2, last2);
|
|
18274
|
+
util.direction(lineB, next2, cur2);
|
|
18275
|
+
util.normal(curNormal, lineA);
|
|
18276
|
+
|
|
18277
|
+
var miterLen2 = util.computeMiter(tangent, miter, lineA, lineB, 1);
|
|
18278
|
+
out[0][0] = miter.slice();
|
|
18279
|
+
out[total-1][0] = miter.slice();
|
|
18280
|
+
out[0][1] = miterLen2;
|
|
18281
|
+
out[total-1][1] = miterLen2;
|
|
18282
|
+
out.pop();
|
|
18283
|
+
}
|
|
18284
|
+
|
|
18285
|
+
return out
|
|
18286
|
+
};
|
|
18287
|
+
|
|
18288
|
+
function addNext(out, normal, length) {
|
|
18289
|
+
out.push([[normal[0], normal[1]], length]);
|
|
18290
|
+
}
|
|
18291
|
+
|
|
18106
18292
|
// 定义常量
|
|
18107
18293
|
const TRIANGLE_NUMBER_OF_RECTANGLE = 2; // 每个矩形有两个三角形
|
|
18108
18294
|
const VERTEX_NUMBER_OF_TRIANGLE = 3; // 每个三角形有三个顶点
|
|
@@ -18122,7 +18308,7 @@ void main() {
|
|
|
18122
18308
|
const divisions = Math.ceil(curve.getLength()); // 曲线切片数
|
|
18123
18309
|
const curvePoints = curve.getPoints(divisions);
|
|
18124
18310
|
const curvePointsLength = curvePoints.length;
|
|
18125
|
-
const normals =
|
|
18311
|
+
const normals = polylineNormals(curvePoints.map((p) => [p.x, p.z])); // curvePoints:每个点切线的向量「二维」
|
|
18126
18312
|
const rectangleNumber = curvePoints.length - 1; // 曲线上 N 个点,构成了 N - 1 个矩形
|
|
18127
18313
|
const indexNumber = rectangleNumber * TRIANGLE_NUMBER_OF_RECTANGLE * VERTEX_NUMBER_OF_TRIANGLE;
|
|
18128
18314
|
const verticesNumber = 2 * curvePointsLength; // 顶点数量(包含公用):每个曲线点对应两个顶点,N 个 点有 2N 个顶点
|