render method
Implementation
void render(WebGLRenderList renderList, Object3D scene) {
var forceClear = false;
var background = scene is Scene ? scene.background : null;
if (background != null && background is Texture) {
background = cubemaps.get(background);
}
// Ignore background in AR
// TODO: Reconsider this.
// var xr = renderer.xr;
// var session = xr.getSession && xr.getSession();
// if ( session && session.environmentBlendMode == 'additive' ) {
// background = null;
// }
if (background == null) {
setClear(clearColor, clearAlpha);
} else if (background != null && background is Color) {
setClear(background, 1);
forceClear = true;
}
if (renderer.autoClear || forceClear) {
renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
}
if (background != null &&
(background is CubeTexture || (background is Texture && background.mapping == CubeUVReflectionMapping))) {
if (boxMesh == null) {
boxMesh = Mesh(
BoxGeometry(1, 1, 1),
ShaderMaterial({
"name": 'BackgroundCubeMaterial',
"uniforms": cloneUniforms(shaderLib["cube"]["uniforms"]),
"vertexShader": shaderLib["cube"]["vertexShader"],
"fragmentShader": shaderLib["cube"]["fragmentShader"],
"side": BackSide,
"depthTest": false,
"depthWrite": false,
"fog": false
}));
boxMesh!.geometry?.deleteAttribute('normal');
boxMesh!.geometry?.deleteAttribute('uv');
boxMesh!.onBeforeRender = ({renderer, scene, camera, renderTarget, mesh, geometry, material, group}) {
boxMesh!.matrixWorld.copyPosition(camera.matrixWorld);
};
// enable code injection for non-built-in material
// Object.defineProperty( boxMesh.material, 'envMap', {
// get: function () {
// return this.uniforms.envMap.value;
// }
// } );
objects.update(boxMesh!);
}
boxMesh!.material.uniforms["envMap"]["value"] = background;
boxMesh!.material.uniforms["flipEnvMap"]["value"] =
(background is CubeTexture && background is WebGL3DRenderTarget) ? -1 : 1;
if (currentBackground != background ||
currentBackgroundVersion != background.version ||
currentTonemapping != renderer.toneMapping) {
boxMesh!.material.needsUpdate = true;
currentBackground = background;
currentBackgroundVersion = background.version;
currentTonemapping = renderer.toneMapping;
}
boxMesh!.layers.enableAll();
// push to the pre-sorted opaque render list
renderList.unshift(boxMesh!, boxMesh!.geometry, boxMesh!.material, 0, 0, null);
} else if (background != null && background is Texture) {
if (planeMesh == undefined) {
planeMesh = Mesh(
PlaneGeometry(2, 2),
ShaderMaterial({
"name": 'BackgroundMaterial',
"uniforms": cloneUniforms(shaderLib["background"]["uniforms"]),
"vertexShader": shaderLib["background"]["vertexShader"],
"fragmentShader": shaderLib["background"]["fragmentShader"],
"side": FrontSide,
"depthTest": false,
"depthWrite": false,
"fog": false
}));
planeMesh!.geometry?.deleteAttribute('normal');
// enable code injection for non-built-in material
// Object.defineProperty( planeMesh.material, 'map', {
// get: function () {
// return this.uniforms.t2D.value;
// }
// } );
objects.update(planeMesh!);
}
planeMesh!.material.uniforms["t2D"]["value"] = background;
if (background.matrixAutoUpdate == true) {
background.updateMatrix();
}
planeMesh!.material.uniforms["uvTransform"]["value"].copy(background.matrix);
if (currentBackground != background ||
currentBackgroundVersion != background.version ||
currentTonemapping != renderer.toneMapping) {
planeMesh!.material.needsUpdate = true;
currentBackground = background;
currentBackgroundVersion = background.version;
currentTonemapping = renderer.toneMapping;
}
planeMesh!.layers.enableAll();
// push to the pre-sorted opaque render list
renderList.unshift(planeMesh!, planeMesh!.geometry, planeMesh!.material, 0, 0, null);
}
}