Example #1
0
int LoadMapFiles(INode* node, SContext* sc, MtlBaseLib& mtls, TimeValue t)
{
	NameTab mapFiles;
	CheckFileNames checkNames(&mapFiles);

	node->EnumAuxFiles(checkNames, FILE_ENUM_MISSING_ONLY | FILE_ENUM_1STSUB_MISSING);

	// Check the lights
	for (int i = 0; i < sc->lightTab.Count(); i++) {
		if (((LightInfo*)sc->lightTab[i])->light != NULL) {
			((LightInfo*)sc->lightTab[i])->light->EnumAuxFiles(checkNames, 
				FILE_ENUM_MISSING_ONLY | FILE_ENUM_1STSUB_MISSING);
		}
	}

	if (mapFiles.Count()) {
		// Error! Missing maps.
		// not sure how to handle this so we gladly continue.
			
		//if (MessageBox(hWnd, "There are missing maps.\nDo you want to render anyway?", "Warning!", MB_YESNO) != IDYES) {
		//	return 0;
		//}
	}

	// Load the maps
	MapLoadEnum mapload(t);
	for (i=0; i<mtls.Count(); i++) {
		EnumMaps(mtls[i],-1, mapload);
	}

	return 1;
}
Example #2
0
void plMerge()
{
    Interface *ip = GetCOREInterface();

    // Get the Max filename to merge
    char file[MAX_PATH];
    memset(&file, 0, sizeof(file));

    OPENFILENAME ofn = {0};
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = ip->GetMAXHWnd();
    ofn.lpstrFilter = "3ds max (*.max)\0*.max\0\0";
    ofn.nFilterIndex = 1;
    ofn.lpstrFile = file;
    ofn.nMaxFile = sizeof(file);
//  ofn.lpstrInitialDir = ip->GetDir(APP_SCENE_DIR);
    ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
    ofn.lpstrTitle = "Merge";

    if (!GetOpenFileName(&ofn))
        return;

    // Don't actually merge yet, just get the names of every node in the file
    NameTab nodeNames;
    ip->MergeFromFile(file, TRUE, FALSE, FALSE, MERGE_LIST_NAMES, &nodeNames);

    // For each node name, search the current scene for a component with the same name.
    // If one is found, append "Merged" to it so its name won't cause a conflict during
    // the actual merge.
    std::vector<plMaxNode*> renamedNodes;
    int i;
    for (i = 0; i < nodeNames.Count(); i++)
    {
        plMaxNode *node = IFindComponentRecur((plMaxNode*)ip->GetRootNode(), nodeNames[i]);
        if (node)
        {
            char buf[256];
            strcpy(buf, node->GetName());
            strcat(buf, "Merged");
            node->SetName(buf);

            renamedNodes.push_back(node);
        }
    }

    // Do the merge
    ip->MergeFromFile(file);

    // Rename the components back to their original names
    for (i = 0; i < renamedNodes.size(); i++)
    {
        char buf[256];
        strcpy(buf, renamedNodes[i]->GetName());
        buf[strlen(buf)-6] = '\0';
        renamedNodes[i]->SetName(buf);
    }

    // Put all the components in the scene in a list
    std::vector<plComponentBase*> components;
    IFindComponentsRecur((plMaxNode*)ip->GetRootNode(), components);

    nodeNames.ZeroCount();

    // For each component, search the scene for any other components with the same
    // name and type.  If there are any, merge their target lists and delete one.
    for (i = 0; i < renamedNodes.size(); i++)
    {
        if (!renamedNodes[i])
            continue;

        plComponentBase *oldComp = renamedNodes[i]->ConvertToComponent();
        char *oldCompName = oldComp->GetINode()->GetName();

        for (int j = 0; j < components.size(); j++)
        {
            plComponentBase *comp = components[j];

            if (oldComp == comp)
                components[j] = nil;
            else if (comp)
            {
                const char *temp = comp->GetINode()->GetName();
                
                if (!strcmp(oldCompName, comp->GetINode()->GetName()) &&
                    comp->ClassID() == comp->ClassID())
                {
                    IMergeComponents(comp, oldComp);
                    nodeNames.AddName(oldCompName);
                    continue;
                }
            }
        }
    }

    // Send out merge notifications again, so that the component dialog will be updated
    BroadcastNotification(NOTIFY_FILE_PRE_MERGE);
    BroadcastNotification(NOTIFY_FILE_POST_MERGE);

#if 0
    if (nodeNames.Count() == 0)
        return;

    // Actually calculate the size of all the merged component names, because
    // a static buffer could be too small in large merges
    uint32_t size = 0;
    for (i = 0; i < nodeNames.Count(); i++)
        size += strlen(nodeNames[i]) + 1;

    // Put all the component names in a list and show it to the user
    char *buf = new char[size+25];
    strcpy(buf, "Components Merged:\n\n");

    for (i = 0; i < nodeNames.Count(); i++)
    {
        strcat(buf, nodeNames[i]);
        strcat(buf, "\n");
    }

    MessageBox(ip->GetMAXHWnd(), buf, "Components Merged", MB_OK);
    
    delete [] buf;
#endif
}