Skip to content

Commit

Permalink
NodeUtils: Add getDataFromObject() (#30171)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunag authored Dec 20, 2024
1 parent 463f476 commit 083f233
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/nodes/accessors/SkinningNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { positionLocal, positionPrevious } from './Position.js';
import { tangentLocal } from './Tangent.js';
import { uniform } from '../core/UniformNode.js';
import { buffer } from './BufferNode.js';
import { getDataFromObject } from '../core/NodeUtils.js';

/** @module SkinningNode **/

Expand Down Expand Up @@ -218,7 +219,7 @@ class SkinningNode extends Node {

const mrt = builder.renderer.getMRT();

return ( mrt && mrt.has( 'velocity' ) ) || builder.object.userData.useVelocity === true;
return ( mrt && mrt.has( 'velocity' ) ) || getDataFromObject( builder.object ).useVelocity === true;

}

Expand Down
23 changes: 23 additions & 0 deletions src/nodes/core/NodeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ const typeFromLength = /*@__PURE__*/ new Map( [
[ 16, 'mat4' ]
] );

const dataFromObject = /*@__PURE__*/ new WeakMap();

/**
* Returns the data type for the given the length.
*
Expand Down Expand Up @@ -334,6 +336,27 @@ export function getValueFromType( type, ...params ) {

}

/**
* Gets the object data that can be shared between different rendering steps.
*
* @param {Object} object - The object to get the data for.
* @return {Object} The object data.
*/
export function getDataFromObject( object ) {

let data = dataFromObject.get( object );

if ( data === undefined ) {

data = {};
dataFromObject.set( object, data );

}

return data;

}

/**
* Converts the given array buffer to a Base64 string.
*
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/lighting/ShadowNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { viewZToLogarithmicDepth } from '../display/ViewportDepthNode.js';
import { objectPosition } from '../accessors/Object3DNode.js';
import { lightShadowMatrix } from '../accessors/Lights.js';
import { resetRendererAndSceneState, restoreRendererAndSceneState } from '../../renderers/common/RendererUtils.js';
import { getDataFromObject } from '../core/NodeUtils.js';

/** @module ShadowNode **/

Expand Down Expand Up @@ -671,8 +672,7 @@ class ShadowNode extends ShadowBaseNode {

if ( useVelocity ) {

object.userData = object.userData || {};
object.userData.useVelocity = true;
getDataFromObject( object ).useVelocity = true;

}

Expand Down

0 comments on commit 083f233

Please sign in to comment.