C++ 和 Maya : constructor is private within this context

标签 c++ maya

我正在编译一个使用 Autodesk Maya API 的程序,并收到有关构造函数在此上下文中为私有(private)的错误:

/usr/autodesk/maya2013-x64/include/maya/MFnTransform.h: In member function ‘MayaEggGroup* MayaEggLoader::MakeGroup(EggGroup*, EggGroup*)’:
/usr/autodesk/maya2013-x64/include/maya/MFnTransform.h:181:2: error: ‘MFnTransform::MFnTransform(const MFnTransform&)’ is private
pandatool/src/mayaegg/mayaEggLoader.cxx:373:60: error: within this context

一点背景 - 我正在构建 Panda3D ,(开源游戏引擎),在 Ubuntu 12.04 上,使用 Maya 2013。它在编译将文件从 Maya 转换为 Panda 模型格式的导出器的构建部分中令人窒息。

我(有点)理解错误的含义,但不知道如何解决它。奇怪的是,相同的代码可以在 Maya 2011 和 Maya 2012 中正常编译,并且据我所知,Maya 2013 中的类声明 (MFnTransform) 没有更改。

这是完整的 g++ 命令:

g++ -ftemplate-depth-30 -fPIC -c -o built/tmp/mayaegg2013_loader.o -Ibuilt/tmp -Ibuilt/include -I/usr/include/python2.7 -I/usr/include/eigen3 -I/usr/autodesk/maya2013-x64/include -DMAYAVERSION=MAYA2013 -DMAKEPANDA= -Ipandatool/src/mayaegg -Ipandatool/src/maya -pthread -msse2 -ggdb -D_DEBUG pandatool/src/mayaegg/mayaEggLoader.cxx   

以及一些相关的代码。

在 mayaEggLoader.cxx 中,错误源自此处:

class MayaEggGroup
{
public:
  string  _name;
  MObject _parent;
  MObject _group;

