NodePath-extensions.py 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. """
  2. NodePath-extensions module: contains methods to extend functionality
  3. of the NodePath class
  4. """
  5. def id(self):
  6. """Returns a unique id identifying the NodePath instance"""
  7. try:
  8. # Old style scene graph
  9. return self.arc()
  10. except:
  11. # New style scene graph
  12. return self.getKey()
  13. def getName(self):
  14. """Returns the name of the bottom node if it exists, or <noname>"""
  15. node = self.node()
  16. if hasattr(node, "getName"):
  17. return node.getName()
  18. return '<noname>'
  19. def setName(self, name = '<noname>'):
  20. """Sets the name of the bottom node if it can be set."""
  21. node = self.node()
  22. if hasattr(node, "setName"):
  23. node.setName(name)
  24. # For iterating over children
  25. def getChildrenAsList(self):
  26. """Converts a node path's child NodePathCollection into a list"""
  27. if self.isEmpty():
  28. return []
  29. else:
  30. children = self.getChildren()
  31. childrenList = []
  32. for childNum in range(self.getNumChildren()):
  33. childrenList.append(children[childNum])
  34. return childrenList
  35. def printChildren(self):
  36. """Prints out the children of the bottom node of a node path"""
  37. for child in self.getChildrenAsList():
  38. print child.getName()
  39. def toggleVis(self):
  40. """Toggles visibility of a nodePath"""
  41. if self.isHidden():
  42. self.show()
  43. return 1
  44. else:
  45. self.hide()
  46. return 0
  47. def showSiblings(self):
  48. """Show all the siblings of a node path"""
  49. for sib in self.getParent().getChildrenAsList():
  50. if sib.node() != self.node():
  51. sib.show()
  52. def hideSiblings(self):
  53. """Hide all the siblings of a node path"""
  54. for sib in self.getParent().getChildrenAsList():
  55. if sib.node() != self.node():
  56. sib.hide()
  57. def showAllDescendants(self):
  58. """Show the node path and all its children"""
  59. if self.hasArcs():
  60. self.show()
  61. for child in self.getChildrenAsList():
  62. child.showAllDescendants()
  63. def isolate(self):
  64. """Show the node path and hide its siblings"""
  65. self.showAllDescendants()
  66. self.hideSiblings()
  67. def remove(self):
  68. """Remove a node path from the scene graph"""
  69. # Send message in case anyone needs to do something
  70. # before node is deleted
  71. messenger.send('preRemoveNodePath', [self])
  72. # Remove nodePath
  73. self.removeNode()
  74. def reversels(self):
  75. """Walk up a tree and print out the path to the root"""
  76. ancestry = self.getAncestry()
  77. indentString = ""
  78. for nodePath in ancestry:
  79. type = nodePath.node().getType().getName()
  80. name = nodePath.getName()
  81. print indentString + type + " " + name
  82. indentString = indentString + " "
  83. def getAncestry(self):
  84. """Get a list of a node path's ancestors"""
  85. node = self.node()
  86. if (self.hasParent()):
  87. ancestry = self.getParent().getAncestry()
  88. ancestry.append(self)
  89. return ancestry
  90. else:
  91. return [self]
  92. def getTightBounds(self):
  93. import Point3
  94. v1 = Point3.Point3(0)
  95. v2 = Point3.Point3(0)
  96. self.calcTightBounds(v1,v2)
  97. return v1, v2
  98. def pprintPos(self, other = None, sd = 2):
  99. """ Pretty print a node path's pos """
  100. formatString = '%0.' + '%d' % sd + 'f'
  101. if other:
  102. pos = self.getPos(other)
  103. otherString = other.getName() + ', '
  104. else:
  105. pos = self.getPos()
  106. otherString = ''
  107. print (self.getName() + '.setPos(' + otherString +
  108. formatString % pos[0] + ', ' +
  109. formatString % pos[1] + ', ' +
  110. formatString % pos[2] +
  111. ')\n')
  112. def pprintHpr(self, other = None, sd = 2):
  113. """ Pretty print a node path's hpr """
  114. formatString = '%0.' + '%d' % sd + 'f'
  115. if other:
  116. hpr = self.getHpr(other)
  117. otherString = other.getName() + ', '
  118. else:
  119. hpr = self.getHpr()
  120. otherString = ''
  121. print (self.getName() + '.setHpr(' + otherString +
  122. formatString % hpr[0] + ', ' +
  123. formatString % hpr[1] + ', ' +
  124. formatString % hpr[2] +
  125. ')\n')
  126. def pprintScale(self, other = None, sd = 2):
  127. """ Pretty print a node path's scale """
  128. formatString = '%0.' + '%d' % sd + 'f'
  129. if other:
  130. scale = self.getScale(other)
  131. otherString = other.getName() + ', '
  132. else:
  133. scale = self.getScale()
  134. otherString = ''
  135. print (self.getName() + '.setScale(' + otherString +
  136. formatString % scale[0] + ', ' +
  137. formatString % scale[1] + ', ' +
  138. formatString % scale[2] +
  139. ')\n')
  140. def pprintPosHpr(self, other = None, sd = 2):
  141. """ Pretty print a node path's pos and, hpr """
  142. formatString = '%0.' + '%d' % sd + 'f'
  143. if other:
  144. pos = self.getPos(other)
  145. hpr = self.getHpr(other)
  146. otherString = other.getName() + ', '
  147. else:
  148. pos = self.getPos()
  149. hpr = self.getHpr()
  150. otherString = ''
  151. print (self.getName() + '.setPosHpr(' + otherString +
  152. formatString % pos[0] + ', ' +
  153. formatString % pos[1] + ', ' +
  154. formatString % pos[2] + ', ' +
  155. formatString % hpr[0] + ', ' +
  156. formatString % hpr[1] + ', ' +
  157. formatString % hpr[2] +
  158. ')\n')
  159. def pprintPosHprScale(self, other = None, sd = 2):
  160. """ Pretty print a node path's pos, hpr, and scale """
  161. formatString = '%0.' + '%d' % sd + 'f'
  162. if other:
  163. pos = self.getPos(other)
  164. hpr = self.getHpr(other)
  165. scale = self.getScale(other)
  166. otherString = other.getName() + ', '
  167. else:
  168. pos = self.getPos()
  169. hpr = self.getHpr()
  170. scale = self.getScale()
  171. otherString = ''
  172. print (self.getName() + '.setPosHprScale(' + otherString +
  173. formatString % pos[0] + ', ' +
  174. formatString % pos[1] + ', ' +
  175. formatString % pos[2] + ', ' +
  176. formatString % hpr[0] + ', ' +
  177. formatString % hpr[1] + ', ' +
  178. formatString % hpr[2] + ', ' +
  179. formatString % scale[0] + ', ' +
  180. formatString % scale[1] + ', ' +
  181. formatString % scale[2] +
  182. ')\n')
  183. def iPos(self, other = None):
  184. """ Set node path's pos to 0,0,0 """
  185. if other:
  186. self.setPos(other, 0,0,0)
  187. else:
  188. self.setPos(0,0,0)
  189. def iHpr(self, other = None):
  190. """ Set node path's hpr to 0,0,0 """
  191. if other:
  192. self.setHpr(other, 0,0,0)
  193. else:
  194. self.setHpr(0,0,0)
  195. def iScale(self, other = None):
  196. """ SEt node path's scale to 1,1,1 """
  197. if other:
  198. self.setScale(other, 1,1,1)
  199. else:
  200. self.setScale(1,1,1)
  201. def iPosHpr(self, other = None):
  202. """ Set node path's pos and hpr to 0,0,0 """
  203. if other:
  204. self.setPosHpr(other,0,0,0,0,0,0)
  205. else:
  206. self.setPosHpr(0,0,0,0,0,0)
  207. def iPosHprScale(self, other = None):
  208. """ Set node path's pos and hpr to 0,0,0 and scale to 1,1,1 """
  209. if other:
  210. self.setPosHprScale(other, 0,0,0,0,0,0,1,1,1)
  211. else:
  212. self.setPosHprScale(0,0,0,0,0,0,1,1,1)
  213. # private methods
  214. def __getBlend(self, blendType):
  215. """__getBlend(self, string)
  216. Return the C++ blend class corresponding to blendType string
  217. """
  218. import LerpBlendHelpers
  219. if (blendType == "easeIn"):
  220. return LerpBlendHelpers.easeIn
  221. elif (blendType == "easeOut"):
  222. return LerpBlendHelpers.easeOut
  223. elif (blendType == "easeInOut"):
  224. return LerpBlendHelpers.easeInOut
  225. elif (blendType == "noBlend"):
  226. return LerpBlendHelpers.noBlend
  227. else:
  228. raise Exception("Error: NodePath.__getBlend: Unknown blend type")
  229. def __lerp(self, functorFunc, duration, blendType, taskName=None):
  230. """
  231. __lerp(self, functorFunc, float, string, string)
  232. Basic lerp functionality used by other lerps.
  233. Fire off a lerp. Make it a task if taskName given.
  234. """
  235. # functorFunc is a function which can be called to create a functor.
  236. # functor creation is defered so initial state (sampled in functorFunc)
  237. # will be appropriate for the time the lerp is spawned
  238. import Task
  239. from TaskManagerGlobal import taskMgr
  240. # upon death remove the functorFunc
  241. def lerpUponDeath(task):
  242. # Try to break circular references
  243. try:
  244. del task.functorFunc
  245. except:
  246. pass
  247. try:
  248. del task.lerp
  249. except:
  250. pass
  251. # make the task function
  252. def lerpTaskFunc(task):
  253. from Lerp import Lerp
  254. from ClockObject import ClockObject
  255. from Task import Task, cont, done
  256. if task.init == 1:
  257. # make the lerp
  258. functor = task.functorFunc()
  259. task.lerp = Lerp(functor, task.duration, task.blendType)
  260. task.init = 0
  261. dt = globalClock.getDt()
  262. task.lerp.setStepSize(dt)
  263. task.lerp.step()
  264. if (task.lerp.isDone()):
  265. # Reset the init flag, in case the task gets re-used
  266. task.init = 1
  267. return(done)
  268. else:
  269. return(cont)
  270. # make the lerp task
  271. lerpTask = Task.Task(lerpTaskFunc)
  272. lerpTask.init = 1
  273. lerpTask.functorFunc = functorFunc
  274. lerpTask.duration = duration
  275. lerpTask.blendType = self.__getBlend(blendType)
  276. lerpTask.uponDeath = lerpUponDeath
  277. if (taskName == None):
  278. # don't spawn a task, return one instead
  279. return lerpTask
  280. else:
  281. # spawn the lerp task
  282. taskMgr.add(lerpTask, taskName)
  283. return lerpTask
  284. def __autoLerp(self, functorFunc, time, blendType, taskName):
  285. """_autoLerp(self, functor, float, string, string)
  286. This lerp uses C++ to handle the stepping. Bonus is
  287. its more efficient, trade-off is there is less control"""
  288. import AutonomousLerp
  289. # make a lerp that lives in C++ land
  290. functor = functorFunc()
  291. lerp = AutonomousLerp.AutonomousLerp(functor, time,
  292. self.__getBlend(blendType),
  293. base.eventHandler)
  294. lerp.start()
  295. return lerp
  296. # user callable lerp methods
  297. def lerpColor(self, *posArgs, **keyArgs):
  298. """lerpColor(self, *positionArgs, **keywordArgs)
  299. determine which lerpColor* to call based on arguments
  300. """
  301. if (len(posArgs) == 2):
  302. return apply(self.lerpColorVBase4, posArgs, keyArgs)
  303. elif (len(posArgs) == 3):
  304. return apply(self.lerpColorVBase4VBase4, posArgs, keyArgs)
  305. elif (len(posArgs) == 5):
  306. return apply(self.lerpColorRGBA, posArgs, keyArgs)
  307. elif (len(posArgs) == 9):
  308. return apply(self.lerpColorRGBARGBA, posArgs, keyArgs)
  309. else:
  310. # bad args
  311. raise Exception("Error: NodePath.lerpColor: bad number of args")
  312. def lerpColorRGBA(self, r, g, b, a, time,
  313. blendType="noBlend", auto=None, task=None):
  314. """lerpColorRGBA(self, float, float, float, float, float,
  315. string="noBlend", string=none, string=none)
  316. """
  317. def functorFunc(self = self, r = r, g = g, b = b, a = a):
  318. import ColorLerpFunctor
  319. # just end rgba values, use current color rgba values for start
  320. startColor = self.getColor()
  321. functor = ColorLerpFunctor.ColorLerpFunctor(
  322. self,
  323. startColor[0], startColor[1],
  324. startColor[2], startColor[3],
  325. r, g, b, a)
  326. return functor
  327. #determine whether to use auto, spawned, or blocking lerp
  328. if (auto != None):
  329. return self.__autoLerp(functorFunc, time, blendType, auto)
  330. elif (task != None):
  331. return self.__lerp(functorFunc, time, blendType, task)
  332. else:
  333. return self.__lerp(functorFunc, time, blendType)
  334. def lerpColorRGBARGBA(self, sr, sg, sb, sa, er, eg, eb, ea, time,
  335. blendType="noBlend", auto=None, task=None):
  336. """lerpColorRGBARGBA(self, float, float, float, float, float,
  337. float, float, float, float, string="noBlend", string=none, string=none)
  338. """
  339. def functorFunc(self = self, sr = sr, sg = sg, sb = sb, sa = sa,
  340. er = er, eg = eg, eb = eb, ea = ea):
  341. import ColorLerpFunctor
  342. # start and end rgba values
  343. functor = ColorLerpFunctor.ColorLerpFunctor(self, sr, sg, sb, sa,
  344. er, eg, eb, ea)
  345. return functor
  346. #determine whether to use auto, spawned, or blocking lerp
  347. if (auto != None):
  348. return self.__autoLerp(functorFunc, time, blendType, auto)
  349. elif (task != None):
  350. return self.__lerp(functorFunc, time, blendType, task)
  351. else:
  352. return self.__lerp(functorFunc, time, blendType)
  353. def lerpColorVBase4(self, endColor, time,
  354. blendType="noBlend", auto=None, task=None):
  355. """lerpColorVBase4(self, VBase4, float, string="noBlend", string=none,
  356. string=none)
  357. """
  358. def functorFunc(self = self, endColor = endColor):
  359. import ColorLerpFunctor
  360. # just end vec4, use current color for start
  361. startColor = self.getColor()
  362. functor = ColorLerpFunctor.ColorLerpFunctor(
  363. self, startColor, endColor)
  364. return functor
  365. #determine whether to use auto, spawned, or blocking lerp
  366. if (auto != None):
  367. return self.__autoLerp(functorFunc, time, blendType, auto)
  368. elif (task != None):
  369. return self.__lerp(functorFunc, time, blendType, task)
  370. else:
  371. return self.__lerp(functorFunc, time, blendType)
  372. def lerpColorVBase4VBase4(self, startColor, endColor, time,
  373. blendType="noBlend", auto=None, task=None):
  374. """lerpColorVBase4VBase4(self, VBase4, VBase4, float, string="noBlend",
  375. string=none, string=none)
  376. """
  377. def functorFunc(self = self, startColor = startColor,
  378. endColor = endColor):
  379. import ColorLerpFunctor
  380. # start color and end vec
  381. functor = ColorLerpFunctor.ColorLerpFunctor(
  382. self, startColor, endColor)
  383. return functor
  384. #determine whether to use auto, spawned, or blocking lerp
  385. if (auto != None):
  386. return self.__autoLerp(functorFunc, time, blendType, auto)
  387. elif (task != None):
  388. return self.__lerp(functorFunc, time, blendType, task)
  389. else:
  390. return self.__lerp(functorFunc, time, blendType)
  391. # user callable lerp methods
  392. def lerpColorScale(self, *posArgs, **keyArgs):
  393. """lerpColorScale(self, *positionArgs, **keywordArgs)
  394. determine which lerpColorScale* to call based on arguments
  395. """
  396. if (len(posArgs) == 2):
  397. return apply(self.lerpColorScaleVBase4, posArgs, keyArgs)
  398. elif (len(posArgs) == 3):
  399. return apply(self.lerpColorScaleVBase4VBase4, posArgs, keyArgs)
  400. elif (len(posArgs) == 5):
  401. return apply(self.lerpColorScaleRGBA, posArgs, keyArgs)
  402. elif (len(posArgs) == 9):
  403. return apply(self.lerpColorScaleRGBARGBA, posArgs, keyArgs)
  404. else:
  405. # bad args
  406. raise Exception("Error: NodePath.lerpColorScale: bad number of args")
  407. def lerpColorScaleRGBA(self, r, g, b, a, time,
  408. blendType="noBlend", auto=None, task=None):
  409. """lerpColorScaleRGBA(self, float, float, float, float, float,
  410. string="noBlend", string=none, string=none)
  411. """
  412. def functorFunc(self = self, r = r, g = g, b = b, a = a):
  413. import ColorScaleLerpFunctor
  414. # just end rgba values, use current color rgba values for start
  415. startColor = self.getColor()
  416. functor = ColorScaleLerpFunctor.ColorScaleLerpFunctor(
  417. self,
  418. startColor[0], startColor[1],
  419. startColor[2], startColor[3],
  420. r, g, b, a)
  421. return functor
  422. #determine whether to use auto, spawned, or blocking lerp
  423. if (auto != None):
  424. return self.__autoLerp(functorFunc, time, blendType, auto)
  425. elif (task != None):
  426. return self.__lerp(functorFunc, time, blendType, task)
  427. else:
  428. return self.__lerp(functorFunc, time, blendType)
  429. def lerpColorScaleRGBARGBA(self, sr, sg, sb, sa, er, eg, eb, ea, time,
  430. blendType="noBlend", auto=None, task=None):
  431. """lerpColorScaleRGBARGBA(self, float, float, float, float, float,
  432. float, float, float, float, string="noBlend", string=none, string=none)
  433. """
  434. def functorFunc(self = self, sr = sr, sg = sg, sb = sb, sa = sa,
  435. er = er, eg = eg, eb = eb, ea = ea):
  436. import ColorScaleLerpFunctor
  437. # start and end rgba values
  438. functor = ColorScaleLerpFunctor.ColorScaleLerpFunctor(self, sr, sg, sb, sa,
  439. er, eg, eb, ea)
  440. return functor
  441. #determine whether to use auto, spawned, or blocking lerp
  442. if (auto != None):
  443. return self.__autoLerp(functorFunc, time, blendType, auto)
  444. elif (task != None):
  445. return self.__lerp(functorFunc, time, blendType, task)
  446. else:
  447. return self.__lerp(functorFunc, time, blendType)
  448. def lerpColorScaleVBase4(self, endColor, time,
  449. blendType="noBlend", auto=None, task=None):
  450. """lerpColorScaleVBase4(self, VBase4, float, string="noBlend", string=none,
  451. string=none)
  452. """
  453. def functorFunc(self = self, endColor = endColor):
  454. import ColorScaleLerpFunctor
  455. # just end vec4, use current color for start
  456. startColor = self.getColor()
  457. functor = ColorScaleLerpFunctor.ColorScaleLerpFunctor(
  458. self, startColor, endColor)
  459. return functor
  460. #determine whether to use auto, spawned, or blocking lerp
  461. if (auto != None):
  462. return self.__autoLerp(functorFunc, time, blendType, auto)
  463. elif (task != None):
  464. return self.__lerp(functorFunc, time, blendType, task)
  465. else:
  466. return self.__lerp(functorFunc, time, blendType)
  467. def lerpColorScaleVBase4VBase4(self, startColor, endColor, time,
  468. blendType="noBlend", auto=None, task=None):
  469. """lerpColorScaleVBase4VBase4(self, VBase4, VBase4, float, string="noBlend",
  470. string=none, string=none)
  471. """
  472. def functorFunc(self = self, startColor = startColor,
  473. endColor = endColor):
  474. import ColorScaleLerpFunctor
  475. # start color and end vec
  476. functor = ColorScaleLerpFunctor.ColorScaleLerpFunctor(
  477. self, startColor, endColor)
  478. return functor
  479. #determine whether to use auto, spawned, or blocking lerp
  480. if (auto != None):
  481. return self.__autoLerp(functorFunc, time, blendType, auto)
  482. elif (task != None):
  483. return self.__lerp(functorFunc, time, blendType, task)
  484. else:
  485. return self.__lerp(functorFunc, time, blendType)
  486. def lerpHpr(self, *posArgs, **keyArgs):
  487. """lerpHpr(self, *positionArgs, **keywordArgs)
  488. Determine whether to call lerpHprHPR or lerpHprVBase3
  489. based on first argument
  490. """
  491. # check to see if lerping with
  492. # three floats or a VBase3
  493. if (len(posArgs) == 4):
  494. return apply(self.lerpHprHPR, posArgs, keyArgs)
  495. elif(len(posArgs) == 2):
  496. return apply(self.lerpHprVBase3, posArgs, keyArgs)
  497. else:
  498. # bad args
  499. raise Exception("Error: NodePath.lerpHpr: bad number of args")
  500. def lerpHprHPR(self, h, p, r, time, other=None,
  501. blendType="noBlend", auto=None, task=None, shortest=1):
  502. """lerpHprHPR(self, float, float, float, float, string="noBlend",
  503. string=none, string=none, NodePath=none)
  504. Perform a hpr lerp with three floats as the end point
  505. """
  506. def functorFunc(self = self, h = h, p = p, r = r,
  507. other = other, shortest=shortest):
  508. import HprLerpFunctor
  509. # it's individual hpr components
  510. if (other != None):
  511. # lerp wrt other
  512. startHpr = self.getHpr(other)
  513. functor = HprLerpFunctor.HprLerpFunctor(
  514. self,
  515. startHpr[0], startHpr[1], startHpr[2],
  516. h, p, r, other)
  517. if shortest:
  518. functor.takeShortest()
  519. else:
  520. startHpr = self.getHpr()
  521. functor = HprLerpFunctor.HprLerpFunctor(
  522. self,
  523. startHpr[0], startHpr[1], startHpr[2],
  524. h, p, r)
  525. if shortest:
  526. functor.takeShortest()
  527. return functor
  528. #determine whether to use auto, spawned, or blocking lerp
  529. if (auto != None):
  530. return self.__autoLerp(functorFunc, time, blendType, auto)
  531. elif (task != None):
  532. return self.__lerp(functorFunc, time, blendType, task)
  533. else:
  534. return self.__lerp(functorFunc, time, blendType)
  535. def lerpHprVBase3(self, hpr, time, other=None,
  536. blendType="noBlend", auto=None, task=None, shortest=1):
  537. """lerpHprVBase3(self, VBase3, float, string="noBlend", string=none,
  538. string=none, NodePath=None)
  539. Perform a hpr lerp with a VBase3 as the end point
  540. """
  541. def functorFunc(self = self, hpr = hpr,
  542. other = other, shortest=shortest):
  543. import HprLerpFunctor
  544. # it's a vbase3 hpr
  545. if (other != None):
  546. # lerp wrt other
  547. functor = HprLerpFunctor.HprLerpFunctor(
  548. self, (self.getHpr(other)), hpr, other)
  549. if shortest:
  550. functor.takeShortest()
  551. else:
  552. functor = HprLerpFunctor.HprLerpFunctor(
  553. self, (self.getHpr()), hpr)
  554. if shortest:
  555. functor.takeShortest()
  556. return functor
  557. #determine whether to use auto, spawned, or blocking lerp
  558. if (auto != None):
  559. return self.__autoLerp(functorFunc, time, blendType, auto)
  560. elif (task != None):
  561. return self.__lerp(functorFunc, time, blendType, task)
  562. else:
  563. return self.__lerp(functorFunc, time, blendType)
  564. def lerpPos(self, *posArgs, **keyArgs):
  565. """lerpPos(self, *positionArgs, **keywordArgs)
  566. Determine whether to call lerpPosXYZ or lerpPosPoint3
  567. based on the first argument
  568. """
  569. # check to see if lerping with three
  570. # floats or a Point3
  571. if (len(posArgs) == 4):
  572. return apply(self.lerpPosXYZ, posArgs, keyArgs)
  573. elif(len(posArgs) == 2):
  574. return apply(self.lerpPosPoint3, posArgs, keyArgs)
  575. else:
  576. # bad number off args
  577. raise Exception("Error: NodePath.lerpPos: bad number of args")
  578. def lerpPosXYZ(self, x, y, z, time, other=None,
  579. blendType="noBlend", auto=None, task=None):
  580. """lerpPosXYZ(self, float, float, float, float, string="noBlend",
  581. string=None, NodePath=None)
  582. Perform a pos lerp with three floats as the end point
  583. """
  584. def functorFunc(self = self, x = x, y = y, z = z, other = other):
  585. import PosLerpFunctor
  586. if (other != None):
  587. # lerp wrt other
  588. startPos = self.getPos(other)
  589. functor = PosLerpFunctor.PosLerpFunctor(self,
  590. startPos[0], startPos[1], startPos[2],
  591. x, y, z, other)
  592. else:
  593. startPos = self.getPos()
  594. functor = PosLerpFunctor.PosLerpFunctor(self, startPos[0],
  595. startPos[1], startPos[2], x, y, z)
  596. return functor
  597. #determine whether to use auto, spawned, or blocking lerp
  598. if (auto != None):
  599. return self.__autoLerp(functorFunc, time, blendType, auto)
  600. elif (task != None):
  601. return self.__lerp(functorFunc, time, blendType, task)
  602. else:
  603. return self.__lerp(functorFunc, time, blendType)
  604. def lerpPosPoint3(self, pos, time, other=None,
  605. blendType="noBlend", auto=None, task=None):
  606. """lerpPosPoint3(self, Point3, float, string="noBlend", string=None,
  607. string=None, NodePath=None)
  608. Perform a pos lerp with a Point3 as the end point
  609. """
  610. def functorFunc(self = self, pos = pos, other = other):
  611. import PosLerpFunctor
  612. if (other != None):
  613. #lerp wrt other
  614. functor = PosLerpFunctor.PosLerpFunctor(
  615. self, (self.getPos(other)), pos, other)
  616. else:
  617. functor = PosLerpFunctor.PosLerpFunctor(
  618. self, (self.getPos()), pos)
  619. return functor
  620. #determine whether to use auto, spawned, or blocking lerp
  621. if (auto != None):
  622. return self.__autoLerp(functorFunc, time, blendType, auto)
  623. elif (task != None):
  624. return self.__lerp(functorFunc, time, blendType, task)
  625. else:
  626. return self.__lerp(functorFunc, time, blendType)
  627. def lerpPosHpr(self, *posArgs, **keyArgs):
  628. """lerpPosHpr(self, *positionArgs, **keywordArgs)
  629. Determine whether to call lerpPosHprXYZHPR or lerpHprPoint3VBase3
  630. based on first argument
  631. """
  632. # check to see if lerping with
  633. # six floats or a Point3 and a VBase3
  634. if (len(posArgs) == 7):
  635. return apply(self.lerpPosHprXYZHPR, posArgs, keyArgs)
  636. elif(len(posArgs) == 3):
  637. return apply(self.lerpPosHprPoint3VBase3, posArgs, keyArgs)
  638. else:
  639. # bad number off args
  640. raise Exception("Error: NodePath.lerpPosHpr: bad number of args")
  641. def lerpPosHprPoint3VBase3(self, pos, hpr, time, other=None,
  642. blendType="noBlend", auto=None, task=None, shortest=1):
  643. """lerpPosHprPoint3VBase3(self, Point3, VBase3, string="noBlend",
  644. string=none, string=none, NodePath=None)
  645. """
  646. def functorFunc(self = self, pos = pos, hpr = hpr,
  647. other = other, shortest=shortest):
  648. import PosHprLerpFunctor
  649. if (other != None):
  650. # lerp wrt other
  651. startPos = self.getPos(other)
  652. startHpr = self.getHpr(other)
  653. functor = PosHprLerpFunctor.PosHprLerpFunctor(
  654. self, startPos, pos,
  655. startHpr, hpr, other)
  656. if shortest:
  657. functor.takeShortest()
  658. else:
  659. startPos = self.getPos()
  660. startHpr = self.getHpr()
  661. functor = PosHprLerpFunctor.PosHprLerpFunctor(
  662. self, startPos, pos,
  663. startHpr, hpr)
  664. if shortest:
  665. functor.takeShortest()
  666. return functor
  667. #determine whether to use auto, spawned, or blocking lerp
  668. if (auto != None):
  669. return self.__autoLerp(functorFunc, time, blendType, auto)
  670. elif (task != None):
  671. return self.__lerp(functorFunc, time, blendType, task)
  672. else:
  673. return self.__lerp(functorFunc, time, blendType)
  674. def lerpPosHprXYZHPR(self, x, y, z, h, p, r, time, other=None,
  675. blendType="noBlend", auto=None, task=None, shortest=1):
  676. """lerpPosHpr(self, float, string="noBlend", string=none,
  677. string=none, NodePath=None)
  678. """
  679. def functorFunc(self = self, x = x, y = y, z = z,
  680. h = h, p = p, r = r, other = other, shortest=shortest):
  681. import PosHprLerpFunctor
  682. if (other != None):
  683. # lerp wrt other
  684. startPos = self.getPos(other)
  685. startHpr = self.getHpr(other)
  686. functor = PosHprLerpFunctor.PosHprLerpFunctor(self,
  687. startPos[0], startPos[1],
  688. startPos[2], x, y, z,
  689. startHpr[0], startHpr[1],
  690. startHpr[2], h, p, r,
  691. other)
  692. if shortest:
  693. functor.takeShortest()
  694. else:
  695. startPos = self.getPos()
  696. startHpr = self.getHpr()
  697. functor = PosHprLerpFunctor.PosHprLerpFunctor(self,
  698. startPos[0], startPos[1],
  699. startPos[2], x, y, z,
  700. startHpr[0], startHpr[1],
  701. startHpr[2], h, p, r)
  702. if shortest:
  703. functor.takeShortest()
  704. return functor
  705. #determine whether to use auto, spawned, or blocking lerp
  706. if (auto != None):
  707. return self.__autoLerp(functorFunc, time, blendType, auto)
  708. elif (task != None):
  709. return self.__lerp(functorFunc, time, blendType, task)
  710. else:
  711. return self.__lerp(functorFunc, time, blendType)
  712. def lerpPosHprScale(self, pos, hpr, scale, time, other=None,
  713. blendType="noBlend", auto=None, task=None, shortest=1):
  714. """lerpPosHpr(self, Point3, VBase3, float, float, string="noBlend",
  715. string=none, string=none, NodePath=None)
  716. Only one case, no need for extra args. Call the appropriate lerp
  717. (auto, spawned, or blocking) based on how(if) a task name is given
  718. """
  719. def functorFunc(self = self, pos = pos, hpr = hpr,
  720. scale = scale, other = other, shortest=shortest):
  721. import PosHprScaleLerpFunctor
  722. if (other != None):
  723. # lerp wrt other
  724. startPos = self.getPos(other)
  725. startHpr = self.getHpr(other)
  726. startScale = self.getScale(other)
  727. functor = PosHprScaleLerpFunctor.PosHprScaleLerpFunctor(self,
  728. startPos, pos,
  729. startHpr, hpr,
  730. startScale, scale, other)
  731. if shortest:
  732. functor.takeShortest()
  733. else:
  734. startPos = self.getPos()
  735. startHpr = self.getHpr()
  736. startScale = self.getScale()
  737. functor = PosHprScaleLerpFunctor.PosHprScaleLerpFunctor(self,
  738. startPos, pos,
  739. startHpr, hpr,
  740. startScale, scale)
  741. if shortest:
  742. functor.takeShortest()
  743. return functor
  744. #determine whether to use auto, spawned, or blocking lerp
  745. if (auto != None):
  746. return self.__autoLerp(functorFunc, time, blendType, auto)
  747. elif (task != None):
  748. return self.__lerp(functorFunc, time, blendType, task)
  749. else:
  750. return self.__lerp(functorFunc, time, blendType)
  751. def lerpScale(self, *posArgs, **keyArgs):
  752. """lerpSclae(self, *positionArgs, **keywordArgs)
  753. Determine whether to call lerpScaleXYZ or lerpScaleaseV3
  754. based on the first argument
  755. """
  756. # check to see if lerping with three
  757. # floats or a Point3
  758. if (len(posArgs) == 4):
  759. return apply(self.lerpScaleXYZ, posArgs, keyArgs)
  760. elif(len(posArgs) == 2):
  761. return apply(self.lerpScaleVBase3, posArgs, keyArgs)
  762. else:
  763. # bad number off args
  764. raise Exception("Error: NodePath.lerpScale: bad number of args")
  765. def lerpScaleVBase3(self, scale, time, other=None,
  766. blendType="noBlend", auto=None, task=None):
  767. """lerpPos(self, VBase3, float, string="noBlend", string=none,
  768. string=none, NodePath=None)
  769. """
  770. def functorFunc(self = self, scale = scale, other = other):
  771. import ScaleLerpFunctor
  772. if (other != None):
  773. # lerp wrt other
  774. functor = ScaleLerpFunctor.ScaleLerpFunctor(self,
  775. (self.getScale(other)),
  776. scale, other)
  777. else:
  778. functor = ScaleLerpFunctor.ScaleLerpFunctor(self,
  779. (self.getScale()), scale)
  780. return functor
  781. #determine whether to use auto, spawned, or blocking lerp
  782. if (auto != None):
  783. return self.__autoLerp(functorFunc, time, blendType, auto)
  784. elif (task != None):
  785. return self.__lerp(functorFunc, time, blendType, task)
  786. else:
  787. return self.__lerp(functorFunc, time, blendType)
  788. def lerpScaleXYZ(self, sx, sy, sz, time, other=None,
  789. blendType="noBlend", auto=None, task=None):
  790. """lerpPos(self, float, float, float, float, string="noBlend",
  791. string=none, string=none, NodePath=None)
  792. """
  793. def functorFunc(self = self, sx = sx, sy = sy, sz = sz, other = other):
  794. import ScaleLerpFunctor
  795. if (other != None):
  796. # lerp wrt other
  797. startScale = self.getScale(other)
  798. functor = ScaleLerpFunctor.ScaleLerpFunctor(self,
  799. startScale[0], startScale[1],
  800. startScale[2], sx, sy, sz, other)
  801. else:
  802. startScale = self.getScale()
  803. functor = ScaleLerpFunctor.ScaleLerpFunctor(self,
  804. startScale[0], startScale[1],
  805. startScale[2], sx, sy, sz)
  806. return functor
  807. #determine whether to use auto, spawned, or blocking lerp
  808. if (auto != None):
  809. return self.__autoLerp(functorFunc, time, blendType, auto)
  810. elif (task != None):
  811. return self.__lerp(functorFunc, time, blendType, task)
  812. else:
  813. return self.__lerp(functorFunc, time, blendType)
  814. def place(self):
  815. base.wantTk = 1
  816. base.wantDIRECT = 1
  817. import DirectSession
  818. direct.enable()
  819. import Placer
  820. return Placer.place(self)
  821. def explore(self):
  822. base.wantTk = 1
  823. base.wantDIRECT = 1
  824. import TkGlobal
  825. import SceneGraphExplorer
  826. return SceneGraphExplorer.explore(self)
  827. def rgbPanel(self, cb = None):
  828. base.wantTk = 1
  829. base.wantDIRECT = 1
  830. import TkGlobal
  831. import Slider
  832. return Slider.rgbPanel(self, cb)
  833. def select(self):
  834. base.wantTk = 1
  835. base.wantDIRECT = 1
  836. import DirectSession
  837. direct.select(self)
  838. def deselect(self):
  839. base.wantTk = 1
  840. base.wantDIRECT = 1
  841. import DirectSession
  842. direct.deselect(self)
  843. def setAlphaScale(self, alpha):
  844. self.setColorScale(1, 1, 1, alpha)
  845. def setAllColorScale(self, color):
  846. self.setColorScale(color, color, color, 1)
  847. def showCS(self, mask = None):
  848. """showCS(self, mask)
  849. Shows the collision solids at or below this node. If mask is
  850. not None, it is a BitMask32 object (e.g. WallBitmask,
  851. CameraBitmask) that indicates which particular collision
  852. solids should be made visible; otherwise, all of them will be.
  853. """
  854. npc = self.findAllMatches('**/+CollisionNode')
  855. for p in range(0, npc.getNumPaths()):
  856. np = npc[p]
  857. if (mask == None or (np.node().getIntoCollideMask() & mask).getWord()):
  858. np.show()
  859. def hideCS(self, mask = None):
  860. """hideCS(self, mask)
  861. Hides the collision solids at or below this node. If mask is
  862. not None, it is a BitMask32 object (e.g. WallBitmask,
  863. CameraBitmask) that indicates which particular collision
  864. solids should be hidden; otherwise, all of them will be.
  865. """
  866. npc = self.findAllMatches('**/+CollisionNode')
  867. for p in range(0, npc.getNumPaths()):
  868. np = npc[p]
  869. if (mask == None or (np.node().getIntoCollideMask() & mask).getWord()):
  870. np.hide()
  871. def posInterval(self, *args, **kw):
  872. import LerpInterval
  873. return LerpInterval.LerpPosInterval(self, *args, **kw)
  874. def hprInterval(self, *args, **kw):
  875. import LerpInterval
  876. return LerpInterval.LerpHprInterval(self, *args, **kw)
  877. def scaleInterval(self, *args, **kw):
  878. import LerpInterval
  879. return LerpInterval.LerpScaleInterval(self, *args, **kw)
  880. def posHprInterval(self, *args, **kw):
  881. import LerpInterval
  882. return LerpInterval.LerpPosHprInterval(self, *args, **kw)
  883. def hprScaleInterval(self, *args, **kw):
  884. import LerpInterval
  885. return LerpInterval.LerpHprScaleInterval(self, *args, **kw)
  886. def posHprScaleInterval(self, *args, **kw):
  887. import LerpInterval
  888. return LerpInterval.LerpPosHprScaleInterval(self, *args, **kw)
  889. def colorInterval(self, *args, **kw):
  890. import LerpInterval
  891. return LerpInterval.LerpColorInterval(self, *args, **kw)
  892. def colorScaleInterval(self, *args, **kw):
  893. import LerpInterval
  894. return LerpInterval.LerpColorScaleInterval(self, *args, **kw)