userData
A node for passing custom data from each 3D object's `userData` to its material, enabling per-object visual customization without creating new materials.
Core Advantages
It allows numerous objects using the same material to exhibit unique visual effects, greatly improving material reuse and rendering efficiency. It is key for implementing procedural variation and data visualization.
Common Uses
Adding random variations to numerous instances (e.g., grass, forests) to avoid visual repetition.
Driving visual properties (e.g., color, height) based on each object's data (e.g., population on a map).
Reflecting a game object's state (e.g., health, poison effect) onto its appearance in real-time.
How to adjust
Adjust by modifying the `userData` property values of a specific object in real-time from JavaScript. For example, change an `outlineColor` in response to a mouse hover event, or update a `detailLevel` value based on the object's distance to the camera to implement dynamic LOD effects.
Code Examples
1// In JS, set data on a specific object
2mesh.userData.highlightColor = new THREE.Color(0x00ffff);
3mesh.userData.fresnelPower = 2.5;
4
5// In the TSL material, reference this data by name and type
6const customColorNode = TSL.userData('highlightColor', 'color');
7const fresnelPowerNode = TSL.userData('fresnelPower', 'float');