1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| import * as THREE from "three" let { innerWidth: WIDTH, innerHeight: HEIGHT } = window let { scene, camera, renderer } = consts, state = new State() let b1, b2, b3, b4;
let div_WebGL = document.createElement('div') div_WebGL.id = 'webgl-output' document.body.appendChild(div_WebGL) let container = document.getElementById('webgl-output')
class DrBaseScene { static getInstance(){ if(!DrBaseScene.instance){ DrBaseScene.instance = new DrBaseScene() } return DrBaseScene.instance } constructor() { this.animate = this.animate.bind(this) this.init() } init() { this.setScene() this.setGUI() this.setCamera() this.addAxis() this.iniPlane() this.setLights() this.setRender() this.orbitControls() this.animate() this.windowResize() } setRender() { renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false, }); renderer.setSize(WIDTH, HEIGHT); renderer.setClearColor(0x220022, 1); container.appendChild(renderer.domElement); } animate() { requestAnimationFrame(this.animate); this.render(); } car(z) { b2.position.z = z } }
let f1 = DrBaseScene.getInstance() f1.car(10)
let f2 = DrBaseScene.getInstance() f2.car(0)
let f3= DrBaseScene.getInstance() f3.car(-10)
|