Ejemplo n.º 1
0
    def getDrawRequests(self, info, objectAndActiveOnly, queue):
        """
		 The draw data is used to pass geometry through the 
		 draw queue. The data should hold all the information
		 needed to draw the shape.
		"""
        data = OpenMayaUI.MDrawData()
        # printMsg("**before getProtoype\n");
        request = info.getPrototype(self)
        # printMsg("**after getProtoype\n");
        shapeNode = self.surfaceShape()
        geom = shapeNode.geometry()
        self.getDrawData(geom, data)
        request.setDrawData(data)

        # Are we displaying meshes?
        if (not info.objectDisplayStatus(OpenMayaUI.M3dView.kDisplayMeshes)):
            return

        # Use display status to determine what color to draw the object
        if (info.displayStyle() == OpenMayaUI.M3dView.kWireFrame):
            self.getDrawRequestsWireframe(request, info)
            queue.add(request)

        elif (info.displayStyle() == OpenMayaUI.M3dView.kGouraudShaded):
            request.setToken(basicShapeUI.__kDrawSmoothShaded)
            self.getDrawRequestsShaded(request, info, queue, data)
            queue.add(request)

        elif (info.displayStyle() == OpenMayaUI.M3dView.kFlatShaded):
            request.setToken(basicShapeUI.__kDrawFlatShaded)
            self.getDrawRequestsShaded(request, info, queue, data)
            queue.add(request)
        return
Ejemplo n.º 2
0
    def getDrawRequests(self, info, objectAndActiveOnly, queue):
        """
		 The draw data is used to pass geometry through the 
		 draw queue. The data should hold all the information
		 needed to draw the shape.
		"""
        self.geometry = None

        # Custom instancer objects can instance other custom surface
        # shapes.  This is done by first getting the draw request
        # data for the instancer shape
        #
        data = OpenMayaUI.MDrawData()
        request = info.getPrototype(self)
        shapeNode = self.surfaceShape()
        path = info.multiPath()
        view = info.view()
        # We stored the instance object via a connection on the surface
        # shape.  Retrieve that value.
        #
        geom = shapeNode.geometry()
        shadedMode = False
        mainMaterial = None
        if request.displayStyle() == OpenMayaUI.M3dView.kGouraudShaded:
            shadedMode = True

        if geom.instanceShape:
            # Find the MPxSurfaceShape for the object that we are instancing
            #
            shapeUI = OpenMayaMPx.MPxSurfaceShapeUI.surfaceShapeUI(
                geom.instanceShape)
            if shapeUI:
                mainMaterial = shapeUI.material(geom.instanceShape)
                mainMaterial.evaluateMaterial(view, geom.instanceShape)
                r = geom.radius
                for a in range(geom.count):
                    myQueue = OpenMayaUI.MDrawRequestQueue()
                    percent = float(a) / float(geom.count)
                    rad = 2 * math.pi * percent
                    position = (r * math.cos(rad), r * math.sin(rad), 0.0)
                    # Construct a reference to MDrawInfo and modify it
                    # to point to the instance shape.  If we do not do
                    # this in then the call to getDrawRequests will think
                    # that we are still the instancer shape and not the
                    # instance shape.
                    #
                    myinfo = OpenMayaUI.MDrawInfo(info)
                    myinfo.setMultiPath(geom.instanceShape)
                    shapeUI.getDrawRequests(myinfo, objectAndActiveOnly,
                                            myQueue)
                    geom.drawQueueList.append((myQueue, position))

        info.setMultiPath(path)
        # Finally we must supply a material back to the drawing code.
        # We attempt to use the instance shape material; however, if
        # that fails then we fall back to the default material
        #
        if shadedMode:
            defaultMaterial = OpenMayaUI.MMaterial.defaultMaterial()
            if not mainMaterial:
                mainMaterial = defaultMaterial
            try:
                request.setMaterial(mainMaterial)
            except:
                request.setMaterial(defaultMaterial)

        self.getDrawData(geom, data)
        request.setDrawData(data)

        self.geometry = geom
        queue.add(request)