Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Allow MultiLineNode.Material setter to change in runtime
#3
I see now that you solve that by using reflection.

But by deriving your own class from MultiLineNode (or any other class that is derived from LineBaseNode), you can change the protected material and lineBaseMaterial fields without using reflection.

For example, you can add the following code to a derived class to change the material:

Code:
        public void ChangeMaterial(Material? newMaterial)
        {
            if (ReferenceEquals(newMaterial, material))
                return;

            DisposeRenderingItems(); // dispose existing RenderingItems


            material = newMaterial;

            if (newMaterial != null)
            {
                CheckIfMaterialIsDisposed(newMaterial);

                if (Scene != null && !newMaterial.IsInitialized)
                    newMaterial.InitializeSceneResources(Scene);

                lastMaterialVersion = -1; // This will update the material in CollectRenderingItems
            }

            // we store material also as LineMaterial for improved performance in getters and setters
            lineBaseMaterial = newMaterial as LineMaterial;

            NotifyChange(SceneNodeDirtyFlags.MaterialChanged);
        }
Andrej Benedik
  


Messages In This Thread
RE: Allow MultiLineNode.Material setter to change in runtime - by abenedik - 03-04-2026, 03:45 PM

Forum Jump:


Users browsing this thread:
1 Guest(s)