三个软件包中包含的三j / gltfloader

发布于 2025-01-31 11:40:59 字数 694 浏览 2 评论 0原文

有一个注释说,从三个r103开始,gltfloader包含在三个软件包本身中,并且不再需要安装三个GLTF-loader。

这是我的html文件脚本导入:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/three.min.js"></script>

js.file,

如果我使用:

const loader = new THREE.GLTFLoader();

und typeError:必须使用'new'''调用类构造仪

,或者如果我使用:

const loader = new GLTFLoader();

nuck offfach coftucterror:gltfloader:gltfloader nons n n's n n n n n's n n n n's << /em>

所以我想我错过了进口或声明GLTF的观点

There is a note saying that starting with three.js r103, GLTFLoader is included in the three package itself and installing three-gltf-loader is no longer necessary.

Here is my html file script import :

<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/three.min.js"></script>

JS.file

If I use :

const loader = new THREE.GLTFLoader();

Uncaught TypeError: class constructors must be invoked with 'new'

Or if I use :

const loader = new GLTFLoader();

Uncaught ReferenceError: GLTFLoader is not defined

So I think I have missed a point about importing or declaring gltf

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

執念 2025-02-07 11:40:59

GLTFLOADER(与其他三个JS加载器和控件一样)是同一NPM软件包的一部分,但不是核心捆绑包的一部分。它可以从子文件夹中导出,而是:

import { Scene } from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';

const scene = new Scene();

const loader = new GLTFLoader();

const gltf = await loader.loadAsync( 'path/to/model.glb' );

scene.add( gltf.scene );

如果安装了“三个”,则捆绑器和构建工具将自动解决此问题,这是我建议使用的方法。如果您喜欢使用CDN,则可能需要其他导入地图来解决正确的URL的“三个”软件包。在

GLTFLoader (like other three.js loaders and controls) is part of the same NPM package, but not part of the core bundle. It can be exported from a subfolder, instead:

import { Scene } from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';

const scene = new Scene();

const loader = new GLTFLoader();

const gltf = await loader.loadAsync( 'path/to/model.glb' );

scene.add( gltf.scene );

Bundlers and build tools will resolve this automatically if you have 'three' installed, and that's what I'd recommend using. If you prefer to use a CDN, then you may need additional import maps to resolve the 'three' package to the right URLs. Both options are discussed in the three.js installation documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文