diff --git a/src/lib/components/CubeCamera.svelte b/src/lib/components/CubeCamera.svelte index 101e555..25d18fb 100644 --- a/src/lib/components/CubeCamera.svelte +++ b/src/lib/components/CubeCamera.svelte @@ -50,7 +50,7 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env MeshBasicMaterial, MeshLambertMaterial } from "three" - import type { RemoveLast } from "../types/types-extra" + import type { RemoveLast, MeshAssignableMaterial } from "../types/types-extra" import type { default as MeshSvelthreeComponent } from "./Mesh.svelte" import type { default as Object3DSvelthreeComponent } from "./Object3D.svelte" @@ -99,7 +99,8 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env * ☝️ The `pos` shorthand attribute will override `bind_pos`! _Alternatively (standard)_: * add the `CubeCamera` component as a child to either a `Mesh` or an `Object3D`/`Group` component, * in this case `CubeCamera`'s position will be bound to it's parent / object (three) instance. */ - export let bind_pos: MeshSvelthreeComponent | Object3DSvelthreeComponent | Object3D = undefined + export let bind_pos: MeshSvelthreeComponent | Object3DSvelthreeComponent | Object3D = + undefined $: if (camera && $svelthreeStores[sti].renderer && bind_pos && !bind_pos_offset && !dynamic) update_cubecam() /** Adjust `CubeCamera`'s position by setting an offset relative to the pivot of the object specified by `bind_pos`. */ @@ -110,7 +111,8 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env * Default: `CubeCamera`'s parent component's object (three) instance will be hidden. * -> ☝️ If you add `CubeCamera` as a direct child of a `Scene` component without specifying some other object / objects to be hidden, * the **root scene** will be hidden during the 'envMap'-texture rendering and your 'envMap' texture will be blank! */ - export let hide: (MeshSvelthreeComponent | Object3DSvelthreeComponent | Object3D)[] = undefined + export let hide: (MeshSvelthreeComponent | Object3DSvelthreeComponent | Object3D)[] = + undefined /** Binds the texture generated by the `CubeCamera` to some `Mesh`-component's `.material`(_currently non PBR + has `.envMap`_). * This is the opposite of / alternative to binding the material's `.envMap` property to `[CubeCamera component reference].texture` */ @@ -375,24 +377,24 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env // checking if their material has an '.envMap' property and is not a PBR material and then apply the the cubemap texture to those objects. // But for now, this is not possible. - let bound_pos: typeof bind_pos = bind_pos || our_parent - let to_hide: typeof hide | typeof bind_pos = hide || bound_pos - let renderer: WebGLRenderer = $svelthreeStores[sti].renderer - let active_scene: Scene = $svelthreeStores[sti].activeScene + const bound_pos: typeof bind_pos = bind_pos || our_parent + const to_hide: typeof hide | typeof bind_pos = hide || bound_pos + const renderer: WebGLRenderer = $svelthreeStores[sti].renderer + const active_scene: Scene = $svelthreeStores[sti].activeScene if (pos === undefined) { // the floor hack -> see https://jsfiddle.net/3mprbLc9/ if (is_floor) { - let active_cam: Camera = $svelthreeStores[sti].activeCamera - let target_pos: Vector3 = get_cubecam_target_position(active_cam) + const active_cam: Camera = $svelthreeStores[sti].activeCamera + const target_pos: Vector3 = get_cubecam_target_position(active_cam) camera.position.copy(target_pos) // IMPORTANT GOOD this does NOT triggers all 'camera' bound reactive statements as opposed to `camera.position.y *= -1`! camera.position.setY(camera.position.y * -1) } else { - let target_pos: Vector3 = get_cubecam_target_position(bound_pos) + const target_pos: Vector3 = get_cubecam_target_position(bound_pos) if (bind_pos_offset) { - let corrected_target_pos: Vector3 = target_pos.clone().add(bind_pos_offset) + const corrected_target_pos: Vector3 = target_pos.clone().add(bind_pos_offset) camera.position.copy(corrected_target_pos) } else { camera.position.copy(target_pos) @@ -407,8 +409,8 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env camera_updated = true if (!bind_tex) { - let op: Mesh = bound_pos as Mesh - let op_mat: MaterialWithEnvMap = op.material as MaterialWithEnvMap + const op = bound_pos as Mesh + const op_mat = op.material as MaterialWithEnvMap if (op_mat && Object.prototype.hasOwnProperty.call(op_mat, "envMap")) { op_mat.envMap = camera.renderTarget.texture } @@ -416,7 +418,7 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env } function change_visibility(to_change: typeof hide | typeof bind_pos, val: boolean) { - let toc: typeof hide = to_change as typeof hide + const toc = to_change as typeof hide if (toc.length && toc.length > 0) { for (let i = 0; i < toc.length; i++) { set_visibility(toc[i], val) @@ -428,12 +430,10 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env function set_visibility(obj: typeof hide | typeof bind_pos, val: boolean) { if (obj["is_svelthree_component"]) { - let o: MeshSvelthreeComponent | Object3DSvelthreeComponent = obj as - | MeshSvelthreeComponent - | Object3DSvelthreeComponent + const o = obj as MeshSvelthreeComponent | Object3DSvelthreeComponent o.get_instance().visible = val } else { - let o = obj as Object3D + const o = obj as Object3D o.visible = val } } @@ -442,12 +442,10 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env let wp: Vector3 = new Vector3() if (typeof obj["getWorldPosition"] === "function") { - let o = obj as Object3D + const o = obj as Object3D o.getWorldPosition(wp) } else { - let o: MeshSvelthreeComponent | Object3DSvelthreeComponent = obj as - | MeshSvelthreeComponent - | Object3DSvelthreeComponent + const o = obj as MeshSvelthreeComponent | Object3DSvelthreeComponent o.get_instance().getWorldPosition(wp) }