@shapediver/viewer.api.general 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/LICENSE ADDED
@@ -0,0 +1,73 @@
1
+ Required Notice: Copyright 2023 ShapeDiver GmbH (https://www.shapediver.com)
2
+
3
+ https://polyformproject.org/licenses/noncommercial/1.0.0
4
+
5
+ Acceptance
6
+
7
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
8
+
9
+ Copyright License
10
+
11
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor’s copyright in it for any permitted purpose. However, you may only distribute the software according to Distribution License and make changes or new works based on the software according to Changes and New Works License.
12
+
13
+ Distribution License
14
+
15
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by Changes and New Works License.
16
+
17
+ Notices
18
+
19
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with Required Notice: that the licensor provided with the software. For example:
20
+
21
+ Required Notice: Copyright 2023 ShapeDiver GmbH (https://www.shapediver.com)
22
+
23
+ Changes and New Works License
24
+
25
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
26
+
27
+ Patent License
28
+
29
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
30
+
31
+ Noncommercial Purposes
32
+
33
+ Any noncommercial purpose is a permitted purpose.
34
+
35
+ Personal Uses
36
+
37
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
38
+
39
+ Noncommercial Organizations
40
+
41
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
42
+
43
+ Fair Use
44
+
45
+ You may have “fair use” rights for the software under the law. These terms do not limit them.
46
+
47
+ No Other Rights
48
+
49
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
50
+
51
+ Patent Defense
52
+
53
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
54
+
55
+ Violations
56
+
57
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
58
+
59
+ No Liability
60
+
61
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
62
+
63
+ Definitions
64
+
65
+ The licensor is the individual or entity offering these terms, and the software is the software the licensor makes available under these terms.
66
+
67
+ You refers to the individual or entity agreeing to these terms.
68
+
69
+ Your company is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. Control means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
70
+
71
+ Your licenses are all the licenses granted to you for the software under these terms.
72
+
73
+ Use means anything you do with the software requiring one of your licenses.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # `@shapediver/viewer.api.general`
@@ -0,0 +1,77 @@
1
+ import { IEvent, LOGGING_LEVEL, MainEventTypes } from '@shapediver/viewer.shared.services';
2
+ import { ITree } from '@shapediver/viewer.shared.node-tree';
3
+ export interface IGeneralOptions {
4
+ /**
5
+ * Caching options.
6
+ */
7
+ caching: {
8
+ /**
9
+ * Option to enable/disable the caching. (default: true)
10
+ */
11
+ enable: boolean;
12
+ /**
13
+ * Query parameters that are excluded when creating the key that is used for the comparison of data entries in the cache. (default: ['Expires', 'Signature', 'Key-Pair-Id'])
14
+ * Example: by the addition of 'Expires' the URLs https://link.example?Expires=0 and https://link.example?Expires=1 are both reduced to https://link.example for caching.
15
+ */
16
+ excludedQueryParameters: string[];
17
+ /**
18
+ * The maximum size of the cache in bytes. (default: 1024^3)
19
+ */
20
+ maxCacheSize: number;
21
+ };
22
+ /**
23
+ * When set to false, the branding in the viewer console will be limited to a single line.
24
+ * This will only include the viewer version. (default: true)
25
+ */
26
+ consoleBranding: boolean;
27
+ /**
28
+ * The logging level that is used.
29
+ */
30
+ loggingLevel: LOGGING_LEVEL;
31
+ /**
32
+ * The number of glTFs that are downloaded and processed at the same time.
33
+ * Restricting this number might help if too much data is downloaded at the same time.
34
+ * (default: Infinity)
35
+ */
36
+ parallelGlTFProcessing: number;
37
+ /**
38
+ * Option to show/hide messages in the browser console.
39
+ */
40
+ showMessages: boolean;
41
+ }
42
+ /**
43
+ * Adds an event listener.
44
+ *
45
+ * @param type The type of event.
46
+ * @param cb The callback.
47
+ * @returns
48
+ */
49
+ export declare const addListener: (type: string | MainEventTypes, cb: (event: IEvent) => void) => string;
50
+ /**
51
+ * Removes an event listener.
52
+ *
53
+ * @param id The id of the listener.
54
+ * @returns
55
+ */
56
+ export declare const removeListener: (id: string) => boolean;
57
+ /**
58
+ * The scene tree that is used to store the scene.
59
+ * The scene tree contains a unique node and child nodes for each session,
60
+ * and can also be used to add your own nodes.
61
+ */
62
+ export declare const sceneTree: ITree;
63
+ /**
64
+ * The version of the viewer.
65
+ */
66
+ export declare const version: string;
67
+ export declare const showConsoleMessage: () => void;
68
+ /**
69
+ * General Viewer options that are used everywhere.
70
+ * - loggingLevel: The logging level that is used.
71
+ * - showMessages: Option to show/hide messages in the browser console.
72
+ * - parallelGlTFProcessing: The number of glTFs that are downloaded and processed at the same time.
73
+ * - consoleBranding: When set to false, the branding in the viewer console will be limited to a single line.
74
+ * - caching: Caching Options.
75
+ */
76
+ export declare const generalOptions: IGeneralOptions;
77
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGH,MAAM,EAGN,aAAa,EACb,cAAc,EACjB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAQ,MAAM,qCAAqC,CAAC;AAIlE,MAAM,WAAW,eAAe;IAG5B;;OAEG;IACH,OAAO,EAAE;QACL;;WAEG;QACH,MAAM,EAAE,OAAO,CAAC;QAEhB;;;WAGG;QACH,uBAAuB,EAAE,MAAM,EAAE,CAAC;QAElC;;WAEG;QACH,YAAY,EAAE,MAAM,CAAC;KACxB,CAAA;IAED;;;OAGG;IACH,eAAe,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,YAAY,EAAE,aAAa,CAAC;IAC5B;;;;OAIG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAC/B;;OAEG;IACH,YAAY,EAAE,OAAO,CAAC;CAGzB;AAiFD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,SAAU,MAAM,GAAG,cAAc,cAAc,MAAM,KAAK,IAAI,KAAG,MAKxF,CAAC;AACF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,OAAQ,MAAM,KAAG,OAI3C,CAAC;AACF;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,KAAqB,CAAC;AAC9C;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAAmD,CAAC;AAC1E,eAAO,MAAM,kBAAkB,YAkB9B,CAAC;AACF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,eAAsC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generalOptions = exports.showConsoleMessage = exports.version = exports.sceneTree = exports.removeListener = exports.addListener = void 0;
4
+ const viewer_shared_build_data_1 = require("@shapediver/viewer.shared.build-data");
5
+ const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
6
+ const viewer_data_engine_geometry_engine_1 = require("@shapediver/viewer.data-engine.geometry-engine");
7
+ const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
8
+ // #endregion Interfaces (1)
9
+ // #region Classes (1)
10
+ class GeneralOptions {
11
+ // #region Public Getters And Setters (10)
12
+ get caching() {
13
+ return {
14
+ enable: httpClient.enableCaching,
15
+ excludedQueryParameters: httpClient.excludedQueryParameters,
16
+ maxCacheSize: httpClient.maxCacheSize
17
+ };
18
+ }
19
+ set caching(value) {
20
+ inputValidator.validateAndError('caching', value, 'object', true);
21
+ inputValidator.validateAndError('caching', value.enable, 'boolean');
22
+ inputValidator.validateAndError('caching', value.excludedQueryParameters, 'stringArray');
23
+ inputValidator.validateAndError('caching', value.maxCacheSize, 'number');
24
+ if (value.enable !== undefined)
25
+ httpClient.enableCaching = value.enable;
26
+ if (value.excludedQueryParameters !== undefined)
27
+ httpClient.excludedQueryParameters = value.excludedQueryParameters;
28
+ if (value.maxCacheSize !== undefined)
29
+ httpClient.maxCacheSize = value.maxCacheSize;
30
+ logger.debug(`caching: CoggingLevel was set to: ${value}`);
31
+ }
32
+ get consoleBranding() {
33
+ return consoleBranding;
34
+ }
35
+ set consoleBranding(value) {
36
+ inputValidator.validateAndError('consoleBranding', value, 'boolean');
37
+ consoleBranding = value;
38
+ logger.debug(`consoleBranding: ConsoleBranding was set to: ${value}`);
39
+ }
40
+ get loggingLevel() {
41
+ return logger.loggingLevel;
42
+ }
43
+ set loggingLevel(value) {
44
+ inputValidator.validateAndError('loggingLevel', value, 'enum', true, Object.values(viewer_shared_services_1.LOGGING_LEVEL));
45
+ logger.loggingLevel = value;
46
+ logger.debug(`loggingLevel: LoggingLevel was set to: ${value}`);
47
+ }
48
+ get parallelGlTFProcessing() {
49
+ return geometryEngine.parallelGlTFProcessing;
50
+ }
51
+ set parallelGlTFProcessing(value) {
52
+ inputValidator.validateAndError('parallelGlTFProcessing', value, 'number');
53
+ geometryEngine.parallelGlTFProcessing = value;
54
+ logger.debug(`parallelGlTFProcessing: ParallelGlTFProcessing was set to: ${value}`);
55
+ }
56
+ get showMessages() {
57
+ return logger.showMessages;
58
+ }
59
+ set showMessages(value) {
60
+ inputValidator.validateAndError('showMessages', value, 'boolean');
61
+ logger.showMessages = value;
62
+ logger.debug(`showMessages: ShowMessages was set to: ${value}`);
63
+ }
64
+ }
65
+ // #endregion Classes (1)
66
+ // #region Variables (12)
67
+ const httpClient = viewer_shared_services_1.HttpClient.instance;
68
+ const inputValidator = viewer_shared_services_1.InputValidator.instance;
69
+ const logger = viewer_shared_services_1.Logger.instance;
70
+ const eventEngine = viewer_shared_services_1.EventEngine.instance;
71
+ const geometryEngine = viewer_data_engine_geometry_engine_1.GeometryEngine.instance;
72
+ let createdConsoleMessage = false, consoleBranding = true;
73
+ /**
74
+ * Adds an event listener.
75
+ *
76
+ * @param type The type of event.
77
+ * @param cb The callback.
78
+ * @returns
79
+ */
80
+ const addListener = (type, cb) => {
81
+ inputValidator.validateAndError('addListener', type, 'string');
82
+ inputValidator.validateAndError('addListener', cb, 'function');
83
+ logger.debug(`addListener: Event Listener was registered for ${type}.`);
84
+ return eventEngine.addListener(type, cb);
85
+ };
86
+ exports.addListener = addListener;
87
+ /**
88
+ * Removes an event listener.
89
+ *
90
+ * @param id The id of the listener.
91
+ * @returns
92
+ */
93
+ const removeListener = (id) => {
94
+ inputValidator.validateAndError('removeListener', id, 'string');
95
+ logger.debug(`removeListener: Removing event listener with id ${id}.`);
96
+ return eventEngine.removeListener(id);
97
+ };
98
+ exports.removeListener = removeListener;
99
+ /**
100
+ * The scene tree that is used to store the scene.
101
+ * The scene tree contains a unique node and child nodes for each session,
102
+ * and can also be used to add your own nodes.
103
+ */
104
+ exports.sceneTree = viewer_shared_node_tree_1.Tree.instance;
105
+ /**
106
+ * The version of the viewer.
107
+ */
108
+ exports.version = viewer_shared_build_data_1.build_data.build_version.replace('3.', '');
109
+ const showConsoleMessage = () => {
110
+ if (createdConsoleMessage === true)
111
+ return;
112
+ createdConsoleMessage = true;
113
+ if (consoleBranding === true) {
114
+ console.log(`Powered by:
115
+ _____ __ ____ _
116
+ / ___/ / /_ ____ _ ____ ___ / __ \\ (_)_ __ ___ _____
117
+ \\__ \\ / __ \\ / __ '// __ \\ / _ \\ / / / // /| | / // _ \\ / ___/
118
+ ___/ // / / // /_/ // /_/ // __// /_/ // / | |/ // __// /
119
+ /____//_/ /_/ \\__,_// .___/ \\___//_____//_/ |___/ \\___//_/
120
+ /_/
121
+ ShapeDiver Viewer 3, Version ${viewer_shared_build_data_1.build_data.build_version.replace('3.', '')}
122
+ Visit us at https://shapediver.com/ and find out more!
123
+ `);
124
+ }
125
+ else {
126
+ console.log(`ShapeDiver Viewer 3, Version ${viewer_shared_build_data_1.build_data.build_version.replace('3.', '')}`);
127
+ }
128
+ };
129
+ exports.showConsoleMessage = showConsoleMessage;
130
+ /**
131
+ * General Viewer options that are used everywhere.
132
+ * - loggingLevel: The logging level that is used.
133
+ * - showMessages: Option to show/hide messages in the browser console.
134
+ * - parallelGlTFProcessing: The number of glTFs that are downloaded and processed at the same time.
135
+ * - consoleBranding: When set to false, the branding in the viewer console will be limited to a single line.
136
+ * - caching: Caching Options.
137
+ */
138
+ exports.generalOptions = new GeneralOptions();
139
+ // #endregion Variables (12)
140
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mFAAkE;AAClE,+EAQ4C;AAC5C,uGAAgF;AAChF,iFAAkE;AAmDlE,4BAA4B;AAE5B,sBAAsB;AAEtB,MAAM,cAAc;IAChB,0CAA0C;IAE1C,IAAW,OAAO;QACd,OAAO;YACH,MAAM,EAAE,UAAU,CAAC,aAAa;YAChC,uBAAuB,EAAE,UAAU,CAAC,uBAAuB;YAC3D,YAAY,EAAE,UAAU,CAAC,YAAY;SACxC,CAAC;IACN,CAAC;IAED,IAAW,OAAO,CAAC,KAAmF;QAClG,cAAc,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC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+ "version": "3.0.0",
4
+ "description": "",
5
+ "keywords": [],
6
+ "author": "Michael Oppitz <michael@shapediver.com>",
7
+ "license": "polyform-noncommercial-1.0.0",
8
+ "main": "dist/index.js",
9
+ "directories": {
10
+ "test": "__tests__"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "src",
15
+ "package.json",
16
+ "README.md",
17
+ "tsconfig.json"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/shapediver/Viewer.git"
25
+ },
26
+ "scripts": {
27
+ "check": "tsc --noEmit",
28
+ "build": "bash ../../scripts/building/build.sh",
29
+ "build-watch": "bash ../../scripts/building/build-watch.sh",
30
+ "build-dep": "bash ../../scripts/building/build-dep.sh"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/shapediver/Viewer/issues"
34
+ },
35
+ "homepage": "https://github.com/shapediver/Viewer#readme",
36
+ "typings": "dist/index.d.ts",
37
+ "jest": {
38
+ "preset": "ts-jest",
39
+ "testEnvironment": "node"
40
+ },
41
+ "dependencies": {
42
+ "@shapediver/viewer.data-engine.geometry-engine": "3.0.0",
43
+ "@shapediver/viewer.shared.build-data": "3.0.0",
44
+ "@shapediver/viewer.shared.node-tree": "3.0.0",
45
+ "@shapediver/viewer.shared.services": "3.0.0",
46
+ "gl-matrix": "3.3.0"
47
+ },
48
+ "gitHead": "b6b0010bf5d5652aa338df8016405d97f33fcabb"
49
+ }
package/src/index.ts ADDED
@@ -0,0 +1,205 @@
1
+ import { build_data } from '@shapediver/viewer.shared.build-data';
2
+ import {
3
+ EventEngine,
4
+ HttpClient,
5
+ IEvent,
6
+ InputValidator,
7
+ Logger,
8
+ LOGGING_LEVEL,
9
+ MainEventTypes
10
+ } from '@shapediver/viewer.shared.services';
11
+ import { GeometryEngine } from '@shapediver/viewer.data-engine.geometry-engine';
12
+ import { ITree, Tree } from '@shapediver/viewer.shared.node-tree';
13
+
14
+ // #region Interfaces (1)
15
+
16
+ export interface IGeneralOptions {
17
+ // #region Properties (5)
18
+
19
+ /**
20
+ * Caching options.
21
+ */
22
+ caching: {
23
+ /**
24
+ * Option to enable/disable the caching. (default: true)
25
+ */
26
+ enable: boolean;
27
+
28
+ /**
29
+ * Query parameters that are excluded when creating the key that is used for the comparison of data entries in the cache. (default: ['Expires', 'Signature', 'Key-Pair-Id'])
30
+ * Example: by the addition of 'Expires' the URLs https://link.example?Expires=0 and https://link.example?Expires=1 are both reduced to https://link.example for caching.
31
+ */
32
+ excludedQueryParameters: string[];
33
+
34
+ /**
35
+ * The maximum size of the cache in bytes. (default: 1024^3)
36
+ */
37
+ maxCacheSize: number;
38
+ }
39
+
40
+ /**
41
+ * When set to false, the branding in the viewer console will be limited to a single line.
42
+ * This will only include the viewer version. (default: true)
43
+ */
44
+ consoleBranding: boolean;
45
+ /**
46
+ * The logging level that is used.
47
+ */
48
+ loggingLevel: LOGGING_LEVEL;
49
+ /**
50
+ * The number of glTFs that are downloaded and processed at the same time.
51
+ * Restricting this number might help if too much data is downloaded at the same time.
52
+ * (default: Infinity)
53
+ */
54
+ parallelGlTFProcessing: number;
55
+ /**
56
+ * Option to show/hide messages in the browser console.
57
+ */
58
+ showMessages: boolean;
59
+
60
+ // #endregion Properties (5)
61
+ }
62
+
63
+ // #endregion Interfaces (1)
64
+
65
+ // #region Classes (1)
66
+
67
+ class GeneralOptions {
68
+ // #region Public Getters And Setters (10)
69
+
70
+ public get caching(): { enable: boolean, excludedQueryParameters: string[], maxCacheSize: number } {
71
+ return {
72
+ enable: httpClient.enableCaching,
73
+ excludedQueryParameters: httpClient.excludedQueryParameters,
74
+ maxCacheSize: httpClient.maxCacheSize
75
+ };
76
+ }
77
+
78
+ public set caching(value: { enable: boolean, excludedQueryParameters: string[], maxCacheSize: number }) {
79
+ inputValidator.validateAndError('caching', value, 'object', true);
80
+ inputValidator.validateAndError('caching', value.enable, 'boolean');
81
+ inputValidator.validateAndError('caching', value.excludedQueryParameters, 'stringArray');
82
+ inputValidator.validateAndError('caching', value.maxCacheSize, 'number');
83
+ if (value.enable !== undefined) httpClient.enableCaching = value.enable;
84
+ if (value.excludedQueryParameters !== undefined) httpClient.excludedQueryParameters = value.excludedQueryParameters;
85
+ if (value.maxCacheSize !== undefined) httpClient.maxCacheSize = value.maxCacheSize;
86
+ logger.debug(`caching: CoggingLevel was set to: ${value}`);
87
+ }
88
+
89
+ public get consoleBranding(): boolean {
90
+ return consoleBranding;
91
+ }
92
+
93
+ public set consoleBranding(value: boolean) {
94
+ inputValidator.validateAndError('consoleBranding', value, 'boolean');
95
+ consoleBranding = value;
96
+ logger.debug(`consoleBranding: ConsoleBranding was set to: ${value}`);
97
+ }
98
+
99
+ public get loggingLevel(): LOGGING_LEVEL {
100
+ return logger.loggingLevel;
101
+ }
102
+
103
+ public set loggingLevel(value: LOGGING_LEVEL) {
104
+ inputValidator.validateAndError('loggingLevel', value, 'enum', true, Object.values(LOGGING_LEVEL));
105
+ logger.loggingLevel = value;
106
+ logger.debug(`loggingLevel: LoggingLevel was set to: ${value}`);
107
+ }
108
+
109
+ public get parallelGlTFProcessing(): number {
110
+ return geometryEngine.parallelGlTFProcessing;
111
+ }
112
+
113
+ public set parallelGlTFProcessing(value: number) {
114
+ inputValidator.validateAndError('parallelGlTFProcessing', value, 'number');
115
+ geometryEngine.parallelGlTFProcessing = value;
116
+ logger.debug(`parallelGlTFProcessing: ParallelGlTFProcessing was set to: ${value}`);
117
+ }
118
+
119
+ public get showMessages(): boolean {
120
+ return logger.showMessages;
121
+ }
122
+
123
+ public set showMessages(value: boolean) {
124
+ inputValidator.validateAndError('showMessages', value, 'boolean');
125
+ logger.showMessages = value;
126
+ logger.debug(`showMessages: ShowMessages was set to: ${value}`);
127
+ }
128
+
129
+ // #endregion Public Getters And Setters (10)
130
+ }
131
+
132
+ // #endregion Classes (1)
133
+
134
+ // #region Variables (12)
135
+
136
+ const httpClient: HttpClient = HttpClient.instance;
137
+ const inputValidator: InputValidator = InputValidator.instance;
138
+ const logger: Logger = Logger.instance;
139
+ const eventEngine: EventEngine = EventEngine.instance;
140
+ const geometryEngine: GeometryEngine = GeometryEngine.instance;
141
+ let createdConsoleMessage = false, consoleBranding = true;
142
+ /**
143
+ * Adds an event listener.
144
+ *
145
+ * @param type The type of event.
146
+ * @param cb The callback.
147
+ * @returns
148
+ */
149
+ export const addListener = (type: string | MainEventTypes, cb: (event: IEvent) => void): string => {
150
+ inputValidator.validateAndError('addListener', type, 'string');
151
+ inputValidator.validateAndError('addListener', cb, 'function');
152
+ logger.debug(`addListener: Event Listener was registered for ${type}.`);
153
+ return eventEngine.addListener(type, cb);
154
+ };
155
+ /**
156
+ * Removes an event listener.
157
+ *
158
+ * @param id The id of the listener.
159
+ * @returns
160
+ */
161
+ export const removeListener = (id: string): boolean => {
162
+ inputValidator.validateAndError('removeListener', id, 'string');
163
+ logger.debug(`removeListener: Removing event listener with id ${id}.`);
164
+ return eventEngine.removeListener(id);
165
+ };
166
+ /**
167
+ * The scene tree that is used to store the scene.
168
+ * The scene tree contains a unique node and child nodes for each session,
169
+ * and can also be used to add your own nodes.
170
+ */
171
+ export const sceneTree: ITree = Tree.instance;
172
+ /**
173
+ * The version of the viewer.
174
+ */
175
+ export const version: string = build_data.build_version.replace('3.', '');
176
+ export const showConsoleMessage = () => {
177
+ if (createdConsoleMessage === true) return;
178
+ createdConsoleMessage = true;
179
+
180
+ if (consoleBranding === true) {
181
+ console.log(`Powered by:
182
+ _____ __ ____ _
183
+ / ___/ / /_ ____ _ ____ ___ / __ \\ (_)_ __ ___ _____
184
+ \\__ \\ / __ \\ / __ '// __ \\ / _ \\ / / / // /| | / // _ \\ / ___/
185
+ ___/ // / / // /_/ // /_/ // __// /_/ // / | |/ // __// /
186
+ /____//_/ /_/ \\__,_// .___/ \\___//_____//_/ |___/ \\___//_/
187
+ /_/
188
+ ShapeDiver Viewer 3, Version ${build_data.build_version.replace('3.', '')}
189
+ Visit us at https://shapediver.com/ and find out more!
190
+ `);
191
+ } else {
192
+ console.log(`ShapeDiver Viewer 3, Version ${build_data.build_version.replace('3.', '')}`);
193
+ }
194
+ };
195
+ /**
196
+ * General Viewer options that are used everywhere.
197
+ * - loggingLevel: The logging level that is used.
198
+ * - showMessages: Option to show/hide messages in the browser console.
199
+ * - parallelGlTFProcessing: The number of glTFs that are downloaded and processed at the same time.
200
+ * - consoleBranding: When set to false, the branding in the viewer console will be limited to a single line.
201
+ * - caching: Caching Options.
202
+ */
203
+ export const generalOptions: IGeneralOptions = new GeneralOptions();
204
+
205
+ // #endregion Variables (12)
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": [
4
+ "./**/*.ts"
5
+ ],
6
+ "compilerOptions": {
7
+ "rootDir": "src",
8
+ "outDir": "dist"
9
+ },
10
+ "exclude": [
11
+ "__tests__",
12
+ "node_modules",
13
+ "dist",
14
+ "dist-dev",
15
+ "dist-prod"
16
+ ]
17
+ }