internal void AddInstanceLod(InstancingId id, int index, MyRenderableProxy[][] newProxies, ulong[][] newSortingKeys, BoundingBoxD aabb)
        {
            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("AddInstanceLod");
            if (!SetDelta(id, index, -0.1f))
            {
                MyInstanceLodId key = new MyInstanceLodId {
                    Id = id, InstanceIndex = index
                };

                MySingleInstance instance = new MySingleInstance();
                instance.Lods = new MySingleInstanceLod[newProxies.Length];

                for (int i = 0; i < newProxies.Length; i++)
                {
                    MySingleInstanceLod lod = new MySingleInstanceLod();
                    lod.RenderableProxies = newProxies[i];
                    lod.SortingKeys       = newSortingKeys[i];

                    if (i < newProxies.Length - 1)
                    {
                        lod.RenderableProxiesForLodTransition = new MyRenderableProxy[newProxies[i].Length + newProxies[i + 1].Length];
                        for (int j = 0; j < newProxies[i].Length; j++)
                        {
                            lod.RenderableProxiesForLodTransition[j] = newProxies[i][j];
                        }
                        for (int j = 0; j < newProxies[i + 1].Length; j++)
                        {
                            lod.RenderableProxiesForLodTransition[j + newProxies[i].Length] = newProxies[i + 1][j];
                        }

                        lod.SortingKeysForLodTransition = new ulong[newSortingKeys[i].Length + newSortingKeys[i + 1].Length];
                        for (int j = 0; j < newSortingKeys[i].Length; j++)
                        {
                            lod.SortingKeysForLodTransition[j] = newSortingKeys[i][j];
                        }
                        for (int j = 0; j < newSortingKeys[i + 1].Length; j++)
                        {
                            lod.SortingKeysForLodTransition[j + newSortingKeys[i].Length] = newSortingKeys[i + 1][j];
                        }
                    }

                    instance.Lods[i] = lod;
                }

                instance.CurrentLod = 0;

                instance.CullProxy = MyProxiesFactory.CreateCullProxy();

                instance.BtreeProxy = MyScene.RenderablesDBVH.AddProxy(ref aabb, instance.CullProxy, 0);
                m_instances.Add(key, instance);

                instance.IsDirty = true;
            }
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
Пример #2
0
        internal MyClipmapCellProxy(MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix, RenderFlags additionalFlags = 0)
        {
            m_worldMatrix = worldMatrix;

            m_actor = MyActorFactory.CreateSceneObject();
            m_actor.SetMatrix(ref worldMatrix);
            m_actor.AddComponent(MyComponentFactory <MyFoliageComponent> .Create());

            m_lod = cellCoord.Lod;

            Mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod);
            m_actor.GetRenderable().SetModel(Mesh);
            m_actor.GetRenderable().m_additionalFlags = MyProxiesFactory.GetRenderableProxyFlags(additionalFlags);
        }
 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);
             }
         }
     }
 }
Пример #4
0
        internal MyClipmapCellProxy(MyCellCoord cellCoord, ref MatrixD worldMatrix, Vector3D massiveCenter, float massiveRadius, RenderFlags additionalFlags = 0)
        {
            m_worldMatrix = worldMatrix;

            m_actor = MyActorFactory.CreateVoxelCell();
            m_actor.SetMatrix(ref worldMatrix);

            m_lod = cellCoord.Lod;

            MyVoxelRenderableComponent renderableComponent = m_actor.GetRenderable() as MyVoxelRenderableComponent;

            m_mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod);
            renderableComponent.SetVoxelLod(m_lod, ScaleGroup);
            renderableComponent.SetModel(m_mesh);
            renderableComponent.m_massiveCenter   = massiveCenter;
            renderableComponent.m_massiveRadius   = massiveRadius;
            renderableComponent.m_additionalFlags = MyProxiesFactory.GetRenderableProxyFlags(additionalFlags);
        }
        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();
        }