Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/jsm/geometries/BoxLineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
* A special type of box geometry intended for {@link LineSegments}.
*
* ```js
* const geometry = new THREE.BoxLineGeometry();
* const geometry = new BoxLineGeometry();
* const material = new THREE.LineBasicMaterial( { color: 0x00ff00 } );
* const lines = new THREE.LineSegments( geometry, material );
* scene.add( lines );
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/geometries/ParametricGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
* Reference: [Mesh Generation with Python](https://prideout.net/blog/old/blog/index.html@p=44.html)
*
* ```js
* const geometry = new THREE.ParametricGeometry( klein, 25, 25 );
* const geometry = new ParametricGeometry( klein, 25, 25 );
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
* const klein = new THREE.Mesh( geometry, material );
* scene.add( klein );
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/geometries/RoundedBoxGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function getUv( faceDirVector, normal, uvAxis, projectionAxis, radius, sideLengt
* A special type of box geometry with rounded corners and edges.
*
* ```js
* const geometry = new THREE.RoundedBoxGeometry();
* const geometry = new RoundedBoxGeometry();
* const material = new THREE.MeshStandardMaterial( { color: 0x00ff00 } );
* const cube = new THREE.Mesh( geometry, material );
* scene.add( cube );
Expand Down
1 change: 1 addition & 0 deletions src/Three.TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ export const objectRadius = TSL.objectRadius;
export const objectScale = TSL.objectScale;
export const objectViewPosition = TSL.objectViewPosition;
export const objectWorldMatrix = TSL.objectWorldMatrix;
export const OnAfterObjectUpdate = TSL.OnAfterObjectUpdate;
export const OnBeforeObjectUpdate = TSL.OnBeforeObjectUpdate;
export const OnBeforeMaterialUpdate = TSL.OnBeforeMaterialUpdate;
export const OnBeforeRenderPipeline = TSL.OnBeforeRenderPipeline;
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/accessors/Batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { textureSize } from './TextureSizeNode.js';
import { tangentLocal } from './Tangent.js';
import { instanceIndex, drawIndex } from '../core/IndexNode.js';
import { varyingProperty } from '../core/PropertyNode.js';
import { OnObjectUpdate } from '../utils/EventNode.js';
import { OnAfterObjectUpdate } from '../utils/EventNode.js';
import { DataTexture } from '../../textures/DataTexture.js';

const _previousBatchingMatrices = /*@__PURE__*/ new WeakMap();
Expand Down Expand Up @@ -140,7 +140,7 @@ export const batch = /*@__PURE__*/ Fn( ( [ batchMesh ], builder ) => {

if ( builder.needsPreviousData() ) {

OnObjectUpdate( ( { object } ) => {
OnAfterObjectUpdate( ( { object } ) => {

const previousBatchData = _previousBatchingMatrices.get( object );

Expand Down
15 changes: 11 additions & 4 deletions src/nodes/accessors/Instance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { vec3, mat4, Fn } from '../tsl/TSLBase.js';
import { OnFrameUpdate, OnObjectUpdate } from '../utils/EventNode.js';
import { OnAfterObjectUpdate, OnFrameUpdate } from '../utils/EventNode.js';
import { normalLocal, transformNormal } from './Normal.js';
import { positionLocal, positionPrevious } from './Position.js';
import { varyingProperty } from '../core/PropertyNode.js';
Expand Down Expand Up @@ -210,11 +210,18 @@ export const instance = /*@__PURE__*/ Fn( ( [ matrices, colors = null ], builder

const instancedMesh = builder.object;

OnObjectUpdate( ( { object } ) => {
OnAfterObjectUpdate( ( { object } ) => {

const previousInstanceData = _previousInstanceMatrices.get( object );
const { previousInstanceMatrix } = _previousInstanceMatrices.get( object );

previousInstanceData.previousInstanceMatrix.array.set( matrices.array );
previousInstanceMatrix.array.set( matrices.array );
previousInstanceMatrix.version = matrices.version;

// handle interleaved path

const previousInterleavedMatrix = _matrixBuffers.get( previousInstanceMatrix );

if ( previousInterleavedMatrix !== undefined ) previousInterleavedMatrix.version = matrices.version;

} );

Expand Down
21 changes: 21 additions & 0 deletions src/nodes/utils/EventNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class EventNode extends Node {

this.updateType = NodeUpdateType.FRAME;

} else if ( eventType === EventNode.AFTER_OBJECT ) {

this.updateAfterType = NodeUpdateType.OBJECT;

} else if ( eventType === EventNode.BEFORE_OBJECT ) {

this.updateBeforeType = NodeUpdateType.OBJECT;
Expand Down Expand Up @@ -97,11 +101,18 @@ class EventNode extends Node {

}

updateAfter( frame ) {

this.callback( frame );

}

}

EventNode.OBJECT = 'object';
EventNode.MATERIAL = 'material';
EventNode.FRAME = 'frame';
EventNode.AFTER_OBJECT = 'afterObject';
EventNode.BEFORE_OBJECT = 'beforeObject';
EventNode.BEFORE_MATERIAL = 'beforeMaterial';
EventNode.BEFORE_FRAME = 'beforeFrame';
Expand Down Expand Up @@ -149,6 +160,16 @@ export const OnMaterialUpdate = ( callback ) => createEvent( EventNode.MATERIAL,
*/
export const OnFrameUpdate = ( callback ) => createEvent( EventNode.FRAME, callback );

/**
* Creates an event that triggers a function every time an object (Mesh|Sprite) has been rendered.
*
* 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 OnAfterObjectUpdate = ( callback ) => createEvent( EventNode.AFTER_OBJECT, callback );

/**
* Creates an event that triggers a function before an object (Mesh|Sprite) is updated.
*
Expand Down