@shapediver/viewer.data-engine.tag3d-engine 2.12.8 → 3.0.0
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/Tag3dEngine.d.ts +4 -4
- package/dist/Tag3dEngine.d.ts.map +1 -1
- package/dist/Tag3dEngine.js +40 -139
- package/dist/Tag3dEngine.js.map +1 -1
- package/package.json +6 -10
- package/src/Tag3dEngine.ts +35 -134
- package/dist/font.d.ts +0 -2365
- package/dist/font.d.ts.map +0 -1
- package/dist/font.js +0 -6
- package/dist/font.js.map +0 -1
- package/dist/three/geometries/TextGeometry.d.ts +0 -22
- package/dist/three/geometries/TextGeometry.d.ts.map +0 -1
- package/dist/three/geometries/TextGeometry.js +0 -45
- package/dist/three/geometries/TextGeometry.js.map +0 -1
- package/dist/three/loaders/FontLoader.d.ts +0 -15
- package/dist/three/loaders/FontLoader.d.ts.map +0 -1
- package/dist/three/loaders/FontLoader.js +0 -118
- package/dist/three/loaders/FontLoader.js.map +0 -1
- package/src/font.ts +0 -2
- package/src/three/geometries/TextGeometry.ts +0 -58
- package/src/three/loaders/FontLoader.ts +0 -205
package/dist/Tag3dEngine.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { ITag3D } from '@shapediver/viewer.data-engine.shared-types';
|
|
1
2
|
import { ITreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
2
3
|
import { ShapeDiverResponseOutputContent } from '@shapediver/sdk.geometry-api-sdk-v2';
|
|
3
4
|
export declare class Tag3dEngine {
|
|
4
|
-
private
|
|
5
|
-
private readonly _httpClient;
|
|
6
|
-
private readonly _logger;
|
|
5
|
+
#private;
|
|
7
6
|
private readonly _stateEngine;
|
|
8
7
|
private static _instance;
|
|
9
|
-
private _font;
|
|
10
8
|
static get instance(): Tag3dEngine;
|
|
9
|
+
get geometryCreator(): ((tag3dInfo: ITag3D) => ITreeNode | undefined) | undefined;
|
|
10
|
+
set geometryCreator(value: ((tag3dInfo: ITag3D) => ITreeNode | undefined) | undefined);
|
|
11
11
|
/**
|
|
12
12
|
* Load the tag3d content into a scene graph node.
|
|
13
13
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tag3dEngine.d.ts","sourceRoot":"","sources":["../src/Tag3dEngine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAY,MAAM,qCAAqC,
|
|
1
|
+
{"version":3,"file":"Tag3dEngine.d.ts","sourceRoot":"","sources":["../src/Tag3dEngine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,6CAA6C,CAAC;AACrE,OAAO,EAAE,SAAS,EAAY,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAC;AAGtF,qBAAa,WAAW;;IAGpB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqC;IAElE,OAAO,CAAC,MAAM,CAAC,SAAS,CAAc;IAQtC,WAAkB,QAAQ,gBAEzB;IAMD,IAAW,eAAe,IAIQ,CAAC,CAAC,SAAS,EAAE,MAAM,KAAK,SAAS,GAAG,SAAS,CAAC,GAAG,SAAS,CAF3F;IAED,IAAW,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,SAAS,EAAE,MAAM,KAAK,SAAS,GAAG,SAAS,CAAC,GAAG,SAAS,EAE3F;IAMD;;;;;OAKG;IACU,WAAW,CAAC,OAAO,EAAE,+BAA+B,GAAG,OAAO,CAAC,SAAS,CAAC;CA+BzF"}
|
package/dist/Tag3dEngine.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -31,30 +8,44 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
9
|
});
|
|
33
10
|
};
|
|
11
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
14
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
+
};
|
|
16
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
17
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
20
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
21
|
+
};
|
|
22
|
+
var _Tag3dEngine_geometryCreator;
|
|
34
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
24
|
exports.Tag3dEngine = void 0;
|
|
36
|
-
const
|
|
25
|
+
const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
|
|
37
26
|
const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
|
|
38
27
|
const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
|
|
39
|
-
const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
|
|
40
|
-
const TextGeometry_1 = require("./three/geometries/TextGeometry");
|
|
41
|
-
const FontLoader_1 = require("./three/loaders/FontLoader");
|
|
42
|
-
const font_1 = require("./font");
|
|
43
28
|
class Tag3dEngine {
|
|
44
29
|
constructor() {
|
|
45
|
-
// #region Properties (
|
|
46
|
-
this._converter = viewer_shared_services_1.Converter.instance;
|
|
47
|
-
this._httpClient = viewer_shared_services_1.HttpClient.instance;
|
|
48
|
-
this._logger = viewer_shared_services_1.Logger.instance;
|
|
30
|
+
// #region Properties (3)
|
|
49
31
|
this._stateEngine = viewer_shared_services_1.StateEngine.instance;
|
|
32
|
+
_Tag3dEngine_geometryCreator.set(this, void 0);
|
|
50
33
|
// #endregion Public Methods (1)
|
|
51
34
|
}
|
|
52
|
-
// #endregion Properties (
|
|
53
|
-
// #region Public Static
|
|
35
|
+
// #endregion Properties (3)
|
|
36
|
+
// #region Public Static Getters And Setters (1)
|
|
54
37
|
static get instance() {
|
|
55
38
|
return this._instance || (this._instance = new this());
|
|
56
39
|
}
|
|
57
|
-
// #endregion Public Static
|
|
40
|
+
// #endregion Public Static Getters And Setters (1)
|
|
41
|
+
// #region Public Getters And Setters (2)
|
|
42
|
+
get geometryCreator() {
|
|
43
|
+
return __classPrivateFieldGet(this, _Tag3dEngine_geometryCreator, "f");
|
|
44
|
+
}
|
|
45
|
+
set geometryCreator(value) {
|
|
46
|
+
__classPrivateFieldSet(this, _Tag3dEngine_geometryCreator, value, "f");
|
|
47
|
+
}
|
|
48
|
+
// #endregion Public Getters And Setters (2)
|
|
58
49
|
// #region Public Methods (1)
|
|
59
50
|
/**
|
|
60
51
|
* Load the tag3d content into a scene graph node.
|
|
@@ -64,118 +55,27 @@ class Tag3dEngine {
|
|
|
64
55
|
*/
|
|
65
56
|
loadContent(content) {
|
|
66
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
if (!this._font) {
|
|
68
|
-
this._font = new FontLoader_1.Font(font_1.font);
|
|
69
|
-
this._stateEngine.fontLoaded.resolve(true);
|
|
70
|
-
}
|
|
71
58
|
const node = new viewer_shared_node_tree_1.TreeNode('tag3d');
|
|
72
59
|
if (this._stateEngine.fontLoaded.resolved === false)
|
|
73
60
|
yield this._stateEngine.fontLoaded;
|
|
74
61
|
if (!content)
|
|
75
62
|
throw new viewer_shared_services_1.ShapeDiverViewerDataProcessingError('Tag3dEngine.loadContent: Invalid content was provided to tag3d engine.');
|
|
76
63
|
if (content.data && Array.isArray(content.data)) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
let lineArray = [];
|
|
84
|
-
for (let lineIndex = 0; lineIndex < tagLines.length; ++lineIndex) {
|
|
85
|
-
if (tagLines[lineIndex] === '')
|
|
86
|
-
continue;
|
|
87
|
-
// create tag mesh object
|
|
88
|
-
let tag = new TextGeometry_1.TextGeometry(tagLines[lineIndex], { size: tag3dInfo.size, height: tag3dInfo.size / 10, font: this._font });
|
|
89
|
-
lineArray.push(tag);
|
|
90
|
-
}
|
|
91
|
-
// create temporary object
|
|
92
|
-
let parentObject = new THREE.Object3D();
|
|
93
|
-
for (let line of lineArray) {
|
|
94
|
-
parentObject.add(new THREE.Mesh(line, new THREE.MeshPhongMaterial()));
|
|
95
|
-
}
|
|
96
|
-
// align lines
|
|
97
|
-
let bb, extentsX, extentsY, lineHeight = 0;
|
|
98
|
-
{
|
|
99
|
-
lineHeight = 0;
|
|
100
|
-
for (let child of parentObject.children) {
|
|
101
|
-
bb = new THREE.Box3().setFromObject(child);
|
|
102
|
-
extentsY = bb.max.y - bb.min.y;
|
|
103
|
-
lineHeight = Math.max(lineHeight, extentsY);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
lineHeight *= 1.15;
|
|
107
|
-
lineArray.forEach((line, i) => {
|
|
108
|
-
line.translate(0, (-i - 1) * lineHeight, 0);
|
|
109
|
-
});
|
|
110
|
-
// justification
|
|
111
|
-
bb = new THREE.Box3().setFromObject(parentObject);
|
|
112
|
-
extentsX = bb.max.x - bb.min.x;
|
|
113
|
-
extentsY = bb.max.y - bb.min.y;
|
|
114
|
-
var tagJustTranslation = new THREE.Vector3(0, 0, 0);
|
|
115
|
-
switch (tag3dInfo.justification) {
|
|
116
|
-
case 'TL':
|
|
117
|
-
break;
|
|
118
|
-
case 'TC':
|
|
119
|
-
tagJustTranslation.x = -extentsX * 0.5;
|
|
120
|
-
break;
|
|
121
|
-
case 'TR':
|
|
122
|
-
tagJustTranslation.x = -extentsX;
|
|
123
|
-
break;
|
|
124
|
-
case 'ML':
|
|
125
|
-
tagJustTranslation.y = extentsY * 0.5;
|
|
126
|
-
break;
|
|
127
|
-
case 'MC':
|
|
128
|
-
tagJustTranslation.x = -extentsX * 0.5;
|
|
129
|
-
tagJustTranslation.y = extentsY * 0.5;
|
|
130
|
-
break;
|
|
131
|
-
case 'MR':
|
|
132
|
-
tagJustTranslation.x = -extentsX;
|
|
133
|
-
tagJustTranslation.y = extentsY * 0.5;
|
|
134
|
-
break;
|
|
135
|
-
case 'BL':
|
|
136
|
-
tagJustTranslation.y = extentsY;
|
|
137
|
-
break;
|
|
138
|
-
case 'BC':
|
|
139
|
-
tagJustTranslation.x = -extentsX * 0.5;
|
|
140
|
-
tagJustTranslation.y = extentsY;
|
|
141
|
-
break;
|
|
142
|
-
case 'BR':
|
|
143
|
-
tagJustTranslation.x = -extentsX;
|
|
144
|
-
tagJustTranslation.y = extentsY;
|
|
145
|
-
break;
|
|
64
|
+
if (__classPrivateFieldGet(this, _Tag3dEngine_geometryCreator, "f")) {
|
|
65
|
+
for (let i = 0; i < content.data.length; i++) {
|
|
66
|
+
const tag3dInfo = content.data[i];
|
|
67
|
+
const child = __classPrivateFieldGet(this, _Tag3dEngine_geometryCreator, "f").call(this, tag3dInfo);
|
|
68
|
+
if (child)
|
|
69
|
+
node.addChild(child);
|
|
146
70
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
rotMatrix.set(tag3dInfo.location.xAxis.X, tag3dInfo.location.yAxis.X, tag3dInfo.location.normal.X, 0, tag3dInfo.location.xAxis.Y, tag3dInfo.location.yAxis.Y, tag3dInfo.location.normal.Y, 0, tag3dInfo.location.xAxis.Z, tag3dInfo.location.yAxis.Z, tag3dInfo.location.normal.Z, 0, 0, 0, 0, 1);
|
|
154
|
-
for (let line of lineArray) {
|
|
155
|
-
line.applyMatrix4(rotMatrix);
|
|
156
|
-
line.translate(tag3dInfo.location.origin.X, tag3dInfo.location.origin.Y, tag3dInfo.location.origin.Z);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
for (let line of lineArray) {
|
|
160
|
-
const attributes = {};
|
|
161
|
-
for (let attribute in line.attributes) {
|
|
162
|
-
let attributeName = attribute.toUpperCase();
|
|
163
|
-
if (/\d/.test(attributeName) && !attributeName.includes('_')) {
|
|
164
|
-
const index = attributeName.search(/\d/);
|
|
165
|
-
attributeName = attributeName.substring(0, index) + '_' + attributeName.substring(index, attributeName.length);
|
|
166
|
-
}
|
|
167
|
-
else if (attributeName === 'TEXCOORD' || attributeName === 'COLOR' || attributeName === 'JOINTS' || attributeName === 'WEIGHTS') {
|
|
168
|
-
attributeName += '_0';
|
|
169
|
-
}
|
|
170
|
-
else if (attributeName === 'UV') {
|
|
171
|
-
attributeName = 'TEXCOORD_0';
|
|
172
|
-
}
|
|
173
|
-
attributes[attributeName] = new viewer_shared_types_1.AttributeData(line.attributes[attribute].array, line.attributes[attribute].itemSize, 0, 0, 0, false, line.attributes[attribute].array.length / line.attributes[attribute].itemSize);
|
|
174
|
-
}
|
|
175
|
-
const child = new viewer_shared_node_tree_1.TreeNode('tag3d_' + line);
|
|
176
|
-
child.data.push(new viewer_shared_types_1.GeometryData(new viewer_shared_types_1.PrimitiveData(attributes, null), viewer_shared_types_1.PRIMITIVE_MODE.TRIANGLES, new viewer_shared_types_1.MaterialStandardData({ color: tag3dInfo.color, metalness: 0, roughness: 1 })));
|
|
177
|
-
node.children.push(child);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const customData = new viewer_shared_types_1.CustomData({});
|
|
74
|
+
for (let i = 0; i < content.data.length; i++) {
|
|
75
|
+
const tag3dInfo = content.data[i];
|
|
76
|
+
customData.data['tag3d_' + tag3dInfo.version] = tag3dInfo;
|
|
178
77
|
}
|
|
78
|
+
node.addData(customData);
|
|
179
79
|
}
|
|
180
80
|
}
|
|
181
81
|
else {
|
|
@@ -186,4 +86,5 @@ class Tag3dEngine {
|
|
|
186
86
|
}
|
|
187
87
|
}
|
|
188
88
|
exports.Tag3dEngine = Tag3dEngine;
|
|
89
|
+
_Tag3dEngine_geometryCreator = new WeakMap();
|
|
189
90
|
//# sourceMappingURL=Tag3dEngine.js.map
|
package/dist/Tag3dEngine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tag3dEngine.js","sourceRoot":"","sources":["../src/Tag3dEngine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Tag3dEngine.js","sourceRoot":"","sources":["../src/Tag3dEngine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAA6D;AAE7D,iFAA0E;AAE1E,+EAAsG;AAEtG,MAAa,WAAW;IAAxB;QACI,yBAAyB;QAER,iBAAY,GAAgB,oCAAW,CAAC,QAAQ,CAAC;QAIlE,+CAA6E;QA8D7E,gCAAgC;IACpC,CAAC;IA7DG,4BAA4B;IAE5B,gDAAgD;IAEzC,MAAM,KAAK,QAAQ;QACtB,OAAO,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,mDAAmD;IAEnD,yCAAyC;IAEzC,IAAW,eAAe;QACtB,OAAO,uBAAA,IAAI,oCAAiB,CAAC;IACjC,CAAC;IAED,IAAW,eAAe,CAAC,KAAiE;QACxF,uBAAA,IAAI,gCAAoB,KAAK,MAAA,CAAC;IAClC,CAAC;IAED,4CAA4C;IAE5C,6BAA6B;IAE7B;;;;;OAKG;IACU,WAAW,CAAC,OAAwC;;YAC7D,MAAM,IAAI,GAAG,IAAI,kCAAQ,CAAC,OAAO,CAAC,CAAC;YAEnC,IAAI,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,QAAQ,KAAK,KAAK;gBAC/C,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;YAEvC,IAAI,CAAC,OAAO;gBACR,MAAM,IAAI,4DAAmC,CAAC,wEAAwE,CAAC,CAAC;YAE5H,IAAI,OAAO,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBAC7C,IAAI,uBAAA,IAAI,oCAAiB,EAAE;oBACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;wBAC1C,MAAM,SAAS,GAAW,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;wBAC1C,MAAM,KAAK,GAAG,uBAAA,IAAI,oCAAiB,MAArB,IAAI,EAAkB,SAAS,CAAC,CAAC;wBAC/C,IAAI,KAAK;4BAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;qBACnC;iBACJ;qBAAM;oBACH,MAAM,UAAU,GAAG,IAAI,gCAAU,CAAC,EAAE,CAAC,CAAC;oBACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;wBAC1C,MAAM,SAAS,GAAW,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;wBAC1C,UAAU,CAAC,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;qBAC7D;oBACD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;iBAC5B;aACJ;iBAAM;gBACH,MAAM,IAAI,4DAAmC,CAAC,sEAAsE,CAAC,CAAC;aACzH;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;KAAA;CAGJ;AAtED,kCAsEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapediver/viewer.data-engine.tag3d-engine",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Michael Oppitz <michael@shapediver.com>",
|
|
@@ -40,14 +40,10 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@shapediver/sdk.geometry-api-sdk-v2": "1.8.2",
|
|
43
|
-
"@shapediver/viewer.data-engine.shared-types": "
|
|
44
|
-
"@shapediver/viewer.shared.node-tree": "
|
|
45
|
-
"@shapediver/viewer.shared.services": "
|
|
46
|
-
"@shapediver/viewer.shared.types": "
|
|
47
|
-
"@types/three": "0.152.0",
|
|
48
|
-
"axios": "^1.2.6",
|
|
49
|
-
"gl-matrix": "3.3.0",
|
|
50
|
-
"three": "0.152.2"
|
|
43
|
+
"@shapediver/viewer.data-engine.shared-types": "3.0.0",
|
|
44
|
+
"@shapediver/viewer.shared.node-tree": "3.0.0",
|
|
45
|
+
"@shapediver/viewer.shared.services": "3.0.0",
|
|
46
|
+
"@shapediver/viewer.shared.types": "3.0.0"
|
|
51
47
|
},
|
|
52
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "b6b0010bf5d5652aa338df8016405d97f33fcabb"
|
|
53
49
|
}
|
package/src/Tag3dEngine.ts
CHANGED
|
@@ -1,34 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ITag3D } from '@shapediver/viewer.data-engine.shared-types'
|
|
7
|
-
import { TextGeometry } from './three/geometries/TextGeometry'
|
|
8
|
-
import { Font } from './three/loaders/FontLoader';
|
|
9
|
-
import { font } from './font'
|
|
1
|
+
import { CustomData } from '@shapediver/viewer.shared.types';
|
|
2
|
+
import { ITag3D } from '@shapediver/viewer.data-engine.shared-types';
|
|
3
|
+
import { ITreeNode, TreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
4
|
+
import { ShapeDiverResponseOutputContent } from '@shapediver/sdk.geometry-api-sdk-v2';
|
|
5
|
+
import { ShapeDiverViewerDataProcessingError, StateEngine } from '@shapediver/viewer.shared.services';
|
|
10
6
|
|
|
11
7
|
export class Tag3dEngine {
|
|
12
|
-
// #region Properties (
|
|
8
|
+
// #region Properties (3)
|
|
13
9
|
|
|
14
|
-
private readonly _converter: Converter = Converter.instance;
|
|
15
|
-
private readonly _httpClient: HttpClient = HttpClient.instance;
|
|
16
|
-
private readonly _logger: Logger = Logger.instance;
|
|
17
10
|
private readonly _stateEngine: StateEngine = StateEngine.instance;
|
|
18
11
|
|
|
19
12
|
private static _instance: Tag3dEngine;
|
|
20
13
|
|
|
21
|
-
|
|
14
|
+
#geometryCreator: ((tag3dInfo: ITag3D) => ITreeNode | undefined) | undefined;
|
|
22
15
|
|
|
23
|
-
// #endregion Properties (
|
|
16
|
+
// #endregion Properties (3)
|
|
24
17
|
|
|
25
|
-
// #region Public Static
|
|
18
|
+
// #region Public Static Getters And Setters (1)
|
|
26
19
|
|
|
27
20
|
public static get instance() {
|
|
28
21
|
return this._instance || (this._instance = new this());
|
|
29
22
|
}
|
|
30
23
|
|
|
31
|
-
// #endregion Public Static
|
|
24
|
+
// #endregion Public Static Getters And Setters (1)
|
|
25
|
+
|
|
26
|
+
// #region Public Getters And Setters (2)
|
|
27
|
+
|
|
28
|
+
public get geometryCreator() {
|
|
29
|
+
return this.#geometryCreator;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public set geometryCreator(value: ((tag3dInfo: ITag3D) => ITreeNode | undefined) | undefined) {
|
|
33
|
+
this.#geometryCreator = value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// #endregion Public Getters And Setters (2)
|
|
32
37
|
|
|
33
38
|
// #region Public Methods (1)
|
|
34
39
|
|
|
@@ -39,132 +44,28 @@ export class Tag3dEngine {
|
|
|
39
44
|
* @returns the scene graph node
|
|
40
45
|
*/
|
|
41
46
|
public async loadContent(content: ShapeDiverResponseOutputContent): Promise<ITreeNode> {
|
|
42
|
-
if(!this._font) {
|
|
43
|
-
this._font = new Font(font);
|
|
44
|
-
this._stateEngine.fontLoaded.resolve(true);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
47
|
const node = new TreeNode('tag3d');
|
|
48
48
|
|
|
49
|
-
if(this._stateEngine.fontLoaded.resolved === false)
|
|
49
|
+
if (this._stateEngine.fontLoaded.resolved === false)
|
|
50
50
|
await this._stateEngine.fontLoaded;
|
|
51
51
|
|
|
52
|
-
if (!content)
|
|
52
|
+
if (!content)
|
|
53
53
|
throw new ShapeDiverViewerDataProcessingError('Tag3dEngine.loadContent: Invalid content was provided to tag3d engine.');
|
|
54
54
|
|
|
55
55
|
if (content.data && Array.isArray(content.data)) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const tagLines = tag3dInfo.text.split(/\r\n|\r|\n/g);
|
|
63
|
-
let lineArray = [];
|
|
64
|
-
|
|
65
|
-
for (let lineIndex = 0; lineIndex < tagLines.length; ++lineIndex) {
|
|
66
|
-
if(tagLines[lineIndex] === '') continue;
|
|
67
|
-
// create tag mesh object
|
|
68
|
-
let tag = new TextGeometry(tagLines[lineIndex], { size: tag3dInfo.size, height: tag3dInfo.size / 10, font: this._font });
|
|
69
|
-
lineArray.push(tag);
|
|
56
|
+
if (this.#geometryCreator) {
|
|
57
|
+
for (let i = 0; i < content.data.length; i++) {
|
|
58
|
+
const tag3dInfo: ITag3D = content.data[i];
|
|
59
|
+
const child = this.#geometryCreator(tag3dInfo);
|
|
60
|
+
if (child) node.addChild(child);
|
|
70
61
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
} else {
|
|
63
|
+
const customData = new CustomData({});
|
|
64
|
+
for (let i = 0; i < content.data.length; i++) {
|
|
65
|
+
const tag3dInfo: ITag3D = content.data[i];
|
|
66
|
+
customData.data['tag3d_' + tag3dInfo.version] = tag3dInfo;
|
|
76
67
|
}
|
|
77
|
-
|
|
78
|
-
// align lines
|
|
79
|
-
let bb, extentsX, extentsY, lineHeight = 0;
|
|
80
|
-
{
|
|
81
|
-
lineHeight = 0;
|
|
82
|
-
for (let child of parentObject.children) {
|
|
83
|
-
bb = new THREE.Box3().setFromObject(child);
|
|
84
|
-
extentsY = bb.max.y - bb.min.y;
|
|
85
|
-
lineHeight = Math.max(lineHeight, extentsY);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
lineHeight *= 1.15;
|
|
89
|
-
|
|
90
|
-
lineArray.forEach((line, i) => {
|
|
91
|
-
line.translate(0, (-i - 1) * lineHeight, 0);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// justification
|
|
95
|
-
bb = new THREE.Box3().setFromObject(parentObject);
|
|
96
|
-
|
|
97
|
-
extentsX = bb.max.x - bb.min.x;
|
|
98
|
-
extentsY = bb.max.y - bb.min.y;
|
|
99
|
-
var tagJustTranslation = new THREE.Vector3(0, 0, 0);
|
|
100
|
-
|
|
101
|
-
switch (tag3dInfo.justification) {
|
|
102
|
-
case 'TL':
|
|
103
|
-
break;
|
|
104
|
-
case 'TC':
|
|
105
|
-
tagJustTranslation.x = -extentsX * 0.5;
|
|
106
|
-
break;
|
|
107
|
-
case 'TR':
|
|
108
|
-
tagJustTranslation.x = -extentsX;
|
|
109
|
-
break;
|
|
110
|
-
case 'ML':
|
|
111
|
-
tagJustTranslation.y = extentsY * 0.5;
|
|
112
|
-
break;
|
|
113
|
-
case 'MC':
|
|
114
|
-
tagJustTranslation.x = -extentsX * 0.5;
|
|
115
|
-
tagJustTranslation.y = extentsY * 0.5;
|
|
116
|
-
break;
|
|
117
|
-
case 'MR':
|
|
118
|
-
tagJustTranslation.x = -extentsX;
|
|
119
|
-
tagJustTranslation.y = extentsY * 0.5;
|
|
120
|
-
break;
|
|
121
|
-
case 'BL':
|
|
122
|
-
tagJustTranslation.y = extentsY;
|
|
123
|
-
break;
|
|
124
|
-
case 'BC':
|
|
125
|
-
tagJustTranslation.x = -extentsX * 0.5;
|
|
126
|
-
tagJustTranslation.y = extentsY;
|
|
127
|
-
break;
|
|
128
|
-
case 'BR':
|
|
129
|
-
tagJustTranslation.x = -extentsX;
|
|
130
|
-
tagJustTranslation.y = extentsY;
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
for (let line of lineArray) {
|
|
135
|
-
line.translate(tagJustTranslation.x, tagJustTranslation.y, tagJustTranslation.z);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// rotation
|
|
139
|
-
if (tag3dInfo.location.hasOwnProperty('xAxis')) {
|
|
140
|
-
var rotMatrix = new THREE.Matrix4();
|
|
141
|
-
rotMatrix.set(tag3dInfo.location.xAxis.X, tag3dInfo.location.yAxis.X, tag3dInfo.location.normal.X, 0, tag3dInfo.location.xAxis.Y, tag3dInfo.location.yAxis.Y, tag3dInfo.location.normal.Y, 0, tag3dInfo.location.xAxis.Z, tag3dInfo.location.yAxis.Z, tag3dInfo.location.normal.Z, 0, 0, 0, 0, 1);
|
|
142
|
-
for (let line of lineArray) {
|
|
143
|
-
line.applyMatrix4(rotMatrix);
|
|
144
|
-
line.translate(tag3dInfo.location.origin.X, tag3dInfo.location.origin.Y, tag3dInfo.location.origin.Z);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
for (let line of lineArray) {
|
|
149
|
-
const attributes: {
|
|
150
|
-
[key: string]: AttributeData
|
|
151
|
-
} = {};
|
|
152
|
-
for (let attribute in line.attributes) {
|
|
153
|
-
let attributeName = attribute.toUpperCase();
|
|
154
|
-
if(/\d/.test(attributeName) && !attributeName.includes('_')) {
|
|
155
|
-
const index = attributeName.search(/\d/)
|
|
156
|
-
attributeName = attributeName.substring(0, index) + '_' + attributeName.substring(index, attributeName.length);
|
|
157
|
-
} else if(attributeName === 'TEXCOORD' || attributeName === 'COLOR' || attributeName === 'JOINTS' || attributeName === 'WEIGHTS') {
|
|
158
|
-
attributeName += '_0';
|
|
159
|
-
} else if (attributeName === 'UV') {
|
|
160
|
-
attributeName = 'TEXCOORD_0';
|
|
161
|
-
}
|
|
162
|
-
attributes[attributeName] = new AttributeData(<Float32Array>(<THREE.BufferAttribute>line.attributes[attribute]).array, line.attributes[attribute].itemSize, 0, 0, 0, false, (<Float32Array>(<THREE.BufferAttribute>line.attributes[attribute]).array).length / line.attributes[attribute].itemSize)
|
|
163
|
-
}
|
|
164
|
-
const child = new TreeNode('tag3d_'+line)
|
|
165
|
-
child.data.push(new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.TRIANGLES, new MaterialStandardData({color: tag3dInfo.color, metalness: 0, roughness: 1})));
|
|
166
|
-
node.children.push(child);
|
|
167
|
-
}
|
|
68
|
+
node.addData(customData);
|
|
168
69
|
}
|
|
169
70
|
} else {
|
|
170
71
|
throw new ShapeDiverViewerDataProcessingError('Tag3dEngine.loadContent: No tag3d data was provided to tag3d engine.');
|