Example #1
0
    def __init__(self,
                 parent,
                 file_name,
                 file_type,
                 num_frames,
                 int_padding=1,
                 scale=(1, 1, 1),
                 fps=60,
                 pos=(0, 0, 0),
                 auto_gc=True):
        self.textures = self.loadTextureMovie(num_frames, file_name, file_type,
                                              int_padding)
        self.plane = base.loader.loadModel('assets/models/plane')
        self.plane.setPos(pos[0], pos[1], pos[2])  #set its position
        self.plane.setScale(scale[0], scale[1], scale[2])
        self.plane.reparentTo(parent)  #reparent to render
        self.plane.setTransparency(1)
        self.fps = fps
        self.animation_task = None
        self.plane.node().setEffect(BillboardEffect.makePointEye())
        self.currentLoop = 0
        self.lastFrame = 0
        self.trash = False
        self.auto_gc = auto_gc

        if base.displayFlipped:
            self.plane.setAttrib(
                CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))

        #dlight = DirectionalLight('my dlight')
        #dlnp = render.attachNewNode(dlight)
        #self.plane.setLight(dlnp)
        #dlnp.lookAt(self.plane)
        base.sprites.append(self)
Example #2
0
 def _addPlane(self):
     plane = base.loader.loadModel('assets/models/plane')
     plane.setPos(self.x + ((len(self._planes) - 1) * self.char_width),
                  self.y, self.z)  #set its position
     plane.setScale(self.sX, self.sY, self.sZ)
     plane.reparentTo(self.__container)  #reparent to render
     plane.setTransparency(1)
     plane.node().setEffect(BillboardEffect.makePointEye())
     self._planes.append(plane)
     return plane
 def _doBillboard(self):
     if self.SHOULD_BILLBOARD:
         self.innerNP.setEffect(
             BillboardEffect.make(
                 Vec3(0, 0, 1),
                 True,
                 False,
                 self.billboardOffset,
                 NodePath(),  # Empty; look at scene camera
                 Point3(0, 0, 0)))
     else:
         self.billboardOffset = 0.0
Example #4
0
    def highlight(self, uuid, intoNode, clear, *args):
        if clear:
            self.clearHighlight()
        pos = intoNode.getBounds().getApproxCenter()

        point = makePoint(pos)
        p = self.uiRoot.attachNewNode(point)
        p.setRenderModeThickness(3)
        self.curSelPoints.append(p)

        textNode = p.attachNewNode(TextNode("%s_text"%uuid))
        textNode.setPos(*pos)
        textNode.node().setText("%s"%uuid)
        textNode.node().setEffect(BillboardEffect.makePointEye())
Example #5
0
    def highlight(self, uuid, intoNode, clear, *args):
        if clear:
            self.clearHighlight()
        pos = intoNode.getBounds().getApproxCenter()

        point = makePoint(pos)
        p = self.uiRoot.attachNewNode(point)
        p.setRenderModeThickness(3)
        self.curSelPoints.append(p)

        textNode = p.attachNewNode(TextNode("%s_text" % uuid))
        textNode.setPos(*pos)
        textNode.node().setText("%s" % uuid)
        textNode.node().setEffect(BillboardEffect.makePointEye())
Example #6
0
 def initSwitchSigns(self):
     self.switchSigns = []
     for i in range(11):
         cm = CardMaker('card%d'%i)
         cm.setColor(0,0,0,0)
         cm.setFrame(-0.5, 0.5, -0.5, 0.5)
         card = self.level.attachNewNode(cm.generate())
         card.setAttrib(TransparencyAttrib.make(TransparencyAttrib.M_alpha))
         tex = loader.loadTexture('%d.png'%i)
         ts = TextureStage('ts')
         ts.setMode(TextureStage.MReplace)
         card.setTexture(ts, tex)
         card.setEffect(BillboardEffect.makePointEye())
         card.hide()
         self.switchSigns.append(card)
    def setChatAbsolute(self, chatString=None):
        if not chatString or chatString.isspace() or len(chatString) == 0:
            return

        self.clearChat()
        self.taskId = random.randint(0, 1000000000000000000000000000000)
        if self.nameTag:
            self.getNameTag().hide()

        if self.isThought(chatString):
            chatString = self.removeThoughtPrefix(chatString)
            bubble = loader.loadModel(CIGlobals.ThoughtBubble)
        else:
            length = math.sqrt(len(chatString)) / self.LENGTH_FACTOR
            if length < self.MIN_LENGTH:
                length = self.MIN_LENGTH
            if length > self.MAX_LENGTH:
                length = self.MAX_LENGTH
            bubble = loader.loadModel(CIGlobals.ChatBubble)
            if self.autoClearChat:
                taskMgr.doMethodLater(
                    length, self.clearChatTask,
                    "clearAvatarChat-%s" % (str(self.taskId)))

        if self.avatarType == CIGlobals.Suit:
            font = CIGlobals.getSuitFont()
        else:
            font = CIGlobals.getToonFont()

        self.chatBubble = ChatBalloon(bubble).generate(chatString, font)
        self.chatBubble.setEffect(
            BillboardEffect.make(Vec3(0, 0, 1), True, False, 3.0, camera,
                                 Point3(0, 0, 0)))
        if self.nameTag:
            self.chatBubble.setZ(self.getNameTag().getZ())
        else:
            if self.avatarType == CIGlobals.Suit:
                nametagZ = self.suitPlan.getNametagZ()
                self.chatBubble.setZ(nametagZ)

        if self.avatar and hasattr(self.avatar, 'getGhost'):
            if not self.avatar.getGhost(
            ) or self.avatar.doId == base.localAvatar.doId:
                self.chatBubble.reparentTo(self)
        else:
            self.chatBubble.reparentTo(self)

        LabelScaler().resize(self.chatBubble)
