constructor()

in backup/renderers/renderer-gsi-gl2/src/GSIGL2Renderer.ts [146:285]


	constructor(props: RendererProps) {
		super()

		this.props = {
			...defaultProps,
			...props,
		}

		/**
		 * @stage_0 MPV
		 */
		const canvasWidth = this.props.width * (this.props.ratio ?? 1.0)
		const canvasHeight = this.props.height * (this.props.ratio ?? 1.0)
		const canvas = document.createElement('canvas')
		canvas.width = canvasWidth
		canvas.height = canvasHeight
		canvas.style.position = 'absolute'
		canvas.style.left = '0px'
		canvas.style.top = '0px'
		canvas.style.width = this.props.width + 'px'
		canvas.style.height = this.props.height + 'px'
		this.canvas = canvas

		// Converter
		this.conv = new GL2Converter(GL2ConvConfig)

		/**
		 * init renderer
		 */
		this.renderer = new GL2.Renderer({
			canvas: this.canvas,
			alpha: true,
			antialias: this.props.antialias === 'msaa',
			stencil: false,
		})
		/** @FIXME gamma correction未生效 */
		// this.renderer.gammaOutput = true
		// this.renderer.gammaFactor = 2.2

		/**
		 * init webgl capabilities
		 */
		const gl = this.renderer.getContext()
		this._capabilities = {
			pointSizeRange: gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE),
			lineWidthRange: gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE),
			maxVertexAttributes: gl.getParameter(gl.MAX_VERTEX_ATTRIBS),
			maxVaryingVectors: gl.getParameter(gl.MAX_VARYING_VECTORS),
		}

		/**
		 * init scene
		 */
		this.scene = new THREE.Scene()
		if (this.props.background === 'transparent') {
			this.scene.background = null
			this.renderer.setClearAlpha(0.0)
		} else {
			this.scene.background = new THREE.Color(this.props.background as string)
		}
		// 在scene optimize pass中主动计算matrix,不需要three的计算了
		this.scene.autoUpdate = false
		this.scene.matrixAutoUpdate = false

		/**
		 * init lights
		 */
		this.lights = new THREE.Group()
		this.lights.name = 'LightsWrapper'
		this.scene.add(this.lights)
		this.initLights()

		/**
		 * init Camera
		 * @note 整个 camera 的转换都放进 renderer 里,这里只提供 camera proxy
		 * 反正在哪里转都是一样的
		 */
		const { cameraNear, cameraFar } = this.props
		this.camera = new THREE.PerspectiveCamera(
			this.props.fov,
			this.props.width / this.props.height,
			cameraNear,
			cameraFar
		)
		this.camera.matrixAutoUpdate = false
		if (this.props.viewOffset) {
			this.camera.setViewOffset(
				this.props.width,
				this.props.height,
				this.props.viewOffset[0],
				this.props.viewOffset[1],
				this.props.viewOffset[2] ?? this.props.width,
				this.props.viewOffset[3] ?? this.props.height
			)
		}

		/**
		 * @stage_1 BI 需要
		 */

		/**
		 * init picking
		 * 出于兼容性、实现简洁性,应该使用 CPU picking (raycasting)
		 * 但是出于 GL2 和 WebGPU 的优势考虑,应该使用 GPU picking (color buffer)
		 * - GPU picking
		 * 		WebGL
		 * 			使用一个单独的 RT
		 * 			使用一个PickingMaterial 绘制layer masked物体,同时编ID,映射layer
		 * 		WebGL2
		 * 			使用一个独立的 color buffer,同步绘制
		 */
		this.raycaster = new Raycaster()
		this._internalThreeRaycaster = new THREE.Raycaster()

		/**
		 * @stage_2 只兼容桌面端,考虑是否放到 GL2 renderer 里,IE 是否需要?
		 */

		// init shadow
		// init reflection
		this.initReflection()

		// init pp
		this.frame = new THREE.WebGLRenderTarget(canvasWidth, canvasHeight, {
			minFilter: THREE.LinearFilter,
			magFilter: THREE.LinearFilter,
			format: THREE.RGBAFormat,
			stencilBuffer: false,
			depthBuffer: true,
		})
		this.frame.depthTexture = new (THREE.DepthTexture as any)()

		this.initPostprocessing()

		// init debug helper
		if (this.props.debug) {
			// 在 场景中加入 坐标轴
			this.scene.add(new THREE.AxesHelper(1000000000))
		}
	}