threepipe
Version:
A 3D viewer framework built on top of three.js in TypeScript with a focus on quality rendering, modularity and extensibility.
67 lines • 2.67 kB
JavaScript
var _a;
import { ObjectLoader } from 'three';
export class GLTFLightExtrasExtension {
}
_a = GLTFLightExtrasExtension;
GLTFLightExtrasExtension.WebGiLightExtrasExtension = 'WEBGI_light_extras';
/**
* Also {@link Export}
* @param _
*/
GLTFLightExtrasExtension.Import = (_) => ({
name: '__' + _a.WebGiLightExtrasExtension, // __ is prefix so that the extension is added to userdata, and we can process later in afterRoot
afterRoot: async (result) => {
const scenes = result.scenes || (result.scene ? [result.scene] : []);
scenes.forEach(s => {
s.traverse((o) => {
if (!o.isLight)
return;
const ext = o.userData?.gltfExtensions?.[_a.WebGiLightExtrasExtension];
if (!ext) {
return;
}
// castShadow is in GLTFObject3DExtrasExtension
if (!o.shadow && ext.shadow) {
console.error('Light has no shadow, cannot import', o, ext);
}
// keep updated with ObjectLoader.js
if (ext.shadow && o.shadow) {
if (ext.shadow.bias !== undefined)
o.shadow.bias = ext.shadow.bias;
if (ext.shadow.normalBias !== undefined)
o.shadow.normalBias = ext.shadow.normalBias;
if (ext.shadow.radius !== undefined)
o.shadow.radius = ext.shadow.radius;
if (ext.shadow.mapSize !== undefined)
o.shadow.mapSize.fromArray(ext.shadow.mapSize);
if (ext.shadow.camera !== undefined) {
o.shadow.camera = new ObjectLoader().parseObject(ext.shadow.camera, {}, {}, {}, {});
}
}
delete o.userData.gltfExtensions[_a.WebGiLightExtrasExtension];
});
});
},
});
/**
* Also {@link Import}
*/
GLTFLightExtrasExtension.Export = (w) => ({
writeNode: (object, nodeDef) => {
if (!object?.isLight)
return;
if (!nodeDef.extensions)
nodeDef.extensions = {};
const dat = {};
if (object.shadow) { // castShadow is in GLTFObject3DExtrasExtension
dat.shadow = object.shadow.toJSON();
}
if (Object.keys(dat).length > 0) {
nodeDef.extensions[_a.WebGiLightExtrasExtension] = dat;
w.extensionsUsed[_a.WebGiLightExtrasExtension] = true;
}
},
});
// see GLTFDracoExportPlugin
GLTFLightExtrasExtension.Textures = undefined;
//# sourceMappingURL=GLTFLightExtrasExtension.js.map