-
-
Save Doprez/5327fbd7d8c371938088db81d82d153b to your computer and use it in GitHub Desktop.
Basic Stride LOD example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DataContract("SimpleLODComponent", Inherited = true)] | |
[ComponentCategory("Model")] | |
public class SimpleLOD : AsyncScript | |
{ | |
[DataMember(0, "LOD's")] | |
public List<LODData> LODs = new List<LODData>(); | |
private Entity _camera; | |
private ModelComponent _modelComponent; | |
public override async Task Execute() | |
{ | |
_modelComponent = Entity.Get<ModelComponent>(); | |
_camera = Entity.GetComponentInScene<CameraComponent>().Entity; | |
while (Game.IsRunning) | |
{ | |
UpdateCurrentLOD(); | |
await Script.NextFrame(); | |
} | |
} | |
private void UpdateCurrentLOD() | |
{ | |
var distance = Vector3.Distance(_camera.WorldPosition(), Entity.WorldPosition()); | |
for (int i = LODs.Count - 1; i >= 0; i--) | |
{ | |
if (distance < LODs[i].DistanceToActivate && _modelComponent.Model != LODs[i].MeshLOD) | |
{ | |
_modelComponent.Model = LODs[i].MeshLOD; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment