_init()

in packages/layers/helper/src/HelperLayer.ts [53:141]


	_init() {
		// 在 场景中加入 坐标轴
		this.watchProps(
			['length', 'box'],
			(e) => {
				const length = this.getProp('length')
				const lineGeom = new Geom({
					mode: 'LINES',
					attributes: {
						position: new Attr(
							new Float32Array([
								0.0,
								0.0,
								0.0,
								length,
								0.0,
								0.0,
								0.0,
								0.0,
								0.0,
								0.0,
								length,
								0.0,
								0.0,
								0.0,
								0.0,
								0.0,
								0.0,
								length,
							]),
							3
						),
						vertexColor: new Attr(
							new Float32Array([
								1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
								1.0,
							]),
							3
						),
					},
				})

				const lineMatr = new UnlitMaterial({})

				lineMatr.vertGlobal = `
				attribute vec3 vertexColor;
				varying vec3 vColor;
			`
				lineMatr.fragGlobal = `
				varying vec3 vColor;
			`
				lineMatr.vertGeometry = `vColor = vertexColor;`
				lineMatr.fragOutput = `fragColor = vec4(vColor, 1.0);`

				if (this.axises) {
					this.group.remove(this.axises)
				}

				this.axises = new Mesh({
					geometry: lineGeom,
					material: lineMatr,
				})

				this.group.add(this.axises)

				// remove box
				if (this.box) {
					this.group.remove(this.box)
					this.box = undefined
				}

				if (this.getProp('box')) {
					const geom = buildBox({
						width: length * 0.1,
						height: length * 0.1,
						depth: length * 0.1,
					})

					this.box = new Mesh({
						geometry: geom,
						material: new UnlitMaterial({ baseColorFactor: { r: 1, g: 0, b: 1 } }),
					})

					this.group.add(this.box)
				}
			},
			{ immediate: true }
		)
	}