sunag 3 месяцев назад
Родитель
Сommit
30fdd5c87e
2 измененных файлов с 37 добавлено и 0 удалено
  1. 2 0
      src/Three.TSL.js
  2. 35 0
      src/nodes/utils/EventNode.js

+ 2 - 0
src/Three.TSL.js

@@ -399,6 +399,8 @@ export const objectRadius = TSL.objectRadius;
 export const objectScale = TSL.objectScale;
 export const objectViewPosition = TSL.objectViewPosition;
 export const objectWorldMatrix = TSL.objectWorldMatrix;
+export const OnBeforeObjectUpdate = TSL.OnBeforeObjectUpdate;
+export const OnBeforeMaterialUpdate = TSL.OnBeforeMaterialUpdate;
 export const OnObjectUpdate = TSL.OnObjectUpdate;
 export const OnMaterialUpdate = TSL.OnMaterialUpdate;
 export const oneMinus = TSL.oneMinus;

+ 35 - 0
src/nodes/utils/EventNode.js

@@ -36,6 +36,14 @@ class EventNode extends Node {
 
 			this.updateType = NodeUpdateType.RENDER;
 
+		} else if ( eventType === EventNode.BEFORE_OBJECT ) {
+
+			this.updateBeforeType = NodeUpdateType.OBJECT;
+
+		} else if ( eventType === EventNode.BEFORE_MATERIAL ) {
+
+			this.updateBeforeType = NodeUpdateType.RENDER;
+
 		}
 
 	}
@@ -46,10 +54,17 @@ class EventNode extends Node {
 
 	}
 
+	updateBefore( frame ) {
+
+		this.callback( frame );
+
+	}
+
 }
 
 EventNode.OBJECT = 'object';
 EventNode.MATERIAL = 'material';
+EventNode.BEFORE_MATERIAL = 'beforeMaterial';
 
 export default EventNode;
 
@@ -81,3 +96,23 @@ export const OnObjectUpdate = ( callback ) => createEvent( EventNode.OBJECT, cal
  * @returns {EventNode}
  */
 export const OnMaterialUpdate = ( callback ) => createEvent( EventNode.MATERIAL, callback );
+
+/**
+ * Creates an event that triggers a function before an object (Mesh|Sprite) is updated.
+ *
+ * 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.
+ *
+ * @param {Function} callback - The callback function.
+ * @returns {EventNode}
+ */
+export const OnBeforeObjectUpdate = ( callback ) => createEvent( EventNode.BEFORE_OBJECT, callback );
+
+/**
+ * Creates an event that triggers a function before the material is updated.
+ *
+ * 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.
+ *
+ * @param {Function} callback - The callback function.
+ * @returns {EventNode}
+ */
+export const OnBeforeMaterialUpdate = ( callback ) => createEvent( EventNode.BEFORE_MATERIAL, callback );

粤ICP备19079148号