|
| 1 | +/** |
| 2 | + Auto-generated by: angular-three-plugin:gltf<% if (size) { %> |
| 3 | + Size: <%= size %><% } %><% if (header) { %> |
| 4 | + <%= header %><% } %><% if (extras) { %> |
| 5 | + <%= extras %><% } %> |
| 6 | + */ |
| 7 | + |
| 8 | +import type * as THREE from 'three'; |
| 9 | +import { Group<%= threeImports %> } from 'three'; |
| 10 | +import { extend, type NgtThreeElements, NgtObjectEvents<% if (args) { %>, NgtArgs<% } %> } from 'angular-three'; |
| 11 | +import { Component, ChangeDetectionStrategy, CUSTOM_ELEMENTS_SCHEMA, input, viewChild, ElementRef, inject, effect<% if (animations.length) { %>, computed, model<% } %> } from '@angular/core'; |
| 12 | +import { injectGLTF } from 'angular-three-soba/loaders'; |
| 13 | +import type { GLTF } from 'three-stdlib';<% if (animations.length) { %> |
| 14 | +import { injectAnimations, type NgtsAnimationClips, type NgtsAnimationApi } from 'angular-three-soba/misc';<% } %><% if (perspective) { %> |
| 15 | +import { NgtsPerspectiveCamera } from 'angular-three-soba/cameras';<% } %><% if (orthographic) { %> |
| 16 | +import { NgtsOrthographicCamera } from 'angular-three-soba/cameras';<% } %> |
| 17 | +<% if (useImportAttribute) { %> |
| 18 | +// @ts-expect-error - import .glb/.gltf file |
| 19 | +import <%= gltfName %> from '.<%= gltfPath %>' with { loader: 'file' }; |
| 20 | +<% } %> |
| 21 | +<% if (preload) { %> |
| 22 | +injectGLTF(() => <% if (useImportAttribute) { %><%= gltfName %><% } else { %>'<%= gltfPath %>'<% } %>); |
| 23 | +<% } %> |
| 24 | +<% if (animations.length) { %> |
| 25 | +type ActionName = <% animations.map(clip => "\""+ clip.name + "\"").join(" | ") %>; |
| 26 | +type <%= gltfAnimationTypeName %> = NgtsAnimationClips<ActionName>; |
| 27 | +export type <%= gltfAnimationApiTypeName %> = Exclude<NgtsAnimationApi<<%= gltfAnimationTypeName %>>, { get isReady(): false }>; |
| 28 | +<% } %> |
| 29 | +export type <%= gltfResultTypeName %> = GLTF & { |
| 30 | + nodes: { |
| 31 | + <% meshes.map(({ name, type }) => "\'" + name + "\'" + ": THREE." + type).join(';\n') %> |
| 32 | + <% bones.map(({ name, type }) => "\'" + name + "\'" + ": THREE." + type).join(';\n') %> |
| 33 | + }; |
| 34 | + materials: { |
| 35 | + <% materials.map(({ name, type }) => "\'" + name + "\'" + ": THREE." + type).join(';\n') %> |
| 36 | + };<% if (animations.length) { %> |
| 37 | + animations: <%= gltfAnimationTypeName %>[];<% } %> |
| 38 | +}; |
| 39 | + |
| 40 | +@Component({ |
| 41 | + selector: '<%= selector %>', |
| 42 | + template: ` |
| 43 | + @if (gltf(); as gltf) { |
| 44 | + <ngt-group #model [parameters]="options()" [dispose]="null"> |
| 45 | + <%= scene %> |
| 46 | + |
| 47 | + <ng-content /> |
| 48 | + </ngt-group> |
| 49 | + } |
| 50 | + `, |
| 51 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 52 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 53 | + hostDirectives: [ |
| 54 | + { |
| 55 | + directive: NgtObjectEvents, |
| 56 | + outputs: ['click', 'dblclick', 'contextmenu', 'pointerup', 'pointerdown', 'pointerover', 'pointerout', 'pointerenter', 'pointerleave', 'pointermove', 'pointermissed', 'pointercancel', 'wheel'], |
| 57 | + }, |
| 58 | + ],<% if (angularImports.length) { %> |
| 59 | + imports: [<% angularImports.join(', ') %>]<% } %> |
| 60 | +}) |
| 61 | +export class <%= className %> { |
| 62 | + protected readonly Math = Math; |
| 63 | + |
| 64 | + options = input({} as Partial<NgtThreeElements['ngt-group']>);<% if (animations.length) { %> |
| 65 | + animations = model<<%= gltfAnimationApiTypeName %>>();<% } %> |
| 66 | + |
| 67 | + modelRef = viewChild<ElementRef<Group>>('model'); |
| 68 | + |
| 69 | + protected gltf = injectGLTF<<%= gltfResultTypeName %>>(() => ${options.importattribute && !url.startsWith("http") ? gltfName : `"${url}"`}${gltfOptions ? `, ${JSON.stringify(gltfOptions)}` : ""}); |
| 70 | + |
| 71 | + constructor() { |
| 72 | + extend({ Group${ngtTypesArr.length ? ", " + ngtTypesArr.join(", ") : ""} }); |
| 73 | + |
| 74 | + ${ |
| 75 | + hasAnimations |
| 76 | + ? ` |
| 77 | + const animations = injectAnimations(this.gltf, this.modelRef); |
| 78 | + effect(() => { |
| 79 | + if (animations.${useNewAnimationApi ? "isReady" : "ready()"}) { |
| 80 | + this.animations.set(animations); |
| 81 | + } |
| 82 | + }${options.ngVer < 19 ? ", { allowSignalWrites: true }" : ""}) |
| 83 | + ` |
| 84 | + : "" |
| 85 | + } |
| 86 | + |
| 87 | + const objectEvents = inject(NgtObjectEvents, { host: true }); |
| 88 | + effect(() => { |
| 89 | + const model = this.modelRef()?.nativeElement; |
| 90 | + if (!model) return; |
| 91 | + |
| 92 | + objectEvents.ngtObjectEvents.set(model); |
| 93 | + }${options.ngVer < 19 ? ", { allowSignalWrites: true }" : ""}); |
| 94 | + } |
| 95 | +} |
0 commit comments