/
types.ts
360 lines (322 loc) · 9.75 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*!
* Copyright 2021 Cognite AS
*/
import { CogniteClient } from '@cognite/sdk';
import { SectorCuller } from '@reveal/cad-geometry-loaders';
import { Cognite3DModel } from './Cognite3DModel';
import { CognitePointCloudModel } from './CognitePointCloudModel';
/**
* @module @cognite/reveal
*/
export type Color = {
r: number;
g: number;
b: number;
};
/**
* Units supported by {@link Cognite3DModel}.
*/
export type WellKnownUnit =
| 'Meters'
| 'Centimeters'
| 'Millimeters'
| 'Micrometers'
| 'Kilometers'
| 'Feet'
| 'Inches'
| 'Yards'
| 'Miles'
| 'Mils'
| 'Microinches';
/**
* Callback to monitor loaded requests and progress.
* Use OnLoadingCallback instead of onProgress/onComplete.
* @module @cognite/reveal
*
* @param itemsLoaded Number of items loaded so far in this batch.
* @param itemsRequested Total number of items to load in this batch.
* @param itemsCulled Number of items deemed unnecessary to load in this batch.
*/
export type OnLoadingCallback = (itemsLoaded: number, itemsRequested: number, itemsCulled: number) => void;
/**
* @module @cognite/reveal
*/
export interface Cognite3DViewerOptions {
/** Initialized connection to CDF used to load data. */
sdk: CogniteClient;
/** An existing DOM element that we will render canvas into. */
domElement?: HTMLElement;
/** Send anonymous usage statistics. */
logMetrics?: boolean;
/**
* Render to offscreen buffer instead of canvas.
*/
renderTargetOptions?: { target: THREE.WebGLRenderTarget; autoSetSize?: boolean };
/**
* Style the loading indicator.
*/
loadingIndicatorStyle?: {
/**
* What corner the spinner should be placed in. Defaults top topLeft.
*/
placement: 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
/**
* Opacity of the spinner in fractions. Valid values are between
* 0.2 and 1.0. Defaults to 1.0.
*/
opacity: number;
};
/**
* When false, camera near and far planes will not be updated automatically (defaults to true).
* This can be useful when you have custom content in the 3D view and need to better
* control the view frustum.
*
* When automatic camera near/far planes are disabled, you are responsible for setting
* this on your own.
* @example
* ```
* viewer.camera.near = 0.1;
* viewer.camera.far = 1000.0;
* viewer.camera.updateProjectionMatrix();
* ```
*/
automaticCameraNearFar?: boolean;
/**
* When false, the sensitivity of the camera controls will not be updated automatically.
* This can be useful to better control the sensitivity of the 3D navigation.
*
* When not set, control the sensitivity of the camera using `viewer.cameraControls.minDistance`
* and `viewer.cameraControls.maxDistance`.
*/
automaticControlsSensitivity?: boolean;
/** Renderer used to visualize model (optional). */
renderer?: THREE.WebGLRenderer;
/**
* Hints Reveal to use a given anti-aliasing technique.
*
* Fast approximate anti-aliasing (FXAA) is a fast technique that will remove some, but not all aliasing effects. See
* https://en.wikipedia.org/wiki/Fast_approximate_anti-aliasing.
*
* Multi-sampling anti-aliasinbg (MSAA) is a technique for taking multiple samples per pixel to avoid aliasing effects.
* This mode requires WebGL 2. See https://www.khronos.org/opengl/wiki/Multisampling.
*
* The combined modes will apply both MSAA and FXAA anti-aliasing and yields the best visual result.
*
* When using the MSAA modes combined with FXAA Reveal will fall back to FXAA on WebGL 1. There is no fallback for the
* "plain" MSAA modes on WebGL 1.
*
* Currently the default mode is FXAA, but this is subject to change.
*/
antiAliasingHint?:
| 'disabled'
| 'fxaa'
| 'msaa2+fxaa'
| 'msaa4+fxaa'
| 'msaa8+fxaa'
| 'msaa16+fxaa'
| 'msaa2'
| 'msaa4'
| 'msaa8'
| 'msaa16';
/**
* Hints the renderer of the quality it should aim for for screen space ambient occlusion,
* an effect creating shadows and that gives the rendered image more depth.
*/
ssaoQualityHint?: 'medium' | 'high' | 'veryhigh' | 'disabled';
/**
* Enables / disables visualizing the edges of geometry. Defaults to true.
*/
enableEdges?: boolean;
/** Callback to download stream progress. */
onLoading?: OnLoadingCallback;
/**
* Allows providing a custom data source that Reveal will
* use to load model data. Note that some features might not
* work when implementing a custom data source. Please refer
* to the Reveal documentation for details.
*
* Note that the data source must support {@link CdfModelIdentifier}.
*
* This cannot be used together with {@link _localModels}.
*/
customDataSource?: DataSource;
/**
* Utility used to determine what parts of the model will be visible on screen and loaded.
* This is only meant for unit testing.
* @internal
*/
_sectorCuller?: SectorCuller;
/**
* When true, the viewer will load models stored locally and ignore
* the provided CogniteClient. This is only meant for development.
* Note! Marked as internal so when using this in debugging you must
* use e.g. @ts-expect-error to ignore type checks.
* @internal
*/
_localModels?: boolean;
}
import { GeometryFilter } from '../../public/types';
import { DataSource } from '@reveal/data-source';
export { GeometryFilter };
/**
* @module @cognite/reveal
*/
export interface AddModelOptions {
modelId: number;
revisionId: number;
// if you need to access local files, this is where you would specify it.
localPath?: string;
geometryFilter?: GeometryFilter;
}
export type CameraControlsOptions = {
/**
* Sets mouse wheel initiated action.
*
* Modes:
*
* 'zoomToTarget' - zooms just to the current target (center of the screen) of the camera.
*
* 'zoomPastCursor' - zooms in the direction of the ray coming from camera through cursor screen position, allows going through objects.
*
* 'zoomToCursor' - mouse wheel scroll zooms towards the point on the model where cursor is hovering over, doesn't allow going through objects.
*
* Default is 'zoomPastCursor'.
*
*/
mouseWheelAction?: 'zoomToTarget' | 'zoomPastCursor' | 'zoomToCursor';
/**
* Enables or disables change of camera target on mouse click. New target is then set to the point of the model under current cursor position.
*
* Default is false.
*
*/
onClickTargetChange?: boolean;
};
export type CadIntersection = {
/**
* The intersection type.
*/
type: 'cad';
/**
* The model that was intersected.
*/
model: Cognite3DModel;
/**
* Coordinate of the intersection.
*/
point: THREE.Vector3;
/**
* Tree index of the intersected 3D node.
*/
treeIndex: number;
/**
* Distance from the camera to the intersection.
*/
distanceToCamera: number;
};
export type PointCloudIntersection = {
/**
* The intersection type.
*/
type: 'pointcloud';
/**
* The model that was intersected.
*/
model: CognitePointCloudModel;
/**
* Tree index of the intersected 3D node.
*/
point: THREE.Vector3;
/**
* The index of the point that was intersected.
*/
pointIndex: number;
/**
* Distance from the camera to the intersection.
*/
distanceToCamera: number;
};
/**
* Represents the result from {@link Cognite3DViewer.getIntersectionFromPixel}.
* @module @cognite/reveal
*/
export type Intersection = CadIntersection | PointCloudIntersection;
/**
* @module @cognite/reveal
*/
export { CameraConfiguration } from '@reveal/utilities';
/**
* Delegate for pointer events.
* @module @cognite/reveal
* @see {@link Cognite3DViewer.on}.
*/
export type PointerEventDelegate = (event: { offsetX: number; offsetY: number }) => void;
/**
* Delegate for camera update events.
* @module @cognite/reveal
* @see {@link Cognite3DViewer.on}.
*/
export type CameraChangeDelegate = (position: THREE.Vector3, target: THREE.Vector3) => void;
/**
* Delegate for disposal events.
*/
export type DisposedDelegate = () => void;
/**
* Delegate for rendering events.
* @module @cognite/reveal
* @see {@link Cognite3DViewer.on}.
*/
export type SceneRenderedDelegate = (event: {
frameNumber: number;
renderTime: number;
renderer: THREE.WebGLRenderer;
camera: THREE.PerspectiveCamera;
}) => void;
export * from './NotSupportedInMigrationWrapperError';
export { CogniteModelBase } from './CogniteModelBase';
/**
* Represents a measurement of how much geometry can be loaded.
*/
export type CadModelBudget = {
// TODO 2020-11-04 larsmoa: Merge this type with CadModelSectorBudget.
/**
* Sectors within this distance from the camera will always be loaded in high details.
*/
readonly highDetailProximityThreshold: number;
/**
* Number of bytes of the geometry that must be downloaded.
*/
readonly geometryDownloadSizeBytes: number;
/**
* Estimated maximum number of WebGL draw calls to download geometry for. Draw calls
* are very important for the framerate.
*/
readonly maximumNumberOfDrawCalls: number;
/**
* Maximum render cost. This number can be thought of as triangle count, although the number
* doesn't match this directly.
*/
readonly maximumRenderCost: number;
};
/**
* Represents a budget of how many point from point clouds can be
* loaded at the same time.
*/
export type PointCloudBudget = {
/**
* Total number of points that can be loaded for all point clouds models
* accumulated.
*/
readonly numberOfPoints: number;
};
/**
* Options to control how {@link Cognite3DViewer.getIntersectionFromPixel} behaves.
*/
export interface IntersectionFromPixelOptions {
/**
* Threshold (in meters) for how close a point must be an intersection
* ray for it to be considered an intersection for point clouds. Defaults
* to 0.05.
*/
pointIntersectionThreshold?: number;
}