Skip to content

Commit

Permalink
Fix *Camera components' add_helper logic (#153)
Browse files Browse the repository at this point in the history
Analog `*Light` components.
  • Loading branch information
Vatroslav Vrbanic committed Nov 19, 2022
1 parent d43a6a8 commit 3206309
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
23 changes: 15 additions & 8 deletions src/lib/components/OrthographicCamera.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -611,18 +611,25 @@ If you use this approach you'll see a warning in the console if you define left,
/** Creates and adds a `CameraHelper` (_no `helperParams`_). */
export let helper: boolean | undefined = undefined
$: camera && !camera.userData.helper && helper === true ? add_helper() : null
$: camera && camera.userData.helper && !helper ? remove_helper() : null
$: camera && helper === true ? add_helper() : null
$: camera && helper !== undefined && !helper ? remove_helper() : null
function add_helper(): void {
if (camera) {
camera.userData.helper = new CameraHelper(camera)
if (scene) {
scene.add(camera.userData.helper)
if (!camera.userData.helper) {
camera.userData.helper = new CameraHelper(camera)
if (scene) {
scene.add(camera.userData.helper)
} else {
console.error(
`SVELTHREE > ${c_name} > add_helper : Couldn't add helper to unavailable 'scene' instance!`,
{ scene }
)
}
} else {
console.error(
`SVELTHREE > ${c_name} > add_helper : Couldn't add helper to unavailable 'scene' instance!`,
{ scene }
console.debug(
`SVELTHREE > ${c_name} > add_helper : Didn't create new helper, 'camera.userData.helper' instance already available!`,
{ camera, helper: camera.userData.helper }
)
}
} else {
Expand Down
23 changes: 15 additions & 8 deletions src/lib/components/PerspectiveCamera.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -687,18 +687,25 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of `
/** Creates and adds a `CameraHelper` (_no `helperParams`_). */
export let helper: boolean | undefined = undefined
$: camera && !camera.userData.helper && helper === true ? add_helper() : null
$: camera && camera.userData.helper && !helper ? remove_helper() : null
$: camera && helper === true ? add_helper() : null
$: camera && helper !== undefined && !helper ? remove_helper() : null
function add_helper(): void {
if (camera) {
camera.userData.helper = new CameraHelper(camera)
if (scene) {
scene.add(camera.userData.helper)
if (!camera.userData.helper) {
camera.userData.helper = new CameraHelper(camera)
if (scene) {
scene.add(camera.userData.helper)
} else {
console.error(
`SVELTHREE > ${c_name} > add_helper : Couldn't add helper to unavailable 'scene' instance!`,
{ scene }
)
}
} else {
console.error(
`SVELTHREE > ${c_name} > add_helper : Couldn't add helper to unavailable 'scene' instance!`,
{ scene }
console.debug(
`SVELTHREE > ${c_name} > add_helper : Didn't create new helper, 'camera.userData.helper' instance already available!`,
{ camera, helper: camera.userData.helper }
)
}
} else {
Expand Down

0 comments on commit 3206309

Please sign in to comment.