def createControler(self, x, y): if self.view != None: self.controler = render.attachNewNode("controler") self.controler = loader.loadModel('models/misc/smiley') controlerPathname = 'controler%d' % self.i self.controler.setName(controlerPathname) self.controler.setColor(0, 0, 0, 1) self.controler.setScale(0.2) self.controler.reparentTo(render) self.controler.setTag('OBJRoot','1') self.controler.setTag('Controller','1') #controller Tag self.i += 1 iRay = SelectionRay(self.view.camera) iRay.collider.setFromLens(self.view.camNode, x, y) iRay.collideWithBitMask(BitMask32.bit(21)) iRay.ct.traverse(self.view.collPlane) if iRay.getNumEntries() > 0: entry = iRay.getEntry(0) hitPt = entry.getSurfacePoint(entry.getFromNodePath()) if hitPt: # create a temp nodePath to get the position np = NodePath('temp') np.setPos(self.view.camera, hitPt) if base.direct.manipulationControl.fGridSnap: snappedPos = self.view.grid.computeSnapPoint(np.getPos()) np.setPos(snappedPos) # update temp nodePath's HPR and scale with newobj's np.setHpr(self.controler.getHpr()) np.setScale(self.controler.getScale()) # transform newobj to cursor position self.controler.setMat(Mat4(np.getMat())) np.remove() iRay.collisionNodePath.removeNode() del iRay self.curve.append((None, self.controler.getPos())) self.curveControl.append((self.i-1, self.controler))
def OnDropText(self, x, y, text): # create new object parentNPRef = [None] if not self.editor.propMeetsReq(text, parentNPRef): return action = ActionAddNewObj(self.editor, text, parent=parentNPRef[0]) self.editor.actionMgr.push(action) newobj = action() print(newobj) if newobj is None: return # change window coordinate to mouse coordinate mx = 2 * (x/float(self.view.ClientSize.GetWidth()) - 0.5) my = -2 * (y/float(self.view.ClientSize.GetHeight()) - 0.5) # create ray from the camera to detect 3d position iRay = SelectionRay(self.view.camera) iRay.collider.setFromLens(self.view.camNode, mx, my) hitPt = None if self.editor.objectMgr.currLiveNP: iRay.collideWithGeom() iRay.ct.traverse(self.editor.objectMgr.currLiveNP) def isEntryBackfacing(iRay, entry): if not entry.hasSurfaceNormal(): # Well, no way to tell. Assume we're not backfacing. return 0 fromNodePath = entry.getFromNodePath() v = Vec3(entry.getSurfacePoint(fromNodePath)) n = entry.getSurfaceNormal(fromNodePath) # Convert to camera space for backfacing test p2cam = iRay.collisionNodePath.getParent().getMat(self.view.camera) v = Vec3(p2cam.xformPoint(v)) n = p2cam.xformVec(n) # Normalize and check angle between to vectors v.normalize() return v.dot(n) >= 0 iRay.sortEntries() for entry in iRay.getEntries(): if isEntryBackfacing(iRay, entry): pass else: hitPt = entry.getSurfacePoint(entry.getFromNodePath()) break if hitPt is None: iRay.collideWithBitMask(BitMask32.bit(21)) iRay.ct.traverse(self.view.collPlane) if iRay.getNumEntries() > 0: entry = iRay.getEntry(0) hitPt = entry.getSurfacePoint(entry.getFromNodePath()) if hitPt: # create a temp nodePath to get the position np = NodePath('temp') np.setPos(self.view.camera, hitPt) if base.direct.manipulationControl.fGridSnap: snappedPos = self.view.grid.computeSnapPoint(np.getPos()) np.setPos(snappedPos) # update temp nodePath's HPR and scale with newobj's np.setHpr(newobj.getHpr()) np.setScale(newobj.getScale()) # transform newobj to cursor position obj = self.editor.objectMgr.findObjectByNodePath(newobj) action = ActionTransformObj(self.editor, obj[OG.OBJ_UID], Mat4(np.getMat())) self.editor.actionMgr.push(action) np.remove() action() iRay.collisionNodePath.removeNode() del iRay
def OnDropText(self, x, y, text): # create new object parentNPRef = [None] if not self.editor.propMeetsReq(text, parentNPRef): return action = ActionAddNewObj(self.editor, text, parent=parentNPRef[0]) self.editor.actionMgr.push(action) newobj = action() print(newobj) if newobj is None: return # change window coordinate to mouse coordinate mx = 2 * (x / float(self.view.ClientSize.GetWidth()) - 0.5) my = -2 * (y / float(self.view.ClientSize.GetHeight()) - 0.5) # create ray from the camera to detect 3d position iRay = SelectionRay(self.view.camera) iRay.collider.setFromLens(self.view.camNode, mx, my) hitPt = None if self.editor.objectMgr.currLiveNP: iRay.collideWithGeom() iRay.ct.traverse(self.editor.objectMgr.currLiveNP) def isEntryBackfacing(iRay, entry): if not entry.hasSurfaceNormal(): # Well, no way to tell. Assume we're not backfacing. return 0 fromNodePath = entry.getFromNodePath() v = Vec3(entry.getSurfacePoint(fromNodePath)) n = entry.getSurfaceNormal(fromNodePath) # Convert to camera space for backfacing test p2cam = iRay.collisionNodePath.getParent().getMat( self.view.camera) v = Vec3(p2cam.xformPoint(v)) n = p2cam.xformVec(n) # Normalize and check angle between to vectors v.normalize() return v.dot(n) >= 0 iRay.sortEntries() for entry in iRay.getEntries(): if isEntryBackfacing(iRay, entry): pass else: hitPt = entry.getSurfacePoint(entry.getFromNodePath()) break if hitPt is None: iRay.collideWithBitMask(BitMask32.bit(21)) iRay.ct.traverse(self.view.collPlane) if iRay.getNumEntries() > 0: entry = iRay.getEntry(0) hitPt = entry.getSurfacePoint(entry.getFromNodePath()) if hitPt: # create a temp nodePath to get the position np = NodePath('temp') np.setPos(self.view.camera, hitPt) if base.direct.manipulationControl.fGridSnap: snappedPos = self.view.grid.computeSnapPoint(np.getPos()) np.setPos(snappedPos) # update temp nodePath's HPR and scale with newobj's np.setHpr(newobj.getHpr()) np.setScale(newobj.getScale()) # transform newobj to cursor position obj = self.editor.objectMgr.findObjectByNodePath(newobj) action = ActionTransformObj(self.editor, obj[OG.OBJ_UID], Mat4(np.getMat())) self.editor.actionMgr.push(action) np.remove() action() iRay.collisionNodePath.removeNode() del iRay
def OnDropText(self, x, y, text): # create new object parentNPRef = [None] if not self.editor.propMeetsReq(text, parentNPRef): return # Get the libraryType and name ind = text.index(">") libraryType = text[0:ind] objectName = text[ind + 1:len(text)] # Get the type, type = None # and the file path... asset = None # in case it is an actor with animations anims = {} # only if it is a mesh if libraryType == "Meshes": type = "Meshes" asset = base.le.lib.meshes[objectName] # if it is an actor elif libraryType == "Actors": type = libraryType asset = base.le.lib.actors[objectName] anims = asset.anims elif libraryType == "Textures": type = libraryType asset = base.le.lib.textures[objectName] elif libraryType == "Terrains": type = libraryType asset = base.le.lib.terrains[objectName] # Otherwise, if the libraryType is a PandaObject elif libraryType == "PandaObject": # The object type is the object name type = objectName objectName = objectName # change window coordinate to mouse coordinate mx = 2 * (x / float(self.view.ClientSize.GetWidth()) - 0.5) my = -2 * (y / float(self.view.ClientSize.GetHeight()) - 0.5) # create ray from the camera to detect 3d position iRay = SelectionRay(self.view.camera) iRay.collider.setFromLens(self.view.camNode, mx, my) hitPt = None iRay.collideWithBitMask(BitMask32.bit(21)) iRay.ct.traverse(self.view.collPlane) if iRay.getNumEntries() > 0: entry = iRay.getEntry(0) hitPt = entry.getSurfacePoint(entry.getFromNodePath()) pos = None if hitPt: # create a temp nodePath to get the position np = NodePath('temp') np.setPos(self.view.camera, hitPt) if base.direct.manipulationControl.fGridSnap: snappedPos = self.view.grid.computeSnapPoint(np.getPos()) np.setPos(snappedPos) pos = np.getPos() np.remove() iRay.collisionNodePath.removeNode() del iRay if type: # Set the action action = ActionAddNewObj(self.editor, type, name=objectName + ':1', asset=asset, anims=anims, parent=parentNPRef[0], pos=pos) self.editor.actionMgr.push(action) newobj = action()
def OnDropText(self, x, y, text): # create new object parentNPRef = [None] if not self.editor.propMeetsReq(text, parentNPRef): return # Get the libraryType and name ind = text.index(">") libraryType = text[0:ind] objectName = text[ind+1:len(text)] # Get the type, type = None # and the file path... asset = None # in case it is an actor with animations anims = {} # only if it is a mesh if libraryType == "Meshes": type = "Meshes" asset = base.le.lib.meshes[objectName] # if it is an actor elif libraryType == "Actors": type = libraryType asset = base.le.lib.actors[objectName] anims = asset.anims elif libraryType == "Textures": type = libraryType asset = base.le.lib.textures[objectName] elif libraryType == "Terrains": type = libraryType asset = base.le.lib.terrains[objectName] # Otherwise, if the libraryType is a PandaObject elif libraryType == "PandaObject": # The object type is the object name type = objectName objectName = objectName # change window coordinate to mouse coordinate mx = 2 * (x/float(self.view.ClientSize.GetWidth()) - 0.5) my = -2 * (y/float(self.view.ClientSize.GetHeight()) - 0.5) # create ray from the camera to detect 3d position iRay = SelectionRay(self.view.camera) iRay.collider.setFromLens(self.view.camNode, mx, my) hitPt = None iRay.collideWithBitMask(BitMask32.bit(21)) iRay.ct.traverse(self.view.collPlane) if iRay.getNumEntries() > 0: entry = iRay.getEntry(0) hitPt = entry.getSurfacePoint(entry.getFromNodePath()) pos = None if hitPt: # create a temp nodePath to get the position np = NodePath('temp') np.setPos(self.view.camera, hitPt) if base.direct.manipulationControl.fGridSnap: snappedPos = self.view.grid.computeSnapPoint(np.getPos()) np.setPos(snappedPos) pos = np.getPos() np.remove() iRay.collisionNodePath.removeNode() del iRay if type: # Set the action action = ActionAddNewObj(self.editor, type, name = objectName + ':1', asset=asset, anims=anims, parent=parentNPRef[0], pos=pos) self.editor.actionMgr.push(action) newobj = action()