@@ -105,9 +105,17 @@ export function applyProps<T extends NgtAnyRecord>(instance: NgtInstanceState<T>
105
105
return applyProps ( root , { [ targetKey ] : value } ) ;
106
106
}
107
107
108
+ // Layers have no copy function, we must therefore copy the mask property
109
+ if ( targetProp instanceof THREE . Layers && value instanceof THREE . Layers ) {
110
+ targetProp . mask = value . mask ;
111
+ } else if ( is . three < THREE . Color > ( targetProp , 'isColor' ) && is . colorRepresentation ( value ) ) {
112
+ targetProp . set ( value ) ;
113
+ }
108
114
// Copy if properties match signatures
109
- if (
110
- targetProp ?. copy &&
115
+ else if (
116
+ targetProp &&
117
+ typeof targetProp . set === 'function' &&
118
+ typeof targetProp . copy === 'function' &&
111
119
( value as ClassConstructor | undefined ) ?. constructor &&
112
120
( targetProp as ClassConstructor ) . constructor === ( value as ClassConstructor ) . constructor
113
121
) {
@@ -118,29 +126,20 @@ export function applyProps<T extends NgtAnyRecord>(instance: NgtInstanceState<T>
118
126
) {
119
127
Object . assign ( root , { [ targetKey ] : value } ) ;
120
128
} else {
121
- // fetch the default state of the target
122
- const ctor = getMemoizedPrototype ( root ) ;
123
- // The target key was originally null or undefined, which indicates that the object which
124
- // is now present was externally set by the user, we should therefore assign the value directly
125
- if ( ctor !== undefined && ctor [ targetKey ] == null ) Object . assign ( root , { [ targetKey ] : value } ) ;
126
- // Otherwise copy is correct
127
- else targetProp . copy ( value ) ;
129
+ targetProp . copy ( value ) ;
128
130
}
129
131
}
130
- // Layers have no copy function, we must therefore copy the mask property
131
- else if ( targetProp instanceof THREE . Layers && value instanceof THREE . Layers ) {
132
- targetProp . mask = value . mask ;
133
- }
134
132
// Set array types
135
- else if ( targetProp ? .set && Array . isArray ( value ) ) {
136
- if ( targetProp . fromArray ) targetProp . fromArray ( value ) ;
133
+ else if ( targetProp && typeof targetProp . set === 'function' && Array . isArray ( value ) ) {
134
+ if ( typeof targetProp . fromArray === 'function' ) targetProp . fromArray ( value ) ;
137
135
else targetProp . set ( ...value ) ;
138
136
}
139
137
// Set literal types
140
- else if ( targetProp ? .set && typeof value !== 'object' ) {
141
- const isColor = ( targetProp as THREE . Color | undefined ) ?. isColor ;
138
+ else if ( targetProp && typeof targetProp . set === 'function' && typeof value !== 'object' ) {
139
+ const isColor = is . three < THREE . Color > ( targetProp , ' isColor' ) ;
142
140
// Allow setting array scalars
143
- if ( ! isColor && targetProp . setScalar && typeof value === 'number' ) targetProp . setScalar ( value ) ;
141
+ if ( ! isColor && typeof targetProp . setScalar === 'function' && typeof value === 'number' )
142
+ targetProp . setScalar ( value ) ;
144
143
// Otherwise just set single value
145
144
else targetProp . set ( value ) ;
146
145
}
0 commit comments