-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
SpotLight.svelte
692 lines (549 loc) · 25.6 KB
/
SpotLight.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
<!--
`accessors:true` hast to be set per component because of the svelte-language-server bug, otherwise accessors would be falsely detected as missing and highlighted as errors.
svelthree uses svelte-accmod, where accessors are always `true`, regardless of `svelte:options`.
-->
<svelte:options accessors />
<!--
@component
**svelthree** _SpotLight_ Component.
[ tbd ] Link to Docs.
-->
<script lang="ts">
import type { Scene } from "three"
import { beforeUpdate, onMount, afterUpdate, onDestroy, getContext, setContext, tick } from "svelte"
import { get_current_component } from "svelte/internal"
import { self as _self } from "svelte/internal"
import { c_rs, c_lc, c_mau, c_dev, verbose_mode, get_comp_name } from "../utils/SvelthreeLogger"
import type { LogLC, LogDEV } from "../utils/SvelthreeLogger"
import type { SvelthreeShadowDOMElement } from "../types-extra"
import { if$_instance_change } from "../logic/if$"
import { remove_instance, recreate_shadow_dom_el, set_initial_userdata, find_in_canvas } from "../logic/shared"
import type { Euler, Matrix4, Quaternion, Vector3 } from "three"
import { svelthreeStores } from "svelthree/stores"
import { PropUtils, SvelthreeProps } from "../utils"
import { SvelthreeAnimation } from "../ani"
import type { SvelthreeAnimationFunction, SvelthreeAnimationFunctionReturn } from "../types-extra"
import { SvelthreeLightWithShadow } from "../components-internal"
import type { LightShadowCamProps, LightShadowProps } from "../types-extra"
//import type { Empty, Mesh } from "."
import type { Targetable } from "../types-extra"
import { LightTarget } from "../utils"
import { Object3D } from "three"
import { SpotLight, SpotLightHelper } from "three"
import type { SpotLightProps } from "../types-comp-props"
import type { SpotLightShadow } from "three"
import type { Color } from "three"
import type { RemoveFirst } from "../types-extra"
import { get_root_scene } from "../utils/SceneUtils"
import type { Writable } from "svelte/store"
/**
* SVELTEKIT SSR /
* `browser` is needed for the SvelteKit setup (SSR / CSR / SPA).
* For non-SSR output in RollUp only and Vite only setups (CSR / SPA) we're just mimicing `$app/env` where `browser = true`,
* -> TS fix: `$app/env` mapped to `src/$app/env` via svelthree's `tsconfig.json`'s `path` property.
* -> RollUp only setup: replace `$app/env` with `../$app/env`
* The import below will work out-of-the-box in a SvelteKit setup.
*/
import { browser } from "$app/env"
const self = get_current_component()
const c_name = get_comp_name(self)
const verbose: boolean = verbose_mode()
export let log_all: boolean = false
export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined
export let log_rs: boolean = log_all
export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined
export let log_mau: boolean = log_all
let scene: Scene = getContext("scene")
const sti: number = getContext("store_index")
/** [ **feature**: allow providing (_injection_) of (_already created_) threejs object instances ].
* `create` is an internal indicator for how the component's corresponding threejs object instance has to be / has been created.
* It's being set to `false` on initialization if an (_already created_) threejs object instance was provided,
* otherwise it's set to `true`, means a new threejs object instance will be created. */
let create = false
/** The (three) instance that was shared to this component as it's 'parent' which can be either another instance / object or a scene / root scene. */
let our_parent: Object3D = undefined
/** Shadow DOM element generated by our parent scene / root scene. Used as fallback if this component has no non-`Scene` component as parent. */
let scene_shadow_dom_el: SvelthreeShadowDOMElement = getContext("scene_shadow_dom_el")
/** Shadow DOM element generated by our parent component (_not `Canvas`_) shared with this component (child) via context.
Fallback is `scene_shadow_dom_el` or `shadow_root_el` in case of the `Scene` component. */
let our_parent_shadow_dom_el: SvelthreeShadowDOMElement = undefined
/** Shadow DOM element generated by this component. Shared by this component (as parent) to it's children via context as "parent_shadow_dom_el". */
let shadow_dom_el: SvelthreeShadowDOMElement = undefined
/** Returns the `light` instance created by the component & allows providing (_injection_) of (_already created / premade_) `THREE.SpotLight` instances. */
export let light: SpotLight = undefined
let light_uuid: string = undefined
/** Sets the `name` property of the created / injected three.js instance. */
export let name: string = undefined
export const is_svelthree_component: boolean = true
export const is_svelthree_light: boolean = true
// ONCE ON INITIALIZATION //
if (light) {
create = false
on_instance_provided()
} else {
create = true
}
// INJECTION ONCE ON INITIALIZATION //
/** Executed when / if an instance was provided **on initializiation** -> only once if at all! */
function on_instance_provided(): void {
if (light.type === "SpotLight") {
} else {
throw new Error(
`SVELTHREE > ${c_name} provided 'light' instance has wrong type '${light.type}', should be '${c_name}'!`
)
}
}
// INJECTION ONCE ON INITIALIZATION //
if (!create) {
// get the instance that was shared to us as our 'parent' or use fallback.
our_parent = getContext("parent") || scene
// get the shadow DOM element that was shared to us by our parent component or use fallback.
our_parent_shadow_dom_el = getContext("parent_shadow_dom_el") || scene_shadow_dom_el
// share created object (three) instance to all children (slots) as 'parent'.
setContext("parent", light)
// SVELTEKIT SSR /
if (browser) create_shadow_dom()
}
/** Initializes `SpotLight` with provided constructor parameters.*/
export let params: ConstructorParameters<typeof SpotLight> = undefined
$: if (!light && create) {
if (params) {
light = new SpotLight(...params)
} else {
light = new SpotLight()
}
set_initial_userdata(light, self)
if (verbose && log_dev) console.debug(...c_dev(c_name, `${light.type} created!`, { light }))
}
// --- AFTER INITIALIZATION --- //
// set light_uuid the first time
$: if (light && light_uuid === undefined) set_uuid()
function set_uuid(): void {
light_uuid = light.uuid
}
// GENERATOR REMARK: 'reactive_re_creation_logic' not implemented for 'SpotLight'!
// Determining 'parent' if 'light' instance has to be created first / was not provided on initialization ('create' is true).
$: if (light && create && scene && !our_parent) set_parent()
function set_parent() {
// get the instance that was shared to us as our 'parent' or use fallback.
our_parent = getContext("parent") || scene
// share created object (three) instance to all children (slots) as 'parent'.
setContext("parent", light)
}
// IMPORTANT TODO
// - see https://github.com/vatro/svelthree/issues/114
// - see https://github.com/vatro/svelthree/issues/103
$: if (light && create && our_parent_shadow_dom_el === undefined) {
our_parent_shadow_dom_el = getContext("parent_shadow_dom_el") || scene_shadow_dom_el
}
// IMPORTANT TODO
// - see https://github.com/vatro/svelthree/issues/114
// - see https://github.com/vatro/svelthree/issues/103
$: if (our_parent_shadow_dom_el !== undefined) {
// SVELTEKIT SSR /
if (browser) create_shadow_dom()
}
function create_shadow_dom(): void {
// create / recreate and share our own shadow_dom_el as parent_shadow_dom_el
shadow_dom_el = recreate_shadow_dom_el(shadow_dom_el, our_parent_shadow_dom_el, null, null, c_name)
if (shadow_dom_el) {
setContext("parent_shadow_dom_el", shadow_dom_el)
} else {
if (!shadow_dom_el) console.error(`SVELTHREE > ${c_name} : 'shadow_dom_el' was not created!`, shadow_dom_el)
}
}
// accessability -> shadow dom focusable
export let tabindex: number = undefined
$: if (shadow_dom_el && tabindex !== undefined) {
shadow_dom_el.tabIndex = tabindex
}
// accessability -> shadow dom wai-aria
export let aria: Partial<ARIAMixin> = undefined
$: if (shadow_dom_el && aria !== undefined) {
for (const key in aria) {
if (key === "ariaLabel") {
// add specified `ariaLabel` as text to generated shadow DOM `<div>` element (for better reader support / indexing (?))
// TODO RECONSIDER needs to be tested more, may be obsolete (?).
shadow_dom_el.innerText += `${aria[key]}`
}
shadow_dom_el[key] = aria[key]
}
}
// this reactive statement willl be triggered on any 'light' instance change (also e.g. `light.foo = value`)
$: if (light) if$_instance_change(light, our_parent, light_uuid, create, "light", name, handle_instance_change)
/** Called from by the `if$_instance_change` logic if needed. */
function handle_instance_change(): void {
if ((light_uuid && light.uuid !== light_uuid) || !light_uuid) {
const uuid_to_remove: string = light_uuid || light.uuid
const old_instance: Object3D = find_in_canvas($svelthreeStores[sti].scenes, uuid_to_remove)
remove_instance(old_instance, "light", light, self)
if (props) sProps = new SvelthreeProps(light)
}
set_initial_userdata(light, self)
our_parent.add(light)
light_uuid = light.uuid
if (verbose && log_dev) {
console.debug(
...c_dev(c_name, `${light.type} was added to ${our_parent.type}!`, {
light,
scene,
total: scene.children.length
})
)
}
}
/** Defaults to `true` which means that components / objects with targets (_`DirectionalLight`, `SpotLight`, `OrthographicCamera` and `PerspectiveCamera`_)
* will add the built-in 'blank' target-Object3D to component's / object's parent on initialization. `target` can be either set to `false` ( TODO ) (_which will remove the target from parent only if it's
* not the built-in 'blank' `Object3D`_) or some other object in the scene (_any `Object3D`, an `Empty` component or a `Mesh` component_) */
export let target: Targetable | boolean = undefined
$: if (target === undefined) target = true
let light_target = undefined
$: if (light && scene && target) light_target = new LightTarget(false, target, scene, light)
$: if (!matrix && light && target && light_target) light_target.change = true
// if the Light is a Light with a 'target' property, start / stop monitoring 'target' position changes if helper is enabled / disabled
$: !matrix && light && target && light_target && light.target?.isObject3D && $svelthreeStores[sti].rendererComponent
? start_monitoring_target_position()
: stop_monitoring_target_position()
// call this to remove the renderer component listener
let remove_target_position_listener: () => void
function start_monitoring_target_position(): void {
// IMPORTANT this does NOT cause a component update! (instead of using requestAnimationFrame)
// COOL! this way the helper is 100% synchronious (not 1 frame late)
if (!remove_target_position_listener) {
if (verbose && log_rs) console.debug(...c_rs(c_name, "start_monitoring_target_position!"))
remove_target_position_listener = $svelthreeStores[sti].rendererComponent.$on(
"before_render_int",
update_light_target
)
}
}
function update_light_target(): void {
light_target.update(helper)
}
function stop_monitoring_target_position(): void {
if (remove_target_position_listener) {
remove_target_position_listener()
remove_target_position_listener = undefined
kill_light_target()
}
}
function kill_light_target(): void {
if (!target) {
light_target = null
if (light.target) {
// remove target from parent only if it's the built-in target
if (light.target.userData.is_builtin_target && light.target.parent) {
light.target.parent.remove(light.target)
}
// recreate / reset target
light.target = new Object3D()
}
}
}
/** Override object's `.matrixAutoUpdate` set (*on initialzation*) by scene's `.matrixAutoUpdate` (*default is `true`*). Also: `mau` can be changed on-the-fly.*/
export let mau: boolean = undefined
$: if (light) light.matrixAutoUpdate = scene.matrixAutoUpdate
$: if (light && mau !== undefined) light.matrixAutoUpdate = mau
$: if (light && name) light.name = name
$: if (shadow_dom_el && name) shadow_dom_el.dataset.name = name
/** ☝️ `matrix` **shorthand** attribute overrides ( *are ignored* ) `pos`, `rot`, `quat`, `scale` and `lookAt` 'shorthand' attributes! */
export let matrix: Matrix4 | Parameters<Matrix4["set"]> = undefined
const w_sh = PropUtils.getShortHandAttrWarnings(`SVELTHREE > ${c_name} >`)
let sProps: SvelthreeProps
// IMPORTANT `props` will be overridden by 'shorthand' attributes!
/** **shorthand** attribute for setting properties using key-value pairs in an `Object`. */
export let props: { [P in keyof SpotLightProps]: SpotLightProps[P] } = undefined
$: if (!sProps && light && props) sProps = new SvelthreeProps(light)
$: if (props && sProps) update_props()
function update_props() {
if (verbose && log_rs) console.debug(...c_rs(c_name, "props", props))
sProps.update(props)
}
// IMPORTANT following 'shorthand' attributes will override `props` attribute!
/** **shorthand** attribute for setting the `position` property. */
export let pos: Vector3 | Parameters<Vector3["set"]> = undefined
$: !matrix && light && pos ? set_pos() : pos && light ? console.warn(w_sh.pos) : null
function set_pos() {
if (verbose && log_rs) console.debug(...c_rs(c_name, "pos", pos))
PropUtils.setPositionFromValue(light, pos)
}
/** With components / objects having a `target` property like `SpotLight`, `lookAt` is used to specify a **point (coordinates) in world space** and cannot be set to an `Object3D`!
* By setting `LookAt` to some value, you're basically moving the built-in 'blank' `Object3D` used as a point in space to look at.
* ☝️ _In order to update the `SpotLightHelper` correctly, the `target: boolean` attribute needs to be set / set to `true` (**default**)!_ */
export let lookAt: Vector3 | Parameters<Vector3["set"]> | Object3D = undefined
$: !matrix && light && lookAt ? set_lookat() : lookAt && light ? console.warn(w_sh.lookAt) : null
function set_lookat() {
if (verbose && log_rs) console.debug(...c_rs(c_name, "lookAt", lookAt))
PropUtils.setLookAtFromValue(light, lookAt)
}
// IMPORTANT `matrix` 'shorthand' attribute will override all other transforms ('shorthand' attributes)!
$: if (matrix && light) set_matrix()
function set_matrix(): void {
if (verbose && log_rs) console.debug(...c_rs(c_name, "matrix", matrix))
PropUtils.setMatrixFromValue(light, matrix)
}
/** Maximum extent of the `SpotLight`, in radians, from its direction. Should be no more than `Math.PI/2`.
* [See threejs-docs.](https://threejs.org/docs/#api/en/lights/SpotLight.angle) */
export let angle: number = undefined
$: if (light && angle !== undefined) set_angle()
function set_angle(): void {
if (verbose && log_rs) console.debug(...c_rs(c_name, "angle", angle))
light.angle = angle
}
/**
* [See threejs-docs.](https://threejs.org/docs/#api/en/lights/SpotLight.decay) */
export let decay: number = undefined
$: if (light && decay !== undefined) set_decay()
function set_decay(): void {
if (verbose && log_rs) console.debug(...c_rs(c_name, "decay", decay))
light.decay = decay
}
/**
* [See threejs-docs.](https://threejs.org/docs/#api/en/lights/SpotLight.distance) */
export let distance: number = undefined
$: if (light && distance !== undefined) set_distance()
function set_distance(): void {
if (verbose && log_rs) console.debug(...c_rs(c_name, "distance", distance))
light.distance = distance
}
/**
* [See threejs-docs.](https://threejs.org/docs/#api/en/lights/SpotLight.penumbra) */
export let penumbra: number = undefined
$: if (light && penumbra !== undefined) set_penumbra()
function set_penumbra(): void {
if (verbose && log_rs) console.debug(...c_rs(c_name, "penumbra", penumbra))
light.penumbra = penumbra
}
/**
* [See threejs-docs.](https://threejs.org/docs/#api/en/lights/SpotLight.power) */
export let power: number = undefined
$: if (light && power !== undefined) set_power()
function set_power(): void {
if (verbose && log_rs) console.debug(...c_rs(c_name, "power", power))
light.power = power
}
export let color: Color | string | number | [r: number, g: number, b: number] | number[] | Vector3 = undefined
$: if (light && color) set_color()
function set_color(): void {
if (verbose && log_rs) console.debug(...c_rs(c_name, "color", color))
PropUtils.setColorFromValueKey(light, color, "color")
}
/** The light's intensity. Default is 1. */
export let intensity: number = undefined
$: if (light && intensity !== undefined) set_intensity()
function set_intensity(): void {
if (verbose && log_rs) console.debug(...c_rs(c_name, "intensity", intensity))
light.intensity = intensity
}
export let shadowMapSize: number = undefined
export let shadowBias: number = undefined
export let castShadow: boolean = undefined
/** **shorthand** attribute for setting properties of `light.shadow` using key-value pairs in an `Object`. */
export let shadowProps: { [P in keyof LightShadowProps<SpotLightShadow>]: LightShadowProps<SpotLightShadow>[P] } =
undefined
/** **shorthand** attribute for setting properties of `light.shadow.camera` using key-value pairs in an `Object`. */
export let shadowCameraProps: {
[P in keyof LightShadowCamProps<typeof light.shadow.camera>]: LightShadowCamProps<typeof light.shadow.camera>[P]
} = undefined
type HelperParams = ConstructorParameters<typeof SpotLightHelper>
export let helperParams: RemoveFirst<HelperParams> = undefined
export let helper: boolean = undefined
$: light && !light.userData.helper && helper ? add_helper() : null
$: light && light.userData.helper && !helper ? remove_helper() : null
function add_helper(): void {
if (helperParams) {
light.userData.helper = new SpotLightHelper(light, ...helperParams)
} else {
light.userData.helper = new SpotLightHelper(light)
}
scene.add(light.userData.helper)
}
function remove_helper(): void {
if (light.userData.helper?.parent) {
light.userData.helper.parent.remove(light.userData.helper)
light.userData.helper = null
}
}
/** Animation logic to be performed with the (three) object instance created by the component. */
export let animation: SvelthreeAnimationFunction = undefined
let animationEnabled: boolean = false
$: if (animation) animationEnabled = true
/** Immediately start provided animation, default: `false`. Alternative: `<component_reference>.start_animation()` or shorter `.start_ani()`. */
export let aniauto: boolean = undefined
let ani: SvelthreeAnimation
$: if (animation && animationEnabled) ani = new SvelthreeAnimation(scene, light, animation, aniauto)
let currentSceneActive = undefined
$: currentSceneActive = $svelthreeStores[sti].scenes[scene.userData.index_in_scenes]?.isActive
$: if (ani && currentSceneActive !== undefined) ani.onCurrentSceneActiveChange(currentSceneActive)
/** The root scene -> `scene.parent = null`. */
let root_scene: Scene | null = undefined
let root_scene_obj = { value: undefined }
$: if (root_scene === undefined) {
root_scene = get_root_scene(getContext("scene"))
root_scene_obj.value = root_scene
}
$: if (light && root_scene) {
light.userData.root_scene = root_scene
}
export const get_helper = (): SpotLightHelper => light.userData.helper as SpotLightHelper
/** Removes the (three) instance created by / provided to the component from it's parent. */
export const remove_instance_from_parent = async (): Promise<boolean> => {
const removed: boolean = await remove_instance(light, "light")
return removed
}
/**
* Same as `remove_instance_from_parent()` just shorter syntax.
* Removes the (three) instance of the object created by the component from it's parent.
*/
export const remove = remove_instance_from_parent
/** Returns the (three) instance of the object created by the component. */
export const get_instance = (): SpotLight => light
/** Returns the `animation` object. */
export const get_animation = (): any => ani.getAnimation()
/** Same as `get_animation()` just shorter syntax. Returns the `animation` object. */
export const get_ani = get_animation
/** Starts the `animation` object. */
export const start_animation = (): void => ani.startAni()
/** Same as `start_animation()` just shorter syntax. Starts the `animation` object. */
export const start_ani = start_animation
/** Sets `focus()` on the component / it's shadow dom element. */
export const focused = (): void => shadow_dom_el.focus()
/**
* Primarily for internal usage. Clears all references to the currently managed three.js instance.
* Called by `remove_instance(...)` / `clear_old_component()` if the instance has been
* assigned to some other component (_before_).
*/
export const clear = () => {
//console.warn(`CLEAR! -> ${name}`)
light = null
// IMPORTANT //
// has to be set to `null`, `undefined` would set `light_uuid` if a cleared component recevies a light
// we don't want that, beacuse then the `handle_instance_change` wouldn't be triggered!
light_uuid = null
}
/** **Completely replace** `onMount` -> any `onMount_inject_before` & `onMount_inject_after` will be ignored.
* _default verbosity will be gone!_ */
export let onMount_replace: (args?: any) => any = undefined
onMount(
onMount_replace
? async () => onMount_replace(_self)
: async () => {
if (verbose && log_lc && (log_lc.all || log_lc.om)) {
console.info(...c_lc(c_name, "onMount"))
}
if (verbose && log_mau) {
console.debug(
...c_mau(c_name, "onMount : light.", {
matrixAutoUpdate: light.matrixAutoUpdate,
matrixWorldNeedsUpdate: light.matrixWorldNeedsUpdate
})
)
}
}
)
/** **Inject** functionality **before** component's existing `onDestroy` logic.
* _default verbosity not affected._ */
export let onDestroy_inject_before: (args?: any) => any = undefined
/** **Inject** functionality **after** component's existing `onDestroy` logic.
* _default verbosity not affected._ */
export let onDestroy_inject_after: (args?: any) => any = undefined
/** **Completely replace** `onDestroy` -> any `onDestroy_inject_before` & `onDestroy_inject_after` will be ignored.
* _default verbosity will be gone!_ */
export let onDestroy_replace: (args?: any) => any = undefined
onDestroy(
onDestroy_replace
? async () => onDestroy_replace(_self)
: async () => {
if (verbose && log_lc && (log_lc.all || log_lc.od)) {
console.info(...c_lc(c_name, "onDestroy"))
}
if (verbose && log_mau) {
console.debug(
...c_mau(c_name, "onDestroy : light.", {
matrixAutoUpdate: light.matrixAutoUpdate,
matrixWorldNeedsUpdate: light.matrixWorldNeedsUpdate
})
)
}
if (onDestroy_inject_before) onDestroy_inject_before()
remove_helper()
if (ani) ani.destroyAnimation()
remove_instance_from_parent()
if (onDestroy_inject_after) onDestroy_inject_after()
}
)
/** **Completely replace** `beforeUpdate` -> any `beforeUpdate_inject_before` & `beforeUpdate_inject_after` will be ignored.
* _default verbosity will be gone!_ */
export let beforeUpdate_replace: (args?: any) => any = undefined
beforeUpdate(
beforeUpdate_replace
? async () => beforeUpdate_replace(_self)
: async () => {
if (verbose && log_lc && (log_lc.all || log_lc.bu)) {
console.info(...c_lc(c_name, "beforeUpdate"))
}
if (verbose && log_mau) {
console.debug(
...c_mau(c_name, "beforeUpdate : light.", {
matrixAutoUpdate: light.matrixAutoUpdate,
matrixWorldNeedsUpdate: light.matrixWorldNeedsUpdate
})
)
}
}
)
/** **Inject** functionality **before** component's existing `afterUpdate` logic.
* _default verbosity not affected._ */
export let afterUpdate_inject_before: (args?: any) => any = undefined
/** **Inject** functionality **after** component's existing `afterUpdate` logic.
* _default verbosity not affected._ */
export let afterUpdate_inject_after: (args?: any) => any = undefined
/** **Completely replace** `afterUpdate` -> any `afterUpdate_inject_before` & `afterUpdate_inject_after` will be ignored.
* _default verbosity will be gone!_ */
export let afterUpdate_replace: (args?: any) => any = undefined
afterUpdate(
afterUpdate_replace
? async () => afterUpdate_replace(_self)
: async () => {
if (verbose && log_lc && (log_lc.all || log_lc.au)) {
console.info(...c_lc(c_name, "afterUpdate"))
}
if (verbose && log_mau) {
console.debug(
...c_mau(c_name, "afterUpdate : light.", {
matrixAutoUpdate: light.matrixAutoUpdate,
matrixWorldNeedsUpdate: light.matrixWorldNeedsUpdate
})
)
}
if (afterUpdate_inject_before) afterUpdate_inject_before()
// Update local matrix after all (props) changes (async microtasks) have been applied.
if (light && !light.matrixAutoUpdate) light.updateMatrix()
if (verbose && !light.matrixAutoUpdate && log_mau) {
console.debug(
...c_mau(c_name, "afterUpdate : light.", {
matrixAutoUpdate: light.matrixAutoUpdate,
matrixWorldNeedsUpdate: light.matrixWorldNeedsUpdate
})
)
}
if (helper && light.userData.helper) light.userData.helper.update()
if ($svelthreeStores[sti].rendererComponent?.mode === "auto") {
// prevent an additional component update by not accessing the `root_scene` prop directly.
root_scene_obj.value.userData.dirty = true
$svelthreeStores[sti].rendererComponent.schedule_render_auto(root_scene)
}
if (afterUpdate_inject_after) afterUpdate_inject_after()
}
)
</script>
<slot />
<SvelthreeLightWithShadow
{light}
{shadowMapSize}
{shadowBias}
{castShadow}
{shadowProps}
{shadowCameraProps}
{log_dev}
/>