Skip to content
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

PhysicsViewer, bbhelper fixes #16442

Merged
merged 2 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion packages/dev/core/src/Culling/Helper/boundingInfoHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { AbstractMesh } from "core/Meshes/abstractMesh";
import type { AbstractEngine } from "core/Engines/abstractEngine";
import type { IBoundingInfoHelperPlatform } from "./IBoundingInfoHelperPlatform";
import type { ThinEngine } from "core/Engines";
import { Logger } from "core/Misc/logger";

/**
* Utility class to help with bounding info management
Expand Down Expand Up @@ -63,6 +64,10 @@ export class BoundingInfoHelper {
* If called multiple times, the second, third, etc calls will perform a union of the bounding boxes calculated in the previous calls
*/
public batchProcess(): void {
if (this._platform === null) {
Logger.Warn("Helper is not initialized. Skipping batch.");
return;
}
this._platform.processMeshList();
}

Expand All @@ -71,13 +76,16 @@ export class BoundingInfoHelper {
* @returns a promise that resolves when the bounding info is/are computed
*/
public async batchFetchResultsAsync(): Promise<void> {
await this._initializePlatform();
return this._platform.fetchResultsForMeshListAsync();
}

/**
* Dispose and release associated resources
*/
public dispose(): void {
this._platform.dispose();
if (this._platform) {
this._platform.dispose();
}
}
}
17 changes: 12 additions & 5 deletions packages/dev/core/src/Debug/physicsViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class PhysicsViewer {
private _inertiaRenderFunction: () => void;
private _constraintRenderFunction: () => void;
private _utilityLayer: Nullable<UtilityLayerRenderer>;
private _ownUtilityLayer = false;

private _debugBoxMesh: Mesh;
private _debugSphereMesh: Mesh;
Expand All @@ -77,8 +78,9 @@ export class PhysicsViewer {
* Creates a new PhysicsViewer
* @param scene defines the hosting scene
* @param size Physics V2 size scalar
* @param utilityLayer The utility layer the viewer will be added to
*/
constructor(scene?: Scene, size?: number) {
constructor(scene?: Scene, size?: number, utilityLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer) {
this._scene = scene || EngineStore.LastCreatedScene;
if (!this._scene) {
return;
Expand All @@ -89,9 +91,14 @@ export class PhysicsViewer {
this._physicsEnginePlugin = physicEngine.getPhysicsPlugin();
}

this._utilityLayer = new UtilityLayerRenderer(this._scene, false);
this._utilityLayer.pickUtilitySceneFirst = false;
this._utilityLayer.utilityLayerScene.autoClearDepthAndStencil = true;
if (utilityLayer) {
this._utilityLayer = utilityLayer;
} else {
this._utilityLayer = new UtilityLayerRenderer(this._scene, false);
this._utilityLayer.pickUtilitySceneFirst = false;
this._utilityLayer.utilityLayerScene.autoClearDepthAndStencil = true;
this._ownUtilityLayer = true;
}
if (size) {
this._constraintAxesSize = 0.4 * size;
this._constraintAngularSize = 0.4 * size;
Expand Down Expand Up @@ -1120,7 +1127,7 @@ export class PhysicsViewer {
this._scene = null;
this._physicsEnginePlugin = null;

if (this._utilityLayer) {
if (this._ownUtilityLayer && this._utilityLayer) {
this._utilityLayer.dispose();
this._utilityLayer = null;
}
Expand Down