我正在尝试在THREE.MeshPhongMaterial上设置纹理,但纹理不会加载。 我的代码:
let earth_geometry = new THREE.SphereGeometry(450, 10, 10)
let earth_material = new THREE.MeshPhongMaterial({
emissive: 0xffffff
})
let earth = new THREE.Mesh(earth_geometry, earth_material)
loadImage(earth_material, '/img/earth.jpg')
scene.add(earth)
function loadImage(material, url) {
let texture = new THREE.TextureLoader().load(url, (e) => {
texture.minFilter = THREE.LinearFilter
texture.anisotropy = 8
material.map = texture
material.needsUpdate = true
})
如果我将材质更改为THREE.MeshBasicMaterial()
,则会加载纹理。
为什么它不适用于THREE.MeshPhongMaterial
?
答案 0 :(得分:2)
可能与纹理变量有关吗?
在您尝试使用它之后,我认为您正在设置纹理变量
加载器回调中的e
参数实际上是加载的纹理
试试这个..
function loadImage(material, url) {
let loader = new THREE.TextureLoader()
loader.load(url, (texture) => {
texture.minFilter = THREE.LinearFilter
texture.anisotropy = 8
material.map = texture
material.needsUpdate = true
// maybe need this too..
material.map.needsUpdate = true;
})