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
8dc4d450
Commit
8dc4d450
authored
6 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
bounding sphere helper and transform data fixes and tweaks
parent
2d97426f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/mol-canvas3d/helper/bounding-sphere-helper.ts
+30
-21
30 additions, 21 deletions
src/mol-canvas3d/helper/bounding-sphere-helper.ts
src/mol-geo/geometry/transform-data.ts
+2
-1
2 additions, 1 deletion
src/mol-geo/geometry/transform-data.ts
src/mol-gl/scene.ts
+5
-1
5 additions, 1 deletion
src/mol-gl/scene.ts
with
37 additions
and
23 deletions
src/mol-canvas3d/helper/bounding-sphere-helper.ts
+
30
−
21
View file @
8dc4d450
...
@@ -15,6 +15,9 @@ import { Sphere3D } from 'mol-math/geometry';
...
@@ -15,6 +15,9 @@ import { Sphere3D } from 'mol-math/geometry';
import
{
Color
}
from
'
mol-util/color
'
;
import
{
Color
}
from
'
mol-util/color
'
;
import
{
ColorNames
}
from
'
mol-util/color/tables
'
;
import
{
ColorNames
}
from
'
mol-util/color/tables
'
;
import
{
TransformData
}
from
'
mol-geo/geometry/transform-data
'
;
import
{
TransformData
}
from
'
mol-geo/geometry/transform-data
'
;
import
{
sphereVertexCount
}
from
'
mol-geo/primitive/sphere
'
;
import
{
ValueCell
}
from
'
mol-util
'
;
import
{
Geometry
}
from
'
mol-geo/geometry/geometry
'
;
export
const
DebugHelperParams
=
{
export
const
DebugHelperParams
=
{
sceneBoundingSpheres
:
PD
.
Boolean
(
false
,
{
description
:
'
Show scene bounding spheres.
'
}),
sceneBoundingSpheres
:
PD
.
Boolean
(
false
,
{
description
:
'
Show scene bounding spheres.
'
}),
...
@@ -24,10 +27,11 @@ export const DebugHelperParams = {
...
@@ -24,10 +27,11 @@ export const DebugHelperParams = {
export
type
DebugHelperParams
=
typeof
DebugHelperParams
export
type
DebugHelperParams
=
typeof
DebugHelperParams
export
type
DebugHelperProps
=
PD
.
Values
<
DebugHelperParams
>
export
type
DebugHelperProps
=
PD
.
Values
<
DebugHelperParams
>
type
BoundingSphereData
=
{
boundingSphere
:
Sphere3D
,
renderObject
:
RenderObject
}
type
BoundingSphereData
=
{
boundingSphere
:
Sphere3D
,
renderObject
:
RenderObject
,
mesh
:
Mesh
}
export
class
BoundingSphereHelper
{
export
class
BoundingSphereHelper
{
readonly
scene
:
Scene
readonly
scene
:
Scene
private
readonly
parent
:
Scene
private
readonly
parent
:
Scene
private
_props
:
DebugHelperProps
private
_props
:
DebugHelperProps
private
objectsData
=
new
Map
<
RenderObject
,
BoundingSphereData
>
()
private
objectsData
=
new
Map
<
RenderObject
,
BoundingSphereData
>
()
...
@@ -44,9 +48,6 @@ export class BoundingSphereHelper {
...
@@ -44,9 +48,6 @@ export class BoundingSphereHelper {
const
newSceneData
=
updateBoundingSphereData
(
this
.
scene
,
this
.
parent
.
boundingSphere
,
this
.
sceneData
,
ColorNames
.
grey
)
const
newSceneData
=
updateBoundingSphereData
(
this
.
scene
,
this
.
parent
.
boundingSphere
,
this
.
sceneData
,
ColorNames
.
grey
)
if
(
newSceneData
)
this
.
sceneData
=
newSceneData
if
(
newSceneData
)
this
.
sceneData
=
newSceneData
const
oldRO
=
new
Set
<
RenderObject
>
()
this
.
objectsData
.
forEach
((
_
,
ro
)
=>
oldRO
.
add
(
ro
))
this
.
instancesData
.
forEach
((
_
,
ro
)
=>
oldRO
.
add
(
ro
))
this
.
parent
.
forEach
((
r
,
ro
)
=>
{
this
.
parent
.
forEach
((
r
,
ro
)
=>
{
const
objectData
=
this
.
objectsData
.
get
(
ro
)
const
objectData
=
this
.
objectsData
.
get
(
ro
)
const
newObjectData
=
updateBoundingSphereData
(
this
.
scene
,
r
.
boundingSphere
,
objectData
,
ColorNames
.
tomato
)
const
newObjectData
=
updateBoundingSphereData
(
this
.
scene
,
r
.
boundingSphere
,
objectData
,
ColorNames
.
tomato
)
...
@@ -63,17 +64,16 @@ export class BoundingSphereHelper {
...
@@ -63,17 +64,16 @@ export class BoundingSphereHelper {
})
})
if
(
newInstanceData
)
this
.
instancesData
.
set
(
ro
,
newInstanceData
)
if
(
newInstanceData
)
this
.
instancesData
.
set
(
ro
,
newInstanceData
)
}
}
oldRO
.
delete
(
ro
)
})
})
oldRO
.
forEach
(
ro
=>
{
const
objectData
=
this
.
object
s
Data
.
get
(
ro
)
this
.
object
s
Data
.
forEach
((
objectData
,
ro
)
=>
{
if
(
objectData
)
{
if
(
!
this
.
parent
.
has
(
ro
)
)
{
this
.
scene
.
remove
(
objectData
.
renderObject
)
this
.
scene
.
remove
(
objectData
.
renderObject
)
this
.
objectsData
.
delete
(
ro
)
this
.
objectsData
.
delete
(
ro
)
}
}
const
instanceData
=
this
.
instancesData
.
get
(
ro
)
})
if
(
instanceData
)
{
this
.
instancesData
.
forEach
((
instanceData
,
ro
)
=>
{
if
(
!
this
.
parent
.
has
(
ro
))
{
this
.
scene
.
remove
(
instanceData
.
renderObject
)
this
.
scene
.
remove
(
instanceData
.
renderObject
)
this
.
instancesData
.
delete
(
ro
)
this
.
instancesData
.
delete
(
ro
)
}
}
...
@@ -83,7 +83,7 @@ export class BoundingSphereHelper {
...
@@ -83,7 +83,7 @@ export class BoundingSphereHelper {
}
}
syncVisibility
()
{
syncVisibility
()
{
if
(
this
.
sceneData
)
{
if
(
this
.
sceneData
)
{
this
.
sceneData
.
renderObject
.
state
.
visible
=
this
.
_props
.
sceneBoundingSpheres
this
.
sceneData
.
renderObject
.
state
.
visible
=
this
.
_props
.
sceneBoundingSpheres
}
}
...
@@ -114,18 +114,27 @@ export class BoundingSphereHelper {
...
@@ -114,18 +114,27 @@ export class BoundingSphereHelper {
}
}
function
updateBoundingSphereData
(
scene
:
Scene
,
boundingSphere
:
Sphere3D
,
data
:
BoundingSphereData
|
undefined
,
color
:
Color
,
transform
?:
TransformData
)
{
function
updateBoundingSphereData
(
scene
:
Scene
,
boundingSphere
:
Sphere3D
,
data
:
BoundingSphereData
|
undefined
,
color
:
Color
,
transform
?:
TransformData
)
{
if
(
!
data
||
!
Sphere3D
.
exactEquals
(
data
.
boundingSphere
,
boundingSphere
))
{
if
(
!
data
||
!
Sphere3D
.
equals
(
data
.
boundingSphere
,
boundingSphere
))
{
if
(
data
)
scene
.
remove
(
data
.
renderObject
)
const
mesh
=
createBoundingSphereMesh
(
boundingSphere
,
data
&&
data
.
mesh
)
const
renderObject
=
createBoundingSphereRenderObject
(
boundingSphere
,
color
,
transform
)
const
renderObject
=
data
?
data
.
renderObject
:
createBoundingSphereRenderObject
(
mesh
,
color
,
transform
)
scene
.
add
(
renderObject
)
if
(
data
)
{
return
{
boundingSphere
:
Sphere3D
.
clone
(
boundingSphere
),
renderObject
}
ValueCell
.
update
(
renderObject
.
values
.
drawCount
,
Geometry
.
getDrawCount
(
mesh
))
}
else
{
scene
.
add
(
renderObject
)
}
return
{
boundingSphere
:
Sphere3D
.
clone
(
boundingSphere
),
renderObject
,
mesh
}
}
}
}
}
function
createBoundingSphereRenderObject
(
boundingSphere
:
Sphere3D
,
color
:
Color
,
transform
?:
TransformData
)
{
function
createBoundingSphereMesh
(
boundingSphere
:
Sphere3D
,
mesh
?:
Mesh
)
{
const
builderState
=
MeshBuilder
.
createState
(
1024
,
512
)
const
detail
=
2
if
(
boundingSphere
.
radius
)
addSphere
(
builderState
,
boundingSphere
.
center
,
boundingSphere
.
radius
,
2
)
const
vertexCount
=
sphereVertexCount
(
detail
)
const
mesh
=
MeshBuilder
.
getMesh
(
builderState
)
const
builderState
=
MeshBuilder
.
createState
(
vertexCount
,
vertexCount
/
2
,
mesh
)
if
(
boundingSphere
.
radius
)
addSphere
(
builderState
,
boundingSphere
.
center
,
boundingSphere
.
radius
,
detail
)
return
MeshBuilder
.
getMesh
(
builderState
)
}
function
createBoundingSphereRenderObject
(
mesh
:
Mesh
,
color
:
Color
,
transform
?:
TransformData
)
{
const
values
=
Mesh
.
createValuesSimple
(
mesh
,
{
alpha
:
0.1
,
doubleSided
:
false
},
color
,
transform
)
const
values
=
Mesh
.
createValuesSimple
(
mesh
,
{
alpha
:
0.1
,
doubleSided
:
false
},
color
,
transform
)
return
createMeshRenderObject
(
values
,
{
visible
:
true
,
pickable
:
false
,
opaque
:
false
})
return
createMeshRenderObject
(
values
,
{
visible
:
true
,
pickable
:
false
,
opaque
:
false
})
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/mol-geo/geometry/transform-data.ts
+
2
−
1
View file @
8dc4d450
...
@@ -19,6 +19,7 @@ export type TransformData = {
...
@@ -19,6 +19,7 @@ export type TransformData = {
export
function
createTransform
(
transformArray
:
Float32Array
,
instanceCount
:
number
,
transformData
?:
TransformData
):
TransformData
{
export
function
createTransform
(
transformArray
:
Float32Array
,
instanceCount
:
number
,
transformData
?:
TransformData
):
TransformData
{
if
(
transformData
)
{
if
(
transformData
)
{
ValueCell
.
update
(
transformData
.
aTransform
,
transformArray
)
ValueCell
.
update
(
transformData
.
aTransform
,
transformArray
)
ValueCell
.
update
(
transformData
.
transform
,
new
Float32Array
(
transformArray
))
ValueCell
.
update
(
transformData
.
uInstanceCount
,
instanceCount
)
ValueCell
.
update
(
transformData
.
uInstanceCount
,
instanceCount
)
ValueCell
.
update
(
transformData
.
instanceCount
,
instanceCount
)
ValueCell
.
update
(
transformData
.
instanceCount
,
instanceCount
)
const
aInstance
=
transformData
.
aInstance
.
ref
.
value
.
length
>=
instanceCount
?
transformData
.
aInstance
.
ref
.
value
:
new
Float32Array
(
instanceCount
)
const
aInstance
=
transformData
.
aInstance
.
ref
.
value
.
length
>=
instanceCount
?
transformData
.
aInstance
.
ref
.
value
:
new
Float32Array
(
instanceCount
)
...
@@ -38,7 +39,7 @@ export function createTransform(transformArray: Float32Array, instanceCount: num
...
@@ -38,7 +39,7 @@ export function createTransform(transformArray: Float32Array, instanceCount: num
const
identityTransform
=
new
Float32Array
(
16
)
const
identityTransform
=
new
Float32Array
(
16
)
Mat4
.
toArray
(
Mat4
.
identity
(),
identityTransform
,
0
)
Mat4
.
toArray
(
Mat4
.
identity
(),
identityTransform
,
0
)
export
function
createIdentityTransform
(
transformData
?:
TransformData
):
TransformData
{
export
function
createIdentityTransform
(
transformData
?:
TransformData
):
TransformData
{
return
createTransform
(
identityTransform
,
1
,
transformData
)
return
createTransform
(
new
Float32Array
(
identityTransform
)
,
1
,
transformData
)
}
}
const
tmpTransformMat4
=
Mat4
.
identity
()
const
tmpTransformMat4
=
Mat4
.
identity
()
...
...
This diff is collapsed.
Click to expand it.
src/mol-gl/scene.ts
+
5
−
1
View file @
8dc4d450
...
@@ -27,7 +27,7 @@ function calculateBoundingSphere(renderables: Renderable<RenderableValues & Base
...
@@ -27,7 +27,7 @@ function calculateBoundingSphere(renderables: Renderable<RenderableValues & Base
const
r
=
renderables
[
i
]
const
r
=
renderables
[
i
]
if
(
!
r
.
boundingSphere
.
radius
)
continue
;
if
(
!
r
.
boundingSphere
.
radius
)
continue
;
boundaryHelper
.
extendStep
(
r
.
boundingSphere
.
center
,
r
.
boundingSphere
.
radius
);
boundaryHelper
.
extendStep
(
r
.
boundingSphere
.
center
,
r
.
boundingSphere
.
radius
);
}
;
}
Vec3
.
copy
(
boundingSphere
.
center
,
boundaryHelper
.
center
);
Vec3
.
copy
(
boundingSphere
.
center
,
boundaryHelper
.
center
);
boundingSphere
.
radius
=
boundaryHelper
.
radius
;
boundingSphere
.
radius
=
boundaryHelper
.
radius
;
...
@@ -43,6 +43,7 @@ interface Scene extends Object3D {
...
@@ -43,6 +43,7 @@ interface Scene extends Object3D {
update
:
(
keepBoundingSphere
?:
boolean
)
=>
void
update
:
(
keepBoundingSphere
?:
boolean
)
=>
void
add
:
(
o
:
RenderObject
)
=>
void
add
:
(
o
:
RenderObject
)
=>
void
remove
:
(
o
:
RenderObject
)
=>
void
remove
:
(
o
:
RenderObject
)
=>
void
has
:
(
o
:
RenderObject
)
=>
boolean
clear
:
()
=>
void
clear
:
()
=>
void
forEach
:
(
callbackFn
:
(
value
:
Renderable
<
any
>
,
key
:
RenderObject
)
=>
void
)
=>
void
forEach
:
(
callbackFn
:
(
value
:
Renderable
<
any
>
,
key
:
RenderObject
)
=>
void
)
=>
void
}
}
...
@@ -89,6 +90,9 @@ namespace Scene {
...
@@ -89,6 +90,9 @@ namespace Scene {
boundingSphereDirty
=
true
boundingSphereDirty
=
true
}
}
},
},
has
:
(
o
:
RenderObject
)
=>
{
return
renderableMap
.
has
(
o
)
},
clear
:
()
=>
{
clear
:
()
=>
{
for
(
let
i
=
0
,
il
=
renderables
.
length
;
i
<
il
;
++
i
)
{
for
(
let
i
=
0
,
il
=
renderables
.
length
;
i
<
il
;
++
i
)
{
renderables
[
i
].
dispose
()
renderables
[
i
].
dispose
()
...
...
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