简体   繁体   English

为什么我的 map 不能使用 MeshPhongMaterial

[英]Why my map not working with MeshPhongMaterial

I try to create the pl.net Earth with three.js. I used a texture on a MeshBasicMaterial and it worked perfectly, but when I change the material to a MeshPhongMaterial it just doesn't render the map anymore.我尝试用 three.js 创建 pl.net Earth。我在MeshBasicMaterial上使用了一个纹理,它工作得很好,但是当我将材质更改为MeshPhongMaterial时,它不再渲染 map。

I want to change the material because I want to add a bump Map too.我想更改材料,因为我也想添加一个凹凸 Map。

Here's my code:这是我的代码:

let renderer;

const earthGeometry = new THREE.SphereGeometry(5, 50, 50);

const earthMaterial = new THREE.MeshPhongMaterial({
    map: new THREE.TextureLoader().load("../img/globe.jpg"),
  //   bumpMap: new THREE.TextureLoader().load("../img/earthbump.jpg"),
  //   bumpScale: 0.3,
});

const sphere = new THREE.Mesh(earthGeometry, earthMaterial); const sphere = new THREE.Mesh(earthGeometry, earthMaterial); scene.add(sphere);场景。添加(球体);

And there's not a single problem in the console so I don't know what to do.而且控制台中没有任何问题,所以我不知道该怎么办。 I'm also using svelte and vite, maybe it can come from here.我也在使用 svelte 和 vite,也许它可以来自这里。

I used a texture on a MeshBasicMaterial and it worked perfectly, but when I change the material to a MeshPhongMaterial it just doesn't render the map anymore.我在 MeshBasicMaterial 上使用了纹理,它工作得很好,但是当我将材质更改为 MeshPhongMaterial 时,它不再渲染 map。

If it does work with MeshBasicMaterial but not with MeshPhongMaterial , you most likely have no lights in your scene.如果它确实适用于MeshBasicMaterial但不适用于MeshPhongMaterial ,那么您的场景中很可能没有灯光。 Try it with this basic setup:试试这个基本设置:

const ambientLight = new THREE.AmbientLight( 0xffffff, 0.4 );
scene.add( ambientLight );

const directionalLight = new THREE.DirectionalLight( 0xffffff, 0.8 );
directionalLight.position.set( 100, 100, 0 );
scene.add( directionalLight );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM