1
1
import { Component , computed , CUSTOM_ELEMENTS_SCHEMA , effect , input , output } from '@angular/core' ;
2
- import { injectBeforeRender , injectStore , NgtArgs , NgtCamera , NgtVector3 , omit , pick } from 'angular-three' ;
2
+ import {
3
+ injectBeforeRender ,
4
+ injectStore ,
5
+ NgtArgs ,
6
+ NgtCamera ,
7
+ NgtOverwrite ,
8
+ NgtThreeElement ,
9
+ NgtVector3 ,
10
+ omit ,
11
+ pick ,
12
+ } from 'angular-three' ;
3
13
import { mergeInputs } from 'ngxtension/inject-inputs' ;
4
14
import * as THREE from 'three' ;
5
15
import { OrbitControls } from 'three-stdlib' ;
6
16
7
- export interface NgtsOrbitControlsOptions {
8
- camera ?: THREE . Camera ;
9
- domElement ?: HTMLElement ;
10
- target ?: NgtVector3 ;
11
- makeDefault : boolean ;
12
- regress : boolean ;
13
- enableDamping : boolean ;
14
- keyEvents : boolean | HTMLElement ;
15
- }
16
-
17
- const defaultOptions : Partial < Omit < OrbitControls , 'target' | 'enableDamping' | 'domElement' > > &
18
- NgtsOrbitControlsOptions = {
17
+ type ExtractCallback < T , E extends string > = T extends { addEventListener ( event : E , callback : infer C ) : void }
18
+ ? C
19
+ : never ;
20
+
21
+ export type OrbitControlsChangeEvent = Parameters < ExtractCallback < OrbitControls , 'change' > > [ 0 ] ;
22
+
23
+ export type NgtsOrbitControlsOptions = Omit <
24
+ NgtOverwrite <
25
+ NgtThreeElement < typeof OrbitControls > ,
26
+ {
27
+ camera ?: THREE . Camera ;
28
+ domElement ?: HTMLElement ;
29
+ target ?: NgtVector3 ;
30
+ makeDefault : boolean ;
31
+ regress : boolean ;
32
+ enableDamping : boolean ;
33
+ keyEvents : boolean | HTMLElement ;
34
+ }
35
+ > ,
36
+ 'attach' | 'addEventListener' | 'removeEventListener' | 'parameters' | '___ngt_args__' | '_domElementKeyEvents'
37
+ > ;
38
+
39
+ const defaultOptions : NgtsOrbitControlsOptions = {
19
40
enableDamping : true ,
20
41
regress : false ,
21
42
makeDefault : false ,
@@ -43,7 +64,7 @@ export class NgtsOrbitControls {
43
64
'enableDamping' ,
44
65
] ) ;
45
66
46
- changed = output < THREE . Event > ( ) ;
67
+ changed = output < OrbitControlsChangeEvent > ( ) ;
47
68
started = output < THREE . Event > ( ) ;
48
69
ended = output < THREE . Event > ( ) ;
49
70
@@ -67,9 +88,7 @@ export class NgtsOrbitControls {
67
88
injectBeforeRender (
68
89
( ) => {
69
90
const controls = this . controls ( ) ;
70
- if ( controls ?. enabled ) {
71
- controls . update ( ) ;
72
- }
91
+ if ( controls . enabled ) controls . update ( ) ;
73
92
} ,
74
93
{ priority : - 1 } ,
75
94
) ;
@@ -79,18 +98,14 @@ export class NgtsOrbitControls {
79
98
if ( ! makeDefault ) return ;
80
99
81
100
const controls = this . controls ( ) ;
82
- if ( ! controls ) return ;
83
-
84
101
const oldControls = this . store . snapshot . controls ;
85
102
this . store . update ( { controls } ) ;
86
103
onCleanup ( ( ) => void this . store . update ( { controls : oldControls } ) ) ;
87
104
} ) ;
88
105
89
106
effect ( ( onCleanup ) => {
90
- const controls = this . controls ( ) ;
91
- if ( ! controls ) return ;
92
-
93
- const [ keyEvents , domElement ] = [
107
+ const [ controls , keyEvents , domElement ] = [
108
+ this . controls ( ) ,
94
109
this . keyEvents ( ) ,
95
110
this . domElement ( ) || this . store . snapshot . events . connected || this . store . gl . domElement ( ) ,
96
111
this . store . invalidate ( ) ,
@@ -106,16 +121,14 @@ export class NgtsOrbitControls {
106
121
} ) ;
107
122
108
123
effect ( ( onCleanup ) => {
109
- const controls = this . controls ( ) ;
110
- if ( ! controls ) return ;
111
-
112
- const [ invalidate , performanceRegress , regress ] = [
124
+ const [ controls , invalidate , performanceRegress , regress ] = [
125
+ this . controls ( ) ,
113
126
this . store . invalidate ( ) ,
114
127
this . store . performance . regress ( ) ,
115
128
this . regress ( ) ,
116
129
] ;
117
130
118
- const changeCallback : ( e : THREE . Event ) => void = ( e ) => {
131
+ const changeCallback : ( e : OrbitControlsChangeEvent ) => void = ( e ) => {
119
132
invalidate ( ) ;
120
133
if ( regress ) performanceRegress ( ) ;
121
134
this . changed . emit ( e ) ;
0 commit comments