Skip to content

Commit d8242d4

Browse files
committed
fix: adjust
1 parent b38b4a5 commit d8242d4

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-three-gltf",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "GLTF to Angular Three converter",
55
"scripts": {
66
"cleanup": "rimraf node_modules"

src/utils/parser.js

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ function parse(fileName, gltf, options = {}) {
55
const url = fileName;
66
const animations = gltf.animations;
77
const hasAnimations = animations.length > 0;
8-
const selector = `app-${options.selector ?? "model"}`;
8+
const selector = options.selector ?? "app-model";
9+
const types = new Set();
910

1011
// Collect all objects
1112
const objects = [];
@@ -140,10 +141,17 @@ function parse(fileName, gltf, options = {}) {
140141

141142
function getType(obj) {
142143
let type = obj.type.charAt(0).toLowerCase() + obj.type.slice(1);
144+
143145
// 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+
}
145150
if (type === "perspectiveCamera") type = "PerspectiveCamera";
146151
if (type === "orthographicCamera") type = "OrthographicCamera";
152+
153+
types.add(obj.type);
154+
147155
return type;
148156
}
149157

@@ -422,6 +430,14 @@ function parse(fileName, gltf, options = {}) {
422430
return "ngt-object3D";
423431
}
424432

433+
if (type === "PerspectiveCamera") {
434+
return `ngts-perspective-camera`;
435+
}
436+
437+
if (type === "OrthographicCamera") {
438+
return `ngts-orthographic-camera`;
439+
}
440+
425441
const kebabType = type.replace(/([A-Z])/g, "-$1").toLowerCase();
426442
return `ngt-${kebabType}`;
427443
}
@@ -544,16 +560,37 @@ function parse(fileName, gltf, options = {}) {
544560
}
545561
: undefined;
546562

563+
const typesArr = Array.from(types).filter(
564+
(t) =>
565+
t !== "Group" && t !== "PerspectiveCamera" && t !== "OrthographicCamera",
566+
);
567+
547568
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';
551572
import { Component, ChangeDetectionStrategy, CUSTOM_ELEMENTS_SCHEMA, Signal, input, viewChild, ElementRef, inject, effect${hasAnimations ? ", computed, model" : ""} } from '@angular/core';
552573
import { injectGLTF } from 'angular-three-soba/loaders';
553574
import { GLTF } from 'three-stdlib';
554575
${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';" : ""}
555578
`;
556579

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+
557594
// Output
558595
return `
559596
/**${
@@ -580,9 +617,9 @@ ${printTypes(objects, animations)}
580617
</ngt-group>
581618
}
582619
\`,${
583-
hasArgs
620+
angularImports.length
584621
? `
585-
imports: [NgtArgs],`
622+
imports: [${angularImports.join(", ")}],`
586623
: ""
587624
}
588625
hostDirectives: [
@@ -632,6 +669,8 @@ export class Model {
632669
private objectEvents = inject(NgtObjectEvents, { host: true });
633670
634671
constructor() {
672+
extend({ Group${typesArr.length ? ", " + typesArr.join(", ") : ""} });
673+
635674
${
636675
hasAnimations
637676
? `

0 commit comments

Comments
 (0)