Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move object generation into init
  • Loading branch information
AdaRoseCannon committed Feb 16, 2021
commit d28a6a2351d13904de50bba631e980080c16fe5c
32 changes: 17 additions & 15 deletions src/components/scene/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,35 @@ module.exports.Component = register('background', {
transparent: {default: false},
generateEnvironment: {default: true}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the default to be true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's pretty safe and not a huge performance hit as it only renders the once. It will even fix materials unexpectedly not looking right because they expect an environment map. So it's a nice feature, that you only need to type 'background` to get.

I'd even be tempted to take it a step further and make background="transparent:true" a default component on <a-scene> or at least add background to the hello-world boilerplate just to get the better behaviour by default.

},
init: function () {
var cubeRenderTarget = new THREE.WebGLCubeRenderTarget(128, { format: THREE.RGBFormat, generateMipmaps: true, minFilter: THREE.LinearMipmapLinearFilter });
var cubeCamera = new THREE.CubeCamera(1, 100000, cubeRenderTarget);
this.cubeRenderTarget = cubeRenderTarget;
this.cubeCamera = cubeCamera;
this.needsEnvironmentUpdate = true;
},
update: function () {
var scene = this.el.sceneEl.object3D;
var data = this.data;
var object3D = this.el.object3D;
if (data.transparent) {
object3D.background = null;
return;
} else {
object3D.background = new THREE.Color(data.color);
}
object3D.background = new THREE.Color(data.color);

if (data.generateEnvironment) {
const scene = this.el.sceneEl.object3D;
const cubeRenderTarget = new THREE.WebGLCubeRenderTarget(128, { format: THREE.RGBFormat, generateMipmaps: true, minFilter: THREE.LinearMipmapLinearFilter });
const cubeCamera = new THREE.CubeCamera(1, 100000, cubeRenderTarget);
this.cubeCamera = cubeCamera;
this.needsEnvironmentUpdate = true;
scene.environment = cubeRenderTarget.texture;
this.el.sceneEl.addEventListener('loaded', function () {
this.needsEnvironmentUpdate = true;
});
scene.environment = this.cubeRenderTarget.texture;
} else {
scene.environment = null;
}
},

tick () {
tick: function () {
if (!this.needsEnvironmentUpdate) return;
const scene = this.el.object3D;
const renderer = this.el.renderer;
const camera = this.el.camera;
var scene = this.el.object3D;
var renderer = this.el.renderer;
var camera = this.el.camera;

this.el.object3D.add(this.cubeCamera);
this.cubeCamera.position.copy(camera.position);
Expand Down