我如何在三个.js中修改GLTF模型的材料

发布于 2025-02-05 06:03:54 字数 147 浏览 1 评论 0 原文

因此,我有一个在搅拌机中制作的模型,所有的照明和纹理都烘烤,但是当我将其导入到三分(以.glb格式)中时,它默认为标准材料。在某些情况下,这可能很好,但是,正如我之前说的那样,我烘烤了所有的照明和纹理。如何将材料从标准更改为基本,而不会失去烘焙信息和纹理/必须将其导入单独的图像?

So I have a model I made in Blender, with all the lighting and textures baked, but when I import it into THREE.js (saved in .glb format), it defaults to the standard material. This might be fine in some situations, but, as I said earlier, I have all the lighting and textures baked. How can I change the material from standard to basic without loosing my baking info and textures/having to import them as separate images?

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

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

发布评论

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

评论(2

半世蒼涼 2025-02-12 06:03:54

您要寻找的是 khr_materials_unlit 在GLTF中或Blender中的“无阴影”。您可以使用以下节点graph

有了这种布置,导出的GLTF文件将具有 khr_materials_unlit 应用于材料,并且纹理中的烘烤照明将保留在三j中。

What you're looking for is called KHR_materials_unlit in glTF, or "Shadeless" in Blender. You can export this from Blender to glTF using the following node graph:

node graph screenshot

With this arrangement, the exported glTF file will have KHR_materials_unlit applied to the material, and the baked lighting in the texture will be preserved in ThreeJS.

听你说爱我 2025-02-12 06:03:54

这样,您可以加载模型并在其上放置自定义材料。

这也适用于您的GLB模型。
但是强烈建议三个JS使用GLTF。

const modelPath = "your model path";
const texturePath = "your texture path"

const loader = new GLTFLoader();
const texture = new TextureLoader().load(texturePath);
loader.load( modelPath, function ( gltf ) {
    const model = gltf.scene;
    model.traverse((obj) => {
        if(obj instanceof Mesh){
            obj.material = new MeshBasicMaterial({map: texture})
            }
        }
    )

}, undefined, function ( error ) {
    console.error( error );
} );

In this way you can load your model and put a custom material on it.

This also should work for your glb model.
But Three js highly recommend to use gltf.

const modelPath = "your model path";
const texturePath = "your texture path"

const loader = new GLTFLoader();
const texture = new TextureLoader().load(texturePath);
loader.load( modelPath, function ( gltf ) {
    const model = gltf.scene;
    model.traverse((obj) => {
        if(obj instanceof Mesh){
            obj.material = new MeshBasicMaterial({map: texture})
            }
        }
    )

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