angular-three-plugin 4.0.0-next.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +11 -0
  2. package/generators.json +46 -0
  3. package/migrations.json +16 -0
  4. package/package.json +55 -0
  5. package/src/generators/aux/aux.d.ts +3 -0
  6. package/src/generators/aux/aux.js +60 -0
  7. package/src/generators/aux/aux.js.map +1 -0
  8. package/src/generators/aux/compat.d.ts +2 -0
  9. package/src/generators/aux/compat.js +7 -0
  10. package/src/generators/aux/compat.js.map +1 -0
  11. package/src/generators/aux/schema.json +7 -0
  12. package/src/generators/gltf/compat.d.ts +2 -0
  13. package/src/generators/gltf/compat.js +7 -0
  14. package/src/generators/gltf/compat.js.map +1 -0
  15. package/src/generators/gltf/files/__fileName__.ts__tmpl__ +93 -0
  16. package/src/generators/gltf/generate-ngt.d.ts +32 -0
  17. package/src/generators/gltf/generate-ngt.js +199 -0
  18. package/src/generators/gltf/generate-ngt.js.map +1 -0
  19. package/src/generators/gltf/gltf.d.ts +32 -0
  20. package/src/generators/gltf/gltf.js +131 -0
  21. package/src/generators/gltf/gltf.js.map +1 -0
  22. package/src/generators/gltf/schema.json +176 -0
  23. package/src/generators/index.d.ts +2 -0
  24. package/src/generators/index.js +9 -0
  25. package/src/generators/index.js.map +1 -0
  26. package/src/generators/init/compat.d.ts +2 -0
  27. package/src/generators/init/compat.js +7 -0
  28. package/src/generators/init/compat.js.map +1 -0
  29. package/src/generators/init/files/scene-graph.ts__tmpl__ +29 -0
  30. package/src/generators/init/init.d.ts +6 -0
  31. package/src/generators/init/init.js +238 -0
  32. package/src/generators/init/init.js.map +1 -0
  33. package/src/generators/init/schema.json +37 -0
  34. package/src/generators/init/utils.d.ts +5 -0
  35. package/src/generators/init/utils.js +38 -0
  36. package/src/generators/init/utils.js.map +1 -0
  37. package/src/generators/migrate-tweakpane/compat.d.ts +2 -0
  38. package/src/generators/migrate-tweakpane/compat.js +7 -0
  39. package/src/generators/migrate-tweakpane/compat.js.map +1 -0
  40. package/src/generators/migrate-tweakpane/migrate-tweakpane.d.ts +6 -0
  41. package/src/generators/migrate-tweakpane/migrate-tweakpane.js +35 -0
  42. package/src/generators/migrate-tweakpane/migrate-tweakpane.js.map +1 -0
  43. package/src/generators/migrate-tweakpane/schema.json +14 -0
  44. package/src/index.d.ts +1 -0
  45. package/src/index.js +3 -0
  46. package/src/index.js.map +1 -0
  47. package/src/migrations/migrate-tweakpane/compat.d.ts +2 -0
  48. package/src/migrations/migrate-tweakpane/compat.js +7 -0
  49. package/src/migrations/migrate-tweakpane/compat.js.map +1 -0
  50. package/src/migrations/migrate-tweakpane/migrate-tweakpane.d.ts +2 -0
  51. package/src/migrations/migrate-tweakpane/migrate-tweakpane.js +9 -0
  52. package/src/migrations/migrate-tweakpane/migrate-tweakpane.js.map +1 -0
  53. package/src/utils.d.ts +2 -0
  54. package/src/utils.js +33 -0
  55. package/src/utils.js.map +1 -0
  56. package/src/versions.d.ts +5 -0
  57. package/src/versions.js +39 -0
  58. package/src/versions.js.map +1 -0
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # plugin
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build plugin` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test plugin` to execute the unit tests via [Jest](https://jestjs.io).
@@ -0,0 +1,46 @@
1
+ {
2
+ "generators": {
3
+ "init": {
4
+ "factory": "./src/generators/init/init",
5
+ "schema": "./src/generators/init/schema.json",
6
+ "description": "init generator"
7
+ },
8
+ "gltf": {
9
+ "factory": "./src/generators/gltf/gltf",
10
+ "schema": "./src/generators/gltf/schema.json",
11
+ "description": "gltf generator"
12
+ },
13
+ "aux": {
14
+ "factory": "./src/generators/aux/aux",
15
+ "schema": "./src/generators/aux/schema.json",
16
+ "description": "aux generator"
17
+ },
18
+ "migrate-tweakpane": {
19
+ "factory": "./src/generators/migrate-tweakpane/migrate-tweakpane",
20
+ "schema": "./src/generators/migrate-tweakpane/schema.json",
21
+ "description": "Migration tweakpane"
22
+ }
23
+ },
24
+ "schematics": {
25
+ "init": {
26
+ "factory": "./src/generators/init/compat",
27
+ "schema": "./src/generators/init/schema.json",
28
+ "description": "init generator"
29
+ },
30
+ "gltf": {
31
+ "factory": "./src/generators/gltf/compat",
32
+ "schema": "./src/generators/gltf/schema.json",
33
+ "description": "gltf generator"
34
+ },
35
+ "aux": {
36
+ "factory": "./src/generators/aux/compat",
37
+ "schema": "./src/generators/aux/schema.json",
38
+ "description": "aux generator"
39
+ },
40
+ "migrate-tweakpane": {
41
+ "factory": "./src/generators/migrate-tweakpane/compat",
42
+ "schema": "./src/generators/migrate-tweakpane/schema.json",
43
+ "description": "Migration tweakpane"
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "generators": {
3
+ "migrate-tweakpane": {
4
+ "version": "4.0.0",
5
+ "description": "Migration for v4.0.0",
6
+ "implementation": "./src/migrations/migrate-tweakpane/migrate-tweakpane"
7
+ }
8
+ },
9
+ "schematics": {
10
+ "migrate-tweakpane": {
11
+ "version": "4.0.0",
12
+ "description": "Migration for v4.0.0",
13
+ "implementation": "./src/migrations/migrate-tweakpane/compat"
14
+ }
15
+ }
16
+ }
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "angular-three-plugin",
3
+ "version": "4.0.0-next.100",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "type": "commonjs",
8
+ "main": "./src/index.js",
9
+ "types": "./src/index.d.ts",
10
+ "exports": {
11
+ "./package.json": "./package.json",
12
+ ".": {
13
+ "types": "./src/index.d.ts",
14
+ "default": "./src/index.js"
15
+ },
16
+ "./generators": {
17
+ "types": "./src/generators/index.d.ts",
18
+ "default": "./src/generators/index.js"
19
+ }
20
+ },
21
+ "dependencies": {
22
+ "@nx/devkit": "^20.0.0",
23
+ "@rosskevin/gltfjsx": "^7.0.0",
24
+ "node-three-gltf": "^2.0.0",
25
+ "nx": "^20.0.0",
26
+ "ts-morph": "^25.0.0",
27
+ "tslib": "^2.3.0"
28
+ },
29
+ "generators": "./generators.json",
30
+ "schematics": "./generators.json",
31
+ "nx-migrations": {
32
+ "migrations": "./migrations.json",
33
+ "packageGroup": [
34
+ "angular-three-plugin",
35
+ "angular-three-soba",
36
+ "angular-three-postprocessing",
37
+ "angular-three-cannon",
38
+ "angular-three-rapier",
39
+ "angular-three-tweakpane",
40
+ "angular-three-theatre"
41
+ ]
42
+ },
43
+ "ng-update": {
44
+ "migrations": "./migrations.json",
45
+ "packageGroup": [
46
+ "angular-three-plugin",
47
+ "angular-three-soba",
48
+ "angular-three-postprocessing",
49
+ "angular-three-cannon",
50
+ "angular-three-rapier",
51
+ "angular-three-tweakpane",
52
+ "angular-three-theatre"
53
+ ]
54
+ }
55
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function auxGenerator(tree: Tree): Promise<() => void>;
3
+ export default auxGenerator;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.auxGenerator = auxGenerator;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const enquirer_1 = require("enquirer");
6
+ const utils_1 = require("../../utils");
7
+ const versions_1 = require("../../versions");
8
+ async function auxGenerator(tree) {
9
+ devkit_1.logger.info('[NGT] Initialize auxiliary packages');
10
+ const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
11
+ if (!packageJson) {
12
+ devkit_1.logger.warn(`[NGT] PackageJson not found in: ${tree.root}`);
13
+ return;
14
+ }
15
+ const ngtVersion = packageJson['dependencies']?.['angular-three'] || packageJson['devDependencies']?.['angular-three'];
16
+ if (!ngtVersion) {
17
+ devkit_1.logger.warn(`[NGT] angular-three is not installed.`);
18
+ return;
19
+ }
20
+ const { packages } = await (0, enquirer_1.prompt)({
21
+ type: 'multiselect',
22
+ name: 'packages',
23
+ message: 'Which packages to add?',
24
+ choices: [
25
+ 'angular-three-soba',
26
+ 'angular-three-rapier',
27
+ 'angular-three-postprocessing',
28
+ 'angular-three-cannon',
29
+ 'angular-three-tweakpane',
30
+ ],
31
+ });
32
+ const packagesToAdd = {};
33
+ for (const pkg of packages) {
34
+ const exist = packageJson['dependencies']?.[pkg] || packageJson['devDependencies']?.[pkg];
35
+ if (exist) {
36
+ devkit_1.logger.warn(`[NGT] ${pkg} is already installed. Skipping`);
37
+ continue;
38
+ }
39
+ packagesToAdd[pkg] = ngtVersion;
40
+ if (versions_1.PEER_DEPENDENCIES[pkg]) {
41
+ for (const depName in versions_1.PEER_DEPENDENCIES[pkg]) {
42
+ packagesToAdd[depName] = versions_1.PEER_DEPENDENCIES[pkg][depName];
43
+ }
44
+ }
45
+ if (pkg === 'angular-three-soba') {
46
+ (0, utils_1.addMetadataJson)(tree, 'angular-three-soba/metadata.json');
47
+ }
48
+ }
49
+ if (Object.keys(packagesToAdd).length === 0) {
50
+ console.warn(`[NGT] No packages to add`);
51
+ return;
52
+ }
53
+ (0, devkit_1.addDependenciesToPackageJson)(tree, packagesToAdd, {});
54
+ await (0, devkit_1.formatFiles)(tree);
55
+ return () => {
56
+ (0, devkit_1.installPackagesTask)(tree);
57
+ };
58
+ }
59
+ exports.default = auxGenerator;
60
+ //# sourceMappingURL=aux.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aux.js","sourceRoot":"","sources":["../../../../../../libs/plugin/src/generators/aux/aux.ts"],"names":[],"mappings":";;AAKA,oCAgEC;AArED,uCAAoH;AACpH,uCAAkC;AAClC,uCAA8C;AAC9C,6CAAmD;AAE5C,KAAK,UAAU,YAAY,CAAC,IAAU;IAC5C,eAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;IAEnD,MAAM,WAAW,GAAG,IAAA,iBAAQ,EAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IACnD,IAAI,CAAC,WAAW,EAAE,CAAC;QAClB,eAAM,CAAC,IAAI,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AClC,IAAA,uBAAe,EAAC,IAAI,EAAE,kCAAkC,CAAC,CAAC;QAC3D,CAAC;IACF,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7C,OAAO,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QACzC,OAAO;IACR,CAAC;IAED,IAAA,qCAA4B,EAAC,IAAI,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC;IAEtD,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAExB,OAAO,GAAG,EAAE;QACX,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC;AACH,CAAC;AAED,kBAAe,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (generatorOptions: any) => (tree: any, context: any) => Promise<any>;
2
+ export default _default;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const devkit_1 = require("@nx/devkit");
5
+ const aux_1 = tslib_1.__importDefault(require("./aux"));
6
+ exports.default = (0, devkit_1.convertNxGenerator)(aux_1.default);
7
+ //# sourceMappingURL=compat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compat.js","sourceRoot":"","sources":["../../../../../../libs/plugin/src/generators/aux/compat.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAChD,wDAAiC;AAEjC,kBAAe,IAAA,2BAAkB,EAAC,aAAY,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ {
2
+ "cli": "nx",
3
+ "$id": "Init",
4
+ "title": "Init aux package",
5
+ "type": "object",
6
+ "properties": {}
7
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: (generatorOptions: import("./gltf").GltfGeneratorSchema) => (tree: any, context: any) => Promise<any>;
2
+ export default _default;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const devkit_1 = require("@nx/devkit");
5
+ const gltf_1 = tslib_1.__importDefault(require("./gltf"));
6
+ exports.default = (0, devkit_1.convertNxGenerator)(gltf_1.default);
7
+ //# sourceMappingURL=compat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compat.js","sourceRoot":"","sources":["../../../../../../libs/plugin/src/generators/gltf/compat.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAChD,0DAAmC;AAEnC,kBAAe,IAAA,2BAAkB,EAAC,cAAa,CAAC,CAAC"}
@@ -0,0 +1,93 @@
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) { %>, 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.preload(() => <% 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
+ <%- meshesTypes %>
32
+ <%- bonesTypes %>
33
+ };
34
+ materials: {
35
+ <%- materialsTypes %>
36
+ };<% if (animations.length) { %>
37
+ animations: <%= gltfAnimationTypeName %>[];<% } %>
38
+ };
39
+
40
+ @Component({
41
+ selector: '<%= selector %>',
42
+ template: `
43
+ @if (gltf(); as gltf) {
44
+ @let nodes = gltf.nodes;
45
+ @let materials = gltf.materials;
46
+
47
+ <ngt-group #model [parameters]="options()" [dispose]="null">
48
+ <%- scene %>
49
+
50
+ <ng-content />
51
+ </ngt-group>
52
+ }
53
+ `,
54
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
55
+ changeDetection: ChangeDetectionStrategy.OnPush,
56
+ hostDirectives: [
57
+ {
58
+ directive: NgtObjectEvents,
59
+ outputs: ['click', 'dblclick', 'contextmenu', 'pointerup', 'pointerdown', 'pointerover', 'pointerout', 'pointerenter', 'pointerleave', 'pointermove', 'pointermissed', 'pointercancel', 'wheel'],
60
+ },
61
+ ],<% if (angularImports.length) { %>
62
+ imports: [<% angularImports.join(', ') %>]<% } %>
63
+ })
64
+ export class <%= className %> {
65
+ protected readonly Math = Math;
66
+
67
+ options = input({} as Partial<NgtThreeElements['ngt-group']>);<% if (animations.length) { %>
68
+ animations = model<<%= gltfAnimationApiTypeName %>>();<% } %>
69
+
70
+ modelRef = viewChild<ElementRef<Group>>('model');
71
+
72
+ protected gltf = injectGLTF<<%= gltfResultTypeName %>>(() => <% if (useImportAttribute) { %> <%= gltfName %> <% } else { %> '<%= url %>' <% } %><% if (gltfOptions) { %>, <%= gltfOptions %><% } %>);
73
+
74
+ constructor() {
75
+ extend({ Group<%= threeImports %> });
76
+
77
+ <% if (animations.length) { %>
78
+ const animations = injectAnimations(this.gltf, this.modelRef);
79
+ effect(() => {
80
+ if (!animations.isReady) return;
81
+ this.animations.set(animations);
82
+ });
83
+ <% } %>
84
+
85
+ const objectEvents = inject(NgtObjectEvents, { host: true });
86
+ effect(() => {
87
+ const model = this.modelRef()?.nativeElement;
88
+ if (!model) return;
89
+
90
+ objectEvents.ngtObjectEvents.set(model);
91
+ });
92
+ }
93
+ }
@@ -0,0 +1,32 @@
1
+ import type { GltfGeneratorSchema } from './gltf';
2
+ export declare class GenerateNGT {
3
+ private analyzedGLTF;
4
+ private gltfjsxAPI;
5
+ private options;
6
+ ngtTypes: Set<string>;
7
+ args: boolean;
8
+ constructor(analyzedGLTF: import('@rosskevin/gltfjsx').AnalyzedGLTF, gltfjsxAPI: typeof import('@rosskevin/gltfjsx'), options: GltfGeneratorSchema);
9
+ generate(): string;
10
+ getGenerateOptions(): {
11
+ animations: import("three").AnimationClip[];
12
+ extras: string;
13
+ threeImports: string;
14
+ args: boolean;
15
+ perspective: boolean;
16
+ orthographic: boolean;
17
+ meshesTypes: string;
18
+ bonesTypes: string;
19
+ materialsTypes: string;
20
+ angularImports: any[];
21
+ };
22
+ private get ngtTypesArr();
23
+ private print;
24
+ private handleAngularInputs;
25
+ private getType;
26
+ /**
27
+ * Transforms a type like "mesh" into "ngt-mesh".
28
+ * @param {string} type
29
+ * @returns
30
+ */
31
+ private getAngularThreeElement;
32
+ }
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GenerateNGT = void 0;
4
+ class GenerateNGT {
5
+ analyzedGLTF;
6
+ gltfjsxAPI;
7
+ options;
8
+ ngtTypes = new Set();
9
+ args = false;
10
+ constructor(
11
+ // @ts-expect-error - type only import
12
+ analyzedGLTF,
13
+ // @ts-expect-error - type only import
14
+ gltfjsxAPI, options) {
15
+ this.analyzedGLTF = analyzedGLTF;
16
+ this.gltfjsxAPI = gltfjsxAPI;
17
+ this.options = options;
18
+ }
19
+ generate() {
20
+ return this.analyzedGLTF.gltf.scene.children.map((child) => this.print(child)).join('\n');
21
+ }
22
+ getGenerateOptions() {
23
+ const perspective = this.ngtTypes.has('PerspectiveCamera');
24
+ const orthographic = this.ngtTypes.has('OrthographicCamera');
25
+ const angularImports = [];
26
+ if (this.args)
27
+ angularImports.push('NgtArgs');
28
+ if (perspective)
29
+ angularImports.push('NgtsPerspectiveCamera');
30
+ if (orthographic)
31
+ angularImports.push('NgtsOrthographicCamera');
32
+ const meshesTypes = this.analyzedGLTF
33
+ .getMeshes()
34
+ .map(({ name, type }) => "\'" + name + "\'" + ': THREE.' + type)
35
+ .join(';\n');
36
+ const bonesTypes = this.analyzedGLTF
37
+ .getBones()
38
+ .map(({ name, type }) => "\'" + name + "\'" + ': THREE.' + type)
39
+ .join(';\n');
40
+ const materialsTypes = this.analyzedGLTF
41
+ .getMaterials()
42
+ .map(({ name, type }) => "\'" + name + "\'" + ': THREE.' + type)
43
+ .join(';\n');
44
+ this.analyzedGLTF.options.log.debug({ materialsTypes });
45
+ const animations = this.analyzedGLTF.gltf.animations || [];
46
+ const gltfExtras = this.analyzedGLTF.gltf.parser.json.asset && this.analyzedGLTF.gltf.parser.json.asset.extras;
47
+ const extras = gltfExtras
48
+ ? Object.keys(gltfExtras)
49
+ .map((key) => `${key.charAt(0).toUpperCase() + key.slice(1)}: ${gltfExtras[key]}`)
50
+ .join('\n')
51
+ : '';
52
+ const ngtTypesArr = this.ngtTypesArr;
53
+ const threeImports = ngtTypesArr.length ? `, ${ngtTypesArr.join(',')}` : '';
54
+ return {
55
+ animations,
56
+ extras,
57
+ threeImports,
58
+ args: this.args,
59
+ perspective,
60
+ orthographic,
61
+ meshesTypes,
62
+ bonesTypes,
63
+ materialsTypes,
64
+ angularImports,
65
+ };
66
+ }
67
+ get ngtTypesArr() {
68
+ return Array.from(this.ngtTypes).filter((t) =>
69
+ // group always is the top-level object
70
+ t !== 'Group' &&
71
+ // we render ngts-perspective-camera instead of ngt-perspective-camera
72
+ t !== 'PerspectiveCamera' &&
73
+ // we render ngts-orthographic-camera instead of ngt-orthographic-camera
74
+ t !== 'OrthographicCamera' &&
75
+ // we don't render ngt-bone
76
+ t !== 'Bone' &&
77
+ // we don't render ngt-object3D
78
+ t !== 'Object3D');
79
+ }
80
+ print(obj) {
81
+ const { nodeName, isRemoved, isTargetedLight, isInstancedMesh, sanitizeName } = this.gltfjsxAPI;
82
+ let result = '';
83
+ let children = '';
84
+ // Children
85
+ if (obj.children)
86
+ obj.children.forEach((child) => (children += this.print(child)));
87
+ // Bail out if the object was pruned
88
+ if (isRemoved(obj))
89
+ return children;
90
+ const { bones } = this.options;
91
+ const node = nodeName(obj);
92
+ const type = this.getType(obj);
93
+ // Bail out on bones
94
+ if (!bones && type === 'bone') {
95
+ this.args = true;
96
+ return `<ngt-primitive *args=[${node}] />\n`;
97
+ }
98
+ const ngtType = this.getAngularThreeElement(type);
99
+ if (isTargetedLight(obj)) {
100
+ this.args = true;
101
+ return `<${ngtType} ${this.handleAngularInputs(obj)} [target]="${node}.target">
102
+ <ngt-primitive *args="[${node}.target]" ${this.handleAngularInputs(obj.target)} />
103
+ </${ngtType}>`;
104
+ }
105
+ // TODO: Instances are currently not supported for NGT components
106
+ //
107
+ if (isInstancedMesh(obj)) {
108
+ const geo = `${node}.geometry`;
109
+ const mat = 'name' in obj.material ? `materials${sanitizeName(obj.material.name)}` : `gltf.${node}.material`;
110
+ this.args = true;
111
+ result = `<ngt-instanced-mesh *args="[${geo}, ${mat}, ${!obj.count ? `gltf.${node}.count` : obj.count}]" `;
112
+ }
113
+ else {
114
+ if (type === 'bone') {
115
+ this.args = true;
116
+ result = `<ngt-primitive *args="[${node}]" `;
117
+ }
118
+ else {
119
+ result = `<${this.getAngularThreeElement(type)} `;
120
+ }
121
+ }
122
+ let shoudSkipName = false;
123
+ if (obj.name.length &&
124
+ 'morphTargetDictionary' in obj &&
125
+ !!obj.morphTargetDictionary &&
126
+ this.analyzedGLTF.hasAnimations()) {
127
+ shoudSkipName = true;
128
+ result += `name="${obj.name}" `;
129
+ }
130
+ result += this.handleAngularInputs(obj, shoudSkipName);
131
+ if (children.length) {
132
+ // Add children and close the element's tag
133
+ result += `>
134
+ ${children}
135
+ </${ngtType}>`;
136
+ }
137
+ else {
138
+ // Close this element's tag
139
+ result += `/>`;
140
+ }
141
+ return result;
142
+ }
143
+ handleAngularInputs(obj, skipName = false) {
144
+ const properties = this.analyzedGLTF.calculateProps(obj);
145
+ let propertiesString = '';
146
+ for (const key in properties) {
147
+ const value = properties[key];
148
+ if (key === 'name') {
149
+ if (skipName)
150
+ continue;
151
+ propertiesString += `name="${value}" `;
152
+ continue;
153
+ }
154
+ if (value === true) {
155
+ // i.e: castShadow, receiveShadow
156
+ propertiesString += `${key} `;
157
+ continue;
158
+ }
159
+ propertiesString += `[${key}]="${value}" `;
160
+ }
161
+ return propertiesString;
162
+ }
163
+ getType(obj) {
164
+ let type = obj.type.charAt(0).toLowerCase() + obj.type.slice(1);
165
+ if (type === 'object3D') {
166
+ type = 'group';
167
+ this.ngtTypes.add('Group');
168
+ }
169
+ if (type === 'perspectiveCamera')
170
+ type = 'PerspectiveCamera';
171
+ if (type === 'orthographicCamera')
172
+ type = 'OrthographicCamera';
173
+ this.ngtTypes.add(obj.type);
174
+ return type;
175
+ }
176
+ /**
177
+ * Transforms a type like "mesh" into "ngt-mesh".
178
+ * @param {string} type
179
+ * @returns
180
+ */
181
+ getAngularThreeElement(type) {
182
+ if (type === 'object3D') {
183
+ return 'ngt-object3D';
184
+ }
185
+ if (type === 'lOD') {
186
+ return 'ngt-lod';
187
+ }
188
+ if (type === 'perspectiveCamera') {
189
+ return `ngts-perspective-camera`;
190
+ }
191
+ if (type === 'orthographicCamera') {
192
+ return `ngts-orthographic-camera`;
193
+ }
194
+ const kebabType = type.replace(/([A-Z])/g, '-$1').toLowerCase();
195
+ return `ngt-${kebabType}`;
196
+ }
197
+ }
198
+ exports.GenerateNGT = GenerateNGT;
199
+ //# sourceMappingURL=generate-ngt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-ngt.js","sourceRoot":"","sources":["../../../../../../libs/plugin/src/generators/gltf/generate-ngt.ts"],"names":[],"mappings":";;;AAGA,MAAa,WAAW;IAMd;IAEA;IACA;IART,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IAC7B,IAAI,GAAG,KAAK,CAAC;IAEb;IACC,sCAAsC;IAC9B,YAAuD;IAC/D,sCAAsC;IAC9B,UAA+C,EAC/C,OAA4B;QAH5B,iBAAY,GAAZ,YAAY,CAA2C;QAEvD,eAAU,GAAV,UAAU,CAAqC;QAC/C,YAAO,GAAP,OAAO,CAAqB;IAClC,CAAC;IAEJ,QAAQ;QACP,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3F,CAAC;IAED,kBAAkB;QACjB,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAC3D,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAE7D,MAAM,cAAc,GAAG,EAAE,CAAC;QAC1B,IAAI,IAAI,CAAC,IAAI;YAAE,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC9C,IAAI,WAAW;YAAE,cAAc,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAC9D,IAAI,YAAY;YAAE,cAAc,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAEhE,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY;aACn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ACnC,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;QAChE,OAAO,OAAO,SAAS,EAAE,CAAC;IAC3B,CAAC;CACD;AA9ND,kCA8NC"}
@@ -0,0 +1,32 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export interface GltfGeneratorSchema {
3
+ modelPath: string;
4
+ output: string;
5
+ className: string;
6
+ selectorPrefix: string;
7
+ draco: boolean;
8
+ bones: boolean;
9
+ meta: boolean;
10
+ shadows: boolean;
11
+ precision: number;
12
+ console: boolean;
13
+ instance: boolean;
14
+ instanceAll: boolean;
15
+ transform: boolean;
16
+ degrade: string;
17
+ degradeResolution: number;
18
+ resolution: number;
19
+ keepMeshes: boolean;
20
+ keepMaterials: boolean;
21
+ keepAttributes: boolean;
22
+ keepNames: boolean;
23
+ keepGroups: boolean;
24
+ format: 'jpeg' | 'png' | 'webp' | 'avif';
25
+ simplify: boolean;
26
+ ratio: number;
27
+ error: number;
28
+ header: string;
29
+ verbose: boolean;
30
+ }
31
+ export declare function gltfGenerator(tree: Tree, options: GltfGeneratorSchema): Promise<never>;
32
+ export default gltfGenerator;