  bool _addedEggFlag;
};
MayaEggGroup *MayaEggLoader::MakeGroup(EggGroup *group, EggGroup *context)
{
    MStatus status;
    MayaEggGroup *result = new MayaEggGroup;
    ...
    MFnTransform tFn = MFnTransform(result->_group, &status);

在 MFnTransform.h 中,这是 MFnTransform 定义的开头:

class OPENMAYA_EXPORT MFnTransform : public MFnDagNode
{
declareDagMFn( MFnTransform, MFn::kTransform );
public:
MObject     create( MObject parent = MObject::kNullObj,MStatus * ReturnStatus = NULL );
    ...

我根本看不到私有(private)构造函数是在哪里定义的......我该如何寻找它?或者这个错误是否意味着其他事情实际上是错误的?

更新:

事实证明,这是 Maya 2013 C++ API 中引入的已知错误:

MAYA-6512: MFnDependencyNode, MFnDagNode copy constructor should be public, not private Workaround: Create a new functionset which operates on the same object, for example: MFnDependencyNode fn2(fn1.object()); If you want to pass a functionset to another method, pass a reference instead.

好的,但是如果我需要设置一个成员变量怎么办?这是我遇到同样错误的另一个地方。

MayaBlendDesc::
MayaBlendDesc(MFnBlendShapeDeformer deformer, int weight_index) 
{
    _weight_index=weight_index;
    _deformer=deformer;
    ostringstream strm;
    strm << _deformer.name().asChar() << "." << _weight_index;
    set_name(strm.str());

    _anim = (EggSAnimData *)NULL;
}

在“_deformer=deformer”行上。

以下是 MayaBlendDesc 的定义。这是我可以编辑的代码。

////////////////////////////////////////////////////////////////////
//       Class : MayaBlendDesc
// Description : A handle to a Maya blend shape description.  This is
//               just one target of a Maya BlendShape object, and
//               thus corresponds more or less one-to-one with a
//               single Egg morph target.  (We don't attempt to
//               support Maya's chained target shapes here; should we
//               need to later, it would mean breaking each of those
//               target shapes on the one continuous Maya slider into
//               a separate MayaBlendDesc object, and synthesizing the
//               egg slider values appropriately.)
////////////////////////////////////////////////////////////////////
class MayaBlendDesc : public ReferenceCount, public Namable {
public:
  MayaBlendDesc(MFnBlendShapeDeformer deformer, int weight_index);
  ~MayaBlendDesc();

  void set_slider(PN_stdfloat value);
  PN_stdfloat get_slider() const;

private:
  void clear_egg();

  MFnBlendShapeDeformer _deformer;
  int _weight_index;

  EggSAnimData *_anim;

public:
  static TypeHandle get_class_type() {
    return _type_handle;
  }
  static void init_type() {
    ReferenceCount::init_type();
    Namable::init_type();
    register_type(_type_handle, "MayaBlendDesc",
                  ReferenceCount::get_class_type(),
                  Namable::get_class_type());
  }

private:
  static TypeHandle _type_handle;

  friend class MayaNodeTree;
};

这是 MFnBlendShape 及其祖先的定义(Maya API 的一部分,我无法触及):

class OPENMAYAANIM_EXPORT MFnBlendShapeDeformer : public MFnDependencyNode
{
    declareMFn(MFnBlendShapeDeformer, MFnDependencyNode );

public:
    //! Specifies the space to use for the deformation origin.
    enum Origin {
        kLocalOrigin,   //!< \nop
        kWorldOrigin    //!< \nop
    };

    //! Specifies where in the shape's history to place the deformer.
    enum HistoryLocation {
        kFrontOfChain,  //!< \nop
        kNormal     //!< \nop
    };

    MObject  create(  MObject baseObject,
                      Origin originSpace = kLocalOrigin,
                      MStatus * ReturnStatus = NULL );
    MObject  create(  const MObjectArray& baseObjects,
                      Origin originSpace = kLocalOrigin,
                      HistoryLocation = kNormal,
                      MStatus * ReturnStatus = NULL );
    MStatus  addBaseObject( MObject & object );
    MStatus  getBaseObjects( MObjectArray & objects ) const;

    MStatus  addTarget( const MObject & baseObject, int weightIndex,
                        const MObject & newTarget, double fullWeight );

    MStatus  removeTarget( const MObject & baseObject,
                           int weightIndex,
                           const MObject & target,
                           double fullWeight );
    MStatus  getTargets( MObject baseObject, int weightIndex,
                         MObjectArray & targetObjects ) const;

    unsigned int numWeights( MStatus * ReturnStatus = NULL ) const;

    MStatus  weightIndexList( MIntArray& indexList ) const;

    MStatus  targetItemIndexList( unsigned int weightIndex,
                                  MObject baseObject,
                                  MIntArray& targetItemIndices ) const;

    float    weight( unsigned int index, MStatus * ReturnStatus = NULL ) const;
    MStatus  setWeight( unsigned int index, float weight );

    float    envelope( MStatus * ReturnStatus = NULL ) const;
    MStatus  setEnvelope( float envelope );

    Origin   origin( MStatus * ReturnStatus = NULL ) const;
    MStatus  setOrigin( Origin space );

BEGIN_NO_SCRIPT_SUPPORT:

    declareMFnConstConstructor( MFnBlendShapeDeformer, MFnDependencyNode );

END_NO_SCRIPT_SUPPORT:

protected:
// No protected members

private:
// No private members
};

MFnDependencyNode:

// ****************************************************************************
// CLASS DECLARATION (MFnDependencyNode)

//! \ingroup OpenMaya MFn
//! \brief Dependency node function set.
/*!
  MFnDependencyNode allows the creation and manipulation of dependency
  graph nodes.  Traversal of the dependency graph is possible using
  the getConnections method.

  This function set does not support creation or removal of connections.
  MDGModifier should be used for that purpose.
*/
class OPENMAYA_EXPORT MFnDependencyNode : public MFnBase
{
    declareMFn(MFnDependencyNode, MFnBase);

public:
    //! Specifies the scope of the attribute.
    enum MAttrClass {
        kLocalDynamicAttr = 1,  //!< Dynamically added, applies to this specific node.
        kNormalAttr,        //!< Static attribute which is part of the original definition for this node type.
        kExtensionAttr,     //!< Extension attribute which is part of all nodes of this or derived node types
        kInvalidAttr        //!< None of the above
    };

    MObject         create( const MTypeId &typeId,
                                MStatus* ReturnStatus = NULL );
    MObject         create( const MTypeId &typeId,
                                const MString& name,
                                MStatus* ReturnStatus = NULL );

    MObject         create( const MString &type,
                                MStatus* ReturnStatus = NULL );
    MObject         create( const MString &type,
                                const MString& name,
                                MStatus* ReturnStatus = NULL );

    MTypeId         typeId( MStatus* ReturnStatus = NULL ) const;
    MString         typeName( MStatus* ReturnStatus = NULL ) const;
    MString         name( MStatus * ReturnStatus = NULL ) const;
    MString         pluginName( MStatus * ReturnStatus = NULL ) const;

    MString         setName( const MString &name,
                             bool createNamespace = false,
                             MStatus * ReturnStatus = NULL );                        
    MStatus         getConnections( MPlugArray& array ) const;
    unsigned int        attributeCount( MStatus* ReturnStatus=NULL) const;
    MObject         attribute(  unsigned int index,
                                MStatus* ReturnStatus=NULL) const;
    MObject         reorderedAttribute( unsigned int index,
                                MStatus* ReturnStatus=NULL) const;
    MObject         attribute(  const MString& attrName,
                                MStatus* ReturnStatus=NULL) const;
    MAttrClass      attributeClass( const MObject& attr,
                                    MStatus* ReturnStatus=NULL) const;
    MStatus         getAffectedAttributes ( const MObject& attr,
                                    MObjectArray& affectedAttributes ) const;
    MStatus         getAffectedByAttributes ( const MObject& attr,
                                    MObjectArray& affectedByAttributes ) const;
    MPlug           findPlug(   const MObject & attr, bool wantNetworkedPlug,
                                MStatus* ReturnStatus=NULL) const;
    MPlug           findPlug(   const MString & attrName, bool wantNetworkedPlug,
                                MStatus* ReturnStatus=NULL) const;
    // Obsolete
    MPlug           findPlug(   const MObject & attr,
                                MStatus* ReturnStatus=NULL) const;
    // Obsolete
    MPlug           findPlug(   const MString & attrName,
                                MStatus* ReturnStatus=NULL) const;
    MStatus         addAttribute    ( const MObject & attr );
    MStatus         removeAttribute ( const MObject & attr );
    MPxNode *       userNode( MStatus* ReturnStatus=NULL ) const;
    bool            isFromReferencedFile(MStatus* ReturnStatus=NULL) const;
    bool            isShared(MStatus* ReturnStatus=NULL) const;
    bool            hasUniqueName(MStatus* ReturnStatus=NULL) const;
    MString         parentNamespace(MStatus* ReturnStatus=NULL) const;
    bool            isLocked(MStatus* ReturnStatus=NULL) const;
    MStatus         setLocked( bool locked );
    static MString  classification( const MString & nodeTypeName );
    bool            isNewAttribute( const MObject& attr,
                                MStatus* ReturnStatus=NULL) const;
    static unsigned int allocateFlag(
                        const MString pluginName, MStatus* ReturnStatus=NULL
                    );
    static MStatus  deallocateFlag(const MString pluginName, unsigned int flag);
    static MStatus  deallocateAllFlags(const MString pluginName);
    MStatus         setFlag(unsigned int flag, bool state);
    bool            isFlagSet(unsigned int flag, MStatus* ReturnStatus=NULL) const;
    bool            isDefaultNode(MStatus* ReturnStatus=NULL) const;

    MStatus         setDoNotWrite ( bool flag );
    bool            canBeWritten(MStatus* ReturnStatus=NULL) const;

    bool            hasAttribute(const MString& name, MStatus* ReturnStatus=NULL) const;

    MObject         getAliasAttr(bool force, MStatus* ReturnStatus=NULL);
    bool            setAlias(const MString& alias,const MString& name, const MPlug& plug, bool add=true,
                    MStatus* ReturnStatus=NULL);
    bool            findAlias(const MString& alias, MObject& attrObj, MStatus* ReturnStatus=NULL) const;
    bool            getAliasList(MStringArray& strArray, MStatus* ReturnStatus=NULL);
    MString         plugsAlias(const MPlug& plug, MStatus* ReturnStatus=NULL);

    MStatus         setIcon( const MString &filename );
    MString         icon( MStatus* ReturnStatus=NULL ) const;



BEGIN_NO_SCRIPT_SUPPORT:

    //! OBSOLETE FUNCTION, NO SCRIPT SUPPORT
    MString         setName( const MString &name,
                             MStatus * ReturnStatus );

    //! NO SCRIPT SUPPORT
    declareMFnConstConstructor( MFnDependencyNode, MFnBase );
    //! NO SCRIPT SUPPORT
    bool            getPlugsAlias(const MPlug& plug, MString& aliasName, MStatus* ReturnStatus=NULL);

END_NO_SCRIPT_SUPPORT:

    // turn on timing on for all nodes in the DG
    static void enableDGTiming(bool enable);

    // For turning node timing on and off, and querying the state...
    MStatus         dgTimerOn();
    MStatus         dgTimerOff();

    //! Possible states for the node's timer.
    enum MdgTimerState {
        kTimerOff,      //!< \nop
        kTimerOn,       //!< \nop
        kTimerUninitialized,    //!< \nop
        kTimerInvalidState  //!< \nop
    };

    MdgTimerState   dgTimerQueryState( MStatus* ReturnStatus = NULL );

    // For resetting node timers to zero...
    MStatus         dgTimerReset();

    //! The different timer metrics which can be queried.
    enum MdgTimerMetric {
        // Primary metrics. The qualities that we measure.
        kTimerMetric_callback,  //!< Time spent within node callbacks for this node.
        kTimerMetric_compute,   //!< Time spent within the compute method for this node.
        kTimerMetric_dirty, //!< Time spent propogating dirty messages from this node.
        kTimerMetric_draw,  //!< Time spent drawing this node.
        kTimerMetric_fetch, //!< Time spent fetching data from plugs.

        // Sub metrics. These are finer-grained breakdowns of the primary
        // metrics. There could be many combinations of the above metrics.
        // Currently we only support the following.
        kTimerMetric_callbackViaAPI,    //!< Time spent in callbacks which were registered through the API.
        kTimerMetric_callbackNotViaAPI, //!< Time spent in callbacks not registered through the API (i.e internal Maya callbacks).
        kTimerMetric_computeDuringCallback, //!< Time spent in this node's compute while executing node callbacks on any node.
        kTimerMetric_computeNotDuringCallback   //!< Time spent in this nodes compute when not executing any node callbacks on any nodes.
    };

    //! The types of timers which can be queried.
    enum MdgTimerType {
        /*!
        Time spent performing an operation, not including any time
        spent by child operations. For example, if we are drawing a
        node and that requires a compute, self time will only include
        the time spent drawing and not the compute time. Self time
        measures wall-clock time as opposed to CPU time and the values
        are in seconds.
        */
        kTimerType_self,

        /*!
        Time spent performing an operation including all time spent by
        child operations. For example, if we are drawing a node and
        that requires a compute, inclusive time is the time for the
        draw plus compute. Inclusive time measure wall-clock time as
        opposed to CPU time and the values are in seconds.
        */
        kTimerType_inclusive,

        /*!
        The number of operations that occurred. Ideally we should
        return an integer when this timer type is queried, but there
        are two advantages to using a double. 1) it keeps the interface
        consistent and 2) integer has a fixed upper bound of roughly
        four billion so using a double allows us to exceed this.
        */
        kTimerType_count
    };

    // Query the timer value given a given metric and timer type.
    double  dgTimer( const MdgTimerMetric           timerMetric,
                            const MdgTimerType      timerType,
                            MStatus* ReturnStatus = NULL ) const;

    // Query the callback timer values.
    MStatus dgCallbacks( const MdgTimerType         type,
                            MStringArray            &callbackName,
                            MDoubleArray            &value );

    // Query the callbackId timer values.
    MStatus dgCallbackIds( const MdgTimerType       type,
                            const MString           &callbackName,
                            MCallbackIdArray        &callbackId,
                            MDoubleArray            &value );

    // Obsolete
    MStatus addAttribute    ( const MObject & attr, MAttrClass type );
    // Obsolete
    MStatus removeAttribute ( const MObject & attr, MAttrClass type );

protected:
// No protected members

private:
// No private members
};

和 MFnBase:

// ****************************************************************************
// CLASS DECLARATION (MFnBase)

//! \ingroup OpenMaya MFn
//! \brief  Function Set Base Class. 
/*!
  Defines the interface for the API RTTI and Maya Object attachment
  methods common to all Function Set Classes.

  Implements the Function Set compatibility test methods for all
  Function Sets.

  The API provides access to Maya Objects as generic MObjects.  Under
  the C++ class scheme MObjects simply have type MObject with no base
  or derived hierarchy.  However, MObjects may be many different types
  of model or scene objects, from Attributes to Transforms, within
  Maya.  This allows many different types of objects to be moved
  across or accessed through the API without undue concern on the part
  of plug-in developers for the type of object being manipulated.

  Since it is impractical to provide every applicable method on
  MObjects, the methods applicable to Maya Objects are encapsulated in
  Function Sets.  Function Sets can be attached to compatible MObjects
  to provide an external interface to methods appropriate to that
  MObject.  All Function Sets provide a method setObject() which
  attaches them to the specified Maya Object.  Additionally, most
  Function Sets provide a version of their constructor which attaches
  the new Function Set to a specified MObject.

  The link between an MObject and the role it performs as a Maya scene
  or model object, as well as the compatibility between MObjects and
  Function Sets is managed by the API Run-Time Type Identification
  (RTTI) system.  The two key concepts of this system are the Maya
  Object type and the Function Set type (both are MFn::Type).  All
  MObjects have one and only one Maya Object type.  All Function Sets
  have one and only one Function Set type.  MObjects may, however, be
  compatible with many types of Function Sets.  This compatibility
  follows the class hierarchy of the Function Sets.  Thus an MObject
  with Maya Object type MFn::kNurbsSurface would be compatible with
  MFnNurbsSurface, MFnDagNode, MFnDependencyNode, MFnNamedObject and
  MFnBase.

  Any MObject can be queried with the MObject::hasFn() method to
  determine if it is comaptible with a given Function Set.

  The purpose of the Base Function Set (MFnBase) is to provide methods for
  determining whether or not a Function Set is compatible with a given Maya
  Object (MObject) type (MFn::Type) or a specific MObject.  See:
                    MFnBase::hasObj(MFn::Type)
                            and
                    MFnBase::hasObj(const MObject &)

  As well, this Function Set provides virtual methods for determining the type
  of a Function Set under the API RTTI system.
*/
class OPENMAYA_EXPORT MFnBase
{
public:
    virtual             ~MFnBase();
    virtual MFn::Type   type() const;
    bool                hasObj( MFn::Type ) const;
    bool                hasObj( const MObject & ) const;
    MObject             object( MStatus* ReturnStatus = NULL ) const;
    virtual MStatus     setObject( MObject & object );

BEGIN_NO_SCRIPT_SUPPORT:

    //! NO SCRIPT SUPPORT
    virtual MStatus     setObject( const MObject & object );

END_NO_SCRIPT_SUPPORT:

    static const char* className();

protected:
    MFnBase();
    void                setPtr( MPtrBase* );
    void                setPtr( const MPtrBase* );
    void                setPtrNull();
    virtual bool        objectChanged( MFn::Type, MStatus * );
    MPtrBase*           f_ptr;      // initialized/set with volatile
    const MPtrBase*     f_constptr; // initialized/set with volatile/const

    // Specific for function sets which use internally reference
    // counted objects!  Only those function sets which use these
    // objects need to set this to true.  By default it is set to
    // false.
    //
    // Classes which do not use internally reference counted objects
    // must not tamper with this boolean value. Doing so can cause
    // crashes when dealing with manually deleted objects.
    //
    bool                fIsReferenceCounted;

private:
    MFnBase( const MFnBase &rhs );
    MFnBase & operator=( const MFnBase & );
    MFnBase * operator& () const;
};

// ****************************************************************************
#define declareMinimalMFn( MFnClass )                               \
    public:                                                         \
        virtual MFn::Type type() const;                             \
        virtual ~MFnClass();                                        \
                                                                    \
        static const char* className();                             \
                                                                    \
    private:                                                        \
        MFnClass( const MFnClass &rhs );                            \
        MFnClass & operator=( const MFnClass & );                   \
        MFnClass * operator& () const;

#define declareMFn( MFnClass, MFnParentClass )                      \
    declareMinimalMFn( MFnClass );                                  \
    public:                                                         \
        MFnClass() {};                                              \
        MFnClass( MObject & object, MStatus * ReturnStatus = NULL )

#define declareMFnConstConstructor( MFnClass, MFnParentClass )      \
        MFnClass( const MObject & object, MStatus * ReturnStatus = NULL )

// Standard MFn class interface *without* the class constructor. This
// is to allow derived MFn classes to optionally specify their own
// custom constructor. For example if they wanted to declare that they
// use internally reference counted objects, they could set fIsReferenceCounted
// to true inside their own custom constructor.
//
#define declareMFnNoVoidConstructor( MFnClass, MFnParentClass )     \
    declareMinimalMFn( MFnClass );                                  \
    public:                                                         \
        MFnClass( MObject & object, MStatus * ReturnStatus = NULL )

#define declareMFnNoVoidConstructorConstConstructor( MFnClass, MFnParentClass )         \
        MFnClass( const MObject & object, MStatus * ReturnStatus = NULL )


#endif /* __cplusplus */
#endif /* _MFnBase */

最佳答案

我没有看到 MFnTransform::MFnTransform(const MFnTransform&)构造函数在任何地方定义(您没有提供足够的代码,但我假设它已被隐式定义为私有(private)),但这没关系 - 您可能不需要它。只需更改:

MFnTransform tFn = MFnTransform(result->_group, &status);

至:

MFnTransform tFn(result->_group, &status);

关于C++ 和 Maya : constructor is private within this context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12067653/

相关文章:

python - 具有自定义属性的 Maya 到 fbx

c++ - 在cpp中创建Maya UI窗口

c++ - 访问 GL_DEPTH_COMPONENT 纹理

python - 项目 2D 指向 3D 球体,每个国家的单个对象

c++ - 清理映射中所有共享指针的正确方法是什么?

c++ - 具有一个显式参数的模板

python - 当您拥有该地理区域的组件时,如何选择该地理区域?

python - 使用文本字段中的文本进行命名 - Maya python

c++ - 转发引用的右值

c++ - 当 ISAPI 筛选器实现 SF_NOTIFY_SEND_RAW_DATA 时,什么会导致吞吐量变得非常慢?