UNPKG

three-game-engine

Version:

Simple light-weight game engine using three.js, three-mesh-ui and rapier

33 lines (32 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Component_1 = require("../Component"); const THREE = require("three"); const ThreeJSHelpers_1 = require("../util/ThreeJSHelpers"); class LightComponent extends Component_1.default { load() { let light = null; const lightTypes = { AmbientLight: THREE.AmbientLight, DirectionalLight: THREE.DirectionalLight, HemisphereLight: THREE.HemisphereLight, PointLight: THREE.PointLight, RectAreaLight: THREE.RectAreaLight, SpotLight: THREE.SpotLight }; const LightClass = lightTypes[this.jsonData.type]; if (LightClass) { light = new LightClass(); light.name = this.jsonData.type.toLowerCase(); } else { throw new Error(`GameObject: error creating ThreeJS light: unknown light type: ${this.jsonData.type}`); } const objectProps = { ...this.jsonData }; delete objectProps.type; (0, ThreeJSHelpers_1.setObject3DProps)(light, objectProps); this.light = light; this.gameObject.threeJSGroup.add(this.light); } } exports.default = LightComponent;