Commit c8ff670a authored by Timothee Chabat's avatar Timothee Chabat
Browse files

MaterialEditor: remove all proxy creation

fix : warnings and errors when loading a state file containing a material library
introduce regression : material libraries are not loadable using state files anymore
introduce regression : material editor cannot edit json libraries anymore
parent 7b0eaa52
......@@ -50,9 +50,6 @@ void vtkSMMaterialLibraryProxy::LoadMaterials(const char* filename)
// Synchronize from server to client
// materials are loaded, create the proxies accordingly
......@@ -70,9 +67,6 @@ void vtkSMMaterialLibraryProxy::LoadDefaultMaterials()
// Synchronize from server to client
// materials are loaded, create the proxies accordingly
......@@ -114,95 +108,3 @@ void vtkSMMaterialLibraryProxy::Synchronize(
void vtkSMMaterialLibraryProxy::CreateProxies()
#if VTK_MODULE_ENABLE_VTK_RenderingRayTracing
vtkOSPRayMaterialLibrary* ml = vtkOSPRayMaterialLibrary::SafeDownCast(
vtkSMSessionProxyManager* pxm = this->GetSessionProxyManager();
std::set<std::string> matNames = ml->GetMaterialNames();
for (auto& matName : matNames)
std::string type = ml->LookupImplName(matName);
vtkSmartPointer<vtkSMProxy> matProxy;
matProxy.TakeReference(pxm->NewProxy("materials", "Material"));
vtkSMPropertyHelper(matProxy, "Name").Set(matName.c_str());
vtkSMPropertyHelper(matProxy, "Type").Set(type.c_str());
// we need to update name and type before adding attributes
auto varList = ml->GetDoubleShaderVariableList(matName);
auto texList = ml->GetTextureList(matName);
// This property is in rendering.xml
// under the Material proxy
vtkSMPropertyHelper(matProxy, "DoubleVariables")
.SetNumberOfElements((varList.size() + texList.size()) * 2);
vtkSMPropertyHelper(this, "Materials").Add(matProxy);
// register have to be done after the proxy is added to the library in order to not
// invoke register event too early
pxm->RegisterProxy("materials", matProxy);
int currentIndex = 0;
// Add all the double variables
for (auto& varName : varList)
vtkSMPropertyHelper(matProxy, "DoubleVariables").Set(currentIndex++, varName.c_str());
auto varValue = ml->GetDoubleShaderVariable(matName, varName);
std::string str =
std::accumulate(varValue.begin() + 1, varValue.end(), std::to_string(varValue[0]),
[](const std::string& a, double b) { return a + ' ' + std::to_string(b); });
vtkSMPropertyHelper(matProxy, "DoubleVariables").Set(currentIndex++, str.c_str());
// Add all the texture
for (auto& varName : texList)
// Get the texture loaded by the material library
vtkTexture* osprayTexture = ml->GetTexture(matName, varName);
// Create a trivial producer to pass the texture as input
vtkSmartPointer<vtkSMSourceProxy> producer;
pxm->NewProxy("sources", "PVTrivialProducerOnAllProcesses")));
auto realProducer = vtkPVTrivialProducer::SafeDownCast(producer->GetClientSideObject());
// Connect the producer to the input of Texture
vtkSmartPointer<vtkSMSourceProxy> texture;
texture.TakeReference(vtkSMSourceProxy::SafeDownCast(pxm->NewProxy("textures", "Texture")));
vtkSMPropertyHelper(texture, "Input").Set(producer);
// Get the name of the texture from the ospray material library
std::string osprayTextureName = ml->GetTextureName(matName, varName);
// Generate an unique name
std::string proxyName = pxm->GetUniqueProxyName("textures", osprayTextureName.c_str(), false);
// Now, register the proxy and update the vtkPVMaterial object
pxm->RegisterProxy("textures", proxyName.c_str(), texture);
vtkSMPropertyHelper(matProxy, "DoubleVariables").Set(currentIndex++, varName.c_str());
vtkSMPropertyHelper(matProxy, "DoubleVariables").Set(currentIndex++, proxyName.c_str());
......@@ -51,12 +51,6 @@ public:
void LoadMaterials(const char*);
* After loading materials in the OSPRay material library, this function is used to
* iterate over all stored materials and create the material proxy accordingly.
void CreateProxies();
vtkSMMaterialLibraryProxy() = default;
~vtkSMMaterialLibraryProxy() override = default;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment