@shapediver/viewer.viewport 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 +73 -0
- package/README.md +1 -0
- package/dist/implementation/PostProcessingApi.d.ts +49 -0
- package/dist/implementation/PostProcessingApi.d.ts.map +1 -0
- package/dist/implementation/PostProcessingApi.js +142 -0
- package/dist/implementation/PostProcessingApi.js.map +1 -0
- package/dist/implementation/ViewportApi.d.ts +200 -0
- package/dist/implementation/ViewportApi.d.ts.map +1 -0
- package/dist/implementation/ViewportApi.js +879 -0
- package/dist/implementation/ViewportApi.js.map +1 -0
- package/dist/implementation/camera/AbstractCameraApi.d.ts +138 -0
- package/dist/implementation/camera/AbstractCameraApi.d.ts.map +1 -0
- package/dist/implementation/camera/AbstractCameraApi.js +473 -0
- package/dist/implementation/camera/AbstractCameraApi.js.map +1 -0
- package/dist/implementation/camera/OrthographicCameraApi.d.ts +11 -0
- package/dist/implementation/camera/OrthographicCameraApi.d.ts.map +1 -0
- package/dist/implementation/camera/OrthographicCameraApi.js +48 -0
- package/dist/implementation/camera/OrthographicCameraApi.js.map +1 -0
- package/dist/implementation/camera/PerspectiveCameraApi.d.ts +11 -0
- package/dist/implementation/camera/PerspectiveCameraApi.d.ts.map +1 -0
- package/dist/implementation/camera/PerspectiveCameraApi.js +47 -0
- package/dist/implementation/camera/PerspectiveCameraApi.js.map +1 -0
- package/dist/implementation/lights/AbstractLightApi.d.ts +20 -0
- package/dist/implementation/lights/AbstractLightApi.d.ts.map +1 -0
- package/dist/implementation/lights/AbstractLightApi.js +81 -0
- package/dist/implementation/lights/AbstractLightApi.js.map +1 -0
- package/dist/implementation/lights/LightSceneApi.d.ts +69 -0
- package/dist/implementation/lights/LightSceneApi.d.ts.map +1 -0
- package/dist/implementation/lights/LightSceneApi.js +172 -0
- package/dist/implementation/lights/LightSceneApi.js.map +1 -0
- package/dist/implementation/lights/types/AmbientLightApi.d.ts +9 -0
- package/dist/implementation/lights/types/AmbientLightApi.d.ts.map +1 -0
- package/dist/implementation/lights/types/AmbientLightApi.js +27 -0
- package/dist/implementation/lights/types/AmbientLightApi.js.map +1 -0
- package/dist/implementation/lights/types/DirectionalLightApi.d.ts +18 -0
- package/dist/implementation/lights/types/DirectionalLightApi.d.ts.map +1 -0
- package/dist/implementation/lights/types/DirectionalLightApi.js +77 -0
- package/dist/implementation/lights/types/DirectionalLightApi.js.map +1 -0
- package/dist/implementation/lights/types/HemisphereLightApi.d.ts +12 -0
- package/dist/implementation/lights/types/HemisphereLightApi.d.ts.map +1 -0
- package/dist/implementation/lights/types/HemisphereLightApi.js +47 -0
- package/dist/implementation/lights/types/HemisphereLightApi.js.map +1 -0
- package/dist/implementation/lights/types/PointLightApi.d.ts +16 -0
- package/dist/implementation/lights/types/PointLightApi.d.ts.map +1 -0
- package/dist/implementation/lights/types/PointLightApi.js +67 -0
- package/dist/implementation/lights/types/PointLightApi.js.map +1 -0
- package/dist/implementation/lights/types/SpotLightApi.d.ts +22 -0
- package/dist/implementation/lights/types/SpotLightApi.d.ts.map +1 -0
- package/dist/implementation/lights/types/SpotLightApi.js +97 -0
- package/dist/implementation/lights/types/SpotLightApi.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +160 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/IPostProcessingApi.d.ts +229 -0
- package/dist/interfaces/IPostProcessingApi.d.ts.map +1 -0
- package/dist/interfaces/IPostProcessingApi.js +3 -0
- package/dist/interfaces/IPostProcessingApi.js.map +1 -0
- package/dist/interfaces/IViewportApi.d.ts +632 -0
- package/dist/interfaces/IViewportApi.d.ts.map +1 -0
- package/dist/interfaces/IViewportApi.js +3 -0
- package/dist/interfaces/IViewportApi.js.map +1 -0
- package/dist/interfaces/camera/ICameraApi.d.ts +249 -0
- package/dist/interfaces/camera/ICameraApi.d.ts.map +1 -0
- package/dist/interfaces/camera/ICameraApi.js +3 -0
- package/dist/interfaces/camera/ICameraApi.js.map +1 -0
- package/dist/interfaces/camera/IOrthographicCameraApi.d.ts +14 -0
- package/dist/interfaces/camera/IOrthographicCameraApi.d.ts.map +1 -0
- package/dist/interfaces/camera/IOrthographicCameraApi.js +3 -0
- package/dist/interfaces/camera/IOrthographicCameraApi.js.map +1 -0
- package/dist/interfaces/camera/IPerspectiveCameraApi.d.ts +13 -0
- package/dist/interfaces/camera/IPerspectiveCameraApi.d.ts.map +1 -0
- package/dist/interfaces/camera/IPerspectiveCameraApi.js +3 -0
- package/dist/interfaces/camera/IPerspectiveCameraApi.js.map +1 -0
- package/dist/interfaces/lights/ILightApi.d.ts +36 -0
- package/dist/interfaces/lights/ILightApi.d.ts.map +1 -0
- package/dist/interfaces/lights/ILightApi.js +3 -0
- package/dist/interfaces/lights/ILightApi.js.map +1 -0
- package/dist/interfaces/lights/ILightSceneApi.d.ts +139 -0
- package/dist/interfaces/lights/ILightSceneApi.d.ts.map +1 -0
- package/dist/interfaces/lights/ILightSceneApi.js +3 -0
- package/dist/interfaces/lights/ILightSceneApi.js.map +1 -0
- package/dist/interfaces/lights/types/IAmbientLightApi.d.ts +7 -0
- package/dist/interfaces/lights/types/IAmbientLightApi.d.ts.map +1 -0
- package/dist/interfaces/lights/types/IAmbientLightApi.js +3 -0
- package/dist/interfaces/lights/types/IAmbientLightApi.js.map +1 -0
- package/dist/interfaces/lights/types/IDirectionalLightApi.d.ts +25 -0
- package/dist/interfaces/lights/types/IDirectionalLightApi.d.ts.map +1 -0
- package/dist/interfaces/lights/types/IDirectionalLightApi.js +3 -0
- package/dist/interfaces/lights/types/IDirectionalLightApi.js.map +1 -0
- package/dist/interfaces/lights/types/IHemisphereLightApi.d.ts +13 -0
- package/dist/interfaces/lights/types/IHemisphereLightApi.d.ts.map +1 -0
- package/dist/interfaces/lights/types/IHemisphereLightApi.js +3 -0
- package/dist/interfaces/lights/types/IHemisphereLightApi.js.map +1 -0
- package/dist/interfaces/lights/types/IPointLightApi.d.ts +21 -0
- package/dist/interfaces/lights/types/IPointLightApi.d.ts.map +1 -0
- package/dist/interfaces/lights/types/IPointLightApi.js +3 -0
- package/dist/interfaces/lights/types/IPointLightApi.js.map +1 -0
- package/dist/interfaces/lights/types/ISpotLightApi.d.ts +33 -0
- package/dist/interfaces/lights/types/ISpotLightApi.d.ts.map +1 -0
- package/dist/interfaces/lights/types/ISpotLightApi.js +3 -0
- package/dist/interfaces/lights/types/ISpotLightApi.js.map +1 -0
- package/dist/main.d.ts +29 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +80 -0
- package/dist/main.js.map +1 -0
- package/package.json +78 -0
- package/src/implementation/PostProcessingApi.ts +184 -0
- package/src/implementation/ViewportApi.ts +1060 -0
- package/src/implementation/camera/AbstractCameraApi.ts +556 -0
- package/src/implementation/camera/OrthographicCameraApi.ts +43 -0
- package/src/implementation/camera/PerspectiveCameraApi.ts +43 -0
- package/src/implementation/lights/AbstractLightApi.ts +87 -0
- package/src/implementation/lights/LightSceneApi.ts +198 -0
- package/src/implementation/lights/types/AmbientLightApi.ts +24 -0
- package/src/implementation/lights/types/DirectionalLightApi.ts +80 -0
- package/src/implementation/lights/types/HemisphereLightApi.ts +44 -0
- package/src/implementation/lights/types/PointLightApi.ts +68 -0
- package/src/implementation/lights/types/SpotLightApi.ts +104 -0
- package/src/index.ts +297 -0
- package/src/interfaces/IPostProcessingApi.ts +269 -0
- package/src/interfaces/IViewportApi.ts +629 -0
- package/src/interfaces/camera/ICameraApi.ts +233 -0
- package/src/interfaces/camera/IOrthographicCameraApi.ts +18 -0
- package/src/interfaces/camera/IPerspectiveCameraApi.ts +17 -0
- package/src/interfaces/lights/ILightApi.ts +41 -0
- package/src/interfaces/lights/ILightSceneApi.ts +147 -0
- package/src/interfaces/lights/types/IAmbientLightApi.ts +7 -0
- package/src/interfaces/lights/types/IDirectionalLightApi.ts +29 -0
- package/src/interfaces/lights/types/IHemisphereLightApi.ts +17 -0
- package/src/interfaces/lights/types/IPointLightApi.ts +25 -0
- package/src/interfaces/lights/types/ISpotLightApi.ts +37 -0
- package/src/main.ts +85 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { CAMERA_TYPE, ICameraOptions } from '@shapediver/viewer.rendering-engine.camera-engine';
|
|
2
|
+
import { IBox } from '@shapediver/viewer.shared.math';
|
|
3
|
+
import { vec2, vec3 } from 'gl-matrix';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The api for a camera, please see the definitions for the [perspective camera api]{@link IPerspectiveCameraApi} and the [orthographic camera api]{@link IOrthographicCameraApi} as this is just a shared interface for both.
|
|
7
|
+
* A camera can be created by calling the corresponding method in the {@link IViewportApi}.
|
|
8
|
+
* A camera has a multitude of properties and methods that can be used to adjust the behavior.
|
|
9
|
+
*/
|
|
10
|
+
export interface ICameraApi {
|
|
11
|
+
// #region Properties (38)
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The id of the camera.
|
|
15
|
+
*/
|
|
16
|
+
readonly id: string;
|
|
17
|
+
/**
|
|
18
|
+
* The type of camera that is being used.
|
|
19
|
+
*/
|
|
20
|
+
readonly type: CAMERA_TYPE;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Option to automatically adjust the camera to the size of the scene whenever a call to
|
|
24
|
+
* {@link ISessionApi.customize} replaced {@link ISessionApi.node}.
|
|
25
|
+
* This does not happen in case {@link ISessionApi.automaticSceneUpdate} is set to false.
|
|
26
|
+
*/
|
|
27
|
+
autoAdjust: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The speed of the camera for auto rotating.
|
|
30
|
+
*/
|
|
31
|
+
autoRotationSpeed: number;
|
|
32
|
+
/**
|
|
33
|
+
* The standard duration for camera movements.
|
|
34
|
+
*/
|
|
35
|
+
cameraMovementDuration: number;
|
|
36
|
+
/**
|
|
37
|
+
* The restrictions for the position of the camera with a cube.
|
|
38
|
+
*/
|
|
39
|
+
cubePositionRestriction: { min: vec3, max: vec3 };
|
|
40
|
+
/**
|
|
41
|
+
* The restrictions for the target of the camera with a cube.
|
|
42
|
+
*/
|
|
43
|
+
cubeTargetRestriction: { min: vec3, max: vec3 };
|
|
44
|
+
/**
|
|
45
|
+
* The damping factor for the camera.
|
|
46
|
+
* The dampening affects how much the camera moves even after you let it got.
|
|
47
|
+
* This smooths the usage of the camera.
|
|
48
|
+
*/
|
|
49
|
+
damping: number;
|
|
50
|
+
/**
|
|
51
|
+
* The default position of the camera.
|
|
52
|
+
*/
|
|
53
|
+
defaultPosition: vec3;
|
|
54
|
+
/**
|
|
55
|
+
* The default target of the camera.
|
|
56
|
+
*/
|
|
57
|
+
defaultTarget: vec3;
|
|
58
|
+
/**
|
|
59
|
+
* Option to enable auto rotating.
|
|
60
|
+
*/
|
|
61
|
+
enableAutoRotation: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Option to enable the rotation of the camera on the azimuth axis (left/right). (default: true)
|
|
64
|
+
*/
|
|
65
|
+
enableAzimuthRotation: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Option to enable panning with key presses.
|
|
68
|
+
*/
|
|
69
|
+
enableKeyPan: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Option to enable the object controls. (default: false)
|
|
72
|
+
*/
|
|
73
|
+
enableObjectControls: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Option to enable panning. Panning can be done by pressing the right mouse button or three-finger touch events.
|
|
76
|
+
*/
|
|
77
|
+
enablePan: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Option to enable the rotation of the camera on the polar axis (up/down). (default: true)
|
|
80
|
+
*/
|
|
81
|
+
enablePolarRotation: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Option to enable rotating.
|
|
84
|
+
*/
|
|
85
|
+
enableRotation: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Option to enable the turntable controls. (default: false)
|
|
88
|
+
*/
|
|
89
|
+
enableTurntableControls: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Option to enable zooming. Zooming can be done with the mouse wheel or two-finger touch events.
|
|
92
|
+
*/
|
|
93
|
+
enableZoom: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Option to enable / disable the movement of the camera.
|
|
96
|
+
*/
|
|
97
|
+
enabled: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* The speed of the camera for key panning. The higher this value, the faster you can pan.
|
|
100
|
+
*/
|
|
101
|
+
keyPanSpeed: number;
|
|
102
|
+
/**
|
|
103
|
+
* The factor for applying smoothing to the camera movement.
|
|
104
|
+
* The various events that come in are blended together to ensure that extremes are not as pronounced.
|
|
105
|
+
*/
|
|
106
|
+
movementSmoothness: number;
|
|
107
|
+
/**
|
|
108
|
+
* The name of the camera.
|
|
109
|
+
* Used by the platform.
|
|
110
|
+
*/
|
|
111
|
+
name?: string;
|
|
112
|
+
/**
|
|
113
|
+
* The center of the object when {@link enableObjectControls} is activated. (default: [0,0,0])
|
|
114
|
+
*/
|
|
115
|
+
objectControlsCenter: vec3;
|
|
116
|
+
/**
|
|
117
|
+
* Optional order property for the camera.
|
|
118
|
+
* Used by the platform.
|
|
119
|
+
*/
|
|
120
|
+
order?: number;
|
|
121
|
+
/**
|
|
122
|
+
* The speed of the camera for panning. The higher this value, the faster you can pan.
|
|
123
|
+
*/
|
|
124
|
+
panSpeed: number;
|
|
125
|
+
/**
|
|
126
|
+
* The current position of the camera.
|
|
127
|
+
*/
|
|
128
|
+
position: vec3;
|
|
129
|
+
/**
|
|
130
|
+
* Option to animate the camera position and target to their defaults whenever the mouse/touch up event is fired.
|
|
131
|
+
*/
|
|
132
|
+
revertAtMouseUp: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* The standard duration for revertAtMouseUp animations.
|
|
135
|
+
*/
|
|
136
|
+
revertAtMouseUpDuration: number;
|
|
137
|
+
/**
|
|
138
|
+
* The restrictions for the rotation of the camera.
|
|
139
|
+
*/
|
|
140
|
+
rotationRestriction: { minPolarAngle: number, maxPolarAngle: number, minAzimuthAngle: number, maxAzimuthAngle: number };
|
|
141
|
+
/**
|
|
142
|
+
* The speed of the camera for rotating.
|
|
143
|
+
*/
|
|
144
|
+
rotationSpeed: number;
|
|
145
|
+
/**
|
|
146
|
+
* The restrictions for the position of the camera with a sphere.
|
|
147
|
+
*/
|
|
148
|
+
spherePositionRestriction: { center: vec3, radius: number };
|
|
149
|
+
/**
|
|
150
|
+
* The restrictions for the target of the camera with a sphere.
|
|
151
|
+
*/
|
|
152
|
+
sphereTargetRestriction: { center: vec3, radius: number };
|
|
153
|
+
/**
|
|
154
|
+
* The current target of the camera.
|
|
155
|
+
*/
|
|
156
|
+
target: vec3;
|
|
157
|
+
/**
|
|
158
|
+
* The center of the turntable when {@link enableTurntableControls} is activated. (default: [0,0,0])
|
|
159
|
+
*/
|
|
160
|
+
turntableCenter: vec3;
|
|
161
|
+
/**
|
|
162
|
+
* The restrictions for the zooming of the camera.
|
|
163
|
+
*/
|
|
164
|
+
zoomRestriction: { minDistance: number, maxDistance: number };
|
|
165
|
+
/**
|
|
166
|
+
* The speed of the camera for zooming. The higher this value, the faster you can zoom.
|
|
167
|
+
*/
|
|
168
|
+
zoomSpeed: number;
|
|
169
|
+
/**
|
|
170
|
+
* The factor that is used when the {@link zoomTo} function is called.
|
|
171
|
+
*
|
|
172
|
+
* See also {@link calculateZoomTo}
|
|
173
|
+
*/
|
|
174
|
+
zoomToFactor: number;
|
|
175
|
+
|
|
176
|
+
// #endregion Properties (38)
|
|
177
|
+
|
|
178
|
+
// #region Public Methods (7)
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Let the camera follow a path along pairs of position and target.
|
|
182
|
+
*
|
|
183
|
+
* @param path The defined path.
|
|
184
|
+
* @param options Various options to be adjusted.
|
|
185
|
+
*/
|
|
186
|
+
animate(path: { position: vec3, target: vec3 }[], options?: ICameraOptions): Promise<boolean>;
|
|
187
|
+
/**
|
|
188
|
+
* Calculate the position and target which a call to {@link zoomTo} would result in.
|
|
189
|
+
*
|
|
190
|
+
* If no target to zoom to is provided, the current bounding box is used.
|
|
191
|
+
* If no startingPosition and startingTarget are provided, the current camera position and target are used.
|
|
192
|
+
*
|
|
193
|
+
* @see {@link zoomToFactor}
|
|
194
|
+
*
|
|
195
|
+
* @param zoomTarget The target to zoom to.
|
|
196
|
+
* @param startingPosition The starting position of the camera.
|
|
197
|
+
* @param startingTarget The starting target of the camera.
|
|
198
|
+
*/
|
|
199
|
+
calculateZoomTo(zoomTarget?: IBox, startingPosition?: vec3, startingTarget?: vec3): { position: vec3; target: vec3; };
|
|
200
|
+
/**
|
|
201
|
+
* Projects the vector from world space into the camera's normalized device coordinate (NDC) space.
|
|
202
|
+
*
|
|
203
|
+
* @param p The point in the scene to project.
|
|
204
|
+
*/
|
|
205
|
+
project(p: vec3): vec2;
|
|
206
|
+
/**
|
|
207
|
+
* Reset / animate the camera to its default position and target.
|
|
208
|
+
*
|
|
209
|
+
* @param options Various options to be adjusted.
|
|
210
|
+
*/
|
|
211
|
+
reset(options?: ICameraOptions): Promise<boolean>;
|
|
212
|
+
/**
|
|
213
|
+
* Set / animate the camera to a specific position and target.
|
|
214
|
+
*
|
|
215
|
+
* @param options Various options to be adjusted.
|
|
216
|
+
*/
|
|
217
|
+
set(position: vec3, target: vec3, options?: ICameraOptions): Promise<boolean>;
|
|
218
|
+
/**
|
|
219
|
+
* Projects the vector from the camera's normalized device coordinate (NDC) space into world space.
|
|
220
|
+
*
|
|
221
|
+
* @param p The point on the screen to project.
|
|
222
|
+
*/
|
|
223
|
+
unproject(p: vec3): vec3;
|
|
224
|
+
/**
|
|
225
|
+
* Zoom to a specific part of the scene, or the whole scene (default).
|
|
226
|
+
*
|
|
227
|
+
* @param zoomTarget The target to zoom to.
|
|
228
|
+
* @param options Various options to be adjusted.
|
|
229
|
+
*/
|
|
230
|
+
zoomTo(zoomTarget?: IBox, options?: ICameraOptions): Promise<boolean>;
|
|
231
|
+
|
|
232
|
+
// #endregion Public Methods (7)
|
|
233
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ICameraApi } from './ICameraApi';
|
|
2
|
+
import { ORTHOGRAPHIC_CAMERA_DIRECTION } from '@shapediver/viewer.rendering-engine.camera-engine';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The api for an orthographic camera.
|
|
6
|
+
* An orthographic camera can be created by calling the {@link createOrthographicCamera} method.
|
|
7
|
+
* A camera has a multitude of properties and methods that can be used to adjust the behavior.
|
|
8
|
+
*/
|
|
9
|
+
export interface IOrthographicCameraApi extends ICameraApi {
|
|
10
|
+
// #region Properties (1)
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The direction of the camera. (default: ORTHOGRAPHIC_CAMERA_DIRECTION.CUSTOM)
|
|
14
|
+
*/
|
|
15
|
+
direction: ORTHOGRAPHIC_CAMERA_DIRECTION;
|
|
16
|
+
|
|
17
|
+
// #endregion Properties (1)
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ICameraApi } from './ICameraApi';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The api for a perspective camera.
|
|
5
|
+
* A perspective camera can be created by calling the {@link createPerspectiveCamera} method.
|
|
6
|
+
* A camera has a multitude of properties and methods that can be used to adjust the behavior.
|
|
7
|
+
*/
|
|
8
|
+
export interface IPerspectiveCameraApi extends ICameraApi {
|
|
9
|
+
// #region Properties (1)
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The field of view for the camera.
|
|
13
|
+
*/
|
|
14
|
+
fov: number;
|
|
15
|
+
|
|
16
|
+
// #endregion Properties (1)
|
|
17
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Color } from '@shapediver/viewer.shared.types';
|
|
2
|
+
import { LIGHT_TYPE } from '@shapediver/viewer.rendering-engine.light-engine';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The api for a light, please see the definitions for [ambient]{@link IAmbientLightApi}, [directional]{@link IDirectionalLightApi}, [hemisphere]{@link IHemisphereLightApi}, [point]{@link IPointLightApi} and [spot]{@link ISpotLightApi} as this is just a shared interface for all of them.
|
|
6
|
+
* A light can be created by calling the corresponding method in the [light scene]{@link ILightSceneApi}.
|
|
7
|
+
* A light has a multitude of properties and methods that can be used to adjust the behavior.
|
|
8
|
+
*/
|
|
9
|
+
export interface ILightApi {
|
|
10
|
+
// #region Properties (6)
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The id of the light.
|
|
14
|
+
*/
|
|
15
|
+
readonly id: string;
|
|
16
|
+
/**
|
|
17
|
+
* The type of the light.
|
|
18
|
+
*/
|
|
19
|
+
readonly type: LIGHT_TYPE;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The color of the light.
|
|
23
|
+
*/
|
|
24
|
+
color: Color;
|
|
25
|
+
/**
|
|
26
|
+
* The intensity of the light.
|
|
27
|
+
*/
|
|
28
|
+
intensity: number;
|
|
29
|
+
/**
|
|
30
|
+
* The name of the light.
|
|
31
|
+
* Used by the platform.
|
|
32
|
+
*/
|
|
33
|
+
name?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The order of the light.
|
|
36
|
+
* Used by the platform.
|
|
37
|
+
*/
|
|
38
|
+
order?: number;
|
|
39
|
+
|
|
40
|
+
// #endregion Properties (6)
|
|
41
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Color } from '@shapediver/viewer.shared.types';
|
|
2
|
+
import { IAmbientLightApi } from './types/IAmbientLightApi';
|
|
3
|
+
import { IDirectionalLightApi } from './types/IDirectionalLightApi';
|
|
4
|
+
import { IHemisphereLightApi } from './types/IHemisphereLightApi';
|
|
5
|
+
import { ILightApi } from './ILightApi';
|
|
6
|
+
import { IPointLightApi } from './types/IPointLightApi';
|
|
7
|
+
import { ISpotLightApi } from './types/ISpotLightApi';
|
|
8
|
+
import { ITreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
9
|
+
import { vec3 } from 'gl-matrix';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The api for a light scene.
|
|
13
|
+
* A light scene is a collection of lights. Therefore multiple light scene can be used to switch between different lighting environments.
|
|
14
|
+
* It can be created by calling the {@link createLightScene} method.
|
|
15
|
+
*/
|
|
16
|
+
export interface ILightSceneApi {
|
|
17
|
+
// #region Properties (4)
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The id of the light scene.
|
|
21
|
+
*/
|
|
22
|
+
readonly id: string;
|
|
23
|
+
/**
|
|
24
|
+
* The node in which the lights are stored in the [scene tree]{@link ITree}.
|
|
25
|
+
*/
|
|
26
|
+
readonly node: ITreeNode;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The collection of lights in the light scene.
|
|
30
|
+
*/
|
|
31
|
+
lights: { [key: string]: ILightApi; };
|
|
32
|
+
/**
|
|
33
|
+
* The name of the light scene.
|
|
34
|
+
*/
|
|
35
|
+
name?: string
|
|
36
|
+
|
|
37
|
+
// #endregion Properties (4)
|
|
38
|
+
|
|
39
|
+
// #region Public Methods (6)
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create an ambient light and add it to the light scene.
|
|
43
|
+
*
|
|
44
|
+
* @param properties.color The color of the light.
|
|
45
|
+
* @param properties.intensity The intensity of the light. (0-Infinity, default: 0.5)
|
|
46
|
+
* @param properties.id The id of the light.
|
|
47
|
+
* @param properties.name The name of the light.
|
|
48
|
+
*/
|
|
49
|
+
addAmbientLight(properties: {
|
|
50
|
+
color?: Color,
|
|
51
|
+
intensity?: number,
|
|
52
|
+
id?: string,
|
|
53
|
+
name?: string
|
|
54
|
+
}): IAmbientLightApi;
|
|
55
|
+
/**
|
|
56
|
+
* Create a directional light and add it to the light scene.
|
|
57
|
+
*
|
|
58
|
+
* @param properties.color The color of the light.
|
|
59
|
+
* @param properties.intensity The intensity of the light. (0-Infinity, default: 0.5)
|
|
60
|
+
* @param properties.id The id of the light.
|
|
61
|
+
* @param properties.name The name of the light.
|
|
62
|
+
* @param properties.direction The direction of the light.
|
|
63
|
+
* @param properties.castShadow Option for the light to cast shadows.
|
|
64
|
+
* @param properties.shadowMapResolution The resolution of the shadow map. (default: 1024, has to be power of two)
|
|
65
|
+
* @param properties.shadowMapBias The bias of the shadow map. For more info on the shadow bias, see [here](https://digitalrune.github.io/DigitalRune-Documentation/html/3f4d959e-9c98-4a97-8d85-7a73c26145d7.htm).
|
|
66
|
+
*/
|
|
67
|
+
addDirectionalLight(properties: {
|
|
68
|
+
color?: Color,
|
|
69
|
+
intensity?: number,
|
|
70
|
+
direction?: vec3,
|
|
71
|
+
castShadow?: boolean,
|
|
72
|
+
shadowMapResolution?: number,
|
|
73
|
+
shadowMapBias?: number,
|
|
74
|
+
id?: string,
|
|
75
|
+
name?: string
|
|
76
|
+
}): IDirectionalLightApi;
|
|
77
|
+
/**
|
|
78
|
+
* Create an hemisphere light and add it to the light scene.
|
|
79
|
+
*
|
|
80
|
+
* @param properties.color The color of the light.
|
|
81
|
+
* @param properties.intensity The intensity of the light. (0-Infinity, default: 0.5)
|
|
82
|
+
* @param properties.id The id of the light.
|
|
83
|
+
* @param properties.name The name of the light.
|
|
84
|
+
* @param properties.groundColor The ground color of the light.
|
|
85
|
+
*/
|
|
86
|
+
addHemisphereLight(properties: {
|
|
87
|
+
color?: Color,
|
|
88
|
+
intensity?: number,
|
|
89
|
+
groundColor?: Color,
|
|
90
|
+
id?: string,
|
|
91
|
+
name?: string
|
|
92
|
+
}): IHemisphereLightApi;
|
|
93
|
+
/**
|
|
94
|
+
* Create a point light and add it to the light scene.
|
|
95
|
+
*
|
|
96
|
+
* @param properties.color The color of the light.
|
|
97
|
+
* @param properties.intensity The intensity of the light. (0-Infinity, default: 0.5)
|
|
98
|
+
* @param properties.id The id of the light.
|
|
99
|
+
* @param properties.name The name of the light.
|
|
100
|
+
* @param properties.position The position of the light.
|
|
101
|
+
* @param properties.distance The distance of the light.
|
|
102
|
+
* @param properties.decay The decay of the light.
|
|
103
|
+
*/
|
|
104
|
+
addPointLight(properties: {
|
|
105
|
+
color?: Color,
|
|
106
|
+
intensity?: number,
|
|
107
|
+
position?: vec3,
|
|
108
|
+
distance?: number,
|
|
109
|
+
decay?: number,
|
|
110
|
+
id?: string,
|
|
111
|
+
name?: string
|
|
112
|
+
}): IPointLightApi;
|
|
113
|
+
/**
|
|
114
|
+
* Create a point light and add it to the light scene.
|
|
115
|
+
*
|
|
116
|
+
* @param properties.color The color of the light.
|
|
117
|
+
* @param properties.intensity The intensity of the light. (0-Infinity, default: 0.5)
|
|
118
|
+
* @param properties.id The id of the light.
|
|
119
|
+
* @param properties.name The name of the light.
|
|
120
|
+
* @param properties.position The position of the light.
|
|
121
|
+
* @param properties.target The target of the light.
|
|
122
|
+
* @param properties.distance The distance of the light.
|
|
123
|
+
* @param properties.decay The decay of the light.
|
|
124
|
+
* @param properties.angle The angle of the light.
|
|
125
|
+
* @param properties.penumbra The penumbra of the light.
|
|
126
|
+
*/
|
|
127
|
+
addSpotLight(properties: {
|
|
128
|
+
color?: Color,
|
|
129
|
+
intensity?: number,
|
|
130
|
+
position?: vec3,
|
|
131
|
+
target?: vec3,
|
|
132
|
+
distance?: number,
|
|
133
|
+
decay?: number,
|
|
134
|
+
angle?: number,
|
|
135
|
+
penumbra?: number,
|
|
136
|
+
id?: string,
|
|
137
|
+
name?: string
|
|
138
|
+
}): ISpotLightApi;
|
|
139
|
+
/**
|
|
140
|
+
* Remove a light from the light scene with the specified id.
|
|
141
|
+
*
|
|
142
|
+
* @param id The id of the light to remove.
|
|
143
|
+
*/
|
|
144
|
+
removeLight(id: string): boolean;
|
|
145
|
+
|
|
146
|
+
// #endregion Public Methods (6)
|
|
147
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ILightApi } from '../ILightApi';
|
|
2
|
+
import { vec3 } from 'gl-matrix';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The api for a directional light.
|
|
6
|
+
* A directional light can be created by calling the {@link addDirectionalLight} method.
|
|
7
|
+
*/
|
|
8
|
+
export interface IDirectionalLightApi extends ILightApi {
|
|
9
|
+
// #region Properties (4)
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Option to cast shadows.
|
|
13
|
+
*/
|
|
14
|
+
castShadow: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The direction of the light.
|
|
17
|
+
*/
|
|
18
|
+
direction: vec3;
|
|
19
|
+
/**
|
|
20
|
+
* The bias of the shadow map.
|
|
21
|
+
*/
|
|
22
|
+
shadowMapBias: number;
|
|
23
|
+
/**
|
|
24
|
+
* The resolution of the shadow map.
|
|
25
|
+
*/
|
|
26
|
+
shadowMapResolution: number;
|
|
27
|
+
|
|
28
|
+
// #endregion Properties (4)
|
|
29
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Color } from '@shapediver/viewer.shared.types';
|
|
2
|
+
import { ILightApi } from '../ILightApi';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The api for an hemisphere light.
|
|
6
|
+
* An hemisphere light can be created by calling the {@link addHemisphereLight} method.
|
|
7
|
+
*/
|
|
8
|
+
export interface IHemisphereLightApi extends ILightApi {
|
|
9
|
+
// #region Properties (1)
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The ground color of the light.
|
|
13
|
+
*/
|
|
14
|
+
groundColor: Color;
|
|
15
|
+
|
|
16
|
+
// #endregion Properties (1)
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ILightApi } from '../ILightApi';
|
|
2
|
+
import { vec3 } from 'gl-matrix';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The api for a point light.
|
|
6
|
+
* A point light can be created by calling the {@link addPointLight} method.
|
|
7
|
+
*/
|
|
8
|
+
export interface IPointLightApi extends ILightApi {
|
|
9
|
+
// #region Properties (3)
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The decay of the light.
|
|
13
|
+
*/
|
|
14
|
+
decay: number;
|
|
15
|
+
/**
|
|
16
|
+
* The distance of the light.
|
|
17
|
+
*/
|
|
18
|
+
distance: number;
|
|
19
|
+
/**
|
|
20
|
+
* The position of the light.
|
|
21
|
+
*/
|
|
22
|
+
position: vec3;
|
|
23
|
+
|
|
24
|
+
// #endregion Properties (3)
|
|
25
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ILightApi } from '../ILightApi';
|
|
2
|
+
import { vec3 } from 'gl-matrix';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The api for a spot light.
|
|
6
|
+
* A spot light can be created by calling the {@link addSpotLight} method.
|
|
7
|
+
*/
|
|
8
|
+
export interface ISpotLightApi extends ILightApi {
|
|
9
|
+
// #region Properties (6)
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The angle of the light.
|
|
13
|
+
*/
|
|
14
|
+
angle: number;
|
|
15
|
+
/**
|
|
16
|
+
* The decay of the light.
|
|
17
|
+
*/
|
|
18
|
+
decay: number;
|
|
19
|
+
/**
|
|
20
|
+
* The distance of the light.
|
|
21
|
+
*/
|
|
22
|
+
distance: number;
|
|
23
|
+
/**
|
|
24
|
+
* The penumbra of the light.
|
|
25
|
+
*/
|
|
26
|
+
penumbra: number;
|
|
27
|
+
/**
|
|
28
|
+
* The position of the light.
|
|
29
|
+
*/
|
|
30
|
+
position: vec3;
|
|
31
|
+
/**
|
|
32
|
+
* The target of the light.
|
|
33
|
+
*/
|
|
34
|
+
target: vec3;
|
|
35
|
+
|
|
36
|
+
// #endregion Properties (6)
|
|
37
|
+
}
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BUSY_MODE_DISPLAY,
|
|
3
|
+
SPINNER_POSITIONING,
|
|
4
|
+
VISIBILITY_MODE
|
|
5
|
+
} from '@shapediver/viewer.rendering-engine.rendering-engine';
|
|
6
|
+
import { CreationControlCenterViewport, ICreationControlCenterViewport, ViewportCreationDefinition } from '@shapediver/viewer.creation-control-center.viewport';
|
|
7
|
+
import { InputValidator, Logger, SESSION_SETTINGS_MODE, ShapeDiverViewerValidationError } from '@shapediver/viewer.shared.services';
|
|
8
|
+
import { IViewportApi } from './interfaces/IViewportApi';
|
|
9
|
+
import { RenderingEngine as RenderingEngineThreeJs } from '@shapediver/viewer.rendering-engine.rendering-engine-threejs';
|
|
10
|
+
import { showConsoleMessage } from '@shapediver/viewer.api.general';
|
|
11
|
+
import { ViewportApi } from './implementation/ViewportApi';
|
|
12
|
+
|
|
13
|
+
const creationControlCenterViewport: ICreationControlCenterViewport = CreationControlCenterViewport.instance;
|
|
14
|
+
const inputValidator: InputValidator = InputValidator.instance;
|
|
15
|
+
const logger: Logger = Logger.instance;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The viewports that are currently being used.
|
|
19
|
+
*/
|
|
20
|
+
export const viewports: { [key: string]: IViewportApi; } = {};
|
|
21
|
+
|
|
22
|
+
// Whenever a session or viewport is added or removed, this update is called.
|
|
23
|
+
creationControlCenterViewport.updateViewports = (
|
|
24
|
+
renderingEngines: { [key: string]: RenderingEngineThreeJs; }
|
|
25
|
+
) => {
|
|
26
|
+
for (const v in renderingEngines)
|
|
27
|
+
if (!viewports[v])
|
|
28
|
+
viewports[v] = new ViewportApi(renderingEngines[v]);
|
|
29
|
+
|
|
30
|
+
for (const v in viewports) {
|
|
31
|
+
if (!renderingEngines[v])
|
|
32
|
+
delete viewports[v];
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create and initialize a viewport with the provided type and canvas,
|
|
38
|
+
* and return a viewport api object allowing to control it.
|
|
39
|
+
*
|
|
40
|
+
* An optional identifier for the viewport can be provided. This identifier can be used to retrieve the
|
|
41
|
+
* viewport object from {@link viewports}. In case no identifier is provided, a unique one will be generated.
|
|
42
|
+
*
|
|
43
|
+
* By default a new viewport displays the complete scene tree. Viewports can be excluded from
|
|
44
|
+
* displaying geometry for specific sessions by using the {@link excludeViewports} property of
|
|
45
|
+
* {@link ISessionApi}.
|
|
46
|
+
*
|
|
47
|
+
* @param properties.visibility The visibility of the viewport.
|
|
48
|
+
* @param properties.canvas The canvas that the viewport should use. A canvas element will be created if none is provided.
|
|
49
|
+
* @param properties.id The unique identifier to use for the viewport.
|
|
50
|
+
* @param properties.branding Optional branding options.
|
|
51
|
+
* @param properties.sessionSettingsId Optional identifier of the session to be used for loading / persisting settings of the viewport when the {@link SESSION_SETTINGS_MODE} is set to MANUAL.
|
|
52
|
+
* @param properties.sessionSettingsMode Allows to control which session to use for loading / persisting settings of the viewport. (default: {@link SESSION_SETTINGS_MODE.FIRST}).
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
export const createViewport = async (properties?: ViewportCreationDefinition): Promise<IViewportApi> => {
|
|
56
|
+
showConsoleMessage();
|
|
57
|
+
|
|
58
|
+
logger.debug(`createSession: Creating and initializing session with properties ${JSON.stringify(properties)}.`);
|
|
59
|
+
inputValidator.validateAndError('createViewport', properties, 'object', false);
|
|
60
|
+
|
|
61
|
+
const prop = Object.assign({}, properties);
|
|
62
|
+
inputValidator.validateAndError('createViewport', prop.canvas, 'HTMLCanvasElement', false);
|
|
63
|
+
inputValidator.validateAndError('createViewport', prop.id, 'string', false);
|
|
64
|
+
inputValidator.validateAndError('createViewport', prop.sessionSettingsId, 'string', false);
|
|
65
|
+
inputValidator.validateAndError('createViewport', prop.sessionSettingsMode, 'enum', false, Object.values(SESSION_SETTINGS_MODE));
|
|
66
|
+
inputValidator.validateAndError('createViewport', prop.visibility, 'enum', false, Object.values(VISIBILITY_MODE));
|
|
67
|
+
|
|
68
|
+
inputValidator.validateAndError('createViewport', prop.branding, 'object', false);
|
|
69
|
+
const branding = Object.assign({}, prop.branding);
|
|
70
|
+
if (branding.logo !== null) inputValidator.validateAndError('createViewport', branding.logo, 'string', false);
|
|
71
|
+
inputValidator.validateAndError('createViewport', branding.backgroundColor, 'string', false);
|
|
72
|
+
inputValidator.validateAndError('createViewport', branding.busyModeSpinner, 'string', false);
|
|
73
|
+
inputValidator.validateAndError('createViewport', branding.busyModeDisplay, 'enum', false, Object.values(BUSY_MODE_DISPLAY));
|
|
74
|
+
inputValidator.validateAndError('createViewport', branding.spinnerPositioning, 'enum', false, Object.values(SPINNER_POSITIONING));
|
|
75
|
+
|
|
76
|
+
prop.sessionSettingsMode = prop.sessionSettingsMode !== undefined ? prop.sessionSettingsMode : SESSION_SETTINGS_MODE.FIRST;
|
|
77
|
+
|
|
78
|
+
if (prop.sessionSettingsMode === SESSION_SETTINGS_MODE.MANUAL && !prop.sessionSettingsId)
|
|
79
|
+
throw new ShapeDiverViewerValidationError('createViewport: Input could not be validated. sessionSettingsId has to point to a valid and created session when using SESSION_SETTINGS_MODE.MANUAL', prop.sessionSettingsId, 'string');
|
|
80
|
+
|
|
81
|
+
const renderingEngine = await creationControlCenterViewport.createViewportEngine(prop);
|
|
82
|
+
|
|
83
|
+
viewports[renderingEngine.id] = new ViewportApi(renderingEngine);
|
|
84
|
+
return viewports[renderingEngine.id];
|
|
85
|
+
};
|
package/tsconfig.json
ADDED