Skip to content

Commit d418747

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
feat(soba): migrate stage
1 parent b0080e0 commit d418747

File tree

4 files changed

+377
-9
lines changed

4 files changed

+377
-9
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Component, CUSTOM_ELEMENTS_SCHEMA, Input } from '@angular/core';
2+
import { Meta, moduleMetadata } from '@storybook/angular';
3+
import { NgtArgs } from 'angular-three';
4+
import { ngtsEnvironmentPresetsObj, NgtsStage } from 'angular-three-soba/staging';
5+
import { makeStoryObject, number, select, StorybookSetup } from '../setup-canvas';
6+
7+
enum presets {
8+
rembrant = 'rembrandt',
9+
portrait = 'portrait',
10+
upfront = 'upfront',
11+
soft = 'soft',
12+
}
13+
14+
@Component({
15+
standalone: true,
16+
template: `
17+
<ngt-color attach="background" *args="['white']" />
18+
<ngts-stage [intensity]="intensity" [environment]="envPreset" [preset]="preset">
19+
<ngt-mesh>
20+
<ngt-sphere-geometry *args="[1, 64, 64]" />
21+
<ngt-mesh-standard-material roughness="0" color="royalblue" />
22+
</ngt-mesh>
23+
</ngts-stage>
24+
`,
25+
imports: [NgtsStage, NgtArgs],
26+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
27+
})
28+
class DefaultStageStory {
29+
@Input() intensity = 1;
30+
@Input() envPreset = Object.keys(ngtsEnvironmentPresetsObj)[0];
31+
@Input() preset = Object.keys(presets)[0];
32+
}
33+
34+
export default {
35+
title: 'Staging/Stage',
36+
decorators: [moduleMetadata({ imports: [StorybookSetup] })],
37+
} as Meta;
38+
39+
export const Default = makeStoryObject(DefaultStageStory, {
40+
canvasOptions: { camera: { position: [0, 0, 3] } },
41+
argsOptions: {
42+
intensity: number(1),
43+
envPreset: select(Object.keys(ngtsEnvironmentPresetsObj)[0], {
44+
options: Object.keys(ngtsEnvironmentPresetsObj),
45+
}),
46+
preset: select(Object.keys(presets)[0], { options: Object.keys(presets) }),
47+
},
48+
});

libs/soba/staging/src/contact-shadows/contact-shadows.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ declare global {
4242
template: `
4343
<ngt-group ngtCompound [ref]="contactShadowsRef" [rotation]="[Math.PI / 2, 0, 0]">
4444
<ngt-mesh
45-
[renderOrder]="shadowRenderOrder()"
45+
[renderOrder]="shadowRenderOrder() ?? 0"
4646
[geometry]="contactShadows().planeGeometry"
4747
[scale]="[1, -1, 1]"
4848
[rotation]="[-Math.PI / 2, 0, 0]"
4949
>
5050
<ngt-mesh-basic-material
5151
[map]="contactShadows().renderTarget.texture"
5252
[transparent]="true"
53-
[opacity]="shadowOpacity()"
54-
[depthWrite]="shadowDepthWrite()"
53+
[opacity]="shadowOpacity() ?? 1"
54+
[depthWrite]="shadowDepthWrite() ?? false"
5555
>
5656
<ngt-value [rawValue]="encoding()" attach="map.encoding" />
5757
</ngt-mesh-basic-material>
@@ -127,11 +127,11 @@ export class NgtsContactShadows extends NgtSignalStore<NgtsContactShadowsState>
127127

128128
readonly #scaledWidth = computed(() => {
129129
const scale = this.#scale();
130-
return this.#width() * (Array.isArray(scale) ? scale[0] : scale || 1);
130+
return (this.#width() || 1) * (Array.isArray(scale) ? scale[0] : scale || 1);
131131
});
132132
readonly #scaledHeight = computed(() => {
133133
const scale = this.#scale();
134-
return this.#height() * (Array.isArray(scale) ? scale[1] : scale || 1);
134+
return (this.#height() || 1) * (Array.isArray(scale) ? scale[1] : scale || 1);
135135
});
136136

137137
readonly encoding = this.#store.select('gl', 'outputEncoding');
@@ -145,9 +145,10 @@ export class NgtsContactShadows extends NgtSignalStore<NgtsContactShadowsState>
145145
return [-width / 2, width / 2, height / 2, -height / 2, 0, this.#far()];
146146
});
147147
readonly contactShadows = computed(() => {
148-
const color = this.#color();
149-
const renderTarget = new THREE.WebGLRenderTarget(this.#resolution(), this.#resolution());
150-
const renderTargetBlur = new THREE.WebGLRenderTarget(this.#resolution(), this.#resolution());
148+
const color = this.#color() || '#000000';
149+
const resolution = this.#resolution() || 512;
150+
const renderTarget = new THREE.WebGLRenderTarget(resolution, resolution);
151+
const renderTargetBlur = new THREE.WebGLRenderTarget(resolution, resolution);
151152
renderTargetBlur.texture.generateMipmaps = renderTarget.texture.generateMipmaps = false;
152153
const planeGeometry = new THREE.PlaneGeometry(this.#scaledWidth(), this.#scaledHeight()).rotateX(Math.PI / 2);
153154
const blurPlane = new Mesh(planeGeometry);
@@ -205,7 +206,7 @@ export class NgtsContactShadows extends NgtSignalStore<NgtsContactShadowsState>
205206
}
206207

207208
#onBeforeRender(count: number, { scene, gl }: NgtRenderState) {
208-
const { frames, blur, smooth } = this.get();
209+
const { frames = Infinity, blur = 1, smooth = true } = this.get();
209210
const { depthMaterial, renderTarget } = this.contactShadows();
210211
const shadowCamera = this.shadowCameraRef.nativeElement;
211212
if (shadowCamera && (frames === Infinity || count < frames)) {

libs/soba/staging/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export * from './sky/sky';
1212
export * from './sparkles/sparkles';
1313
export * from './spot-light/spot-light';
1414
export { NgtsSpotLightShadow } from './spot-light/spot-light-shadow-mesh';
15+
export * from './stage/stage';
1516
export * from './stars/stars';

0 commit comments

Comments
 (0)