-
Notifications
You must be signed in to change notification settings - Fork 35
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
Gizmo Normal Snapping #2539
Gizmo Normal Snapping #2539
Changes from 7 commits
da56ced
2781261
956adc1
609866e
f0a506d
5edbb04
a47d1c1
6093f61
fc37031
f7be198
1a98418
0e224e9
73ddfa6
1d6af39
1d01595
eaf5a8d
9348b90
c18f820
e575bf0
78eb92c
d73ba82
2e08856
bc3cef1
4c2ba6a
fb30528
125b217
30c4482
96940bc
24cd4e2
6e99d14
ce1db5d
3c37e31
bea2a06
e8d3d10
a3313e2
079fcf9
aafadb0
2e19a05
e22785d
c5f6e14
8222fb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -773,6 +773,80 @@ export class CameraControls { | |
}) | ||
} | ||
|
||
async updateCameraToAxis( | ||
axis: 'x' | 'y' | 'z' | '-x' | '-y' | '-z' | 'reset' | ||
): Promise<void> { | ||
if (axis === 'reset') { | ||
await this.resetCameraPosition() | ||
return | ||
} | ||
|
||
const distance = this.camera.position.distanceTo(this.target) | ||
|
||
let vantage = { x: 0, y: 0, z: 0 } | ||
let up = { x: 0, y: 0, z: 0 } | ||
|
||
if (axis === 'x') { | ||
vantage = { x: distance, y: 0, z: 0 } | ||
up = { x: 0, y: 0, z: 1 } | ||
} else if (axis === 'y') { | ||
vantage = { x: 0, y: distance, z: 0 } | ||
up = { x: 0, y: 0, z: 1 } | ||
} else if (axis === 'z') { | ||
vantage = { x: 0, y: 0, z: distance } | ||
up = { x: -1, y: 0, z: 0 } | ||
} else if (axis === '-x') { | ||
vantage = { x: -distance, y: 0, z: 0 } | ||
up = { x: 0, y: 0, z: 1 } | ||
} else if (axis === '-y') { | ||
vantage = { x: 0, y: -distance, z: 0 } | ||
up = { x: 0, y: 0, z: 1 } | ||
} else if (axis === '-z') { | ||
vantage = { x: 0, y: 0, z: -distance } | ||
up = { x: -1, y: 0, z: 0 } | ||
} | ||
|
||
await this.engineCommandManager.sendSceneCommand({ | ||
type: 'modeling_cmd_req', | ||
cmd_id: uuidv4(), | ||
cmd: { | ||
type: 'default_camera_look_at', | ||
center: { x: 0, y: 0, z: 0 }, | ||
vantage: vantage, | ||
up: up, | ||
}, | ||
}) | ||
await this.engineCommandManager.sendSceneCommand({ | ||
type: 'modeling_cmd_req', | ||
cmd_id: uuidv4(), | ||
cmd: { | ||
type: 'default_camera_get_settings', | ||
}, | ||
}) | ||
} | ||
|
||
async resetCameraPosition(): Promise<void> { | ||
await this.engineCommandManager.sendSceneCommand({ | ||
type: 'modeling_cmd_req', | ||
cmd_id: uuidv4(), | ||
cmd: { | ||
type: 'default_camera_look_at', | ||
center: { x: 0, y: 0, z: 0 }, | ||
vantage: { x: 0, y: -128, z: 64 }, | ||
up: { x: 0, y: 0, z: 1 }, | ||
}, | ||
}) | ||
await this.engineCommandManager.sendSceneCommand({ | ||
type: 'modeling_cmd_req', | ||
cmd_id: uuidv4(), | ||
cmd: { | ||
type: 'zoom_to_fit', | ||
object_ids: [], // leave empty to zoom to all objects | ||
padding: 0.2, // padding around the objects | ||
}, | ||
}) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I couldn't help but make a commit, just cause I wanted to see this working. All I did is change the vantage to where the camera is on boot up But immediately followed up by a zoom to fit means it will look exactly the same as when you refresh the page. Note: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we fixed my viewport issue today, I could test this one... In my case it does not work. The camera resets to weird position somewhere far away. My findings: 1. Unexpected Camera Position: After executing both commands, the camera ended up in a strange position, far from where it should have been. The coordinates before resetting were something like 2. Testing Commands Individually: When I tested each command ( 3. Pause Between Commands: I suspected that the rapid change from large coordinate values to small ones and back to large values might be causing the issue. I tried adding a short pause (1000ms) between the two commands to give the server time to process the changes, but it didn't help. 4. Eliminating the Coordinate Jump: Instead of using fixed small values for the
instead of:
This approach worked and the camera reset correctly without any issues. but in case of moving camera super far away you might need to click reset 2 times :DD 5. Further Investigation: I found it strange that using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay this sounds like a good work around, but maybe the zoom to fit should be robust against this kind of thing? Maybe I'll mess with it and raise something with the engine team because I'm not sure it should require us to finagle like this. |
||
|
||
async tweenCameraToQuaternion( | ||
targetQuaternion: Quaternion, | ||
targetPosition = new Vector3(), | ||
|
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.
Could we change this so to something like
And then for the default camera look at keep the users's target
Sorry if if this is different from what I originally asked for, but think this will be better as it respects the user's current target, and just rotates the camera to a different perspective.
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.
now I can see that too ! so much better to code with viewport on :DDD