@@ -1111,16 +1111,13 @@ void MaterialBrowser::Resize(Number width, Number height) {
11111111}
11121112
11131113PolycodeMaterialEditor::PolycodeMaterialEditor () : PolycodeEditor(true ){
1114- resourcePool = new ResourcePool (" Local" , CoreServices::getInstance ()->getResourceManager ()->getGlobalPool ());
1115- resourcePool->reloadResourcesOnModify = true ;
11161114
1117- CoreServices::getInstance ()-> getResourceManager ()-> addResourcePool (resourcePool);
1115+
11181116 selectedMaterialNode = NULL ;
11191117}
11201118
11211119PolycodeMaterialEditor::~PolycodeMaterialEditor () {
1122- delete resourcePool;
1123-
1120+ CoreServices::getInstance ()->getResourceManager ()->unsubscibeFromResourcePool (resourcePool);
11241121
11251122 mainWindow->setOwnsChildrenRecursive (true );
11261123 delete mainWindow;
@@ -1130,6 +1127,19 @@ PolycodeMaterialEditor::~PolycodeMaterialEditor() {
11301127
11311128bool PolycodeMaterialEditor::openFile (OSFileEntry filePath) {
11321129
1130+ String resourceName = filePath.fullPath .replace (parentProject->getRootFolder ()+" /" , " " );
1131+
1132+ resourcePool = CoreServices::getInstance ()->getResourceManager ()->getResourcePoolByName (resourceName);
1133+
1134+ if (!resourcePool) {
1135+ resourcePool = new ResourcePool (resourceName, CoreServices::getInstance ()->getResourceManager ()->getGlobalPool ());
1136+ resourcePool->reloadResourcesOnModify = true ;
1137+ resourcePool->deleteOnUnsubscribe = true ;
1138+ CoreServices::getInstance ()->getMaterialManager ()->loadMaterialLibraryIntoPool (resourcePool, filePath.fullPath );
1139+ CoreServices::getInstance ()->getResourceManager ()->addResourcePool (resourcePool);
1140+ }
1141+
1142+ CoreServices::getInstance ()->getResourceManager ()->subscribeToResourcePool (resourcePool);
11331143
11341144 mainSizer = new UIHSizer (100 ,100 ,200 ,false );
11351145 addChild (mainSizer);
@@ -1139,42 +1149,33 @@ bool PolycodeMaterialEditor::openFile(OSFileEntry filePath) {
11391149
11401150 materialBrowser->addEventListener (this , Event::CHANGE_EVENT);
11411151
1142-
1143- shaders = CoreServices::getInstance ()->getMaterialManager ()->loadShadersFromFile (resourcePool, filePath.fullPath );
1144- for (int i=0 ; i < shaders.size (); i++) {
1145- materialBrowser->addShader (shaders[i]);
1146- CoreServices::getInstance ()->getMaterialManager ()->addShader (shaders[i]);
1147- resourcePool->addResource (shaders[i]);
1148- shaders[i]->vp ->reloadOnFileModify = true ;
1149- shaders[i]->fp ->reloadOnFileModify = true ;
1150- }
1151-
1152- cubemaps = CoreServices::getInstance ()->getMaterialManager ()->loadCubemapsFromFile (filePath.fullPath );
1153- for (int i=0 ; i < cubemaps.size (); i++) {
1154- materialBrowser->addCubemap (cubemaps[i]);
1155- resourcePool->addResource (cubemaps[i]);
1156- }
1157-
1158-
1159- std::vector<Material*> mats = CoreServices::getInstance ()->getMaterialManager ()->loadMaterialsFromFile (resourcePool, filePath.fullPath );
1160-
1161- materials.clear ();
1162- for (int i=0 ; i < mats.size (); i++) {
1163- if (mats[i]->screenMaterial ) {
1164- postMaterials.push_back (mats[i]);
1152+ std::vector<Resource*> res = resourcePool->getResources (Resource::RESOURCE_SHADER);
1153+ for (int i=0 ; i < res.size (); i++) {
1154+ Shader *shader = (Shader*)res[i];
1155+ materialBrowser->addShader (shader);
1156+ shader->vp ->reloadOnFileModify = true ;
1157+ shader->fp ->reloadOnFileModify = true ;
1158+ shaders.push_back (shader);
1159+ }
1160+
1161+ res = resourcePool->getResources (Resource::RESOURCE_CUBEMAP);
1162+ for (int i=0 ; i < res.size (); i++) {
1163+ Cubemap *cubemap = (Cubemap*)res[i];
1164+ materialBrowser->addCubemap (cubemap);
1165+ cubemaps.push_back (cubemap);
1166+ }
1167+
1168+ res = resourcePool->getResources (Resource::RESOURCE_MATERIAL);
1169+ for (int i=0 ; i < res.size (); i++) {
1170+ Material *material = (Material*)res[i];
1171+ if (material->screenMaterial ) {
1172+ postMaterials.push_back (material);
1173+ materialBrowser->addPostMaterial (material);
11651174 } else {
1166- materials.push_back (mats[i]);
1175+ materials.push_back (material);
1176+ materialBrowser->addMaterial (material);
11671177 }
1168- }
1169-
1170- for (int i=0 ; i < materials.size (); i++) {
1171- materialBrowser->addMaterial (materials[i]);
1172- resourcePool->addResource (materials[i]);
1173- }
1174-
1175- for (int i=0 ; i < postMaterials.size (); i++) {
1176- materialBrowser->addPostMaterial (postMaterials[i]);
1177- }
1178+ }
11781179
11791180 mainWindow = new MaterialMainWindow (resourcePool);
11801181 mainSizer->addLeftChild (mainWindow);
0 commit comments