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
9d730e95
Commit
9d730e95
authored
6 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
use boundary helper to calculate geometry bounding sphere
parent
8dc4d450
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mol-gl/renderable/util.ts
+28
-61
28 additions, 61 deletions
src/mol-gl/renderable/util.ts
with
28 additions
and
61 deletions
src/mol-gl/renderable/util.ts
+
28
−
61
View file @
9d730e95
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
import
{
Sphere3D
}
from
'
mol-math/geometry
'
import
{
Sphere3D
}
from
'
mol-math/geometry
'
import
{
Mat4
,
Vec3
}
from
'
mol-math/linear-algebra
'
import
{
Mat4
,
Vec3
}
from
'
mol-math/linear-algebra
'
import
{
ValueCell
}
from
'
mol-util
'
;
import
{
BoundaryHelper
}
from
'
mol-math/geometry/boundary-helper
'
;
export
function
calculateTextureInfo
(
n
:
number
,
itemSize
:
number
)
{
export
function
calculateTextureInfo
(
n
:
number
,
itemSize
:
number
)
{
const
sqN
=
Math
.
sqrt
(
n
)
const
sqN
=
Math
.
sqrt
(
n
)
...
@@ -34,76 +34,43 @@ export function createTextureImage(n: number, itemSize: number): TextureImage<Ui
...
@@ -34,76 +34,43 @@ export function createTextureImage(n: number, itemSize: number): TextureImage<Ui
return
{
array
:
new
Uint8Array
(
length
),
width
,
height
}
return
{
array
:
new
Uint8Array
(
length
),
width
,
height
}
}
}
export
interface
PositionValues
{
//
aPosition
:
ValueCell
<
Float32Array
>
drawCount
:
ValueCell
<
number
>
,
aTransform
:
ValueCell
<
Float32Array
>
,
instanceCount
:
ValueCell
<
number
>
,
}
function
getPositionDataFromValues
(
values
:
PositionValues
)
{
return
{
position
:
values
.
aPosition
.
ref
.
value
,
positionCount
:
values
.
drawCount
.
ref
.
value
/
3
/
3
,
transform
:
values
.
aTransform
.
ref
.
value
,
transformCount
:
values
.
instanceCount
.
ref
.
value
}
}
export
function
calculateBoundingSphereFromValues
(
values
:
PositionValues
)
{
const
{
position
,
positionCount
,
transform
,
transformCount
}
=
getPositionDataFromValues
(
values
)
return
calculateBoundingSphere
(
position
,
positionCount
,
transform
,
transformCount
)
}
export
function
calculateBoundingSphere
(
position
:
Float32Array
,
positionCount
:
number
,
transform
:
Float32Array
,
transformCount
:
number
):
{
boundingSphere
:
Sphere3D
,
invariantBoundingSphere
:
Sphere3D
}
{
const
m
=
Mat4
.
zero
()
const
m
=
Mat4
.
zero
()
const
v
=
Vec3
.
zero
()
let
cx
=
0
,
cy
=
0
,
cz
=
0
;
const
boundaryHelper
=
new
BoundaryHelper
()
let
radiusSq
=
0
;
export
function
calculateInvariantBoundingSphere
(
position
:
Float32Array
,
positionCount
:
number
):
Sphere3D
{
boundaryHelper
.
reset
(
0
)
for
(
let
i
=
0
,
_i
=
positionCount
*
3
;
i
<
_i
;
i
+=
3
)
{
for
(
let
i
=
0
,
_i
=
positionCount
*
3
;
i
<
_i
;
i
+=
3
)
{
cx
+=
position
[
i
];
Vec3
.
fromArray
(
v
,
position
,
i
)
cy
+=
position
[
i
+
1
];
boundaryHelper
.
boundaryStep
(
v
,
0
)
cz
+=
position
[
i
+
2
];
}
if
(
positionCount
>
0
)
{
cx
/=
positionCount
;
cy
/=
positionCount
;
cz
/=
positionCount
;
}
}
boundaryHelper
.
finishBoundaryStep
()
for
(
let
i
=
0
,
_i
=
positionCount
*
3
;
i
<
_i
;
i
+=
3
)
{
for
(
let
i
=
0
,
_i
=
positionCount
*
3
;
i
<
_i
;
i
+=
3
)
{
const
dx
=
position
[
i
]
-
cx
Vec3
.
fromArray
(
v
,
position
,
i
)
const
dy
=
position
[
i
+
1
]
-
cy
boundaryHelper
.
extendStep
(
v
,
0
)
const
dz
=
position
[
i
+
2
]
-
cz
;
const
d
=
dx
*
dx
+
dy
*
dy
+
dz
*
dz
;
if
(
d
>
radiusSq
)
radiusSq
=
d
;
}
}
return
boundaryHelper
.
getSphere
()
}
const
c
=
Vec3
.
create
(
cx
,
cy
,
cz
)
export
function
calculateTransformBoundingSphere
(
invariantBoundingSphere
:
Sphere3D
,
transform
:
Float32Array
,
transformCount
:
number
):
Sphere3D
{
const
ct
=
Vec3
.
zero
()
const
{
center
,
radius
}
=
invariantBoundingSphere
boundaryHelper
.
reset
(
0
)
const
center
=
Vec3
.
zero
()
const
centers
=
new
Float32Array
(
3
*
transformCount
)
for
(
let
i
=
0
,
_i
=
transformCount
;
i
<
_i
;
++
i
)
{
for
(
let
i
=
0
,
_i
=
transformCount
;
i
<
_i
;
++
i
)
{
Mat4
.
fromArray
(
m
,
transform
,
i
*
16
)
Vec3
.
transformMat4
(
v
,
center
,
Mat4
.
fromArray
(
m
,
transform
,
i
*
16
))
Vec3
.
transformMat4
(
ct
,
c
,
m
)
boundaryHelper
.
boundaryStep
(
v
,
radius
)
Vec3
.
add
(
center
,
center
,
ct
)
Vec3
.
toArray
(
ct
,
centers
,
i
*
3
)
}
}
boundaryHelper
.
finishBoundaryStep
()
Vec3
.
scale
(
center
,
center
,
1
/
transformCount
)
let
r
=
Math
.
sqrt
(
radiusSq
)
let
radius
=
r
for
(
let
i
=
0
,
_i
=
transformCount
;
i
<
_i
;
++
i
)
{
for
(
let
i
=
0
,
_i
=
transformCount
;
i
<
_i
;
++
i
)
{
Vec3
.
fromArray
(
ct
,
centers
,
i
*
3
)
Vec3
.
transformMat4
(
v
,
center
,
Mat4
.
fromArray
(
m
,
transform
,
i
*
16
)
)
radius
=
Math
.
max
(
radius
,
Vec3
.
distance
(
center
,
ct
)
+
r
)
boundaryHelper
.
extendStep
(
v
,
radius
)
}
}
return
boundaryHelper
.
getSphere
()
}
return
{
boundingSphere
:
{
center
,
radius
},
invariantBoundingSphere
:
{
center
:
c
,
radius
:
r
}
};
export
function
calculateBoundingSphere
(
position
:
Float32Array
,
positionCount
:
number
,
transform
:
Float32Array
,
transformCount
:
number
):
{
boundingSphere
:
Sphere3D
,
invariantBoundingSphere
:
Sphere3D
}
{
const
invariantBoundingSphere
=
calculateInvariantBoundingSphere
(
position
,
positionCount
)
const
boundingSphere
=
calculateTransformBoundingSphere
(
invariantBoundingSphere
,
transform
,
transformCount
)
return
{
boundingSphere
,
invariantBoundingSphere
}
}
}
\ No newline at end of file
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