UNPKG

threepipe

Version:

A 3D viewer framework built on top of three.js in TypeScript with a focus on quality rendering, modularity and extensibility.

127 lines 5.53 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { DirectionalLight } from 'three'; import { iLightCommons } from '../object/iLightCommons'; import { uiColor, uiNumber, uiPanelContainer, uiSlider, uiToggle, uiVector } from 'uiconfig.js'; import { onChange2, onChange3 } from 'ts-browser-helpers'; import { bindToValue } from '../../three'; /** * Extension of three.js DirectionalLight with additional properties for serialization and UI * A directional light is a light source that has a position but no dimensions - a single point in space that emits light in a specific direction. * * Note - gltf serialization is handled by {@link GLTFLightExtrasExtension} * * @category Lights */ // todo: add Light section in the readme detailing these ...2 lights let DirectionalLight2 = class DirectionalLight2 extends DirectionalLight { _mapSizeChanged() { this.shadow.map?.dispose(); this.shadow.mapPass?.dispose(); this.shadow.map = null; this.shadow.mapPass = null; this.setDirty({ change: 'shadowMapSize' }); } _shadowFrustumChanged() { const v = this.shadowFrustum; this.shadow.camera.left = -v / 2; this.shadow.camera.right = v / 2; this.shadow.camera.top = v / 2; this.shadow.camera.bottom = -v / 2; this.shadow.camera.updateProjectionMatrix(); this.setDirty({ change: 'shadowFrustum' }); } _shadowCamUpdate(change) { this.shadow.camera.updateProjectionMatrix(); this.setDirty({ change }); } constructor(color, intensity) { super(color, intensity); this.assetType = 'light'; this.setDirty = iLightCommons.setDirty; this.refreshUi = iLightCommons.refreshUi; this.isDirectionalLight2 = true; this.target.position.set(0, 0, -1); // because of GLTF spec: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_lights_punctual this.add(this.target); // todo: make sure the child isn't exported in gltf iLightCommons.upgradeLight.call(this); this.shadowFrustum = 10; } autoScale() { console.warn('DirectionalLight2: AutoScale not supported on Lights'); return this; } autoCenter() { console.warn('DirectionalLight2: AutoCenter not supported on Lights'); return this; } /** * @deprecated use `this` instead */ get lightObject() { return this; } /** * @deprecated use `this` instead */ get modelObject() { return this; } }; __decorate([ uiToggle('Enabled'), onChange3('setDirty') ], DirectionalLight2.prototype, "visible", void 0); __decorate([ uiColor('Color', (that) => ({ onChange: () => that.setDirty() })) ], DirectionalLight2.prototype, "color", void 0); __decorate([ uiSlider('Intensity', [0, 100], 0.01), onChange3('setDirty') ], DirectionalLight2.prototype, "intensity", void 0); __decorate([ uiVector('Position', undefined, undefined, (that) => ({ onChange: () => that.setDirty() })) ], DirectionalLight2.prototype, "position", void 0); __decorate([ uiVector('Rotation', undefined, undefined, (that) => ({ onChange: () => that.setDirty() })) ], DirectionalLight2.prototype, "rotation", void 0); __decorate([ uiToggle('Cast Shadow'), onChange3('setDirty') ], DirectionalLight2.prototype, "castShadow", void 0); __decorate([ uiVector('Shadow Map Size'), bindToValue({ obj: 'shadow', key: 'mapSize', onChange: DirectionalLight2.prototype._mapSizeChanged, onChangeParams: false }) ], DirectionalLight2.prototype, "shadowMapSize", void 0); __decorate([ uiSlider('Shadow Bias', [-0.001, 0.001], 0.00001), bindToValue({ obj: 'shadow', key: 'bias', onChange: 'setDirty' }) ], DirectionalLight2.prototype, "shadowBias", void 0); __decorate([ uiSlider('Shadow Normal Bias', [-0.1, 0.1], 0.005), bindToValue({ obj: 'shadow', key: 'normalBias', onChange: 'setDirty' }) ], DirectionalLight2.prototype, "shadowNormalBias", void 0); __decorate([ uiSlider('Shadow Radius', [0, 5], 0.01), bindToValue({ obj: 'shadow', key: 'radius', onChange: 'setDirty' }) ], DirectionalLight2.prototype, "shadowRadius", void 0); __decorate([ uiSlider('Shadow Frustum', [0.1, 50], 0.01), onChange2(DirectionalLight2.prototype._shadowFrustumChanged) ], DirectionalLight2.prototype, "shadowFrustum", void 0); __decorate([ uiNumber('Shadow Near'), bindToValue({ obj: 'shadow', key: ['camera', 'near'], onChange: DirectionalLight2.prototype._shadowCamUpdate }) ], DirectionalLight2.prototype, "shadowNear", void 0); __decorate([ uiNumber('Shadow Far'), bindToValue({ obj: 'shadow', key: ['camera', 'far'], onChange: DirectionalLight2.prototype._shadowCamUpdate }) ], DirectionalLight2.prototype, "shadowFar", void 0); DirectionalLight2 = __decorate([ uiPanelContainer('Directional Light') ], DirectionalLight2); export { DirectionalLight2 }; //# sourceMappingURL=DirectionalLight2.js.map