render method

void render(
  1. Object3D scene,
  2. Camera camera
)

Implementation

void render(Object3D scene, Camera camera) {
  if (_isContextLost == true) return;

  // update scene graph
  if (scene.autoUpdate == true) scene.updateMatrixWorld();

  // update camera matrices and frustum

  if (camera.parent == null) camera.updateMatrixWorld();

  // if ( xr.enabled == true && xr.isPresenting == true ) {

  // 	camera = xr.getCamera( camera );

  // }

  if (scene is Scene) {
    if (scene.onBeforeRender != null) {
      scene.onBeforeRender!(
          renderer: this,
          scene: scene,
          camera: camera,
          renderTarget: _currentRenderTarget);
    }
  }

  currentRenderState =
      renderStates.get(scene, renderCallDepth: renderStateStack.length);
  currentRenderState!.init();

  renderStateStack.add(currentRenderState!);

  projScreenMatrix.multiplyMatrices(
      camera.projectionMatrix, camera.matrixWorldInverse);

  _frustum.setFromProjectionMatrix(projScreenMatrix);

  _localClippingEnabled = localClippingEnabled;
  _clippingEnabled =
      clipping.init(clippingPlanes, _localClippingEnabled, camera);

  currentRenderList = renderLists.get(scene, renderListStack.length);
  currentRenderList!.init();

  renderListStack.add(currentRenderList!);

  projectObject(scene, camera, 0, sortObjects);

  currentRenderList!.finish();

  if (sortObjects == true) {
    currentRenderList!.sort(_opaqueSort, _transparentSort);
  }

  if (_clippingEnabled == true) clipping.beginShadows();

  var shadowsArray = currentRenderState!.state.shadowsArray;

  shadowMap.render(shadowsArray, scene, camera);

  // currentRenderState!.setupLights(physicallyCorrectLights);
  // currentRenderState!.setupLightsView(camera);

  if (_clippingEnabled == true) clipping.endShadows();

  if (info.autoReset == true) info.reset();

  background.render(currentRenderList!, scene);

  // render scene

  currentRenderState!.setupLights(physicallyCorrectLights);

  if (camera is ArrayCamera) {
    var cameras = camera.cameras;

    for (var i = 0, l = cameras.length; i < l; i++) {
      var camera2 = cameras[i];

      renderScene(currentRenderList!, scene, camera2, camera2.viewport);
    }
  } else {
    renderScene(currentRenderList!, scene, camera);
  }

  if (_currentRenderTarget != null) {
    // resolve multisample renderbuffers to a single-sample texture if necessary
    textures.updateMultisampleRenderTarget(_currentRenderTarget!);

    // Generate mipmap if we're using any kind of mipmap filtering
    textures.updateRenderTargetMipmap(_currentRenderTarget!);
  }

  if (scene is Scene) {
    scene.onAfterRender(renderer: this, scene: scene, camera: camera);
  }

  // _gl.finish();

  bindingStates.resetDefaultState();
  _currentMaterialId = -1;
  _currentCamera = null;

  renderStateStack.removeLast();
  if (renderStateStack.isNotEmpty) {
    currentRenderState = renderStateStack[renderStateStack.length - 1];
  } else {
    currentRenderState = null;
  }

  renderListStack.removeLast();

  if (renderListStack.isNotEmpty) {
    currentRenderList = renderListStack[renderListStack.length - 1];
  } else {
    currentRenderList = null;
  }
}