Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
feat(core): clean up ngtObjectPassThrough
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Jul 23, 2022
1 parent a2486fe commit 35a77f6
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 351 deletions.
4 changes: 2 additions & 2 deletions apps/sandbox/src/app/reuse-gltf/reuse-gltf.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, Inject, NgModule, NgZone, Optional, SkipSelf } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Observable } from 'rxjs';
import { GLTF } from 'three-stdlib';
import * as THREE from 'three';
import { GLTF } from 'three-stdlib';

@Component({
selector: 'sandbox-reuse-gltf',
Expand Down Expand Up @@ -70,7 +70,7 @@ interface ShoeGLTF extends GLTF {
selector: 'sandbox-shoe',
template: `
<ng-container *ngIf="shoe$ | async as shoe">
<ngt-group [ngtObjectInputs]="this" [ngtObjectOutputs]="this">
<ngt-group [ngtObjectPassThrough]="this">
<ngt-mesh castShadow receiveShadow [geometry]="shoe.nodes.shoe.geometry" [material]="shoe.materials.laces">
<ngt-value [attach]="['material', 'envMapIntensity']" [value]="0.8"></ngt-value>
</ngt-mesh>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { startWithUndefined } from '@angular-three/core';
import { createPassThroughInput } from '@angular-three/core';
import { Directive, Input, NgModule, Optional, Self } from '@angular/core';
import { merge, takeUntil } from 'rxjs';
import { NgtSpotLight } from '../spot-light/spot-light';

@Directive({
Expand All @@ -9,68 +8,23 @@ import { NgtSpotLight } from '../spot-light/spot-light';
})
export class NgtSpotLightPassThrough {
@Input() set ngtSpotLightPassThrough(wrapper: unknown) {
this.assertWrapper(wrapper);
NgtSpotLightPassThrough.assertWrapper(wrapper);

merge(
this.host.select((s) => s['distance']).pipe(startWithUndefined()),
wrapper.select((s) => s['distance']).pipe(startWithUndefined())
)
.pipe(takeUntil(wrapper.destroy$))
.subscribe((distance) => {
this.host.distance = distance;
});
const passThroughInput = createPassThroughInput(wrapper, this.host);

merge(
this.host.select((s) => s['angle']).pipe(startWithUndefined()),
wrapper.select((s) => s['angle']).pipe(startWithUndefined())
)
.pipe(takeUntil(wrapper.destroy$))
.subscribe((angle) => {
this.host.angle = angle;
});

merge(
this.host.select((s) => s['penumbra']).pipe(startWithUndefined()),
wrapper.select((s) => s['penumbra']).pipe(startWithUndefined())
)
.pipe(takeUntil(wrapper.destroy$))
.subscribe((penumbra) => {
this.host.penumbra = penumbra;
});

merge(
this.host.select((s) => s['decay']).pipe(startWithUndefined()),
wrapper.select((s) => s['decay']).pipe(startWithUndefined())
)
.pipe(takeUntil(wrapper.destroy$))
.subscribe((decay) => {
this.host.decay = decay;
});

merge(
this.host.select((s) => s['target']).pipe(startWithUndefined()),
wrapper.select((s) => s['target']).pipe(startWithUndefined())
)
.pipe(takeUntil(wrapper.destroy$))
.subscribe((target) => {
this.host.target = target;
});

merge(
this.host.select((s) => s['power']).pipe(startWithUndefined()),
wrapper.select((s) => s['power']).pipe(startWithUndefined())
)
.pipe(takeUntil(wrapper.destroy$))
.subscribe((power) => {
this.host.power = power;
});
passThroughInput('distance', true, true);
passThroughInput('angle', true, true);
passThroughInput('penumbra', true, true);
passThroughInput('decay', true, true);
passThroughInput('target', true, true);
passThroughInput('power', true, true);
}

constructor(@Self() @Optional() private host: NgtSpotLight) {
if (!host) return;
}

private assertWrapper(wrapper: unknown): asserts wrapper is NgtSpotLight {
private static assertWrapper(wrapper: unknown): asserts wrapper is NgtSpotLight {
if (!wrapper || !(wrapper instanceof NgtSpotLight)) {
throw new Error('ngtSpotLightPassThrough wrapper is not a NgtSpotLight');
}
Expand Down
1 change: 1 addition & 0 deletions libs/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ export * from './lib/utils/is';
export * from './lib/utils/loop';
export * from './lib/utils/make';
export * from './lib/utils/shader-material';
export * from './lib/utils/pass-through';
Loading

0 comments on commit 35a77f6

Please sign in to comment.