Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
a7388be2
Commit
a7388be2
authored
5 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
mol-canvas3d: fixed camera focus
parent
4635bdff
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/mol-canvas3d/camera.ts
+7
-16
7 additions, 16 deletions
src/mol-canvas3d/camera.ts
src/mol-canvas3d/canvas3d.ts
+5
-6
5 additions, 6 deletions
src/mol-canvas3d/canvas3d.ts
with
12 additions
and
22 deletions
src/mol-canvas3d/camera.ts
+
7
−
16
View file @
a7388be2
...
...
@@ -90,30 +90,21 @@ class Camera implements Object3D {
return
ret
;
}
getFocus
(
target
:
Vec3
,
radius
:
number
,
dir
?:
Vec3
):
Partial
<
Camera
.
Snapshot
>
{
getFocus
(
target
:
Vec3
,
radius
:
number
):
Partial
<
Camera
.
Snapshot
>
{
const
fov
=
this
.
state
.
fov
const
{
width
,
height
}
=
this
.
viewport
const
aspect
=
width
/
height
const
aspectFactor
=
(
height
<
width
?
1
:
aspect
)
const
currentDistance
=
Vec3
.
distance
(
this
.
state
.
position
,
target
)
const
targetDistance
=
Math
.
abs
((
radius
/
aspectFactor
)
/
Math
.
sin
(
fov
/
2
))
const
deltaDistance
=
Math
.
abs
(
currentDistance
-
targetDistance
)
Vec3
.
setMagnitude
(
this
.
deltaDirection
,
this
.
state
.
direction
,
targetDistance
)
Vec3
.
sub
(
this
.
newPosition
,
target
,
this
.
deltaDirection
)
if
(
dir
)
{
Vec3
.
setMagnitude
(
this
.
deltaDirection
,
dir
,
targetDistance
)
Vec3
.
add
(
this
.
newPosition
,
target
,
this
.
deltaDirection
)
}
else
{
Vec3
.
setMagnitude
(
this
.
deltaDirection
,
this
.
state
.
direction
,
deltaDistance
)
if
(
currentDistance
<
targetDistance
)
Vec3
.
negate
(
this
.
deltaDirection
,
this
.
deltaDirection
)
Vec3
.
add
(
this
.
newPosition
,
this
.
state
.
position
,
this
.
deltaDirection
)
}
return
{
target
,
position
:
Vec3
.
clone
(
this
.
newPosition
)
};
return
{
target
:
Vec3
.
clone
(
target
),
position
:
Vec3
.
clone
(
this
.
newPosition
)
};
}
focus
(
target
:
Vec3
,
radius
:
number
,
dir
?:
Vec3
)
{
if
(
radius
>
0
)
this
.
setState
(
this
.
getFocus
(
target
,
radius
,
dir
));
focus
(
target
:
Vec3
,
radius
:
number
)
{
if
(
radius
>
0
)
this
.
setState
(
this
.
getFocus
(
target
,
radius
));
}
// lookAt(target: Vec3) {
...
...
@@ -202,7 +193,7 @@ namespace Camera {
mode
:
Mode
,
position
:
Vec3
,
// Normalized camera direction
// Normalized camera direction
, from Target to Position, for some reason?
direction
:
Vec3
,
up
:
Vec3
,
target
:
Vec3
,
...
...
This diff is collapsed.
Click to expand it.
src/mol-canvas3d/canvas3d.ts
+
5
−
6
View file @
a7388be2
...
...
@@ -140,7 +140,7 @@ namespace Canvas3D {
const
multiSample
=
new
MultiSamplePass
(
webgl
,
camera
,
drawPass
,
postprocessing
,
p
.
multiSample
)
let
drawPending
=
false
let
cameraResetRequested
:
boolean
|
Vec3
=
false
let
cameraResetRequested
=
false
function
getLoci
(
pickingId
:
PickingId
)
{
let
loci
:
Loci
=
EmptyLoci
...
...
@@ -271,8 +271,7 @@ namespace Canvas3D {
runTask
(
scene
.
commit
()).
then
(()
=>
{
if
(
cameraResetRequested
&&
!
scene
.
isCommiting
)
{
const
dir
=
typeof
cameraResetRequested
===
'
boolean
'
?
undefined
:
cameraResetRequested
camera
.
focus
(
scene
.
boundingSphere
.
center
,
scene
.
boundingSphere
.
radius
,
dir
)
camera
.
focus
(
scene
.
boundingSphere
.
center
,
scene
.
boundingSphere
.
radius
)
cameraResetRequested
=
false
}
if
(
debugHelper
.
isEnabled
)
debugHelper
.
update
()
...
...
@@ -345,11 +344,11 @@ namespace Canvas3D {
getLoci
,
handleResize
,
resetCamera
:
(
dir
?:
Vec3
)
=>
{
resetCamera
:
(
/*
dir?: Vec3
*/
)
=>
{
if
(
scene
.
isCommiting
)
{
cameraResetRequested
=
dir
||
true
cameraResetRequested
=
true
}
else
{
camera
.
focus
(
scene
.
boundingSphere
.
center
,
scene
.
boundingSphere
.
radius
,
dir
)
camera
.
focus
(
scene
.
boundingSphere
.
center
,
scene
.
boundingSphere
.
radius
)
requestDraw
(
true
);
}
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment