internal override void Destruct() { base.Destruct(); foreach (var instance in m_instances.Values) { MyScene.RenderablesDBVH.RemoveProxy(instance.BtreeProxy); foreach (var lod in instance.Lods) { foreach (var proxy in lod.RenderableProxies) { MyProxiesFactory.Remove(proxy); } } } }
void UpdateLodState() { ProfilerShort.Begin("MyInstancingComponent::UpdateLodState"); foreach (var pair in m_activeTransitions) { ProfilerShort.Begin("SetAlphaForInstance"); pair.Value.Time += pair.Value.Delta; SetAlphaForInstance(pair.Key.Id, pair.Key.InstanceIndex, pair.Value.Time); ProfilerShort.End(); if (pair.Value.IsProxyToInstance) { if (pair.Value.Time >= 1.0f) { ProfilerShort.Begin("PositiveTransition"); var instance = m_instances[pair.Key]; MyScene.RenderablesDBVH.RemoveProxy(instance.BtreeProxy); foreach (var lod in instance.Lods) { foreach (var proxy in lod.RenderableProxies) { MyProxiesFactory.Remove(proxy); } } MyProxiesFactory.Remove(instance.CullProxy); m_instances.Remove(pair.Key); m_completedTransitions.Add(pair.Key); ProfilerShort.End(); continue; } else if (pair.Value.Time <= -1.0f) { ProfilerShort.Begin("NegativeTransition"); MyInstancing.Instancings.Data[pair.Key.Id.Index].SetVisibility(pair.Key.InstanceIndex, false); m_dirtyInstances.Add(pair.Key.Id); m_completedTransitions.Add(pair.Key); pair.Value.Time = 0; ProfilerShort.End(); } } else { if (Math.Abs(pair.Value.Time) >= 1.0f) { var instance = m_instances[pair.Key]; instance.CurrentLod += Math.Sign(pair.Value.Delta); pair.Value.Delta = -pair.Value.Delta; m_completedTransitions.Add(pair.Key); pair.Value.Time = 0; instance.IsDirty = true; } } ProfilerShort.Begin("SetAlphaForProxies"); SetAlphaForProxies(pair.Key, pair.Value); ProfilerShort.End(); } foreach (var key in m_completedTransitions) { m_activeTransitions.Remove(key); } m_completedTransitions.Clear(); VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); }