多纹理 OBJ->JSON 转换文件如何跟踪面部纹理映射?

发布于 2025-01-06 06:06:43 字数 312 浏览 5 评论 0原文

我正在尝试手动(没有诸如 Three.js 之类的库)将 JSON 3D 模型加载到我的 webGL 代码中,只是为了好玩,但当我的模型具有超过 1 个纹理时,我遇到了困难。 在 OBJ->JSON 转换的文件中,我如何知道哪个纹理对于后面的面是“活动的”? OBJ 文件使用“usemtl”标签来标识正在使用的纹理/材质,但在使用 JSON 时我似乎找不到这种指针。 随着时间的推移,我正在使用 alteredq 编写的 OBJ->JSON 转换器,

非常感谢, 杆

I'm trying to manually (no libs such as Three.js) load a JSON 3D model into my webGL code just for fun but I'm having a hard time when my models have more than 1 texture.
In a OBJ->JSON converted file, how do I know which texture is the "active" for the faces that follow? OBJ files use 'usemtl' tag to identify the texture/material in use but I can't seem to find that kind of pointer when working with JSONs.
In time, I'm using the OBJ->JSON converter written by alteredq

Thanks a bunch,
Rod

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

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

发布评论

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

评论(2

江心雾 2025-01-13 06:06:44

看一下这个文件:two.js/src/extras/loaders/JSONLoader.js

JSON 文件的 faces 数组中每个面的第一个元素是一个位字段。第一个位表示该面是否有三到四个索引。第二位表示该面是否分配了材质。材料索引(如果有)出现在索引之后。

示例:面:[2, 46, 44, 42, 0, 1, 45, 46, 48, 3, ...

第一个面(有材质的三角形):

Type: 2 (00000010b)
Indices: 46, 44, 42
Material index: 0

第二个面(没有材质的四边形) :

Type: 1 (00000001b)
Indices: 45, 46, 48

第三面(带有材料的四边形):

Type: 3 (00000011b)
Indices: ...

检查源代码以了解该位字段的完整含义。

Take a look at this file: three.js / src / extras / loaders / JSONLoader.js.

The first element of each face in the faces array of the JSON file is a bit field. The first bit says if that face have three o four indices. And the second bit says if that face has a material assigned. Material index, if any, appears after indices.

Example: faces: [2, 46, 44, 42, 0, 1, 45, 46, 48, 3, ...

First face (triangle with material):

Type: 2 (00000010b)
Indices: 46, 44, 42
Material index: 0

Second face (quad without material):

Type: 1 (00000001b)
Indices: 45, 46, 48

Third face (quad with material):

Type: 3 (00000011b)
Indices: ...

Check source code for full meaning of that bit field.

猥琐帝 2025-01-13 06:06:44

在我为 KickJS 游戏引擎编写的 OBJ->JSON 转换器中,每种材质都有自己的索引范围。

这意味着一个简单的 OBJ 模型,如

    mtllib plane.mtl
    o Plane
    v 1.000000 0.000000 -1.000000
    v 1.000000 0.000000 1.000000
    v -1.000000 0.000000 1.000000
    v -1.000000 0.000000 -1.000000
    usemtl Material
    s 1
    f 2 3 4
    usemtl Material.001
    f 1 2 4

将被翻译成这样(有两个索引;每种材料一个):

    [
       {
          "vertex": [1,0,1,-1,0,1,-1,0,-1,1,0,-1],
          "name": "Plane mesh",
          "normal": [0,-1,0,0,-1,0,0,-1,0,0,0,0],
          "indices0": [0,1,2],
          "indices1": [3,0,2]
       }
    ]

使用在线模型查看器进行转换:

http://www.kickjs.org/example/model_viewer/model_viewer.html

In the OBJ->JSON converter I have written for the KickJS game engine, each material has its own range of indices.

This means a simple OBJ model such as

    mtllib plane.mtl
    o Plane
    v 1.000000 0.000000 -1.000000
    v 1.000000 0.000000 1.000000
    v -1.000000 0.000000 1.000000
    v -1.000000 0.000000 -1.000000
    usemtl Material
    s 1
    f 2 3 4
    usemtl Material.001
    f 1 2 4

Would be translated into this (With two indices; one for each material):

    [
       {
          "vertex": [1,0,1,-1,0,1,-1,0,-1,1,0,-1],
          "name": "Plane mesh",
          "normal": [0,-1,0,0,-1,0,0,-1,0,0,0,0],
          "indices0": [0,1,2],
          "indices1": [3,0,2]
       }
    ]

Use the online model viewer for the convertion:

http://www.kickjs.org/example/model_viewer/model_viewer.html

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