@@ -925,6 +925,7 @@ export class ModelScene extends Scene {
925
925
// the slots appear in the shadow DOM and the elements get attached,
926
926
// allowing us to dispatch events on them.
927
927
this . annotationRenderer . domElement . appendChild ( hotspot . element ) ;
928
+ this . updateSurfaceHotspot ( hotspot ) ;
928
929
}
929
930
930
931
removeHotspot ( hotspot : Hotspot ) {
@@ -947,49 +948,50 @@ export class ModelScene extends Scene {
947
948
/**
948
949
* Lazy initializer for surface hotspots - will only run once.
949
950
*/
950
- initializeSurface ( hotspot : Hotspot ) {
951
- if ( hotspot . surface != null && hotspot . mesh == null ) {
952
- const nodes = parseExpressions ( hotspot . surface ) [ 0 ] . terms as NumberNode [ ] ;
953
- if ( nodes . length != 8 ) {
954
- console . warn ( hotspot . surface + ' does not have exactly 8 numbers.' ) ;
955
- return ;
956
- }
957
- const primitiveNode =
958
- this . element . model ! [ $nodeFromIndex ] ( nodes [ 0 ] . number , nodes [ 1 ] . number ) ;
959
- const tri =
960
- new Vector3 ( nodes [ 2 ] . number , nodes [ 3 ] . number , nodes [ 4 ] . number ) ;
961
-
962
- if ( primitiveNode == null ) {
963
- console . warn (
964
- hotspot . surface +
965
- ' does not match a node/primitive in this glTF! Skipping this hotspot.' ) ;
966
- return ;
967
- }
968
-
969
- const numVert = primitiveNode . mesh . geometry . attributes . position . count ;
970
- if ( tri . x >= numVert || tri . y >= numVert || tri . z >= numVert ) {
971
- console . warn (
972
- hotspot . surface +
973
- ' vertex indices out of range in this glTF! Skipping this hotspot.' ) ;
974
- return ;
975
- }
951
+ updateSurfaceHotspot ( hotspot : Hotspot ) {
952
+ if ( hotspot . surface == null || this . element . model == null ) {
953
+ return ;
954
+ }
955
+ const nodes = parseExpressions ( hotspot . surface ) [ 0 ] . terms as NumberNode [ ] ;
956
+ if ( nodes . length != 8 ) {
957
+ console . warn ( hotspot . surface + ' does not have exactly 8 numbers.' ) ;
958
+ return ;
959
+ }
960
+ const primitiveNode =
961
+ this . element . model [ $nodeFromIndex ] ( nodes [ 0 ] . number , nodes [ 1 ] . number ) ;
962
+ if ( primitiveNode == null ) {
963
+ console . warn (
964
+ hotspot . surface +
965
+ ' does not match a node/primitive in this glTF! Skipping this hotspot.' ) ;
966
+ return ;
967
+ }
976
968
977
- const bary =
978
- new Vector3 ( nodes [ 5 ] . number , nodes [ 6 ] . number , nodes [ 7 ] . number ) ;
979
- hotspot . mesh = primitiveNode . mesh ;
980
- hotspot . tri = tri ;
981
- hotspot . bary = bary ;
969
+ const numVert = primitiveNode . mesh . geometry . attributes . position . count ;
970
+ const tri = new Vector3 ( nodes [ 2 ] . number , nodes [ 3 ] . number , nodes [ 4 ] . number ) ;
971
+ if ( tri . x >= numVert || tri . y >= numVert || tri . z >= numVert ) {
972
+ console . warn (
973
+ hotspot . surface +
974
+ ' vertex indices out of range in this glTF! Skipping this hotspot.' ) ;
975
+ return ;
982
976
}
977
+
978
+ const bary = new Vector3 ( nodes [ 5 ] . number , nodes [ 6 ] . number , nodes [ 7 ] . number ) ;
979
+ hotspot . mesh = primitiveNode . mesh ;
980
+ hotspot . tri = tri ;
981
+ hotspot . bary = bary ;
982
+
983
+ hotspot . updateSurface ( ) ;
983
984
}
984
985
985
986
/**
986
987
* Update positions of surface hotspots to follow model animation.
987
988
*/
988
- updateSurfaceHotspots ( ) {
989
- const forceUpdate = ! this . element . paused ;
989
+ animateSurfaceHotspots ( ) {
990
+ if ( this . element . paused ) {
991
+ return ;
992
+ }
990
993
this . forHotspots ( ( hotspot ) => {
991
- this . initializeSurface ( hotspot ) ;
992
- hotspot . updateSurface ( forceUpdate ) ;
994
+ hotspot . updateSurface ( ) ;
993
995
} ) ;
994
996
}
995
997
0 commit comments