blenderPodExporter.py 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052
  1. #!BPY
  2. """
  3. Name: 'POD (.pod)'
  4. Blender: 248
  5. Group: 'Export'
  6. Tooltip: 'exporter to POD file format'
  7. """
  8. bppversion = "0.1" # version of library(so,dll) to load
  9. import sys
  10. from ctypes import *
  11. from Blender import *
  12. from os import *
  13. from math import *
  14. from operator import itemgetter
  15. # Some Constants and defines
  16. MAXIMAL_VARIATION = 0.00001
  17. EPODDataNone = 0
  18. EPODDataFloat = 1
  19. EPODDataInt = 2
  20. EPODDataUnsignedShort = 3
  21. EPODDataRGBA = 4
  22. EPODDataARGB = 5
  23. EPODDataD3DCOLOR = 6
  24. EPODDataUBYTE4 = 7
  25. EPODDataDEC3N = 8
  26. EPODDataFixed16_16 = 9
  27. EPODDataUnsignedByte = 10
  28. EPODDataShort = 11
  29. EPODDataShortNorm = 12
  30. EPODDataByte = 13
  31. EPODDataByteNorm = 14
  32. types_dict = { EPODDataNone : "EPODDataNone",
  33. EPODDataFloat : "float",
  34. EPODDataInt : "int",
  35. EPODDataUnsignedShort : "unsigned short",
  36. EPODDataRGBA : "RGBA",
  37. EPODDataARGB : "ARGB",
  38. EPODDataD3DCOLOR : "D3DCOLOR",
  39. EPODDataUBYTE4 : "EPODDataUBYTE4", # this one does not correspond to anything
  40. EPODDataDEC3N : "DEC3N",
  41. EPODDataFixed16_16 : "fixed 16.16",
  42. EPODDataUnsignedByte : "unsigned byte",
  43. EPODDataShort : "short",
  44. EPODDataShortNorm : "short, normalised",
  45. EPODDataByte : "byte",
  46. EPODDataByteNorm : "byte, normalised"
  47. }
  48. types_indices = { "ARGB" : 1,
  49. "byte":2,
  50. "byte, normalised":3,
  51. "D3DCOLOR":4,
  52. "DEC3N":5,
  53. "fixed 16.16":6,
  54. "float":7,
  55. "int":8,
  56. "RGBA":9,
  57. "short":10,
  58. "short, normalised":11,
  59. "unsigned byte":12,
  60. "unsigned short":13}
  61. # ESkinType
  62. ePODSkin = 0
  63. ePhysiqueSkin = 1
  64. # EPODLight
  65. ePODPoint=0 # Point light
  66. ePODDirectional=1 # Directional light
  67. ePODSpot=2 # Spot light
  68. # EPODCamera
  69. eFreeCamera = 0
  70. eTargetCamera = 1
  71. #ECNodeTypes
  72. eDummyCNode = 0
  73. eMeshCNode = 1
  74. eCameraCNode = 2
  75. eLightCNode = 3
  76. eBoneCNode = 4
  77. DLGOPT_UVW_OPT_REMEMBERED = 8
  78. DLGOPT_VECTOR_X = 0x01
  79. DLGOPT_VECTOR_Y = 0x02
  80. DLGOPT_VECTOR_Z = 0x04
  81. DLGOPT_VECTOR_W = 0x08
  82. DLGOPT_VECTOR_MASK = 0x0F
  83. MAX_UV_COORD = 8
  84. eOGL = 0
  85. eD3D = 1
  86. ePOD = 0
  87. eH = 1
  88. eNone = 0
  89. e590Blocks = 1
  90. eD3DX = 2
  91. ePVRTTriStrip = 3
  92. eList = 0
  93. eStrip = 1
  94. PODfilename = "obiekt.pod"
  95. # ID that should be unique for each node
  96. uniqueID = 0
  97. # Events identifiers list
  98. ID_POSITION_EVT_TYPE = 1110
  99. ID_POSITION_EVT_A1 = 1111
  100. ID_POSITION_EVT_A2 = 1112
  101. ID_POSITION_EVT_A3 = 1113
  102. ID_NORMAL_EVT_TYPE = 1120
  103. ID_NORMAL_EVT_A1 = 1121
  104. ID_NORMAL_EVT_A2 = 1122
  105. ID_NORMAL_EVT_A3 = 1123
  106. ID_TANGENT_EVT_TYPE = 1130
  107. ID_TANGENT_EVT_A1 = 1131
  108. ID_TANGENT_EVT_A2 = 1132
  109. ID_TANGENT_EVT_A3 = 1133
  110. ID_BINORMAL_EVT_TYPE = 1140
  111. ID_BINORMAL_EVT_A1 = 1141
  112. ID_BINORMAL_EVT_A2 = 1142
  113. ID_BINORMAL_EVT_A3 = 1143
  114. ID_COLOUR_EVT_TYPE = 1260
  115. ID_COLOUR_EVT_A1 = 1261
  116. ID_COLOUR_EVT_A2 = 1262
  117. ID_COLOUR_EVT_A3 = 1263
  118. ID_COLOUR_EVT_A4 = 1264
  119. ID_BONE_INDICES_EVT_TYPE = 1150
  120. ID_BONE_INDICES_EVT_A1 = 1151
  121. ID_BONE_INDICES_EVT_A2 = 1152
  122. ID_BONE_INDICES_EVT_A3 = 1153
  123. ID_BONE_INDICES_EVT_A4 = 1154
  124. ID_BONE_WEIGHTS_EVT_TYPE = 1160
  125. ID_BONE_WEIGHTS_EVT_A1 = 1161
  126. ID_BONE_WEIGHTS_EVT_A2 = 1162
  127. ID_BONE_WEIGHTS_EVT_A3 = 1163
  128. ID_BONE_WEIGHTS_EVT_A4 = 1164
  129. ID_UVW0_EVT_TYPE = 1170
  130. ID_UVW0_EVT_A1 = 1171
  131. ID_UVW0_EVT_A2 = 1172
  132. ID_UVW0_EVT_A3 = 1173
  133. ID_UVW1_EVT_TYPE = 1180
  134. ID_UVW1_EVT_A1 = 1181
  135. ID_UVW1_EVT_A2 = 1182
  136. ID_UVW1_EVT_A3 = 1183
  137. ID_UVW2_EVT_TYPE = 1190
  138. ID_UVW2_EVT_A1 = 1191
  139. ID_UVW2_EVT_A2 = 1192
  140. ID_UVW2_EVT_A3 = 1193
  141. ID_UVW3_EVT_TYPE = 1210
  142. ID_UVW3_EVT_A1 = 1211
  143. ID_UVW3_EVT_A2 = 1212
  144. ID_UVW3_EVT_A3 = 1213
  145. ID_UVW4_EVT_TYPE = 1220
  146. ID_UVW4_EVT_A1 = 1221
  147. ID_UVW4_EVT_A2 = 1222
  148. ID_UVW4_EVT_A3 = 1223
  149. ID_UVW5_EVT_TYPE = 1230
  150. ID_UVW5_EVT_A1 = 1231
  151. ID_UVW5_EVT_A2 = 1232
  152. ID_UVW5_EVT_A3 = 1233
  153. ID_UVW6_EVT_TYPE = 1240
  154. ID_UVW6_EVT_A1 = 1241
  155. ID_UVW6_EVT_A2 = 1242
  156. ID_UVW6_EVT_A3 = 1243
  157. ID_UVW7_EVT_TYPE = 1250
  158. ID_UVW7_EVT_A1 = 1251
  159. ID_UVW7_EVT_A2 = 1252
  160. ID_UVW7_EVT_A3 = 1253
  161. primitive_type_menu = 0
  162. triangle_sorting_method_menu = 0
  163. static_frame_button = 0
  164. max_simulatnous_matrices_button = 0
  165. position_data_type_menu = 0
  166. normal_data_type_menu = 0
  167. tangent_data_type_menu = 0
  168. binormal_data_type_menu = 0
  169. colour_data_type_menu = 0
  170. bone_indices_data_type_menu = 0
  171. bone_weights_data_type_menu = 0
  172. uvw0_data_type_menu = 0
  173. uvw1_data_type_menu = 0
  174. uvw2_data_type_menu = 0
  175. uvw3_data_type_menu = 0
  176. uvw4_data_type_menu = 0
  177. uvw5_data_type_menu = 0
  178. uvw6_data_type_menu = 0
  179. uvw7_data_type_menu = 0
  180. listOfAddedObjects = {}
  181. class MyVectorOpt(Structure):
  182. _fields_ = [("eType",c_int),("nEnable",c_uint)]
  183. def __init__(self):
  184. self.eType = EPODDataFloat
  185. self.nEnable = DLGOPT_VECTOR_X | DLGOPT_VECTOR_Y | DLGOPT_VECTOR_Z | DLGOPT_VECTOR_W | DLGOPT_VECTOR_MASK
  186. class FormatDescription:
  187. def __init__(self):
  188. self.type = 0
  189. self.evt_type = 0
  190. self.evt1 = 0
  191. self.evt2 = 0
  192. self.evt3 = 0
  193. self.evt4 = 0
  194. self.enabled = 0
  195. def __init__(self,atype,aevt_type,aevt1,aevt2,aevt3,aevt4,aenabled):
  196. self.type = atype
  197. self.evt_type = aevt_type
  198. self.evt1 = aevt1
  199. self.evt2 = aevt2
  200. self.evt3 = aevt3
  201. self.evt4 = aevt4
  202. self.enabled = aenabled
  203. class MyOptions(Structure):
  204. _fields_ = [("staticFrame",c_int),("eExpFormat",c_int),("exportGeom",c_int),("exportNormals",c_int),("exportVertexColor",c_int),("exportControllers",c_int),
  205. ("exportMappingChannel",c_int),("exportMaterials",c_int),("exportSplines",c_int),("exportSkin",c_int),("exportObjectSpace",c_int),
  206. ("exportBoneGeometry",c_int),("exportMatrices",c_int),("cS",c_int),("dwBoneLimit",c_uint),("eTriSort",c_int),("bSortVtx",c_int),("ePrimType",c_int),
  207. ("bIndexed",c_int),("bInterleaved",c_int),("bTangentSpace",c_int),("bFixedPoint",c_int),("bFlipTextureV",c_int),("fTangentSpaceVtxSplit",c_float),
  208. ("sVcOptPos",MyVectorOpt),("sVcOptNor",MyVectorOpt),("sVcOptTan",MyVectorOpt),("sVcOptBin",MyVectorOpt),("sVcOptCol",MyVectorOpt),
  209. ("sVcOptBoneInd",MyVectorOpt),("sVcOptBoneWt",MyVectorOpt),("psVcOptUVW", DLGOPT_UVW_OPT_REMEMBERED * MyVectorOpt),
  210. ("sClPostTarget",c_char_p),("sClPostArgs",c_char_p),("sClPostCWD",c_char_p),("m_sSerialisedOpt",c_char_p)]
  211. def __init__(self):
  212. # set default values of export options
  213. self.staticFrame = 0
  214. self.eExpFormat = ePOD
  215. self.exportGeom = 1
  216. self.exportNormals = 1
  217. self.exportVertexColor = 0
  218. self.exportControllers = 0
  219. self.exportMappingChannel = 1
  220. self.exportMaterials = 1
  221. self.exportSplines = 0
  222. self.exportSkin = 0
  223. self.exportObjectSpace = 1
  224. self.exportBoneGeometry = 0
  225. self.exportMatrices = 0
  226. self.cS = eOGL
  227. self.dwBoneLimit = 9
  228. self.eTriSort = eNone
  229. self.bSortVtx = 0
  230. self.ePrimType = eList
  231. self.bIndexed = 1
  232. self.bInterleaved = 1
  233. self.bTangentSpace = 0
  234. self.bFixedPoint = 0
  235. self.bFlipTextureV = 0
  236. self.fTangentSpaceVtxSplit = 0
  237. self.sVcOptPos = MyVectorOpt()
  238. self.sVcOptNor = MyVectorOpt()
  239. self.sVcOptTan = MyVectorOpt()
  240. self.sVcOptBin = MyVectorOpt()
  241. self.sVcOptCol = MyVectorOpt()
  242. self.sVcOptCol.eType = EPODDataARGB
  243. self.sVcOptCol.nEnable = DLGOPT_VECTOR_X | DLGOPT_VECTOR_Y | DLGOPT_VECTOR_Z | DLGOPT_VECTOR_W
  244. self.sVcOptBoneInd.eType = EPODDataUnsignedByte
  245. self.sVcOptBoneInd.nEnable = DLGOPT_VECTOR_X | DLGOPT_VECTOR_Y | DLGOPT_VECTOR_Z | DLGOPT_VECTOR_W
  246. self.sVcOptBoneWt.eType = EPODDataFloat
  247. self.sVcOptBoneWt.nEnable = DLGOPT_VECTOR_X | DLGOPT_VECTOR_Y | DLGOPT_VECTOR_Z | DLGOPT_VECTOR_W
  248. for i in range(0,DLGOPT_UVW_OPT_REMEMBERED):
  249. self.psVcOptUVW[i] = MyVectorOpt()
  250. self.psVcOptUVW[i].nEnable &= ~DLGOPT_VECTOR_Z
  251. self.sClPostTarget = ""
  252. self.sClPostArgs = ""
  253. self.sClPostCWD = ""
  254. # Export options
  255. export_options = MyOptions()
  256. # additional globals
  257. chosen_page = 0
  258. number_of_raw = 0
  259. class MyVec3f(Structure):
  260. _fields_ = [("x",c_float),("y",c_float),("z",c_float)]
  261. def __init__(self,ax,ay,az):
  262. self.x = c_float(ax)
  263. self.y = c_float(ay)
  264. self.z = c_float(az)
  265. class MyVec4f(Structure):
  266. _fields_ = [("x",c_float),("y",c_float),("z",c_float), ("w",c_float)]
  267. class MyQuaternionf(Structure):
  268. _fields_ = [("x",c_float),("y",c_float),("z",c_float),("w",c_float)]
  269. class MyMatrixf(Structure):
  270. _fields_ = [("f",c_float * 16)]
  271. class SceneInfo(Structure):
  272. _fields_ = [("m_startFrame",c_int),("m_endFrame",c_int),("m_ambient",MyVec3f)]
  273. class MyMaterial(Structure):
  274. _fields_ = [("sName",c_char_p),("sTexDiffuse",c_char_p),("sTexAmbient",c_char_p),("sTexSpecularColour",c_char_p),
  275. ("sTexSpecularLevel",c_char_p),("sTexBump",c_char_p),("sTexEmissive",c_char_p),
  276. ("sTexGlossiness",c_char_p),("sTexOpacity",c_char_p),("sTexReflection",c_char_p),
  277. ("sTexRefraction",c_char_p),("vDiffuse",MyVec3f),("vAmbient",MyVec3f),("vSpecular",MyVec3f),
  278. ("fOpacity",c_float),("fGlossiness",c_float),("fSpecularLevel",c_float),
  279. ("sPFXFileName",c_char_p),("sPFXEffectName",c_char_p)]
  280. def __init__(self):
  281. self.sName = c_char_p("")
  282. self.fOpacity = c_float(0.0)
  283. self.fGlossiness = c_float(0.0)
  284. self.fSpecularLevel = c_float(0.0)
  285. self.vDiffuse.x = self.vDiffuse.y = self.vDiffuse.z = c_float(0.0)
  286. self.vAmbient.x = self.vAmbient.y = self.vAmbient.z = c_float(0.0)
  287. self.vSpecular.xyz = c_float(0.0)
  288. self.sTexDiffuse = c_char_p("")
  289. self.sTexAmbient = c_char_p("")
  290. self.sTexSpecularColour = c_char_p("")
  291. self.sTexSpecularLevel = c_char_p("")
  292. self.sTexBump = c_char_p("")
  293. self.sTexEmissive = c_char_p("")
  294. self.sTexGlossiness = c_char_p("")
  295. self.sTexOpacity = c_char_p("")
  296. self.sTexReflection = c_char_p("")
  297. self.sTexRefraction = c_char_p("")
  298. self.sPFXFileName = c_char_p("")
  299. self.sPFXEffectName = c_char_p("")
  300. class SScale(Structure):
  301. _fields_ = [ ("f0",c_float),("f1",c_float) ,("f2",c_float) ,("f3",c_float) ,("f4",c_float) , ("f5",c_float), ("f6",c_float) ]
  302. class SLightData(Structure):
  303. _fields_ = [("eType",c_int),("vColour",MyVec3f),("nTargetID",c_int),("fConstantAttenuation",c_float),("fLinearAttenuation",c_float),
  304. ("fQuadraticAttenuation",c_float),("fFalloffAngle",c_float),("fFalloffExponent",c_float)]
  305. def __init__(self):
  306. self.eType = 0
  307. self.nTargetID = -1
  308. self.fConstantAttenuation = c_float(1.0)
  309. self.fLinearAttenuation = c_float(0.0)
  310. self.fQuadraticAttenuation = c_float(0.0)
  311. self.fFalloffAngle = c_float(radians(180))
  312. self.fFalloffExponent = c_float(0.0)
  313. class SCameraData(Structure):
  314. _fields_ = [("eType",c_int),("fFOV",c_float),("fFarClip",c_float),("fNearClip",c_float),("nTargetID",c_int)]
  315. def __init__(self):
  316. self.eType = 0
  317. self.nTargetID = -1
  318. self.fFOV = 0.0
  319. class SNodeTM(Structure):
  320. _fields_ = [("vPos",MyVec3f),("qRot",MyQuaternionf),("sScale",SScale),("fMatrix",MyMatrixf)]
  321. class CBoneWeight(Structure):
  322. _fields_ = [("nBone",c_int),("fWeight",c_float)]
  323. def __init__(self):
  324. self.nBone = -1
  325. self.fWeight = 1.0
  326. class SBonedVtx(Structure):
  327. _fields_ = [("vBone",POINTER(CBoneWeight)),("numvBone",c_int)]
  328. def __init__(self):
  329. self.vBone = None
  330. self.numvBone = 0
  331. class SModifier(Structure):
  332. _fields_ = [("sName",c_char_p),("eSkinType",c_int),("bIsSkin",c_int),("vVtx",POINTER(SBonedVtx)),("numvVtx",c_int)]
  333. def __init__(self):
  334. self.sName = c_char_p("")
  335. self.eSkinType = ePODSkin
  336. self.bIsSkin = 0 # False - no skinning at the beginning
  337. self.numvVtx = 0
  338. self.vVtx = None
  339. class CTriIdx(Structure):
  340. _fields_ = [("i",c_int * 3)]
  341. def __init__(self):
  342. self.i[0] = -1
  343. self.i[1] = -1
  344. self.i[2] = -1
  345. class SFace(Structure):
  346. _fields_ = [("sVtx",CTriIdx),("smGrp",c_int),("sNrm",CTriIdx),("sVtxCol",CTriIdx)]
  347. def __init__(self):
  348. self.sVtx = CTriIdx()
  349. self.sNrm = CTriIdx()
  350. self.sVtxCol = CTriIdx()
  351. class SMappingChannel(Structure):
  352. _fields_ = [("vVtx",POINTER(MyVec3f)),("vIdx",POINTER(CTriIdx)),("numvVtx",c_int),("numvIdx",c_int) ]
  353. def __init__(self):
  354. self.vVtx = None
  355. self.numvVtx = 0
  356. self.vIdx = None
  357. self.numvIdx = 0
  358. class SGeomData(Structure):
  359. _fields_ = [("vVtx",POINTER(MyVec3f)),("vNrm",POINTER(MyVec3f)),("vCol",POINTER(MyVec4f)),("vFace",POINTER(SFace)),("vMap",POINTER(SMappingChannel)),
  360. ("numvVtx",c_int),("numvNrm",c_int),("numvCol",c_int),("numvFace",c_int),("numvMap",c_int)]
  361. def __init__(self):
  362. self.vVtx = None
  363. self.numvVtx = 0
  364. self.vNrm = None
  365. self.numvNrm = 0
  366. self.vCol = None
  367. self.numvCol = 0
  368. self.vFace = None
  369. self.numvFace = 0
  370. self.vMap = None
  371. self.numvMap = 0
  372. class MyNode(Structure):
  373. _fields_ = [("nID",c_int),("nParentID",c_int),("nMaterialIndex",c_int),("sName",c_char_p),("eNodeType",c_int),
  374. ("sNode",SNodeTM),("sGeomData",SGeomData),("vAnim",POINTER(SNodeTM)),("numvAnim",c_int),("sLightData",SLightData),("sCameraData",SCameraData),
  375. ("vModData",POINTER(SModifier)),("numvModData",c_int)]
  376. def __init__(self):
  377. self.nID = 0
  378. self.nParentID = -1
  379. self.nMaterialIndex = -1
  380. self.sName = ""
  381. self.eNodeType = 0
  382. self.sNode = SNodeTM()
  383. self.sGeomData = SGeomData()
  384. self.sLightData = SLightData()
  385. self.sCameraData = SCameraData()
  386. self.vModData = None
  387. self.numvModData = 0
  388. self.vAnim = None
  389. self.numvAnim = 0
  390. # TODO: proper texture picking not first enabled
  391. def addSceneMaterials(pvrgp):
  392. tobeadded = MyMaterial()
  393. matlist = Material.Get()
  394. for mat in matlist:
  395. # get the list of txtures for given material
  396. mattextures = mat.getTextures()
  397. tobeadded.sName = c_char_p(mat.getName())
  398. tobeadded.fOpacity = c_float(mat.getAlpha())
  399. # TODO: check if hardness is ok
  400. tobeadded.fGlossiness = c_float((mat.getHardness() -1) /float(510))
  401. # TODO check if specular level is fine
  402. tobeadded.fSpecularLevel = c_float(mat.getSpec())
  403. tobeadded.vDiffuse.x = c_float(mat.getRGBCol()[0])
  404. tobeadded.vDiffuse.y = c_float(mat.getRGBCol()[1])
  405. tobeadded.vDiffuse.z = c_float(mat.getRGBCol()[2])
  406. # World Ambient is multiplied by material ambient factor ,TODO: is it right?
  407. tobeadded.vAmbient.x = c_float(World.GetCurrent().getAmb()[0] * mat.getAmb())
  408. tobeadded.vAmbient.y = c_float(World.GetCurrent().getAmb()[1] * mat.getAmb())
  409. tobeadded.vAmbient.z = c_float(World.GetCurrent().getAmb()[2] * mat.getAmb())
  410. tobeadded.vSpecular.x = c_float(mat.getSpecCol()[0])
  411. tobeadded.vSpecular.y = c_float(mat.getSpecCol()[1])
  412. tobeadded.vSpecular.z = c_float(mat.getSpecCol()[2])
  413. # and so far first active texture is being assumed to be diffuse texture (if any)
  414. if len(mat.enabledTextures) > 0 and mat.getTextures()[mat.enabledTextures[0]].tex.getImage() != None:
  415. tobeadded.sTexDiffuse = c_char_p(mat.getTextures()[mat.enabledTextures[0]].tex.getImage().getName())
  416. print "Texture attached: ",tobeadded.sTexDiffuse
  417. else:
  418. print "No texture exported"
  419. tobeadded.sTexDiffuse = c_char_p("")
  420. # TODO: other textures if avilable
  421. tobeadded.sTexAmbient = c_char_p("")
  422. tobeadded.sTexSpecularColour = c_char_p("")
  423. tobeadded.sTexSpecularLevel = c_char_p("")
  424. tobeadded.sTexBump = c_char_p("")
  425. tobeadded.sTexEmissive = c_char_p("")
  426. tobeadded.sTexGlossiness = c_char_p("")
  427. tobeadded.sTexOpacity = c_char_p("")
  428. tobeadded.sTexReflection = c_char_p("")
  429. tobeadded.sTexRefraction = c_char_p("")
  430. tobeadded.sPFXFileName = c_char_p("")
  431. tobeadded.sPFXEffectName = c_char_p("")
  432. pvrgp.AddMaterial(byref(tobeadded))
  433. def addSceneLamp(pvrgp,obiekt,parentID):
  434. global uniqueID
  435. tobefilled = MyNode()
  436. returnvalue = -1
  437. if obiekt.getType() == "Lamp":
  438. lamp = obiekt.getData()
  439. tobefilled.nID = uniqueID # ujique ID
  440. returnvalue = uniqueID
  441. uniqueID+=1
  442. tobefilled.nParentID = parentID
  443. tobefilled.nMaterialIndex = -1
  444. tobefilled.sName = lamp.name
  445. tobefilled.eNodeType = eLightCNode
  446. tobefilled.sNode = SNodeTM()
  447. tobefilled.sGeomData = SGeomData()
  448. tobefilled.sLightData = SLightData()
  449. tobefilled.sCameraData = SCameraData()
  450. tobefilled.vModData = None
  451. tobefilled.numvModData = 0
  452. tobefilled.vAnim = None
  453. tobefilled.numvAnim = 0
  454. if lamp.type == Lamp.Types["Spot"]:
  455. tobefilled.sLightData.eType = c_int(ePODSpot)
  456. tobefilled.sLightData.fFalloffAngle = c_float(radians(lamp.getSpotSize()))
  457. tobefilled.sLightData.fFalloffExponent = c_float(0.0)
  458. tobefilled.sLightData.fConstantAttenuation = c_float(1.0 - lamp.energy)
  459. tobefilled.sLightData.fLinearAttenuation = c_float( (0.5 - (1.0 - lamp.energy))/lamp.dist)
  460. tobefilled.sLightData.fQuadraticAttenuation = c_float(0.0)
  461. elif lamp.type == Lamp.Types["Lamp"]: # Point
  462. print "ePODPoint: ",ePODPoint
  463. tobefilled.sLightData.eType = c_int(ePODPoint)
  464. tobefilled.sLightData.fFalloffAngle = c_float(radians(180))
  465. tobefilled.sLightData.fFalloffExponent = c_float(0.0)
  466. tobefilled.sLightData.fConstantAttenuation = c_float(1.0 - lamp.energy)
  467. tobefilled.sLightData.fLinearAttenuation = c_float( (0.5 - (1.0 - lamp.energy))/lamp.dist)
  468. tobefilled.sLightData.fQuadraticAttenuation = c_float(0.0)
  469. elif lamp.type == Lamp.Types["Sun"]:
  470. tobefilled.sLightData.eType = c_int(ePODDirectional)
  471. tobefilled.sLightData.fFalloffAngle = c_float(radians(180))
  472. tobefilled.sLightData.fFalloffExponent = c_float(0.0)
  473. tobefilled.sLightData.fConstantAttenuation = c_float(1.0)
  474. tobefilled.sLightData.fLinearAttenuation = c_float(0.0)
  475. tobefilled.sLightData.fQuadraticAttenuation = c_float(0.0)
  476. else:
  477. return
  478. tobefilled.vColour = MyVec3f(lamp.R,lamp.G,lamp.B)
  479. tobefilled.nTargetID = -1 # no target light source
  480. mv = obiekt.getMatrix("localspace")
  481. # do the conversion if only there is no parent (final transformation is multiplied by one)
  482. if parentID == -1:
  483. nmv = mat4x4DirectX2OpenGLCoords(mv.copy())
  484. else:
  485. nmv = mv.copy()
  486. matrixToSNodeTM(tobefilled.sNode, nmv)
  487. # copy transformation matrix of the current frame which should be frame 1
  488. Set('curframe',1)
  489. for i in range(0,4):
  490. for j in range(0,4):
  491. tobefilled.sNode.fMatrix.f[i*4+j] = nmv[i][j]
  492. # IPO (animtaion) if any
  493. if export_options.exportControllers == 1 and obiekt.getIpo() != None:
  494. # Go through all frames and get modelview matrices for this object
  495. startframe = Get('staframe')
  496. endframe = Get('endframe')
  497. # allocate space for animation data (number)
  498. tobefilled.numvAnim = c_int(endframe)
  499. tobefilled.vAnim = (endframe*SNodeTM)()
  500. for fridx in range(0,endframe):
  501. tobefilled.vAnim[fridx] = SNodeTM()
  502. for framenum in range(startframe,endframe+1):
  503. Set('curframe',framenum)
  504. mv = obiekt.getMatrix("localspace")
  505. if parentID == -1:
  506. nmv = mat4x4DirectX2OpenGLCoords(mv.copy())
  507. else:
  508. nmv = mv.copy()
  509. for i in range(0,4):
  510. for j in range(0,4):
  511. tobefilled.vAnim[framenum-1].fMatrix.f[i*4+j] = nmv[i][j]
  512. matrixToSNodeTM(tobefilled.vAnim[framenum-1], nmv)
  513. # pass it to POD
  514. pvrgp.AddNode(byref(tobefilled))
  515. return returnvalue
  516. def addSceneCamera(pvrgp,obiekt,parentID):
  517. global uniqueID
  518. global export_options
  519. tobefilled = MyNode()
  520. returnvalue = -1
  521. if obiekt.getType() == "Camera":
  522. camera = obiekt.getData()
  523. if camera.type == "persp":
  524. tobefilled.nID = uniqueID
  525. returnvalue = uniqueID
  526. uniqueID+=1
  527. tobefilled.nParentID = parentID
  528. tobefilled.nMaterialIndex = -1
  529. tobefilled.sName = camera.name
  530. tobefilled.eNodeType = eCameraCNode
  531. tobefilled.sNode = SNodeTM()
  532. tobefilled.sGeomData = SGeomData()
  533. tobefilled.sLightData = SLightData()
  534. tobefilled.sCameraData = SCameraData()
  535. tobefilled.vModData = None
  536. tobefilled.numvModData = 0
  537. tobefilled.vAnim = None
  538. tobefilled.numvAnim = 0
  539. # CamerData should be filled in
  540. tobefilled.sCameraData.fFOV = c_float(radians(camera.angle))
  541. tobefilled.sCameraData.fFarClip = c_float(camera.clipEnd)
  542. tobefilled.sCameraData.fNearClip = c_float(camera.clipStart)
  543. # TODO: target camera
  544. tobefilled.sCameraData.nTargetID = -1 # free camera
  545. # OpenGL coords require to be rotated to be exported to POD
  546. # For POD we need to change coordinates system.
  547. # So we rotate by 90,180,180 and then camera rotation angles to be applied
  548. # also are tranformed x => -x (why minus?), y => z , z => -y
  549. # NOTE: do not used setMatrix method becouse it does not update IPO.. however getMatrix return final matrix
  550. # so executing : mat = obiekt.getMatrix(`localspace`) obiekt.setMatrix(`localspace`)
  551. # print "camera angles: x=",obiekt.getEuler().x*180.0/3.141592653," y=",obiekt.getEuler().y*180.0/3.141592653," z=",obiekt.getEuler().z*180.0/3.141592653
  552. mv = obiekt.getMatrix("localspace")
  553. if parentID == -1:
  554. nmv = mat4x4DirectX2OpenGLCoords(mv.copy())
  555. else:
  556. nmv = mv.copy()
  557. matrixToSNodeTM(tobefilled.sNode, nmv)
  558. # copy transformation matrix of the current frame which should be frame 1
  559. Set('curframe',1)
  560. for i in range(0,4):
  561. for j in range(0,4):
  562. tobefilled.sNode.fMatrix.f[i*4+j] = nmv[i][j]
  563. # IPO (animtaion) if any
  564. if export_options.exportControllers == 1 and obiekt.getIpo() != None:
  565. # Go through all frames and get modelview matrices for this object
  566. startframe = Get('staframe')
  567. endframe = Get('endframe')
  568. # allocate space for animation data (number)
  569. tobefilled.numvAnim = c_int(endframe)
  570. tobefilled.vAnim = (endframe*SNodeTM)()
  571. for fridx in range(0,endframe):
  572. tobefilled.vAnim[fridx] = SNodeTM()
  573. for framenum in range(startframe,endframe+1):
  574. Set('curframe',framenum)
  575. # again. get original angles, clear coords (return camera to parentspace), roate coords,
  576. #apply original transformation in another coords system
  577. # values to be restores are returned as well as new modelview
  578. mv = obiekt.getMatrix("localspace")
  579. if parentID == -1:
  580. nmv = mat4x4DirectX2OpenGLCoords(mv.copy())
  581. else:
  582. nmv = mv.copy()
  583. for i in range(0,4):
  584. for j in range(0,4):
  585. tobefilled.vAnim[framenum-1].fMatrix.f[i*4+j] = nmv[i][j]
  586. matrixToSNodeTM(tobefilled.vAnim[framenum-1], nmv)
  587. else:
  588. print "NO CAMERA IPO"
  589. # pass it to POD
  590. pvrgp.AddNode(byref(tobefilled))
  591. else:
  592. print "Warning: Orthogonal Camera will not be exported!"
  593. return returnvalue
  594. def showListOfAddedObjects():
  595. for i in listOfAddedObjects:
  596. print "obj: ",i," id=",listOfAddedObjects[i]
  597. return
  598. # This function adds dummy based on given object whatever type
  599. # basically we take parenting info and modelview transformation and we create
  600. # dummy object holding that info. Animation included as well
  601. # ID is assigned based on the value that was passed to that function
  602. def addSceneDummyOrBone(pvrgp,obiekt,typobiektu,tobeassignedID,parentID):
  603. global export_options
  604. tobefilled = MyNode()
  605. returnvalue = -1
  606. obiektname = obiekt.getName()
  607. tobefilled.nID = tobeassignedID
  608. returnvalue = tobeassignedID
  609. tobefilled.nParentID = parentID
  610. tobefilled.nMaterialIndex = -1
  611. tobefilled.sName = obiektname
  612. tobefilled.eNodeType = typobiektu #eDummyCNode,eBoneCNode
  613. tobefilled.sNode = SNodeTM()
  614. tobefilled.sGeomData = SGeomData()
  615. tobefilled.sLightData = SLightData()
  616. tobefilled.sCameraData = SCameraData()
  617. tobefilled.vModData = None
  618. tobefilled.numvModData = 0
  619. tobefilled.vAnim = None
  620. tobefilled.numvAnim = 0
  621. mv = obiekt.getMatrix("localspace")
  622. if parentID == -1:
  623. nmv = mat4x4DirectX2OpenGLCoords(mv.copy())
  624. else:
  625. nmv = mv.copy()
  626. matrixToSNodeTM(tobefilled.sNode, nmv)
  627. # copy transformation matrix of the current frame which should be frame 1
  628. Set('curframe',1)
  629. for i in range(0,4):
  630. for j in range(0,4):
  631. tobefilled.sNode.fMatrix.f[i*4+j] = nmv[i][j]
  632. # IPO (animtaion) if any
  633. if export_options.exportControllers == 1 and obiekt.getIpo() != None:
  634. # Go through all frames and get modelview matrices for this object
  635. startframe = Get('staframe')
  636. endframe = Get('endframe')
  637. # allocate space for animation data (number)
  638. tobefilled.numvAnim = c_int(endframe)
  639. tobefilled.vAnim = (endframe*SNodeTM)()
  640. for fridx in range(0,endframe):
  641. tobefilled.vAnim[fridx] = SNodeTM()
  642. for framenum in range(startframe,endframe+1):
  643. Set('curframe',framenum)
  644. # again. get original angles, clear coords (return camera to parentspace), roate coords,
  645. #apply original transformation in another coords system
  646. # values to be restores are returned as well as new modelview
  647. mv = obiekt.getMatrix("localspace")
  648. if parentID == -1:
  649. nmv = mat4x4DirectX2OpenGLCoords(mv.copy())
  650. else:
  651. nmv = mv.copy()
  652. for i in range(0,4):
  653. for j in range(0,4):
  654. tobefilled.vAnim[framenum-1].fMatrix.f[i*4+j] = nmv[i][j]
  655. matrixToSNodeTM(tobefilled.vAnim[framenum-1], nmv)
  656. else:
  657. print "no IPO for DUMMY"
  658. # pass it to POD
  659. pvrgp.AddNode(byref(tobefilled))
  660. return returnvalue
  661. def addSceneRelativesBones(pvrgp,chainObjects,arm_obiekt,parentid):
  662. global uniqueID
  663. global listOfAddedObjects
  664. parID = parentid
  665. tobefilled = MyNode()
  666. returnvalue = -1
  667. # the eldest come first
  668. for bone in chainObjects:
  669. tobefilled.nID = uniqueID
  670. tobefilled.nParentID = parID
  671. listOfAddedObjects[bone.name] = uniqueID
  672. parID = uniqueID
  673. uniqueID+=1
  674. tobefilled.nMaterialIndex = -1
  675. tobefilled.sName = bone.name
  676. tobefilled.eNodeType = eBoneCNode
  677. tobefilled.sNode = SNodeTM()
  678. tobefilled.sGeomData = SGeomData()
  679. tobefilled.sLightData = SLightData()
  680. tobefilled.sCameraData = SCameraData()
  681. tobefilled.vModData = None
  682. tobefilled.numvModData = 0
  683. tobefilled.vAnim = None
  684. tobefilled.numvAnim = 0
  685. print "Adding Bone: ",bone.name," ID=",tobefilled.nID," parentID=",tobefilled.nParentID
  686. # copy transformation matrix of the current frame which should be frame 1
  687. Set('curframe',1)
  688. arm_obiekt.evaluatePose(1)
  689. # Transformations data is filled below
  690. # We need an transformation according the parent coords (bone space?) coords
  691. mv = bone.poseMatrix #* arm_obiekt.getMatrix()
  692. # since we are given ulitmate pose matrix (once includeing parents transofmraion )
  693. # then we need to transform it back to have a transformation in parent coords not in armature coords (if only there is a parent)
  694. # The matrix is transposed comparing to normal transformation matrix so multiplication
  695. # takes place in reverse order
  696. mvc = mv.copy()
  697. if bone.parent != None:
  698. pmv = bone.parent.poseMatrix
  699. #mvc = pmv.invert()*mvc
  700. mvc = mvc*pmv.invert()
  701. nmv = mvc
  702. # revese z value
  703. matrixToSNodeTM(tobefilled.sNode, nmv)
  704. for i in range(0,4):
  705. for j in range(0,4):
  706. tobefilled.sNode.fMatrix.f[i*4+j] = nmv[i][j]
  707. # Go through all frames and get modelview matrices for this object
  708. startframe = Get('staframe')
  709. endframe = Get('endframe')
  710. # allocate space for animation data (number)
  711. tobefilled.numvAnim = c_int(endframe)
  712. tobefilled.vAnim = (endframe*SNodeTM)()
  713. for fridx in range(0,endframe):
  714. tobefilled.vAnim[fridx] = SNodeTM()
  715. # print "Armature MV Worldmat: ",arm_obiekt.getMatrix()
  716. for framenum in range(startframe,endframe+1):
  717. Set('curframe',framenum)
  718. arm_obiekt.evaluatePose(framenum)
  719. # print "=============================================="
  720. # print "frame: ",framenum," globposemat: ",bone.poseMatrix
  721. mv = bone.poseMatrix #* arm_obiekt.getMatrix()
  722. mvc = mv.copy()
  723. if bone.parent != None:
  724. pmv = bone.parent.poseMatrix
  725. #print "frame: ",framenum," pose: ",bone.poseMatrix*pmv.invert()
  726. #mvc = pmv.invert()*mvc
  727. mvc = mvc*pmv.invert()
  728. nmv = mvc
  729. # print "frame: ",framenum," local bone matrix: ",mvc
  730. for i in range(0,4):
  731. for j in range(0,4):
  732. tobefilled.vAnim[framenum-1].fMatrix.f[i*4+j] = nmv[i][j]
  733. matrixToSNodeTM(tobefilled.vAnim[framenum-1], nmv)
  734. Set('curframe',1)
  735. arm_obiekt.evaluatePose(1)
  736. # Get material index and store it this node
  737. pvrgp.AddNode(byref(tobefilled))
  738. # last one so, the requested bone to be added (rest bones in chain are elder that that)
  739. return parID
  740. def addSceneBones(pvrgp,obiekt,parentID):
  741. global uniqueID
  742. global listOfAddedObjects
  743. chainOfBones = []
  744. returnvalue = -1
  745. armatureID = parentID
  746. if obiekt.getType() == "Armature":
  747. print "Adding Armature Bones , armatureID=",armatureID
  748. pbones = obiekt.getPose().bones
  749. for bone in pbones.keys(): #armature.bones.keys():
  750. tobefilled = MyNode()
  751. # check if bone was already added
  752. if not listOfAddedObjects.has_key(bone):
  753. # now check if given object got a parent, parent has to be added first
  754. # so find first ancastor not added that does not have any objects
  755. # create a list of ancastors to be added in the order starting from the eldest
  756. tmpbone = bone
  757. while pbones[tmpbone].parent != None and (not listOfAddedObjects.has_key(pbones[tmpbone].parent.name)):
  758. chainOfBones.insert(0,pbones[tmpbone])
  759. tmpbone = pbones[tmpbone].parent.name
  760. chainOfBones.insert(0,pbones[tmpbone])
  761. if pbones[tmpbone].parent == None:
  762. parentID = armatureID
  763. else:
  764. parentID = listOfAddedObjects[pbones[tmpbone].parent.name]
  765. print "chainsOFBones to be added: ",chainOfBones
  766. addSceneRelativesBones(pvrgp,chainOfBones,obiekt,parentID)
  767. chainOfBones = []
  768. # tutaj sobie wypisze info jakies
  769. # Dodawanie kosteczki
  770. return returnvalue
  771. def fillInSkinningData(name_of_object,tobefilled,moddata_index,vert_idx,influences,numInfluences):
  772. dictOfInfluences = {}
  773. if numInfluences == 0:
  774. return
  775. for bone, weight in influences:
  776. # print "Influence: id: ",bone," weight: ",weight
  777. dictOfInfluences[bone] = weight
  778. # for more that four bones, sort all in order of decreasing values and get rid of any but for entries with biggest values
  779. if numInfluences > 4:
  780. print "Warning: More than for bones influencing the vertex! Performing striping less inflencial influences"
  781. listOfInfluences = sorted(dictOfInfluences.items(),key=itemgetter(1),reverse=True)
  782. del listOfInfluences[4:]
  783. for bone,weight in listOfInfluences:
  784. dictOfInfluences[bone]=weight
  785. global listOfAddedObjects
  786. # calculate the sum of weights
  787. sumOfWeights = 0
  788. for bone in dictOfInfluences:
  789. sumOfWeights+=dictOfInfluences[bone]
  790. # perform normalization
  791. # For sum of weights close to zero then no normalization will take place
  792. # print "Skiining vert_indx=",vert_idx," lenOfInfluences=",len(dictOfInfluences)
  793. # print "Skiining vert[",vert_idx,"]=",tobefilled.vModData[moddata_index].vVtx[vert_idx]
  794. tobefilled.vModData[moddata_index].vVtx[vert_idx].numvBone = len(dictOfInfluences)
  795. tobefilled.vModData[moddata_index].vVtx[vert_idx].vBone = (len(dictOfInfluences)*CBoneWeight)()
  796. for boneweightidx in range(0,len(dictOfInfluences)):
  797. tobefilled.vModData[moddata_index].vVtx[vert_idx].vBone[boneweightidx] = CBoneWeight()
  798. # For sum of weights close to zero then no normalization will take place
  799. if sumOfWeights < MAXIMAL_VARIATION:
  800. sumOfWeights = 1.0
  801. lidx = 0
  802. for bone in dictOfInfluences:
  803. dictOfInfluences[bone]/=sumOfWeights
  804. if not listOfAddedObjects.has_key(bone):
  805. print "Warning: Mesh (\"",name_of_object,"\") is influenced by vertex group referring to bones that does not exist. Skinning is NOT exported"
  806. return
  807. tobefilled.vModData[moddata_index].vVtx[vert_idx].vBone[lidx].nBone = listOfAddedObjects[bone]
  808. tobefilled.vModData[moddata_index].vVtx[vert_idx].vBone[lidx].fWeight = dictOfInfluences[bone]
  809. # print "filled entry: ",tobefilled.vModData[moddata_index].vVtx[vert_idx].vBone[lidx].nBone," weight=",tobefilled.vModData[moddata_index].vVtx[vert_idx].vBone[lidx].fWeight
  810. lidx+=1
  811. ## print "local influences: ",dictOfInfluences," len of dict: ",len(dictOfInfluences)
  812. return
  813. def addSceneMesh(pvrgp,obiekt,parentID):
  814. global uniqueID
  815. global export_options
  816. returnvalue = -1
  817. tobefilled = MyNode()
  818. editmode = Window.EditMode()
  819. if editmode == 1:
  820. Window.EditMode(0)
  821. if obiekt.getType() == "Mesh":
  822. print "Obiekt: "+obiekt.getName()
  823. mesik_orig = obiekt.getData(False,True)
  824. mesik = mesik_orig.__copy__()
  825. # POD support only faces that are triangles
  826. # converting quads into triangles works only in "face mode"
  827. # which we need to set for that moment
  828. # Get copy of mesh, create new object base on copy of mesh
  829. # so we can freely modify this copy , preserving original scene
  830. orig_scene = Scene.GetCurrent()
  831. tmpobiekt = orig_scene.objects.new(mesik)
  832. mesik.sel = True
  833. oldmode = Mesh.Mode()
  834. Mesh.Mode(Mesh.SelectModes['FACE'])
  835. mesik.quadToTriangle(0)
  836. Mesh.Mode(oldmode)
  837. tobefilled.nID = uniqueID
  838. returnvalue = uniqueID
  839. uniqueID+=1
  840. tobefilled.nParentID = parentID
  841. tobefilled.nMaterialIndex = -1
  842. tobefilled.sName = obiekt.getName()
  843. tobefilled.eNodeType = eMeshCNode
  844. tobefilled.sNode = SNodeTM()
  845. tobefilled.sGeomData = SGeomData()
  846. tobefilled.sLightData = SLightData()
  847. tobefilled.sCameraData = SCameraData()
  848. tobefilled.vModData = None
  849. tobefilled.numvModData = 0
  850. tobefilled.vAnim = None
  851. tobefilled.numvAnim = 0
  852. # Number of stored vertices will be 3 times number of faces
  853. # it is huge redundancy that will be later reduced during POD creation process
  854. tobefilled.sGeomData.numvVtx = c_int(len(mesik.faces)*3)
  855. tobefilled.sGeomData.vVtx = (len(mesik.faces)*3* MyVec3f)()
  856. for vidx in range(0,len(mesik.faces)*3):
  857. tobefilled.sGeomData.vVtx[vidx] = MyVec3f(0,0,0)
  858. if export_options.exportNormals:
  859. tobefilled.sGeomData.numvNrm = c_int(len(mesik.faces)*3)
  860. tobefilled.sGeomData.vNrm = (len(mesik.faces)*3* MyVec3f)()
  861. for vidx in range(0,len(mesik.faces)*3):
  862. tobefilled.sGeomData.vNrm[vidx] = MyVec3f(0,0,0)
  863. if mesik.faceUV == True and export_options.exportMappingChannel:
  864. # amount of entries is 3 per every face (triangle) , becaouse we
  865. # grab texcords per face
  866. print "Exporting mapping channels"
  867. tobefilled.sGeomData.numvMap = 1 # To be changed when supporting many channels
  868. tobefilled.sGeomData.vMap = (tobefilled.sGeomData.numvMap*SMappingChannel)()
  869. for i in range(0,tobefilled.sGeomData.numvMap):
  870. tobefilled.sGeomData.vMap[i].numvVtx = c_int(len(mesik.faces)*3)
  871. tobefilled.sGeomData.vMap[i].vVtx = (len(mesik.faces)*3*MyVec3f)()
  872. for vidx in range(0,len(mesik.faces)*3):
  873. tobefilled.sGeomData.vMap[i].vVtx[vidx] = MyVec3f(0,0,0)
  874. tobefilled.sGeomData.vMap[i].numvIdx = c_int(len(mesik.faces))
  875. tobefilled.sGeomData.vMap[i].vIdx = (len(mesik.faces)*CTriIdx)()
  876. for idx in range(0,len(mesik.faces)):
  877. tobefilled.sGeomData.vMap[i].vIdx[idx] = CTriIdx()
  878. tobefilled.sGeomData.numvFace = c_int(len(mesik.faces))
  879. tobefilled.sGeomData.vFace = (len(mesik.faces) * SFace)()
  880. for idx in range(0,len(mesik.faces)):
  881. tobefilled.sGeomData.vFace[idx] = SFace()
  882. # three colors per face so total number of colours is numFaces*3 (I knowthat it is redundant)
  883. if mesik.vertexColors == True and export_options.exportVertexColor :
  884. tobefilled.sGeomData.numvCol = c_int(len(mesik.faces) * 3)
  885. tobefilled.sGeomData.vCol = (len(mesik.faces) * 3 *MyVec4f)()
  886. for idx in range(0,len(mesik.faces)):
  887. tobefilled.sGeomData.vCol[idx] = MyVec4f()
  888. if export_options.exportSkin :
  889. # TODO: allow more modifiers
  890. # Copy of mesh does not copy
  891. # print "Orig Bone influences: ",mesik_orig.getVertexInfluences(0)
  892. if len(mesik_orig.getVertexInfluences(0)):
  893. print "Object(Mesh): ",obiekt.getName()," Skinning exported"
  894. tobefilled.numvModData = 1
  895. tobefilled.vModData = (tobefilled.numvModData*SModifier)()
  896. for i in range(0,tobefilled.numvModData):
  897. tobefilled.vModData[i].sName = c_char_p("Skin")
  898. tobefilled.vModData[i].eSkinType = c_int(ePODSkin)
  899. tobefilled.vModData[i].bIsSkin = c_int(1)
  900. tobefilled.vModData[i].numvVtx = tobefilled.sGeomData.numvVtx
  901. tobefilled.vModData[i].vVtx = (tobefilled.vModData[i].numvVtx*SBonedVtx)()
  902. for vidx in range(0,tobefilled.sGeomData.numvVtx):
  903. tobefilled.sGeomData.vVtx[vidx] = MyVec3f(0,0,0)
  904. # space for bones and weights will be assigned later , according to needs
  905. else:
  906. print "Object(Mesh): ",obiekt.getName()," No Skinning exported"
  907. # Very memory consuming implementation
  908. # Each face got 3 vertices because mesh was converted to be like that
  909. fidx = 0
  910. vidx = 0
  911. colIdx = 0
  912. if export_options.exportNormals:
  913. mesik.calcNormals()
  914. for face in mesik.faces:
  915. # grab the blender vertex data
  916. v0 = mesik.verts[face.v[0].index]
  917. v1 = mesik.verts[face.v[1].index]
  918. v2 = mesik.verts[face.v[2].index]
  919. # adding new vertices
  920. tobefilled.sGeomData.vVtx[vidx].x = v0.co.x
  921. tobefilled.sGeomData.vVtx[vidx].y = v0.co.y
  922. tobefilled.sGeomData.vVtx[vidx].z = v0.co.z
  923. tobefilled.sGeomData.vVtx[vidx+1].x = v1.co.x
  924. tobefilled.sGeomData.vVtx[vidx+1].y = v1.co.y
  925. tobefilled.sGeomData.vVtx[vidx+1].z = v1.co.z
  926. tobefilled.sGeomData.vVtx[vidx+2].x = v2.co.x
  927. tobefilled.sGeomData.vVtx[vidx+2].y = v2.co.y
  928. tobefilled.sGeomData.vVtx[vidx+2].z = v2.co.z
  929. # normals
  930. if export_options.exportNormals:
  931. if face.smooth:
  932. tobefilled.sGeomData.vNrm[vidx].x = v0.no.x
  933. tobefilled.sGeomData.vNrm[vidx].y = v0.no.y
  934. tobefilled.sGeomData.vNrm[vidx].z = v0.no.z
  935. #print "Face smooth normal 0 x=",v0.no.x," y=",v0.no.y," z=",v0.no.z
  936. #vec = Mathutils.Vector(v0.no.x,v0.no.y,v0.no.z)
  937. #vec.normalize()
  938. #print "Face smooth normalized normal 0 x=",vec.x," y=",vec.y," z=",vec.z
  939. #tobefilled.sGeomData.vNrm[vidx].x = vec.x
  940. #tobefilled.sGeomData.vNrm[vidx].y = vec.y
  941. #tobefilled.sGeomData.vNrm[vidx].z = vec.z
  942. tobefilled.sGeomData.vNrm[vidx+1].x = v1.no.x
  943. tobefilled.sGeomData.vNrm[vidx+1].y = v1.no.y
  944. tobefilled.sGeomData.vNrm[vidx+1].z = v1.no.z
  945. #print "Face smooth normal 1 x=",v1.no.x," y=",v1.no.y," z=",v1.no.z
  946. #vec = Mathutils.Vector(v1.no.x,v1.no.y,v1.no.z)
  947. #vec.normalize()
  948. #print "Face smooth normalized normal 1 x=",vec.x," y=",vec.y," z=",vec.z
  949. #tobefilled.sGeomData.vNrm[vidx].x = vec.x
  950. #tobefilled.sGeomData.vNrm[vidx].y = vec.y
  951. #tobefilled.sGeomData.vNrm[vidx].z = vec.z
  952. tobefilled.sGeomData.vNrm[vidx+2].x = v2.no.x
  953. tobefilled.sGeomData.vNrm[vidx+2].y = v2.no.y
  954. tobefilled.sGeomData.vNrm[vidx+2].z = v2.no.z
  955. #print "Face smooth normal 2 x=",v1.no.x," y=",v1.no.y," z=",v1.no.z
  956. #vec = Mathutils.Vector(v2.no.x,v2.no.y,v2.no.z)
  957. #vec.normalize()
  958. #print "Face smooth normalized normal 2 x=",vec.x," y=",vec.y," z=",vec.z
  959. #tobefilled.sGeomData.vNrm[vidx].x = vec.x
  960. #tobefilled.sGeomData.vNrm[vidx].y = vec.y
  961. #tobefilled.sGeomData.vNrm[vidx].z = vec.z
  962. else:
  963. #vec = Mathutils.Vector(face.no.x,face.no.y,face.no.z)
  964. #vec.normalize()
  965. #tobefilled.sGeomData.vNrm[vidx].x = vec.x
  966. #tobefilled.sGeomData.vNrm[vidx].y = vec.y
  967. #tobefilled.sGeomData.vNrm[vidx].z = vec.z
  968. #tobefilled.sGeomData.vNrm[vidx+1].x = vec.x
  969. #tobefilled.sGeomData.vNrm[vidx+1].y = vec.y
  970. #tobefilled.sGeomData.vNrm[vidx+1].z = vec.z
  971. #tobefilled.sGeomData.vNrm[vidx+2].x = vec.x
  972. #tobefilled.sGeomData.vNrm[vidx+2].y = vec.y
  973. #tobefilled.sGeomData.vNrm[vidx+2].z = vec.z
  974. tobefilled.sGeomData.vNrm[vidx].x = face.no.x
  975. tobefilled.sGeomData.vNrm[vidx].y = face.no.y
  976. tobefilled.sGeomData.vNrm[vidx].z = face.no.z
  977. tobefilled.sGeomData.vNrm[vidx+1].x = face.no.x
  978. tobefilled.sGeomData.vNrm[vidx+1].y = face.no.y
  979. tobefilled.sGeomData.vNrm[vidx+1].z = face.no.z
  980. tobefilled.sGeomData.vNrm[vidx+2].x = face.no.x
  981. tobefilled.sGeomData.vNrm[vidx+2].y = face.no.y
  982. tobefilled.sGeomData.vNrm[vidx+2].z = face.no.z
  983. # Only up to 4 bones per vertex are supported
  984. if export_options.exportSkin and len(mesik_orig.getVertexInfluences(0)):
  985. influences = mesik_orig.getVertexInfluences(face.v[0].index)
  986. # print "influences0: ",influences
  987. fillInSkinningData(obiekt.getName(),tobefilled,0,vidx+0,influences,len(influences),)
  988. # print "influences1: ",influences
  989. influences = mesik_orig.getVertexInfluences(face.v[1].index)
  990. # print "influences2: ",influences
  991. fillInSkinningData(obiekt.getName(),tobefilled,0,vidx+1,influences,len(influences),)
  992. # print "influences3: ",influences
  993. influences = mesik_orig.getVertexInfluences(face.v[2].index)
  994. fillInSkinningData(obiekt.getName(),tobefilled,0,vidx+2,influences,len(influences),)
  995. # fill the faces data with our newly created vertex indices
  996. tobefilled.sGeomData.vFace[fidx].sVtx.i[0] = vidx
  997. tobefilled.sGeomData.vFace[fidx].sVtx.i[1] = vidx + 1
  998. tobefilled.sGeomData.vFace[fidx].sVtx.i[2] = vidx + 2
  999. # Normals to vertices correspond to the indices
  1000. if export_options.exportNormals:
  1001. tobefilled.sGeomData.vFace[fidx].sNrm.i[0] = vidx
  1002. tobefilled.sGeomData.vFace[fidx].sNrm.i[1] = vidx + 1
  1003. tobefilled.sGeomData.vFace[fidx].sNrm.i[2] = vidx + 2
  1004. # TODO: colours to be tested
  1005. if mesik.vertexColors == True and export_options.exportVertexColor:
  1006. # add a color to the list of colors
  1007. tobefilled.sGeomData.vCol[colIdx].x = face.col[0].r
  1008. tobefilled.sGeomData.vCol[colIdx].y = face.col[0].g
  1009. tobefilled.sGeomData.vCol[colIdx].z = face.col[0].b
  1010. tobefilled.sGeomData.vCol[colIdx].w = face.col[0].a
  1011. tobefilled.sGeomData.vCol[colIdx+1].x = face.col[1].r
  1012. tobefilled.sGeomData.vCol[colIdx+1].y = face.col[1].g
  1013. tobefilled.sGeomData.vCol[colIdx+1].z = face.col[1].b
  1014. tobefilled.sGeomData.vCol[colIdx+1].w = face.col[1].a
  1015. tobefilled.sGeomData.vCol[colIdx+2].x = face.col[2].r
  1016. tobefilled.sGeomData.vCol[colIdx+2].y = face.col[2].g
  1017. tobefilled.sGeomData.vCol[colIdx+2].z = face.col[2].b
  1018. tobefilled.sGeomData.vCol[colIdx+2].w = face.col[2].a
  1019. # assign color index into POD face data
  1020. tobefilled.sGeomData.vFace[fidx].sVtxCol.i[0] = colIdx
  1021. tobefilled.sGeomData.vFace[fidx].sVtxCol.i[1] = colIdx+1
  1022. tobefilled.sGeomData.vFace[fidx].sVtxCol.i[2] = colIdx+2
  1023. colIdx+=3
  1024. # UV coords
  1025. if mesik.faceUV == True and export_options.exportMappingChannel == 1:
  1026. #print "exportuje UVcoords"
  1027. fillMappingChannelEntry(tobefilled.sGeomData.vMap[0],face,fidx,vidx)
  1028. #print "exported uvs x= ",tobefilled.sGeomData.vMap[0].vVtx[vidx].x," y= ",tobefilled.sGeomData.vMap[0].vVtx[vidx].y," idx=",fidx
  1029. fidx+=1
  1030. vidx+=3
  1031. # Transofmations data is filled below
  1032. # We need an transformation according the local coords
  1033. mv = obiekt.getMatrix("localspace")
  1034. # revese z value
  1035. if parentID == -1:
  1036. nmv = mat4x4DirectX2OpenGLCoords(mv.copy())
  1037. else:
  1038. nmv = mv.copy()
  1039. #print "object being stored: ",tobefilled.sName
  1040. #print "object transformation matrix: ",nmv
  1041. #print "object rotation part of matrix: ",nmv.rotationPart()
  1042. #print "object Euler of matrix: ",nmv.toEuler()
  1043. #newmatrix = nmv.copy()
  1044. #newmatrix.transpose()
  1045. #print "object Euler of transposed matrix: ",newmatrix.toEuler()
  1046. #print "object quaternion:",nmv.toQuat()
  1047. #q = nmv.toEuler().toQuat()
  1048. #print "object euler->quaternion:",q, "angle=",q.angle," axis[0]=",q.axis[0]," axis[1]=",q.axis[1]," axis[2]=",q.axis[2]
  1049. #print "object quat->matrix",q.toMatrix()
  1050. matrixToSNodeTM(tobefilled.sNode, nmv)
  1051. # copy transformation matrix of the current frame which should be frame 1
  1052. Set('curframe',1)
  1053. for i in range(0,4):
  1054. for j in range(0,4):
  1055. tobefilled.sNode.fMatrix.f[i*4+j] = nmv[i][j]
  1056. # IPO (animtaion)
  1057. objIpo = obiekt.getIpo()
  1058. if objIpo != None:
  1059. # Go through all frames and get modelview matrices for this object
  1060. startframe = Get('staframe')
  1061. endframe = Get('endframe')
  1062. # allocate space for animation data (number)
  1063. tobefilled.numvAnim = c_int(endframe)
  1064. tobefilled.vAnim = (endframe*SNodeTM)()
  1065. for fridx in range(0,endframe):
  1066. tobefilled.vAnim[fridx] = SNodeTM()
  1067. for framenum in range(startframe,endframe+1):
  1068. Set('curframe',framenum)
  1069. mv = obiekt.getMatrix("localspace")
  1070. # revese z value
  1071. if parentID == -1:
  1072. nmv = mat4x4DirectX2OpenGLCoords(mv.copy())
  1073. else:
  1074. nmv = mv.copy()
  1075. for i in range(0,4):
  1076. for j in range(0,4):
  1077. tobefilled.vAnim[framenum-1].fMatrix.f[i*4+j] = nmv[i][j]
  1078. matrixToSNodeTM(tobefilled.vAnim[framenum-1], nmv)
  1079. # Get material index and store it this node
  1080. tobefilled.nMaterialIndex = c_int(getMaterialIndex(obiekt.activeMaterial))
  1081. # revert triangulation
  1082. orig_scene.objects.unlink(tmpobiekt)
  1083. pvrgp.AddNode(byref(tobefilled))
  1084. if editmode == 1:
  1085. Window.EditMode(1)
  1086. return returnvalue
  1087. def addSceneRelativesObjects(pvrgp,chainObjects,listOfAddedArmatures,parentid):
  1088. # go throuh all of given object , that should be in
  1089. # the order of obiekt, child, child of child etc...
  1090. global listOfAddedObjects
  1091. global uniqueID
  1092. parID = parentid
  1093. for obiekt in chainObjects:
  1094. # add object
  1095. if obiekt.getType() == "Mesh":
  1096. #print "Mesh: ",obiekt.getName(),", parent: ",obiekt.getParent()," parID=",parID
  1097. listOfAddedObjects[obiekt.getName()] = addSceneMesh(pvrgp,obiekt,parID)
  1098. parID = listOfAddedObjects[obiekt.getName()]
  1099. #print "list: ",listOfAddedObjects
  1100. elif obiekt.getType() == "Camera":
  1101. #print "Camera: ",obiekt.getName(),", parent: ",obiekt.getParent()
  1102. listOfAddedObjects[obiekt.getName()] = addSceneCamera(pvrgp,obiekt,parID)
  1103. parID = listOfAddedObjects[obiekt.getName()]
  1104. #print "list: ",listOfAddedObjects
  1105. elif obiekt.getType() == "Lamp":
  1106. #print "Lamp: ",obiekt.getName(),", parent: ",obiekt.getParent()
  1107. listOfAddedObjects[obiekt.getName()] = addSceneLamp(pvrgp,obiekt,parID)
  1108. parID = listOfAddedObjects[obiekt.getName()]
  1109. #print "list: ",listOfAddedObjects
  1110. elif obiekt.getType() == "Armature":
  1111. # Here we add dummy object holding only transformation and relationships info
  1112. #print "Armature: ",obiekt.getName(),", parent: ",obiekt.getParent()
  1113. # here find the given armature on the list of IDs of armatures and
  1114. # pass ID to function creating dummy
  1115. tobeassignedID = listOfAddedArmatures[obiekt.getName()]
  1116. listOfAddedObjects[obiekt.getName()] = addSceneDummyOrBone(pvrgp,obiekt,eBoneCNode,tobeassignedID,parID)
  1117. parID = listOfAddedObjects[obiekt.getName()]
  1118. #print "list: ",listOfAddedObjects
  1119. elif obiekt.getType() == "Empty":
  1120. tobeassignedID = uniqueID
  1121. uniqueID += 1
  1122. listOfAddedObjects[obiekt.getName()] = addSceneDummyOrBone(pvrgp,obiekt,eDummyCNode,tobeassignedID,parID)
  1123. else:
  1124. print "Another Kind of object: ",obiekt.getType()," name: ",obiekt.getName(),", parent: ",obiekt.getParent()
  1125. def addSceneObjects(pvrgp):
  1126. global listOfAddedObjects
  1127. global uniqueID
  1128. # export z aktywnej sceny
  1129. orig_scene = Scene.GetCurrent()
  1130. listOfAddedObjects = {}
  1131. chainOfObjects = []
  1132. listOfAddedArmatures = {}
  1133. # first passing to get armatures nd add all bones
  1134. # TODO: implement consideration of parents of armatures. Only armature can parent other armature
  1135. for obiekt in orig_scene.objects:
  1136. if obiekt.getType() == "Armature":
  1137. if obiekt.getData().vertexGroups == True:
  1138. listOfAddedArmatures[obiekt.getName()] = uniqueID
  1139. uniqueID += 1
  1140. addSceneBones(pvrgp,obiekt,listOfAddedArmatures[obiekt.getName()])
  1141. # here we record ID passed as a parent of root bone and later the same one will be used
  1142. # for ID of dummy reperesenting Armature object (its World View matrix)
  1143. if obiekt.getData().envelopes == True:
  1144. print "Warning: Export of Envelopes based skinning not implemented!"
  1145. # second passing so that bones are already passed and its IDs are known
  1146. for obiekt in orig_scene.objects:
  1147. # check if object was already added
  1148. #print "OBIEKT to be analyzed: ",obiekt.getName()
  1149. if not listOfAddedObjects.has_key(obiekt.getName()):
  1150. #print "obiekt: ",obiekt.getName()," parent: ",obiekt.getParent()," not added before. Adding!"
  1151. # now check if given object got a parent (Armature objects do not count), parent has to be added first
  1152. # so find first ancastor not added that does not have any objects
  1153. # create a list of ancastors to be added in the order starting from the eldest
  1154. chainOfObjects.append(obiekt)
  1155. tmpobiekt = obiekt
  1156. while tmpobiekt.getParent() != None and (not listOfAddedObjects.has_key(tmpobiekt.getParent().getName())):
  1157. chainOfObjects.insert(0,tmpobiekt)
  1158. tmpobiekt = tmpobiekt.getParent()
  1159. if tmpobiekt.getParent() == None:
  1160. parentID = -1
  1161. else:
  1162. parentID = listOfAddedObjects[tmpobiekt.getParent().getName()]
  1163. addSceneRelativesObjects(pvrgp,chainOfObjects,listOfAddedArmatures,parentID)
  1164. chainOfObjects = []
  1165. # Now some of the bones are parented by Armatures , which is my dummy objects. So we need to
  1166. # update its parents with IDs of dummies
  1167. #for obiekt in listOfAddedObjects:
  1168. return
  1169. # get ID of proper Material for given object
  1170. def getMaterialIndex(activematindex):
  1171. global export_options
  1172. # if activematindex is zero then material not assigned
  1173. # other wise value should decrease by 1
  1174. # if no export of materials was chosen then also put -1
  1175. if export_options.exportMaterials == 1:
  1176. return activematindex - 1
  1177. else:
  1178. return -1
  1179. # Change blender coords (DirectX like coordinates system) to POD coords( OpenGL likecoordinates system)
  1180. # Reverting Z axe is needed
  1181. def mat4x4DirectX2OpenGLCoords(mat):
  1182. # mat_flip = Mathutils.Matrix([1, 0, 0, 0], [0, 1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1])
  1183. # mat*=mat_flip
  1184. # mat[2][0]*= (-1.0)
  1185. # mat[2][1]*= (-1.0)
  1186. # mat[2][2]*= (-1.0)
  1187. # mat[2][3]*= (-1.0)
  1188. return mat
  1189. def matrixToSNodeTM(snode, matrix):
  1190. trans = matrix.translationPart()
  1191. snode.vPos.x = trans[0]
  1192. snode.vPos.y = trans[1]
  1193. snode.vPos.z = trans[2]
  1194. newmatrix = matrix.copy()
  1195. # TODO: find out why transpose is needed here
  1196. newmatrix.transpose()
  1197. qrotate = newmatrix.toEuler().toQuat()
  1198. snode.qRot.x = qrotate.x
  1199. snode.qRot.y = qrotate.y
  1200. snode.qRot.z = qrotate.z
  1201. snode.qRot.w = qrotate.w
  1202. scale = newmatrix.scalePart()
  1203. snode.sScale.f0 = scale[0]
  1204. snode.sScale.f1 = scale[1]
  1205. snode.sScale.f2 = scale[2]
  1206. # not used
  1207. snode.sScale.f3 = 0.0
  1208. snode.sScale.f4 = 0.0
  1209. snode.sScale.f5 = 0.0
  1210. snode.sScale.f6 = 0.0
  1211. # print "matrixToSNode trans(",trans[0],trans[1],trans[2],") rot=(",qrotate[0],qrotate[1],qrotate[2],qrotate[3],")"
  1212. # Clear any global variables
  1213. def clearData():
  1214. global listOfAddedObjects
  1215. listOfAddedObjects = {}
  1216. return
  1217. # args: mapping channel entry, face data, face index, vertex index (next two will be vidx+1 and vidx+2)
  1218. def fillMappingChannelEntry(vMap,face,fidx,vidx):
  1219. vMap.vVtx[vidx].x = (face.uv[0])[0]
  1220. vMap.vVtx[vidx].y = (face.uv[0])[1]
  1221. if len(face.uv[0]) == 3:
  1222. vMap.vVtx[vidx].z = (face.uv[0])[2]
  1223. else:
  1224. vMap.vVtx[vidx].z = 0.0
  1225. vMap.vVtx[vidx+1].x = (face.uv[1])[0]
  1226. vMap.vVtx[vidx+1].y = (face.uv[1])[1]
  1227. if len(face.uv[1]) == 3:
  1228. vMap.vVtx[vidx+1].z = (face.uv[1])[2]
  1229. else:
  1230. vMap.vVtx[vidx+1].z = 0.0
  1231. vMap.vVtx[vidx+2].x = (face.uv[2])[0]
  1232. vMap.vVtx[vidx+2].y = (face.uv[2])[1]
  1233. if len(face.uv[2]) == 3:
  1234. vMap.vVtx[vidx+2].z = (face.uv[2])[2]
  1235. else:
  1236. vMap.vVtx[vidx+2].z = 0.0
  1237. vMap.vIdx[fidx].i[0] = vidx
  1238. vMap.vIdx[fidx].i[1] = vidx + 1
  1239. vMap.vIdx[fidx].i[2] = vidx + 2
  1240. # Callbacks sections and events handling
  1241. def simplecallback(event,val):
  1242. if event == 314:
  1243. Draw.Exit()
  1244. def mycallback(name):
  1245. global PODfilename
  1246. PODfilename = name
  1247. Draw.Register(draw_gui,input_events, gui_events)
  1248. return
  1249. def mycallbackCommand(evt,name):
  1250. global export_options
  1251. export_options.sClPostTarget = c_char_p(name)
  1252. return
  1253. def mycallbackCommandArgs(evt,name):
  1254. global export_options
  1255. export_options.sClPostArgs = c_char_p(name)
  1256. return
  1257. def mycallbackWorkingDir(evt,name):
  1258. global export_options
  1259. export_options.sClPostCWD = c_char_p(name)
  1260. return
  1261. def input_events(evt,val):
  1262. #print "Event: ",evt," value:",val
  1263. return
  1264. ###########################
  1265. # Main Event routine #
  1266. ###########################
  1267. def gui_events(evt):
  1268. global chosen_page
  1269. global number_of_raw
  1270. global export_options
  1271. global types_indices
  1272. global types_dict
  1273. global primitive_type_menu
  1274. if evt == 314:
  1275. libpathtoload = Get('scriptsdir')
  1276. if libpathtoload[0] == "/":
  1277. print "Linux"
  1278. libpathtoload += "/libPVRGeoPOD.so."+bppversion
  1279. else:
  1280. print "Windows"
  1281. libpathtoload += "\libPVRGeoPOD-"+bppversion+".dll"
  1282. print "Loading library: ",libpathtoload
  1283. pvrgp = cdll.LoadLibrary(libpathtoload)
  1284. pvrgp.clearData()
  1285. clearData()
  1286. if export_options.exportMaterials == 1:
  1287. addSceneMaterials(pvrgp)
  1288. addSceneObjects(pvrgp)
  1289. # print "Ambinet: x=",World.GetCurrent().getAmb()[0]," y=",World.GetCurrent().getAmb()[1]," z=",World.GetCurrent().getAmb()[2]
  1290. pvrgp.SetUpSceneInfo(byref(SceneInfo(Get('staframe'),Get('endframe'),MyVec3f(World.GetCurrent().getAmb()[0],
  1291. World.GetCurrent().getAmb()[1],World.GetCurrent().getAmb()[2]))))
  1292. pvrgp.SetUpExportOptions(byref(export_options))
  1293. showListOfAddedObjects()
  1294. # pvrgp.showNodeSkinning(11,0)
  1295. pvrgp.GeneratePODAndStoreIntoFile(c_char_p(PODfilename))
  1296. print "Export completed"
  1297. Draw.Exit()
  1298. elif evt == 315:
  1299. print "Export Canceled"
  1300. Draw.Exit()
  1301. elif evt == 333:
  1302. export_options.exportGeom = 1 - export_options.exportGeom
  1303. Draw.Redraw()
  1304. elif evt == 334:
  1305. export_options.exportMaterials = 1 - export_options.exportMaterials
  1306. Draw.Redraw()
  1307. elif evt == 335:
  1308. export_options.bFixedPoint = 1 - export_options.bFixedPoint
  1309. Draw.Redraw()
  1310. # Tickbox of export Contoller
  1311. elif evt == 336:
  1312. export_options.exportControllers = 1 - export_options.exportControllers
  1313. chosen_page = 0
  1314. Draw.Redraw()
  1315. # Static Frame number
  1316. elif evt == 337:
  1317. export_options.staticFrame = static_frame_button.val
  1318. chosen_page = 0
  1319. Draw.Redraw()
  1320. elif evt == 338:
  1321. export_options.cS = 1 - export_options.cS
  1322. chosen_page = 0
  1323. Draw.Redraw()
  1324. # "Normals export"
  1325. elif evt == 339:
  1326. export_options.exportNormals = 1 - export_options.exportNormals
  1327. chosen_page = 0
  1328. Draw.Redraw()
  1329. # Export Vertex Colours
  1330. elif evt == 340:
  1331. export_options.exportVertexColor = 1 - export_options.exportVertexColor
  1332. chosen_page = 0
  1333. Draw.Redraw()
  1334. # mapping channels
  1335. elif evt == 341:
  1336. export_options.exportMappingChannel = 1 - export_options.exportMappingChannel
  1337. chosen_page = 0
  1338. Draw.Redraw()
  1339. # "Generate tangent-space"
  1340. elif evt == 342:
  1341. export_options.bTangentSpace = 1 - export_options.bTangentSpace
  1342. chosen_page = 0
  1343. Draw.Redraw()
  1344. elif evt == 343:
  1345. export_options.bInterleaved = 1 - export_options.bInterleaved
  1346. Draw.Redraw()
  1347. elif evt == 344:
  1348. export_options.exportMatrices = 1 - export_options.exportMatrices
  1349. Draw.Redraw()
  1350. # Tickbox of Skin modifiers
  1351. elif evt == 345:
  1352. export_options.exportSkin = 1 - export_options.exportSkin
  1353. chosen_page = 0
  1354. Draw.Redraw()
  1355. # Static Frame number
  1356. elif evt == 346:
  1357. export_options.dwBoneLimit = max_simulatnous_matrices_button.val
  1358. chosen_page = 0
  1359. Draw.Redraw()
  1360. elif evt == 347:
  1361. export_options.ePrimType = primitive_type_menu.val - 1
  1362. Draw.Redraw()
  1363. elif evt == 348:
  1364. export_options.bIndexed = 1 - export_options.bIndexed
  1365. Draw.Redraw()
  1366. elif evt == 349:
  1367. export_options.eTriSort = getTriangleSortingValue()
  1368. Draw.Redraw()
  1369. elif evt == 350:
  1370. export_options.bSortVtx = 1 - export_options.bSortVtx
  1371. Draw.Redraw()
  1372. # change a page with displayed vector data
  1373. elif evt == 3151:
  1374. chosen_page = (chosen_page+1)%( 1+number_of_raw/4 )
  1375. Draw.Redraw()
  1376. elif evt == ID_POSITION_EVT_TYPE:
  1377. export_options.sVcOptPos.eType = getMenuValue(position_data_type_menu)
  1378. Draw.Redraw()
  1379. elif evt == ID_POSITION_EVT_A1:
  1380. export_options.sVcOptPos.nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1381. Draw.Redraw()
  1382. elif evt == ID_POSITION_EVT_A2:
  1383. export_options.sVcOptPos.nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1384. Draw.Redraw()
  1385. elif evt == ID_POSITION_EVT_A3:
  1386. export_options.sVcOptPos.nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1387. Draw.Redraw()
  1388. elif evt == ID_NORMAL_EVT_TYPE:
  1389. export_options.sVcOptNor.eType = getMenuValue(normal_data_type_menu)
  1390. Draw.Redraw()
  1391. elif evt == ID_NORMAL_EVT_A1:
  1392. export_options.sVcOptNor.nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1393. Draw.Redraw()
  1394. elif evt == ID_NORMAL_EVT_A2:
  1395. export_options.sVcOptNor.nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1396. Draw.Redraw()
  1397. elif evt == ID_NORMAL_EVT_A3:
  1398. export_options.sVcOptNor.nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1399. Draw.Redraw()
  1400. elif evt == ID_TANGENT_EVT_TYPE:
  1401. export_options.sVcOptTan.eType = getMenuValue(tangent_data_type_menu)
  1402. Draw.Redraw()
  1403. elif evt == ID_TANGENT_EVT_A1:
  1404. export_options.sVcOptTan.nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1405. Draw.Redraw()
  1406. elif evt == ID_TANGENT_EVT_A2:
  1407. export_options.sVcOptTan.nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1408. Draw.Redraw()
  1409. elif evt == ID_TANGENT_EVT_A3:
  1410. export_options.sVcOptTan.nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1411. Draw.Redraw()
  1412. elif evt == ID_BINORMAL_EVT_TYPE:
  1413. export_options.sVcOptBin.eType = getMenuValue(binormal_data_type_menu)
  1414. Draw.Redraw()
  1415. elif evt == ID_BINORMAL_EVT_A1:
  1416. export_options.sVcOptBin.nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1417. Draw.Redraw()
  1418. elif evt == ID_BINORMAL_EVT_A2:
  1419. export_options.sVcOptBin.nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1420. Draw.Redraw()
  1421. elif evt == ID_BINORMAL_EVT_A3:
  1422. export_options.sVcOptBin.nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1423. Draw.Redraw()
  1424. elif evt == ID_COLOUR_EVT_TYPE:
  1425. export_options.sVcOptCol.eType = getMenuValue(colour_data_type_menu)
  1426. Draw.Redraw()
  1427. elif evt == ID_COLOUR_EVT_A1:
  1428. export_options.sVcOptCol.nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1429. Draw.Redraw()
  1430. elif evt == ID_COLOUR_EVT_A2:
  1431. export_options.sVcOptCol.nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1432. Draw.Redraw()
  1433. elif evt == ID_COLOUR_EVT_A3:
  1434. export_options.sVcOptCol.nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1435. Draw.Redraw()
  1436. elif evt == ID_COLOUR_EVT_A4:
  1437. export_options.sVcOptCol.nEnable ^= DLGOPT_VECTOR_W # if 1 then set 0 if 0 set 1
  1438. Draw.Redraw()
  1439. elif evt == ID_BONE_INDICES_EVT_TYPE:
  1440. export_options.sVcOptBoneInd.eType = getMenuValue(bone_indices_data_type_menu)
  1441. Draw.Redraw()
  1442. elif evt == ID_BONE_INDICES_EVT_A1:
  1443. export_options.sVcOptBoneInd.nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1444. Draw.Redraw()
  1445. elif evt == ID_BONE_INDICES_EVT_A2:
  1446. export_options.sVcOptBoneInd.nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1447. Draw.Redraw()
  1448. elif evt == ID_BONE_INDICES_EVT_A3:
  1449. export_options.sVcOptBoneInd.nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1450. Draw.Redraw()
  1451. elif evt == ID_BONE_INDICES_EVT_A4:
  1452. export_options.sVcOptBoneInd.nEnable ^= DLGOPT_VECTOR_W # if 1 then set 0 if 0 set 1
  1453. Draw.Redraw()
  1454. elif evt == ID_BONE_WEIGHTS_EVT_TYPE:
  1455. export_options.sVcOptBoneWt.eType = getMenuValue(bone_weights_data_type_menu)
  1456. Draw.Redraw()
  1457. elif evt == ID_BONE_WEIGHTS_EVT_A1:
  1458. export_options.sVcOptBoneWt.nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1459. Draw.Redraw()
  1460. elif evt == ID_BONE_WEIGHTS_EVT_A2:
  1461. export_options.sVcOptBoneWt.nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1462. Draw.Redraw()
  1463. elif evt == ID_BONE_WEIGHTS_EVT_A3:
  1464. export_options.sVcOptBoneWt.nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1465. Draw.Redraw()
  1466. elif evt == ID_BONE_WEIGHTS_EVT_A4:
  1467. export_options.sVcOptBoneWt.nEnable ^= DLGOPT_VECTOR_W # if 1 then set 0 if 0 set 1
  1468. Draw.Redraw()
  1469. elif evt == ID_UVW0_EVT_TYPE:
  1470. export_options.psVcOptUVW[0].eType = getMenuValue(uvw0_data_type_menu)
  1471. Draw.Redraw()
  1472. elif evt == ID_UVW0_EVT_A1:
  1473. export_options.psVcOptUVW[0].nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1474. Draw.Redraw()
  1475. elif evt == ID_UVW0_EVT_A2:
  1476. export_options.psVcOptUVW[0].nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1477. Draw.Redraw()
  1478. elif evt == ID_UVW0_EVT_A3:
  1479. export_options.psVcOptUVW[0].nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1480. Draw.Redraw()
  1481. elif evt == ID_UVW1_EVT_TYPE:
  1482. export_options.psVcOptUVW[1].eType = getMenuValue(uvw1_data_type_menu)
  1483. Draw.Redraw()
  1484. elif evt == ID_UVW1_EVT_A1:
  1485. export_options.psVcOptUVW[1].nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1486. Draw.Redraw()
  1487. elif evt == ID_UVW1_EVT_A2:
  1488. export_options.psVcOptUVW[1].nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1489. Draw.Redraw()
  1490. elif evt == ID_UVW1_EVT_A3:
  1491. export_options.psVcOptUVW[1].nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1492. Draw.Redraw()
  1493. elif evt == ID_UVW2_EVT_TYPE:
  1494. export_options.psVcOptUVW[2].eType = getMenuValue(uvw2_data_type_menu)
  1495. Draw.Redraw()
  1496. elif evt == ID_UVW2_EVT_A1:
  1497. export_options.psVcOptUVW[2].nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1498. Draw.Redraw()
  1499. elif evt == ID_UVW2_EVT_A2:
  1500. export_options.psVcOptUVW[2].nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1501. Draw.Redraw()
  1502. elif evt == ID_UVW2_EVT_A3:
  1503. export_options.psVcOptUVW[2].nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1504. Draw.Redraw()
  1505. elif evt == ID_UVW3_EVT_TYPE:
  1506. export_options.psVcOptUVW[3].eType = getMenuValue(uvw3_data_type_menu)
  1507. Draw.Redraw()
  1508. elif evt == ID_UVW3_EVT_A1:
  1509. export_options.psVcOptUVW[3].nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1510. Draw.Redraw()
  1511. elif evt == ID_UVW3_EVT_A2:
  1512. export_options.psVcOptUVW[3].nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1513. Draw.Redraw()
  1514. elif evt == ID_UVW3_EVT_A3:
  1515. export_options.psVcOptUVW[3].nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1516. Draw.Redraw()
  1517. elif evt == ID_UVW4_EVT_TYPE:
  1518. export_options.psVcOptUVW[4].eType = getMenuValue(uvw4_data_type_menu)
  1519. Draw.Redraw()
  1520. elif evt == ID_UVW4_EVT_A1:
  1521. export_options.psVcOptUVW[4].nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1522. Draw.Redraw()
  1523. elif evt == ID_UVW4_EVT_A2:
  1524. export_options.psVcOptUVW[4].nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1525. Draw.Redraw()
  1526. elif evt == ID_UVW4_EVT_A3:
  1527. export_options.psVcOptUVW[4].nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1528. Draw.Redraw()
  1529. elif evt == ID_UVW5_EVT_TYPE:
  1530. export_options.psVcOptUVW[5].eType = getMenuValue(uvw5_data_type_menu)
  1531. Draw.Redraw()
  1532. elif evt == ID_UVW5_EVT_A1:
  1533. export_options.psVcOptUVW[5].nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1534. Draw.Redraw()
  1535. elif evt == ID_UVW5_EVT_A2:
  1536. export_options.psVcOptUVW[5].nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1537. Draw.Redraw()
  1538. elif evt == ID_UVW5_EVT_A3:
  1539. export_options.psVcOptUVW[5].nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1540. Draw.Redraw()
  1541. elif evt == ID_UVW6_EVT_TYPE:
  1542. export_options.psVcOptUVW[6].eType = getMenuValue(uvw6_data_type_menu)
  1543. Draw.Redraw()
  1544. elif evt == ID_UVW6_EVT_A1:
  1545. export_options.psVcOptUVW[6].nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1546. Draw.Redraw()
  1547. elif evt == ID_UVW6_EVT_A2:
  1548. export_options.psVcOptUVW[6].nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1549. Draw.Redraw()
  1550. elif evt == ID_UVW6_EVT_A3:
  1551. export_options.psVcOptUVW[6].nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1552. Draw.Redraw()
  1553. elif evt == ID_UVW7_EVT_TYPE:
  1554. export_options.psVcOptUVW[7].eType = getMenuValue(uvw7_data_type_menu)
  1555. Draw.Redraw()
  1556. elif evt == ID_UVW7_EVT_A1:
  1557. export_options.psVcOptUVW[7].nEnable ^= DLGOPT_VECTOR_X # if 1 then set 0 if 0 set 1
  1558. Draw.Redraw()
  1559. elif evt == ID_UVW7_EVT_A2:
  1560. export_options.psVcOptUVW[7].nEnable ^= DLGOPT_VECTOR_Y # if 1 then set 0 if 0 set 1
  1561. Draw.Redraw()
  1562. elif evt == ID_UVW7_EVT_A3:
  1563. export_options.psVcOptUVW[7].nEnable ^= DLGOPT_VECTOR_Z # if 1 then set 0 if 0 set 1
  1564. Draw.Redraw()
  1565. def getMenuValue(data_type_menu):
  1566. global types_indices
  1567. global types_dict
  1568. for typek in types_indices:
  1569. if types_indices[typek] == data_type_menu.val:
  1570. for data_type in types_dict:
  1571. if types_dict[data_type] == typek:
  1572. return data_type
  1573. return 0
  1574. def getTriangleSortingValue():
  1575. global triangle_sorting_method_menu
  1576. if triangle_sorting_method_menu.val == 1:
  1577. return eNone
  1578. elif triangle_sorting_method_menu.val == 2:
  1579. return e590Blocks
  1580. elif triangle_sorting_method_menu.val == 3:
  1581. return ePVRTTriStrip
  1582. return eNone
  1583. def setTriangleSortingValue():
  1584. global export_options
  1585. if export_options.eTriSort == eNone:
  1586. return 1
  1587. elif export_options.eTriSort == e590Blocks:
  1588. return 2
  1589. elif export_options.eTriSort == ePVRTTriStrip:
  1590. return 3
  1591. return 1
  1592. def drawLabelledGroupBox(text,textwidth,textheight,startx,starty,width,height):
  1593. BGL.glColor3f(0.0,0.0,0.0)
  1594. BGL.glBegin(BGL.GL_LINES)
  1595. # first line
  1596. BGL.glVertex2i(startx,int(starty-textheight*0.5))
  1597. BGL.glVertex2i(startx+20,int(starty-textheight*0.5))
  1598. # second line
  1599. BGL.glVertex2i(startx,int(starty-textheight*0.5))
  1600. BGL.glVertex2i(startx,int(starty-height-textheight*0.5))
  1601. # third line
  1602. BGL.glVertex2i(startx,int(starty-height-textheight*0.5))
  1603. BGL.glVertex2i(startx+width,int(starty-height-textheight*0.5))
  1604. # fourth line
  1605. BGL.glVertex2i(startx+width,int(starty-height-textheight*0.5))
  1606. BGL.glVertex2i(startx+width,int(starty-textheight*0.5))
  1607. #fifth line
  1608. BGL.glVertex2i(startx+width,int(starty-textheight*0.5))
  1609. BGL.glVertex2i(startx+textwidth,int(starty-textheight*0.5))
  1610. BGL.glEnd()
  1611. # Display text
  1612. BGL.glRasterPos2i(startx+20,starty-textheight)
  1613. Draw.Text(text,'large')
  1614. return
  1615. # startx,starty is left top corner
  1616. def drawFormatControlWidget(startx,starty,name_of_format,evt_types,evt_a1,evt_a2,evt_a3,evt_a4,rtype,enabled):
  1617. global types_indices
  1618. name_width = 100
  1619. name_height = 20
  1620. menu_width = 120
  1621. menu_height = 20
  1622. toggle_size = 20
  1623. space_to_toggle = 30
  1624. Draw.Label(name_of_format,startx,starty-name_height,name_width,name_height)
  1625. list_of_types = "ARGB|byte| byte, normalised|D3DCOLOR|DEC3N|fixed 16.16|float|int|RGBA|short|short, normalised|unsigned byte|unsigned short"
  1626. result = Draw.Menu(list_of_types,evt_types,startx+name_width,starty-menu_height,menu_width,menu_height,types_indices[rtype])
  1627. Draw.Toggle(" ",evt_a1,startx+name_width+menu_width+space_to_toggle,starty-toggle_size,toggle_size,toggle_size, enabled & DLGOPT_VECTOR_X)
  1628. Draw.Toggle(" ",evt_a2,startx+name_width+menu_width+space_to_toggle+toggle_size,starty-toggle_size,toggle_size,toggle_size,enabled & DLGOPT_VECTOR_Y)
  1629. Draw.Toggle(" ",evt_a3,startx+name_width+menu_width+space_to_toggle+toggle_size*2,starty-toggle_size,toggle_size,toggle_size,enabled & DLGOPT_VECTOR_Z)
  1630. if evt_a4:
  1631. Draw.Toggle(" ",evt_a4,startx+name_width+menu_width+space_to_toggle+toggle_size*3,starty-toggle_size,toggle_size,toggle_size,enabled & DLGOPT_VECTOR_W)
  1632. return result
  1633. # Draw Exports geometry options at given location
  1634. def drawExportOptions(startx,starty):
  1635. # draw grouping Box for exports options
  1636. global export_options
  1637. global static_frame_button
  1638. drawLabelledGroupBox(" Export options ",Draw.GetStringWidth(" Export options ",'large'),10,startx,starty,200,450)
  1639. step = 20
  1640. marginx = 20
  1641. marginy = 40
  1642. gcb = Draw.Toggle("Geometry ",333,startx+marginx,starty-marginy,100,step,export_options.exportGeom)
  1643. mcb = Draw.Toggle("Materials",334,startx+marginx,starty-step-marginy,100,step,export_options.exportMaterials)
  1644. # bgb = Draw.Toggle("Bone geometry",332,startx+marginx,starty-step*2-marginy,100,step,0)
  1645. fcb = Draw.Toggle("Fixed point",335,startx+marginx,starty-step*2-marginy,100,step,export_options.bFixedPoint)
  1646. drawLabelledGroupBox("Animation",Draw.GetStringWidth("Animation ",'large'),10,startx+marginx,starty-120,170,80)
  1647. ecb = Draw.Toggle("Export controllers ",336,startx+marginx*2,starty-marginy-120,120,step,export_options.exportControllers)
  1648. if export_options.exportControllers:
  1649. static_frame_button = Draw.Number("Static Frame",337,startx+marginx*2,starty-marginy-120-10-step,120,step,export_options.staticFrame,0,32767,"Static Frame value")
  1650. drawLabelledGroupBox("Coordinate System",Draw.GetStringWidth("Coordinate System ",'large'),10,startx+marginx,starty-220,170,40)
  1651. name = "OpenGL| DirectX"
  1652. result = Draw.Menu(name,338,startx+marginx*2,starty-220-marginy,130,step,export_options.cS+1)
  1653. return
  1654. def drawGeometryOptions(startx,starty):
  1655. global export_options
  1656. global chosen_page
  1657. global number_of_raw
  1658. global types_dict
  1659. global position_data_type_menu
  1660. global normal_data_type_menu
  1661. global tangent_data_type_menu
  1662. global binormal_data_type_menu
  1663. global colour_data_type_menu
  1664. global bone_indices_data_type_menu
  1665. global bone_weights_data_type_menu
  1666. global uvw0_data_type_menu
  1667. global uvw1_data_type_menu
  1668. global uvw2_data_type_menu
  1669. global uvw3_data_type_menu
  1670. global uvw4_data_type_menu
  1671. global uvw5_data_type_menu
  1672. global uvw6_data_type_menu
  1673. global uvw7_data_type_menu
  1674. global primitive_type_menu
  1675. global triangle_sorting_method_menu
  1676. global max_simulatnous_matrices_button
  1677. step = 20
  1678. marginx = 20
  1679. marginy = 40
  1680. tickboxwidth = 150
  1681. label_width = 100
  1682. menu_width = 120
  1683. toggle_size = 20
  1684. space_to_toggle = 30
  1685. # draw grouping Box for geometry options
  1686. drawLabelledGroupBox(" Geometry options ",Draw.GetStringWidth(" Geometry Options ",'large'),10,startx,starty,420,450)
  1687. cb1 = Draw.Toggle("Normals",339,startx+marginx,starty - marginy,tickboxwidth,step, export_options.exportNormals)
  1688. cb2 = Draw.Toggle("Vertex colours",340,startx+marginx,starty-step-marginy,tickboxwidth,step,export_options.exportVertexColor)
  1689. cb3 = Draw.Toggle("Mapping channels",341,startx+marginx,starty-step*2-marginy,tickboxwidth,step,export_options.exportMappingChannel)
  1690. cb4 = Draw.Toggle("Generate tangent-space",342,startx+marginx,starty-step*3-marginy,tickboxwidth,step,export_options.bTangentSpace)
  1691. cb5 = Draw.Toggle("Interleave vectors",343,startx+marginx,starty-step*4-marginy,tickboxwidth,step,export_options.bInterleaved)
  1692. cb6 = Draw.Toggle("Export Matrices",344,startx+marginx,starty-step*5-marginy,tickboxwidth,step,export_options.exportMatrices)
  1693. # grouping box Skin options
  1694. drawLabelledGroupBox("Skin",Draw.GetStringWidth("Skin ",'large'),10,startx+2*marginx+tickboxwidth,starty-step,210,80)
  1695. cb7 = Draw.Toggle("Export skin modifiers",345,startx+3*marginx+tickboxwidth,starty-marginy-step,tickboxwidth,step,export_options.exportSkin)
  1696. if export_options.exportSkin:
  1697. max_simulatnous_matrices_button = Draw.Number("Max simultanous matrices",346,startx+3*marginx+tickboxwidth,starty-marginy -2*step - 10,tickboxwidth+30,step,export_options.dwBoneLimit,0,65356,"Maximum simultanious matrices value ")
  1698. # grouping box Primitive type options
  1699. ptposy = starty-marginy*3
  1700. drawLabelledGroupBox("Primitive type",Draw.GetStringWidth("Primitive type ",'large'),10,startx+2*marginx+tickboxwidth,ptposy,210,70)
  1701. name = "Triangle list|Triangle strip"
  1702. primitive_type_menu = Draw.Menu(name,347,startx+3*marginx+tickboxwidth,ptposy - marginy,tickboxwidth,step,export_options.ePrimType+1)
  1703. cb8 = Draw.Toggle("Indexed",348,startx+3*marginx+tickboxwidth,ptposy - marginy -step,tickboxwidth,step,export_options.bIndexed)
  1704. # grouping box Primitive type options
  1705. ptposy = starty-marginy*5-step +10
  1706. drawLabelledGroupBox("Triangle sorting method",Draw.GetStringWidth("Triangle sorting method ",'large'),10,startx+2*marginx+tickboxwidth,ptposy,210,70)
  1707. name = "None|PVRTGeometrySort|PVRTTriStrip"
  1708. triangle_sorting_method_menu = Draw.Menu(name,349,startx+3*marginx+tickboxwidth,ptposy - marginy,tickboxwidth,step, setTriangleSortingValue())
  1709. cb8 = Draw.Toggle("Sort vertices",350,startx+3*marginx+tickboxwidth,ptposy - marginy -step,tickboxwidth,step,export_options.bSortVtx)
  1710. # grouping box Vertex vector formats
  1711. ptposy = starty-marginy*7-step
  1712. drawLabelledGroupBox("Vertex vector formats",Draw.GetStringWidth("Vertex vector format ",'large'),10,startx+marginx,ptposy,tickboxwidth+230,140)
  1713. # Name of collumns comes below and the columns itself
  1714. Draw.Label("Vector",startx+marginx*2,ptposy-marginy,label_width,20)
  1715. Draw.Label("Type",startx+marginx*2+label_width,ptposy-marginy,label_width,20)
  1716. Draw.Label("A1",startx+marginx*2+label_width+space_to_toggle+menu_width,ptposy-marginy,toggle_size,toggle_size)
  1717. Draw.Label("A2",startx+marginx*2+label_width+space_to_toggle+menu_width+toggle_size,ptposy-marginy,toggle_size,toggle_size)
  1718. Draw.Label("A3",startx+marginx*2+label_width+space_to_toggle+menu_width+toggle_size*2,ptposy-marginy,toggle_size,toggle_size)
  1719. Draw.Label("A4",startx+marginx*2+label_width+space_to_toggle+menu_width+toggle_size*3,ptposy-marginy,toggle_size,toggle_size)
  1720. number_of_raw = 0
  1721. list_of_formats = ["Position", "Normal", "Tangent", "Binormal", "Colour", "Bone indices", "Bone weights", "UVW0","UVW1","UVW2","UVW3","UVW4","UVW5","UVW6","UVW7"]
  1722. list_of_formats_descriptions = {"Position": FormatDescription(types_dict[export_options.sVcOptPos.eType],ID_POSITION_EVT_TYPE,ID_POSITION_EVT_A1,ID_POSITION_EVT_A2,ID_POSITION_EVT_A3,0,export_options.sVcOptPos.nEnable),
  1723. "Normal": FormatDescription(types_dict[export_options.sVcOptNor.eType],ID_NORMAL_EVT_TYPE,ID_NORMAL_EVT_A1,ID_NORMAL_EVT_A2,ID_NORMAL_EVT_A3,0,export_options.sVcOptNor.nEnable),
  1724. "Tangent": FormatDescription(types_dict[export_options.sVcOptTan.eType],ID_TANGENT_EVT_TYPE,ID_TANGENT_EVT_A1,ID_TANGENT_EVT_A2,ID_TANGENT_EVT_A3,0,export_options.sVcOptTan.nEnable),
  1725. "Binormal": FormatDescription(types_dict[export_options.sVcOptBin.eType],ID_BINORMAL_EVT_TYPE,ID_BINORMAL_EVT_A1,ID_BINORMAL_EVT_A2,ID_BINORMAL_EVT_A3,0,export_options.sVcOptBin.nEnable),
  1726. "Colour": FormatDescription(types_dict[export_options.sVcOptCol.eType],ID_COLOUR_EVT_TYPE,ID_COLOUR_EVT_A1,ID_COLOUR_EVT_A2,ID_COLOUR_EVT_A3,ID_COLOUR_EVT_A4,export_options.sVcOptCol.nEnable),
  1727. "Bone indices": FormatDescription(types_dict[export_options.sVcOptBoneInd.eType],ID_BONE_INDICES_EVT_TYPE,ID_BONE_INDICES_EVT_A1,ID_BONE_INDICES_EVT_A2,ID_BONE_INDICES_EVT_A3,ID_BONE_INDICES_EVT_A4,export_options.sVcOptBoneInd.nEnable),
  1728. "Bone weights": FormatDescription(types_dict[export_options.sVcOptBoneWt.eType],ID_BONE_WEIGHTS_EVT_TYPE,ID_BONE_WEIGHTS_EVT_A1,ID_BONE_WEIGHTS_EVT_A2,ID_BONE_WEIGHTS_EVT_A3,ID_BONE_WEIGHTS_EVT_A4,export_options.sVcOptBoneWt.nEnable),
  1729. "UVW0": FormatDescription(types_dict[export_options.psVcOptUVW[0].eType],ID_UVW0_EVT_TYPE,ID_UVW0_EVT_A1,ID_UVW0_EVT_A2,ID_UVW0_EVT_A3,0,export_options.psVcOptUVW[0].nEnable),
  1730. "UVW1": FormatDescription(types_dict[export_options.psVcOptUVW[1].eType],ID_UVW1_EVT_TYPE,ID_UVW1_EVT_A1,ID_UVW1_EVT_A2,ID_UVW1_EVT_A3,0,export_options.psVcOptUVW[1].nEnable),
  1731. "UVW2": FormatDescription(types_dict[export_options.psVcOptUVW[2].eType],ID_UVW2_EVT_TYPE,ID_UVW2_EVT_A1,ID_UVW2_EVT_A2,ID_UVW2_EVT_A3,0,export_options.psVcOptUVW[2].nEnable),
  1732. "UVW3": FormatDescription(types_dict[export_options.psVcOptUVW[3].eType],ID_UVW3_EVT_TYPE,ID_UVW3_EVT_A1,ID_UVW3_EVT_A2,ID_UVW3_EVT_A3,0,export_options.psVcOptUVW[3].nEnable),
  1733. "UVW4": FormatDescription(types_dict[export_options.psVcOptUVW[4].eType],ID_UVW4_EVT_TYPE,ID_UVW4_EVT_A1,ID_UVW4_EVT_A2,ID_UVW4_EVT_A3,0,export_options.psVcOptUVW[4].nEnable),
  1734. "UVW5": FormatDescription(types_dict[export_options.psVcOptUVW[5].eType],ID_UVW5_EVT_TYPE,ID_UVW5_EVT_A1,ID_UVW5_EVT_A2,ID_UVW5_EVT_A3,0,export_options.psVcOptUVW[5].nEnable),
  1735. "UVW6": FormatDescription(types_dict[export_options.psVcOptUVW[6].eType],ID_UVW6_EVT_TYPE,ID_UVW6_EVT_A1,ID_UVW6_EVT_A2,ID_UVW6_EVT_A3,0,export_options.psVcOptUVW[6].nEnable),
  1736. "UVW7": FormatDescription(types_dict[export_options.psVcOptUVW[7].eType],ID_UVW7_EVT_TYPE,ID_UVW7_EVT_A1,ID_UVW7_EVT_A2,ID_UVW7_EVT_A3,0,export_options.psVcOptUVW[7].nEnable)}
  1737. i = 0
  1738. while i<len(list_of_formats):
  1739. # warunek ze niby jak aktywne to rysuj, trza odpowiedi atrybut jeszcze gdzies dodac
  1740. if list_of_formats[i] == "Normal" and export_options.exportNormals == 0 :
  1741. number_of_raw+=0
  1742. elif list_of_formats[i] == "Colour" and export_options.exportVertexColor == 0 :
  1743. number_of_raw+=0
  1744. elif list_of_formats[i] in ["Tangent","Binormal"] and export_options.bTangentSpace == 0 :
  1745. number_of_raw+=0
  1746. elif list_of_formats[i] in ["UVW0","UVW1","UVW2","UVW3","UVW4","UVW5","UVW6","UVW7"] and export_options.exportMappingChannel == 0 :
  1747. number_of_raw+=0
  1748. elif list_of_formats[i] in ["Bone indices","Bone weights"] and export_options.exportSkin == 0 :
  1749. number_of_raw+=0
  1750. else:
  1751. # print "format: ",list_of_formats[i]," chosen page=",chosen_page," number_of_raws=",number_of_raw,"floor(numbver/4)=",floor(number_of_raw/4)," i=",i ," len of list_of_formats=",len(list_of_formats)
  1752. if floor(number_of_raw/4) == chosen_page:
  1753. menu_widget = drawFormatControlWidget(startx+marginx*2,ptposy-marginy-step*(number_of_raw%4),list_of_formats[i],\
  1754. list_of_formats_descriptions[list_of_formats[i]].evt_type,list_of_formats_descriptions[list_of_formats[i]].evt1,\
  1755. list_of_formats_descriptions[list_of_formats[i]].evt2,list_of_formats_descriptions[list_of_formats[i]].evt3,\
  1756. list_of_formats_descriptions[list_of_formats[i]].evt4,list_of_formats_descriptions[list_of_formats[i]].type,
  1757. list_of_formats_descriptions[list_of_formats[i]].enabled)
  1758. if list_of_formats[i] == "Position":
  1759. position_data_type_menu = menu_widget
  1760. elif list_of_formats[i] == "Normal":
  1761. normal_data_type_menu = menu_widget
  1762. elif list_of_formats[i] == "Colour":
  1763. colour_data_type_menu = menu_widget
  1764. elif list_of_formats[i] == "Tangent":
  1765. tangent_data_type_menu = menu_widget
  1766. elif list_of_formats[i] == "Binormal":
  1767. binormal_data_type_menu = menu_widget
  1768. elif list_of_formats[i] == "Bone indices":
  1769. bone_indices_data_type_menu = menu_widget
  1770. elif list_of_formats[i] == "Bone weights":
  1771. bone_weights_data_type_menu = menu_widget
  1772. elif list_of_formats[i] == "UVW0":
  1773. uvw0_data_type_menu = menu_widget
  1774. elif list_of_formats[i] == "UVW1":
  1775. uvw1_data_type_menu = menu_widget
  1776. elif list_of_formats[i] == "UVW2":
  1777. uvw2_data_type_menu = menu_widget
  1778. elif list_of_formats[i] == "UVW3":
  1779. uvw3_data_type_menu = menu_widget
  1780. elif list_of_formats[i] == "UVW4":
  1781. uvw4_data_type_menu = menu_widget
  1782. elif list_of_formats[i] == "UVW5":
  1783. uvw5_data_type_menu = menu_widget
  1784. elif list_of_formats[i] == "UVW6":
  1785. uvw6_data_type_menu = menu_widget
  1786. elif list_of_formats[i] == "UVW7":
  1787. uvw7_data_type_menu = menu_widget
  1788. number_of_raw += 1
  1789. i += 1
  1790. # If there are more than one page requested to show all visible raws then create a button for changing the pages
  1791. number_of_raw-=1
  1792. endpage = floor(number_of_raw/4)
  1793. # print "chosen page=",chosen_page," number_of_raws=",number_of_raw,"floor(numbver/4)=",floor(number_of_raw/4)," i=",i ," len of list_of_formats=",len(list_of_formats)," endpage=",endpage
  1794. if endpage >= 1:
  1795. endpage+=1
  1796. etykieta = str(int(chosen_page+1))+" of "+str(int(endpage))
  1797. Draw.PushButton(etykieta,3151,int(startx+marginx*2+label_width+space_to_toggle+menu_width+toggle_size*2.5), int(starty - 450 + 0.5*step) ,50,15,"Change a page with displayed vector formats")
  1798. def drawCommandLineOptions(startx,starty):
  1799. step = 20
  1800. marginx = 20
  1801. marginy = 40
  1802. tickboxwidth = 150
  1803. # draw grouping Box for geometry options
  1804. drawLabelledGroupBox(" Post export command line ",Draw.GetStringWidth(" Post export command line ",'large'),10,startx,starty,620,80)
  1805. Draw.String("Command: ",351, startx + marginx, starty - marginy ,620 - marginx*2,step," ",200,"command to execute after data being exported to POD",mycallbackCommand)
  1806. Draw.String("Command arguments: ",352, startx + marginx, starty - marginy -step ,620 - marginx*2,step," ",200,"command arguments",mycallbackCommandArgs)
  1807. Draw.String("Working directory: ",353, startx + marginx, starty - marginy -step*2,620 - marginx*2,step," ",200,"Working directory",mycallbackWorkingDir)
  1808. def drawExport(startx,starty):
  1809. global PODfilename
  1810. step = 20
  1811. marginx = 20
  1812. marginy = 40
  1813. width = 620
  1814. drawLabelledGroupBox(" Generating POD: "+PODfilename,Draw.GetStringWidth(" Generating POD: "+PODfilename,'large'),10,startx,starty,width,40)
  1815. Draw.PushButton("OK",314,startx + marginx*11, starty - marginy ,60,20,"Proceed generating of POD file")
  1816. Draw.PushButton("Cancel",315,startx + width - marginx*11 -60, starty - marginy,60,20,"Cancel export to POD file")
  1817. # The function redrawing the GUI
  1818. def draw_gui():
  1819. wymiary = Window.GetScreenSize()
  1820. # Each element is defined by his left top corner
  1821. # Y axe is positive in upward directon
  1822. # X axe is positive in right directon
  1823. # total width of GUI is 620
  1824. drawExportOptions(wymiary[0]/2 - 310,wymiary[1]/2 + 150)
  1825. drawGeometryOptions(wymiary[0]/2 - 110,wymiary[1]/2 + 150 )
  1826. drawCommandLineOptions(wymiary[0]/2 - 310,wymiary[1]/2 - 320)
  1827. drawExport(wymiary[0]/2 - 310,wymiary[1]/2 - 420)
  1828. print ">>>------"
  1829. name = "untitled.pod"
  1830. Window.FileSelector(mycallback,"OK",name)
  1831. #Window.DrawProgressBar(0.0,"Initialize Data")
  1832. #Window.DrawProgressBar(0.5,"Passing gathered data to processing library")
  1833. #Window.DrawProgressBar(1.0,"Finalizing")
  1834. print "\n---------<<<<"