NodePath_extensions.py 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  1. from extension_native_helpers import *
  2. Dtool_PreloadDLL("libpanda")
  3. from libpanda import *
  4. ####################################################################
  5. #Dtool_funcToMethod(func, class)
  6. #del func
  7. #####################################################################
  8. """
  9. NodePath-extensions module: contains methods to extend functionality
  10. of the NodePath class
  11. """
  12. ####################################################################
  13. def id(self):
  14. """Returns a unique id identifying the NodePath instance"""
  15. return self.getKey()
  16. Dtool_funcToMethod(id, NodePath)
  17. del id
  18. #####################################################################
  19. ## def __hash__(self): // inside c code
  20. ## return self.getKey()
  21. #####################################################################
  22. # For iterating over children
  23. def getChildrenAsList(self):
  24. """Converts a node path's child NodePathCollection into a list"""
  25. print "Warning: NodePath.getChildren() is deprecated. Use getChildren() instead."
  26. return list(self.getChildren())
  27. Dtool_funcToMethod(getChildrenAsList, NodePath)
  28. del getChildrenAsList
  29. #####################################################################
  30. def printChildren(self):
  31. """Prints out the children of the bottom node of a node path"""
  32. for child in self.getChildren():
  33. print child.getName()
  34. Dtool_funcToMethod(printChildren, NodePath)
  35. del printChildren
  36. #####################################################################
  37. def removeChildren(self):
  38. """Deletes the children of the bottom node of a node path"""
  39. self.getChildren().detach()
  40. Dtool_funcToMethod(removeChildren, NodePath)
  41. del removeChildren
  42. #####################################################################
  43. def toggleVis(self):
  44. """Toggles visibility of a nodePath"""
  45. if self.isHidden():
  46. self.show()
  47. return 1
  48. else:
  49. self.hide()
  50. return 0
  51. Dtool_funcToMethod(toggleVis, NodePath)
  52. del toggleVis
  53. #####################################################################
  54. def showSiblings(self):
  55. """Show all the siblings of a node path"""
  56. for sib in self.getParent().getChildren():
  57. if sib.node() != self.node():
  58. sib.show()
  59. Dtool_funcToMethod(showSiblings, NodePath)
  60. del showSiblings
  61. #####################################################################
  62. def hideSiblings(self):
  63. """Hide all the siblings of a node path"""
  64. for sib in self.getParent().getChildren():
  65. if sib.node() != self.node():
  66. sib.hide()
  67. Dtool_funcToMethod(hideSiblings, NodePath)
  68. del hideSiblings
  69. #####################################################################
  70. def showAllDescendants(self):
  71. """Show the node path and all its children"""
  72. self.show()
  73. for child in self.getChildren():
  74. child.showAllDescendants()
  75. Dtool_funcToMethod(showAllDescendants, NodePath)
  76. del showAllDescendants
  77. #####################################################################
  78. def isolate(self):
  79. """Show the node path and hide its siblings"""
  80. self.showAllDescendants()
  81. self.hideSiblings()
  82. Dtool_funcToMethod(isolate, NodePath)
  83. del isolate
  84. #####################################################################
  85. def remove(self):
  86. """Remove a node path from the scene graph"""
  87. # Send message in case anyone needs to do something
  88. # before node is deleted
  89. messenger.send('preRemoveNodePath', [self])
  90. # Remove nodePath
  91. self.removeNode()
  92. Dtool_funcToMethod(remove, NodePath)
  93. del remove
  94. #####################################################################
  95. def lsNames(self):
  96. """Walk down a tree and print out the path"""
  97. if self.isEmpty():
  98. print "(empty)"
  99. else:
  100. type = self.node().getType().getName()
  101. name = self.getName()
  102. print type + " " + name
  103. self.lsNamesRecurse()
  104. Dtool_funcToMethod(lsNames, NodePath)
  105. del lsNames
  106. #####################################################################
  107. def lsNamesRecurse(self, indentString=' '):
  108. """Walk down a tree and print out the path"""
  109. for nodePath in self.getChildren():
  110. type = nodePath.node().getType().getName()
  111. name = nodePath.getName()
  112. print indentString + type + " " + name
  113. nodePath.lsNamesRecurse(indentString + " ")
  114. Dtool_funcToMethod(lsNamesRecurse, NodePath)
  115. del lsNamesRecurse
  116. #####################################################################
  117. def reverseLsNames(self):
  118. """Walk up a tree and print out the path to the root"""
  119. ancestry = self.getAncestry()
  120. indentString = ""
  121. for nodePath in ancestry:
  122. type = nodePath.node().getType().getName()
  123. name = nodePath.getName()
  124. print indentString + type + " " + name
  125. indentString = indentString + " "
  126. Dtool_funcToMethod(reverseLsNames, NodePath)
  127. del reverseLsNames
  128. #####################################################################
  129. def getAncestry(self):
  130. """Get a list of a node path's ancestors"""
  131. print "NodePath.getAncestry() is deprecated. Use getAncestors() instead."""
  132. ancestors = list(self.getAncestors())
  133. ancestors.reverse()
  134. return ancestors
  135. Dtool_funcToMethod(getAncestry, NodePath)
  136. del getAncestry
  137. #####################################################################
  138. def getTightBounds(self):
  139. from pandac.PandaModules import Point3
  140. v1 = Point3.Point3(0)
  141. v2 = Point3.Point3(0)
  142. self.calcTightBounds(v1, v2)
  143. return v1, v2
  144. Dtool_funcToMethod(getTightBounds, NodePath)
  145. del getTightBounds
  146. #####################################################################
  147. def pPrintString(self, other = None):
  148. """
  149. pretty print
  150. """
  151. if __debug__:
  152. # Normally I would have put the if __debug__ around
  153. # the entire funciton, the that doesn't seem to work
  154. # with -extensions. Maybe someone will look into
  155. # this further.
  156. if other:
  157. pos = self.getPos(other)
  158. hpr = self.getHpr(other)
  159. scale = self.getScale(other)
  160. shear = self.getShear(other)
  161. otherString = " 'other': %s,\n" % (other.getName(),)
  162. else:
  163. pos = self.getPos()
  164. hpr = self.getHpr()
  165. scale = self.getScale()
  166. shear = self.getShear()
  167. otherString = '\n'
  168. return (
  169. "%s = {"%(self.getName()) +
  170. otherString +
  171. " 'Pos': (%s),\n" % pos.pPrintValues() +
  172. " 'Hpr': (%s),\n" % hpr.pPrintValues() +
  173. " 'Scale': (%s),\n" % scale.pPrintValues() +
  174. " 'Shear': (%s),\n" % shear.pPrintValues() +
  175. "}")
  176. Dtool_funcToMethod(pPrintString, NodePath)
  177. del pPrintString
  178. #####################################################################
  179. def printPos(self, other = None, sd = 2):
  180. """ Pretty print a node path's pos """
  181. formatString = '%0.' + '%d' % sd + 'f'
  182. if other:
  183. pos = self.getPos(other)
  184. otherString = other.getName() + ', '
  185. else:
  186. pos = self.getPos()
  187. otherString = ''
  188. print (self.getName() + '.setPos(' + otherString +
  189. formatString % pos[0] + ', ' +
  190. formatString % pos[1] + ', ' +
  191. formatString % pos[2] +
  192. ')\n')
  193. Dtool_funcToMethod(printPos, NodePath)
  194. del printPos
  195. #####################################################################
  196. def printHpr(self, other = None, sd = 2):
  197. """ Pretty print a node path's hpr """
  198. formatString = '%0.' + '%d' % sd + 'f'
  199. if other:
  200. hpr = self.getHpr(other)
  201. otherString = other.getName() + ', '
  202. else:
  203. hpr = self.getHpr()
  204. otherString = ''
  205. print (self.getName() + '.setHpr(' + otherString +
  206. formatString % hpr[0] + ', ' +
  207. formatString % hpr[1] + ', ' +
  208. formatString % hpr[2] +
  209. ')\n')
  210. Dtool_funcToMethod(printHpr, NodePath)
  211. del printHpr
  212. #####################################################################
  213. def printScale(self, other = None, sd = 2):
  214. """ Pretty print a node path's scale """
  215. formatString = '%0.' + '%d' % sd + 'f'
  216. if other:
  217. scale = self.getScale(other)
  218. otherString = other.getName() + ', '
  219. else:
  220. scale = self.getScale()
  221. otherString = ''
  222. print (self.getName() + '.setScale(' + otherString +
  223. formatString % scale[0] + ', ' +
  224. formatString % scale[1] + ', ' +
  225. formatString % scale[2] +
  226. ')\n')
  227. Dtool_funcToMethod(printScale, NodePath)
  228. del printScale
  229. #####################################################################
  230. def printPosHpr(self, other = None, sd = 2):
  231. """ Pretty print a node path's pos and, hpr """
  232. formatString = '%0.' + '%d' % sd + 'f'
  233. if other:
  234. pos = self.getPos(other)
  235. hpr = self.getHpr(other)
  236. otherString = other.getName() + ', '
  237. else:
  238. pos = self.getPos()
  239. hpr = self.getHpr()
  240. otherString = ''
  241. print (self.getName() + '.setPosHpr(' + otherString +
  242. formatString % pos[0] + ', ' +
  243. formatString % pos[1] + ', ' +
  244. formatString % pos[2] + ', ' +
  245. formatString % hpr[0] + ', ' +
  246. formatString % hpr[1] + ', ' +
  247. formatString % hpr[2] +
  248. ')\n')
  249. Dtool_funcToMethod(printPosHpr, NodePath)
  250. del printPosHpr
  251. #####################################################################
  252. def printPosHprScale(self, other = None, sd = 2):
  253. """ Pretty print a node path's pos, hpr, and scale """
  254. formatString = '%0.' + '%d' % sd + 'f'
  255. if other:
  256. pos = self.getPos(other)
  257. hpr = self.getHpr(other)
  258. scale = self.getScale(other)
  259. otherString = other.getName() + ', '
  260. else:
  261. pos = self.getPos()
  262. hpr = self.getHpr()
  263. scale = self.getScale()
  264. otherString = ''
  265. print (self.getName() + '.setPosHprScale(' + otherString +
  266. formatString % pos[0] + ', ' +
  267. formatString % pos[1] + ', ' +
  268. formatString % pos[2] + ', ' +
  269. formatString % hpr[0] + ', ' +
  270. formatString % hpr[1] + ', ' +
  271. formatString % hpr[2] + ', ' +
  272. formatString % scale[0] + ', ' +
  273. formatString % scale[1] + ', ' +
  274. formatString % scale[2] +
  275. ')\n')
  276. Dtool_funcToMethod(printPosHprScale, NodePath)
  277. del printPosHprScale
  278. #####################################################################
  279. def printTransform(self, other = None, sd = 2, fRecursive = 0):
  280. from pandac.PandaModules import Vec3
  281. fmtStr = '%%0.%df' % sd
  282. name = self.getName()
  283. if other == None:
  284. transform = self.getTransform()
  285. else:
  286. transform = self.getTransform(other)
  287. if transform.hasPos():
  288. pos = transform.getPos()
  289. if not pos.almostEqual(Vec3(0)):
  290. outputString = '%s.setPos(%s, %s, %s)' % (name, fmtStr, fmtStr, fmtStr)
  291. print outputString % (pos[0], pos[1], pos[2])
  292. if transform.hasHpr():
  293. hpr = transform.getHpr()
  294. if not hpr.almostEqual(Vec3(0)):
  295. outputString = '%s.setHpr(%s, %s, %s)' % (name, fmtStr, fmtStr, fmtStr)
  296. print outputString % (hpr[0], hpr[1], hpr[2])
  297. if transform.hasScale():
  298. if transform.hasUniformScale():
  299. scale = transform.getUniformScale()
  300. if scale != 1.0:
  301. outputString = '%s.setScale(%s)' % (name, fmtStr)
  302. print outputString % scale
  303. else:
  304. scale = transform.getScale()
  305. if not scale.almostEqual(Vec3(1)):
  306. outputString = '%s.setScale(%s, %s, %s)' % (name, fmtStr, fmtStr, fmtStr)
  307. print outputString % (scale[0], scale[1], scale[2])
  308. if fRecursive:
  309. for child in self.getChildren():
  310. child.printTransform(other, sd, fRecursive)
  311. Dtool_funcToMethod(printTransform, NodePath)
  312. del printTransform
  313. #####################################################################
  314. def iPos(self, other = None):
  315. """ Set node path's pos to 0, 0, 0 """
  316. if other:
  317. self.setPos(other, 0, 0, 0)
  318. else:
  319. self.setPos(0, 0, 0)
  320. Dtool_funcToMethod(iPos, NodePath)
  321. del iPos
  322. #####################################################################
  323. def iHpr(self, other = None):
  324. """ Set node path's hpr to 0, 0, 0 """
  325. if other:
  326. self.setHpr(other, 0, 0, 0)
  327. else:
  328. self.setHpr(0, 0, 0)
  329. Dtool_funcToMethod(iHpr, NodePath)
  330. del iHpr
  331. #####################################################################
  332. def iScale(self, other = None):
  333. """ SEt node path's scale to 1, 1, 1 """
  334. if other:
  335. self.setScale(other, 1, 1, 1)
  336. else:
  337. self.setScale(1, 1, 1)
  338. Dtool_funcToMethod(iScale, NodePath)
  339. del iScale
  340. #####################################################################
  341. def iPosHpr(self, other = None):
  342. """ Set node path's pos and hpr to 0, 0, 0 """
  343. if other:
  344. self.setPosHpr(other, 0, 0, 0, 0, 0, 0)
  345. else:
  346. self.setPosHpr(0, 0, 0, 0, 0, 0)
  347. Dtool_funcToMethod(iPosHpr, NodePath)
  348. del iPosHpr
  349. #####################################################################
  350. def iPosHprScale(self, other = None):
  351. """ Set node path's pos and hpr to 0, 0, 0 and scale to 1, 1, 1 """
  352. if other:
  353. self.setPosHprScale(other, 0, 0, 0, 0, 0, 0, 1, 1, 1)
  354. else:
  355. self.setPosHprScale(0, 0, 0, 0, 0, 0, 1, 1, 1)
  356. # private methods
  357. Dtool_funcToMethod(iPosHprScale, NodePath)
  358. del iPosHprScale
  359. #####################################################################
  360. def __lerp(self, functorFunc, duration, blendType, taskName=None):
  361. """
  362. __lerp(self, functorFunc, float, string, string)
  363. Basic lerp functionality used by other lerps.
  364. Fire off a lerp. Make it a task if taskName given.
  365. """
  366. # functorFunc is a function which can be called to create a functor.
  367. # functor creation is defered so initial state (sampled in functorFunc)
  368. # will be appropriate for the time the lerp is spawned
  369. from direct.task import Task
  370. from direct.showbase import LerpBlendHelpers
  371. from direct.task.TaskManagerGlobal import taskMgr
  372. # upon death remove the functorFunc
  373. def lerpUponDeath(task):
  374. # Try to break circular references
  375. try:
  376. del task.functorFunc
  377. except:
  378. pass
  379. try:
  380. del task.lerp
  381. except:
  382. pass
  383. # make the task function
  384. def lerpTaskFunc(task):
  385. from pandac.PandaModules import Lerp
  386. from pandac.PandaModules import ClockObject
  387. from direct.task.Task import Task, cont, done
  388. if task.init == 1:
  389. # make the lerp
  390. functor = task.functorFunc()
  391. task.lerp = Lerp(functor, task.duration, task.blendType)
  392. task.init = 0
  393. dt = globalClock.getDt()
  394. task.lerp.setStepSize(dt)
  395. task.lerp.step()
  396. if (task.lerp.isDone()):
  397. # Reset the init flag, in case the task gets re-used
  398. task.init = 1
  399. return(done)
  400. else:
  401. return(cont)
  402. # make the lerp task
  403. lerpTask = Task.Task(lerpTaskFunc)
  404. lerpTask.init = 1
  405. lerpTask.functorFunc = functorFunc
  406. lerpTask.duration = duration
  407. lerpTask.blendType = LerpBlendHelpers.getBlend(blendType)
  408. lerpTask.setUponDeath(lerpUponDeath)
  409. if (taskName == None):
  410. # don't spawn a task, return one instead
  411. return lerpTask
  412. else:
  413. # spawn the lerp task
  414. taskMgr.add(lerpTask, taskName)
  415. return lerpTask
  416. Dtool_funcToMethod(__lerp, NodePath)
  417. del __lerp
  418. #####################################################################
  419. def __autoLerp(self, functorFunc, time, blendType, taskName):
  420. """_autoLerp(self, functor, float, string, string)
  421. This lerp uses C++ to handle the stepping. Bonus is
  422. its more efficient, trade-off is there is less control"""
  423. from pandac.PandaModules import AutonomousLerp
  424. from direct.showbase import LerpBlendHelpers
  425. # make a lerp that lives in C++ land
  426. functor = functorFunc()
  427. lerp = AutonomousLerp.AutonomousLerp(functor, time,
  428. LerpBlendHelpers.getBlend(blendType),
  429. base.eventHandler)
  430. lerp.start()
  431. return lerp
  432. Dtool_funcToMethod(__autoLerp, NodePath)
  433. del __autoLerp
  434. #####################################################################
  435. # user callable lerp methods
  436. def lerpColor(self, *posArgs, **keyArgs):
  437. """lerpColor(self, *positionArgs, **keywordArgs)
  438. determine which lerpColor* to call based on arguments
  439. """
  440. if (len(posArgs) == 2):
  441. return apply(self.lerpColorVBase4, posArgs, keyArgs)
  442. elif (len(posArgs) == 3):
  443. return apply(self.lerpColorVBase4VBase4, posArgs, keyArgs)
  444. elif (len(posArgs) == 5):
  445. return apply(self.lerpColorRGBA, posArgs, keyArgs)
  446. elif (len(posArgs) == 9):
  447. return apply(self.lerpColorRGBARGBA, posArgs, keyArgs)
  448. else:
  449. # bad args
  450. raise Exception("Error: NodePath.lerpColor: bad number of args")
  451. Dtool_funcToMethod(lerpColor, NodePath)
  452. del lerpColor
  453. #####################################################################
  454. def lerpColorRGBA(self, r, g, b, a, time,
  455. blendType="noBlend", auto=None, task=None):
  456. """lerpColorRGBA(self, float, float, float, float, float,
  457. string="noBlend", string=none, string=none)
  458. """
  459. def functorFunc(self = self, r = r, g = g, b = b, a = a):
  460. from pandac.PandaModules import ColorLerpFunctor
  461. # just end rgba values, use current color rgba values for start
  462. startColor = self.getColor()
  463. functor = ColorLerpFunctor.ColorLerpFunctor(
  464. self,
  465. startColor[0], startColor[1],
  466. startColor[2], startColor[3],
  467. r, g, b, a)
  468. return functor
  469. #determine whether to use auto, spawned, or blocking lerp
  470. if (auto != None):
  471. return self.__autoLerp(functorFunc, time, blendType, auto)
  472. elif (task != None):
  473. return self.__lerp(functorFunc, time, blendType, task)
  474. else:
  475. return self.__lerp(functorFunc, time, blendType)
  476. Dtool_funcToMethod(lerpColorRGBA, NodePath)
  477. del lerpColorRGBA
  478. #####################################################################
  479. def lerpColorRGBARGBA(self, sr, sg, sb, sa, er, eg, eb, ea, time,
  480. blendType="noBlend", auto=None, task=None):
  481. """lerpColorRGBARGBA(self, float, float, float, float, float,
  482. float, float, float, float, string="noBlend", string=none, string=none)
  483. """
  484. def functorFunc(self = self, sr = sr, sg = sg, sb = sb, sa = sa,
  485. er = er, eg = eg, eb = eb, ea = ea):
  486. from pandac.PandaModules import ColorLerpFunctor
  487. # start and end rgba values
  488. functor = ColorLerpFunctor.ColorLerpFunctor(self, sr, sg, sb, sa,
  489. er, eg, eb, ea)
  490. return functor
  491. #determine whether to use auto, spawned, or blocking lerp
  492. if (auto != None):
  493. return self.__autoLerp(functorFunc, time, blendType, auto)
  494. elif (task != None):
  495. return self.__lerp(functorFunc, time, blendType, task)
  496. else:
  497. return self.__lerp(functorFunc, time, blendType)
  498. Dtool_funcToMethod(lerpColorRGBARGBA, NodePath)
  499. del lerpColorRGBARGBA
  500. #####################################################################
  501. def lerpColorVBase4(self, endColor, time,
  502. blendType="noBlend", auto=None, task=None):
  503. """lerpColorVBase4(self, VBase4, float, string="noBlend", string=none,
  504. string=none)
  505. """
  506. def functorFunc(self = self, endColor = endColor):
  507. from pandac.PandaModules import ColorLerpFunctor
  508. # just end vec4, use current color for start
  509. startColor = self.getColor()
  510. functor = ColorLerpFunctor.ColorLerpFunctor(
  511. self, startColor, endColor)
  512. return functor
  513. #determine whether to use auto, spawned, or blocking lerp
  514. if (auto != None):
  515. return self.__autoLerp(functorFunc, time, blendType, auto)
  516. elif (task != None):
  517. return self.__lerp(functorFunc, time, blendType, task)
  518. else:
  519. return self.__lerp(functorFunc, time, blendType)
  520. Dtool_funcToMethod(lerpColorVBase4, NodePath)
  521. del lerpColorVBase4
  522. #####################################################################
  523. def lerpColorVBase4VBase4(self, startColor, endColor, time,
  524. blendType="noBlend", auto=None, task=None):
  525. """lerpColorVBase4VBase4(self, VBase4, VBase4, float, string="noBlend",
  526. string=none, string=none)
  527. """
  528. def functorFunc(self = self, startColor = startColor,
  529. endColor = endColor):
  530. from pandac.PandaModules import ColorLerpFunctor
  531. # start color and end vec
  532. functor = ColorLerpFunctor.ColorLerpFunctor(
  533. self, startColor, endColor)
  534. return functor
  535. #determine whether to use auto, spawned, or blocking lerp
  536. if (auto != None):
  537. return self.__autoLerp(functorFunc, time, blendType, auto)
  538. elif (task != None):
  539. return self.__lerp(functorFunc, time, blendType, task)
  540. else:
  541. return self.__lerp(functorFunc, time, blendType)
  542. Dtool_funcToMethod(lerpColorVBase4VBase4, NodePath)
  543. del lerpColorVBase4VBase4
  544. #####################################################################
  545. # user callable lerp methods
  546. def lerpColorScale(self, *posArgs, **keyArgs):
  547. """lerpColorScale(self, *positionArgs, **keywordArgs)
  548. determine which lerpColorScale* to call based on arguments
  549. """
  550. if (len(posArgs) == 2):
  551. return apply(self.lerpColorScaleVBase4, posArgs, keyArgs)
  552. elif (len(posArgs) == 3):
  553. return apply(self.lerpColorScaleVBase4VBase4, posArgs, keyArgs)
  554. elif (len(posArgs) == 5):
  555. return apply(self.lerpColorScaleRGBA, posArgs, keyArgs)
  556. elif (len(posArgs) == 9):
  557. return apply(self.lerpColorScaleRGBARGBA, posArgs, keyArgs)
  558. else:
  559. # bad args
  560. raise Exception("Error: NodePath.lerpColorScale: bad number of args")
  561. Dtool_funcToMethod(lerpColorScale, NodePath)
  562. del lerpColorScale
  563. #####################################################################
  564. def lerpColorScaleRGBA(self, r, g, b, a, time,
  565. blendType="noBlend", auto=None, task=None):
  566. """lerpColorScaleRGBA(self, float, float, float, float, float,
  567. string="noBlend", string=none, string=none)
  568. """
  569. def functorFunc(self = self, r = r, g = g, b = b, a = a):
  570. from pandac.PandaModules import ColorScaleLerpFunctor
  571. # just end rgba values, use current color rgba values for start
  572. startColor = self.getColor()
  573. functor = ColorScaleLerpFunctor.ColorScaleLerpFunctor(
  574. self,
  575. startColor[0], startColor[1],
  576. startColor[2], startColor[3],
  577. r, g, b, a)
  578. return functor
  579. #determine whether to use auto, spawned, or blocking lerp
  580. if (auto != None):
  581. return self.__autoLerp(functorFunc, time, blendType, auto)
  582. elif (task != None):
  583. return self.__lerp(functorFunc, time, blendType, task)
  584. else:
  585. return self.__lerp(functorFunc, time, blendType)
  586. Dtool_funcToMethod(lerpColorScaleRGBA, NodePath)
  587. del lerpColorScaleRGBA
  588. #####################################################################
  589. def lerpColorScaleRGBARGBA(self, sr, sg, sb, sa, er, eg, eb, ea, time,
  590. blendType="noBlend", auto=None, task=None):
  591. """lerpColorScaleRGBARGBA(self, float, float, float, float, float,
  592. float, float, float, float, string="noBlend", string=none, string=none)
  593. """
  594. def functorFunc(self = self, sr = sr, sg = sg, sb = sb, sa = sa,
  595. er = er, eg = eg, eb = eb, ea = ea):
  596. from pandac.PandaModules import ColorScaleLerpFunctor
  597. # start and end rgba values
  598. functor = ColorScaleLerpFunctor.ColorScaleLerpFunctor(self, sr, sg, sb, sa,
  599. er, eg, eb, ea)
  600. return functor
  601. #determine whether to use auto, spawned, or blocking lerp
  602. if (auto != None):
  603. return self.__autoLerp(functorFunc, time, blendType, auto)
  604. elif (task != None):
  605. return self.__lerp(functorFunc, time, blendType, task)
  606. else:
  607. return self.__lerp(functorFunc, time, blendType)
  608. Dtool_funcToMethod(lerpColorScaleRGBARGBA, NodePath)
  609. del lerpColorScaleRGBARGBA
  610. #####################################################################
  611. def lerpColorScaleVBase4(self, endColor, time,
  612. blendType="noBlend", auto=None, task=None):
  613. """lerpColorScaleVBase4(self, VBase4, float, string="noBlend", string=none,
  614. string=none)
  615. """
  616. def functorFunc(self = self, endColor = endColor):
  617. from pandac.PandaModules import ColorScaleLerpFunctor
  618. # just end vec4, use current color for start
  619. startColor = self.getColor()
  620. functor = ColorScaleLerpFunctor.ColorScaleLerpFunctor(
  621. self, startColor, endColor)
  622. return functor
  623. #determine whether to use auto, spawned, or blocking lerp
  624. if (auto != None):
  625. return self.__autoLerp(functorFunc, time, blendType, auto)
  626. elif (task != None):
  627. return self.__lerp(functorFunc, time, blendType, task)
  628. else:
  629. return self.__lerp(functorFunc, time, blendType)
  630. Dtool_funcToMethod(lerpColorScaleVBase4, NodePath)
  631. del lerpColorScaleVBase4
  632. #####################################################################
  633. def lerpColorScaleVBase4VBase4(self, startColor, endColor, time,
  634. blendType="noBlend", auto=None, task=None):
  635. """lerpColorScaleVBase4VBase4(self, VBase4, VBase4, float, string="noBlend",
  636. string=none, string=none)
  637. """
  638. def functorFunc(self = self, startColor = startColor,
  639. endColor = endColor):
  640. from pandac.PandaModules import ColorScaleLerpFunctor
  641. # start color and end vec
  642. functor = ColorScaleLerpFunctor.ColorScaleLerpFunctor(
  643. self, startColor, endColor)
  644. return functor
  645. #determine whether to use auto, spawned, or blocking lerp
  646. if (auto != None):
  647. return self.__autoLerp(functorFunc, time, blendType, auto)
  648. elif (task != None):
  649. return self.__lerp(functorFunc, time, blendType, task)
  650. else:
  651. return self.__lerp(functorFunc, time, blendType)
  652. Dtool_funcToMethod(lerpColorScaleVBase4VBase4, NodePath)
  653. del lerpColorScaleVBase4VBase4
  654. #####################################################################
  655. def lerpHpr(self, *posArgs, **keyArgs):
  656. """lerpHpr(self, *positionArgs, **keywordArgs)
  657. Determine whether to call lerpHprHPR or lerpHprVBase3
  658. based on first argument
  659. """
  660. # check to see if lerping with
  661. # three floats or a VBase3
  662. if (len(posArgs) == 4):
  663. return apply(self.lerpHprHPR, posArgs, keyArgs)
  664. elif(len(posArgs) == 2):
  665. return apply(self.lerpHprVBase3, posArgs, keyArgs)
  666. else:
  667. # bad args
  668. raise Exception("Error: NodePath.lerpHpr: bad number of args")
  669. Dtool_funcToMethod(lerpHpr, NodePath)
  670. del lerpHpr
  671. #####################################################################
  672. def lerpHprHPR(self, h, p, r, time, other=None,
  673. blendType="noBlend", auto=None, task=None, shortest=1):
  674. """lerpHprHPR(self, float, float, float, float, string="noBlend",
  675. string=none, string=none, NodePath=none)
  676. Perform a hpr lerp with three floats as the end point
  677. """
  678. def functorFunc(self = self, h = h, p = p, r = r,
  679. other = other, shortest=shortest):
  680. from pandac.PandaModules import HprLerpFunctor
  681. # it's individual hpr components
  682. if (other != None):
  683. # lerp wrt other
  684. startHpr = self.getHpr(other)
  685. functor = HprLerpFunctor.HprLerpFunctor(
  686. self,
  687. startHpr[0], startHpr[1], startHpr[2],
  688. h, p, r, other)
  689. if shortest:
  690. functor.takeShortest()
  691. else:
  692. startHpr = self.getHpr()
  693. functor = HprLerpFunctor.HprLerpFunctor(
  694. self,
  695. startHpr[0], startHpr[1], startHpr[2],
  696. h, p, r)
  697. if shortest:
  698. functor.takeShortest()
  699. return functor
  700. #determine whether to use auto, spawned, or blocking lerp
  701. if (auto != None):
  702. return self.__autoLerp(functorFunc, time, blendType, auto)
  703. elif (task != None):
  704. return self.__lerp(functorFunc, time, blendType, task)
  705. else:
  706. return self.__lerp(functorFunc, time, blendType)
  707. Dtool_funcToMethod(lerpHprHPR, NodePath)
  708. del lerpHprHPR
  709. #####################################################################
  710. def lerpHprVBase3(self, hpr, time, other=None,
  711. blendType="noBlend", auto=None, task=None, shortest=1):
  712. """lerpHprVBase3(self, VBase3, float, string="noBlend", string=none,
  713. string=none, NodePath=None)
  714. Perform a hpr lerp with a VBase3 as the end point
  715. """
  716. def functorFunc(self = self, hpr = hpr,
  717. other = other, shortest=shortest):
  718. from pandac.PandaModules import HprLerpFunctor
  719. # it's a vbase3 hpr
  720. if (other != None):
  721. # lerp wrt other
  722. functor = HprLerpFunctor.HprLerpFunctor(
  723. self, (self.getHpr(other)), hpr, other)
  724. if shortest:
  725. functor.takeShortest()
  726. else:
  727. functor = HprLerpFunctor.HprLerpFunctor(
  728. self, (self.getHpr()), hpr)
  729. if shortest:
  730. functor.takeShortest()
  731. return functor
  732. #determine whether to use auto, spawned, or blocking lerp
  733. if (auto != None):
  734. return self.__autoLerp(functorFunc, time, blendType, auto)
  735. elif (task != None):
  736. return self.__lerp(functorFunc, time, blendType, task)
  737. else:
  738. return self.__lerp(functorFunc, time, blendType)
  739. Dtool_funcToMethod(lerpHprVBase3, NodePath)
  740. del lerpHprVBase3
  741. #####################################################################
  742. def lerpPos(self, *posArgs, **keyArgs):
  743. """lerpPos(self, *positionArgs, **keywordArgs)
  744. Determine whether to call lerpPosXYZ or lerpPosPoint3
  745. based on the first argument
  746. """
  747. # check to see if lerping with three
  748. # floats or a Point3
  749. if (len(posArgs) == 4):
  750. return apply(self.lerpPosXYZ, posArgs, keyArgs)
  751. elif(len(posArgs) == 2):
  752. return apply(self.lerpPosPoint3, posArgs, keyArgs)
  753. else:
  754. # bad number off args
  755. raise Exception("Error: NodePath.lerpPos: bad number of args")
  756. Dtool_funcToMethod(lerpPos, NodePath)
  757. del lerpPos
  758. #####################################################################
  759. def lerpPosXYZ(self, x, y, z, time, other=None,
  760. blendType="noBlend", auto=None, task=None):
  761. """lerpPosXYZ(self, float, float, float, float, string="noBlend",
  762. string=None, NodePath=None)
  763. Perform a pos lerp with three floats as the end point
  764. """
  765. def functorFunc(self = self, x = x, y = y, z = z, other = other):
  766. from pandac.PandaModules import PosLerpFunctor
  767. if (other != None):
  768. # lerp wrt other
  769. startPos = self.getPos(other)
  770. functor = PosLerpFunctor.PosLerpFunctor(self,
  771. startPos[0], startPos[1], startPos[2],
  772. x, y, z, other)
  773. else:
  774. startPos = self.getPos()
  775. functor = PosLerpFunctor.PosLerpFunctor(self, startPos[0],
  776. startPos[1], startPos[2], x, y, z)
  777. return functor
  778. #determine whether to use auto, spawned, or blocking lerp
  779. if (auto != None):
  780. return self.__autoLerp(functorFunc, time, blendType, auto)
  781. elif (task != None):
  782. return self.__lerp(functorFunc, time, blendType, task)
  783. else:
  784. return self.__lerp(functorFunc, time, blendType)
  785. Dtool_funcToMethod(lerpPosXYZ, NodePath)
  786. del lerpPosXYZ
  787. #####################################################################
  788. def lerpPosPoint3(self, pos, time, other=None,
  789. blendType="noBlend", auto=None, task=None):
  790. """lerpPosPoint3(self, Point3, float, string="noBlend", string=None,
  791. string=None, NodePath=None)
  792. Perform a pos lerp with a Point3 as the end point
  793. """
  794. def functorFunc(self = self, pos = pos, other = other):
  795. from pandac.PandaModules import PosLerpFunctor
  796. if (other != None):
  797. #lerp wrt other
  798. functor = PosLerpFunctor.PosLerpFunctor(
  799. self, (self.getPos(other)), pos, other)
  800. else:
  801. functor = PosLerpFunctor.PosLerpFunctor(
  802. self, (self.getPos()), pos)
  803. return functor
  804. #determine whether to use auto, spawned, or blocking lerp
  805. if (auto != None):
  806. return self.__autoLerp(functorFunc, time, blendType, auto)
  807. elif (task != None):
  808. return self.__lerp(functorFunc, time, blendType, task)
  809. else:
  810. return self.__lerp(functorFunc, time, blendType)
  811. Dtool_funcToMethod(lerpPosPoint3, NodePath)
  812. del lerpPosPoint3
  813. #####################################################################
  814. def lerpPosHpr(self, *posArgs, **keyArgs):
  815. """lerpPosHpr(self, *positionArgs, **keywordArgs)
  816. Determine whether to call lerpPosHprXYZHPR or lerpHprPoint3VBase3
  817. based on first argument
  818. """
  819. # check to see if lerping with
  820. # six floats or a Point3 and a VBase3
  821. if (len(posArgs) == 7):
  822. return apply(self.lerpPosHprXYZHPR, posArgs, keyArgs)
  823. elif(len(posArgs) == 3):
  824. return apply(self.lerpPosHprPoint3VBase3, posArgs, keyArgs)
  825. else:
  826. # bad number off args
  827. raise Exception("Error: NodePath.lerpPosHpr: bad number of args")
  828. Dtool_funcToMethod(lerpPosHpr, NodePath)
  829. del lerpPosHpr
  830. #####################################################################
  831. def lerpPosHprPoint3VBase3(self, pos, hpr, time, other=None,
  832. blendType="noBlend", auto=None, task=None, shortest=1):
  833. """lerpPosHprPoint3VBase3(self, Point3, VBase3, string="noBlend",
  834. string=none, string=none, NodePath=None)
  835. """
  836. def functorFunc(self = self, pos = pos, hpr = hpr,
  837. other = other, shortest=shortest):
  838. from pandac.PandaModules import PosHprLerpFunctor
  839. if (other != None):
  840. # lerp wrt other
  841. startPos = self.getPos(other)
  842. startHpr = self.getHpr(other)
  843. functor = PosHprLerpFunctor.PosHprLerpFunctor(
  844. self, startPos, pos,
  845. startHpr, hpr, other)
  846. if shortest:
  847. functor.takeShortest()
  848. else:
  849. startPos = self.getPos()
  850. startHpr = self.getHpr()
  851. functor = PosHprLerpFunctor.PosHprLerpFunctor(
  852. self, startPos, pos,
  853. startHpr, hpr)
  854. if shortest:
  855. functor.takeShortest()
  856. return functor
  857. #determine whether to use auto, spawned, or blocking lerp
  858. if (auto != None):
  859. return self.__autoLerp(functorFunc, time, blendType, auto)
  860. elif (task != None):
  861. return self.__lerp(functorFunc, time, blendType, task)
  862. else:
  863. return self.__lerp(functorFunc, time, blendType)
  864. Dtool_funcToMethod(lerpPosHprPoint3VBase3, NodePath)
  865. del lerpPosHprPoint3VBase3
  866. #####################################################################
  867. def lerpPosHprXYZHPR(self, x, y, z, h, p, r, time, other=None,
  868. blendType="noBlend", auto=None, task=None, shortest=1):
  869. """lerpPosHpr(self, float, string="noBlend", string=none,
  870. string=none, NodePath=None)
  871. """
  872. def functorFunc(self = self, x = x, y = y, z = z,
  873. h = h, p = p, r = r, other = other, shortest=shortest):
  874. from pandac.PandaModules import PosHprLerpFunctor
  875. if (other != None):
  876. # lerp wrt other
  877. startPos = self.getPos(other)
  878. startHpr = self.getHpr(other)
  879. functor = PosHprLerpFunctor.PosHprLerpFunctor(self,
  880. startPos[0], startPos[1],
  881. startPos[2], x, y, z,
  882. startHpr[0], startHpr[1],
  883. startHpr[2], h, p, r,
  884. other)
  885. if shortest:
  886. functor.takeShortest()
  887. else:
  888. startPos = self.getPos()
  889. startHpr = self.getHpr()
  890. functor = PosHprLerpFunctor.PosHprLerpFunctor(self,
  891. startPos[0], startPos[1],
  892. startPos[2], x, y, z,
  893. startHpr[0], startHpr[1],
  894. startHpr[2], h, p, r)
  895. if shortest:
  896. functor.takeShortest()
  897. return functor
  898. #determine whether to use auto, spawned, or blocking lerp
  899. if (auto != None):
  900. return self.__autoLerp(functorFunc, time, blendType, auto)
  901. elif (task != None):
  902. return self.__lerp(functorFunc, time, blendType, task)
  903. else:
  904. return self.__lerp(functorFunc, time, blendType)
  905. Dtool_funcToMethod(lerpPosHprXYZHPR, NodePath)
  906. del lerpPosHprXYZHPR
  907. #####################################################################
  908. def lerpPosHprScale(self, pos, hpr, scale, time, other=None,
  909. blendType="noBlend", auto=None, task=None, shortest=1):
  910. """lerpPosHpr(self, Point3, VBase3, float, float, string="noBlend",
  911. string=none, string=none, NodePath=None)
  912. Only one case, no need for extra args. Call the appropriate lerp
  913. (auto, spawned, or blocking) based on how(if) a task name is given
  914. """
  915. def functorFunc(self = self, pos = pos, hpr = hpr,
  916. scale = scale, other = other, shortest=shortest):
  917. from pandac.PandaModules import PosHprScaleLerpFunctor
  918. if (other != None):
  919. # lerp wrt other
  920. startPos = self.getPos(other)
  921. startHpr = self.getHpr(other)
  922. startScale = self.getScale(other)
  923. functor = PosHprScaleLerpFunctor.PosHprScaleLerpFunctor(self,
  924. startPos, pos,
  925. startHpr, hpr,
  926. startScale, scale, other)
  927. if shortest:
  928. functor.takeShortest()
  929. else:
  930. startPos = self.getPos()
  931. startHpr = self.getHpr()
  932. startScale = self.getScale()
  933. functor = PosHprScaleLerpFunctor.PosHprScaleLerpFunctor(self,
  934. startPos, pos,
  935. startHpr, hpr,
  936. startScale, scale)
  937. if shortest:
  938. functor.takeShortest()
  939. return functor
  940. #determine whether to use auto, spawned, or blocking lerp
  941. if (auto != None):
  942. return self.__autoLerp(functorFunc, time, blendType, auto)
  943. elif (task != None):
  944. return self.__lerp(functorFunc, time, blendType, task)
  945. else:
  946. return self.__lerp(functorFunc, time, blendType)
  947. Dtool_funcToMethod(lerpPosHprScale, NodePath)
  948. del lerpPosHprScale
  949. #####################################################################
  950. def lerpScale(self, *posArgs, **keyArgs):
  951. """lerpSclae(self, *positionArgs, **keywordArgs)
  952. Determine whether to call lerpScaleXYZ or lerpScaleaseV3
  953. based on the first argument
  954. """
  955. # check to see if lerping with three
  956. # floats or a Point3
  957. if (len(posArgs) == 4):
  958. return apply(self.lerpScaleXYZ, posArgs, keyArgs)
  959. elif(len(posArgs) == 2):
  960. return apply(self.lerpScaleVBase3, posArgs, keyArgs)
  961. else:
  962. # bad number off args
  963. raise Exception("Error: NodePath.lerpScale: bad number of args")
  964. Dtool_funcToMethod(lerpScale, NodePath)
  965. del lerpScale
  966. #####################################################################
  967. def lerpScaleVBase3(self, scale, time, other=None,
  968. blendType="noBlend", auto=None, task=None):
  969. """lerpPos(self, VBase3, float, string="noBlend", string=none,
  970. string=none, NodePath=None)
  971. """
  972. def functorFunc(self = self, scale = scale, other = other):
  973. from pandac.PandaModules import ScaleLerpFunctor
  974. if (other != None):
  975. # lerp wrt other
  976. functor = ScaleLerpFunctor.ScaleLerpFunctor(self,
  977. (self.getScale(other)),
  978. scale, other)
  979. else:
  980. functor = ScaleLerpFunctor.ScaleLerpFunctor(self,
  981. (self.getScale()), scale)
  982. return functor
  983. #determine whether to use auto, spawned, or blocking lerp
  984. if (auto != None):
  985. return self.__autoLerp(functorFunc, time, blendType, auto)
  986. elif (task != None):
  987. return self.__lerp(functorFunc, time, blendType, task)
  988. else:
  989. return self.__lerp(functorFunc, time, blendType)
  990. Dtool_funcToMethod(lerpScaleVBase3, NodePath)
  991. del lerpScaleVBase3
  992. #####################################################################
  993. def lerpScaleXYZ(self, sx, sy, sz, time, other=None,
  994. blendType="noBlend", auto=None, task=None):
  995. """lerpPos(self, float, float, float, float, string="noBlend",
  996. string=none, string=none, NodePath=None)
  997. """
  998. def functorFunc(self = self, sx = sx, sy = sy, sz = sz, other = other):
  999. from pandac.PandaModules import ScaleLerpFunctor
  1000. if (other != None):
  1001. # lerp wrt other
  1002. startScale = self.getScale(other)
  1003. functor = ScaleLerpFunctor.ScaleLerpFunctor(self,
  1004. startScale[0], startScale[1],
  1005. startScale[2], sx, sy, sz, other)
  1006. else:
  1007. startScale = self.getScale()
  1008. functor = ScaleLerpFunctor.ScaleLerpFunctor(self,
  1009. startScale[0], startScale[1],
  1010. startScale[2], sx, sy, sz)
  1011. return functor
  1012. #determine whether to use auto, spawned, or blocking lerp
  1013. if (auto != None):
  1014. return self.__autoLerp(functorFunc, time, blendType, auto)
  1015. elif (task != None):
  1016. return self.__lerp(functorFunc, time, blendType, task)
  1017. else:
  1018. return self.__lerp(functorFunc, time, blendType)
  1019. Dtool_funcToMethod(lerpScaleXYZ, NodePath)
  1020. del lerpScaleXYZ
  1021. #####################################################################
  1022. def place(self):
  1023. base.startDirect(fWantTk = 1)
  1024. from direct.tkpanels import Placer
  1025. return Placer.place(self)
  1026. Dtool_funcToMethod(place, NodePath)
  1027. del place
  1028. #####################################################################
  1029. def explore(self):
  1030. base.startDirect(fWantTk = 1)
  1031. from direct.tkwidgets import SceneGraphExplorer
  1032. return SceneGraphExplorer.explore(self)
  1033. Dtool_funcToMethod(explore, NodePath)
  1034. del explore
  1035. #####################################################################
  1036. def rgbPanel(self, cb = None):
  1037. base.startTk()
  1038. from direct.tkwidgets import Slider
  1039. return Slider.rgbPanel(self, cb)
  1040. Dtool_funcToMethod(rgbPanel, NodePath)
  1041. del rgbPanel
  1042. #####################################################################
  1043. def select(self):
  1044. base.startDirect(fWantTk = 0)
  1045. base.direct.select(self)
  1046. Dtool_funcToMethod(select, NodePath)
  1047. del select
  1048. #####################################################################
  1049. def deselect(self):
  1050. base.startDirect(fWantTk = 0)
  1051. base.direct.deselect(self)
  1052. Dtool_funcToMethod(deselect, NodePath)
  1053. del deselect
  1054. #####################################################################
  1055. def showCS(self, mask = None):
  1056. """
  1057. Shows the collision solids at or below this node. If mask is
  1058. not None, it is a BitMask32 object (e.g. WallBitmask,
  1059. CameraBitmask) that indicates which particular collision
  1060. solids should be made visible; otherwise, all of them will be.
  1061. """
  1062. npc = self.findAllMatches('**/+CollisionNode')
  1063. for p in range(0, npc.getNumPaths()):
  1064. np = npc[p]
  1065. if (mask == None or (np.node().getIntoCollideMask() & mask).getWord()):
  1066. np.show()
  1067. Dtool_funcToMethod(showCS, NodePath)
  1068. del showCS
  1069. #####################################################################
  1070. def hideCS(self, mask = None):
  1071. """
  1072. Hides the collision solids at or below this node. If mask is
  1073. not None, it is a BitMask32 object (e.g. WallBitmask,
  1074. CameraBitmask) that indicates which particular collision
  1075. solids should be hidden; otherwise, all of them will be.
  1076. """
  1077. npc = self.findAllMatches('**/+CollisionNode')
  1078. for p in range(0, npc.getNumPaths()):
  1079. np = npc[p]
  1080. if (mask == None or (np.node().getIntoCollideMask() & mask).getWord()):
  1081. np.hide()
  1082. Dtool_funcToMethod(hideCS, NodePath)
  1083. del hideCS
  1084. #####################################################################
  1085. def posInterval(self, *args, **kw):
  1086. from direct.interval import LerpInterval
  1087. return LerpInterval.LerpPosInterval(self, *args, **kw)
  1088. Dtool_funcToMethod(posInterval, NodePath)
  1089. del posInterval
  1090. #####################################################################
  1091. def hprInterval(self, *args, **kw):
  1092. from direct.interval import LerpInterval
  1093. return LerpInterval.LerpHprInterval(self, *args, **kw)
  1094. Dtool_funcToMethod(hprInterval, NodePath)
  1095. del hprInterval
  1096. #####################################################################
  1097. def quatInterval(self, *args, **kw):
  1098. from direct.interval import LerpInterval
  1099. return LerpInterval.LerpQuatInterval(self, *args, **kw)
  1100. Dtool_funcToMethod(quatInterval, NodePath)
  1101. del quatInterval
  1102. #####################################################################
  1103. def scaleInterval(self, *args, **kw):
  1104. from direct.interval import LerpInterval
  1105. return LerpInterval.LerpScaleInterval(self, *args, **kw)
  1106. Dtool_funcToMethod(scaleInterval, NodePath)
  1107. del scaleInterval
  1108. #####################################################################
  1109. def shearInterval(self, *args, **kw):
  1110. from direct.interval import LerpInterval
  1111. return LerpInterval.LerpShearInterval(self, *args, **kw)
  1112. Dtool_funcToMethod(shearInterval, NodePath)
  1113. del shearInterval
  1114. #####################################################################
  1115. def posHprInterval(self, *args, **kw):
  1116. from direct.interval import LerpInterval
  1117. return LerpInterval.LerpPosHprInterval(self, *args, **kw)
  1118. Dtool_funcToMethod(posHprInterval, NodePath)
  1119. del posHprInterval
  1120. #####################################################################
  1121. def posQuatInterval(self, *args, **kw):
  1122. from direct.interval import LerpInterval
  1123. return LerpInterval.LerpPosQuatInterval(self, *args, **kw)
  1124. Dtool_funcToMethod(posQuatInterval, NodePath)
  1125. del posQuatInterval
  1126. #####################################################################
  1127. def hprScaleInterval(self, *args, **kw):
  1128. from direct.interval import LerpInterval
  1129. return LerpInterval.LerpHprScaleInterval(self, *args, **kw)
  1130. Dtool_funcToMethod(hprScaleInterval, NodePath)
  1131. del hprScaleInterval
  1132. #####################################################################
  1133. def quatScaleInterval(self, *args, **kw):
  1134. from direct.interval import LerpInterval
  1135. return LerpInterval.LerpQuatScaleInterval(self, *args, **kw)
  1136. Dtool_funcToMethod(quatScaleInterval, NodePath)
  1137. del quatScaleInterval
  1138. #####################################################################
  1139. def posHprScaleInterval(self, *args, **kw):
  1140. from direct.interval import LerpInterval
  1141. return LerpInterval.LerpPosHprScaleInterval(self, *args, **kw)
  1142. Dtool_funcToMethod(posHprScaleInterval, NodePath)
  1143. del posHprScaleInterval
  1144. #####################################################################
  1145. def posQuatScaleInterval(self, *args, **kw):
  1146. from direct.interval import LerpInterval
  1147. return LerpInterval.LerpPosQuatScaleInterval(self, *args, **kw)
  1148. Dtool_funcToMethod(posQuatScaleInterval, NodePath)
  1149. del posQuatScaleInterval
  1150. #####################################################################
  1151. def posHprScaleShearInterval(self, *args, **kw):
  1152. from direct.interval import LerpInterval
  1153. return LerpInterval.LerpPosHprScaleShearInterval(self, *args, **kw)
  1154. Dtool_funcToMethod(posHprScaleShearInterval, NodePath)
  1155. del posHprScaleShearInterval
  1156. #####################################################################
  1157. def posQuatScaleShearInterval(self, *args, **kw):
  1158. from direct.interval import LerpInterval
  1159. return LerpInterval.LerpPosQuatScaleShearInterval(self, *args, **kw)
  1160. Dtool_funcToMethod(posQuatScaleShearInterval, NodePath)
  1161. del posQuatScaleShearInterval
  1162. #####################################################################
  1163. def colorInterval(self, *args, **kw):
  1164. from direct.interval import LerpInterval
  1165. return LerpInterval.LerpColorInterval(self, *args, **kw)
  1166. Dtool_funcToMethod(colorInterval, NodePath)
  1167. del colorInterval
  1168. #####################################################################
  1169. def colorScaleInterval(self, *args, **kw):
  1170. from direct.interval import LerpInterval
  1171. return LerpInterval.LerpColorScaleInterval(self, *args, **kw)
  1172. Dtool_funcToMethod(colorScaleInterval, NodePath)
  1173. del colorScaleInterval
  1174. #####################################################################
  1175. def attachCollisionSphere(self, name, cx, cy, cz, r, fromCollide, intoCollide):
  1176. from pandac.PandaModules import CollisionSphere
  1177. from pandac.PandaModules import CollisionNode
  1178. coll = CollisionSphere.CollisionSphere(cx, cy, cz, r)
  1179. collNode = CollisionNode.CollisionNode(name)
  1180. collNode.addSolid(coll)
  1181. collNode.setFromCollideMask(fromCollide)
  1182. collNode.setIntoCollideMask(intoCollide)
  1183. collNodePath = self.attachNewNode(collNode)
  1184. return collNodePath
  1185. Dtool_funcToMethod(attachCollisionSphere, NodePath)
  1186. del attachCollisionSphere
  1187. #####################################################################
  1188. def attachCollisionSegment(self, name, ax, ay, az, bx, by, bz, fromCollide, intoCollide):
  1189. from pandac.PandaModules import CollisionSegment
  1190. from pandac.PandaModules import CollisionNode
  1191. coll = CollisionSegment.CollisionSegment(ax, ay, az, bx, by, bz)
  1192. collNode = CollisionNode.CollisionNode(name)
  1193. collNode.addSolid(coll)
  1194. collNode.setFromCollideMask(fromCollide)
  1195. collNode.setIntoCollideMask(intoCollide)
  1196. collNodePath = self.attachNewNode(collNode)
  1197. return collNodePath
  1198. Dtool_funcToMethod(attachCollisionSegment, NodePath)
  1199. del attachCollisionSegment
  1200. #####################################################################
  1201. def attachCollisionRay(self, name, ox, oy, oz, dx, dy, dz, fromCollide, intoCollide):
  1202. from pandac.PandaModules import CollisionRay
  1203. from pandac.PandaModules import CollisionNode
  1204. coll = CollisionRay.CollisionRay(ox, oy, oz, dx, dy, dz)
  1205. collNode = CollisionNode.CollisionNode(name)
  1206. collNode.addSolid(coll)
  1207. collNode.setFromCollideMask(fromCollide)
  1208. collNode.setIntoCollideMask(intoCollide)
  1209. collNodePath = self.attachNewNode(collNode)
  1210. return collNodePath
  1211. Dtool_funcToMethod(attachCollisionRay, NodePath)
  1212. del attachCollisionRay
  1213. #####################################################################
  1214. def flattenMultitex(self, stateFrom = None, target = None,
  1215. useGeom = 0, allowTexMat = 0, win = None):
  1216. from pandac.PandaModules import MultitexReducer
  1217. mr = MultitexReducer.MultitexReducer()
  1218. if target != None:
  1219. mr.setTarget(target)
  1220. mr.setUseGeom(useGeom)
  1221. mr.setAllowTexMat(allowTexMat)
  1222. if win == None:
  1223. win = base.win
  1224. if stateFrom == None:
  1225. mr.scan(self)
  1226. else:
  1227. mr.scan(self, stateFrom)
  1228. mr.flatten(win)
  1229. Dtool_funcToMethod(flattenMultitex, NodePath)
  1230. del flattenMultitex
  1231. #####################################################################
  1232. def getNumDescendants(self):
  1233. return len(self.findAllMatches('**')) - 1
  1234. Dtool_funcToMethod(getNumDescendants, NodePath)
  1235. del getNumDescendants
  1236. #####################################################################
  1237. def removeNonCollisions(self):
  1238. # remove anything that is not collision-related
  1239. stack = [self]
  1240. while len(stack):
  1241. np = stack.pop()
  1242. # if there are no CollisionNodes under this node, remove it
  1243. if np.find('**/+CollisionNode').isEmpty():
  1244. np.detachNode()
  1245. else:
  1246. stack.extend(np.getChildren())
  1247. Dtool_funcToMethod(removeNonCollisions, NodePath)
  1248. del removeNonCollisions
  1249. #####################################################################
  1250. def subdivideCollisions(self, numSolidsInLeaves):
  1251. """
  1252. expand CollisionNodes out into balanced trees, with a particular number
  1253. of solids in the leaves
  1254. TODO: better splitting logic at each level of the tree wrt spatial separation
  1255. and cost of bounding volume tests vs. cost of collision solid tests
  1256. """
  1257. colNps = self.findAllMatches('**/+CollisionNode')
  1258. for colNp in colNps:
  1259. node = colNp.node()
  1260. numSolids = node.getNumSolids()
  1261. if numSolids <= numSolidsInLeaves:
  1262. # this CollisionNode doesn't need to be split
  1263. continue
  1264. solids = []
  1265. for i in xrange(numSolids):
  1266. solids.append(node.getSolid(i))
  1267. # recursively subdivide the solids into a spatial binary tree
  1268. solidTree = self.r_subdivideCollisions(solids, numSolidsInLeaves)
  1269. root = colNp.getParent().attachNewNode('%s-subDivRoot' % colNp.getName())
  1270. self.r_constructCollisionTree(solidTree, root, colNp.getName())
  1271. colNp.stash()
  1272. def r_subdivideCollisions(self, solids, numSolidsInLeaves):
  1273. # takes a list of solids, returns a list containing some number of lists,
  1274. # with the solids evenly distributed between them (recursively nested until
  1275. # the lists at the leaves contain no more than numSolidsInLeaves)
  1276. # if solids is already small enough, returns solids unchanged
  1277. if len(solids) <= numSolidsInLeaves:
  1278. return solids
  1279. origins = []
  1280. avgX = 0; avgY = 0; avgZ = 0
  1281. minX = None; minY = None; minZ = None
  1282. maxX = None; maxY = None; maxZ = None
  1283. for solid in solids:
  1284. origin = solid.getCollisionOrigin()
  1285. origins.append(origin)
  1286. x = origin.getX(); y = origin.getY(); z = origin.getZ()
  1287. avgX += x; avgY += y; avgZ += z
  1288. if minX is None:
  1289. minX = x; minY = y; minZ = z
  1290. maxX = x; maxY = y; maxZ = z
  1291. else:
  1292. minX = min(x, minX); minY = min(y, minY); minZ = min(z, minZ)
  1293. maxX = max(x, maxX); maxY = max(y, maxY); maxZ = max(z, maxZ)
  1294. avgX /= len(solids); avgY /= len(solids); avgZ /= len(solids)
  1295. extentX = maxX - minX; extentY = maxY - minY; extentZ = maxZ - minZ
  1296. maxExtent = max(max(extentX, extentY), extentZ)
  1297. # sparse octree
  1298. xyzSolids = []
  1299. XyzSolids = []
  1300. xYzSolids = []
  1301. XYzSolids = []
  1302. xyZSolids = []
  1303. XyZSolids = []
  1304. xYZSolids = []
  1305. XYZSolids = []
  1306. midX = avgX
  1307. midY = avgY
  1308. midZ = avgZ
  1309. # throw out axes that are not close to the max axis extent; try and keep
  1310. # the divisions square/spherical
  1311. if extentX < (maxExtent * .75) or extentX > (maxExtent * 1.25):
  1312. midX += maxExtent
  1313. if extentY < (maxExtent * .75) or extentY > (maxExtent * 1.25):
  1314. midY += maxExtent
  1315. if extentZ < (maxExtent * .75) or extentZ > (maxExtent * 1.25):
  1316. midZ += maxExtent
  1317. for i in xrange(len(solids)):
  1318. origin = origins[i]
  1319. x = origin.getX(); y = origin.getY(); z = origin.getZ()
  1320. if x < midX:
  1321. if y < midY:
  1322. if z < midZ:
  1323. xyzSolids.append(solids[i])
  1324. else:
  1325. xyZSolids.append(solids[i])
  1326. else:
  1327. if z < midZ:
  1328. xYzSolids.append(solids[i])
  1329. else:
  1330. xYZSolids.append(solids[i])
  1331. else:
  1332. if y < midY:
  1333. if z < midZ:
  1334. XyzSolids.append(solids[i])
  1335. else:
  1336. XyZSolids.append(solids[i])
  1337. else:
  1338. if z < midZ:
  1339. XYzSolids.append(solids[i])
  1340. else:
  1341. XYZSolids.append(solids[i])
  1342. newSolids = []
  1343. if len(xyzSolids):
  1344. newSolids.append(self.r_subdivideCollisions(xyzSolids, numSolidsInLeaves))
  1345. if len(XyzSolids):
  1346. newSolids.append(self.r_subdivideCollisions(XyzSolids, numSolidsInLeaves))
  1347. if len(xYzSolids):
  1348. newSolids.append(self.r_subdivideCollisions(xYzSolids, numSolidsInLeaves))
  1349. if len(XYzSolids):
  1350. newSolids.append(self.r_subdivideCollisions(XYzSolids, numSolidsInLeaves))
  1351. if len(xyZSolids):
  1352. newSolids.append(self.r_subdivideCollisions(xyZSolids, numSolidsInLeaves))
  1353. if len(XyZSolids):
  1354. newSolids.append(self.r_subdivideCollisions(XyZSolids, numSolidsInLeaves))
  1355. if len(xYZSolids):
  1356. newSolids.append(self.r_subdivideCollisions(xYZSolids, numSolidsInLeaves))
  1357. if len(XYZSolids):
  1358. newSolids.append(self.r_subdivideCollisions(XYZSolids, numSolidsInLeaves))
  1359. #import pdb;pdb.set_trace()
  1360. return newSolids
  1361. def r_constructCollisionTree(self, solidTree, parentNode, colName):
  1362. for item in solidTree:
  1363. if type(item[0]) == type([]):
  1364. newNode = parentNode.attachNewNode('%s-branch' % colName)
  1365. self.r_constructCollisionTree(item, newNode, colName)
  1366. else:
  1367. cn = CollisionNode('%s-leaf' % colName)
  1368. for solid in item:
  1369. cn.addSolid(solid)
  1370. parentNode.attachNewNode(cn)
  1371. Dtool_funcToMethod(subdivideCollisions, NodePath)
  1372. Dtool_funcToMethod(r_subdivideCollisions, NodePath)
  1373. Dtool_funcToMethod(r_constructCollisionTree, NodePath)
  1374. del subdivideCollisions
  1375. del r_subdivideCollisions
  1376. del r_constructCollisionTree