Skip to content

Commit

Permalink
use is instead of instanceof
Browse files Browse the repository at this point in the history
  • Loading branch information
michealparks committed Dec 17, 2023
1 parent 50fbb3b commit b1c7172
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
17 changes: 7 additions & 10 deletions src/lib/components/Bindings/Bindings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import Scene from './Scene.svelte'
import Material from './Material.svelte'
export let object: THREE.Object3D
export let object: THREE.Scene | THREE.Light | THREE.PerspectiveCamera | THREE.OrthographicCamera
$: scene = object as THREE.Scene
$: light = object as THREE.Light
$: camera = object as THREE.PerspectiveCamera | THREE.OrthographicCamera
$: userData = JSON.stringify(object.userData)
</script>

Expand Down Expand Up @@ -63,20 +60,20 @@
options={{ step: 1 }}
/>

{#if 'isPerspectiveCamera' in camera || 'isOrthographicCamera' in camera}
{#if 'isPerspectiveCamera' in object || 'isOrthographicCamera' in object}
<Folder
title="Camera"
expanded={false}
>
<Camera object={camera} />
<Camera {object} />
</Folder>

{:else if light.isLight}
{:else if 'isDirectionalLight' in object || 'isPointLight' in object || 'isSpotLight' in object || 'isHemisphereLight' in object || 'isRectAreaLight' in object}
<Folder
title="Light"
expanded={false}
>
<Light object={light} />
<Light {object} />
</Folder>

{:else if 'material' in object && object.material instanceof THREE.Material}
Expand All @@ -87,12 +84,12 @@
<Material object={object.material} />
</Folder>

{:else if scene.isScene}
{:else if 'isScene' in object}
<Folder
title="Scene"
expanded={false}
>
<Scene object={scene} />
<Scene {object} />
</Folder>

{/if}
Expand Down
12 changes: 6 additions & 6 deletions src/lib/components/Bindings/Light.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Color from './Color.svelte'
import Shadow from './Shadow.svelte'
export let object: THREE.Light
export let object: THREE.DirectionalLight | THREE.PointLight | THREE.SpotLight | THREE.HemisphereLight | THREE.RectAreaLight
</script>

<Color
Expand All @@ -19,13 +19,13 @@
options={{ step: 0.05 }}
/>

{#if object instanceof THREE.DirectionalLight}
{#if 'isDirectionalLight' in object}
<Binding
bind:object={object.target}
key="position"
label="target"
/>
{:else if object instanceof THREE.PointLight}
{:else if 'isPointLight' in object}
<Binding
bind:object
key="decay"
Expand All @@ -41,7 +41,7 @@
key="power"
label="power"
/>
{:else if object instanceof THREE.SpotLight}
{:else if 'isSpotLight' in object}
<Binding
bind:object={object.target}
key="position"
Expand Down Expand Up @@ -79,13 +79,13 @@
key="position"
label="position"
/>
{:else if object instanceof THREE.HemisphereLight}
{:else if 'isHemisphereLight' in object}
<Binding
bind:object
key="groundColor"
label="groundColor"
/>
{:else if object instanceof THREE.RectAreaLight}
{:else if 'isRectAreaLight' in object}
<Binding
bind:object
key="power"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/Bindings/Material.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
/>
{/if}

{#if object instanceof THREE.MeshStandardMaterial}
{#if 'isMeshStandardMaterial' in object}
<Binding
bind:object
key="roughness"
Expand All @@ -94,7 +94,7 @@
/>
{/if}

{#if object instanceof THREE.MeshPhysicalMaterial}
{#if 'isMeshPhysicalMaterial' in object}
<Binding
bind:object
key="clearcoat"
Expand Down

0 comments on commit b1c7172

Please sign in to comment.