Example #8
0
 def doBillboardEffect(self):
     billboardEffect = BillboardEffect.make(
         Vec3(0, 0, 1), True, False, self.billboardOffset, base.cam,
         Point3(0, 0, 0))
     self.contents.setEffect(billboardEffect)
Example #9
0
    def __init__(self):
        self.canPlantLabel = DirectLabel(
            frameColor=(0, 0, 0, 0.25),
            text_fg=(1, 1, 1, 1),
            scale=0.15,
            pos=(0, 0, 0.25),
            pad=(0.2,0.2),
            text=_("Plant Seed"))
        self.canPlantLabel.setTransparency(True)
        self.canPlantLabel.reparentTo(base.a2dBottomCenter)
        self.canPlantLabel.hide()

        self.speekLabel = DirectLabel(
            frameColor=(0, 0, 0, 0.25),
            text_fg=(1, 1, 1, 1),
            scale=0.15,
            pos=(0, 0, 0.5),
            pad=(0.2,0.2),
            text="...")
        self.speekLabel.reparentTo(render)
        self.speekLabel.hide()
        self.speekLabel.setTransparency(True)
        self.speekLabel.setEffect(BillboardEffect.makePointEye())
        self.speekLabel.setBin("fixed", 11)
        self.speekLabel.setDepthWrite(False)

        self.storyText = DirectLabel(
            frameColor=(0, 0, 0, 0.25),
            text_fg=(1, 1, 1, 1),
            scale=0.08,
            pos=(0, 0, 0.25),
            pad=(0.2,0.2),
            text="Story text")
        self.storyText.setTransparency(True)
        self.storyText.reparentTo(base.a2dBottomCenter)
        self.storyText.hide()

        self.points = DirectLabel(
            frameColor=(0, 0, 0, 0.25),
            text_fg=(1, 1, 1, 1),
            scale=0.075,
            pos=(0.05, 0, -0.1),
            pad=(0.2,0.2),
            text_align=TextNode.ALeft,
            text=_("Points: %d")%0)
        self.points.setTransparency(True)
        self.points.reparentTo(base.a2dTopLeft)

        self.playerWater = DirectLabel(
            frameColor=(0, 0, 0, 0.25),
            text_fg=(1, 1, 1, 1),
            scale=0.075,
            pos=(0.05, 0, -0.2),
            pad=(0.2,0.2),
            text_align=TextNode.ALeft,
            text=_("Remaining Water: %d")%100)
        self.playerWater.setTransparency(True)
        self.playerWater.reparentTo(base.a2dTopLeft)


        self.helpInfo = DirectLabel(
            frameColor=(0, 0, 0, 0.25),
            text_fg=(1, 1, 1, 1),
            scale=0.075,
            pos=(-0.05, 0, -0.1),
            pad=(0.2,0.2),
            text_align=TextNode.ARight,
            text=_("F1 - show help"))
        self.helpInfo.setTransparency(True)
        self.helpInfo.reparentTo(base.a2dTopRight)

        self.hide()
Example #10
0
 def doBillboardEffect(self):
     billboardEffect = BillboardEffect.make(
         Vec3(0, 0, 1), True, False, self.billboardOffset, base.cam,
         Point3(0, 0, 0))
     self.contents.setEffect(billboardEffect)
Example #11
0
    def __init__(self):
        #Standard initialization stuff
        #Standard title that's on screen in every tutorial
        self.title = OnscreenText(text='Panda3D: Tutorial - Texture "Movies"',
                                  style=1,
                                  fg=(1, 1, 1, 1),
                                  pos=(0.7, -0.95),
                                  scale=.07)

        #Text to show the keyboard keys and their functions on screen
        self.escapeEventText = OnscreenText(text="ESC: Quit",
                                            style=1,
                                            fg=(1, 1, 1, 1),
                                            pos=(-1.3, 0.95),
                                            align=TextNode.ALeft,
                                            scale=.05)
        self.onekeyEventText = OnscreenText(text="[1]: Freeview camera",
                                            style=1,
                                            fg=(1, 1, 1, 1),
                                            pos=(-1.3, 0.90),
                                            align=TextNode.ALeft,
                                            scale=.05)
        self.twokeyEventText = OnscreenText(
            text="[2]: Preset Camera Angle 2 (Verify billboard effect)",
            style=1,
            fg=(1, 1, 1, 1),
            pos=(-1.3, 0.85),
            align=TextNode.ALeft,
            scale=.05,
            mayChange=1)

        base.setBackgroundColor(0, 0, 0)  #Set the background color

        #Set up the key input
        self.accept('escape', sys.exit)  #Escape quits
        self.accept('1', self.setViewMain)  #Free view
        self.accept('2', self.setViewBillboard)  #Billboard effect view

        #Initialization specific to this world
        #Load a polygon plane (4 sided square) to put an animated duck sprite on
        self.duckPlane = loader.loadModel('models/plane')
        self.duckPlane.setPos(-2, 8, 0)  #set its position
        self.duckPlane.reparentTo(render)  #reparent to render

        #Enable tranparency: this attribute needs to be set for Panda to render the
        #transparency in the duck's texture as transparent rather than opaque
        self.duckPlane.setTransparency(1)

        #Now we call our special 'loadTextureMovie' function that returns a list
        #containing all of the textures for the duck sprite.
        #Check the function definition later in this file for its parameters
        self.duckTexs = self.loadTextureMovie(24,
                                              'duck/duck_fly_left',
                                              'png',
                                              padding=2)

        #Next we add a task to our task list that will animate the texture on the
        #duck plane according to the time elapsed.
        self.duckTask = taskMgr.add(self.textureMovie, "duckTask")
        #The function self.textureMovie is set to run any texture movie that
        #animates and loops based on time (rather that some other value like
        #position). To do that, it is set up to expect a number of parameters set
        #in the task object. The following lines set those parameters

        #Framerate: The texture will be changed 36 times per second
        self.duckTask.fps = 36
        #self.duckPlane is the object whose texture should be changed
        self.duckTask.obj = self.duckPlane
        #self.duckTexs (which we created earlier with self.oadTextureMovie)
        #contains the list of textures to animate from
        self.duckTask.textures = self.duckTexs

        #Now, instead of a duck, we will put an animated explosion onto a polygon
        #This is the same as loading the duck animation, with the expection that
        #we will "billboard" the explosion so that it always faces the camera
        self.expPlane = loader.loadModel('models/plane')  #load the object
        self.expPlane.setPos(2, 8, 0)  #set the position
        self.expPlane.reparentTo(render)  #reparent to render
        self.expPlane.setTransparency(1)  #enable transparency
        #load the texture movie
        self.expTexs = self.loadTextureMovie(51,
                                             'explosion/explosion',
                                             'png',
                                             padding=4)

        #create the animation task
        self.expTask = taskMgr.add(self.textureMovie, "explosionTask")
        self.expTask.fps = 30  #set framerate
        self.expTask.obj = self.expPlane  #set object
        self.expTask.textures = self.expTexs  #set texture list

        #This create the "billboard" effect that will rotate the object so that it
        #is always rendered as facing the eye (camera)
        self.expPlane.node().setEffect(BillboardEffect.makePointEye())

        #The code below generates the plane you see with the numbers and arrows.
        #This is just to give a sense of orientation as the camera is moved around.
        self.orientPlane = loader.loadModel('models/plane')  #Load the object
        #load the texture
        self.orientTex = loader.loadTexture("models/textures/orientation.png")
        self.orientPlane.setTexture(self.orientTex, 1)  #Set the texture
        self.orientPlane.reparentTo(render)  #Parent to render
        #Set the position, orientation, and scale
        self.orientPlane.setPosHprScale(0, 8, -1, 0, -90, 0, 10, 10, 10)
  def __init__(self):
    #Standard initialization stuff
    #Standard title that's on screen in every tutorial
    self.title = OnscreenText(text='Panda3D: Tutorial - Texture "Movies"',
                              style=1, fg=(1,1,1,1), pos=(0.7,-0.95),
                              scale = .07)
    
    #Text to show the keyboard keys and their functions on screen
    self.escapeEventText = OnscreenText(
      text="ESC: Quit", style=1, fg=(1,1,1,1), pos=(-1.3, 0.95),
      align=TextNode.ALeft, scale = .05)
    self.onekeyEventText = OnscreenText(
      text="[1]: Freeview camera", style=1, fg=(1,1,1,1), pos=(-1.3, 0.90),
      align=TextNode.ALeft, scale = .05)
    self.twokeyEventText = OnscreenText(
      text="[2]: Preset Camera Angle 2 (Verify billboard effect)",
      style=1, fg=(1,1,1,1), pos=(-1.3, 0.85),
      align=TextNode.ALeft, scale = .05, mayChange = 1)
    
    base.setBackgroundColor(0, 0, 0)        #Set the background color
    
    #Set up the key input
    self.accept('escape', sys.exit)         #Escape quits
    self.accept('1', self.setViewMain)      #Free view
    self.accept('2', self.setViewBillboard) #Billboard effect view

    #Initialization specific to this world
    #Load a polygon plane (4 sided square) to put an animated duck sprite on
    self.duckPlane = loader.loadModel('models/plane')
    self.duckPlane.setPos(-2, 8, 0)         #set its position
    self.duckPlane.reparentTo(render)       #reparent to render

    #Enable tranparency: this attribute needs to be set for Panda to render the
    #transparency in the duck's texture as transparent rather than opaque
    self.duckPlane.setTransparency(1)

    #Now we call our special 'loadTextureMovie' function that returns a list
    #containing all of the textures for the duck sprite.
    #Check the function definition later in this file for its parameters
    self.duckTexs = self.loadTextureMovie(24, 'duck/duck_fly_left',
                                          'png', padding = 2)

    #Next we add a task to our task list that will animate the texture on the
    #duck plane according to the time elapsed.
    self.duckTask = taskMgr.add(self.textureMovie, "duckTask")
    #The function self.textureMovie is set to run any texture movie that
    #animates and loops based on time (rather that some other value like
    #position). To do that, it is set up to expect a number of parameters set
    #in the task object. The following lines set those parameters

    #Framerate: The texture will be changed 36 times per second
    self.duckTask.fps = 36
    #self.duckPlane is the object whose texture should be changed
    self.duckTask.obj = self.duckPlane  
    #self.duckTexs (which we created earlier with self.oadTextureMovie)
    #contains the list of textures to animate from
    self.duckTask.textures = self.duckTexs

    #Now, instead of a duck, we will put an animated explosion onto a polygon
    #This is the same as loading the duck animation, with the expection that
    #we will "billboard" the explosion so that it always faces the camera
    self.expPlane = loader.loadModel('models/plane')  #load the object
    self.expPlane.setPos(2, 8, 0)                         #set the position
    self.expPlane.reparentTo(render)                      #reparent to render
    self.expPlane.setTransparency(1)                      #enable transparency
    #load the texture movie
    self.expTexs = self.loadTextureMovie(51, 'explosion/explosion',
                                         'png', padding = 4)

    #create the animation task
    self.expTask = taskMgr.add(self.textureMovie, "explosionTask")
    self.expTask.fps = 30                                 #set framerate
    self.expTask.obj = self.expPlane                      #set object
    self.expTask.textures = self.expTexs                  #set texture list

    #This create the "billboard" effect that will rotate the object so that it
    #is always rendered as facing the eye (camera)
    self.expPlane.node().setEffect(BillboardEffect.makePointEye())
    
    #The code below generates the plane you see with the numbers and arrows.
    #This is just to give a sense of orientation as the camera is moved around.
    self.orientPlane = loader.loadModel('models/plane') #Load the object
    #load the texture
    self.orientTex = loader.loadTexture("models/textures/orientation.png")
    self.orientPlane.setTexture(self.orientTex, 1)        #Set the texture
    self.orientPlane.reparentTo(render)                   #Parent to render
    #Set the position, orientation, and scale
    self.orientPlane.setPosHprScale(0, 8, -1, 0, -90, 0, 10, 10, 10)
Example #13
0
 def apply(self, nodePath):
     effect = BillboardEffect.make(self.up_vector, self.eye_relative,
                                   self.axial_rotate, 0.0, NodePath(),
                                   LPoint3f(0, 0, 0))
     nodePath.setEffect(effect)
Example #14
0
def hasNetBillboard(np):
    # Returns true if this node or any ancestor of this node contains a BillboardEffect.
    from panda3d.core import BillboardEffect
    return hasNetEffect(np, BillboardEffect.getClassType())