Skip to content

Commit 8daef3c

Browse files
authored
TSL: Add OnFrameUpdate and OnBeforeFrameUpdate (#33356)
1 parent 446f223 commit 8daef3c

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/nodes/utils/EventNode.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class EventNode extends Node {
3535

3636
this.updateType = NodeUpdateType.RENDER;
3737

38+
} else if ( eventType === EventNode.FRAME ) {
39+
40+
this.updateType = NodeUpdateType.FRAME;
41+
3842
} else if ( eventType === EventNode.BEFORE_OBJECT ) {
3943

4044
this.updateBeforeType = NodeUpdateType.OBJECT;
@@ -43,6 +47,10 @@ class EventNode extends Node {
4347

4448
this.updateBeforeType = NodeUpdateType.RENDER;
4549

50+
} else if ( eventType === EventNode.BEFORE_FRAME ) {
51+
52+
this.updateBeforeType = NodeUpdateType.FRAME;
53+
4654
}
4755

4856
}
@@ -63,8 +71,10 @@ class EventNode extends Node {
6371

6472
EventNode.OBJECT = 'object';
6573
EventNode.MATERIAL = 'material';
74+
EventNode.FRAME = 'frame';
6675
EventNode.BEFORE_OBJECT = 'beforeObject';
6776
EventNode.BEFORE_MATERIAL = 'beforeMaterial';
77+
EventNode.BEFORE_FRAME = 'beforeFrame';
6878

6979
export default EventNode;
7080

@@ -97,6 +107,16 @@ export const OnObjectUpdate = ( callback ) => createEvent( EventNode.OBJECT, cal
97107
*/
98108
export const OnMaterialUpdate = ( callback ) => createEvent( EventNode.MATERIAL, callback );
99109

110+
/**
111+
* Creates an event that triggers a function every frame.
112+
*
113+
* The event will be bound to the declared TSL function `Fn()`; it must be declared within a `Fn()` or the JS function call must be inherited from one.
114+
*
115+
* @param {Function} callback - The callback function.
116+
* @returns {EventNode}
117+
*/
118+
export const OnFrameUpdate = ( callback ) => createEvent( EventNode.FRAME, callback );
119+
100120
/**
101121
* Creates an event that triggers a function before an object (Mesh|Sprite) is updated.
102122
*
@@ -116,3 +136,13 @@ export const OnBeforeObjectUpdate = ( callback ) => createEvent( EventNode.BEFOR
116136
* @returns {EventNode}
117137
*/
118138
export const OnBeforeMaterialUpdate = ( callback ) => createEvent( EventNode.BEFORE_MATERIAL, callback );
139+
140+
/**
141+
* Creates an event that triggers a function before every frame.
142+
*
143+
* The event will be bound to the declared TSL function `Fn()`; it must be declared within a `Fn()` or the JS function call must be inherited from one.
144+
*
145+
* @param {Function} callback - The callback function.
146+
* @returns {EventNode}
147+
*/
148+
export const OnBeforeFrameUpdate = ( callback ) => createEvent( EventNode.BEFORE_FRAME, callback );

0 commit comments

Comments
 (0)