ResourceVisualStrategy API Reference
Interface for resource entity visual rendering strategies.Interface
Methods
createVisual(ctx: ResourceVisualContext): Promise<void>
Creates the visual representation for a resource entity.
Parameters:
ctx- Resource visual context containing entity data, node, and configuration
- Once when resource entity is created
- After respawn (if visual was destroyed)
onDepleted(ctx: ResourceVisualContext): Promise<boolean>
Called when a resource is depleted (e.g., tree chopped down, ore mined).
Parameters:
ctx- Resource visual context
true- Strategy handled depletion visuals (e.g., instanced stump). ResourceEntity will skip loading individual depleted model.false- ResourceEntity should load individual depleted model (legacy behavior).
Promise<void>. Now returns Promise<boolean> to indicate whether the strategy handles depletion.
Example:
onRespawn(ctx: ResourceVisualContext): Promise<void>
Called when a depleted resource respawns.
Parameters:
ctx- Resource visual context
- After resource respawn timer completes
- Before resource becomes interactable again
update(ctx: ResourceVisualContext, deltaTime: number): void
Called every frame to update visual state.
Parameters:
ctx- Resource visual contextdeltaTime- Time since last frame in seconds
- LOD switching
- Animation updates
- Material parameter updates
- Particle effects
destroy(ctx: ResourceVisualContext): void
Called when resource entity is destroyed (e.g., world cleanup, chunk unload).
Parameters:
ctx- Resource visual context
- Remove meshes from scene
- Dispose geometries and materials
- Remove from instancer pools
- Clean up event listeners
getHighlightMesh?(ctx: ResourceVisualContext): THREE.Object3D | null (Optional)
Returns a temporary mesh positioned at this instance for hover outline rendering.
Parameters:
ctx- Resource visual context
THREE.Object3D- Positioned mesh for outline passnull- No highlight mesh available (falls back to entity’s scene-graph mesh)
EntityHighlightService adds to the scene for the duration of the hover.
Example:
ResourceVisualContext
Context object passed to all strategy methods:Built-in Strategies
TreeGLBVisualStrategy
For tree resources with GLB models. Features:- Integrates with
GLBTreeInstancer - Automatic LOD switching (LOD0/LOD1/LOD2)
- Instanced depletion (stumps)
- Highlight mesh support
onDepleted(): true (handles instanced stumps)
InstancedModelVisualStrategy
For non-tree resources with GLB models (rocks, ores, herbs). Features:- Integrates with
GLBResourceInstancer - Automatic LOD switching
- Instanced depletion
- Highlight mesh support
- Falls back to
StandardModelVisualStrategyif instancing fails
onDepleted(): true if instanced, false if fallback
StandardModelVisualStrategy
Legacy strategy for non-instanced resources. Features:- Loads individual GLB model per entity
- No LOD switching
- No instancing
- Higher draw call count
onDepleted(): false (ResourceEntity loads stump)
FishingSpotVisualStrategy
For fishing spot resources. Features:- Glow particle effect
- Water particle manager integration
- No depletion visuals (fishing spots don’t deplete)
onDepleted(): false
PlaceholderVisualStrategy
For resources without models (uses colored cubes). Features:- Integrates with
PlaceholderInstancer - Colored cube based on resource type
- Minimal memory footprint
onDepleted(): false
TreeProcgenVisualStrategy
For procedurally generated trees. Features:- Integrates with
ProcgenTreeInstancer - L-system based tree generation
- Instanced rendering
- LOD support
onDepleted(): false
Strategy Selection
Strategies are automatically selected bycreateVisualStrategy():
Migration Guide
Updating Existing Strategies
If you have custom visual strategies, update them for the new API: 1. UpdateonDepleted() signature:
getHighlightMesh():