第二个 UV 在 Aframe 中用于环境遮挡。

huangapple go评论68阅读模式
英文:

2nd uv in Aframe for ambient occlusion

问题

以下是翻译好的内容:

我想在Aframe中对一个obj模型使用烘焙的AO效果。Don Mccurdy解释了AO需要第二个UV通道,并在这里用Java说明了如何解决这个问题:

https://github.com/aframevr/aframe/issues/2721

我尝试了,但是我无法让它工作!

var geometry = mesh.geometry;

geometry.addAttribute('uv2', new THREE.BufferAttribute(geometry.attributes.uv.array, 2));

我如何将这些JavaScript代码行指向我在Aframe中的obj模型?
感谢您的帮助,非常感谢!最好,can

英文:

I would like to use baked AO on an obj-model in Aframe. Don Mccurdy explains
that AO needs a 2nd UV channel and how to solve this in Java here:

https://github.com/aframevr/aframe/issues/2721

I tried it but I don`t get it to work!

var geometry = mesh.geometry;

geometry.addAttribute( 'uv2', new THREE.BufferAttribute( geometry.attributes.uv.array, 2 ) );

How do I point this js-lines to my obj-model in Aframe?

Thanks a lot for help, appreciate! Best, can

答案1

得分: 2

理想情况下,我建议在Blender中打开OBJ文件,按照Blender文档中所描述的方法添加环境遮挡贴图,然后导出为glTF格式。其余部分将通过A-Frame的gltf-model组件自动处理,并且加载速度将更快。


如果转换为其他格式不是一个选项,您将需要编写一个自定义组件,该组件会监听模型的加载,然后遍历模型中的每个网格(可能不止一个!)并创建额外的UV集:

AFRAME.registerComponent('copy-uvs', {
  init: function () {
    this.el.addEventListener('model-loaded', function (e) {
      e.detail.model.traverse(function(object) {
        if (object.isMesh && object.geometry.attributes.uv) {
          var geometry = object.geometry;
          geometry.setAttribute('uv2', geometry.attributes.uv);
          console.log('copied UVs!');
        }
      });
    });
  }
});

这个copy-uvs组件需要附加到与您的OBJ模型相同的元素上。

英文:

Ideally, I'd suggest opening the OBJ file in Blender, adding the Ambient Occlusion texture as described in the Blender docs, then exporting to glTF. The rest will be handled automatically with A-Frame's gltf-model component, and will load more quickly.


If converting to another format isn't an option, you'll need to write a custom component that listens for the model to load, then traverses every mesh in the model (there might be more than one!) and creates an extra UV set:

AFRAME.registerComponent('copy-uvs', {
  init: function () {
    this.el.addEventListener('model-loaded', function (e) {
      e.detail.model.traverse(function(object) {
        if (object.isMesh && object.geometry.attributes.uv) {
          var geometry = object.geometry;
          geometry.setAttribute('uv2', geometry.attributes.uv);
          console.log('copied UVs!');
        }
      });
    });
  }
});

This copy-uvs component would need to be attached to the same element as your OBJ model.

huangapple
  • 本文由 发表于 2020年5月30日 20:15:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/62102297.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定