Maya变换节点未出现在DAG中

时间:2016-01-12 11:18:51

标签: api boolean nodes maya nurbs

this讨论后,我发现使用python命令 cmds.refresh()在循环中刷新Maya场景最终会导致应用程序崩溃(内存不足)在循环返回之前)。

讨论中提出的问题与创建一个nurbs布尔表面有关,首先,取大球和一个以大球体表面为中心的小球之间的差异,然后取得所得到的nurbs曲面的差异。第二个小球体。此几何体的DAG层次结构是surfaceVarGroup,nurbsBooleanSurface1,为三个变换节点nurbsBooleanSurface1_1,nurbsBooleanSurface1_2和nurbsBooleanSurface1_3提供父级,每个节点都是其自身形状节点的父级。

奇怪的是,在执行

cmds.nurbsBoolean("nurbsSphere1", "nurbsSphere2", nsf=1, op=1)

(其中 nurbsSphere1 是大球体, nurbsSphere2 是两个小球体中的第一个)其次是

print(cmds.ls("nurbsBooleanSurface1_*", type="transform"))

按预期产生[u'nurbsBooleanSurface1_1',u'nurbsBooleanSurface1_2'],随后执行

cmds.nurbsBoolean("nurbsBooleanSurface1", "nurbsSphere3", nsf=1, op=1)

(其中 nurbsBooleanSurface1 是由上述布尔计算产生的'单凹坑'nurbs曲面,而 nurbsSphere3 是两个小球体中的第二个)接下来是

print(cmds.ls("nurbsBooleanSurface1_*", type="transform"))

再次产生[u'nurbsBooleanSurface1_1',u'nurbsBooleanSurface1_2']; nurbsBooleanSurface1_3丢失。

amorten's解决方案涉及通过调用 cmds.refresh()在第二次布尔计算后刷新场景。但正如我所说,这不适用于循环(其迭代次数大于100)。

我发现nurbsBooleanSurface1_3在程序执行期间不会显示为DAG节点;它最后会出现'爆裂'。以下c ++ API代码遍历场景中的所有DAG节点:

#include <maya/MSimple.h>
#include<maya/MGlobal.h>
#include <iostream>
#include <maya/MIOStream.h>
#include <maya/MString.h>
#include <maya/MDagPath.h>
#include<maya/MObject.h>
#include<maya/MItDag.h>
#include<maya/MFnDagNode.h>

// This command iteratively computes the boolen difference between a large nurbs surface and a set of small nurbs spheres. It first
// executes the nurbs boolean (difference) command on a pair of intersecting nurbs spheres, one of radius 10 (the large sphere) and
// the other of radius 3 (a small sphere, whose centre sits on the surface of the large sphere). The result is a transform node Maya names 
// nurbsBooleanSurface1, which has two children transform nodes, nurbsBooleanSurface1_1 and nurbsBooleanSurface1_2. The latter are the two  
// components of the dimpled large sphere.
//
// When the nurbs boolean command is executed on nurbsBooleanSurface1 and a second small sphere of radius 3, a thrid node, nurbsBooleanSurface1_3,
// is added to the list of child nodes parented by nurbsBooleanSurface1.
//
// The problem is that nurbsBooleanSurface1_3 does not appear in the DAG during program execution.

DeclareSimpleCommand( nurbsBooleanSurface, "A test of the presence in the DAG of the child nodes of a nurbs boolean surface node", "4.0");

MStatus nurbsBooleanSurface::doIt( const MArgList& args ) {

    MStatus stat = MS::kSuccess;

    // Create the large sphere
    MGlobal::executeCommand("sphere -r 10 -n sphere1");

    // Create the first small sphere, with centre on the surface of the large sphere at (10,0,0)
    MGlobal::executeCommand("sphere -r 3 -n sphere2");
    MGlobal::executeCommand("setAttr \"sphere2.translateX\" 10;");

    // First nurbs boolean computation
    stat = MGlobal::executeCommand("nurbsBoolean -nsf 1 -op 1 sphere1 sphere2;");

    // Check the boolean computation
    if(stat==MS::kSuccess) {
        std::cout << "Boolean computation success." << std::endl;
    }
    else {
        displayError("Boolean computation fail.");
    }

    // Create the second small sphere, with centre on the surface of the nurbs boolean surface at (0,10,0)
    MGlobal::executeCommand("sphere -r 3 -n sphere3");
    MGlobal::executeCommand("setAttr \"sphere3.translateY\" 10;");

    // Second nurbs boolean computation
    stat = MGlobal::executeCommand("nurbsBoolean -nsf 1 -op 1 nurbsBooleanSurface1 sphere3;");

    if(stat==MS::kSuccess) {
        std::cout << "Boolean computation success." << std::endl;
    }
    else {
        displayError("Boolean computation fail.");
    }

    // Use an iterator to traverse the DAG nodes
    MItDag it(MItDag::kDepthFirst);

    // Loop through all the DAG nodes
    while(!it.isDone()) {

        // Attach a function set for a DAG node to the
        // object. Rather than access data directly, 
        // it is accessed via the function set. 
        MFnDagNode fn(it.currentItem());

        // Get the name of the node 
        MString name = fn.name();

        // Write the node type found
        cout << "node: " << name.asChar() << endl;

        // Write the info about the children 
        cout <<"num_children " << fn.childCount() << endl;

        for(int i=0;i<fn.childCount();++i) {

            // Get the MObject for the ith child 
            MObject child = fn.child(i);

            // Attach a function set to it
            MFnDagNode fnChild(child);

            // Write the child name
            cout << "\t" << fnChild.name().asChar();
            cout << endl;
        }

        // Write the info about the parents
        cout<<"num_parents "<< fn.parentCount() << endl;

        for(int i=0;i<fn.parentCount();++i) {

            // Get the MObject for the ith parent
            MObject parent = fn.parent(i);

            // Attach a function set to it
            MFnDagNode fnParent(parent);

            // Write the parent name
            cout << "\t" << fnParent.name().asChar();
            cout << endl;
        }

        // Move to next node
        it.next();
    }

    return stat;
}     

输出窗口中的相关片段是

node: nurbsBooleanSurface1
num_children 2
    nurbsBooleanSurface1_1
    nurbsBooleanSurface1_2
num_parents 1
world

显然没有提到难以捉摸的nurbsBooleanSurface1_3。

所以我的问题是, 这个节点或其数据存储在程序执行期间以什么形式?它必须位于Maya的数据库某处

在找到它的位置后,我也想知道如何访问它。

0 个答案:

没有答案