Skip to content

Commit b7650b2

Browse files
committed
fix(core): loosen instanceof check
1 parent 56612c3 commit b7650b2

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

Diff for: libs/core/src/lib/roots.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
Raycaster,
1111
Scene,
1212
VSMShadowMap,
13-
Vector3,
1413
} from 'three';
1514
import { prepare } from './instance';
1615
import { injectLoop, roots } from './loop';
@@ -133,7 +132,7 @@ export function injectCanvasRootInitializer(injector?: Injector) {
133132
// always look at center or passed-in lookAt by default
134133
if (!state.camera && !cameraOptions?.rotation && !cameraOptions?.quaternion) {
135134
if (Array.isArray(lookAt)) camera.lookAt(lookAt[0], lookAt[1], lookAt[2]);
136-
else if (lookAt instanceof Vector3) camera.lookAt(lookAt);
135+
else if (lookAt?.isVector3) camera.lookAt(lookAt);
137136
else camera.lookAt(0, 0, 0);
138137
}
139138

@@ -154,7 +153,7 @@ export function injectCanvasRootInitializer(injector?: Injector) {
154153
if (!state.scene) {
155154
let scene: Scene;
156155

157-
if (sceneOptions instanceof Scene) {
156+
if (is.scene(sceneOptions)) {
158157
scene = sceneOptions;
159158
} else {
160159
scene = new Scene();

Diff for: libs/core/src/lib/store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ function storeFactory(previousStore: NgtSignalStore<NgtState> | null) {
3232
const { width, height, top, left } = size;
3333
const aspect = width / height;
3434

35-
if (target instanceof Vector3) tempTarget.copy(target);
36-
else tempTarget.set(...target);
35+
if ((target as Vector3).isVector3) tempTarget.copy(target as Vector3);
36+
else tempTarget.set(...(target as [number, number, number]));
3737

3838
const distance = camera.getWorldPosition(position).distanceTo(tempTarget);
3939

Diff for: libs/core/src/lib/utils/apply-props.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Color, ColorManagement, Layers, RGBAFormat, Texture, UnsignedByteType } from 'three';
1+
import { ColorManagement, Layers, RGBAFormat, Texture, UnsignedByteType } from 'three';
22
import { getLocalState, invalidateInstance } from '../instance';
33
import { NgtAnyRecord, NgtInstanceNode, NgtState } from '../types';
44
import { is } from './is';
@@ -63,7 +63,7 @@ export function applyProps(instance: NgtInstanceNode, props: NgtAnyRecord) {
6363

6464
// special treatmen for objects with support for set/copy, and layers
6565
if (targetProp && targetProp['set'] && (targetProp['copy'] || targetProp instanceof Layers)) {
66-
const isColor = targetProp instanceof Color;
66+
const isColor = targetProp.isColor;
6767
// if value is an array
6868
if (Array.isArray(value)) {
6969
if (targetProp['fromArray']) targetProp['fromArray'](value);
@@ -79,7 +79,7 @@ export function applyProps(instance: NgtInstanceNode, props: NgtAnyRecord) {
7979
if (!ColorManagement && !rootState.linear && isColor) targetProp['convertSRGBToLinear']();
8080
} // if nothing else fits, just set the single value, ignore undefined
8181
else if (value !== undefined) {
82-
const isColor = targetProp instanceof Color;
82+
const isColor = targetProp.isColor;
8383
// allow setting array scalars
8484
if (!isColor && targetProp['setScalar']) targetProp['setScalar'](value);
8585
// layers have no copy function, copy the mask
@@ -95,7 +95,7 @@ export function applyProps(instance: NgtInstanceNode, props: NgtAnyRecord) {
9595
currentInstance[key] = value;
9696
// auto-convert srgb textures
9797
if (
98-
currentInstance[key] instanceof Texture &&
98+
currentInstance[key].isTexture &&
9999
currentInstance[key].format === RGBAFormat &&
100100
currentInstance[key].type === UnsignedByteType
101101
) {

0 commit comments

Comments
 (0)