Exemplo n.º 1
0
class pcReader(Node):
    def __init__(self, name, parent):
        Node.__init__(self, name, parent)
        
        self.path = StringAttribute('filename', self)
        self.input = NumericAttribute('frame', self)
        self.output = NumericAttribute('points',self)
        
        self.addInputAttribute(self.input)
        self.addInputAttribute(self.path)
        self.addOutputAttribute(self.output)
        
        self._setAttributeAffect(self.input, self.output)
        self._setAttributeAffect(self.path, self.output)
        
        
        self._setAttributeAllowedSpecializations(self.input, ['Float'])
        self._setAttributeAllowedSpecializations(self.output, ['Vec3Array'])
        
        #self._pcLoader = pcLoader.pcLoader('/Users/sjt/Dev/pc2/cache.pc2')
        
        
    def update(self, attribute):
        path = self.path.value().stringValue()        
        self._pcLoader = pcLoader.pcLoader(path)
        
        value1 = self.input.value().floatValueAt(0)
        points = self._pcLoader.get_frame(value1)

        
        imath_points = []
        for point in points:
            imath_points.append(Imath.Vec3f(point[0],point[1],point[2]))
        
        self.output.outValue().setVec3Values(imath_points)
Exemplo n.º 2
0
class ViewportCameraNode(Node):
    def __init__(self, name, parent):
        Node.__init__(self, name, parent)

        self.setClassName("ViewportCamera")

        self._modelMatrix = NumericAttribute("modelMatrix", self)
        self._fov = NumericAttribute("fov", self)
        self._zNear = NumericAttribute("zNear", self)
        self._zFar = NumericAttribute("zFar", self)

        self.addOutputAttribute(self._modelMatrix)
        self.addOutputAttribute(self._fov)
        self.addOutputAttribute(self._zNear)
        self.addOutputAttribute(self._zFar)

        self._setAttributeAllowedSpecializations(self._modelMatrix,
                                                 ["Matrix44"])
        self._setAttributeAllowedSpecializations(self._fov, ["Float"])
        self._setAttributeAllowedSpecializations(self._zNear, ["Float"])
        self._setAttributeAllowedSpecializations(self._zFar, ["Float"])

        viewport.addCameraNode(self)

        self._extractViewportInfo()

    def __del__(self):
        viewport.removeCameraNode(self)

    def cameraChanged(self):
        # called by viewport.py
        # here we have to dirty each camera related attribute in order to cause an update

        self._extractViewportInfo()

        self._modelMatrix.valueChanged()
        self._fov.valueChanged()
        self._zNear.valueChanged()
        self._zFar.valueChanged()

    def _extractViewportInfo(self):
        viewports = viewport.instancedViewports()
        if viewports:
            vport = viewports[0]

            modelMatrix = vport.modelMatrix()
            self._modelMatrix.outValue().setMatrix44ValueAt(0, modelMatrix)

            fov = vport.fov()
            self._fov.outValue().setFloatValueAt(0, fov)

            zNear = vport.zNear()
            self._zNear.outValue().setFloatValueAt(0, zNear)

            zFar = vport.zFar()
            self._zFar.outValue().setFloatValueAt(0, zFar)
Exemplo n.º 3
0
class ViewportCameraNode(Node):
    def __init__(self, name, parent):
        Node.__init__(self, name, parent)
        
        self.setClassName("ViewportCamera")

        self._modelMatrix = NumericAttribute("modelMatrix", self)
        self._fov = NumericAttribute("fov", self)
        self._zNear = NumericAttribute("zNear", self)
        self._zFar = NumericAttribute("zFar", self)
        
        self.addOutputAttribute(self._modelMatrix)
        self.addOutputAttribute(self._fov)
        self.addOutputAttribute(self._zNear)
        self.addOutputAttribute(self._zFar)
        
        self._setAttributeAllowedSpecializations(self._modelMatrix, ["Matrix44"])
        self._setAttributeAllowedSpecializations(self._fov, ["Float"])
        self._setAttributeAllowedSpecializations(self._zNear, ["Float"])
        self._setAttributeAllowedSpecializations(self._zFar, ["Float"])

        viewport.addCameraNode(self)

        self._extractViewportInfo()
    
    def __del__(self):
        viewport.removeCameraNode(self)
    
    def cameraChanged(self):
        # called by viewport.py
        # here we have to dirty each camera related attribute in order to cause an update

        self._extractViewportInfo()

        self._modelMatrix.valueChanged()
        self._fov.valueChanged()
        self._zNear.valueChanged()
        self._zFar.valueChanged()

    def _extractViewportInfo(self):
        viewports = viewport.instancedViewports()
        if viewports:
            vport = viewports[0]

            modelMatrix = vport.modelMatrix()
            self._modelMatrix.outValue().setMatrix44ValueAt(0, modelMatrix)
            
            fov = vport.fov()
            self._fov.outValue().setFloatValueAt(0, fov)

            zNear = vport.zNear()
            self._zNear.outValue().setFloatValueAt(0, zNear)

            zFar = vport.zFar()
            self._zFar.outValue().setFloatValueAt(0, zFar)
