propertyWindow.py 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  1. #################################################################
  2. # propertyWindow.py
  3. # Written by Yi-Hong Lin, [email protected], 2004
  4. #################################################################
  5. from direct.tkwidgets.AppShell import *
  6. from direct.showbase.TkGlobal import *
  7. from seColorEntry import *
  8. from direct.tkwidgets import Floater
  9. from direct.tkwidgets import Dial
  10. from direct.tkwidgets import Slider
  11. from direct.tkwidgets import VectorWidgets
  12. from pandac.PandaModules import *
  13. from Tkinter import *
  14. import Pmw
  15. class propertyWindow(AppShell,Pmw.MegaWidget):
  16. #################################################################
  17. # propertyWindow(AppShell,Pmw.MegaWidget)
  18. # This class will create a widow to show the object property and
  19. # let user can change shoe of them.
  20. #################################################################
  21. appversion = '1.0'
  22. appname = 'Property Window'
  23. frameWidth = 400
  24. frameHeight = 400
  25. padx = 0
  26. pady = 0
  27. usecommandarea = 0
  28. usestatusarea = 0
  29. widgetsDict = {}
  30. def __init__(self, target, type, info, parent = None, nodePath = render, **kw):
  31. self.nodePath = target
  32. self.name = target.getName()
  33. self.type = type
  34. self.info = info
  35. # Initialise superclass
  36. Pmw.MegaWidget.__init__(self, parent)
  37. # Define the megawidget options.
  38. optiondefs = (
  39. ('title', self.appname, None),
  40. )
  41. self.defineoptions(kw, optiondefs)
  42. if parent == None:
  43. self.parent = Toplevel()
  44. AppShell.__init__(self, self.parent)
  45. self.parent.resizable(False,False) ## Disable the ability to resize for this Window.
  46. def appInit(self):
  47. return
  48. def createInterface(self):
  49. # The interior of the toplevel panel
  50. interior = self.interior()
  51. mainFrame = Frame(interior)
  52. name_label = Label(mainFrame, text= self.name,font=('MSSansSerif', 15),
  53. relief = RIDGE, borderwidth=5)
  54. name_label.pack()
  55. outFrame = Frame(mainFrame, relief = RIDGE, borderwidth=3)
  56. self.contentWidge = self.createcomponent(
  57. 'scrolledFrame',
  58. (), None,
  59. Pmw.ScrolledFrame, (outFrame,),
  60. hull_width = 200, hull_height = 300,
  61. usehullsize = 1)
  62. self.contentFrame = self.contentWidge.component('frame')
  63. self.contentWidge.pack(fill = 'both', expand = 1,padx = 3, pady = 5)
  64. outFrame.pack(fill = 'both', expand = 1)
  65. # Creating different interface depands on object's type
  66. if self.type == 'camera':
  67. self.cameraInterface(self.contentFrame)
  68. self.accept('forPorpertyWindow'+self.name, self.trackDataFromSceneCamera)
  69. elif self.type == 'Model':
  70. self.modelInterface(self.contentFrame)
  71. self.accept('forPorpertyWindow'+self.name, self.trackDataFromSceneModel)
  72. elif self.type == 'Actor':
  73. self.modelInterface(self.contentFrame)
  74. self.actorInterface(self.contentFrame)
  75. self.accept('forPorpertyWindow'+self.name, self.trackDataFromSceneActor)
  76. pass
  77. elif self.type == 'Light':
  78. self.lightInterface(self.contentFrame)
  79. self.accept('forPorpertyWindow'+self.name, self.trackDataFromSceneLight)
  80. pass
  81. elif self.type == 'dummy':
  82. self.dummyInterface(self.contentFrame)
  83. self.accept('forPorpertyWindow'+self.name, self.trackDataFromSceneDummy)
  84. pass
  85. elif self.type == 'collisionNode':
  86. self.collisionInterface(self.contentFrame)
  87. self.accept('forPorpertyWindow'+self.name, self.trackDataFromSceneCollision)
  88. pass
  89. elif self.type == 'Special':
  90. # If user try to open the property window for node "SEditor"
  91. # It will show the grid property.
  92. self.gridInterface(self.contentFrame)
  93. self.accept('forPorpertyWindow'+self.name, None)
  94. pass
  95. self.curveFrame = None
  96. #### If nodePath has been binded with any curves
  97. if self.info.has_key('curveList'):
  98. self.createCurveFrame(self.contentFrame)
  99. ## Set all stuff done
  100. mainFrame.pack(fill = 'both', expand = 1)
  101. def createMenuBar(self):
  102. # we don't need menu bar here.
  103. self.menuBar.destroy()
  104. def onDestroy(self, event):
  105. self.ignore('forPorpertyWindow'+self.name)
  106. messenger.send('PW_close', [self.name])
  107. '''
  108. If you have open any thing, please rewrite here!
  109. '''
  110. pass
  111. def createEntryField(self, parent,text, value,
  112. command, initialState, labelWidth = 12,
  113. side = 'left', fill = X, expand = 0,
  114. validate = None,
  115. defaultButton = False, buttonText = 'Default',defaultFunction = None ):
  116. #################################################################
  117. # createEntryField(self, parent,text, value,
  118. # command, initialState, labelWidth = 12,
  119. # side = 'left', fill = X, expand = 0,
  120. # validate = None,
  121. # defaultButton = False, buttonText = 'Default',defaultFunction = None ):
  122. # This function will create a Entry on the frame "parent"
  123. # Also, if user has enabled the "defaultButton," it will create a button right after the entry.
  124. #################################################################
  125. frame = Frame(parent)
  126. widget = Pmw.EntryField(frame, labelpos='w', label_text = text,
  127. value = value, entry_font=('MSSansSerif', 10),label_font=('MSSansSerif', 10),
  128. modifiedcommand=command, validate = validate,
  129. label_width = labelWidth)
  130. widget.configure(entry_state = initialState)
  131. widget.pack(side=LEFT)
  132. self.widgetsDict[text] = widget
  133. if defaultButton and (defaultFunction!=None):
  134. # create a button if they need.
  135. widget = Button(frame, text=buttonText, font=('MSSansSerif', 10), command = defaultFunction)
  136. widget.pack(side=LEFT, padx=3)
  137. self.widgetsDict[text+'-'+'DefaultButton']=widget
  138. frame.pack(side = side, fill = fill, expand = expand,pady=3)
  139. def createPosEntry(self, contentFrame):
  140. #################################################################
  141. # createPosEntry(self, contentFrame)
  142. # This function will create three entries for setting position for the objects.
  143. # the entry type is Floater.
  144. # And, it will set the call back function to setNodePathPosHprScale()
  145. #################################################################
  146. posInterior = Frame(contentFrame)
  147. self.posX = self.createcomponent('posX', (), None,
  148. Floater.Floater, (posInterior,),
  149. text = 'X', relief = FLAT,
  150. value = self.nodePath.getX(),
  151. label_foreground = 'Red',
  152. entry_width = 9)
  153. self.posX['commandData'] = ['x']
  154. self.posX['command'] = self.setNodePathPosHprScale
  155. self.posX.pack(side=LEFT,expand=0,fill=X, padx=1)
  156. self.posY = self.createcomponent('posY', (), None,
  157. Floater.Floater, (posInterior,),
  158. text = 'Y', relief = FLAT,
  159. value = self.nodePath.getY(),
  160. label_foreground = '#00A000',
  161. entry_width = 9)
  162. self.posY['commandData'] = ['y']
  163. self.posY['command'] = self.setNodePathPosHprScale
  164. self.posY.pack(side=LEFT, expand=0,fill=X, padx=1)
  165. self.posZ = self.createcomponent('posZ', (), None,
  166. Floater.Floater, (posInterior,),
  167. text = 'Z', relief = FLAT,
  168. value = self.nodePath.getZ(),
  169. label_foreground = 'Blue',
  170. entry_width = 9)
  171. self.posZ['commandData'] = ['z']
  172. self.posZ['command'] = self.setNodePathPosHprScale
  173. self.posZ.pack(side=LEFT, expand=0,fill=X, padx=1)
  174. posInterior.pack(side=TOP, expand=0,fill=X, padx=3, pady=3)
  175. def createHprEntry(self, contentFrame):
  176. #################################################################
  177. # createHprEntry(self, contentFrame)
  178. # This function will create three entries for setting orientation for the objects.
  179. # the entry type is Floater.
  180. # And, it will set the call back function to setNodePathPosHprScale()
  181. #################################################################
  182. hprInterior = Frame(contentFrame)
  183. self.hprH = self.createcomponent('hprH', (), None,
  184. Dial.AngleDial, (hprInterior,),
  185. style = 'mini',
  186. text = 'H', value = self.nodePath.getH(),
  187. relief = FLAT,
  188. label_foreground = 'blue',
  189. entry_width = 9)
  190. self.hprH['commandData'] = ['h']
  191. self.hprH['command'] = self.setNodePathPosHprScale
  192. self.hprH.pack(side = LEFT, expand=0,fill=X)
  193. self.hprP = self.createcomponent('hprP', (), None,
  194. Dial.AngleDial, (hprInterior,),
  195. style = 'mini',
  196. text = 'P', value = self.nodePath.getP(),
  197. relief = FLAT,
  198. label_foreground = 'red',
  199. entry_width = 9)
  200. self.hprP['commandData'] = ['p']
  201. self.hprP['command'] = self.setNodePathPosHprScale
  202. self.hprP.pack(side = LEFT, expand=0,fill=X)
  203. self.hprR = self.createcomponent('hprR', (), None,
  204. Dial.AngleDial, (hprInterior,),
  205. style = 'mini',
  206. text = 'R', value = self.nodePath.getR(),
  207. relief = FLAT,
  208. label_foreground = '#00A000',
  209. entry_width = 9)
  210. self.hprR['commandData'] = ['r']
  211. self.hprR['command'] = self.setNodePathPosHprScale
  212. self.hprR.pack(side = LEFT, expand=0,fill=X)
  213. hprInterior.pack(side=TOP, expand=0,fill=X, padx=3, pady=3)
  214. def createScaleEntry(self, contentFrame):
  215. #################################################################
  216. # createScaleEntry(self, contentFrame)
  217. # This function will create three entries for setting scale for the objects.
  218. # the entry type is Floater.
  219. # And, it will set the call back function to setNodePathPosHprScale()
  220. #################################################################
  221. scaleInterior = Frame(contentFrame)
  222. self.scale = self.createcomponent('scale', (), None,
  223. Floater.Floater, (scaleInterior,),
  224. text = 'Scale',
  225. relief = FLAT,
  226. min = 0.0001, value = self.nodePath.getScale().getX(),
  227. resetValue = 1.0,
  228. label_foreground = 'Blue')
  229. self.scale['commandData'] = ['s']
  230. self.scale['command'] = self.setNodePathPosHprScale
  231. self.scale.pack(side=LEFT,expand=0,fill=X)
  232. scaleInterior.pack(side=TOP,expand=0,fill=X, padx=3, pady=3)
  233. def createColorEntry(self, contentFrame):
  234. #################################################################
  235. # createColorEntry(self, contentFrame)
  236. # This function will create three entries for setting color for the objects.
  237. # the entry type is Floater.
  238. # And, it will set the call back function to setNodeColorVec()
  239. #################################################################
  240. color = self.nodePath.getColor()
  241. print color
  242. self.nodeColor = VectorWidgets.ColorEntry(
  243. contentFrame, text = 'Node Color', value=[color.getX()*255,
  244. color.getY()*255,
  245. color.getZ()*255,
  246. color.getW()*255])
  247. self.nodeColor['command'] = self.setNodeColorVec
  248. self.nodeColor['resetValue'] = [255,255,255,255]
  249. self.nodeColor.place(anchor=NW,y=235)
  250. self.bind(self.nodeColor, 'Set nodePath color')
  251. self.nodeColor.pack(side=TOP,expand=0,fill=X, padx=3, pady=3)
  252. return
  253. def setNodeColorVec(self, color):
  254. #################################################################
  255. # setNodeColorVec(self, color)
  256. # This function will set the color of the object
  257. #################################################################
  258. self.nodePath.setColor(color[0]/255.0,
  259. color[1]/255.0,
  260. color[2]/255.0,
  261. color[3]/255.0)
  262. return
  263. def setNodePathPosHprScale(self, data, axis):
  264. #################################################################
  265. # setNodePathPosHprScale(self, data, axis)
  266. # This function will set the postion, orientation or scale of the object
  267. # use the "axis" parameter to decide which property should be set.
  268. #################################################################
  269. if axis == 'x':
  270. self.nodePath.setX(data)
  271. elif axis == 'y':
  272. self.nodePath.setY(data)
  273. elif axis == 'z':
  274. self.nodePath.setZ(data)
  275. elif axis == 'h':
  276. self.nodePath.setH(data)
  277. elif axis == 'p':
  278. self.nodePath.setP(data)
  279. elif axis == 'r':
  280. self.nodePath.setR(data)
  281. elif axis == 's':
  282. self.nodePath.setScale(data)
  283. #### Curve property
  284. def createCurveFrame(self, contentFrame):
  285. #################################################################
  286. # createCurveFrame(self, contentFrame)
  287. # Draw the curve property frame
  288. # This function will draw the property frame and content of curves
  289. # pass the target frame as a variable
  290. #################################################################
  291. if self.curveFrame==None:
  292. self.curveFrame = Frame(contentFrame)
  293. group = Pmw.Group(self.curveFrame,
  294. tag_text='Motion Path List for this Node',
  295. tag_font=('MSSansSerif', 10))
  296. innerFrame = group.interior()
  297. n = 0
  298. for curve in self.info['curveList']:
  299. n += 1
  300. self.createEntryField(innerFrame,'Curve %d:' %n,
  301. value = curve.getCurve(0).getName(),
  302. command = None,
  303. initialState='disabled',
  304. side = 'top',
  305. defaultButton = True,
  306. buttonText = 'delete',
  307. defaultFunction = lambda a = n, b = self : b.deleteCurve(a))
  308. group.pack(side = TOP, fill = X, expand = 0,pady=3, padx=3)
  309. self.curveFrame.pack(side = TOP, fill = X, expand = 0,pady=3, padx=3)
  310. return
  311. def deleteCurve(self, number = 0):
  312. #################################################################
  313. # deleteCurve(self, number = 0)
  314. # Call back function, will be called when user click on the "delete" button beside the curve name.
  315. # This function will send the message to sceneEditor to remove the target curve
  316. # and will set a callback function waitting the result.
  317. #################################################################
  318. widget = self.widgetsDict['Curve %d:' %number]
  319. curveName = widget.getvalue()
  320. self.accept('curveRemovedFromNode',self.redrawCurveProperty)
  321. messenger.send('PW_removeCurveFromNode',[self.nodePath, curveName])
  322. return
  323. def redrawCurveProperty(self, nodePath, curveList):
  324. #################################################################
  325. # redrawCurveProperty(self, nodePath, curveList)
  326. # Callback function, will be called once get the result from dataHolder.
  327. # It will check the target nodePath first, then check the curve list is empty or not.
  328. # If yes, then delete whole curve frame. If not, then renew the data and redraw the curve frame again.
  329. #################################################################
  330. self.name = self.nodePath.getName()
  331. if self.name != nodePath.getName():
  332. messenger.send('curveRemovedFromNode',[nodePath, curveList])
  333. return
  334. else:
  335. self.ignore('curveRemovedFromNode')
  336. if curveList!= None:
  337. del self.info['curveList']
  338. self.info['curveList'] = curveList
  339. self.curveFrame.destroy()
  340. del self.curveFrame
  341. self.curveFrame = None
  342. self.createCurveFrame(self.contentFrame)
  343. else:
  344. del self.info['curveList']
  345. self.curveFrame.destroy()
  346. del self.curveFrame
  347. self.curveFrame = None
  348. return
  349. ####
  350. #### Anything about Camera will be here!
  351. ####
  352. def cameraInterface(self, contentFrame):
  353. #################################################################
  354. # cameraInterface(self, interior, mainFrame)
  355. # Create the interface for camera node.
  356. #################################################################
  357. ## Type entry : unchageable
  358. widget = self.createEntryField(contentFrame,'Type:',
  359. value = self.type,
  360. command = None,
  361. initialState='disabled',
  362. side = 'top')
  363. ## lens Type entry
  364. widget = self.createEntryField(contentFrame, 'Lens Type:',
  365. value = self.info['lensType'],
  366. command = None,
  367. initialState='disabled',
  368. side = 'top')
  369. ## Pos
  370. group = Pmw.Group(contentFrame,tag_text='Position',
  371. tag_font=('MSSansSerif', 10))
  372. self.createPosEntry(group.interior())
  373. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  374. ## Orientation
  375. group = Pmw.Group(contentFrame,tag_text='Orientation',
  376. tag_font=('MSSansSerif', 10))
  377. self.createHprEntry(group.interior())
  378. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  379. ## near entry
  380. group = Pmw.Group(contentFrame,tag_text='Lens Property',
  381. tag_font=('MSSansSerif', 10))
  382. lensFrame = group.interior()
  383. widget = self.createEntryField(lensFrame, 'Near:',value = self.info['near'],
  384. command = self.setCameraNear,
  385. initialState='normal',
  386. validate = Pmw.realvalidator,
  387. side = 'top',
  388. defaultButton = True,
  389. defaultFunction = self.defaultCameraNear)
  390. ## far entry
  391. widget = self.createEntryField(lensFrame, 'Far:',
  392. value = self.info['far'],
  393. command = self.setCameraFar,
  394. initialState='normal',
  395. side = 'top',
  396. validate = Pmw.realvalidator,
  397. defaultButton = True,
  398. defaultFunction = self.defaultCameraFar)
  399. ## Hfov entry
  400. widget = self.createEntryField(lensFrame, 'H.F.O.V.:',
  401. value = self.info['hFov'],
  402. command = self.setCameraFov,
  403. validate = Pmw.realvalidator,
  404. initialState='normal',
  405. side = 'top',
  406. defaultButton = True,
  407. defaultFunction = self.defaultCameraHfov)
  408. ## Vfov entry
  409. widget = self.createEntryField(lensFrame, 'V.F.O.V.:',
  410. value = self.info['vFov'],
  411. command = self.setCameraFov,
  412. validate = Pmw.realvalidator,
  413. initialState='normal',
  414. side = 'top',
  415. defaultButton = True,
  416. defaultFunction = self.defaultCameraVfov)
  417. ## Film Size entry
  418. frame = Frame(lensFrame)
  419. widget = Label(frame, text = "Film Size:", font=('MSSansSerif', 10),width=12)
  420. widget.pack(side=LEFT)
  421. frame.pack(side = TOP, fill = X, expand = 0, pady=3)
  422. frame = Frame(lensFrame)
  423. widget = Pmw.EntryField(frame, labelpos='w', label_text = ' ',
  424. value = self.info['FilmSize'].getX(),
  425. entry_font=('MSSansSerif', 10),
  426. label_font=('MSSansSerif', 10),
  427. modifiedcommand=self.setCameraFilmSize, validate = Pmw.realvalidator,
  428. entry_width = 8)
  429. self.widgetsDict['FilmSizeX']=widget
  430. widget.pack(side=LEFT, padx=3)
  431. widget = Pmw.EntryField(frame, labelpos='w', label_text = ': ', value = self.info['FilmSize'].getY() ,
  432. label_font=('MSSansSerif', 10),
  433. entry_font=('MSSansSerif', 10),
  434. modifiedcommand=self.setCameraFilmSize, validate = Pmw.realvalidator,
  435. entry_width = 8)
  436. self.widgetsDict['FilmSizeY']=widget
  437. widget.pack(side=LEFT, padx=3)
  438. widget = Button(frame, text='Default', font=('MSSansSerif', 10), command = self.defaultCameraFilmSize)
  439. widget.pack(side=LEFT, padx=3)
  440. self.widgetsDict['FilmSize'+'-'+'DefaultButton']=widget
  441. frame.pack(side = TOP, fill = X, expand = 0,pady=0)
  442. ## Focal Length entry
  443. widget = self.createEntryField(lensFrame, 'Focal Length:',
  444. value = self.info['focalLength'],
  445. command = self.setCameraFocalLength,
  446. validate = Pmw.realvalidator,
  447. initialState='normal',
  448. side = 'top',
  449. defaultButton = True,
  450. defaultFunction = self.defaultCameraFocalLength)
  451. group.pack(side = TOP, fill = X, expand = 0,pady=2)
  452. def defaultCameraFar(self):
  453. #################################################################
  454. # defaultCameraFar(self)
  455. # set the camera "Far" value back to default.
  456. #################################################################
  457. widget = self.widgetsDict['Far:']
  458. widget.setvalue(base.cam.node().getLens().getDefaultFar())
  459. return
  460. def setCameraFar(self):
  461. #################################################################
  462. # setCameraFar(self)
  463. # set the camera "Far" value to what now user has typed in the entry
  464. #################################################################
  465. if self.widgetsDict['Far:'].getvalue() != '':
  466. value = float(self.widgetsDict['Far:'].getvalue())
  467. else:
  468. value = 0
  469. camera.getChild(0).node().getLens().setFar(value)
  470. return
  471. def defaultCameraNear(self):
  472. #################################################################
  473. # defaultCameraNear(self)
  474. # set the camera "Near" value back to default.
  475. #################################################################
  476. widget = self.widgetsDict['Near:']
  477. widget.setvalue(base.cam.node().getLens().getDefaultNear())
  478. return
  479. def setCameraNear(self):
  480. #################################################################
  481. # setCameraNear(self)
  482. # set the camera "Near" value to what now user has typed in the entry
  483. #################################################################
  484. if self.widgetsDict['Near:'].getvalue() != '':
  485. value = float(self.widgetsDict['Near:'].getvalue())
  486. else:
  487. value = 0
  488. camera.getChild(0).node().getLens().setNear(value)
  489. return
  490. def defaultCameraHfov(self):
  491. #################################################################
  492. # defaultCameraHfov(self)
  493. # set the camera "Hfov" value back to default.
  494. #################################################################
  495. widget = self.widgetsDict['H.F.O.V.:']
  496. widget.setvalue(45.0)
  497. return
  498. def setCameraFov(self):
  499. #################################################################
  500. # setCameraFov(self)
  501. # set the camera "Fov" value to what now user has typed in the entry
  502. #################################################################
  503. if self.widgetsDict['H.F.O.V.:'].getvalue() != '':
  504. value1 = float(self.widgetsDict['H.F.O.V.:'].getvalue())
  505. else:
  506. value1 = 0
  507. if self.widgetsDict['V.F.O.V.:'].getvalue() != '':
  508. value2 = float(self.widgetsDict['V.F.O.V.:'].getvalue())
  509. else:
  510. value2 = 0
  511. camera.getChild(0).node().getLens().setFov(VBase2(value1,value2))
  512. return
  513. def defaultCameraVfov(self):
  514. #################################################################
  515. # defaultCameraVfov(self)
  516. # set the camera "Vfov" value back to default.
  517. #################################################################
  518. widget = self.widgetsDict['V.F.O.V.:']
  519. widget.setvalue(34.51587677)
  520. return
  521. def defaultCameraFocalLength(self):
  522. #################################################################
  523. # defaultCameraFocalLength(self)
  524. # set the camera "Focal Length" value back to default.
  525. #################################################################
  526. widget = self.widgetsDict['Focal Length:']
  527. widget.setvalue(1.20710682869)
  528. return
  529. def setCameraFocalLength(self):
  530. #################################################################
  531. # setCameraFocalLength(self)
  532. # set the camera "Focal Length" value to what now user has typed in the entry
  533. #################################################################
  534. if self.widgetsDict['Focal Length:'].getvalue() != '':
  535. value = float(self.widgetsDict['Focal Length:'].getvalue())
  536. else:
  537. value = 0
  538. camera.getChild(0).node().getLens().setFocalLength(value)
  539. camera.getChild(0).node().getLens().setFilmSize(VBase2(float(self.widgetsDict['FilmSizeX'].getvalue()),float(self.widgetsDict['FilmSizeY'].getvalue())))
  540. return
  541. def defaultCameraFilmSize(self):
  542. #################################################################
  543. # defaultCameraFilmSize(self)
  544. # set the camera "Film Size" value back to default.
  545. #################################################################
  546. widget = self.widgetsDict['FilmSizeX']
  547. widget.setvalue(1)
  548. widget = self.widgetsDict['FilmSizeY']
  549. widget.setvalue(0.75)
  550. return
  551. def setCameraFilmSize(self):
  552. #################################################################
  553. # setCameraFilmSize(self)
  554. # set the camera "Film Size" value to what now user has typed in the entry
  555. #################################################################
  556. if self.widgetsDict['FilmSizeX'].getvalue() != '':
  557. value1 = float(self.widgetsDict['FilmSizeX'].getvalue())
  558. else:
  559. value1 = 0
  560. if self.widgetsDict['FilmSizeY'].getvalue() != '':
  561. value2 = float(self.widgetsDict['FilmSizeY'].getvalue())
  562. else:
  563. value2 = 0
  564. camera.getChild(0).node().getLens().setFilmSize(VBase2(value1,value2))
  565. return
  566. ####
  567. #### Anything about Model & Actor will be here!
  568. ####
  569. def modelInterface(self, contentFrame):
  570. #################################################################
  571. # modelInterface(self, contentFrame)
  572. # Create the basic interface for ModelRoot Type Node
  573. #################################################################
  574. widget = self.createEntryField(contentFrame,'Type:',
  575. value = self.type,
  576. command = None,
  577. initialState='disabled',
  578. side = 'top')
  579. widget = self.createEntryField(contentFrame,'Model File:',
  580. value = self.info['filePath'].getFullpath(),
  581. command = None,
  582. initialState='disabled',
  583. side = 'top',
  584. defaultButton = False,
  585. buttonText = 'Change',
  586. defaultFunction = None)
  587. group = Pmw.Group(contentFrame,tag_text='Position',
  588. tag_font=('MSSansSerif', 10))
  589. self.createPosEntry(group.interior())
  590. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  591. group = Pmw.Group(contentFrame,tag_text='Orientation',
  592. tag_font=('MSSansSerif', 10))
  593. self.createHprEntry(group.interior())
  594. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  595. self.createScaleEntry(contentFrame)
  596. group = Pmw.Group(contentFrame,tag_text='Color',
  597. tag_font=('MSSansSerif', 10))
  598. frame = group.interior()
  599. self.createColorEntry(frame)
  600. self.varAlpha = IntVar()
  601. self.varAlpha.set(self.nodePath.hasTransparency())
  602. checkButton = Checkbutton(frame, text='Enable Alpha',
  603. variable=self.varAlpha, command=self.toggleAlpha)
  604. checkButton.pack(side=RIGHT,pady=3)
  605. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  606. return
  607. def toggleAlpha(self):
  608. #################################################################
  609. # toggleAlpha(self)
  610. # This funtion will toggle the objects alpha value
  611. # And, it will also reset the "Bin" to
  612. # "fixed" if user enable the alpha for this object.
  613. #################################################################
  614. if self.nodePath.hasTransparency():
  615. self.nodePath.clearTransparency()
  616. self.nodePath.setBin("default", 0)
  617. else:
  618. self.nodePath.setTransparency(True)
  619. self.nodePath.setBin("fixed", 1)
  620. return
  621. def actorInterface(self, contentFrame):
  622. #################################################################
  623. # actorInterface(self, contentFrame)
  624. # Create the basic interface for Actor Type Node
  625. #################################################################
  626. self.animFrame = None
  627. animeDict = self.info['animDict']
  628. if len(animeDict)==0:
  629. return
  630. self.animFrame = Frame(contentFrame)
  631. group = Pmw.Group(self.animFrame,tag_text='Animations',
  632. tag_font=('MSSansSerif', 10))
  633. innerFrame = group.interior()
  634. for name in animeDict:
  635. self.createEntryField(innerFrame, name,
  636. value = animeDict[name],
  637. command = None,
  638. initialState='disabled',
  639. side = 'top',
  640. defaultButton = True,
  641. buttonText = 'Remove',
  642. defaultFunction = lambda a = name, b = self : b.deleteAnimation(a))
  643. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  644. self.animFrame.pack(side=TOP,fill = X, expand = 0, pady=3)
  645. return
  646. def deleteAnimation(self, anim):
  647. #################################################################
  648. # deleteAnimation(self, anim)
  649. # This function will delete the animation named "anim" in this actor
  650. # But, not directly removed be this function.
  651. # This function will send out a message to notice dataHolder to remove this animation
  652. #################################################################
  653. print anim
  654. widget = self.widgetsDict[anim]
  655. self.accept('animRemovedFromNode',self.redrawAnimProperty)
  656. messenger.send('PW_removeAnimFromNode',[self.name, anim])
  657. return
  658. def redrawAnimProperty(self, nodePath, animDict):
  659. #################################################################
  660. # redrawCurveProperty(self, nodePath, curveList)
  661. # Callback function, will be called once get the result from dataHolder.
  662. # It will check the target nodePath first, then check the curve list is empty or not.
  663. # If yes, then delete whole curve frame. If not, then renew the data and redraw the curve frame again.
  664. #################################################################
  665. self.name = self.nodePath.getName()
  666. if self.name != nodePath.getName():
  667. messenger.send('animRemovedFromNode',[nodePath, animDict])
  668. return
  669. else:
  670. self.ignore('animRemovedFromNode')
  671. if len(animDict)!= 0:
  672. del self.info['animDict']
  673. self.info['animDict'] = animDict
  674. self.animFrame.destroy()
  675. del self.animFrame
  676. self.animFrame = None
  677. self.actorInterface(self.contentFrame)
  678. else:
  679. del self.info['animDict']
  680. self.animFrame.destroy()
  681. del self.animFrame
  682. self.animFrame = None
  683. return
  684. ####
  685. #### Anything about Light will be here!
  686. ####
  687. def lightInterface(self, contentFrame):
  688. #################################################################
  689. # lightInterface(self, contentFrame)
  690. # Create the basic interface for light Type Node
  691. #################################################################
  692. widget = self.createEntryField(contentFrame,'Type:',
  693. value = self.nodePath.node().getType().getName(),
  694. command = None,
  695. initialState='disabled',
  696. side = 'top')
  697. self.lightNode = self.info['lightNode']
  698. lightingGroup = Pmw.Group(contentFrame,tag_pyclass=None)
  699. frame = lightingGroup.interior()
  700. self.lightColor = seColorEntry(
  701. frame, text = 'Light Color', label_font=('MSSansSerif', 10),
  702. value=[self.lightNode.lightcolor.getX()*255, self.lightNode.lightcolor.getY()*255,self.lightNode.lightcolor.getZ()*255,0])
  703. self.lightColor['command'] = self.setLightingColorVec
  704. self.lightColor['resetValue'] = [0.3*255,0.3*255,0.3*255,0]
  705. self.lightColor.pack(side=TOP, fill=X,expand=1, padx = 2, pady =2)
  706. self.bind(self.lightColor, 'Set light color')
  707. self.varActive = IntVar()
  708. self.varActive.set(self.lightNode.active)
  709. checkButton = Checkbutton(frame, text='Enable This Light',
  710. variable=self.varActive, command=self.toggleLight)
  711. checkButton.pack(side=RIGHT,pady=3)
  712. lightingGroup.pack(side=TOP, fill = X, expand =1)
  713. # Directional light controls
  714. if self.lightNode.type == 'directional':
  715. lightingGroup = Pmw.Group(contentFrame,tag_pyclass=None)
  716. directionalPage = lightingGroup.interior()
  717. self.dSpecularColor = seColorEntry(
  718. directionalPage, text = 'Specular Color', label_font=('MSSansSerif', 10),value = [self.lightNode.specularColor.getX()*255,self.lightNode.specularColor.getY()*255,self.lightNode.specularColor.getZ()*255,0])
  719. self.dSpecularColor['command'] = self.setSpecularColor
  720. self.dSpecularColor.pack(fill = X, expand = 1)
  721. self.bind(self.dSpecularColor,
  722. 'Set directional light specular color')
  723. self.dPosition = VectorWidgets.Vector3Entry(
  724. directionalPage, text = 'Position', label_font=('MSSansSerif', 10),value = [self.lightNode.getPosition().getX(),self.lightNode.getPosition().getY(),self.lightNode.getPosition().getZ()])
  725. self.dPosition['command'] = self.setPosition
  726. self.dPosition['resetValue'] = [0,0,0,0]
  727. self.dPosition.pack(fill = X, expand = 1)
  728. self.bind(self.dPosition, 'Set directional light position')
  729. self.dOrientation = VectorWidgets.Vector3Entry(
  730. directionalPage, text = 'Orientation', label_font=('MSSansSerif', 10),
  731. value = [self.lightNode.getOrientation().getX(),self.lightNode.getOrientation().getY(),self.lightNode.getOrientation().getZ(),0])
  732. self.dOrientation['command'] = self.setOrientation
  733. self.dOrientation['resetValue'] = [0,0,0,0]
  734. self.dOrientation.pack(fill = X, expand = 1)
  735. self.bind(self.dOrientation, 'Set directional light orientation')
  736. lightingGroup.pack(side=TOP, fill = X, expand =1)
  737. elif self.lightNode.type == 'point':
  738. # Point light controls
  739. lightingGroup = Pmw.Group(contentFrame,tag_pyclass=None)
  740. pointPage = lightingGroup.interior()
  741. self.pSpecularColor = seColorEntry(
  742. pointPage, text = 'Specular Color', label_font=('MSSansSerif', 10),
  743. value = [self.lightNode.specularColor.getX(),self.lightNode.specularColor.getY(),self.lightNode.specularColor.getZ(),0])
  744. self.pSpecularColor['command'] = self.setSpecularColor
  745. self.pSpecularColor.pack(fill = X, expand = 1)
  746. self.bind(self.pSpecularColor,
  747. 'Set point light specular color')
  748. self.pPosition = VectorWidgets.Vector3Entry(
  749. pointPage, text = 'Position', label_font=('MSSansSerif', 10),
  750. value = [self.lightNode.getPosition().getX(),self.lightNode.getPosition().getY(),self.lightNode.getPosition().getZ(),0])
  751. self.pPosition['command'] = self.setPosition
  752. self.pPosition['resetValue'] = [0,0,0,0]
  753. self.pPosition.pack(fill = X, expand = 1)
  754. self.bind(self.pPosition, 'Set point light position')
  755. self.pConstantAttenuation = Slider.Slider(
  756. pointPage,
  757. text = 'Constant Attenuation', label_font=('MSSansSerif', 10),
  758. max = 1.0,
  759. value = self.lightNode.constant)
  760. self.pConstantAttenuation['command'] = self.setConstantAttenuation
  761. self.pConstantAttenuation.pack(fill = X, expand = 1)
  762. self.bind(self.pConstantAttenuation,
  763. 'Set point light constant attenuation')
  764. self.pLinearAttenuation = Slider.Slider(
  765. pointPage,
  766. text = 'Linear Attenuation', label_font=('MSSansSerif', 10),
  767. max = 1.0,
  768. value = self.lightNode.linear)
  769. self.pLinearAttenuation['command'] = self.setLinearAttenuation
  770. self.pLinearAttenuation.pack(fill = X, expand = 1)
  771. self.bind(self.pLinearAttenuation,
  772. 'Set point light linear attenuation')
  773. self.pQuadraticAttenuation = Slider.Slider(
  774. pointPage,
  775. text = 'Quadratic Attenuation', label_font=('MSSansSerif', 10),
  776. max = 1.0,
  777. value = self.lightNode.quadratic)
  778. self.pQuadraticAttenuation['command'] = self.setQuadraticAttenuation
  779. self.pQuadraticAttenuation.pack(fill = X, expand = 1)
  780. self.bind(self.pQuadraticAttenuation,
  781. 'Set point light quadratic attenuation')
  782. lightingGroup.pack(side=TOP, fill = X, expand =1)
  783. elif self.lightNode.type == 'spot':
  784. # Spot light controls
  785. lightingGroup = Pmw.Group(contentFrame,tag_pyclass=None)
  786. spotPage = lightingGroup.interior()
  787. self.sSpecularColor = seColorEntry(
  788. spotPage, text = 'Specular Color', label_font=('MSSansSerif', 10),
  789. value = [self.lightNode.specularColor.getX()*255,self.lightNode.specularColor.getY()*255,self.lightNode.specularColor.getZ()*255,0])
  790. self.sSpecularColor['command'] = self.setSpecularColor
  791. self.sSpecularColor.pack(fill = X, expand = 1)
  792. self.bind(self.sSpecularColor,
  793. 'Set spot light specular color')
  794. self.sConstantAttenuation = Slider.Slider(
  795. spotPage,
  796. text = 'Constant Attenuation', label_font=('MSSansSerif', 10),
  797. max = 1.0,
  798. value = self.lightNode.constant)
  799. self.sConstantAttenuation['command'] = self.setConstantAttenuation
  800. self.sConstantAttenuation.pack(fill = X, expand = 1)
  801. self.bind(self.sConstantAttenuation,
  802. 'Set spot light constant attenuation')
  803. self.sLinearAttenuation = Slider.Slider(
  804. spotPage,
  805. text = 'Linear Attenuation', label_font=('MSSansSerif', 10),
  806. max = 1.0,
  807. value = self.lightNode.linear)
  808. self.sLinearAttenuation['command'] = self.setLinearAttenuation
  809. self.sLinearAttenuation.pack(fill = X, expand = 1)
  810. self.bind(self.sLinearAttenuation,
  811. 'Set spot light linear attenuation')
  812. self.sQuadraticAttenuation = Slider.Slider(
  813. spotPage,
  814. text = 'Quadratic Attenuation', label_font=('MSSansSerif', 10),
  815. max = 1.0,
  816. value = self.lightNode.quadratic)
  817. self.sQuadraticAttenuation['command'] = self.setQuadraticAttenuation
  818. self.sQuadraticAttenuation.pack(fill = X, expand = 1)
  819. self.bind(self.sQuadraticAttenuation,
  820. 'Set spot light quadratic attenuation')
  821. self.sExponent = Slider.Slider(
  822. spotPage,
  823. text = 'Exponent', label_font=('MSSansSerif', 10),
  824. max = 1.0,
  825. value = self.lightNode.exponent)
  826. self.sExponent['command'] = self.setExponent
  827. self.sExponent.pack(fill = X, expand = 1)
  828. self.bind(self.sExponent,
  829. 'Set spot light exponent')
  830. lightingGroup.pack(side=TOP, fill = X, expand =1)
  831. return
  832. def setLightingColorVec(self,color):
  833. if self.lightNode==None:
  834. return
  835. self.lightNode.setColor(VBase4((color[0]/255),(color[1]/255),(color[2]/255),1))
  836. return
  837. def setSpecularColor(self,color):
  838. if self.lightNode==None:
  839. return
  840. self.lightNode.setSpecColor(VBase4((color[0]/255),(color[1]/255),(color[2]/255),1))
  841. return
  842. def setPosition(self,position):
  843. if self.lightNode==None:
  844. return
  845. self.lightNode.setPosition(Point3(position[0],position[1],position[2]))
  846. return
  847. def setOrientation(self, orient):
  848. if self.lightNode==None:
  849. return
  850. self.lightNode.setOrientation(Vec3(orient[0],orient[1],orient[2]))
  851. return
  852. def setConstantAttenuation(self, value):
  853. self.lightNode.setConstantAttenuation(value)
  854. return
  855. def setLinearAttenuation(self, value):
  856. self.lightNode.setLinearAttenuation(value)
  857. return
  858. def setQuadraticAttenuation(self, value):
  859. self.lightNode.setQuadraticAttenuation(value)
  860. return
  861. def setExponent(self, value):
  862. self.lightNode.setExponent(value)
  863. return
  864. def toggleLight(self):
  865. messenger.send('PW_toggleLight',[self.lightNode])
  866. return
  867. ####
  868. #### Anything about Dummy will be here!
  869. ####
  870. def dummyInterface(self, contentFrame):
  871. #################################################################
  872. # dummyInterface(self, contentFrame)
  873. # Create the basic interface for dummy Type Node
  874. #################################################################
  875. '''dummyInterface(self, contentFrame)
  876. Create the basic interface for dummy Node
  877. '''
  878. widget = self.createEntryField(contentFrame,'Type:',
  879. value = 'Dummy Nodepath',
  880. command = None,
  881. initialState='disabled',
  882. side = 'top')
  883. group = Pmw.Group(contentFrame,tag_text='Position',
  884. tag_font=('MSSansSerif', 10))
  885. self.createPosEntry(group.interior())
  886. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  887. group = Pmw.Group(contentFrame,tag_text='Orientation',
  888. tag_font=('MSSansSerif', 10))
  889. self.createHprEntry(group.interior())
  890. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  891. self.createScaleEntry(contentFrame)
  892. group = Pmw.Group(contentFrame,tag_text='Color',
  893. tag_font=('MSSansSerif', 10))
  894. frame = group.interior()
  895. self.createColorEntry(frame)
  896. self.varAlpha = IntVar()
  897. self.varAlpha.set(self.nodePath.hasTransparency())
  898. checkButton = Checkbutton(frame, text='Enable Alpha',
  899. variable=self.varAlpha, command=self.toggleAlpha)
  900. checkButton.pack(side=RIGHT,pady=3)
  901. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  902. return
  903. #########
  904. ####### This will be called when user try to open property window for SEditor Node
  905. #########
  906. def gridInterface(self, contentFrame):
  907. #################################################################
  908. # gridInterface(self, contentFrame)
  909. # Create the basic interface for grid (Which is stolen from directGrid)
  910. #################################################################
  911. group = Pmw.Group(contentFrame,tag_text='Grid Property',
  912. tag_font=('MSSansSerif', 10))
  913. group.pack(side=TOP,fill = X, expand = 0, padx = 3, pady=3)
  914. gridPage = group.interior()
  915. self.xyzSnap = BooleanVar()
  916. self.xyzSnapButton = Checkbutton(
  917. gridPage,
  918. text = 'XYZ Snap',
  919. anchor = 'w', justify = LEFT,
  920. variable = self.xyzSnap,
  921. command = self.toggleXyzSnap)
  922. self.xyzSnapButton.pack(fill = X, expand = 0, pady=3)
  923. self.hprSnap = BooleanVar()
  924. self.hprSnapButton = Checkbutton(
  925. gridPage,
  926. text = 'HPR Snap',
  927. anchor = 'w', justify = LEFT,
  928. variable = self.hprSnap,
  929. command = self.toggleHprSnap)
  930. self.hprSnapButton.pack(fill = X, expand = 0, pady=3)
  931. self.xyzSnap.set(SEditor.grid.getXyzSnap())
  932. self.hprSnap.set(SEditor.grid.getHprSnap())
  933. self.gridSpacing = Floater.Floater(
  934. gridPage,
  935. text = 'Grid Spacing',
  936. min = 0.1,
  937. value = SEditor.grid.getGridSpacing())
  938. self.gridSpacing['command'] = SEditor.grid.setGridSpacing
  939. self.gridSpacing.pack(fill = X, expand = 0, pady=3)
  940. self.gridSize = Floater.Floater(
  941. gridPage,
  942. text = 'Grid Size',
  943. min = 1.0,
  944. value = SEditor.grid.getGridSize())
  945. self.gridSize['command'] = SEditor.grid.setGridSize
  946. self.gridSize.pack(fill = X, expand = 0, pady=3)
  947. self.gridSnapAngle = Dial.AngleDial(
  948. gridPage,
  949. text = 'Snap Angle',
  950. style = 'mini',
  951. value = SEditor.grid.getSnapAngle())
  952. self.gridSnapAngle['command'] = SEditor.grid.setSnapAngle
  953. self.gridSnapAngle.pack(fill = X, expand = 0, pady=3)
  954. return
  955. def toggleXyzSnap(self):
  956. SEditor.grid.setXyzSnap(self.xyzSnap.get())
  957. return
  958. def toggleHprSnap(self):
  959. SEditor.grid.setHprSnap(self.hprSnap.get())
  960. return
  961. ###### Collision Section!!!!
  962. def collisionInterface(self, contentFrame):
  963. #################################################################
  964. # collisionInterface(self, contentFrame)
  965. # Create the basic interface for CollisionNode Type Node
  966. #################################################################
  967. collisionNode = self.info['collisionNode']
  968. self.collisionObj = collisionNode.node().getSolid(0)
  969. widget = self.createEntryField(contentFrame,'Node Type:',
  970. value = self.type,
  971. command = None,
  972. initialState='disabled',
  973. side = 'top')
  974. cType = self.collisionObj.getType().getName()
  975. widget = self.createEntryField(contentFrame,'Object Type:',
  976. value = cType,
  977. command = None,
  978. initialState='disabled',
  979. side = 'top')
  980. group = Pmw.Group(contentFrame,tag_text='Position',
  981. tag_font=('MSSansSerif', 10))
  982. self.createPosEntry(group.interior())
  983. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  984. group = Pmw.Group(contentFrame,tag_text='Orientation',
  985. tag_font=('MSSansSerif', 10))
  986. self.createHprEntry(group.interior())
  987. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  988. self.createScaleEntry(contentFrame)
  989. collisionGroup = Pmw.Group(contentFrame,tag_text='Collision Object Properties',
  990. tag_font=('MSSansSerif', 10))
  991. cObjFrame = collisionGroup.interior()
  992. ### Generate different Interface for each different kinds of Collision Objects
  993. ### Yeah, yeah. I know this part of code looks so ugly...
  994. if cType == 'CollisionSphere':
  995. centerPos = self.collisionObj.getCenter()
  996. radius = self.collisionObj.getRadius()
  997. group = Pmw.Group(cObjFrame,tag_text='Origin',
  998. tag_font=('MSSansSerif', 10))
  999. posInterior = Frame(group.interior())
  1000. self.cPosX = self.createcomponent('originX', (), None,
  1001. Floater.Floater, (posInterior,),
  1002. text = 'X', relief = FLAT,
  1003. value = centerPos.getX(),
  1004. label_foreground = 'Red',
  1005. entry_width = 9)
  1006. self.cPosX['commandData'] = ['sphere-o']
  1007. self.cPosX['command'] = self.setCollisionPosHprScale
  1008. self.cPosX.pack(side=LEFT,expand=0,fill=X, padx=1)
  1009. self.cPosY = self.createcomponent('originY', (), None,
  1010. Floater.Floater, (posInterior,),
  1011. text = 'Y', relief = FLAT,
  1012. value = centerPos.getY(),
  1013. label_foreground = '#00A000',
  1014. entry_width = 9)
  1015. self.cPosY['commandData'] = ['sphere-o']
  1016. self.cPosY['command'] = self.setCollisionPosHprScale
  1017. self.cPosY.pack(side=LEFT, expand=0,fill=X, padx=1)
  1018. self.cPosZ = self.createcomponent('originZ', (), None,
  1019. Floater.Floater, (posInterior,),
  1020. text = 'Z', relief = FLAT,
  1021. value = centerPos.getZ(),
  1022. label_foreground = 'Blue',
  1023. entry_width = 9)
  1024. self.cPosZ['commandData'] = ['sphere-o']
  1025. self.cPosZ['command'] = self.setCollisionPosHprScale
  1026. self.cPosZ.pack(side=LEFT, expand=0,fill=X, padx=1)
  1027. posInterior.pack(side=TOP, expand=0,fill=X, padx=3, pady=3)
  1028. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  1029. scaleInterior = Frame(cObjFrame)
  1030. self.scaleS = self.createcomponent('radius', (), None,
  1031. Floater.Floater, (scaleInterior,),
  1032. text = 'Radius',
  1033. relief = FLAT,
  1034. min = 0.0001, value = radius,
  1035. resetValue = 1.0,
  1036. label_foreground = 'Blue')
  1037. self.scaleS['commandData'] = ['sphere-radius']
  1038. self.scaleS['command'] = self.setCollisionPosHprScale
  1039. self.scaleS.pack(side=LEFT,expand=0,fill=X)
  1040. scaleInterior.pack(side=TOP,expand=0,fill=X, padx=3, pady=3)
  1041. pass
  1042. elif cType == 'CollisionPolygon':
  1043. frame = Frame(cObjFrame)
  1044. label = Label(frame, text= "Sorry!",font=('MSSansSerif', 10),
  1045. borderwidth=5)
  1046. label.pack(side=LEFT)
  1047. frame.pack(side=TOP, fill=X, expand=True)
  1048. frame = Frame(cObjFrame)
  1049. label = Label(frame, text= "There is no way to change",font=('MSSansSerif', 10),
  1050. borderwidth=5)
  1051. label.pack(side=LEFT)
  1052. frame.pack(side=TOP, fill=X, expand=True)
  1053. frame = Frame(cObjFrame)
  1054. label = Label(frame, text= "the basic properties of Collision Polygon!",font=('MSSansSerif', 10),
  1055. borderwidth=5)
  1056. label.pack(side=LEFT)
  1057. frame.pack(side=TOP, fill=X, expand=True)
  1058. frame = Frame(cObjFrame)
  1059. label = Label(frame, text= "If you really need to change, recreate one...",font=('MSSansSerif', 10),
  1060. borderwidth=5)
  1061. label.pack(side=LEFT)
  1062. frame.pack(side=TOP, fill=X, expand=True)
  1063. pass
  1064. elif cType == 'CollisionSegment':
  1065. pointA = self.collisionObj.getPointA()
  1066. pointB = self.collisionObj.getPointB()
  1067. group = Pmw.Group(cObjFrame,tag_text='Point A',
  1068. tag_font=('MSSansSerif', 10))
  1069. posInterior = Frame(group.interior())
  1070. self.cPosX = self.createcomponent('pointA-X', (), None,
  1071. Floater.Floater, (posInterior,),
  1072. text = 'X', relief = FLAT,
  1073. value = pointA.getX(),
  1074. label_foreground = 'Red',
  1075. entry_width = 9)
  1076. self.cPosX['commandData'] = ['segment-A']
  1077. self.cPosX['command'] = self.setCollisionPosHprScale
  1078. self.cPosX.pack(side=LEFT,expand=0,fill=X, padx=1)
  1079. self.cPosY = self.createcomponent('pointA-Y', (), None,
  1080. Floater.Floater, (posInterior,),
  1081. text = 'Y', relief = FLAT,
  1082. value = pointA.getY(),
  1083. label_foreground = '#00A000',
  1084. entry_width = 9)
  1085. self.cPosY['commandData'] = ['segment-A']
  1086. self.cPosY['command'] = self.setCollisionPosHprScale
  1087. self.cPosY.pack(side=LEFT, expand=0,fill=X, padx=1)
  1088. self.cPosZ = self.createcomponent('pointA-Z', (), None,
  1089. Floater.Floater, (posInterior,),
  1090. text = 'Z', relief = FLAT,
  1091. value = pointA.getZ(),
  1092. label_foreground = 'Blue',
  1093. entry_width = 9)
  1094. self.cPosZ['commandData'] = ['segment-A']
  1095. self.cPosZ['command'] = self.setCollisionPosHprScale
  1096. self.cPosZ.pack(side=LEFT, expand=0,fill=X, padx=1)
  1097. posInterior.pack(side=TOP, expand=0,fill=X, padx=3, pady=3)
  1098. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  1099. group = Pmw.Group(cObjFrame,tag_text='Point B',
  1100. tag_font=('MSSansSerif', 10))
  1101. posInterior = Frame(group.interior())
  1102. self.cPosXB = self.createcomponent('pointB-X', (), None,
  1103. Floater.Floater, (posInterior,),
  1104. text = 'X', relief = FLAT,
  1105. value = pointB.getX(),
  1106. label_foreground = 'Red',
  1107. entry_width = 9)
  1108. self.cPosXB['commandData'] = ['segment-B']
  1109. self.cPosXB['command'] = self.setCollisionPosHprScale
  1110. self.cPosXB.pack(side=LEFT,expand=0,fill=X, padx=1)
  1111. self.cPosYB = self.createcomponent('pointB-Y', (), None,
  1112. Floater.Floater, (posInterior,),
  1113. text = 'Y', relief = FLAT,
  1114. value = pointB.getY(),
  1115. label_foreground = '#00A000',
  1116. entry_width = 9)
  1117. self.cPosYB['commandData'] = ['segment-B']
  1118. self.cPosYB['command'] = self.setCollisionPosHprScale
  1119. self.cPosYB.pack(side=LEFT, expand=0,fill=X, padx=1)
  1120. self.cPosZB = self.createcomponent('pointB-Z', (), None,
  1121. Floater.Floater, (posInterior,),
  1122. text = 'Z', relief = FLAT,
  1123. value = pointB.getZ(),
  1124. label_foreground = 'Blue',
  1125. entry_width = 9)
  1126. self.cPosZB['commandData'] = ['segment-B']
  1127. self.cPosZB['command'] = self.setCollisionPosHprScale
  1128. self.cPosZB.pack(side=LEFT, expand=0,fill=X, padx=1)
  1129. posInterior.pack(side=TOP, expand=0,fill=X, padx=3, pady=3)
  1130. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  1131. pass
  1132. elif cType == 'CollisionRay':
  1133. origin = self.collisionObj.getOrigin()
  1134. direction = self.collisionObj.getDirection()
  1135. group = Pmw.Group(cObjFrame,tag_text='Origin Point',
  1136. tag_font=('MSSansSerif', 10))
  1137. posInterior = Frame(group.interior())
  1138. self.cPosX = self.createcomponent('origin-X', (), None,
  1139. Floater.Floater, (posInterior,),
  1140. text = 'X', relief = FLAT,
  1141. value = origin.getX(),
  1142. label_foreground = 'Red',
  1143. entry_width = 9)
  1144. self.cPosX['commandData'] = ['ray-A']
  1145. self.cPosX['command'] = self.setCollisionPosHprScale
  1146. self.cPosX.pack(side=LEFT,expand=0,fill=X, padx=1)
  1147. self.cPosY = self.createcomponent('origin-Y', (), None,
  1148. Floater.Floater, (posInterior,),
  1149. text = 'Y', relief = FLAT,
  1150. value = origin.getY(),
  1151. label_foreground = '#00A000',
  1152. entry_width = 9)
  1153. self.cPosY['commandData'] = ['ray-A']
  1154. self.cPosY['command'] = self.setCollisionPosHprScale
  1155. self.cPosY.pack(side=LEFT, expand=0,fill=X, padx=1)
  1156. self.cPosZ = self.createcomponent('origin-Z', (), None,
  1157. Floater.Floater, (posInterior,),
  1158. text = 'Z', relief = FLAT,
  1159. value = origin.getZ(),
  1160. label_foreground = 'Blue',
  1161. entry_width = 9)
  1162. self.cPosZ['commandData'] = ['ray-A']
  1163. self.cPosZ['command'] = self.setCollisionPosHprScale
  1164. self.cPosZ.pack(side=LEFT, expand=0,fill=X, padx=1)
  1165. posInterior.pack(side=TOP, expand=0,fill=X, padx=3, pady=3)
  1166. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  1167. group = Pmw.Group(cObjFrame,tag_text='Direction',
  1168. tag_font=('MSSansSerif', 10))
  1169. posInterior = Frame(group.interior())
  1170. self.cPosXB = self.createcomponent('direction-X', (), None,
  1171. Floater.Floater, (posInterior,),
  1172. text = 'X', relief = FLAT,
  1173. value = direction.getX(),
  1174. label_foreground = 'Red',
  1175. entry_width = 9)
  1176. self.cPosXB['commandData'] = ['ray-B']
  1177. self.cPosXB['command'] = self.setCollisionPosHprScale
  1178. self.cPosXB.pack(side=LEFT,expand=0,fill=X, padx=1)
  1179. self.cPosYB = self.createcomponent('direction-Y', (), None,
  1180. Floater.Floater, (posInterior,),
  1181. text = 'Y', relief = FLAT,
  1182. value = direction.getY(),
  1183. label_foreground = '#00A000',
  1184. entry_width = 9)
  1185. self.cPosYB['commandData'] = ['ray-B']
  1186. self.cPosYB['command'] = self.setCollisionPosHprScale
  1187. self.cPosYB.pack(side=LEFT, expand=0,fill=X, padx=1)
  1188. self.cPosZB = self.createcomponent('direction-Z', (), None,
  1189. Floater.Floater, (posInterior,),
  1190. text = 'Z', relief = FLAT,
  1191. value = direction.getZ(),
  1192. label_foreground = 'Blue',
  1193. entry_width = 9)
  1194. self.cPosZB['commandData'] = ['ray-B']
  1195. self.cPosZB['command'] = self.setCollisionPosHprScale
  1196. self.cPosZB.pack(side=LEFT, expand=0,fill=X, padx=1)
  1197. posInterior.pack(side=TOP, expand=0,fill=X, padx=3, pady=3)
  1198. group.pack(side=TOP,fill = X, expand = 0, pady=3)
  1199. pass
  1200. collisionGroup.pack(side=TOP,fill = X, expand = 0, pady=3)
  1201. return
  1202. def setCollisionPosHprScale(self, data, dataType):
  1203. #################################################################
  1204. # setCollisionPosHprScale(self, data, dataType)
  1205. # Well, the reason that we didn't use the same one with other nodePath
  1206. # is that each tyoe of collsion objects has its unique properties and way to set value.
  1207. # So, they have to be separated from other nodePath
  1208. #################################################################
  1209. if dataType == 'sphere-o':
  1210. origin = Point3(float(self.cPosX._entry.get()),
  1211. float(self.cPosY._entry.get()),
  1212. float(self.cPosZ._entry.get()))
  1213. self.collisionObj.setCenter(origin)
  1214. elif dataType == 'sphere-radius':
  1215. self.collisionObj.setRadius(data)
  1216. elif dataType == 'segment-A':
  1217. pointA = Point3(float(self.cPosX._entry.get()),
  1218. float(self.cPosY._entry.get()),
  1219. float(self.cPosZ._entry.get()))
  1220. self.collisionObj.setPointA(pointA)
  1221. elif dataType == 'segment-B':
  1222. pointB = Point3(float(self.cPosXB._entry.get()),
  1223. float(self.cPosYB._entry.get()),
  1224. float(self.cPosZB._entry.get()))
  1225. self.collisionObj.setPointB(pointB)
  1226. elif dataType == 'ray-A':
  1227. pointA = Point3(float(self.cPosX._entry.get()),
  1228. float(self.cPosY._entry.get()),
  1229. float(self.cPosZ._entry.get()))
  1230. self.collisionObj.setOrigin(pointA)
  1231. elif dataType == 'ray-B':
  1232. pointB = Vec3(float(self.cPosXB._entry.get()),
  1233. float(self.cPosYB._entry.get()),
  1234. float(self.cPosZB._entry.get()))
  1235. self.collisionObj.setDirection(pointB)
  1236. return
  1237. #################################################################
  1238. #################################################################
  1239. # Functions below are all call back function
  1240. # They will be called when user has manipulated its node on the screen
  1241. # The message itself is sent by a task called monitorSelectedNode in the sceneEditor.
  1242. #################################################################
  1243. #################################################################
  1244. def trackDataFromSceneCamera(self, pos=Point3(0,0,0), hpr=Vec3(0,0,0), scale=Point3(0,0,0)):
  1245. self.posX.set(pos.getX())
  1246. self.posY.set(pos.getY())
  1247. self.posZ.set(pos.getZ())
  1248. self.hprH.set(hpr.getX())
  1249. self.hprP.set(hpr.getY())
  1250. self.hprR.set(hpr.getZ())
  1251. return
  1252. def trackDataFromSceneModel(self, pos=Point3(0,0,0), hpr=Vec3(0,0,0), scale=Point3(0,0,0)):
  1253. self.posX.set(pos.getX())
  1254. self.posY.set(pos.getY())
  1255. self.posZ.set(pos.getZ())
  1256. self.hprH.set(hpr.getX())
  1257. self.hprP.set(hpr.getY())
  1258. self.hprR.set(hpr.getZ())
  1259. self.scale.set(scale.getX())
  1260. return
  1261. def trackDataFromSceneActor(self, pos=Point3(0,0,0), hpr=Vec3(0,0,0), scale=Point3(0,0,0)):
  1262. self.posX.set(pos.getX())
  1263. self.posY.set(pos.getY())
  1264. self.posZ.set(pos.getZ())
  1265. self.hprH.set(hpr.getX())
  1266. self.hprP.set(hpr.getY())
  1267. self.hprR.set(hpr.getZ())
  1268. self.scale.set(scale.getX())
  1269. return
  1270. def trackDataFromSceneLight(self, pos=Point3(0,0,0), hpr=Vec3(0,0,0), scale=Point3(0,0,0)):
  1271. if self.lightNode.type == 'directional':
  1272. self.dPosition.set([pos.getX(),pos.getY(),pos.getZ()])
  1273. self.dOrientation.set([hpr.getX(),hpr.getY(),hpr.getZ()])
  1274. pass
  1275. elif self.lightNode.type == 'point':
  1276. self.pPosition.set([pos.getX(),pos.getY(),pos.getZ()])
  1277. pass
  1278. return
  1279. def trackDataFromSceneDummy(self, pos=Point3(0,0,0), hpr=Vec3(0,0,0), scale=Point3(0,0,0)):
  1280. self.posX.set(pos.getX())
  1281. self.posY.set(pos.getY())
  1282. self.posZ.set(pos.getZ())
  1283. self.hprH.set(hpr.getX())
  1284. self.hprP.set(hpr.getY())
  1285. self.hprR.set(hpr.getZ())
  1286. self.scale.set(scale.getX())
  1287. return
  1288. def trackDataFromSceneCollision(self, pos=Point3(0,0,0), hpr=Vec3(0,0,0), scale=Point3(0,0,0)):
  1289. self.posX.set(pos.getX())
  1290. self.posY.set(pos.getY())
  1291. self.posZ.set(pos.getZ())
  1292. self.hprH.set(hpr.getX())
  1293. self.hprP.set(hpr.getY())
  1294. self.hprR.set(hpr.getZ())
  1295. self.scale.set(scale.getX())
  1296. return