Skip to main content

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
Called:
  • Once when resource entity is created
  • After respawn (if visual was destroyed)
Example:

onDepleted(ctx: ResourceVisualContext): Promise<boolean>

Called when a resource is depleted (e.g., tree chopped down, ore mined). Parameters:
  • ctx - Resource visual context
Returns:
  • 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).
Breaking Change (PR #946): Previously returned 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
Called:
  • After resource respawn timer completes
  • Before resource becomes interactable again
Example:

update(ctx: ResourceVisualContext, deltaTime: number): void

Called every frame to update visual state. Parameters:
  • ctx - Resource visual context
  • deltaTime - Time since last frame in seconds
Use cases:
  • LOD switching
  • Animation updates
  • Material parameter updates
  • Particle effects
Example:

destroy(ctx: ResourceVisualContext): void

Called when resource entity is destroyed (e.g., world cleanup, chunk unload). Parameters:
  • ctx - Resource visual context
Responsibilities:
  • Remove meshes from scene
  • Dispose geometries and materials
  • Remove from instancer pools
  • Clean up event listeners
Example:

getHighlightMesh?(ctx: ResourceVisualContext): THREE.Object3D | null (Optional)

Returns a temporary mesh positioned at this instance for hover outline rendering. Parameters:
  • ctx - Resource visual context
Returns:
  • THREE.Object3D - Positioned mesh for outline pass
  • null - No highlight mesh available (falls back to entity’s scene-graph mesh)
Added in: PR #946 Use case: Instanced entities don’t have individual scene-graph meshes, so the outline pass can’t find them. This method provides a temporary mesh that 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
Returns from 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 StandardModelVisualStrategy if instancing fails
Returns from 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
Returns from 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)
Returns from onDepleted(): false

PlaceholderVisualStrategy

For resources without models (uses colored cubes). Features:
  • Integrates with PlaceholderInstancer
  • Colored cube based on resource type
  • Minimal memory footprint
Returns from onDepleted(): false

TreeProcgenVisualStrategy

For procedurally generated trees. Features:
  • Integrates with ProcgenTreeInstancer
  • L-system based tree generation
  • Instanced rendering
  • LOD support
Returns from onDepleted(): false

Strategy Selection

Strategies are automatically selected by createVisualStrategy():

Migration Guide

Updating Existing Strategies

If you have custom visual strategies, update them for the new API: 1. Update onDepleted() signature:
2. Optional: Add getHighlightMesh():

Creating New Strategies