Updating Materials after Initialized
#1
Hi,

Is there any way to change a DX material after it has been initialized? 

By default we utilize PBR materials for scene nodes. I'd like to be able to change individual/all nodes to use VertexColorMaterial - so effectively replacing the PBR material I use when I initialize the scene. Then I'd like to go back to PBR later.

I have tried the following but it doesn't seem to work:

Code:
            if (_CalculatedMaterials.TryGetValue(node, out VertexColorMaterial vertexMaterial))
            {
                //we need to get the WPF material used, so we can tell the engine to replace it.
                if (node is WpfGeometryModel3DNode wpfNode)
                {
                    wpfNode.GeometryModel3D.Material.SetUsedDXMaterial(vertexMaterial);
                }
            }

(Note that the call to SetUsedDXMaterial() has already been done before we add nodes to the scene too).

It seems there is something very similar in CustomFog Example in the demo which I was following. I must be missing something :(

Thanks
#2
One DXEngine's material can be assigned to one WPF's material.

For your use case, you would need two WPF materials and two DXEngine materials and then change the Material from one WPF's material to another, for example:
Code:
var pbrMaterial = new PhysicallyBasedMaterial() { /* ... */ };
var vertexColorMaterial = new VertexColorMaterial() { /* ... */ };


var wpfPbrMaterial = new DiffuseMaterial();
wpfPbrMaterial.SetUsedDXMaterial(pbrMaterial);


var wpfVertexColorMaterial  = new DiffuseMaterial();
wpfVertexColorMaterial.SetUsedDXMaterial(vertexColorMaterial);



// Use PBR material
geometryModel3D.Material = wpfPbrMaterial;

// Change to VertexColorMaterial:
geometryModel3D.Material = wpfVertexColorMaterial;
Andrej Benedik
  


Forum Jump:


Users browsing this thread:
1 Guest(s)