NodePath_extensions.py 60 KB

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