Skip to content

KHR_node_visibility #15754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { AbstractMesh } from "core/Meshes/abstractMesh";
import type { GLTFLoader } from "../glTFLoader";
import type { IGLTFLoaderExtension } from "../glTFLoaderExtension";
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry";

const NAME = "KHR_node_visibility";

declare module "../../glTFFileLoader" {
// eslint-disable-next-line jsdoc/require-jsdoc
export interface GLTFLoaderExtensionOptions {
/**
* Defines options for the KHR_node_visibility extension.
*/
// NOTE: Don't use NAME here as it will break the UMD type declarations.
["KHR_node_visibility"]: {};
}
}

/**
* Loader extension for KHR_node_visibility
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export class KHR_node_visibility implements IGLTFLoaderExtension {
/**
* The name of this extension.
*/
public readonly name = NAME;
/**
* Defines whether this extension is enabled.
*/
public enabled: boolean;

private _loader: GLTFLoader;

/**
* @internal
*/
constructor(loader: GLTFLoader) {
this._loader = loader;
this.enabled = loader.isExtensionUsed(NAME);
}

public async onReady(): Promise<void> {
this._loader.gltf.nodes?.forEach((node) => {
node._primitiveBabylonMeshes?.forEach((mesh) => {
mesh.inheritVisibility = true;
});
// When the JSON Pointer is used we need to change both the transform node and the primitive meshes to the new value.
if (node.extensions?.KHR_node_visibility) {
if (node.extensions?.KHR_node_visibility.visible === false) {
if (node._babylonTransformNode) {
(node._babylonTransformNode as AbstractMesh).isVisible = false;
}
node._primitiveBabylonMeshes?.forEach((mesh) => {
mesh.isVisible = false;
});
}
}
});
}

public dispose() {
(this._loader as any) = null;
}
}

unregisterGLTFExtension(NAME);
registerGLTFExtension(NAME, true, (loader) => new KHR_node_visibility(loader));
1 change: 1 addition & 0 deletions packages/dev/loaders/src/glTF/2.0/Extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export * from "./MSFT_lod";
export * from "./MSFT_minecraftMesh";
export * from "./MSFT_sRGBFactors";
export * from "./KHR_interactivity";
export * from "./KHR_node_visibility";
export * from "./ExtrasAsMetadata";
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/tools/tests/test/visualization/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,11 @@
"playgroundId": "#WGZLGJ#3009",
"referenceImage": "gltfTextureLinearInterpolation.png"
},
{
"title": "GLTF Node visibility test",
"playgroundId": "#80DN99#3",
"referenceImage": "gltfNodeVisibility.png"
},
{
"title": "Asset Containers",
"playgroundId": "#P3U079#19",
Expand Down