void IfWeeder::weedMaterial(SoNode *root, IfWeederMaterialEntry *entry) { // If the material affects no shapes at all, get rid of it. This // can happen when vertex property nodes are used. if (entry->shapes.getLength() == 0) { SoSearchAction sa; sa.setNode(entry->material); sa.setInterest(SoSearchAction::ALL); sa.apply(root); for (int i = 0; i < sa.getPaths().getLength(); i++) { SoPath *path = sa.getPaths()[i]; SoSeparator *parent = (SoSeparator *) path->getNodeFromTail(1); int index = path->getIndexFromTail(0); ASSERT(parent->isOfType(SoSeparator::getClassTypeId())); ASSERT(parent->getChild(index) == entry->material); parent->removeChild(index); } } // Remove all material values from the material node that are // not used by any dependent shapes. Adjust the indices in the // dependent shapes accordingly. removeDuplicateMaterials(entry); // Now remove all material values that are not used by any // dependent shapes. Again, adjust the indices in the dependent // shapes. removeUnusedMaterials(entry); }