Beispiel #1
0
// Function name	: Xrefutil::NodeToXref
// Description	    : This method does a straightforward conversion of a Node to an XRef
// Return type		: void 
// Argument         : INode * pNode
// Argument         : TSTR &filename
// Argument         : bool bProxy
// Argument         : bool bIgnoreAnim
void Xrefutil::NodeToXref(INode * pNode, TSTR &filename, bool bProxy, bool bIgnoreAnim)
{
    IXRefObject * pXRef = (IXRefObject *)m_pInterface->CreateInstance(SYSTEM_CLASS_ID, 
        XREFOBJ_CLASS_ID);
    TSTR obName = TSTR(pNode->GetName());
	AssetUser asset = IAssetManager::GetInstance()->GetAsset(filename, kXRefAsset);
    pXRef->Init(asset, obName, pNode->GetObjectRef(), bProxy);
    pNode->SetObjectRef(pXRef);
    // also, set visual queue that we're ignoring anim if we did
    if (bIgnoreAnim)
        pXRef->SetIgnoreAnim(TRUE,FALSE);
}
Beispiel #2
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 ********
	// ********************************************************************************
}