()
| 103 | renderer.render(scene, camera); |
| 104 | }, |
| 105 | init () { |
| 106 | const that = this |
| 107 | this.scene = null |
| 108 | this.objects = [] |
| 109 | const felidView = 40; |
| 110 | const height = document.getElementById(this.id).clientHeight; |
| 111 | const width = document.getElementById(this.id).clientWidth; |
| 112 | const aspect = width / height; |
| 113 | const nearPlane = 1; |
| 114 | const farPlane = 10000; |
| 115 | const WebGLoutput = document.getElementById('container'); |
| 116 | |
| 117 | this.scene = new THREE.Scene(); |
| 118 | this.camera = new THREE.PerspectiveCamera(felidView, aspect, nearPlane, farPlane); |
| 119 | this.camera.position.z = 3000; |
| 120 | |
| 121 | this.renderer = new THREE.CSS3DRenderer(); |
| 122 | this.renderer.setSize(width, height); |
| 123 | this.renderer.domElement.style.position = 'absolute'; |
| 124 | WebGLoutput.appendChild(this.renderer.domElement); |
| 125 | |
| 126 | this.controls = new THREE.TrackballControls(this.camera, this.renderer.domElement); |
| 127 | |
| 128 | this.controls.rotateSpeed = 1; |
| 129 | this.controls.staticMoving = true; |
| 130 | this.controls.minDistance = 500; |
| 131 | this.controls.maxDistance = 6000; |
| 132 | this.controls.addEventListener('change', this.render); |
| 133 | |
| 134 | let i = 0; |
| 135 | const len = this.option.data.length; |
| 136 | |
| 137 | for (; i < len; i++) { |
| 138 | |
| 139 | const element = document.createElement('div'); |
| 140 | element.className = 'element'; |
| 141 | element.dataset.index = i |
| 142 | element.style.backgroundColor = `rgba( 0, 127, 127, ${Math.random() * 0.5 + 0.25} )`; |
| 143 | element.onclick = () => { |
| 144 | if (element.dataset.isScale === 'true') { |
| 145 | element.style.transform = element.dataset.oldTransform // 恢复备份 |
| 146 | element.dataset.isScale = false |
| 147 | } else { |
| 148 | element.dataset.isScale = true |
| 149 | element.dataset.oldTransform = element.style.transform // 备个份 |
| 150 | element.style.transition = '1s' |
| 151 | element.style.transform = `translate(-50%, -50%) matrix3d(8, 0, 0, 0, 0, -8, 0, 0, 0, 0, 8, 0, 0, 0, 1000, 1)` |
| 152 | } |
| 153 | |
| 154 | } |
| 155 | |
| 156 | const symbol = document.createElement('div'); |
| 157 | symbol.className = 'symbol'; |
| 158 | symbol.textContent = this.option.data[i]; |
| 159 | element.appendChild(symbol); |
| 160 | |
| 161 | const object = new THREE.CSS3DObject(element); |
| 162 | object.position.x = Math.random() * 4000 - 2000; |
nothing calls this directly
no test coverage detected