|
| 1 | +import { NgIf } from '@angular/common'; |
| 2 | +import { CUSTOM_ELEMENTS_SCHEMA, Component, Input } from '@angular/core'; |
| 3 | +import { NgtArgs } from 'angular-three'; |
| 4 | +import { NgtsOrbitControls } from 'angular-three-soba/controls'; |
| 5 | +import { NgtsHtml } from 'angular-three-soba/misc'; |
| 6 | +import { NgtsBBAnchor, NgtsBBAnchorState } from 'angular-three-soba/staging'; |
| 7 | +import { NgtsSobaContent } from 'angular-three-soba/utils'; |
| 8 | +import { makeCanvasOptions, makeDecorators, makeStoryObject, number } from '../setup-canvas'; |
| 9 | + |
| 10 | +@Component({ |
| 11 | + selector: 'bb-anchor-scene', |
| 12 | + standalone: true, |
| 13 | + template: ` |
| 14 | + <ngts-orbit-controls [autoRotate]="true" /> |
| 15 | + <ngt-mesh #mesh> |
| 16 | + <ngt-icosahedron-geometry /> |
| 17 | + <ngt-mesh-basic-material color="hotpink" [wireframe]="true" /> |
| 18 | + <ngts-bb-anchor [anchor]="anchor"> |
| 19 | + <ng-content /> |
| 20 | + </ngts-bb-anchor> |
| 21 | + </ngt-mesh> |
| 22 | + <ng-container *ngIf="drawBoundingBox"> |
| 23 | + <ngt-box-helper *args="[mesh, 'cyan']" /> |
| 24 | + </ng-container> |
| 25 | + `, |
| 26 | + imports: [NgtsOrbitControls, NgtsBBAnchor, NgIf, NgtArgs], |
| 27 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 28 | +}) |
| 29 | +class BBAnchorScene { |
| 30 | + @Input() anchor: NgtsBBAnchorState['anchor'] = [1, 1, 1]; |
| 31 | + @Input() drawBoundingBox = true; |
| 32 | +} |
| 33 | + |
| 34 | +@Component({ |
| 35 | + standalone: true, |
| 36 | + template: ` |
| 37 | + <bb-anchor-scene [anchor]="[anchorX, anchorY, anchorZ]" [drawBoundingBox]="drawBoundingBox"> |
| 38 | + <ngt-mesh [position]="-0.1"> |
| 39 | + <ngt-sphere-geometry *args="[0.25]" /> |
| 40 | + <ngt-mesh-basic-material color="lime" /> |
| 41 | + </ngt-mesh> |
| 42 | + </bb-anchor-scene> |
| 43 | + `, |
| 44 | + imports: [NgtArgs, BBAnchorScene], |
| 45 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 46 | +}) |
| 47 | +class MeshBBAnchorStory { |
| 48 | + @Input() anchorX = 1; |
| 49 | + @Input() anchorY = 1; |
| 50 | + @Input() anchorZ = 1; |
| 51 | + @Input() drawBoundingBox = true; |
| 52 | +} |
| 53 | + |
| 54 | +@Component({ |
| 55 | + standalone: true, |
| 56 | + template: ` |
| 57 | + <bb-anchor-scene [anchor]="[anchorX, anchorY, anchorZ]" [drawBoundingBox]="drawBoundingBox"> |
| 58 | + <ngts-html [center]="true" [style]="{ color: 'white', whiteSpace: 'nowrap' }"> |
| 59 | + <ng-container *ngtsSobaContent>Html element</ng-container> |
| 60 | + </ngts-html> |
| 61 | + </bb-anchor-scene> |
| 62 | + `, |
| 63 | + imports: [NgtsHtml, NgtsSobaContent, BBAnchorScene], |
| 64 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 65 | +}) |
| 66 | +class HtmlBBAnchorStory { |
| 67 | + @Input() anchorX = 1; |
| 68 | + @Input() anchorY = 1; |
| 69 | + @Input() anchorZ = 1; |
| 70 | + @Input() drawBoundingBox = true; |
| 71 | +} |
| 72 | + |
| 73 | +export default { |
| 74 | + title: 'Staging/BBAnchor', |
| 75 | + decorators: makeDecorators(), |
| 76 | +}; |
| 77 | + |
| 78 | +const canvasOptions = makeCanvasOptions({ |
| 79 | + camera: { position: [2, 2, 2] }, |
| 80 | + controls: false, |
| 81 | +}); |
| 82 | + |
| 83 | +const argsOptions = { |
| 84 | + drawBoundingBox: true, |
| 85 | + anchorX: number(1, { range: true, min: -1, max: 1, step: 0.1 }), |
| 86 | + anchorY: number(1, { range: true, min: -1, max: 1, step: 0.1 }), |
| 87 | + anchorZ: number(1, { range: true, min: -1, max: 1, step: 0.1 }), |
| 88 | +}; |
| 89 | + |
| 90 | +export const WithHTML = makeStoryObject(HtmlBBAnchorStory, { canvasOptions, argsOptions }); |
| 91 | +export const WithMesh = makeStoryObject(MeshBBAnchorStory, { canvasOptions, argsOptions }); |
0 commit comments