ResourceVisualStrategy API Documentation
Breaking Changes: ResourceVisualStrategy API updated to support instanced rendering and depleted models.Overview
TheResourceVisualStrategy 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):getHighlightMesh() Method
New optional method (commit 9643d5d):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
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
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
PlaceholderVisualStrategy
File:packages/shared/src/entities/world/visuals/PlaceholderVisualStrategy.ts
Features:
- Colored cube proxies for testing
- No model loading
- Fast initialization
ResourceVisualContext
The context provides controlled access to entity state without circular dependencies:ResourceEntity Integration
getHighlightRoot()
New method (commit 9643d5d):EntityHighlightService to get the correct mesh for outline rendering.
Depletion Flow
Before (commit 4c55f45 and earlier):Configuration
Resource Manifest
Depleted Models:depletedModelPath- Path to depleted model (e.g., stump)depletedModelScale- Scale multiplier for depleted model (default: 1.0)
Instancer Configuration
GLBResourceInstancer:EntityHighlightService Integration
Before (commit 4c55f45 and earlier):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
- 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
- Loads individual depleted model per entity
- Higher memory usage
- Loading delay on depletion
- More flexible (per-entity customization)
Related Files
packages/shared/src/entities/world/visuals/ResourceVisualStrategy.ts- Interface definitionpackages/shared/src/entities/world/visuals/InstancedModelVisualStrategy.ts- Instanced implementationpackages/shared/src/entities/world/visuals/TreeGLBVisualStrategy.ts- Tree-specific instancingpackages/shared/src/entities/world/visuals/StandardModelVisualStrategy.ts- Non-instanced fallbackpackages/shared/src/systems/shared/world/GLBResourceInstancer.ts- Resource instancerpackages/shared/src/systems/shared/world/GLBTreeInstancer.ts- Tree instancerpackages/shared/src/entities/world/ResourceEntity.ts- Entity integrationpackages/shared/src/systems/client/interaction/services/EntityHighlightService.ts- Highlight integration
Related Commits
9643d5d- Add instanced highlight mesh and instanced depleted models53a9513- Add instanced rendering for StandardModel resources4c55f45- Merge PR #946 (instanced rendering for GLB resources)