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
Conversation
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
Snapshot stored with reference name: Test environment: To test a playground add it to the URL, for example: https://babylonsnapshots.z22.web.core.windows.net/refs/pull/14653/merge/index.html#WGZLGJ#4600 Links to test babylon tools with this snapshot: https://playground.babylonjs.com/?snapshot=refs/pull/14653/merge To test the snapshot in the playground with a playground ID add it after the snapshot query string: https://playground.babylonjs.com/?snapshot=refs/pull/14653/merge#BCU1XR#0 |
Thanks for the PR, but please be patient for the review as the team is on Christmas vacation. |
There was a problem hiding this 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.
to determine whether the user has forced a camera target value
yeah , u are right |
There was a problem hiding this 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.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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 { |
There was a problem hiding this comment.
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
This pull request has been marked as stale because it has been inactive for more than 14 days. Please update to "unstale". |
This pull request has been marked as stale because it has been inactive for more than 14 days. Please update to "unstale". |
Closing with no activity |
https://forum.babylonjs.com/t/zoomtomouselocation-issue-after-camera-settarget/46716
fixed bug : zoomtomouselocation-issue-after-camera-settarget