コード例 #1
0
 def __init__(self):
   super(LidarLocator, self).__init__()
   self.__fileNameValue = ""
   self.__scene = Scene(None, exts = {'FabricLIDAR': ''}, guarded = True)
   self.__viewport = EmulatedViewport(self.__scene)
   self.__parser = None
コード例 #2
0
class LidarLocator(OpenMayaMPx.MPxLocatorNode):
  
  __fileName = OpenMaya.MObject()
  __fileNameValue = None
  __scene = None
  __viewport = None
  __parser = None
  __instance = None
  
  def __init__(self):
    super(LidarLocator, self).__init__()
    self.__fileNameValue = ""
    self.__scene = Scene(None, exts = {'FabricLIDAR': ''}, guarded = True)
    self.__viewport = EmulatedViewport(self.__scene)
    self.__parser = None
    
  def __del__(self):
    self.__parser = None
    self.__viewport = None
    self.__scene.close()
    self.__scene = None
    
  def draw(self, view, path, style, status):
    fileNameValue = OpenMaya.MPlug(self.thisMObject(), LidarLocator.__fileName).asString()
    if not fileNameValue == self.__fileNameValue:
      self.__fileNameValue = fileNameValue
      
      # todo: proper file checking
      if self.__parser is None:
        self.__parser = LidarParser(self.__scene, url = self.__fileNameValue)
        
        # setup the shader group
        group = ShaderGroup(self.__scene)
        self.__viewport.addShaderGroupNode(group)
        
        # compute the bbox of the points
        points = self.__parser.getPointsNode()
        bbox = points.getBoundingBox()
        center = bbox['min'].add(bbox['max']).multiplyScalar(0.5).negate()
        scale = Vec3(1.0, 1.0, 1.0).multiplyScalar(0.01)
        center = center.multiply(scale)
        
        # create the material
        material = Material(self.__scene, xmlFile='Standard/FlatVertexColor', shaderGroup=group)
        self.__instance = Instance(self.__scene,
          transform = Transform(self.__scene, globalXfo = Xfo(tr = center, sc = scale)),
          geometry = points,
          material = material
        )

      else:
        self.__parser.setUrl(self.__fileNameValue)
      
    # retrieve both the inv camera matrix as well as projection matrix
    cameraDag = OpenMaya.MDagPath()
    view.getCamera(cameraDag)
    invCameraMat = cameraDag.inclusiveMatrix().inverse()
    projectionMat = OpenMaya.MMatrix()
    view.projectionMatrix(projectionMat)
    self.__viewport.setMatrices(invCameraMat, projectionMat)
    
    # render the fabric creation platform content
    self.__viewport.redraw()
    
  @staticmethod
  def creator():
    return OpenMayaMPx.asMPxPtr( LidarLocator() )
  
  @staticmethod
  def initializer():
    tAttr = OpenMaya.MFnTypedAttribute()
    
    LidarLocator.__fileName = tAttr.create("fileName", "fn", OpenMaya.MFnData.kString)
    tAttr.setStorable(1)
    tAttr.setUsedAsFilename(1)
    LidarLocator.addAttribute(LidarLocator.__fileName)
    
    return OpenMaya.MStatus.kSuccess