Changing three.js background to transparent or other color

后端 未结 6 1222
误落风尘
误落风尘 2020-11-28 02:55

I\'ve been trying to change what seems to be the default background color of my canvas from black to transparent / any other color - but no luck.

My HTML:

         


        
6条回答
  •  难免孤独
    2020-11-28 03:32

    I came across this when I started using three.js as well. It's actually a javascript issue. You currently have:

    renderer.setClearColorHex( 0x000000, 1 );
    

    in your threejs init function. Change it to:

    renderer.setClearColorHex( 0xffffff, 1 );
    

    Update: Thanks to HdN8 for the updated solution:

    renderer.setClearColor( 0xffffff, 0);
    

    Update #2: As pointed out by WestLangley in another, similar question - you must now use the below code when creating a new WebGLRenderer instance in conjunction with the setClearColor() function:

    var renderer = new THREE.WebGLRenderer({ alpha: true });
    

    Update #3: Mr.doob points out that since r78 you can alternatively use the code below to set your scene's background colour:

    var scene = new THREE.Scene(); // initialising the scene
    scene.background = new THREE.Color( 0xff0000 );
    

提交回复
热议问题