Node Traversal

3DSMAXÀÇ ¸ðµ¨ ±¸Á¶´Â ¾À ³ëµå·Î ÀÌ·ïÁ® ÀÖ´Ù. À̹ø Àå¿¡¼­´Â ¾À ³ëµå¸¦ ¼øȸ Çϸ鼭 ³ëµåÀÇ À̸§À» Ãâ·ÂÇØ ¹®ÀÚ¿­·Î Ãâ·ÂÇØ º»´Ù.

class maxPluginTest : public SceneExport {

    ......

    ......

    ......

    private:

        //¾À³ëµå¸¦ ¼øȸÇÏ´Â Àç±Í È£Ãâ ¸Þ½îµå

        void Export(INode* pNode, int iTreeDepth = 0);

        FILE* m_pFile;

        //m_pFile ÀúÀå ½ÃÀÛ

        bool BeginWriting(const char* pPath);

        //m_pFile ÀúÀå ¿Ï·á

        void EndWriting();

        //iTreeDepthÀÇ ±íÀ̸¦ indent·Î Àü´ÞÇÏ¿© ¹®ÀÚ¿­·Î m_pFile¿¡ ÀúÀåÇÑ´Ù.

        void Write(int indent, const char* pMsg, ...);

 

};

DoExport()¿¡¼­ °£´ÜÇÏ°Ô Å×½ºÆ® Çϱâ À§ÇØ ±âº»ÀÇ ½ÇÇ๮Àº ÁÖ¼® ó¸®ÇÑ´Ù.
Export() ¸í·É¿¡ ÀÇÇØ Àç±Í È£Ãâ ½ÇÇà µÇ¸é¼­ ³ëµåÀÇ À̸§À» ÀúÀåÇÑ´Ù.

int    maxPluginTest::DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts, DWORD options)

{

    //TODO: Implement the actual file Export here and

    //        return TRUE If the file is exported properly

/*

    if(!suppressPrompts)

        DialogBoxParam(hInstance,

                MAKEINTRESOURCE(IDD_PANEL),

                GetActiveWindow(),

                maxPluginTestOptionsDlgProc, (LPARAM)this);

*/

    if (BeginWriting(name))

    {

        // Interface* can also be accessed by GetCOREInterface()

        INode* pRootNode = i->GetRootNode();

 

        //Export tree.

        Export(pRootNode);

 

        EndWriting();

 

        return TRUE; // We have successfully exported to our file!

    }

 

    // If we are here, something in the export failed.

    return FALSE;

}

 

 

void maxPluginTest::Export(INode* pNode, int iTreeDepth /* = 0 */)

{

    // First step to export: What are we exporting?

    // Here we are going to export the basic scene tree,

    // identifying each node by name.

 

    MCHAR* pNodeName = pNode->GetName();

    int nChildren = pNode->NumberOfChildren();

 

    // Write out this node as [NodeName] : XX Children

    Write(iTreeDepth, "[%s] : %i children", pNodeName, nChildren);

 

    // Recursively call the children

    iTreeDepth++;

    for (int i = 0; i < nChildren; i++)

    {

        Export(pNode->GetChildNode(i), iTreeDepth);

    }

}

 

bool maxPluginTest::BeginWriting(const char *pPath)

{

    // Check we are not currently writing

    DbgAssert(m_pFile == NULL);

 

    errno_t lErr = fopen_s(&m_pFile, pPath, "w");

    return ( lErr == 0 );

}

 

void maxPluginTest::EndWriting()

{

    DbgAssert(m_pFile != NULL);

 

    fclose(m_pFile);

    m_pFile = NULL;

}

 

void maxPluginTest::Write(int indent, const char* pMsg, ...)

{

    DbgAssert(m_pFile != NULL);

 

    // first, write in the indent

    for (int i = 0; i < indent; i++) fprintf_s(m_pFile, "\t");

 

    // Write the message, passing in our variable

    // parameters to a function that wraps printf

    va_list vargs;

    va_start(vargs, pMsg);

    vfprintf_s(m_pFile, pMsg, vargs);

    va_end(vargs);

 

    // Finish the line

    fprintf_s(m_pFile, "\n");

}

 

¹Ú½º¸¦ Çϳª ÀͽºÆ÷Æ® ÇÑÈÄ ½ÇÇà °á°ú

[Scene Root] : 1 children
    [Box01] : 0 children