Skip to content

Commit 9617006

Browse files
committed
fix(plugin): gltfPath
1 parent 8009ab6 commit 9617006

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

libs/plugin/src/generators/gltf/files/__fileName__.ts__tmpl__

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { NgtsOrthographicCamera } from 'angular-three-soba/cameras';<% } %>
1919
import <%= gltfName %> from '.<%= gltfPath %>' with { loader: 'file' };
2020
<% } %>
2121
<% if (preload) { %>
22-
injectGLTF(() => <% if (useImportAttribute) { %><%= gltfName %><% } else { %>'<%= gltfPath %>'<% } %>);
22+
injectGLTF.preload(() => <% if (useImportAttribute) { %><%= gltfName %><% } else { %>'<%= gltfPath %>'<% } %>);
2323
<% } %>
2424
<% if (animations.length) { %>
2525
type ActionName = <% animations.map(clip => "\""+ clip.name + "\"").join(" | ") %>;

libs/plugin/src/generators/gltf/gltf.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { formatFiles, generateFiles, names, Tree } from '@nx/devkit';
2-
import { dirname, join, resolve } from 'node:path';
2+
import { dirname, join, relative, resolve } from 'node:path';
33
import { GenerateNGT } from './utils/generate-ngt';
44

55
export interface GltfGeneratorSchema {
@@ -117,7 +117,15 @@ export async function gltfGenerator(tree: Tree, options: GltfGeneratorSchema) {
117117
t !== 'Object3D',
118118
);
119119
const threeImports = ngtTypesArr.length ? `, ${ngtTypesArr.join(',')}` : '';
120-
const gltfPath = transformedModelPath || modelPath;
120+
let gltfPath =
121+
!transformedModelPath && modelPath.startsWith('http')
122+
? modelPath
123+
: relative(dirname(options.output), transformedModelPath || modelPath);
124+
125+
if (!gltfPath.startsWith('http') && !gltfPath.startsWith('.')) {
126+
gltfPath = `./${gltfPath}`;
127+
}
128+
121129
const gltfAnimationTypeName = className + 'AnimationClips';
122130
const gltfAnimationApiTypeName = className + 'AnimationApi';
123131
const gltfName = className + 'GLTF';

0 commit comments

Comments
 (0)