propertyWindow.py 69 KB

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