[cgkit-commits] maya/maya_wrapper createplugincode.py,NONE,1.1 extraheaders.h,NONE,1.1 maya_sdk.h,NO
Brought to you by:
mbaas
From: Matthias B. <mb...@us...> - 2006-04-12 20:03:54
|
Update of /cvsroot/cgkit/maya/maya_wrapper In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25859 Added Files: createplugincode.py extraheaders.h maya_sdk.h pypp_setup.py Log Message: Added the py++ driver script --- NEW FILE: extraheaders.h --- /* This header is included in every generated source file. */ #include <maya/MAngle.h> #include <maya/MArgList.h> #include <maya/MBoundingBox.h> #include <maya/MClothParticle.h> #include <maya/MColorArray.h> #include <maya/MCommonRenderSettingsData.h> #include <maya/MCommandResult.h> #include <maya/MDagModifier.h> #include <maya/MDagPath.h> #include <maya/MDagPathArray.h> #include <maya/MDistance.h> #include <maya/MDoubleArray.h> #include <maya/MDrawData.h> #include <maya/MEulerRotation.h> #include <maya/MFloatArray.h> #include <maya/MFloatMatrix.h> #include <maya/MFloatVector.h> #include <maya/MFloatVectorArray.h> #include <maya/MFloatPointArray.h> #include <maya/MGeometryData.h> #include <maya/MImage.h> #include <maya/MIteratorType.h> #include <maya/MItGeometry.h> #include <maya/MMatrix.h> #include <maya/MObjectArray.h> #include <maya/MPlug.h> #include <maya/MPlugArray.h> #include <maya/MPoint.h> #include <maya/MPointArray.h> #include <maya/MPxContext.h> #include <maya/MPxData.h> #include <maya/MPxGlBuffer.h> #include <maya/MPxHwShaderNode.h> #include <maya/MPxNode.h> #include <maya/MPxSurfaceShapeUI.h> #include <maya/MQuaternion.h> #include <maya/MSelectionList.h> #include <maya/MString.h> #include <maya/MStringArray.h> #include <maya/MTime.h> #include <maya/MTrimBoundaryArray.h> #include <maya/MUintArray.h> #include <maya/MVector.h> #include "mglobal.h" #include "mstatus.h" #include "mstring.h" #include "mvector.h" #include "mpoint.h" #include "mfloatvector.h" #include "mfloatpoint.h" #include "mobject.h" #include "mfnplugin.h" #include "mitselectionlist.h" #include "mdatahandle.h" #include "mselectionlist.h" #include "mplug.h" #include "mpointarray.h" #include "mvectorarray.h" --- NEW FILE: createplugincode.py --- # Create extra source code for managing plugins # createObj2Ptr def createObj2Ptr(mpxclasses, out): print >>out, """/** Convert a Python object into a raw pointer. The Python object must be an instance of a MPx... class, otherwise 0 is returned. \\param obj The Python object that holds a MPx instance \\returns Corresponding C++ object or 0. */ void* object2ptr(boost::python::object& obj) {""" for i,cls in enumerate(mpxclasses): print >>out, " boost::python::extract<%s&> x%d(obj);"%(cls,i) print >>out, " if (x%d.check()) return &(x%d());"%(i,i) print >>out, " return 0;\n}\n" # createCreatorFuncs def createCreatorFuncs(n, out): for i in range(n): print >>out, """/** Creator function that will be passed to Maya via the C++ MFnPlugin object. This function invokes the Python function with index %d. This function must return an object derived from a MPx class. The C++ object is extracted from the Python object and a reference to that object is returned. */ void* createFunc%04d() { boost::python::object pyres = pycreatorfuncs[%d](); void* res = object2ptr(pyres); if (res==0) { std::cerr<<"ERROR: creator function did not return a MPx object."<<std::endl; } else { // Increase the reference count of the created plugin object, // otherwise the instance would be deleted by Python when this function // terminates. Maya will take over the responsibility of deleting the // object (the reference count will however never decrease again). Py_XINCREF(pyres.ptr()); } return res; }\n"""%(i,i,i) # createCreateSyntaxFuncs def createCreateSyntaxFuncs(n, out): for i in range(n): print >>out, """/** Syntax creator function that will be passed to Maya via the C++ MFnPlugin object. This function invokes the corresponding Python function with index %d. This function must return a MSyntax object. The C++ object is extracted from the Python object and is returned. */ MSyntax createSyntaxFunc%04d() { boost::python::object pyres = pycreatesyntaxfuncs[%d](); boost::python::extract<MSyntax> x(pyres); if (x.check()) { return x(); } else { std::cerr<<"ERROR: Syntax creator function did not return a MSyntax object."<<std::endl; return MSyntax(); } }\n"""%(i,i,i) # createInitFuncs def createInitFuncs(n, out): for i in range(n): print >>out, """/** Init function that will be passed to Maya via the C++ MFnPlugin object. This function invokes the corresponding Python function with index %d. This function must return a MStatus object. The C++ object is extracted from the Python object and is returned. */ MStatus initFunc%04d() { boost::python::object pyres = pyinitfuncs[%d](); boost::python::extract<MStatus> x(pyres); if (x.check()) { return x(); } else { std::cerr<<"ERROR: Init function did not return a MStatus object."<<std::endl; return MStatus::kFailure; } }\n"""%(i,i,i) # createSourceFile def createSourceFile(mpxclasses, numcreators, numscreators, numinits, out): print >>out, """/* Plugin creator functions. This file was generated automatically and is included in the file creatorfuncmanager.cpp. */ """ for cls in mpxclasses: print >>out, "#include <maya/%s.h>"%cls print >>out, "" print >>out, "static const int MAX_CREATOR_FUNCTIONS = %d;"%numcreators print >>out, "static const int MAX_CREATESYNTAX_FUNCTIONS = %d;"%numscreators print >>out, "static const int MAX_INIT_FUNCTIONS = %d;"%numinits print >>out, "static boost::python::object pycreatorfuncs[MAX_CREATOR_FUNCTIONS];" print >>out, "static boost::python::object pycreatesyntaxfuncs[MAX_CREATOR_FUNCTIONS];" print >>out, "static boost::python::object pyinitfuncs[MAX_INIT_FUNCTIONS];" print >>out, "" createObj2Ptr(mpxclasses, out) createCreatorFuncs(numcreators, out) createCreateSyntaxFuncs(numscreators, out) createInitFuncs(numinits, out) print >>out, "// A list with the C creator functions" print >>out, "// (so that they can be referenced by index)" print >>out, "static CreatorFunc ccreatorfuncs[MAX_CREATOR_FUNCTIONS] = {" for i in range(numcreators): out.write(" createFunc%04d"%i) if i<numcreators-1: print >>out, "," else: print >>out, "" print >>out, "};\n" print >>out, "// A list with the C syntax creator functions" print >>out, "// (so that they can be referenced by index)" print >>out, "static CreateSyntaxFunc ccreatesyntaxfuncs[MAX_CREATESYNTAX_FUNCTIONS] = {" for i in range(numscreators): out.write(" createSyntaxFunc%04d"%i) if i<numscreators-1: print >>out, "," else: print >>out, "" print >>out, "};\n" print >>out, "// A list with the C init functions" print >>out, "// (so that they can be referenced by index)" print >>out, "static InitFunc cinitfuncs[MAX_INIT_FUNCTIONS] = {" for i in range(numinits): out.write(" initFunc%04d"%i) if i<numinits-1: print >>out, "," else: print >>out, "" print >>out, "};\n" --- NEW FILE: pypp_setup.py --- #!/usr/bin/env python ###################################################################### # pyplusplus script for wrapping the Maya SDK ###################################################################### import sys, os.path from pypp_api import * import createplugincode import logging # Replace with test version import pypp_api import declwrapper pypp_api.DeclWrapper = declwrapper.IDecl from decltypes import arg, cpp ###################################################################### MAX_CREATOR_FUNCTIONS = 200 MAX_CREATESYNTAX_FUNCTIONS = 200 MAX_INIT_FUNCTIONS = 200 mayaincpath = "/usr/aw/maya7.0/include" ###################################################################### logger = logging.getLogger('pyplusplus') logger.setLevel(logging.INFO) # A list of classes the should be included in the wrappers classes = [ "M3dView", "MAngle", "MAnimControl", "MAnimCurveChange", "MAnimCurveClipboard", "MAnimCurveClipboardItem", "MAnimCurveClipboardItemArray", ### "MAnimMessage", "MAnimUtil", "MArgDatabase", "MArgList", "MArgParser", "MArrayDataBuilder", "MArrayDataHandle", "MAttributeIndex", "MAttributeSpec", "MAttributeSpecArray", "MBoundingBox", # "MCallbackIdArray", "MClothConstraint", "MColor", "MColorArray", "MCommandResult", "MComputation", "MDGContext", "MDGModifier", "MDagModifier", "MDagPath", "MDagPathArray", "MDataBlock", "MDataHandle", "MDeviceChannel", "MDeviceState", "MDistance", "MDoubleArray", "MDrawInfo", "MDrawProcedureBase", "MDrawRequest", "MDrawRequestQueue", "MDynSweptLine", "MDynSweptTriangle", "MEulerRotation", "MEvent", "MFeedbackLine", "MFileIO", "MFileObject", "MFloatArray", "MFloatMatrix", "MFloatPoint", "MFloatPointArray", "MFloatVector", "MFloatVectorArray", "MFn", "MFnAirField", "MFnAmbientLight", "MFnAnimCurve", "MFnAnisotropyShader", "MFnAreaLight", "MFnArrayAttrsData", "MFnAttribute", "MFnBase", "MFnBlendShapeDeformer", "MFnBlinnShader", "MFnCamera", "MFnCharacter", "MFnCircleSweepManip", "MFnClip", "MFnComponent", "MFnComponentListData", "MFnCompoundAttribute", "MFnCurveSegmentManip", "MFnDagNode", "MFnData", "MFnDependencyNode", "MFnDirectionManip", "MFnDirectionalLight", "MFnDiscManip", "MFnDistanceManip", "MFnDoubleIndexedComponent", "MFnDragField", "MFnDynSweptGeometryData", "MFnEnumAttribute", "MFnExpression", "MFnField", "MFnFreePointTriadManip", "MFnGenericAttribute", "MFnGeometryData", "MFnGeometryFilter", "MFnGravityField", "MFnHikEffector", "MFnIkEffector", "MFnIkHandle", "MFnIkJoint", "MFnIkSolver", "MFnIntArrayData", "MFnKeyframeDelta", "MFnKeyframeDeltaAddRemove", "MFnKeyframeDeltaBlockAddRemove", "MFnKeyframeDeltaBreakdown", "MFnKeyframeDeltaInfType", "MFnKeyframeDeltaMove", "MFnKeyframeDeltaScale", "MFnKeyframeDeltaTangent", "MFnKeyframeDeltaWeighted", "MFnLambertShader", "MFnLattice", "MFnLatticeDeformer", "MFnLayeredShader", "MFnLight", "MFnLightDataAttribute", "MFnManip3D", "MFnMatrixAttribute", "MFnMatrixData", "MFnMesh", "MFnMessageAttribute", "MFnMotionPath", "MFnNewtonField", "MFnNonAmbientLight", "MFnNonExtendedLight", "MFnNumericAttribute", "MFnNumericData", "MFnNurbsCurve", "MFnNurbsCurveData", "MFnNurbsSurface", "MFnNurbsSurfaceData", "MFnParticleSystem", "MFnPartition", "MFnPfxGeometry", "MFnPhongEShader", "MFnPhongShader", "MFnPlugin", "MFnPointArrayData", "MFnPointLight", "MFnPointOnCurveManip", "MFnPointOnSurfaceManip", "MFnRadialField", "MFnReflectShader", "MFnRenderLayer", "MFnRotateManip", "MFnScaleManip", "MFnSet", "MFnSingleIndexedComponent", "MFnSkinCluster", "MFnSphereData", "MFnSpotLight", "MFnStateManip", "MFnStringArrayData", "MFnStringData", "MFnSubd", "MFnSubdNames", "MFnToggleManip", "MFnTransform", "MFnTripleIndexedComponent", "MFnTurbulenceField", "MFnTypedAttribute", "MFnUInt64ArrayData", "MFnUniformField", "MFnUnitAttribute", "MFnVectorArrayData", "MFnVolumeAxisField", "MFnVolumeLight", "MFnVortexField", "MFnWeightGeometryFilter", "MFnWireDeformer", # "MGeometryData", "MGlobal", "MHardwareRenderer", "MIkHandleGroup", "MIkSystem", "MImage", "MIntArray", "MItCurveCV", "MItDag", "MItDependencyGraph", "MItDependencyNodes", "MItGeometry", "MItInstancer", "MItMeshEdge", "MItMeshFaceVertex", "MItMeshPolygon", "MItMeshVertex", "MItSelectionList", "MItSubdEdge", "MItSubdFace", "MItSubdVertex", "MItSurfaceCV", "MIteratorType", "MLibrary", "MLightLinks", "MManipData", "MMaterial", "MMatrix", "MObject", "MObjectArray", "MObjectHandle", "MPlug", "MPlugArray", "MPoint", "MPointArray", "MProgressWindow", "MPxCommand", # "MPxComponentShape", "MPxContext", "MPxData", "MPxDeformerNode", # "MPxDragAndDropBehavior", "MPxEmitterNode", "MPxFieldNode", "MPxFileTranslator", # "MPxFluidEmitterNode", "MPxLocatorNode", "MPxNode", "MPxObjectSet", "MPxSpringNode", # "MPxSurfaceShape", # "MPxToolCommand", "MQuaternion", "MRampAttribute", "MRenderData", "MRenderLine", "MRenderLineArray", "MRenderShadowData", "MRenderUtil", "MRenderView", "MSelectInfo", "MSelectionList", "MSelectionMask", "MSpace", "MStatus", "MString", "MStringArray", "MSwatchRenderBase", "MSyntax", "MTesselationParams", "MTime", "MTimeArray", "MTimer", "MToolsInfo", "MTransformationMatrix", "MTrimBoundaryArray", "MTypeId", "MUintArray", "MUint64Array", "MVector", "MVectorArray", ] #classes = filter(lambda x: x in ["MFnTransform"], classes) #classes = filter(lambda x: x in ["MGlobal", "MObject", "MStatus", # "MVector", "MTransformationMatrix", # "MString", "MStringArray", # "MFnPlugin", "MFn", "MTypeId", # "MPxFileTranslator", "MFileObject"], classes) # Usually, a class MClass is defined in a header MClass.h. # If this is not the case, there must be an entry in the following # dictionary. Key is the class name and value the header where this class # is defined. other_header = { "MSpace" : "MTypes.h" } policies = { # "::M3dView::display" : return_internal_reference(), # "::M3dView::glxContext" : return_internal_reference(), "::MAnimCurveClipboard::theAPIClipboard" : return_internal_reference(), "::MClothConstraint::getParticle" : return_internal_reference(), # "::MDataHandle::asBool" : return_internal_reference(), # "::MDataHandle::asChar" : return_internal_reference(), # "::MDataHandle::asDouble" : return_internal_reference(), # "::MDataHandle::asDouble2" : return_internal_reference(), # "::MDataHandle::asDouble3" : return_internal_reference(), # "::MDataHandle::asFloat" : return_internal_reference(), # "::MDataHandle::asFloat2" : return_internal_reference(), # "::MDataHandle::asFloat3" : return_internal_reference(), "::MDataHandle::asFloatMatrix" : return_internal_reference(), "::MDataHandle::asFloatVector" : return_internal_reference(), # "::MDataHandle::asInt" : return_internal_reference(), # "::MDataHandle::asInt2" : return_internal_reference(), # "::MDataHandle::asInt3" : return_internal_reference(), # "::MDataHandle::asLong" : return_internal_reference(), # "::MDataHandle::asLong2" : return_internal_reference(), # "::MDataHandle::asLong3" : return_internal_reference(), "::MDataHandle::asMatrix" : return_internal_reference(), "::MDataHandle::asPluginData" : return_internal_reference(), # "::MDataHandle::asShort" : return_internal_reference(), # "::MDataHandle::asShort2" : return_internal_reference(), # "::MDataHandle::asShort3" : return_internal_reference(), # "::MDataHandle::asString" : return_internal_reference(), # "::MDataHandle::asUChar" : return_internal_reference(), "::MDataHandle::asVector" : return_internal_reference(), "::MEulerRotation::boundIt" : return_self(), "::MEulerRotation::incrementalRotateBy" : return_self(), "::MEulerRotation::invertIt" : return_self(), "::MEulerRotation::reorderIt" : return_self(), "::MEulerRotation::setToAlternateSolution" : return_self(), "::MEulerRotation::setToClosestCut" : return_self(), "::MEulerRotation::setToClosestSolution" : return_self(), "::MEulerRotation::setValue" : return_self(), "::MFloatMatrix::setToIdentity" : return_self(), "::MFloatMatrix::setToProduct" : return_self(), "::MFloatPoint::cartesianize" : return_self(), "::MFloatPoint::homogenize" : return_self(), "::MFloatPoint::rationalize" : return_self(), "::MFloatVectorArray::operator[]" : return_internal_reference(), "::MFnDependencyNode::userNode" : return_internal_reference(), "::MFnLattice::point" : return_internal_reference(), "::MFnPointArrayData::operator[]" : return_internal_reference(), "::MHardwareRenderer::findDrawProcedure" : return_internal_reference(), "::MHardwareRenderer::referenceDefaultGeometry" : return_internal_reference(), "::MHardwareRenderer::theRenderer" : return_internal_reference(), "::MMaterial::getHwShaderNode" : return_internal_reference(), "::MMatrix::setToIdentity" : return_self(), "::MMatrix::setToProduct" : return_self(), "::MPoint::cartesianize" : return_self(), "::MPoint::homogenize" : return_self(), "::MPoint::rationalize" : return_self(), "::MQuaternion::conjugateIt" : return_self(), "::MQuaternion::invertIt" : return_self(), "::MQuaternion::negateIt" : return_self(), "::MQuaternion::normalizeIt" : return_self(), "::MQuaternion::scaleIt" : return_self(), "::MQuaternion::setAxisAngle" : return_self(), "::MQuaternion::setToXAxis" : return_self(), "::MQuaternion::setToYAxis" : return_self(), "::MQuaternion::setToZAxis" : return_self(), "::MString::toLowerCase" : return_self(), "::MString::toUpperCase" : return_self(), "::MSwatchRenderBase::image" : return_internal_reference(), "::MTransformationMatrix::rotateBy" : return_self(), "::MTransformationMatrix::rotateTo" : return_self(), "::MTransformationMatrix::setRotationOrientation" : return_self(), # "::MVectorArray::operator[]" : return_internal_reference(), } # Create a list with all required header files, i.e. the files # that will be parsed... files = [] headerproxy = file("maya_sdk.h", "wt") for cls in classes: if cls in other_header: headername = other_header[cls] else: headername = cls+".h" headerfile = os.path.join(mayaincpath, "maya", headername) files.append(headerfile) print >>headerproxy, "#include <%s>"%os.path.join("maya", headername) headerfile = "src_aux/_main.h" files.append(headerfile) print >>headerproxy, "#include <%s>"%headerfile headerproxy.close() print len(classes),"classes" # Helper functions: def createClassWrappers(declaration): for member in declaration.iterContained(): decl = member.decl_handles[0] if not hasattr(decl, "arguments"): continue stats = filter(lambda a: str(a.type)=="MStatus *", decl.arguments) if len(stats)>0: print createStatus2ExceptionWrapper(member) def createStatus2ExceptionWrapper(declaration): """Return source code for wrapping functions with a MStatus object as input. declaration contains the member function declaration (IDecl). """ assert declaration.count==1 decl = declaration.decl_handles[0] # Return type of the function rtype = decl.return_type # Obtain the name of the variable that is of type MStatus* statusvar = filter(lambda a: str(a.type)=="MStatus *", decl.arguments)[0].name args = map(lambda a: str(a), decl.arguments) if not decl.has_static: args = ["%s& self"%decl.parent.name]+args res = "// Wrapper for %s.%s\n"%(decl.parent.name, decl.name) res += "%s wrap_%s(%s)\n"%(rtype, decl.name, ", ".join(args)) res += "{\n" res += " MStatus internalstat;\n" res += " MStatus* finalstat = &internalstat;\n" res += " if (%s!=0)\n"%statusvar res += " finalstat = %s;\n"%statusvar params = [] for arg in decl.arguments: if arg.name==statusvar: params.append("finalstat") else: params.append(arg.name) call = decl.name if decl.has_static: call = "%s::%s"%(decl.parent.name, call) else: call = "self.%s"%call res += " %s res = %s(%s);\n"%(rtype, call, ", ".join(params)) res += " if (finalstat->error())\n" res += " throw EMayaException(*finalstat);\n" res += " return res;\n" res += "}\n\n" return res ### # ConvertMStatusRetVal class ConvertMStatusRetVal(ArgTransformerBase): def __init__(self): ArgTransformerBase.__init__(self) def prepareWrapper(self, wm): wm.removeResult(wm.callargs[0]) pt = declarations.pointer_t(None) pt._create_decl_string = lambda: "MStatus *" wm.insertArg(-1, declarations.argument_t("status", pt, "0")) def postCall(self, wm): return "if (status!=0)\n (*status)=%s;"%wm.callargs[0] # MStatusToException class MStatusToException(ArgTransformerBase): def __init__(self): ArgTransformerBase.__init__(self) def prepareWrapper(self, wm): # Determine the name of the MStatus variable (-> self.statusvar)... self.statusvar = None for idx, arg in enumerate(wm.funcargs[1:]): if str(arg.type)=="MStatus *": self.statusvar = arg.name idx += 1 break else: if wm.funcargs[0]==None or str(wm.funcargs[0].type)!="MStatus": raise ValueError, "No MStatus object found in the signature of the function:\n%s"%wm.decl if self.statusvar!=None: # Declare additional variables... self.internalstat = wm.declareLocal("internalstat", "MStatus") self.finalstat = wm.declareLocal("finalstat", "MStatus*", default="&%s"%self.internalstat) wm.replaceCallArg(idx, self.finalstat) # preCall def preCall(self, wm): if self.statusvar!=None: res = "if (%s!=0)\n"%self.statusvar res += " %s = %s;"%(self.finalstat, self.statusvar) return res else: return None # postCall def postCall(self, wm): res = "" # res += "*%s = %s;\n"%(self.finalstat, wm.callargs[0]) if self.statusvar==None: res += "if (%s.error())\n"%wm.callargs[0] else: res += "if (%s->error())\n"%self.finalstat res += " throw EException();" return res ### # Create the file src_aux/creatorfuncs.cpp.h... filename = "src_aux/creatorfuncs.cpp.h" print 'Creating "%s"...'%filename mpxclasses = [] for cls in classes: if cls[:3]=="MPx": mpxclasses.append(cls) f = file(filename, "wt") createplugincode.createSourceFile(mpxclasses, MAX_CREATOR_FUNCTIONS, MAX_CREATESYNTAX_FUNCTIONS, MAX_INIT_FUNCTIONS, f) f.close() ###################################################################### # Configuration ###################################################################### mod = ModuleBuilder( ["maya_sdk.h"], # files, includePaths = [mayaincpath], defines = ["_BOOL", "LINUX", "MNoVersionString", "REQUIRE_IOSTREAM"], # cacheFile = "maya.cache", cacheDir = "cache", moduleName = "_api", output = "_api", multiFile = True, queryLog = "query.log", decorationLog = "decoration.log" ) mod.addInclude("extraheaders.h") ###################################################################### # Parsing the headers ###################################################################### root = mod.parse() # Expose all SDK classes... print "Exposing SDK classes..." mod.Classes(classes, assert_count=len(classes)).expose() ###TEST #MGlobal = mod.Class("MItDag") #createClassWrappers(MGlobal) #sys.exit() ### # Wrap the copy constructor manually (as pyplusplus doesn't support copy # constructors yet). # The following loop checks all classes whether they have a copy constructor # or not and adds an appropriate definition. print "Exposing copy constructors..." declwrapper.allow_empty_queries = True for clsname in classes: cls = mod.Class(clsname) cc = cls.Constructor(args=["%s const &"%clsname]) if cc.count>0: decl = cc.decl_handles[0] if (not decl.is_artificial) and decl.access_type==PUBLIC: cls.cdef("bp::init< const %s& >()"%clsname) declwrapper.allow_empty_queries = False # Allow empty queries... declwrapper.allow_empty_queries = True declwrapper.default_recursive = True # Ignore all protected methods mod.Methods(accesstype=PROTECTED).ignore() # Assign special policies print "Assigning policies..." for method in policies: policy = policies[method] mod.Method(fullname=method, recursive=True).setPolicy(policy) # Special cases... print "Individual customizations..." mod.Function("toMObject").expose() # String wrappers MString = mod.Class("MString") #MString.rename("_MString") MString.cdef("__str__", "pyMString::__str__") mod.addStartText(""" // Convert MStrings to Python strings struct MString_to_python_str { static PyObject* convert(MString const& s) { return boost::python::incref(boost::python::object(s.asChar()).ptr()); } }; // Convert Python strings to MStrings struct MString_from_python_str { MString_from_python_str() { boost::python::converter::registry::push_back( &convertible, &construct, boost::python::type_id<MString>()); } static void* convertible(PyObject* obj_ptr) { if (!PyString_Check(obj_ptr)) return 0; return obj_ptr; } static void construct( PyObject* obj_ptr, boost::python::converter::rvalue_from_python_stage1_data* data) { const char* value = PyString_AsString(obj_ptr); if (value==0) boost::python::throw_error_already_set(); void* storage = ( (boost::python::converter::rvalue_from_python_storage<MString>*) data)->storage.bytes; new (storage) MString(value); data->convertible = storage; } }; // Convert Python sequences to MPoints struct MPoint_from_sequence { MPoint_from_sequence() { boost::python::converter::registry::push_back( &convertible, &construct, boost::python::type_id<MPoint>()); } static void* convertible(PyObject* obj_ptr) { if (!PySequence_Check(obj_ptr)) return 0; int size = PySequence_Size(obj_ptr); if (size<2 || size>4) return 0; return obj_ptr; } static void construct( PyObject* obj_ptr, boost::python::converter::rvalue_from_python_stage1_data* data) { double values[4] = {0.0, 0.0, 0.0, 1.0}; for(int i=0; i<PySequence_Size(obj_ptr); i++) { PyObject* item = PySequence_ITEM(obj_ptr, i); if (item==0) boost::python::throw_error_already_set(); values[i] = PyFloat_AsDouble(item); Py_DECREF(item); if (PyErr_Occurred()!=0) { boost::python::throw_error_already_set(); } } void* storage = ( (boost::python::converter::rvalue_from_python_storage<MPoint>*) data)->storage.bytes; new (storage) MPoint(values); data->convertible = storage; } }; // Convert Python sequences to MVectors struct MVector_from_sequence { MVector_from_sequence() { boost::python::converter::registry::push_back( &convertible, &construct, boost::python::type_id<MVector>()); } static void* convertible(PyObject* obj_ptr) { if (!PySequence_Check(obj_ptr)) return 0; int size = PySequence_Size(obj_ptr); if (size<2 || size>3) return 0; return obj_ptr; } static void construct( PyObject* obj_ptr, boost::python::converter::rvalue_from_python_stage1_data* data) { double values[3] = {0.0, 0.0, 0.0}; for(int i=0; i<PySequence_Size(obj_ptr); i++) { PyObject* item = PySequence_ITEM(obj_ptr, i); if (item==0) boost::python::throw_error_already_set(); values[i] = PyFloat_AsDouble(item); Py_DECREF(item); if (PyErr_Occurred()!=0) { boost::python::throw_error_already_set(); } } void* storage = ( (boost::python::converter::rvalue_from_python_storage<MVector>*) data)->storage.bytes; new (storage) MVector(values); data->convertible = storage; } }; """) mod.addBodyTailText(""" boost::python::to_python_converter<MString, MString_to_python_str>(); MString_from_python_str(); MPoint_from_sequence(); """) # Ignore all [] operators that return a reference or a pointer... mod.Methods("operator[]", retval="/.*&/").exclude() mod.Methods("operator[]", retval="/.*\*/").exclude() # Ignore all call and index operators that return a reference to float or double mod.Methods("operator()", retval=["float &", "double &"]).exclude() mod.Methods("operator[]", retval=["float &", "double &"]).exclude() # Ignore some constructors from MPointArray, MVectorArray, ... mod.Methods(args=["double[4] const *", "unsigned int"]).ignore() mod.Methods(args=["float[4] const *", "unsigned int"]).ignore() mod.Methods(args=["double[3] const *", "unsigned int"]).ignore() mod.Methods(args=["float[3] const *", "unsigned int"]).ignore() # Ignore all get() methods mod.Methods("get").ignore() # MColorArray methods... mod.Methods("set", args=["double[4] *", "unsigned int"]).ignore() mod.Methods("set", args=["float[4] *", "unsigned int"]).ignore() # Handle MMatrix and MFloatMatrix together... MMatrices = mod.Classes(["MMatrix", "MFloatMatrix"]) #MMatrices.finalize() MMatrices.Methods(args=["double[4] const *"]).ignore() MMatrices.Methods(args=["float[4] const *"]).ignore() MMatrices.Methods("get").ignore() MMatrices.Decls(name="matrix").ignore() M3dView = mod.Class("M3dView") M3dView.Method("applicationShell").ignore() M3dView.Method("display").ignore() M3dView.Method("glxContext").ignore() M3dView.Method("deviceContext", allow_empty=True).ignore() M3dView.Method("window").ignore() MPointArray = mod.Class("MPointArray") MPointArray.Method("set", args=["double *", "unsigned int"]).ignore() MPointArray.Method("set", args=["float *", "unsigned int"]).ignore() MPointArray.Method("operator[]", retval="MPoint &").expose() MPointArray.cdef("__str__", "pyMPointArray::__str__") MPointArray.cdef("__setitem__", "pyMPointArray::__setitem__") MPointArray.cdef("get", "pyMPointArray::get1") MPointArray.cdef("get", "pyMPointArray::get2") MVectorArray = mod.Class("MVectorArray") MVectorArray.Method("set", args=["double *", "unsigned int"]).ignore() MVectorArray.Method("set", args=["float *", "unsigned int"]).ignore() MVectorArray.Method("operator[]", retval="MVector &").expose() MVectorArray.cdef("__str__", "pyMVectorArray::__str__") MVectorArray.cdef("__setitem__", "pyMVectorArray::__setitem__") MVectorArray.cdef("get", "pyMVectorArray::get1") MVectorArray.cdef("get", "pyMVectorArray::get2") MImage = mod.Class("MImage") MImage.Method("pixels").ignore() MSelectionList = mod.Class("MSelectionList") MSelectionList.cdef("__str__", "pyMSelectionList::__str__") MSelectionMask = mod.Class("MSelectionMask") MSelectionMask.Methods("operator|").ignore() MPlug = mod.Class("MPlug") MPlug.cdef("__str__", "pyMPlug::__str__") MDataHandle = mod.Class("MDataHandle") MDataHandle.Method("asBool").ignore() MDataHandle.Method("asChar").ignore() MDataHandle.Method("asUChar").ignore() MDataHandle.Methods("/asShort.*/").ignore() MDataHandle.Methods("/asLong.*/").ignore() MDataHandle.Methods("/asInt.*/").ignore() MDataHandle.Methods("/asFloat[2-3]*/").ignore() MDataHandle.Methods("/asDouble[2-3]*/").ignore() MDataHandle.Method("asString").ignore() MDataHandle.cdef("asBool", "pyMDataHandle::asBool") MDataHandle.cdef("asChar", "pyMDataHandle::asChar") MDataHandle.cdef("asUChar", "pyMDataHandle::asUChar") MDataHandle.cdef("asShort", "pyMDataHandle::asShort") MDataHandle.cdef("asLong", "pyMDataHandle::asLong") MDataHandle.cdef("asInt", "pyMDataHandle::asInt") MDataHandle.cdef("asFloat", "pyMDataHandle::asFloat") MDataHandle.cdef("asDouble", "pyMDataHandle::asDouble") MDataHandle.cdef("asShort2", "pyMDataHandle::asShort2") MDataHandle.cdef("asLong2", "pyMDataHandle::asLong2") MDataHandle.cdef("asInt2", "pyMDataHandle::asInt2") MDataHandle.cdef("asFloat2", "pyMDataHandle::asFloat2") MDataHandle.cdef("asDouble2", "pyMDataHandle::asDouble2") MDataHandle.cdef("asShort3", "pyMDataHandle::asShort3") MDataHandle.cdef("asLong3", "pyMDataHandle::asLong3") MDataHandle.cdef("asInt3", "pyMDataHandle::asInt3") MDataHandle.cdef("asFloat3", "pyMDataHandle::asFloat3") MDataHandle.cdef("asDouble3", "pyMDataHandle::asDouble3") MDataHandle.cdef("asString", "pyMDataHandle::asString") # Disable keyword args on all constructors... mod.Classes("/M.*/").Constructors().disableKeywordArgs() # Remove the _padding attribute in the EulerRotation class mod.Class("MEulerRotation").Decl("_padding").ignore() # operator() doesn't compile on Windows for MColor and MVector...? mod.Class("MColor").Methods("operator()").ignore() mod.Class("MVector").Methods("operator()").ignore() MGlobal = mod.Class("MGlobal") MGlobal.cdef("executeCommandPy", "pyMGlobal::executeCommandPy", (arg("command"), arg("displayEnabled",False), arg("undoEnabled", False))) MGlobal.staticmethod("executeCommandPy") MStatus = mod.Class("MStatus") MStatus.cdef("__str__", "pyMStatus::__str__") MStatus.cdef("__nonzero__", "&MStatus::operator bool") MVector = mod.Class("MVector") #MVector.cdef("bp::init< const MVector& >()") MVector.cdef("__str__", "pyMVector::__str__") # Replace one version of rotateBy() by a "Pythonized" version that serves # the same purpose MVector.Method("rotateBy", args=["double const *", "MTransformationMatrix::RotationOrder"]).ignore() MVector.cdef("rotateBy", "pyMVector::rotateBy", (arg("rotXYZ"), arg("order"))); MPoint = mod.Class("MPoint") MPoint.cdef("__str__", "pyMPoint::__str__") MFloatVector = mod.Class("MFloatVector") MFloatVector.cdef("__str__", "pyMFloatVector::__str__") MFloatPoint = mod.Class("MFloatPoint") MFloatPoint.cdef("__str__", "pyMFloatPoint::__str__") MObject = mod.Class("MObject") MObject.cdef("__str__", "pyMObject::__str__") MFileObject = mod.Class("MFileObject") MFileObject.cdef("__str__", "&MFileObject::fullName") MDagPath = mod.Class("MDagPath") #MDagPath.cdef("bp::init< const MDagPath& >()") MDagPath.cdef("__str__", "&MDagPath::fullPathName", arg("ReturnStatus", cpp("bp::object()"))) MItSelectionList = mod.Class("MItSelectionList") MItSelectionList.cdef("__str__", "pyMItSelectionList::__str__") MFnNurbsCurve = mod.Class("MFnNurbsCurve") MFnNurbsCurve.Method("getKnotDomain").setArgPolicy(Output(1), Output(2), ConvertMStatusRetVal()) MFnNurbsCurve.Method("getParamAtPoint").setArgPolicy(Output(2), ConvertMStatusRetVal()) MFnNurbsCurve.Method("closestPoint").setArgPolicy(Output(2)) MFnTransform = mod.Class("MFnTransform") MFnTransform.Method("getScale").setArgPolicy(OutputArray(1,3), ConvertMStatusRetVal()) MFnTransform.Method("setScale").setArgPolicy(InputArray(1,3)) MFnTransform.Method("scaleBy").setArgPolicy(InputArray(1,3)) MFnTransform.Method("getShear").setArgPolicy(OutputArray(1,3), ConvertMStatusRetVal()) MFnTransform.Method("setShear").setArgPolicy(InputArray(1,3)) MFnTransform.Method("shearBy").setArgPolicy(InputArray(1,3)) MFnTransform.Method("getRotationQuaternion").setArgPolicy(Output(1), Output(2), Output(3), Output(4), ConvertMStatusRetVal()) MFnTransform.Method("getRotation", args=["double *", "MTransformationMatrix::RotationOrder &"]).setArgPolicy(OutputArray(1,3), Output(2), ConvertMStatusRetVal()) MFnTransform.Method("setRotation", args=["double const *", "MTransformationMatrix::RotationOrder"]).setArgPolicy(InputArray(1,3)) MFnTransform.Method("rotateBy", args=["double const *", "MTransformationMatrix::RotationOrder", "MSpace::Space"]).setArgPolicy(InputArray(1,3)) MFnTransform.Method("getRotation", args=["double *", "MTransformationMatrix::RotationOrder &", "MSpace::Space"]).ignore() # obsolete MFnTransform.Method("setRotation", args=["double const *", "MTransformationMatrix::RotationOrder", "MSpace::Space"]).ignore() # obsolete MFnPlugin = mod.Class("MFnPlugin") #MFnPlugin.finalize() MFnPlugin.Methods("/register.*/").ignore() MFnPlugin.cdef("_releaseCreatorFunc", "pyMFnPlugin::_releaseCreatorFunc") MFnPlugin.cdef("_releaseCreateSyntaxFunc", "pyMFnPlugin::_releaseCreateSyntaxFunc") MFnPlugin.cdef("_releaseInitFunc", "pyMFnPlugin::_releaseInitFunc") MFnPlugin.cdef("registerCommand", "pyMFnPlugin::registerCommand") MFnPlugin.cdef("registerFileTranslator", "pyMFnPlugin::registerFileTranslator") MFnPlugin.cdef("registerNode", "pyMFnPlugin::registerNode") MPxDeformerNode = mod.Class("MPxDeformerNode") MPxDeformerNode.Method("accessoryAttribute").ignore() ###################################################################### # Writing the source files ###################################################################### mod.writeModule() --- NEW FILE: maya_sdk.h --- #include <maya/M3dView.h> #include <maya/MAngle.h> #include <maya/MAnimControl.h> #include <maya/MAnimCurveChange.h> #include <maya/MAnimCurveClipboard.h> #include <maya/MAnimCurveClipboardItem.h> #include <maya/MAnimCurveClipboardItemArray.h> #include <maya/MAnimUtil.h> #include <maya/MArgDatabase.h> #include <maya/MArgList.h> #include <maya/MArgParser.h> #include <maya/MArrayDataBuilder.h> #include <maya/MArrayDataHandle.h> #include <maya/MAttributeIndex.h> #include <maya/MAttributeSpec.h> #include <maya/MAttributeSpecArray.h> #include <maya/MBoundingBox.h> #include <maya/MClothConstraint.h> #include <maya/MColor.h> #include <maya/MColorArray.h> #include <maya/MCommandResult.h> #include <maya/MComputation.h> #include <maya/MDGContext.h> #include <maya/MDGModifier.h> #include <maya/MDagModifier.h> #include <maya/MDagPath.h> #include <maya/MDagPathArray.h> #include <maya/MDataBlock.h> #include <maya/MDataHandle.h> #include <maya/MDeviceChannel.h> #include <maya/MDeviceState.h> #include <maya/MDistance.h> #include <maya/MDoubleArray.h> #include <maya/MDrawInfo.h> #include <maya/MDrawProcedureBase.h> #include <maya/MDrawRequest.h> #include <maya/MDrawRequestQueue.h> #include <maya/MDynSweptLine.h> #include <maya/MDynSweptTriangle.h> #include <maya/MEulerRotation.h> #include <maya/MEvent.h> #include <maya/MFeedbackLine.h> #include <maya/MFileIO.h> #include <maya/MFileObject.h> #include <maya/MFloatArray.h> #include <maya/MFloatMatrix.h> #include <maya/MFloatPoint.h> #include <maya/MFloatPointArray.h> #include <maya/MFloatVector.h> #include <maya/MFloatVectorArray.h> #include <maya/MFn.h> #include <maya/MFnAirField.h> #include <maya/MFnAmbientLight.h> #include <maya/MFnAnimCurve.h> #include <maya/MFnAnisotropyShader.h> #include <maya/MFnAreaLight.h> #include <maya/MFnArrayAttrsData.h> #include <maya/MFnAttribute.h> #include <maya/MFnBase.h> #include <maya/MFnBlendShapeDeformer.h> #include <maya/MFnBlinnShader.h> #include <maya/MFnCamera.h> #include <maya/MFnCharacter.h> #include <maya/MFnCircleSweepManip.h> #include <maya/MFnClip.h> #include <maya/MFnComponent.h> #include <maya/MFnComponentListData.h> #include <maya/MFnCompoundAttribute.h> #include <maya/MFnCurveSegmentManip.h> #include <maya/MFnDagNode.h> #include <maya/MFnData.h> #include <maya/MFnDependencyNode.h> #include <maya/MFnDirectionManip.h> #include <maya/MFnDirectionalLight.h> #include <maya/MFnDiscManip.h> #include <maya/MFnDistanceManip.h> #include <maya/MFnDoubleIndexedComponent.h> #include <maya/MFnDragField.h> #include <maya/MFnDynSweptGeometryData.h> #include <maya/MFnEnumAttribute.h> #include <maya/MFnExpression.h> #include <maya/MFnField.h> #include <maya/MFnFreePointTriadManip.h> #include <maya/MFnGenericAttribute.h> #include <maya/MFnGeometryData.h> #include <maya/MFnGeometryFilter.h> #include <maya/MFnGravityField.h> #include <maya/MFnHikEffector.h> #include <maya/MFnIkEffector.h> #include <maya/MFnIkHandle.h> #include <maya/MFnIkJoint.h> #include <maya/MFnIkSolver.h> #include <maya/MFnIntArrayData.h> #include <maya/MFnKeyframeDelta.h> #include <maya/MFnKeyframeDeltaAddRemove.h> #include <maya/MFnKeyframeDeltaBlockAddRemove.h> #include <maya/MFnKeyframeDeltaBreakdown.h> #include <maya/MFnKeyframeDeltaInfType.h> #include <maya/MFnKeyframeDeltaMove.h> #include <maya/MFnKeyframeDeltaScale.h> #include <maya/MFnKeyframeDeltaTangent.h> #include <maya/MFnKeyframeDeltaWeighted.h> #include <maya/MFnLambertShader.h> #include <maya/MFnLattice.h> #include <maya/MFnLatticeDeformer.h> #include <maya/MFnLayeredShader.h> #include <maya/MFnLight.h> #include <maya/MFnLightDataAttribute.h> #include <maya/MFnManip3D.h> #include <maya/MFnMatrixAttribute.h> #include <maya/MFnMatrixData.h> #include <maya/MFnMesh.h> #include <maya/MFnMessageAttribute.h> #include <maya/MFnMotionPath.h> #include <maya/MFnNewtonField.h> #include <maya/MFnNonAmbientLight.h> #include <maya/MFnNonExtendedLight.h> #include <maya/MFnNumericAttribute.h> #include <maya/MFnNumericData.h> #include <maya/MFnNurbsCurve.h> #include <maya/MFnNurbsCurveData.h> #include <maya/MFnNurbsSurface.h> #include <maya/MFnNurbsSurfaceData.h> #include <maya/MFnParticleSystem.h> #include <maya/MFnPartition.h> #include <maya/MFnPfxGeometry.h> #include <maya/MFnPhongEShader.h> #include <maya/MFnPhongShader.h> #include <maya/MFnPlugin.h> #include <maya/MFnPointArrayData.h> #include <maya/MFnPointLight.h> #include <maya/MFnPointOnCurveManip.h> #include <maya/MFnPointOnSurfaceManip.h> #include <maya/MFnRadialField.h> #include <maya/MFnReflectShader.h> #include <maya/MFnRenderLayer.h> #include <maya/MFnRotateManip.h> #include <maya/MFnScaleManip.h> #include <maya/MFnSet.h> #include <maya/MFnSingleIndexedComponent.h> #include <maya/MFnSkinCluster.h> #include <maya/MFnSphereData.h> #include <maya/MFnSpotLight.h> #include <maya/MFnStateManip.h> #include <maya/MFnStringArrayData.h> #include <maya/MFnStringData.h> #include <maya/MFnSubd.h> #include <maya/MFnSubdNames.h> #include <maya/MFnToggleManip.h> #include <maya/MFnTransform.h> #include <maya/MFnTripleIndexedComponent.h> #include <maya/MFnTurbulenceField.h> #include <maya/MFnTypedAttribute.h> #include <maya/MFnUInt64ArrayData.h> #include <maya/MFnUniformField.h> #include <maya/MFnUnitAttribute.h> #include <maya/MFnVectorArrayData.h> #include <maya/MFnVolumeAxisField.h> #include <maya/MFnVolumeLight.h> #include <maya/MFnVortexField.h> #include <maya/MFnWeightGeometryFilter.h> #include <maya/MFnWireDeformer.h> #include <maya/MGlobal.h> #include <maya/MHardwareRenderer.h> #include <maya/MIkHandleGroup.h> #include <maya/MIkSystem.h> #include <maya/MImage.h> #include <maya/MIntArray.h> #include <maya/MItCurveCV.h> #include <maya/MItDag.h> #include <maya/MItDependencyGraph.h> #include <maya/MItDependencyNodes.h> #include <maya/MItGeometry.h> #include <maya/MItInstancer.h> #include <maya/MItMeshEdge.h> #include <maya/MItMeshFaceVertex.h> #include <maya/MItMeshPolygon.h> #include <maya/MItMeshVertex.h> #include <maya/MItSelectionList.h> #include <maya/MItSubdEdge.h> #include <maya/MItSubdFace.h> #include <maya/MItSubdVertex.h> #include <maya/MItSurfaceCV.h> #include <maya/MIteratorType.h> #include <maya/MLibrary.h> #include <maya/MLightLinks.h> #include <maya/MManipData.h> #include <maya/MMaterial.h> #include <maya/MMatrix.h> #include <maya/MObject.h> #include <maya/MObjectArray.h> #include <maya/MObjectHandle.h> #include <maya/MPlug.h> #include <maya/MPlugArray.h> #include <maya/MPoint.h> #include <maya/MPointArray.h> #include <maya/MProgressWindow.h> #include <maya/MPxCommand.h> #include <maya/MPxContext.h> #include <maya/MPxData.h> #include <maya/MPxDeformerNode.h> #include <maya/MPxEmitterNode.h> #include <maya/MPxFieldNode.h> #include <maya/MPxFileTranslator.h> #include <maya/MPxLocatorNode.h> #include <maya/MPxNode.h> #include <maya/MPxObjectSet.h> #include <maya/MPxSpringNode.h> #include <maya/MQuaternion.h> #include <maya/MRampAttribute.h> #include <maya/MRenderData.h> #include <maya/MRenderLine.h> #include <maya/MRenderLineArray.h> #include <maya/MRenderShadowData.h> #include <maya/MRenderUtil.h> #include <maya/MRenderView.h> #include <maya/MSelectInfo.h> #include <maya/MSelectionList.h> #include <maya/MSelectionMask.h> #include <maya/MTypes.h> #include <maya/MStatus.h> #include <maya/MString.h> #include <maya/MStringArray.h> #include <maya/MSwatchRenderBase.h> #include <maya/MSyntax.h> #include <maya/MTesselationParams.h> #include <maya/MTime.h> #include <maya/MTimeArray.h> #include <maya/MTimer.h> #include <maya/MToolsInfo.h> #include <maya/MTransformationMatrix.h> #include <maya/MTrimBoundaryArray.h> #include <maya/MTypeId.h> #include <maya/MUintArray.h> #include <maya/MUint64Array.h> #include <maya/MVector.h> #include <maya/MVectorArray.h> #include <src_aux/_main.h> |