Three.js 中的光照贴图 [英] Lightmaps in Three.js

查看:110
本文介绍了Three.js 中的光照贴图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

光照贴图独立于其他纹理,对吧?

Lightmaps live independently of other textures, right?

所以我必须设置第二组 UV.

So I have to set up a second set of UVs.

我已经使用第二组 UV 导出了我的 JSON 对象并添加了以下内容.

I have exported my JSON object with a second set of UVs and added the following.

geometry.faceVertexUvs[0] = geometry.faceVertexUvs[1];

我没有得到任何工作结果.我缺少什么?也许有人可以为我指明方向.三.js r.73

I got no working results. What I'm missing? Maybe someone can wise me a direction. Three.js r.73

loader.load("model.js", function(geometry){
geometry.faceVertexUvs[0] = geometry.faceVertexUvs[1];

var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( {
  color: 0x777777,
  lightMap: THREE.ImageUtils.loadTexture( "lightmap.png" ),
  normalMap: THREE.ImageUtils.loadTexture( "normalmap.png" ),
  specularMap: THREE.ImageUtils.loadTexture( "specularmap.png" )
}));
scene.add(mesh );
});

推荐答案

three.js 中的光照贴图需要第二组 UV.一种解决方案是通过复制第一组 UV 来添加第二组 UV.

Lightmaps in three.js require a second set of UVs. One solution is to add a second set of UVs by duplicating the first set.

对于 THREE.Geometry,您可以这样做:

For THREE.Geometry you can do this:

geometry.faceVertexUvs[ 1 ] = geometry.faceVertexUvs[ 0 ];

对于THREE.BufferGeometry,使用这种模式;

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

three.js r.73

three.js r.73

这篇关于Three.js 中的光照贴图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