Exemplo n.º 4
0
class SimplePyNode(Node):
    def __init__(self, name, parent):
        Node.__init__(self, name, parent)
        
        self.input1 = NumericAttribute("input1", self)
        self.input2 = NumericAttribute("input2", self)
        self.output = NumericAttribute("output", self)
        
        self.addInputAttribute(self.input1)
        self.addInputAttribute(self.input2)
        self.addOutputAttribute(self.output)
        
        self._setAttributeAffect(self.input1, self.output)
        self._setAttributeAffect(self.input2, self.output)
        
        self._setAttributeAllowedSpecializations(self.input1, ["Float"])
        self._setAttributeAllowedSpecializations(self.input2, ["Float"])
        self._setAttributeAllowedSpecializations(self.output, ["Float"])
        
    def update(self, attribute):
        value1 = self.input1.value().floatValueAt(0)
        value2 = self.input2.value().floatValueAt(0)
        
        self.output.outValue().setFloatValueAt(0, value1 + value2)
Exemplo n.º 5
0
class SoundStreamNode(Node):
    def __init__(self, name, parent):
        Node.__init__(self, name, parent)

        self._fileName = StringAttribute("fileName", self)
        self._leftSpectrum = NumericAttribute("leftSpectrum", self)
        self._rightSpectrum = NumericAttribute("rightSpectrum", self)
        self._time = NumericAttribute("time", self)
        self._play = False

        self.addInputAttribute(self._fileName)
        self.addOutputAttribute(self._time)
        self.addOutputAttribute(self._leftSpectrum)
        self.addOutputAttribute(self._rightSpectrum)

        self._setAttributeAffect(self._fileName, self._time)
        self._setAttributeAffect(self._fileName, self._leftSpectrum)
        self._setAttributeAffect(self._fileName, self._rightSpectrum)

        self._setAttributeAllowedSpecializations(self._time, ["Float"])
        self._setAttributeAllowedSpecializations(self._leftSpectrum, ["FloatArray"])
        self._setAttributeAllowedSpecializations(self._rightSpectrum, ["FloatArray"])

        self._setUpdateEnabled(False)

        self._leftSpectrum.outValue().resize(64)
        self._rightSpectrum.outValue().resize(64)

        SoundManager.init()
    
    def isPlaying(self):
        return self._play

    def _advanceTime(self):
        leftSpectrum = self._leftSpectrum.outValue()
        rightSpectrum = self._rightSpectrum.outValue()
        timeVal = self._time.outValue()

        framesPerSecond = 24.0
        timeStep = 1.0 / framesPerSecond
        
        enlapsedTime = 0.0
        while self._play:
            enlapsedTime = enlapsedTime + timeStep
            
            SoundManager.setSpectrumOnNumeric(leftSpectrum, 0)
            SoundManager.setSpectrumOnNumeric(rightSpectrum, 1)
            
            self._leftSpectrum.valueChanged()
            self._rightSpectrum.valueChanged()

            timeVal.setFloatValueAt(0, enlapsedTime)
            self._time.valueChanged()

            time.sleep(timeStep)

    def play(self, value = True):
        self._play = value
        if self._play:
            SoundManager.load(self._fileName.value().stringValue())
            SoundManager.play()
            thread.start_new_thread(self._advanceTime, ())
        else:
            SoundManager.stop()
            
            self._time.outValue().setFloatValueAt(0, 0.0)
            self._time.valueChanged()

    def __del__(self):
        self._play = False
        SoundManager.terminate()