纹理加载完成后创建 MeshPhongMaterial。但是,在加载纹理之前,已经创建了网格。由于 this.atmosphere_material 仍未定义,因此使用基本材质。
在您的加载程序函数中,您有一个可能导致此问题的范围错误:
this.loader.load( 'app/textures/atmospheres/earth_1.jpg', function ( texture ) {
this.atmosphere_material = new THREE.MeshPhongMaterial({
map: texture,
color: 10790052,
ambient: 16777215,
emissive: 1381653,
specular: 16777215,
shininess: 5000,
opacity: 0.46,
transparent: true,
wireframe: false
});
});
地球对象上未设置 this.atmosphere_material 属性。在这个回调中,范围是不同的。以下是加载纹理的更简单方法:
var Earth = function() {
this.planet = new THREE.Object3D();
this.planet_geometry = new THREE.SphereGeometry( 200, 32, 32 );
this.atmosphere = new THREE.Object3D();
this.atmosphere_geometry = new THREE.SphereGeometry( 205, 32, 32 );
this.material = new THREE.MeshPhongMaterial({
map: THREE.ImageUtils.loadTexture( "app/textures/surfaces/earth.jpg" ),
color: 13750737,
ambient: 13092807,
emissive: 595494,
specular: 3223857,
shininess: 25,
opacity: 1,
transparent: false,
wireframe: false,
});
this.surface = new THREE.Mesh( this.planet_geometry, this.material );
this.planet.add(this.surface);
scene.add( this.planet );
this.atmosphere_material = new THREE.MeshPhongMaterial({
map: THREE.ImageUtils.loadTexture( "app/textures/atmospheres/earth_1.jpg" ),
color: 10790052,
ambient: 16777215,
emissive: 1381653,
specular: 16777215,
shininess: 5000,
opacity: 0.46,
transparent: true,
wireframe: false
});
this.surface = new THREE.Mesh( this.atmosphere_geometry, this.atmosphere_material );
this.atmosphere.add(this.surface);
scene.add( this.atmosphere );
}
我没有测试过代码,但应该是正确的。