Skip to main content

ResourceVisualStrategy API Documentation

Breaking Changes: ResourceVisualStrategy API updated to support instanced rendering and depleted models.

Overview

The ResourceVisualStrategy interface defines how resource entities (trees, rocks, fishing spots, herbs) are rendered. Each resource type has its own strategy that handles mesh creation, LOD, animation, depletion visuals, and cleanup.

Interface

Breaking Changes

onDepleted() Return Type

Before (commit 4c55f45 and earlier):
After (commit 9643d5d):
Migration:

getHighlightMesh() Method

New optional method (commit 9643d5d):
Purpose: Return a positioned mesh for the outline pass on instanced entities. Implementation:

Implementations

InstancedModelVisualStrategy

File: packages/shared/src/entities/world/visuals/InstancedModelVisualStrategy.ts Features:
  • GPU instancing for resources (rocks, ores, herbs)
  • Separate instance pools per LOD level
  • Depleted model support (e.g., empty rock)
  • Highlight mesh for hover/selection
  • Invisible collision proxy for raycasting
Usage:

TreeGLBVisualStrategy

File: packages/shared/src/entities/world/visuals/TreeGLBVisualStrategy.ts Features:
  • GPU instancing for trees
  • Dissolve material for tree cutting animation
  • Depleted model support (tree → stump)
  • Highlight mesh for hover/selection
  • Invisible collision proxy for raycasting
Usage:

StandardModelVisualStrategy

File: packages/shared/src/entities/world/visuals/StandardModelVisualStrategy.ts Features:
  • Non-instanced rendering (one mesh per entity)
  • Fallback for resources that don’t support instancing
  • Individual depleted model loading
Usage:

PlaceholderVisualStrategy

File: packages/shared/src/entities/world/visuals/PlaceholderVisualStrategy.ts Features:
  • Colored cube proxies for testing
  • No model loading
  • Fast initialization
Usage:

ResourceVisualContext

The context provides controlled access to entity state without circular dependencies:

ResourceEntity Integration

getHighlightRoot()

New method (commit 9643d5d):
Purpose: Used by EntityHighlightService to get the correct mesh for outline rendering.

Depletion Flow

Before (commit 4c55f45 and earlier):
After (commit 9643d5d):
Benefit: Instanced strategies can handle depletion internally (e.g., switch to stump instance pool) without loading individual models.

Configuration

Resource Manifest

Depleted Models:
Fields:
  • depletedModelPath - Path to depleted model (e.g., stump)
  • depletedModelScale - Scale multiplier for depleted model (default: 1.0)

Instancer Configuration

GLBResourceInstancer:
GLBTreeInstancer:

EntityHighlightService Integration

Before (commit 4c55f45 and earlier):
After (commit 9643d5d):
Benefit: Supports instanced entities by getting highlight mesh from strategy instead of main mesh.

Examples

Creating a Custom Strategy

Using Instanced Rendering

Testing

Visual Testing

Integration Testing

Performance Considerations

Instanced Rendering

Benefits:
  • Reduces draw calls from O(n) to O(1) per unique model per LOD level
  • Supports thousands of resources with minimal performance impact
  • Automatic LOD switching based on distance
Limitations:
  • All instances share the same material
  • Cannot have per-instance animations (use vertex animation textures)
  • Raycasting requires collision proxies

Depleted Models

Instanced Approach (recommended):
  • Maintains separate instance pools for normal and depleted states
  • No individual model loading on depletion
  • Instant transition (no loading delay)
  • Lower memory usage
Non-Instanced Approach (fallback):
  • Loads individual depleted model per entity
  • Higher memory usage
  • Loading delay on depletion
  • More flexible (per-entity customization)
  • packages/shared/src/entities/world/visuals/ResourceVisualStrategy.ts - Interface definition
  • packages/shared/src/entities/world/visuals/InstancedModelVisualStrategy.ts - Instanced implementation
  • packages/shared/src/entities/world/visuals/TreeGLBVisualStrategy.ts - Tree-specific instancing
  • packages/shared/src/entities/world/visuals/StandardModelVisualStrategy.ts - Non-instanced fallback
  • packages/shared/src/systems/shared/world/GLBResourceInstancer.ts - Resource instancer
  • packages/shared/src/systems/shared/world/GLBTreeInstancer.ts - Tree instancer
  • packages/shared/src/entities/world/ResourceEntity.ts - Entity integration
  • packages/shared/src/systems/client/interaction/services/EntityHighlightService.ts - Highlight integration
  • 9643d5d - Add instanced highlight mesh and instanced depleted models
  • 53a9513 - Add instanced rendering for StandardModel resources
  • 4c55f45 - Merge PR #946 (instanced rendering for GLB resources)

References