C ++和Maya:构造函数在此上下文中是私有的

时间:2012-08-22 06:47:08

标签: c++ maya

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

/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

一点背景 - 我正在使用Maya 2013在Ubuntu 12.04上构建Panda3D(一个开源游戏引擎)。它正在构建的一部分,它正在编译从以下位置转换文件的导出器Maya成熊猫的模型格式。

我(有点)了解错误的含义,但不了解如何解决错误。奇怪的是,相同的代码在Maya 2011和Maya 2012中编译得很好,而据我所知,2013年的Maya中的类声明(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 );
    ...

我根本没有看到私人构造函数的定义...我该如何去寻找呢?或者这个错误是否意味着其他东西实际上是错误的?

更新

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

  

MAYA-6512:MFnDependencyNode,MFnDagNode复制构造函数应该是公共的,而不是私有的   解决方法:创建一个对同一对象进行操作的新函数集,例如:   MFnDependencyNode fn2(fn1.object());   如果要将函数集传递给另一个方法,请改为传递引用。

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

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 */

1 个答案:

答案 0 :(得分:2)

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

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

为:

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