1
1
var _ = require ( 'underscore' ) ;
2
2
var widgets = require ( "@jupyter-widgets/base" ) ;
3
+ var utils = require ( "../_base/utils" ) ;
3
4
var AnimationActionAutogen = require ( './AnimationAction.autogen' ) . AnimationActionModel ;
4
5
5
6
var THREE = require ( 'three' ) ;
6
7
7
8
var pkgName = require ( '../../package.json' ) . name ;
8
9
9
- function getObjectScene ( object3d ) {
10
- while ( object3d . parent ) {
11
- object3d = object3d . parent ;
12
- }
13
- if ( object3d . type === 'Scene' ) {
14
- return object3d ;
15
- }
16
- return null ;
17
- }
18
-
19
- function getModelScene ( model ) {
20
- let obj = model . obj ;
21
- while ( obj . parent ) {
22
- obj = obj . parent ;
23
- }
24
- if ( obj . type === 'Scene' ) {
25
- return obj . ipymodel ;
26
- }
27
- return null ;
28
- }
29
-
30
10
var AnimationActionModel = AnimationActionAutogen . extend ( {
31
11
32
12
defaults : function ( ) {
@@ -70,7 +50,7 @@ var AnimationActionModel = AnimationActionAutogen.extend({
70
50
this . obj . paused = false ;
71
51
72
52
var root = this . get ( 'localRoot' ) ;
73
- var scene = getModelScene ( root ) ;
53
+ var scene = utils . getModelScene ( root ) ;
74
54
if ( scene ) {
75
55
this . listenTo ( scene , 'afterRender' , this . animateFrame . bind ( this ) ) ;
76
56
}
@@ -92,7 +72,7 @@ var AnimationActionModel = AnimationActionAutogen.extend({
92
72
mixer . update ( delta ) ;
93
73
// As long as root is in scene, this will trigger a re-render
94
74
// The onAfterRender will then trigger a new frame
95
- var scene = getModelScene ( this . get ( 'localRoot' ) ) ;
75
+ var scene = utils . getModelScene ( this . get ( 'localRoot' ) ) ;
96
76
if ( scene ) {
97
77
scene . trigger ( 'rerender' ) ;
98
78
}
@@ -118,7 +98,7 @@ var AnimationActionModel = AnimationActionAutogen.extend({
118
98
} ,
119
99
120
100
resetRenderHook : function ( ) {
121
- var scene = getModelScene ( this . get ( 'localRoot' ) ) ;
101
+ var scene = utils . getModelScene ( this . get ( 'localRoot' ) ) ;
122
102
if ( scene ) {
123
103
this . stopListening ( scene , 'afterRender' ) ;
124
104
}
@@ -223,4 +203,4 @@ var AnimationActionView = widgets.DOMWidgetView.extend({
223
203
module . exports = {
224
204
AnimationActionModel : AnimationActionModel ,
225
205
AnimationActionView : AnimationActionView ,
226
- } ;
206
+ } ;
0 commit comments