最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Three.js skybox texture issue - Stack Overflow

programmeradmin3浏览0评论

I'm trying to create a simple Skybox using Three.js but have run into an issue with the texture I'm applying to the cube only working on the outside, and not displaying on the inside of the cube.

Here's my skybox code:

var path = assetPath + skyboxPrefix;
var urls = [ path + 'alpine_front.jpg',
             path + 'alpine_back.jpg',
             path + 'alpine_left.jpg',
             path + 'alpine_right.jpg',
             path + 'alpine_top.jpg' ];

var cubeTexture = THREE.ImageUtils.loadTextureCube( urls );

var shader = THREE.ShaderUtils.lib["cube"];
shader.uniforms["tCube"].texture = cubeTexture;

var skyboxMaterial = new THREE.ShaderMaterial( {
    uniforms        : shader.uniforms,
    fragmentShader  : shader.fragmentShader,
    vertexShader    : shader.vertexShader,
    depthWrite      : false
} );

var skyboxGeom = new THREE.CubeGeometry( 10000, 10000, 10000 );

skybox = new THREE.Mesh( skyboxGeom, skyboxMaterial );
skybox.flipSided = true;
    
scene.add(skybox);

Here's a live version /

I'm trying to create a simple Skybox using Three.js but have run into an issue with the texture I'm applying to the cube only working on the outside, and not displaying on the inside of the cube.

Here's my skybox code:

var path = assetPath + skyboxPrefix;
var urls = [ path + 'alpine_front.jpg',
             path + 'alpine_back.jpg',
             path + 'alpine_left.jpg',
             path + 'alpine_right.jpg',
             path + 'alpine_top.jpg' ];

var cubeTexture = THREE.ImageUtils.loadTextureCube( urls );

var shader = THREE.ShaderUtils.lib["cube"];
shader.uniforms["tCube"].texture = cubeTexture;

var skyboxMaterial = new THREE.ShaderMaterial( {
    uniforms        : shader.uniforms,
    fragmentShader  : shader.fragmentShader,
    vertexShader    : shader.vertexShader,
    depthWrite      : false
} );

var skyboxGeom = new THREE.CubeGeometry( 10000, 10000, 10000 );

skybox = new THREE.Mesh( skyboxGeom, skyboxMaterial );
skybox.flipSided = true;
    
scene.add(skybox);

Here's a live version http://projects.harrynorthover./landscape/src/

Share Improve this question edited Feb 7, 2022 at 12:43 vvvvv 32.2k19 gold badges65 silver badges100 bronze badges asked Oct 1, 2012 at 8:56 Harry NorthoverHarry Northover 5811 gold badge6 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

object.flipSided has been gone since r50. It got replaced with object.material = THREE.BackSide. Checking updated examples that use the same feature and also this migration page should be handy on cases like this.

I've also seen the "flipSided" switch in other examples and didn't get it to work (might be outdated). What works for me (with a sphere) is setting a negative scale:

skybox.scale.x = -1;
发布评论

评论列表(0)

  1. 暂无评论