diff --git a/src/nodes/accessors/SkinningNode.js b/src/nodes/accessors/SkinningNode.js index 8337dd2d2b3e0a..f3c62ac5f77796 100644 --- a/src/nodes/accessors/SkinningNode.js +++ b/src/nodes/accessors/SkinningNode.js @@ -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 **/ @@ -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; } diff --git a/src/nodes/core/NodeUtils.js b/src/nodes/core/NodeUtils.js index a4f0f813ac0cf7..f55926b954cbab 100644 --- a/src/nodes/core/NodeUtils.js +++ b/src/nodes/core/NodeUtils.js @@ -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. * @@ -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. * diff --git a/src/nodes/lighting/ShadowNode.js b/src/nodes/lighting/ShadowNode.js index aa2ed33591fb9a..426e694ae12d2f 100644 --- a/src/nodes/lighting/ShadowNode.js +++ b/src/nodes/lighting/ShadowNode.js @@ -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 **/ @@ -671,8 +672,7 @@ class ShadowNode extends ShadowBaseNode { if ( useVelocity ) { - object.userData = object.userData || {}; - object.userData.useVelocity = true; + getDataFromObject( object ).useVelocity = true; }