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

Fix scene not clearing in some Default Rendering Pipeline with multicamera cases #12905

Merged
merged 5 commits into from
Sep 1, 2022
Merged

Fix scene not clearing in some Default Rendering Pipeline with multicamera cases #12905

merged 5 commits into from
Sep 1, 2022

Conversation

carolhmj
Copy link
Contributor

Examples of where this would happen:

…ges in defaultRenderingPipeline, to ensure we call autoClear whenever we set more than 2 active cameras and have post-processes.
Copy link
Member

@RaananW RaananW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :-)

I see Proxies are helpful in that case :-)

If we will use a Proxy somewhere else as well it might be helpful to move the makeArrayAProxy functionality to tools.

Is there anything we need to do when disposing the proxied array?

@deltakosh
Copy link
Contributor

Really appreciate the use of Reflect and Proxy. I agree with @RaananW let's make that part of tools just in case

packages/dev/core/src/scene.ts Outdated Show resolved Hide resolved
packages/dev/core/src/scene.ts Outdated Show resolved Hide resolved
@carolhmj carolhmj requested review from RaananW and sebavan August 30, 2022 13:51
@azure-pipelines
Copy link

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@carolhmj
Copy link
Contributor Author

@sebavan sharing the implementation with the render target texture now :D

@azure-pipelines
Copy link

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@azure-pipelines
Copy link

Copy link
Member

@sebavan sebavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GG !!!!

@sebavan
Copy link
Member

sebavan commented Aug 31, 2022

@RaananW for final merge ?

@RaananW RaananW merged commit 5322d44 into BabylonJS:master Sep 1, 2022
return Reflect.set(target, property, value);
}

private static _ProxyPushOrUnshift<T>(operation: "push" | "unshift", observable: Observable<INotifyArrayChangeType<T>>, target: Array<T>, ...values: Array<T>): number {
observable.notifyObservers({ target, values, operation });
observable.notifyObservers({ target, previousLength: target.length });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that for the renderList array of the RenderTargetTexture class it is a change in behaviour: the push operation was done before the additional code was executed. Here, the additional code will be execute first (through the notifyObservers call) and the push operation will be done afterwards.

I don't know if it will break something or not, but it's for sure a different behaviour. To keep the existing behaviour it would be safer to notify the observers after the operation has been done.

Also, I think it should be wise to always notify the observers at the same point (either before or after the operation on the array has been performed) for the sake of clarity. Currently:

  • set, push/unshift, delete: observers notified before the operation
  • pop/shift, splice: observers notified after the operation

Or maybe it is on purpose? In that case, adding some doc on MakeObservableArray explaining when the observers are notified in each case would probably be a good idea.

}
private _startObservingRenderListEvents() {
this._renderListHasChangedObserver = this._renderListHasChangedObservable.add(({ target, previousLength }) => {
if (target && previousLength && ((target.length > 0 && previousLength === 0) || (target.length === 0 && previousLength > 0))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to check previousLength !== undefined and not simply previousLength in target && previousLength

return Reflect.deleteProperty(target, property);
}

private static _ProxyPopOrShift<T>(operation: "pop" | "shift", observable: Observable<INotifyArrayChangeType<T>>, target: Array<T>) {
const value = operation === "pop" ? Array.prototype.pop.apply(target) : Array.prototype.shift.apply(target);
observable.notifyObservers({ target, operation, values: [value] });
observable.notifyObservers({ target, previousLength: target.length });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should get the previous length before doing the operation and pass it to the observers, as previousLength: target.length will in reality pass the current length.

return value;
}

private static _ProxySplice<T>(observable: Observable<INotifyArrayChangeType<T>>, target: Array<T>, start: number, deleteNumber: number, ...added: Array<T>) {
const values = Array.prototype.splice.apply(target, [start, deleteNumber, added]);
observable.notifyObservers({ target, values, operation: "splice" });
observable.notifyObservers({ target, previousLength: target.length });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment than above.

@carolhmj carolhmj deleted the fixSceneClearWhenPostProcessRTTCameraIsDifferentThanSceneCamera branch September 2, 2022 17:31
@sebavan sebavan mentioned this pull request Sep 13, 2022
RaananW pushed a commit that referenced this pull request Dec 9, 2022
…amera cases (#12905)

* Fixes to scene clear when there are multiple cameras and post-processes.

* Finish observable on activeCameras property and respond to these changes in defaultRenderingPipeline, to ensure we call autoClear whenever we set more than 2 active cameras and have post-processes.

* Move observable array logic to a separate scene

* Code Review

* Update rendertargettexture to use the new observable array.

Former-commit-id: 01910c8afd4b39194841fe06b78db52741d7fa45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants