DirectFrame - collision ?

Hi!
I have exactly this problem:
panda3d.org/forums/viewtopi … f095d28dd8

But I can not make it work properly, use this example:

self.accept(“mouse1”, self.LCPrep)

def LCPrep(self):
self.acceptOnce(“mouse1-up”, self.LCResponse)

def LCResponse(self):
self.performMousePicking()

that’s what I do wrong? :frowning:
thanks all

Did you put state = DGG.NORMAL in your frame’s constructor?

Thanks!
Yes:
FrameContenedor = DirectFrame(state = DGG.NORMAL, image=self.barra,image_scale=(3,1,0.25),image_pos=(-1,0,0.25),
frameSize=(-4, 1, -1, 0.5),
pos=(1, -1, -1))


self.accept(“mouse1”, self.LCPrep)

def LCPrep(self):
self.acceptOnce(“mouse1-up”, self.LCResponse)

def LCResponse(self):
self.performMousePicking()
.
.
.
.
.
.
.
if you want to prepare my code and shipping…
Thanks!

So it’s working correctly now?

I am working with Tut-Chessboard modified example.
I need that when the mouse is over the DirectFrame not interact with the chessboard.
Do not know how to use the functions LCPrep, LCResponse and self.accept (“mouse1” self.LCPrep)
thank you very much for your help!
Here’s the code:

import direct.directbase.DirectStart
from panda3d.core import CollisionTraverser,CollisionNode
from panda3d.core import CollisionHandlerQueue,CollisionRay
from panda3d.core import TextNode
from panda3d.core import Point3,Vec3,Vec4,BitMask32
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
from direct.task.Task import Task
import sys
from direct.gui.DirectGui import *
BLACK = Vec4(0,0,0,1)
WHITE = Vec4(1,1,1,1)
HIGHLIGHT = Vec4(0,1,1,1)
PIECEBLACK = Vec4(.15, .15, .15, 1)


def PointAtZ(z, point, vec):
  return point + vec * ((z-point.getZ()) / vec.getZ())


def SquarePos(i):
  return Point3((i%8) - 3.5, int(i/8) - 3.5, 0)

def SquareColor(i):
  if (i + ((i/8)%2))%2: return BLACK
  else: return WHITE

class World(DirectObject):
  def __init__(self):
   
    DirectFrame( state = DGG.NORMAL,
                      frameSize=(-4, 1, -1, 0.8),
                      pos=(1, -1, -1))


    
    self.accept('escape', sys.exit)              
    base.disableMouse()                       
    camera.setPosHpr(0, -13.75, 6, 0, -25, 0)                          
    self.picker = CollisionTraverser()        
    self.pq     = CollisionHandlerQueue() 
    self.pickerNode = CollisionNode('mouseRay')
    self.pickerNP = camera.attachNewNode(self.pickerNode)
    self.pickerNode.setFromCollideMask(BitMask32.bit(1))
    self.pickerRay = CollisionRay()       
    self.pickerNode.addSolid(self.pickerRay)    
    self.picker.addCollider(self.pickerNP, self.pq)


  
    self.squareRoot = render.attachNewNode("squareRoot")
    self.squares = [None for i in range(64)]
    self.pieces = [None for i in range(64)]
    for i in range(64):
      self.squares[i] = loader.loadModel("models/square")
      self.squares[i].reparentTo(self.squareRoot)
      self.squares[i].setPos(SquarePos(i))
      self.squares[i].setColor(SquareColor(i))
      self.squares[i].find("**/polygon").node().setIntoCollideMask(
        BitMask32.bit(1))
      self.squares[i].find("**/polygon").node().setTag('square', str(i))


 

 
    self.hiSq = False
     

    self.mouseTask = taskMgr.add(self.mouseTask, 'mouseTask')



  def mouseTask(self, task):

    if self.hiSq is not False:
      self.squares[self.hiSq].setColor(SquareColor(self.hiSq))
      self.hiSq = False

    if base.mouseWatcherNode.hasMouse():
      mpos = base.mouseWatcherNode.getMouse()
      self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())

      self.picker.traverse(self.squareRoot)
      if self.pq.getNumEntries() > 0:
        self.pq.sortEntries()
        i = int(self.pq.getEntry(0).getIntoNode().getTag('square'))
        self.squares[i].setColor(HIGHLIGHT)
        self.hiSq = i
          
    return Task.cont

 
w = World()
run()

Okay, to use the solution I used you just need to change the mouse picking so that it isn’t a task. You only want to mouse pick when the mouse button is actually clicked.

Change

    self.mouseTask = taskMgr.add(self.mouseTask, 'mouseTask')

  def mouseTask(self, task):

    if self.hiSq is not False:
      self.squares[self.hiSq].setColor(SquareColor(self.hiSq))
      self.hiSq = False

    if base.mouseWatcherNode.hasMouse():
      mpos = base.mouseWatcherNode.getMouse()
      self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())

      self.picker.traverse(self.squareRoot)
      if self.pq.getNumEntries() > 0:
        self.pq.sortEntries()
        i = int(self.pq.getEntry(0).getIntoNode().getTag('square'))
        self.squares[i].setColor(HIGHLIGHT)
        self.hiSq = i
          
    return Task.cont

to

  self.accept("mouse1", self.LCPrep)

  def LCPrep(self):
    self.acceptOnce("mouse1-up", self.mousePick)

  def mousePick(self):

    if self.hiSq is not False:
      self.squares[self.hiSq].setColor(SquareColor(self.hiSq))
      self.hiSq = False

    if base.mouseWatcherNode.hasMouse():
      mpos = base.mouseWatcherNode.getMouse()
      self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())

      self.picker.traverse(self.squareRoot)
      if self.pq.getNumEntries() > 0:
        self.pq.sortEntries()
        i = int(self.pq.getEntry(0).getIntoNode().getTag('square'))
        self.squares[i].setColor(HIGHLIGHT)
        self.hiSq = i
          
    return

If you make that change, clicking on the frame won’t initiate a mouse pick, because the “mouse1” event will be blocked by the frame and self.LCPrep won’t be called. If self.LCPrep isn’t called, the program won’t accept “mouse1-up” either, and self.mousePick won’t be called.

hi! Sorry for the delay.
thanks for your help, but could not solve my problem with your code, I do not need to click so that there is interaction, I just need that there is no interaction when the mouse is above the directframe. I will try to solve the problem with
panda3d.org/manual/index.ph … ay_Regions
Thanks for your help. I hope you help me later:)

yeah, if you’re not looking for click based interaction, then the solution above is no good to you.