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

update camera's target when the mouse wheel is rolling for zoomtomouselocation #14653

Closed
wants to merge 8 commits into from

Conversation

ecojust
Copy link

@ecojust ecojust commented Dec 27, 2023

https://forum.babylonjs.com/t/zoomtomouselocation-issue-after-camera-settarget/46716

fixed bug : zoomtomouselocation-issue-after-camera-settarget

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 27, 2023

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.

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 27, 2023

@ecojust ecojust changed the title update camera's target when the mouse wheel is rolling update camera's target when the mouse wheel is rolling for zoomtomouselocation Dec 27, 2023
@Popov72
Copy link
Contributor

Popov72 commented Dec 27, 2023

Thanks for the PR, but please be patient for the review as the team is on Christmas vacation.

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.

I do not think this is the right fix but I am terrible with Cameras :-)

Could we not update some of the parameters only once when we actually sets the new target ?

The new change is pretty heavy to run every frame.

juzisang added 2 commits January 3, 2024 18:53
to determine whether the user has forced a camera target value
@ecojust
Copy link
Author

ecojust commented Jan 3, 2024

I do not think this is the right fix but I am terrible with Cameras :-)

Could we not update some of the parameters only once when we actually sets the new target ?

The new change is pretty heavy to run every frame.

yeah , u are right
I have used a variable to limit the occurrence of this behavior (_targetSetManually)

@ecojust ecojust requested a review from sebavan January 3, 2024 12:35
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.

I am still not sure it is the right approach overall.

First, we know if someone called setTarget and we could use this as our trigger.

Second, I wonder if some parameters could be computed once in setTarget only so that the render loop does not change if setTarget has not been called.

Lets wait on @PolygonalSun inputs.

Comment on lines 215 to 220
const direction = camera.target.subtract(camera.position).normalize();
const ray = new Ray(camera.position, direction, Number.MAX_SAFE_INTEGER);
const ground = Plane.FromPositionAndNormal(Vector3.Zero(), camera.upVector);
const distance = ray.intersectsPlane(ground) ?? 0;
const intersectionPoint = ray.origin.add(ray.direction.scale(distance));
camera.setTarget(intersectionPoint);
Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of this code is similar to the code found in _updateHitPlane and _getPosition. It'd be worth looking into combining some of the new code with the _updateHitPlane code so you're not potentially creating two rays and planes on a single frame.

@@ -61,6 +61,8 @@ export class ArcRotateCamera extends TargetCamera {
protected _target: Vector3;
@serializeAsMeshReference("targetHost")
protected _targetHost: Nullable<AbstractMesh>;
@serialize("targetSetManually")
protected _targetSetManually: Boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason why this can't just be a public variable instead of a property with a protected variable?

Copy link
Author

Choose a reason for hiding this comment

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

It is considered here that this variable is used in conjunction with other functions and should not be explicitly modified separately
For example, modify this parameter with setTarget

const distance = ray.intersectsPlane(ground) ?? 0;
const intersectionPoint = ray.origin.add(ray.direction.scale(distance));
camera.setTarget(intersectionPoint);
camera.targetSetManually = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this value is set outside of the code (possibly by the user) to allow the user to force the target to be set for a single frame and then is reset to false. What is the use case for this to be set to true? Is it something to be set to true once (as needed) or repeated more frequently?

Copy link
Author

Choose a reason for hiding this comment

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

This value can now be set to true when passed in by setTarget.

The use case that is true is :
to tell the mouse wheel event that the user forcibly changed the camera's target,
and that the camera's reasonable target needs to be updated once to ensure proper use of zoomToMouseLocation

@PolygonalSun PolygonalSun marked this pull request as draft January 3, 2024 21:21
@PolygonalSun
Copy link
Contributor

Marking as draft. I think that this needs a bit more work before we can merge it.

*/
public setTarget(target: AbstractMesh | Vector3, toBoundingCenter = false, allowSamePosition = false, cloneAlphaBetaRadius = false): void {
public setTarget(target: AbstractMesh | Vector3, toBoundingCenter = false, allowSamePosition = false, cloneAlphaBetaRadius = false, setManually = false): void {
Copy link
Author

Choose a reason for hiding this comment

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

@sebavan @PolygonalSun
My previous idea was to change the _targetSetManually variable by adding a parameter to setTarget so that the user does not have to explicitly change the parameter
If you agree, I can resume the previous operation

Copy link

github-actions bot commented Mar 14, 2024

This pull request has been marked as stale because it has been inactive for more than 14 days. Please update to "unstale".

@github-actions github-actions bot added stale and removed stale labels Mar 14, 2024
Copy link

This pull request has been marked as stale because it has been inactive for more than 14 days. Please update to "unstale".

@github-actions github-actions bot added the stale label Mar 30, 2024
@deltakosh
Copy link
Contributor

Closing with no activity

@deltakosh deltakosh closed this Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants