Example #1
0
// Function name	: Xrefutil::AddNewXrefScene_IXROMGR
// Description	    : The purpose of this method is to provide a show of how to 
//						bring in xref objects by way of the IXRefObjectManager
//						interface.  As pertaining to this sample, the 
//						functionality it provides replaces most of the scene
//						scene enumeration and ::NodeToXref() call.
// Return type		: void 
// Argument         : HWND hWnd
void Xrefutil::AddNewXrefScene_IXROMGR(HWND hWnd)
{
	IXRefObject *pXRef;  // a temporary XRef object to handle the incoming one
	
	//  This is just a copy of the same variables from ::AddNewXrefObject
	INode * pNode = NULL;
    TSTR filename = _T("");
    TSTR pickedname = _T("");
    TSTR * workname = NULL;
	
	
	// getting the interface pointer
	m_pIobjrefmgr = static_cast<IObjXRefManager *>(GetCOREInterface(OBJXREFMANAGER_INTERFACE));
	
	//  if we don't get a good pointer to an IObjXRefManager _IS_REALLY_ bad!
	//  I am opting to just leave the method. 
	if(!m_pIobjrefmgr) {
		return;
	}
	
	// ********************************************************************************
	// ********** BELOW THIS LINE EVERYTHING IS COPIED FROM ::AddNewXrefObject ********
	// ********************************************************************************
	
    INode * pRootNode = m_pInterface->GetRootNode();
    if (!pRootNode) {
        // well, this is actually _really_ bad, but we just exit
        return;
    }
    if (!DoOpenSaveDialog(filename, true)) {
        // either cancel or fail, just return
        return;
    }
	
	// in preparation for merge, flag current scene nodes
    NodeFlagger newFlagger(A_WORK1);
    newFlagger.Enumerate(pRootNode);
	
	// merge in user-picked file into current scene
	// NOTE: We just skip anything in xref'd file that has the same name
	// as an object in the current scene
    if (! m_pInterface->MergeFromFile(filename, TRUE, FALSE, FALSE, MERGE_DUPS_SKIP, NULL)) {
        // error, merge failed
        newFlagger.set_clear(true);
        newFlagger.Enumerate(pRootNode);
        return;
    }
	
    // walk scene and build list of non-flagged nodes
    m_objnamesholder.ZeroCount();
	m_objnamesholder.Shrink();
    UnflaggedNodeNamer newNamer;
    newNamer.m_namelist = &m_objnamesholder;
    newNamer.Enumerate(pRootNode);
    UnflaggedNodeDeleter newDeleter;
	
    // present list of nodes to user, sep. modal dialog
    if (DoPickObjDialog() && m_picknameholder.length() > 0) {
        pNode = m_pInterface->GetINodeByName(m_picknameholder);
        if (pNode) {
            if (m_ignoreanimholder && pNode->IsAnimated()) {
                // if animation is ignored, we basically go through
                // the node and delete all the keys for the node's controllers
                // Note that this won't remove animation for procedural controllers
                DeleteAllAnimation(pNode);
            }
			// Woohoo!  we get to use the IXRefObjectManager interface
			AssetUser asset = IAssetManager::GetInstance()->GetAsset(filename,kXRefAsset);
			pXRef = m_pIobjrefmgr->AddXRefObject(asset, pNode->GetName(), m_proxyholder);
			pNode->SetObjectRef(pXRef);
			
			// also, set visual queue that we're ignoring anim if we did
			if (m_ignoreanimholder)
				pXRef->SetIgnoreAnim(TRUE,FALSE);
			// flag this converted node so we keep it
			pNode->SetAFlag(A_WORK1);
        }
    }
	
    // deleted non-flagged nodes, un-flag original nodes, and return
    newDeleter.Enumerate(pRootNode);
    newFlagger.set_clear(true);
    newFlagger.Enumerate(pRootNode);
    for (int delme = 0; delme < m_objnamesholder.Count(); delme++) { 
        // (clean up TSTRs)
        delete m_objnamesholder[delme];
    }
	
    m_pInterface->RedrawViews(m_pInterface->GetTime());
	
	// ********************************************************************************
	// ********** ABOVE THIS LINE EVERYTHING IS COPIED FROM ::AddNewXrefObject ********
	// ********************************************************************************
}
Example #2
0
// Function name	: Xrefutil::AddNewXrefObject
// Description	    : ...please read below...
// Return type		: void 
// Argument         : HWND hWnd
void Xrefutil::AddNewXrefObject(HWND hWnd)
{
    // *** AddNewXrefObject ***
    //
    // Tries to mimic the functionality of MAX's Add New XRef Object
    // 
    // Does the following:
    // 1) Gets a source .MAX filename from user to get the XRef Object from
    // 1.5) Flags current nodes for later
    // 2) Merges in this file, but doesn't display end results (yet)
    // 3) Walks list of file nodes (not flagged), and lets user pick one to XRef
    // 4) Blows away all merged (not flagged) nodes except picked node.  Converts
    //    the chosen node into an XRef node (see ConvertSelectedToXrefObject below)
    //    with default settings
	
    INode * pNode = NULL;
    TSTR filename = _T("");
    TSTR pickedname = _T("");
    TSTR * workname = NULL;
	
    INode * pRootNode = m_pInterface->GetRootNode();
    if (!pRootNode) {
        // well, this is actually _really_ bad, but we just exit
        return;
    }
    if (!DoOpenSaveDialog(filename, true)) {
        // either cancel or fail, just return
        return;
    }
	
    // in preparation for merge, flag current scene nodes
    NodeFlagger newFlagger(A_WORK1);
    newFlagger.Enumerate(pRootNode);
	
    // merge in user-picked file into current scene
    // NOTE: We just skip anything in xref'd file that has the same name
    // as an object in the current scene
    if (! m_pInterface->MergeFromFile(filename, TRUE, FALSE, FALSE, MERGE_DUPS_SKIP, NULL)) {
        // error, merge failed
        newFlagger.set_clear(true);
        newFlagger.Enumerate(pRootNode);
        return;
    }
	
    // walk scene and build list of non-flagged nodes
    m_objnamesholder.ZeroCount();
	m_objnamesholder.Shrink();
    UnflaggedNodeNamer newNamer;
    newNamer.m_namelist = &m_objnamesholder;
    newNamer.Enumerate(pRootNode);
    UnflaggedNodeDeleter newDeleter;
	
    // present list of nodes to user, sep. modal dialog
    if (DoPickObjDialog() && m_picknameholder.length() > 0) {
        pNode = m_pInterface->GetINodeByName(m_picknameholder);
        if (pNode) {
            if (m_ignoreanimholder && pNode->IsAnimated()) {
                // if animation is ignored, we basically go through
                // the node and delete all the keys for the node's controllers
                // Note that this won't remove animation for procedural controllers
                DeleteAllAnimation(pNode);
            }
            NodeToXref(pNode, filename, m_proxyholder, m_ignoreanimholder);
            // flag this converted node so we keep it
            pNode->SetAFlag(A_WORK1);
        }
    }
	
    // deleted non-flagged nodes, un-flag original nodes, and return
    newDeleter.Enumerate(pRootNode);
    newFlagger.set_clear(true);
    newFlagger.Enumerate(pRootNode);
    for (int delme = 0; delme < m_objnamesholder.Count(); delme++) { 
        // (clean up TSTRs)
        delete m_objnamesholder[delme];
    }
	
    m_pInterface->RedrawViews(m_pInterface->GetTime());
	
}