@@ -5,7 +5,8 @@ function parse(fileName, gltf, options = {}) {
5
5
const url = fileName ;
6
6
const animations = gltf . animations ;
7
7
const hasAnimations = animations . length > 0 ;
8
- const selector = `app-${ options . selector ?? "model" } ` ;
8
+ const selector = options . selector ?? "app-model" ;
9
+ const types = new Set ( ) ;
9
10
10
11
// Collect all objects
11
12
const objects = [ ] ;
@@ -140,10 +141,17 @@ function parse(fileName, gltf, options = {}) {
140
141
141
142
function getType ( obj ) {
142
143
let type = obj . type . charAt ( 0 ) . toLowerCase ( ) + obj . type . slice ( 1 ) ;
144
+
143
145
// Turn object3d's into groups, it should be faster according to the threejs docs
144
- if ( type === "object3D" ) type = "group" ;
146
+ if ( type === "object3D" ) {
147
+ types . add ( "Group" ) ;
148
+ type = "group" ;
149
+ }
145
150
if ( type === "perspectiveCamera" ) type = "PerspectiveCamera" ;
146
151
if ( type === "orthographicCamera" ) type = "OrthographicCamera" ;
152
+
153
+ types . add ( obj . type ) ;
154
+
147
155
return type ;
148
156
}
149
157
@@ -422,6 +430,14 @@ function parse(fileName, gltf, options = {}) {
422
430
return "ngt-object3D" ;
423
431
}
424
432
433
+ if ( type === "PerspectiveCamera" ) {
434
+ return `ngts-perspective-camera` ;
435
+ }
436
+
437
+ if ( type === "OrthographicCamera" ) {
438
+ return `ngts-orthographic-camera` ;
439
+ }
440
+
425
441
const kebabType = type . replace ( / ( [ A - Z ] ) / g, "-$1" ) . toLowerCase ( ) ;
426
442
return `ngt-${ kebabType } ` ;
427
443
}
@@ -544,16 +560,37 @@ function parse(fileName, gltf, options = {}) {
544
560
}
545
561
: undefined ;
546
562
563
+ const typesArr = Array . from ( types ) . filter (
564
+ ( t ) =>
565
+ t !== "Group" && t !== "PerspectiveCamera" && t !== "OrthographicCamera" ,
566
+ ) ;
567
+
547
568
const imports = `
548
- import type * as THREE from 'three'
549
- import { Group } from 'three'
550
- import { NgtGroup, NgtObjectEvents${ hasArgs ? ", NgtArgs" : "" } } from 'angular-three';
569
+ import type * as THREE from 'three';
570
+ import { Group${ typesArr . length ? ", " + typesArr . join ( ", " ) : "" } } from 'three';
571
+ import { extend, NgtGroup, NgtObjectEvents${ hasArgs ? ", NgtArgs" : "" } } from 'angular-three';
551
572
import { Component, ChangeDetectionStrategy, CUSTOM_ELEMENTS_SCHEMA, Signal, input, viewChild, ElementRef, inject, effect${ hasAnimations ? ", computed, model" : "" } } from '@angular/core';
552
573
import { injectGLTF } from 'angular-three-soba/loaders';
553
574
import { GLTF } from 'three-stdlib';
554
575
${ hasAnimations ? "import { injectAnimations } from 'angular-three-soba/misc';" : "" }
576
+ ${ types . has ( "PerspectiveCamera" ) ? "import { NgtsPerspectiveCamera } from 'angular-three-soba/cameras';" : "" }
577
+ ${ types . has ( "OrthographicCamera" ) ? "import { NgtsOrthographicCamera } from 'angular-three-soba/cameras';" : "" }
555
578
` ;
556
579
580
+ const angularImports = [ ] ;
581
+
582
+ if ( hasArgs ) {
583
+ angularImports . push ( "NgtArgs" ) ;
584
+ }
585
+
586
+ if ( types . has ( "PerspectiveCamera" ) ) {
587
+ angularImports . push ( "NgtsPerspectiveCamera" ) ;
588
+ }
589
+
590
+ if ( types . has ( "OrthographicCamera" ) ) {
591
+ angularImports . push ( "NgtsOrthographicCamera" ) ;
592
+ }
593
+
557
594
// Output
558
595
return `
559
596
/**${
@@ -580,9 +617,9 @@ ${printTypes(objects, animations)}
580
617
</ngt-group>
581
618
}
582
619
\`,${
583
- hasArgs
620
+ angularImports . length
584
621
? `
585
- imports: [NgtArgs ],`
622
+ imports: [${ angularImports . join ( ", " ) } ],`
586
623
: ""
587
624
}
588
625
hostDirectives: [
@@ -632,6 +669,8 @@ export class Model {
632
669
private objectEvents = inject(NgtObjectEvents, { host: true });
633
670
634
671
constructor() {
672
+ extend({ Group${ typesArr . length ? ", " + typesArr . join ( ", " ) : "" } });
673
+
635
674
${
636
675
hasAnimations
637
676
? `
0 commit comments