-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
108 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,51 @@ | ||
// GLTF EXTENSION: KHR_lights_punctual | ||
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual | ||
|
||
import assert from '../utils/assert'; | ||
import GLTFScenegraph from '../gltf-scenegraph'; | ||
import {KHR_LIGHTS_PUNCTUAL} from '../gltf-constants'; | ||
|
||
// GLTF EXTENSION: KHR_lights_punctual | ||
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual | ||
// eslint-disable-next-line camelcase | ||
export default class KHR_lights_punctual { | ||
static get name() { | ||
return KHR_LIGHTS_PUNCTUAL; | ||
} | ||
|
||
static decode(gltfData, options) { | ||
const gltfScenegraph = new GLTFScenegraph(gltfData); | ||
export function decode(gltfData, options) { | ||
const gltfScenegraph = new GLTFScenegraph(gltfData); | ||
const {json} = gltfScenegraph; | ||
|
||
// Move the light array out of the extension and remove the extension | ||
const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL); | ||
if (extension) { | ||
gltfScenegraph.json.lights = extension.lights; | ||
gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL); | ||
} | ||
// Move the light array out of the extension and remove the extension | ||
const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL); | ||
if (extension) { | ||
gltfScenegraph.json.lights = extension.lights; | ||
gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL); | ||
} | ||
|
||
// Any nodes that have the extension, add lights field pointing to light object | ||
// and remove the extension | ||
for (const node of gltfScenegraph.nodes || []) { | ||
const nodeExtension = node.extensions && node.extensions.KHR_lights_punctual; | ||
if (nodeExtension) { | ||
node.light = gltfScenegraph._get('lights', nodeExtension.light); | ||
delete node.extensions.KHR_lights_punctual; | ||
} | ||
// Any nodes that have the extension, add lights field pointing to light object | ||
// and remove the extension | ||
for (const node of json.nodes || []) { | ||
const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL); | ||
if (nodeExtension) { | ||
node.light = nodeExtension.light; | ||
} | ||
gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL); | ||
} | ||
} | ||
|
||
// Move the light ar ray out of the extension and remove the extension | ||
static encode(gltfData, options) { | ||
const gltfScenegraph = new GLTFScenegraph(gltfData); | ||
const {json} = gltfScenegraph; | ||
// Move the light ar ray out of the extension and remove the extension | ||
export function encode(gltfData, options) { | ||
const gltfScenegraph = new GLTFScenegraph(gltfData); | ||
const {json} = gltfScenegraph; | ||
|
||
if (json.lights) { | ||
const extension = gltfScenegraph.addExtensions(KHR_LIGHTS_PUNCTUAL); | ||
assert(!extension.lights); | ||
extension.lights = json.lights; | ||
delete json.lights; | ||
} | ||
if (json.lights) { | ||
const extension = gltfScenegraph.addExtensions(KHR_LIGHTS_PUNCTUAL); | ||
assert(!extension.lights); | ||
extension.lights = json.lights; | ||
delete json.lights; | ||
} | ||
|
||
// Any nodes that have lights field pointing to light object | ||
// add the extension | ||
if (gltfScenegraph.json.lights) { | ||
for (const light of gltfScenegraph.json.lights) { | ||
const node = light.node; | ||
gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light); | ||
} | ||
delete gltfScenegraph.json.lights; | ||
// Any nodes that have lights field pointing to light object | ||
// add the extension | ||
if (gltfScenegraph.json.lights) { | ||
for (const light of gltfScenegraph.json.lights) { | ||
const node = light.node; | ||
gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light); | ||
} | ||
delete gltfScenegraph.json.lights; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
/* eslint-disable camelcase */ | ||
import KHR_draco_mesh_compression from './KHR_draco_mesh_compression'; | ||
import KHR_lights_punctual from './KHR_lights_punctual'; | ||
import * as KHR_draco_mesh_compression from './KHR_draco_mesh_compression'; | ||
import * as KHR_lights_punctual from './KHR_lights_punctual'; | ||
// import UBER_POINT_CLOUD_COMPRESSION from './KHR_draco_mesh_compression'; | ||
|
||
export const EXTENSIONS = { | ||
KHR_draco_mesh_compression, | ||
KHR_lights_punctual | ||
}; | ||
|
||
export async function decodeExtensions(gltf, options, context) { | ||
export async function decodeExtensions(gltf, options = {}, context) { | ||
options.gltf = options.gltf || {}; | ||
for (const extensionName in EXTENSIONS) { | ||
const disableExtension = extensionName in options && !options[extensionName]; | ||
if (!disableExtension) { | ||
const excludes = options.gltf.excludeExtensions || {}; | ||
const exclude = extensionName in excludes && !excludes[extensionName]; | ||
if (!exclude) { | ||
const extension = EXTENSIONS[extensionName]; | ||
// Note: We decode extensions sequentially, this might not be necessary | ||
// Currently we only have glTF, but when we add Basis we may revisit | ||
// Note: We decode async extensions sequentially, this might not be necessary | ||
// Currently we only have Draco, but when we add Basis we may revisit | ||
await extension.decode(gltf, options, context); | ||
// TODO - warn if extension cannot be decoded synchronously? | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters