glge.js 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626
  1. "use strict";
  2. // Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  3. // Secretary of Defense (Personnel & Readiness).
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the License
  11. // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  12. // or implied. See the License for the specific language governing permissions and limitations under
  13. // the License.
  14. /// vwf/model/glge.js is an interface to the GLGE WebGL scene manager.
  15. ///
  16. /// @module vwf/model/glge
  17. /// @requires vwf/model
  18. /// @requires vwf/utility
  19. define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utility ) {
  20. // For historical reasons yet to be resolved, the GLGE model code currently resides in
  21. // vwf-model.glge.js intermixed with the view code. This driver is a gross hack to delegate model
  22. // calls to the appropriate parts of the GLGE view.
  23. return model.load( module, {
  24. // == Module Definition ====================================================================
  25. // -- initialize ---------------------------------------------------------------------------
  26. initialize: function() {
  27. checkCompatibility.call(this);
  28. this.state.scenes = {}; // id => { glgeDocument: new GLGE.Document(), glgeRenderer: new GLGE.Renderer(), glgeScene: new GLGE.Scene() }
  29. this.state.nodes = {}; // id => { name: string, glgeObject: GLGE.Object, GLGE.Collada, GLGE.Light, or other...? }
  30. this.state.prototypes = {};
  31. this.state.kernel = this.kernel;
  32. },
  33. // == Model API ============================================================================
  34. // -- creatingNode ------------------------------------------------------------------------
  35. creatingNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
  36. childSource, childType, childIndex, childName, callback ) {
  37. var childURI = nodeID === 0 ? childIndex : undefined;
  38. var self = this;
  39. //console.log(["creatingNode:",nodeID,childID,childName,childExtendsID,childType]);
  40. var prototypeID = isPrototype.call( this, nodeID, childID );
  41. if ( prototypeID !== undefined ) {
  42. //console.info( "FOUND prototype: " + prototypeID );
  43. this.state.prototypes[ prototypeID ] = {
  44. parentID: nodeID,
  45. ID: childID,
  46. extendsID: childExtendsID,
  47. implementsID: childImplementsIDs,
  48. source: childSource,
  49. type: childType,
  50. uri: childURI,
  51. name: childName
  52. };
  53. return;
  54. }
  55. if ( childExtendsID === undefined )
  56. return;
  57. //console.log("Create " + childID);
  58. var node, parentNode, glgeChild, glgeParent;
  59. var kernel = this.kernel;
  60. var prototypes = getPrototypes.call( this, kernel, childExtendsID );
  61. // this.logger.enabled = true;
  62. // this.logger.infox( "creatingNode", nodeID, childID, childExtendsID, childImplementsIDs,
  63. // childSource, childType, childIndex, childName );
  64. // this.logger.enabled = false;
  65. // find the parent node
  66. if ( nodeID ) {
  67. if ( this.state.nodes[ nodeID ] )
  68. parentNode = this.state.nodes[ nodeID ];
  69. else
  70. parentNode = this.state.scenes[ nodeID ];
  71. if ( parentNode ) {
  72. glgeParent = parentNode.glgeObject ? parentNode.glgeObject : parentNode.glgeScene;
  73. var recursive = false;
  74. if ( glgeParent && childName ) {
  75. recursive = ( glgeParent.constructor == GLGE.Collada );
  76. glgeChild = glgeObjectChild.call( this, glgeParent, childName, childExtendsID, prototypes, recursive );
  77. }
  78. }
  79. }
  80. if ( prototypes && isGlgeSceneDefinition.call( this, prototypes ) && childID == this.kernel.application() ) {
  81. this.state.sceneRootID = childID;
  82. var sceneNode = this.state.scenes[childID] = {
  83. glgeDocument: new GLGE.Document(),
  84. glgeRenderer: undefined,
  85. glgeScene: new GLGE.Scene(),
  86. ID: childID,
  87. parentID: nodeID,
  88. glgeKeys: new GLGE.KeyInput(),
  89. type: childExtendsID,
  90. camera: {
  91. ID: undefined
  92. },
  93. xmlColladaObjects: [],
  94. srcColladaObjects: [],
  95. viewInited: false,
  96. modelInited: false,
  97. pendingLoads: 0,
  98. };
  99. if ( sceneNode.glgeScene.camera ) {
  100. sceneNode.glgeScene.camera.name = "camera";
  101. this.state.cameraInUse = sceneNode.glgeScene.camera;
  102. initCamera.call( this, sceneNode.glgeScene.camera );
  103. }
  104. var model = this;
  105. var xmlDocLoadedCallback = callback;
  106. sceneNode.glgeDocument.onLoad = function () {
  107. sceneNode.pendingLoads--;
  108. xmlDocLoadedCallback( true );
  109. };
  110. if ( childSource ) {
  111. switch ( childType ) {
  112. case "model/x-glge":
  113. callback( false );
  114. sceneNode.glgeDocument.load( utility.resolveURI( childSource, childURI ) );
  115. sceneNode.pendingLoads++;
  116. break;
  117. }
  118. }
  119. } else if ( prototypes && isGlgeCameraDefinition.call( this, prototypes ) ) {
  120. if ( childName !== undefined ) {
  121. var camName = this.kernel.name( childID );
  122. var sceneNode = this.state.scenes[ this.state.sceneRootID ];
  123. node = this.state.nodes[childID] = {
  124. name: childName,
  125. glgeObject: glgeChild,
  126. ID: childID,
  127. parentID: nodeID,
  128. sceneID: this.state.sceneRootID,
  129. glgeScene: sceneNode ? sceneNode.glgeScene : undefined,
  130. type: childExtendsID,
  131. sourceType: childType,
  132. };
  133. if ( nodeID === this.kernel.application() && childName === "camera" ) {
  134. } else if ( node.glgeObject === undefined ){
  135. createCamera.call( this, nodeID, childID, childName );
  136. }
  137. }
  138. } else if ( prototypes && isGlgeLightDefinition.call( this, prototypes ) ) {
  139. if ( childName !== undefined ) {
  140. node = this.state.nodes[childID] = {
  141. name: childName,
  142. glgeObject: glgeChild,
  143. ID: childID,
  144. parentID: nodeID,
  145. type: childExtendsID,
  146. sourceType: childType,
  147. };
  148. if ( nodeID != 0 && !node.glgeObject ) {
  149. createLight.call( this, nodeID, childID, childName );
  150. }
  151. }
  152. } else if ( prototypes && isGlgeParticleSystemDefinition.call( this, prototypes ) ) {
  153. if ( childName !== undefined ) {
  154. node = this.state.nodes[childID] = {
  155. name: childName,
  156. glgeObject: glgeChild,
  157. ID: childID,
  158. parentID: nodeID,
  159. type: childExtendsID
  160. };
  161. if ( nodeID != 0 && !node.glgeObject ) {
  162. createParticleSystem.call( this, nodeID, childID, childName );
  163. }
  164. }
  165. } else if ( prototypes && isGlgeNodeDefinition.call( this, prototypes ) ) {
  166. if ( childName !== undefined ) {
  167. var sceneNode = this.state.scenes[ this.state.sceneRootID ];
  168. switch ( childType ) {
  169. case "model/vnd.collada+xml":
  170. callback( false );
  171. node = this.state.nodes[childID] = {
  172. name: childName,
  173. glgeObject: undefined,
  174. source: utility.resolveURI( childSource, childURI ),
  175. ID: childID,
  176. parentID: nodeID,
  177. sourceType: childType,
  178. type: childExtendsID,
  179. loadedCallback: callback,
  180. glgeScene: sceneNode
  181. };
  182. loadCollada.call( this, parentNode, node, notifyDriverOfPrototypeAndBehaviorProps );
  183. break;
  184. case "text/xml":
  185. node = this.state.nodes[childID] = {
  186. name: childName,
  187. glgeObject: undefined,
  188. source: childSource,
  189. ID: childID,
  190. parentID: nodeID,
  191. type: childExtendsID,
  192. sourceType: childType,
  193. glgeScene: sceneNode
  194. };
  195. if ( sceneNode && sceneNode.glgeDocument ){
  196. var meshDef = sceneNode.glgeDocument.getElement( node.source );
  197. if ( meshDef ) {
  198. node.glgeObject = new GLGE.Object();
  199. node.glgeObject.setMesh( meshDef );
  200. if ( glgeParent ) {
  201. glgeParent.addObject( node.glgeObject );
  202. } else {
  203. if ( sceneNode.glgeScene ) {
  204. sceneNode.glgeScene.addObject( node.glgeObject );
  205. }
  206. }
  207. }
  208. }
  209. break;
  210. case "definition/mesh": {
  211. node = this.state.nodes[childID] = {
  212. name: childName,
  213. glgeObject: undefined,
  214. glgeParent: glgeParent,
  215. source: childSource,
  216. ID: childID,
  217. parentID: nodeID,
  218. type: childExtendsID,
  219. sourceType: childType,
  220. glgeScene: sceneNode
  221. };
  222. createMesh.call( this, node );
  223. }
  224. break;
  225. default:
  226. node = this.state.nodes[childID] = {
  227. name: childName,
  228. glgeObject: glgeChild,
  229. ID: childID,
  230. parentID: nodeID,
  231. type: childExtendsID,
  232. sourceType: childType,
  233. glgeScene: sceneNode
  234. };
  235. if ( node.glgeObject ) {
  236. if ( ( node.glgeObject.constructor == GLGE.Collada ) ) {
  237. callback( false );
  238. node.glgeObject.vwfID = childID;
  239. sceneNode.xmlColladaObjects.push( node.glgeObject );
  240. setColladaCallback.call( this, node.glgeObject, sceneNode );
  241. node.loadedCallback = callback;
  242. }
  243. } else {
  244. if ( nodeID != 0 ) {
  245. node.glgeObject = new GLGE.Group();
  246. if ( parentNode ) {
  247. if ( parentNode.glgeObject ) {
  248. parentNode.glgeObject.addObject( node.glgeObject );
  249. } else if ( parentNode.glgeScene ) {
  250. parentNode.glgeScene.addObject( node.glgeObject );
  251. }
  252. }
  253. node.gui = node.glgeObject.uid;
  254. node.glgeObject.name = childName;
  255. }
  256. }
  257. break;
  258. }
  259. this.settingProperty( childID, "playing", false ); // TODO: these are matching the defaults in node3; they should be sent through creatingProperty() so that we don't have to ask
  260. this.settingProperty( childID, "looping", false ); // TODO: these are matching the defaults in node3; they should be sent through creatingProperty() so that we don't have to ask
  261. this.settingProperty( childID, "speed", 1 ); // TODO: these are matching the defaults in node3; they should be sent through creatingProperty() so that we don't have to ask
  262. }
  263. } else if ( prototypes && isGlgeMaterialDefinition.call( this, prototypes ) ) {
  264. if ( childName !== undefined ) {
  265. node = this.state.nodes[childID] = {
  266. name: childName,
  267. glgeObject: undefined,
  268. glgeMaterial: true,
  269. ID: childID,
  270. parentID: nodeID,
  271. type: childExtendsID,
  272. sourceType: childType,
  273. };
  274. findMaterial.call( this, nodeID, childName, node );
  275. }
  276. } // end of else
  277. // If we do not have a load a model for this node, then we are almost done, so we can update all
  278. // the driver properties w/ the stop-gap function below.
  279. // Else, it will be called at the end of the assetLoaded callback
  280. if ( ! ( childType == "model/vnd.collada+xml" ||
  281. childType == "model/vnd.osgjs+json+compressed" ) )
  282. notifyDriverOfPrototypeAndBehaviorProps();
  283. // Since prototypes are created before the object, it does not get "setProperty" updates for
  284. // its prototype (and behavior) properties. Therefore, we cycle through those properties to
  285. // notify the drivers of the property values so they can react accordingly
  286. // TODO: Have the kernel send the "setProperty" updates itself so the driver need not
  287. // NOTE: Identical code exists in three.js driver, so if an change is necessary, it should be made
  288. // there, too
  289. function notifyDriverOfPrototypeAndBehaviorProps() {
  290. var ptPropValue;
  291. var protos = getPrototypes.call( this, kernel, childExtendsID );
  292. protos.forEach( function( prototypeID ) {
  293. for ( var propertyName in kernel.getProperties( prototypeID ) ) {
  294. //console.info( " 1 getting "+propertyName+" of: " + childExtendsID );
  295. ptPropValue = kernel.getProperty( childExtendsID, propertyName );
  296. if ( ptPropValue !== undefined && ptPropValue !== null && childID !== undefined && childID !== null) {
  297. //console.info( " 1 setting "+propertyName+" of: " + nodeID + " to " + ptPropValue );
  298. self.settingProperty( childID, propertyName, ptPropValue );
  299. }
  300. }
  301. } );
  302. childImplementsIDs.forEach( function( behaviorID ) {
  303. for ( var propertyName in kernel.getProperties( behaviorID ) ) {
  304. //console.info( " 2 getting "+propertyName+" of: " + behaviorID );
  305. ptPropValue = kernel.getProperty( behaviorID, propertyName );
  306. if ( ptPropValue !== undefined && ptPropValue !== null && childID !== undefined && childID !== null) {
  307. //console.info( " 2 setting "+propertyName+" of: " + nodeID + " to " + ptPropValue );
  308. self.settingProperty( childID, propertyName, ptPropValue );
  309. }
  310. }
  311. } );
  312. };
  313. },
  314. // -- deletingNode -------------------------------------------------------------------------
  315. deletingNode: function( nodeID ) {
  316. if ( this.state.nodes[ nodeID ] ) {
  317. var node = this.state.nodes[ nodeID ];
  318. if ( node.glgeObject ) {
  319. var obj = node.glgeObject;
  320. var parent = obj.parent;
  321. if ( parent ) {
  322. if ( parent.removeChild ) parent.removeChild( obj );
  323. node.glgeObject = undefined;
  324. //delete obj;
  325. }
  326. }
  327. delete this.state.nodes[ nodeID ];
  328. }
  329. },
  330. // -- addingChild ------------------------------------------------------------------------
  331. addingChild: function( nodeID, childID, childName ) {
  332. var parentGlgeObj = getGlgeObject.call( this, nodeID );
  333. var childGlgeObj = getGlgeObject.call( this, childID );
  334. if ( parentGlgeObj && childGlgeObj && parentGlgeObj instanceof GLGE.Group ) {
  335. var childParent = childGlgeObj.parent;
  336. // what does vwf do here? add only if parent is currently undefined
  337. if ( childParent ) {
  338. childParent.remove( childGlgeObj )
  339. }
  340. parentGlgeObj.add( childGlgeObj );
  341. }
  342. },
  343. // -- movingChild ------------------------------------------------------------------------
  344. movingChild: function( nodeID, childID, childName ) {
  345. var parentGlgeObj = getGlgeObject.call( this, nodeID );
  346. var childGlgeObj = getGlgeObject.call( this, childID );
  347. if ( parentGlgeObj && childGlgeObj && parentGlgeObj instanceof GLGE.Group ) {
  348. var childParent = childGlgeObj.parent;
  349. if ( childParent ) {
  350. childParent.remove( childGlgeObj );
  351. parentGlgeObj.add( childGlgeObj );
  352. }
  353. }
  354. },
  355. // -- removingChild ------------------------------------------------------------------------
  356. removingChild: function( nodeID, childID, childName ) {
  357. var parentGlgeObj = getGlgeObject.call( this, nodeID );
  358. var childGlgeObj = getGlgeObject.call( this, childID );
  359. if ( parentGlgeObj && childGlgeObj && parentGlgeObj instanceof GLGE.Group ) {
  360. var childParent = childGlgeObj.parent;
  361. if ( childParent === parentGlgeObj ) {
  362. parentGlgeObj.remove( childGlgeObj )
  363. }
  364. }
  365. },
  366. // -- creatingProperty ---------------------------------------------------------------------
  367. creatingProperty: function( nodeID, propertyName, propertyValue ) {
  368. return this.initializingProperty( nodeID, propertyName, propertyValue );
  369. },
  370. // -- initializingProperty -----------------------------------------------------------------
  371. initializingProperty: function( nodeID, propertyName, propertyValue ) {
  372. var value = undefined;
  373. if ( propertyValue !== undefined ) {
  374. var node = this.state.nodes[ nodeID ];
  375. if ( !node ) node = this.state.scenes[ nodeID ];
  376. if ( node ) {
  377. switch ( propertyName ) {
  378. case "meshDefinition":
  379. defineMesh.call( this, propertyValue, node );
  380. break;
  381. default:
  382. value = this.settingProperty( nodeID, propertyName, propertyValue );
  383. break;
  384. }
  385. }
  386. }
  387. return value;
  388. },
  389. // -- settingProperty ----------------------------------------------------------------------
  390. settingProperty: function( nodeID, propertyName, propertyValue ) {
  391. var node = this.state.nodes[ nodeID ]; // { name: childName, glgeObject: undefined }
  392. var prototypes;
  393. var value = undefined;
  394. if ( node && node.glgeObject && propertyValue !== undefined ) {
  395. var validProperty = false;
  396. var glgeObject = node.glgeObject;
  397. var isAnimatable = glgeObject.animate; // implements GLGE.Animatable?
  398. isAnimatable = isAnimatable && glgeObject.animation || propertyName == "looping" && glgeObject.constructor == GLGE.ParticleSystem; // has an animation?
  399. isAnimatable = isAnimatable && node.name != "cityblock.dae"; // TODO: this is a hack to prevent disabling the animation that keeps the world upright
  400. value = propertyValue;
  401. if ( isAnimatable ) {
  402. switch ( propertyName ) {
  403. case "playing":
  404. if ( !Boolean( propertyValue ) && glgeObject.animFinished ) { // TODO: GLGE finished doesn't flow back into node3's playing yet; assume playing is being toggled and interpret it as true if the animation has played and finished.
  405. propertyValue = true;
  406. }
  407. // if ( !node.initialized ) { // TODO: this is a hack to set the animation to frame 0 during initialization
  408. // //if ( glgeObject.animFrames == 100 ) { glgeObject.setFrames( 50 ); } // hack to use only the opening half of the door animation
  409. // glgeObject.setStartFrame( 0, 0, glgeObject.getLoop() );
  410. // glgeObject.getInitialValues( glgeObject.animation, glgeObject.animationStart );
  411. // }
  412. if ( Boolean( propertyValue ) ) {
  413. if ( glgeObject.animFinished ) {
  414. glgeObject.setStartFrame( 0, 0, glgeObject.getLoop() );
  415. } else if ( glgeObject.getPaused() ) {
  416. if ( glgeObject.animFrames == 100 ) {
  417. glgeObject.setFrames( 50 );
  418. }
  419. glgeObject.setPaused( GLGE.FALSE );
  420. value = false;
  421. validProperty = true;
  422. }
  423. } else {
  424. glgeObject.setPaused( GLGE.TRUE );
  425. value = true;
  426. validProperty = true;
  427. }
  428. break;
  429. case "looping":
  430. value = Boolean( propertyValue ) ? GLGE.TRUE : GLGE.FALSE;
  431. glgeObject.setLoop( value );
  432. value = (value == GLGE.TRUE) ? true : false;
  433. validProperty = true;
  434. break;
  435. case "speed":
  436. value = Number( propertyValue ) * 30; // TODO: not safe to assume default speed is 30 fps
  437. glgeObject.setFrameRate( value );
  438. validProperty = true;
  439. break;
  440. }
  441. }
  442. var pv = propertyValue;
  443. switch ( propertyName ) {
  444. case "transform":
  445. //console.info( "setting transform of: " + nodeID + " to " + Array.prototype.slice.call( propertyValue ) );
  446. var transform = goog.vec.Mat4.createFromArray( propertyValue || [] );
  447. // Rotate 90 degress around X to convert from VWF Z-up to GLGE Y-up.
  448. if ( glgeObject instanceof GLGE.Camera ) {
  449. var columny = goog.vec.Vec4.create();
  450. goog.vec.Mat4.getColumn( transform, 1, columny );
  451. var columnz = goog.vec.Vec4.create();
  452. goog.vec.Mat4.getColumn( transform, 2, columnz );
  453. goog.vec.Mat4.setColumn( transform, 1, columnz );
  454. goog.vec.Mat4.setColumn( transform, 2, goog.vec.Vec4.negate( columny, columny ) );
  455. }
  456. // Assign the transform. GLGE matrices are transposed compared to VWF.
  457. // setStaticMatrix() doesn't propagate correctly for cameras, so we have to
  458. // decompose camera assignments.
  459. if ( glgeObject instanceof GLGE.Camera || glgeObject instanceof GLGE.Light || glgeObject instanceof GLGE.ParticleSystem ) { // setStaticMatrix doesn't work for cameras
  460. var translation = goog.vec.Vec3.create();
  461. goog.vec.Mat4.getColumn( transform, 3, translation );
  462. goog.vec.Mat4.setColumnValues( transform, 3, 0, 0, 0, 1 );
  463. goog.vec.Mat4.transpose( transform, transform );
  464. glgeObject.setRotMatrix( transform );
  465. glgeObject.setLoc( translation[0], translation[1], translation[2] );
  466. } else {
  467. // Set loc[XYZ] so that GLGE.Placeable.getPosition() will return correct
  468. // values for lookAt. setLoc() clears the static matrix, so call it
  469. // before setStaticMatrix().
  470. var translation = goog.vec.Vec3.create();
  471. goog.vec.Mat4.getColumn( transform, 3, translation );
  472. glgeObject.setLoc( translation[0], translation[1], translation[2] );
  473. // Set the full matrix.
  474. glgeObject.setStaticMatrix(
  475. goog.vec.Mat4.transpose( transform, goog.vec.Mat4.create() )
  476. );
  477. }
  478. break;
  479. case "material": {
  480. var sceneNode = this.state.scenes[ this.state.sceneRootID ];
  481. if ( sceneNode && node.glgeObject ) {
  482. if ( propertyValue && propertyValue.constructor == Array ) propertyValue = propertyValue[(Math.random() * propertyValue.length) | 0];
  483. if ( !propertyValue ) propertyValue = "grey";
  484. var mat = sceneNode.glgeDocument.getElement( propertyValue );
  485. if ( mat ) {
  486. node.glgeObject.setMaterial( mat );
  487. }
  488. }
  489. }
  490. break;
  491. case "lookAt": {
  492. //console.info( "settingProperty( " + nodeID + ", " + propertyName + ", " + propertyValue + " )" );
  493. if ( propertyValue == "activeCamera" ) {
  494. if ( this.state.cameraInUse ) {
  495. glgeObject.setLookat( this.state.cameraInUse );
  496. }
  497. } else {
  498. var lookAtNode = this.state.nodes[ propertyValue ];
  499. if ( lookAtNode && lookAtNode.glgeObject ) {
  500. //console.info( " settingProperty found lookat object" );
  501. glgeObject.setLookat( lookAtNode.glgeObject );
  502. } else {
  503. if ( glgeObject.getLookat && glgeObject.getLookat() )
  504. glgeObject.setLookat( null );
  505. }
  506. }
  507. }
  508. break;
  509. case "pickable":
  510. if ( glgeObject.setPickable ){
  511. glgeObject.setPickable( propertyValue );
  512. }
  513. break;
  514. case "visible":
  515. if ( glgeObject.setVisible ) {
  516. glgeObject.setVisible( propertyValue );
  517. }
  518. break;
  519. default:
  520. prototypes = getPrototypes.call( this, this.kernel.kernel.kernel, node["type"] );
  521. if ( isGlgeMaterialDefinition.call( this, prototypes ) ){
  522. value = setMaterialProperty.call( this, nodeID, propertyName, propertyValue );
  523. } else if ( isGlgeCameraDefinition.call( this, prototypes ) ) {
  524. value = setCameraProperty.call( this, nodeID, propertyName, propertyValue );
  525. } else if ( isGlgeLightDefinition.call( this, prototypes ) ) {
  526. value = setLightProperty.call( this, nodeID, propertyName, propertyValue );
  527. } else if ( isGlgeParticleSystemDefinition.call( this, prototypes ) ) {
  528. value = setParticleSystemProperty.call( this, nodeID, propertyName, propertyValue );
  529. } else if ( isGlgeSceneDefinition.call( this, prototypes ) ) {
  530. value = setSceneProperty.call( this, nodeID, propertyName, propertyValue );
  531. } else {
  532. if ( !validProperty ) {
  533. value = undefined;
  534. }
  535. }
  536. break;
  537. }
  538. } else if ( this.state.scenes[nodeID] ) {
  539. value = setSceneProperty.call( this, nodeID, propertyName, propertyValue );
  540. }
  541. return value;
  542. },
  543. // -- gettingProperty ----------------------------------------------------------------------
  544. gettingProperty: function( nodeID, propertyName, propertyValue ) {
  545. var node = this.state.nodes[nodeID]; // { name: childName, glgeObject: undefined }
  546. var value = undefined;
  547. var glgeModel = this;
  548. var prototypes = undefined;
  549. var validProperty = false;
  550. if ( node && node.glgeObject ) {
  551. var glgeObject = node.glgeObject;
  552. var isAnimatable = glgeObject.animate; // implements GLGE.Animatable?
  553. isAnimatable = isAnimatable && glgeObject.animation || propertyName == "looping" && glgeObject.constructor == GLGE.ParticleSystem; // has an animation?
  554. isAnimatable = isAnimatable && node.name != "cityblock.dae"; // TODO: this is a hack to prevent disabling the animation that keeps the world upright
  555. if ( isAnimatable ) {
  556. switch ( propertyName ) {
  557. case "playing":
  558. value = !Boolean( glgeObject.getPaused() );
  559. validProperty = true;
  560. break;
  561. case "looping":
  562. value = Boolean( glgeObject.getLoop() );
  563. validProperty = true;
  564. break;
  565. case "speed":
  566. value = glgeObject.getFrameRate() / 30; // TODO: not safe to assume default speed is 30 fps
  567. validProperty = true;
  568. break;
  569. }
  570. }
  571. switch ( propertyName ) {
  572. case "transform":
  573. // We would use glgeObject.getLocalMatrix(), but glgeObject.localMatrix
  574. // isn't always recalculated. So, we need to replicate the calculations from
  575. // glgeObject.getModelMatrix(). VWF matrices are transposed compared to GLGE.
  576. value = goog.vec.Mat4.transpose( glgeObject.staticMatrix ||
  577. GLGE.mulMat4(
  578. glgeObject.getTranslateMatrix(),
  579. GLGE.mulMat4(
  580. glgeObject.getRotMatrix(),
  581. glgeObject.getScaleMatrix()
  582. )
  583. ),
  584. goog.vec.Mat4.create()
  585. );
  586. // Rotate -90 degress around X to convert from GLGE Y-up to VWF Z-up.
  587. if ( glgeObject instanceof GLGE.Camera ) {
  588. var columny = goog.vec.Vec4.create();
  589. goog.vec.Mat4.getColumn( value, 1, columny );
  590. var columnz = goog.vec.Vec4.create();
  591. goog.vec.Mat4.getColumn( value, 2, columnz );
  592. goog.vec.Mat4.setColumn( value, 2, columny );
  593. goog.vec.Mat4.setColumn( value, 1, goog.vec.Vec4.negate( columnz, columnz ) );
  594. }
  595. break;
  596. case "boundingbox":
  597. var bbox;
  598. if ( glgeObject.getBoundingVolume ) {
  599. bbox = glgeObject.getBoundingVolume( true );
  600. value = { min: { x: bbox.limits[0], y: bbox.limits[2], z: bbox.limits[4] }, max: { x: bbox.limits[1], y: bbox.limits[3], z: bbox.limits[5] } };
  601. }
  602. break;
  603. case "centerOffset":
  604. var centerOff = getCenterOffset.call( this, glgeObject );
  605. var scale = this.kernel.getProperty( nodeID, "scale", undefined );
  606. value = new Array;
  607. value.push( centerOff[0] * scale[0], centerOff[1] * scale[1], centerOff[2] * scale[2] );
  608. break;
  609. case "vertices":
  610. value = getMeshVertices.call( this, glgeObject );
  611. break;
  612. case "vertexIndices":
  613. value = getMeshVertexIndices.call( this, glgeObject );
  614. break;
  615. case "meshData":
  616. value = [];
  617. var scale = this.gettingProperty( nodeID, "scale", [] );
  618. var meshList = findAllMeshes.call( this, glgeObject );
  619. for ( var i = 0; i < meshList.length; i++ ) {
  620. value.push( { "vertices": getMeshVertices.call( this, meshList[i] ),
  621. "vertexIndices": getMeshVertexIndices.call( this, meshList[i] ),
  622. "scale": scale
  623. } );
  624. }
  625. break;
  626. case "lookAt": {
  627. value = "";
  628. var lookAtObject = glgeObject.getLookat();
  629. if ( lookAtObject ) {
  630. value = getObjectID.call( glgeModel, lookAtObject, false, false );
  631. }
  632. }
  633. break;
  634. case "pickable":
  635. if ( glgeObject.getPickable ){
  636. value = glgeObject.getPickable();
  637. }
  638. break;
  639. case "visible":
  640. if ( glgeObject.getVisible ) {
  641. value = glgeObject.getVisible();
  642. }
  643. break;
  644. default:
  645. // handle all of the other types
  646. prototypes = getPrototypes.call( this, this.kernel.kernel.kernel, node["type"] );
  647. if ( isGlgeMaterialDefinition.call( this, prototypes ) ){
  648. value = getMaterialProperty.call( this, nodeID, propertyName, propertyValue );
  649. } else if ( isGlgeCameraDefinition.call( this, prototypes ) ) {
  650. value = getCameraProperty.call( this, nodeID, propertyName, propertyValue );
  651. } else if ( isGlgeLightDefinition.call( this, prototypes ) ) {
  652. value = getLightProperty.call( this, nodeID, propertyName, propertyValue );
  653. } else if ( isGlgeParticleSystemDefinition.call( this, prototypes ) ) {
  654. value = getParticleSystemProperty.call( this, nodeID, propertyName, propertyValue );
  655. } else if ( isGlgeSceneDefinition.call( this, prototypes ) ) {
  656. value = getSceneProperty.call( this, nodeID, propertyName, propertyValue );
  657. } else {
  658. if ( !validProperty ) {
  659. value = undefined;
  660. }
  661. }
  662. break;
  663. }
  664. } else if ( this.state.scenes[nodeID] ) {
  665. value = getSceneProperty.call( this, nodeID, propertyName, propertyValue );
  666. }
  667. // if ( value && value instanceof Object && !( value instanceof Array ) && !( value instanceof Float32Array ) ){
  668. // console.info( "WARNING: gettingProperty( "+nodeID+", "+propertyName+" ) returning an OBJECT: " + value );
  669. // }
  670. return value;
  671. },
  672. // TODO: deletingMethod
  673. // -- callingMethod --------------------------------------------------------------------------
  674. // callingMethod: function( nodeID, methodName /* [, parameter1, parameter2, ... ] */ ) { // TODO: parameters
  675. // return undefined;
  676. // },
  677. // TODO: creatingEvent, deltetingEvent, firingEvent
  678. // -- executing ------------------------------------------------------------------------------
  679. // executing: function( nodeID, scriptText, scriptType ) {
  680. // return undefined;
  681. // },
  682. // == ticking =============================================================================
  683. // ticking: function( vwfTime ) {
  684. // },
  685. } );
  686. // == Private functions ==================================================================
  687. // -- checkCompatibility -------------------------------------------------------------
  688. function checkCompatibility() {
  689. this.compatibilityStatus = { compatible:true, errors:{} }
  690. var contextNames = ["webgl","experimental-webgl","moz-webgl","webkit-3d"];
  691. for(var i = 0; i < contextNames.length; i++){
  692. try{
  693. var canvas = document.createElement('canvas');
  694. var gl = canvas.getContext(contextNames[i]);
  695. if(gl){
  696. return true;
  697. }
  698. }
  699. catch(e){}
  700. }
  701. this.compatibilityStatus.compatible = false;
  702. this.compatibilityStatus.errors["WGL"] = "This browser is not compatible. The vwf/view/threejs driver requires WebGL.";
  703. return false;
  704. }
  705. // -- initScene ------------------------------------------------------------------------
  706. function initScene( sceneNode ) {
  707. if ( sceneNode && !sceneNode.modelInited ) {
  708. sceneNode.modelInited = true;
  709. //findAllColladaObjs.call( this, sceneNode.glgeScene, sceneNode.ID );
  710. }
  711. }
  712. // -- loadCollada ------------------------------------------------------------------------
  713. function loadCollada( parentNode, node, propertyNotifyCallback ) {
  714. // Create new GLGE collada object
  715. node.glgeObject = new GLGE.Collada;
  716. // Set properties on new GLGE collada object
  717. var sceneNode = this.state.scenes[ this.state.sceneRootID ];
  718. var colladaLoadedCallback = setColladaCallback.call( this, node.glgeObject, sceneNode,
  719. propertyNotifyCallback );
  720. node.glgeObject.vwfID = node.ID;
  721. node.glgeObject.setDocument( node.source, window.location.href, colladaLoadedCallback );
  722. // Add the new GLGE collada object to the list of those that need to be loaded
  723. sceneNode.srcColladaObjects.push( node.glgeObject );
  724. // If the new node has a parent, attach its GLGE object to that of the parent
  725. // Else, attach it to the scene directly as a top-level object
  726. if ( parentNode && parentNode.glgeObject )
  727. parentNode.glgeObject.addCollada( node.glgeObject );
  728. else if ( sceneNode && sceneNode.glgeScene )
  729. sceneNode.glgeScene.addCollada( node.glgeObject );
  730. }
  731. // -- findCollada ------------------------------------------------------------------------
  732. function findCollada( grp, nodeID ) {
  733. if ( grp && grp.getChildren ) {
  734. var children = grp.getChildren();
  735. var sceneNode = this.state.scenes[ this.state.sceneRootID ];
  736. for ( var i = 0; i < children.length; i++ ) {
  737. if ( children[i].constructor == GLGE.Collada ) {
  738. var modelID = nodeID;
  739. var glgeModel = this;
  740. sceneNode.xmlColladaObjects.push( children[i] );
  741. setColladaCallback.call( this, children[i], sceneNode );
  742. children[i].loadedCallback = colladaLoaded;
  743. sceneNode.pendingLoads++;
  744. }
  745. findCollada.call( this, children[i] );
  746. }
  747. }
  748. }
  749. // -- setColladaCallback ------------------------------------------------------------------------
  750. function setColladaCallback( glgeColladaObject, sceneNode, propertyNotifyCallback ) {
  751. var self = this;
  752. // Update the number of pending loads on the scene node
  753. // This information is just for our own knowledge; it is not used anywhere
  754. // (But double-check to make sure no one has added a reference before you do anything drastic)
  755. sceneNode.pendingLoads++;
  756. // Set the callback as defined below
  757. glgeColladaObject.loadedCallback = colladaLoaded;
  758. function colladaLoaded( colladaObject ) {
  759. // Undo default GLGE rotation applied in GLGE.Collada.initVisualScene that adjusts for +Y up
  760. colladaObject.setRot( 0, 0, 0 );
  761. // Update the number of pending loads on the scene node
  762. // This information is just for our own knowledge; it is not used anywhere
  763. // (But double-check to make sure no one has added a reference before you do anything drastic)
  764. sceneNode.pendingLoads--;
  765. // Now that this object has loaded, remove it from the list of objects to be loaded
  766. var removedFromLoadList = false;
  767. for ( var i = 0; !removedFromLoadList && i < sceneNode.srcColladaObjects.length; i++ ) {
  768. if ( sceneNode.srcColladaObjects[ i ] == colladaObject ){
  769. sceneNode.srcColladaObjects.splice( i, 1 );
  770. removedFromLoadList = true;
  771. }
  772. }
  773. for ( var i = 0; !removedFromLoadList && i < sceneNode.xmlColladaObjects.length; i++ ) {
  774. if ( sceneNode.xmlColladaObjects[ i ] == colladaObject ){
  775. sceneNode.xmlColladaObjects.splice( i, 1 );
  776. removedFromLoadList = true;
  777. }
  778. }
  779. // Since prototypes are created before the object, it does not get "setProperty" updates for
  780. // its prototype (and behavior) properties. Therefore, we cycle through those properties to
  781. // notify the drivers of the property values so they can react accordingly
  782. // TODO: Have the kernel send the "setProperty" updates itself so the driver need not
  783. if ( propertyNotifyCallback )
  784. propertyNotifyCallback();
  785. // If the VWF node for the newly loaded collada has a callback function, call it
  786. // TODO: Since the callback resumes the queue, maybe we should not call it if there are still
  787. // objects to be loaded
  788. var id = colladaObject.vwfID || getObjectID.call( self, colladaObject, true, false );
  789. if ( id && ( id != "" ) ) {
  790. var colladaNode = self.state.nodes[ id ];
  791. if ( colladaNode && colladaNode.loadedCallback ) {
  792. colladaNode.loadedCallback( true );
  793. }
  794. }
  795. }
  796. return colladaLoaded;
  797. }
  798. // -- findColladaParent ------------------------------------------------------------------------
  799. function findAllColladaObjs( glgeScene, nodeID ) {
  800. findCollada.call( this, glgeScene, nodeID );
  801. }
  802. // -- findColladaParent ------------------------------------------------------------------------
  803. function findColladaParent( glgeObject ) {
  804. var colladaObj = undefined;
  805. var currentObj;
  806. if ( glgeObject ) {
  807. currentObj = glgeObject;
  808. while ( !colladaObj && currentObj ) {
  809. if ( currentObj.constructor == GLGE.Collada )
  810. colladaObj = currentObj;
  811. else
  812. currentObj = currentObj.parent;
  813. }
  814. }
  815. return colladaObj;
  816. }
  817. // -- setSceneProperty ------------------------------------------------------------------------
  818. function setSceneProperty( nodeID, propertyName, propertyValue ) {
  819. var value = propertyValue;
  820. var sceneNode = this.state.scenes[ nodeID ];
  821. if ( sceneNode && sceneNode.glgeScene ) {
  822. switch ( propertyName ) {
  823. case "ambientColor":
  824. if ( propertyValue )
  825. sceneNode.glgeScene.setAmbientColor( propertyValue );
  826. else
  827. this.logger.warn( "Invalid ambient color");
  828. break;
  829. case "activeCamera":
  830. if ( this.state.nodes[ propertyValue ] ) {
  831. setActiveCamera.call( this, sceneNode, propertyValue );
  832. }
  833. break;
  834. case "backgroundColor":
  835. if ( propertyValue )
  836. sceneNode.glgeScene.setBackgroundColor( propertyValue );
  837. else
  838. this.logger.warn( "Invalid background color");
  839. break;
  840. default:
  841. value = undefined;
  842. break;
  843. }
  844. }
  845. return value;
  846. }
  847. // -- setParticleSystemProperty ------------------------------------------------------------------------
  848. function setParticleSystemProperty( nodeID, propertyName, propertyValue ) {
  849. var node = this.state.nodes[nodeID]; // { name: childName, glgeObject: undefined }
  850. var value = propertyValue;
  851. switch ( propertyName ) {
  852. case "numberParticles":
  853. node.glgeObject.setNumParticles( propertyValue );
  854. break;
  855. case "lifeTime":
  856. node.glgeObject.setLifeTime( propertyValue );
  857. break;
  858. case "maxLifeTime":
  859. node.glgeObject.setMaxLifeTime( propertyValue );
  860. break;
  861. case "minLifeTime":
  862. node.glgeObject.setMinLifeTime( propertyValue );
  863. break;
  864. case "startSize":
  865. node.glgeObject.setStartSize( propertyValue );
  866. break;
  867. case "endSize":
  868. node.glgeObject.setEndSize( propertyValue );
  869. break;
  870. case "loop":
  871. node.glgeObject.setLoop( propertyValue );
  872. break;
  873. case "velocity":
  874. if ( propertyValue )
  875. node.glgeObject.setVelocity( propertyValue[0], propertyValue[1], propertyValue[2] );
  876. break;
  877. case "maxVelocity":
  878. if ( propertyValue )
  879. node.glgeObject.setMaxVelocity( propertyValue[0], propertyValue[1], propertyValue[2] );
  880. break;
  881. case "minVelocity":
  882. if ( propertyValue )
  883. node.glgeObject.setMinVelocity( propertyValue[0], propertyValue[1], propertyValue[2] );
  884. break;
  885. case "startAcceleration":
  886. if ( propertyValue )
  887. node.glgeObject.setStartAccelertaion( propertyValue[0], propertyValue[1],
  888. propertyValue[2] );
  889. break;
  890. case "endAcceleration":
  891. if ( propertyValue )
  892. node.glgeObject.setEndAccelertaion( propertyValue[0], propertyValue[1], propertyValue[2] );
  893. break;
  894. case "maxStartAcceleration":
  895. if ( propertyValue )
  896. node.glgeObject.setMaxStartAccelertaion( propertyValue[0], propertyValue[1],
  897. propertyValue[2] );
  898. break;
  899. case "maxEndAcceleration":
  900. if ( propertyValue )
  901. node.glgeObject.setMaxEndAccelertaion( propertyValue[0], propertyValue[1],
  902. propertyValue[2] );
  903. break;
  904. case "minStartAcceleration":
  905. if ( propertyValue )
  906. node.glgeObject.setMinStartAccelertaion( propertyValue[0], propertyValue[1],
  907. propertyValue[2] );
  908. break;
  909. case "minEndAcceleration":
  910. if ( propertyValue )
  911. node.glgeObject.setMinEndAccelertaion( propertyValue[0], propertyValue[1],
  912. propertyValue[2] );
  913. break;
  914. case "startColor":
  915. if ( propertyValue )
  916. node.glgeObject.setStartColor( propertyValue );
  917. break;
  918. case "endColor":
  919. if ( propertyValue )
  920. node.glgeObject.setEndColor( propertyValue );
  921. break;
  922. case "image":
  923. node.glgeObject.setImage( propertyValue );
  924. break;
  925. default:
  926. value = undefined;
  927. break;
  928. }
  929. return value;
  930. }
  931. // -- setCameraProperty ------------------------------------------------------------------------
  932. function setCameraProperty( nodeID, propertyName, propertyValue ) {
  933. var node = this.state.nodes[nodeID]; // { name: childName, glgeObject: undefined }
  934. var value = propertyValue;
  935. switch ( propertyName ) {
  936. case "cameraType":
  937. switch ( propertyValue ) {
  938. case "perspective":
  939. node.glgeObject.setType( GLGE.C_PERSPECTIVE );
  940. break;
  941. case "orthographic":
  942. node.glgeObject.setType( GLGE.C_ORTHO );
  943. break;
  944. default:
  945. value = undefined;
  946. break;
  947. }
  948. break;
  949. case "far":
  950. node.glgeObject.setFar( Number( propertyValue ) );
  951. break;
  952. case "near":
  953. node.glgeObject.setNear( Number( propertyValue ) );
  954. break;
  955. case "fovy":
  956. node.glgeObject.setFovY( Number( propertyValue ) );
  957. break;
  958. case "aspect":
  959. // If the propertyValue is real, set it
  960. // Else, it will be set to be the aspect ratio of the GLGE canvas
  961. if ( propertyValue )
  962. node.glgeObject.setAspect( Number( propertyValue ) );
  963. break;
  964. // case "orthoscale":
  965. // if ( propertyValue ) {
  966. // node.glgeObject.setOrthoScale( Number( propertyValue ) );
  967. // }
  968. // break;
  969. default:
  970. value = undefined;
  971. break;
  972. }
  973. return value;
  974. }
  975. // -- setMaterialProperty ------------------------------------------------------------------------
  976. function setMaterialProperty( nodeID, propertyName, propertyValue ) {
  977. var node = this.state.nodes[ nodeID ];
  978. var value = propertyValue;
  979. var txtr, mat, txtrPropValue;
  980. if ( propertyValue ) {
  981. if ( node.glgeMaterial && node.glgeMaterial.textures ) {
  982. mat = node.glgeMaterial;
  983. txtr = node.glgeMaterial.textures[0];
  984. } else if ( node.glgeObject && node.glgeObject.material ) {
  985. mat = node.glgeObject.material;
  986. txtr = node.glgeObject.material.textures[0];
  987. }
  988. switch ( propertyName ) {
  989. case "texture": {
  990. // setting the texture back to the same value is causing a problem, need
  991. // to find out why so this get and check can be removed
  992. txtrPropValue = getMaterialProperty.call( this, nodeID, propertyName );
  993. //console.info( "txtrProp = " + txtrPropValue );
  994. //console.info( "Setting the texture of: " + nodeID + " to " + propertyValue);
  995. if ( ( propertyValue !== undefined ) && ( propertyValue != "" ) && ( propertyValue != txtrPropValue ) ) {
  996. var textureType = "image";
  997. if ( propertyValue == "canvas" ) {
  998. textureType = "canvas";
  999. } else if ( propertyValue.indexOf( "canvas_" ) == 0 ) {
  1000. textureType = "canvas";
  1001. } else if ( this.state.nodes[propertyValue] ) {
  1002. textureType = "camera";
  1003. } else if ( !isImageFileRef.call( this, propertyValue ) /* isVideoFileRef.call( this, propertyValue ) */ ) {
  1004. textureType = "video";
  1005. }
  1006. //console.info( " mat: " + mat );
  1007. //console.info( " txtr: " + txtr );
  1008. //console.info( " textureType: " + textureType );
  1009. var isCorrectTexture = false;
  1010. if ( txtr ) {
  1011. switch ( textureType ){
  1012. case "image":
  1013. isCorrectTexture = ( txtr instanceof GLGE.Texture );
  1014. break;
  1015. case "canvas":
  1016. isCorrectTexture = ( txtr instanceof GLGE.TextureCanvas );
  1017. break;
  1018. case "camera":
  1019. isCorrectTexture = ( txtr instanceof GLGE.TextureCamera );
  1020. break;
  1021. case "video":
  1022. isCorrectTexture = ( txtr instanceof GLGE.TextureVideo );
  1023. break;
  1024. }
  1025. }
  1026. //console.info( " isCorrectTexture: " + isCorrectTexture );
  1027. if ( isCorrectTexture ) {
  1028. if ( textureType == "video" || textureType == "image" ){
  1029. txtr.setSrc( propertyValue );
  1030. } else if ( "camera" ) {
  1031. var camNode = this.state.nodes[ propertyValue ];
  1032. var cam = findCamera.call( this, camNode );
  1033. if ( cam ) {
  1034. txtr.setCamera( cam );
  1035. }
  1036. }
  1037. } else if ( mat ) {
  1038. var txt;
  1039. var ml = new GLGE.MaterialLayer;
  1040. ml.setMapto( GLGE.M_COLOR );
  1041. ml.setMapinput( GLGE.UV1 );
  1042. //console.info( " new textureType: " + textureType );
  1043. switch ( textureType ) {
  1044. case "image":
  1045. txt = new GLGE.Texture();
  1046. txt.setSrc( propertyValue );
  1047. break;
  1048. case "canvas":
  1049. //console.info( " GLGE.TextureCanvas with id = " + propertyValue );
  1050. txt = new GLGE.TextureCanvas( undefined, "512", "512", propertyValue );
  1051. break;
  1052. case "camera":
  1053. txt = new GLGE.TextureCamera( undefined, "512", "512" );
  1054. var camNode = this.state.nodes[ propertyValue ];
  1055. var cam = findCamera.call( this, camNode );
  1056. if ( cam ) {
  1057. txt.setCamera( cam );
  1058. }
  1059. break;
  1060. case "video":
  1061. txt = new GLGE.TextureVideo( undefined, "1024", "512" );
  1062. txt.setSrc( propertyValue );
  1063. ml.setScaleX( -1 );
  1064. ml.setScaleY( -1 );
  1065. break;
  1066. }
  1067. //console.info( " txt: " + txt );
  1068. mat.addTexture( txt );
  1069. ml.setTexture( txt );
  1070. mat.addMaterialLayer( ml );
  1071. }
  1072. }
  1073. }
  1074. break;
  1075. case "color":
  1076. if ( mat ) { mat.setColor( propertyValue ); }
  1077. break;
  1078. case "ambient":
  1079. if ( mat ) { mat.setAmbient( propertyValue ); }
  1080. break;
  1081. case "specColor":
  1082. if ( mat ) { mat.setSpecularColor( propertyValue ); }
  1083. break;
  1084. case "shininess":
  1085. if ( mat ) { mat.setShininess( propertyValue ); }
  1086. break;
  1087. case "reflect":
  1088. if ( mat ) { mat.setReflectivity( propertyValue ); }
  1089. break;
  1090. case "specular":
  1091. if ( mat ) { mat.setSpecular( propertyValue ); }
  1092. break;
  1093. case "emit":
  1094. if ( mat ) { mat.setEmit( propertyValue ); }
  1095. break;
  1096. case "alpha":
  1097. if ( mat ) { mat.setAlpha( propertyValue ); }
  1098. break;
  1099. case "binaryAlpha":
  1100. if ( mat ) { mat.setBinaryAlpha( propertyValue ); }
  1101. break;
  1102. default:
  1103. value = undefined;
  1104. break;
  1105. }
  1106. }
  1107. return value;
  1108. }
  1109. // -- setLightProperty ------------------------------------------------------------------------
  1110. function setLightProperty( nodeID, propertyName, propertyValue ) {
  1111. if ( propertyValue === undefined ) return;
  1112. var node = this.state.nodes[nodeID]; // { name: childName, glgeObject: undefined }
  1113. var value = propertyValue;
  1114. switch ( propertyName ) {
  1115. case "lightType":
  1116. switch ( propertyValue ) {
  1117. case "point":
  1118. node.glgeObject.setType( GLGE.L_POINT );
  1119. break;
  1120. case "directional":
  1121. node.glgeObject.setType( GLGE.L_DIR );
  1122. break;
  1123. case "spot":
  1124. node.glgeObject.setType( GLGE.L_SPOT );
  1125. break;
  1126. default:
  1127. value = undefined;
  1128. break;
  1129. }
  1130. break;
  1131. case "enable":
  1132. if ( propertyValue && propertyValue != "false" ) {
  1133. node.glgeObject.enableLight();
  1134. } else {
  1135. node.glgeObject.disableLight();
  1136. }
  1137. break;
  1138. case "glge-constantAttenuation":
  1139. node.glgeObject.setAttenuationConstant( propertyValue );
  1140. break;
  1141. case "glge-linearAttenuation":
  1142. node.glgeObject.setAttenuationLinear( propertyValue );
  1143. break;
  1144. case "glge-quadraticAttenuation":
  1145. node.glgeObject.setAttenuationQuadratic( propertyValue );
  1146. break;
  1147. case "glge-spotCosCutOff":
  1148. node.glgeObject.setSpotCosCutOff( propertyValue );
  1149. break;
  1150. case "glge-spotCutOff":
  1151. node.glgeObject.setSpotCutOff( propertyValue );
  1152. break;
  1153. case "glge-spotExponent":
  1154. node.glgeObject.setSpotExponent( propertyValue );
  1155. break;
  1156. case "color":
  1157. node.glgeObject.setColor( propertyValue );
  1158. break;
  1159. case "diffuse":
  1160. node.glgeObject.setColor(propertyValue); // no setDiffuse() in GLGE 0.7
  1161. break;
  1162. case "specular":
  1163. case "glge-specular":
  1164. node.glgeObject.specular = propertyValue; // no setSpecular() in GLGE 0.7
  1165. break;
  1166. case "glge-samples":
  1167. node.glgeObject.setShadowSamples( propertyValue );
  1168. break;
  1169. case "glge-softness":
  1170. node.glgeObject.setShadowSoftness( propertyValue );
  1171. break;
  1172. case "glge-bufferHeight":
  1173. node.glgeObject.setBufferHeight( propertyValue );
  1174. break;
  1175. case "glge-bufferWidth":
  1176. node.glgeObject.setBufferWidth( propertyValue );
  1177. break;
  1178. case "glge-shadowBias":
  1179. node.glgeObject.setShadowBias( propertyValue );
  1180. break;
  1181. case "distance":
  1182. node.glgeObject.setDistance( propertyValue );
  1183. break;
  1184. case "castShadows":
  1185. node.glgeObject.setCastShadows( propertyValue );
  1186. break;
  1187. case "glge-spotSoftness":
  1188. node.glgeObject.setSpotSoftness( propertyValue );
  1189. break;
  1190. case "glge-spotSoftnessDistance":
  1191. node.glgeObject.setSpotSoftDistance( propertyValue );
  1192. break;
  1193. case "glge-cascadeLevels":
  1194. node.glgeObject.setCascadeLevels( propertyValue );
  1195. break;
  1196. default:
  1197. value = undefined;
  1198. break;
  1199. }
  1200. return value;
  1201. }
  1202. // -- getSceneProperty ------------------------------------------------------------------------------
  1203. function getSceneProperty( nodeID, propertyName, propertyValue ) {
  1204. var color = undefined, tempClr;
  1205. var sceneNode = this.state.scenes[nodeID] // { name: childName, glgeObject: undefined }
  1206. var value = undefined;
  1207. switch ( propertyName ) {
  1208. case "ambientColor":
  1209. color = vwfColor.call( this, sceneNode.glgeScene.getAmbientColor() );
  1210. value = color.toString();
  1211. break;
  1212. case "activeCamera":
  1213. if ( sceneNode.glgeScene.camera ) {
  1214. value = getObjectID.call( this, sceneNode.glgeScene.camera, false, false );
  1215. }
  1216. break;
  1217. case "backgroundColor":
  1218. tempClr = sceneNode.glgeScene.getBackgroundColor();
  1219. if ( tempClr ) {
  1220. if ( tempClr.r && isNaN( tempClr.r ) ) tempClr.r = 0;
  1221. if ( tempClr.g && isNaN( tempClr.g ) ) tempClr.g = 0;
  1222. if ( tempClr.b && isNaN( tempClr.b ) ) tempClr.b = 0;
  1223. if ( tempClr.a && isNaN( tempClr.a ) ) tempClr.a = 0;
  1224. color = vwfColor.call( this, tempClr );
  1225. value = color.toString();
  1226. }
  1227. break;
  1228. default:
  1229. value = undefined;
  1230. break;
  1231. }
  1232. return value;
  1233. }
  1234. // -- getParticleSystemProperty ------------------------------------------------------------------------------
  1235. function getParticleSystemProperty( nodeID, propertyName, propertyValue ) {
  1236. var value = undefined;
  1237. var obj, color;
  1238. var node = this.state.nodes[nodeID];
  1239. if ( node && node.glgeObject ) {
  1240. var ps = node.glgeObject;
  1241. switch ( propertyName ) {
  1242. case "numberParticles":
  1243. if ( ps.getNumParticles )
  1244. value = ps.getNumParticles();
  1245. break;
  1246. case "maxLifeTime":
  1247. if ( ps.getMaxLifeTime )
  1248. value = ps.getMaxLifeTime();
  1249. break;
  1250. case "minLifeTime":
  1251. if ( ps.getMinLifeTime )
  1252. value = ps.getMinLifeTime();
  1253. break;
  1254. case "startSize":
  1255. if ( ps.getStartSize )
  1256. value = ps.getStartSize();
  1257. break;
  1258. case "endSize":
  1259. if ( ps.getEndSize )
  1260. value = ps.getEndSize();
  1261. break;
  1262. case "loop":
  1263. if ( ps.getLoop )
  1264. value = ps.getLoop();
  1265. break;
  1266. case "maxVelocity":
  1267. if ( ps.getMaxVelocity ) {
  1268. obj = ps.getMaxVelocity();
  1269. value = [ obj.x, obj.y, obj.z ];
  1270. }
  1271. break;
  1272. case "minVelocity":
  1273. if ( ps.getMinVelocity ) {
  1274. obj = ps.getMinVelocity();
  1275. value = [ obj.x, obj.y, obj.z ];
  1276. }
  1277. break;
  1278. case "maxStartAcceleration":
  1279. if ( ps.getMaxStartAccelertaion ) {
  1280. obj = ps.getMaxStartAccelertaion();
  1281. value = [ obj.x, obj.y, obj.z ];
  1282. }
  1283. break;
  1284. case "maxEndAcceleration":
  1285. if ( ps.getMaxEndAccelertaion ) {
  1286. obj = ps.getMaxEndAccelertaion();
  1287. value = [ obj.x, obj.y, obj.z ];
  1288. }
  1289. break;
  1290. case "minStartAcceleration":
  1291. if ( ps.getMinStartAccelertaion ) {
  1292. obj = ps.getMinStartAccelertaion();
  1293. value = [ obj.x, obj.y, obj.z ];
  1294. }
  1295. break;
  1296. case "minEndAcceleration":
  1297. if ( ps.getMinEndAccelertaion )
  1298. obj = ps.getMinEndAccelertaion();
  1299. value = [ obj.x, obj.y, obj.z ];
  1300. break;
  1301. case "startColor":
  1302. if ( ps.getStartColor ) {
  1303. color = vwfColor.call( this, ps.getStartColor() );
  1304. value = color.toString();
  1305. } else { value = undefined; }
  1306. break;
  1307. case "endColor":
  1308. if ( ps.getEndColor ){
  1309. color = vwfColor.call( this, ps.getEndColor() );
  1310. value = color.toString();
  1311. } else { value = undefined; }
  1312. break;
  1313. case "image":
  1314. if ( ps.getImage )
  1315. value = ps.getImage();
  1316. break;
  1317. default:
  1318. value = undefined;
  1319. break;
  1320. }
  1321. }
  1322. return value;
  1323. }
  1324. // -- getObjectProperty ------------------------------------------------------------------------------
  1325. function getObjectProperty( nodeID, propertyName, propertyValue ) {
  1326. var node = this.state.nodes[ nodeID ];
  1327. var value = undefined;
  1328. var txtr, mat;
  1329. switch ( propertyName ) {
  1330. case "mesh": {
  1331. if ( node.glgeObject && node.glgeObject && node.glgeObject.getMesh ) {
  1332. value = node.glgeObject.getMesh();
  1333. }
  1334. }
  1335. break;
  1336. }
  1337. return value;
  1338. }
  1339. // -- getMaterialProperty ------------------------------------------------------------------------------
  1340. function getMaterialProperty( nodeID, propertyName, propertyValue ) {
  1341. var node = this.state.nodes[ nodeID ];
  1342. var value = undefined;
  1343. var txtr, mat, obj, color;
  1344. if ( node.glgeMaterial && node.glgeMaterial.textures ) {
  1345. mat = node.glgeMaterial;
  1346. txtr = node.glgeMaterial.textures[0];
  1347. } else if ( node.glgeObject && node.glgeObject.material ) {
  1348. mat = node.glgeObject.material;
  1349. txtr = node.glgeObject.material.textures[0];
  1350. }
  1351. switch ( propertyName ) {
  1352. case "texture":
  1353. if ( txtr ) {
  1354. if ( txtr instanceof GLGE.TextureCanvas ) {
  1355. var cv = txtr.getCanvas();
  1356. value = "canvas";
  1357. if ( cv ) {
  1358. value = cv.getAttribute( 'id' );
  1359. }
  1360. } else if ( txtr instanceof GLGE.TextureCamera ) {
  1361. var cam = txtr.getCamera();
  1362. if ( cam === this.state.cameraInUse ) {
  1363. value = "activeCamera";
  1364. } else {
  1365. value = getObjectID.call( this, cam, false, false );
  1366. }
  1367. } else {
  1368. if ( txtr.getSrc ) {
  1369. value = txtr.getSrc();
  1370. }
  1371. }
  1372. }
  1373. break;
  1374. case "color":
  1375. if ( mat ) {
  1376. color = vwfColor.call( this, mat.getColor() );
  1377. value = color.toString();
  1378. } else { value = undefined; }
  1379. break;
  1380. case "ambient":
  1381. if ( mat ) {
  1382. color = vwfColor.call( this, mat.getAmbient() );
  1383. value = color.toString();
  1384. } else { value = undefined; }
  1385. break;
  1386. case "specColor":
  1387. if ( mat ) {
  1388. color = vwfColor.call( this, mat.getSpecularColor() );
  1389. value = color.toString();
  1390. } else { value = undefined; }
  1391. break;
  1392. case "shininess":
  1393. if ( mat ) { value = mat.getShininess(); }
  1394. break;
  1395. case "reflect":
  1396. if ( mat ) { value = mat.getReflectivity(); }
  1397. break;
  1398. case "specular":
  1399. if ( mat ) { value = mat.getSpecular(); }
  1400. break;
  1401. case "emit":
  1402. if ( mat ) { value = mat.getEmit(); }
  1403. break;
  1404. case "alpha":
  1405. if ( mat ) { value = mat.getAlpha(); }
  1406. break;
  1407. case "binaryAlpha":
  1408. if ( mat ) { value = mat.getBinaryAlpha(); }
  1409. break;
  1410. }
  1411. return value;
  1412. }
  1413. // -- getLightProperty ------------------------------------------------------------------------------
  1414. function getLightProperty( nodeID, propertyName, propertyValue ) {
  1415. var value = undefined;
  1416. var node = this.state.nodes[ nodeID ];
  1417. var temp, color;
  1418. switch( propertyName ) {
  1419. case "lightType":
  1420. switch ( node.glgeObject.getType() ) {
  1421. case GLGE.L_POINT:
  1422. value = "point";
  1423. break;
  1424. case GLGE.L_DIR:
  1425. value = "directional";
  1426. break;
  1427. case GLGE.L_SPOT:
  1428. value = "spot";
  1429. break;
  1430. }
  1431. break;
  1432. case "glge-constantAttenuation":
  1433. temp = node.glgeObject.getAttenuation();
  1434. value = temp.constant;
  1435. break;
  1436. case "glge-linearAttenuation":
  1437. temp = node.glgeObject.getAttenuation();
  1438. value = temp.linear;
  1439. break;
  1440. case "glge-quadraticAttenuation":
  1441. temp = node.glgeObject.getAttenuation();
  1442. value = temp.quadratic;
  1443. break;
  1444. case "glge-spotCosCutOff":
  1445. value = node.glgeObject.getSpotCosCutOff();
  1446. break;
  1447. case "glge-spotCutOff":
  1448. node.glgeObject.getSpotCutOff( propertyValue );
  1449. break;
  1450. case "spotExponent":
  1451. value = node.glgeObject.getSpotExponent();
  1452. break;
  1453. case "color":
  1454. color = vwfColor.call( this, node.glgeObject.getColor() );
  1455. value = color.toString();
  1456. break;
  1457. case "diffuse":
  1458. value = node.glgeObject.diffuse; // no getDiffuse() in GLGE 0.7
  1459. break;
  1460. case "glge-specular":
  1461. value = node.glgeObject.specular; // no getSpecular() in GLGE 0.7
  1462. break;
  1463. case "glge-samples":
  1464. value = node.glgeObject.getShadowSamples();
  1465. break;
  1466. case "glge-softness":
  1467. value = node.glgeObject.getShadowSoftness();
  1468. break;
  1469. case "glge-bufferHeight":
  1470. value = node.glgeObject.getBufferHeight();
  1471. break;
  1472. case "glge-bufferWidth":
  1473. value = node.glgeObject.getBufferWidth();
  1474. break;
  1475. case "glge-shadowBias":
  1476. value = node.glgeObject.getShadowBias();
  1477. break;
  1478. case "distance":
  1479. value = node.glgeObject.getDistance();
  1480. break;
  1481. case "castShadows":
  1482. value = node.glgeObject.getCastShadows();
  1483. break;
  1484. case "glge-spotSoftness":
  1485. value = node.glgeObject.getSpotSoftness();
  1486. break;
  1487. case "glge-spotSoftnessDistance":
  1488. value = node.glgeObject.getSpotSoftDistance();
  1489. break;
  1490. case "glge-cascadeLevels":
  1491. value = node.glgeObject.getCascadeLevels();
  1492. break;
  1493. default:
  1494. value = undefined;
  1495. break;
  1496. }
  1497. return value;
  1498. }
  1499. // -- getCameraProperty ------------------------------------------------------------------------------
  1500. function getCameraProperty(nodeID, propertyName, propertyValue) {
  1501. var node = this.state.nodes[nodeID];
  1502. var value = undefined;
  1503. switch( propertyName ) {
  1504. case "cameraType":
  1505. switch ( node.glgeObject.getType() ) {
  1506. case GLGE.C_PERSPECTIVE:
  1507. value = "perspective";
  1508. break;
  1509. case GLGE.C_ORTHO:
  1510. value = "orthographic";
  1511. break;
  1512. }
  1513. break;
  1514. case "far":
  1515. value = node.glgeObject.getFar();
  1516. break;
  1517. case "near":
  1518. value = node.glgeObject.getNear();
  1519. break;
  1520. case "fovy":
  1521. value = node.glgeObject.getFovY();
  1522. break;
  1523. case "aspect":
  1524. value = node.glgeObject.getAspect();
  1525. break;
  1526. case "orthoscale":
  1527. value = node.glgeObject.getOrthoScale();
  1528. break;
  1529. default:
  1530. value = undefined;
  1531. break;
  1532. }
  1533. return value;
  1534. }
  1535. // -- findGlgeObject ------------------------------------------------------------------------------
  1536. function findGlgeObject( objName, type, prototypes ) {
  1537. var obj = undefined;
  1538. var assetObj = undefined;
  1539. var glgeObjName = "";
  1540. for ( var key in GLGE.Assets.assets ) {
  1541. assetObj = GLGE.Assets.assets[key];
  1542. if ( assetObj ) {
  1543. glgeObjName = name( assetObj );
  1544. if ( glgeObjName == objName ) {
  1545. switch ( type ) {
  1546. case "http://vwf.example.com/mesh.vwf":
  1547. if ( assetObj.constructor == GLGE.Object )
  1548. obj = assetObj;
  1549. break;
  1550. case "http://vwf.example.com/node3.vwf":
  1551. if ( ( assetObj.constructor == GLGE.Group ) || ( assetObj.constructor == GLGE.Object ) )
  1552. obj = assetObj;
  1553. break;
  1554. case "http://vwf.example.com/light.vwf":
  1555. if ( assetObj.constructor == GLGE.Light )
  1556. obj = assetObj;
  1557. break;
  1558. case "http://vwf.example.com/camera.vwf":
  1559. if ( assetObj.constructor == GLGE.Camera )
  1560. obj = assetObj;
  1561. break;
  1562. case "http://vwf.example.com/scene.vwf":
  1563. if ( assetObj.constructor == GLGE.Scene )
  1564. obj = assetObj;
  1565. break;
  1566. case "http://vwf.example.com/particleSystem.vwf":
  1567. if ( assetObj.constructor == GLGE.ParticleSystem )
  1568. obj = assetObj;
  1569. break;
  1570. }
  1571. if ( obj ) break;
  1572. }
  1573. }
  1574. }
  1575. return obj;
  1576. }
  1577. // -- setActiveCamera ------------------------------------------------------------------------------
  1578. function setActiveCamera( sceneNode, nodeID ) {
  1579. if ( this.state.nodes[ nodeID ] ) {
  1580. var glgeCamera = this.state.nodes[ nodeID ].glgeObject;
  1581. if ( glgeCamera ) {
  1582. setAspect.call( this, nodeID );
  1583. this.state.cameraInUse = glgeCamera;
  1584. sceneNode.glgeScene.setCamera( glgeCamera );
  1585. }
  1586. }
  1587. }
  1588. // -- setAspect ------------------------------------------------------------------------------
  1589. function setAspect( nodeID ) {
  1590. if ( this.state.nodes[ nodeID ] ) {
  1591. var glgeCamera = this.state.nodes[ nodeID ].glgeObject;
  1592. if ( glgeCamera ) {
  1593. var canvas = document.getElementById( this.state.sceneRootID );
  1594. glgeCamera.setAspect( canvas.width / canvas.height );
  1595. }
  1596. }
  1597. }
  1598. // -- createLight ------------------------------------------------------------------------------
  1599. function createLight( nodeID, childID, childName ) {
  1600. var child = this.state.nodes[childID];
  1601. if ( child ) {
  1602. child.glgeObject = new GLGE.Light();
  1603. child.glgeObject.name = childName;
  1604. child.name = childName;
  1605. child.uid = child.glgeObject.uid;
  1606. addGlgeChild.call( this, nodeID, childID );
  1607. }
  1608. }
  1609. // -- createCamera ------------------------------------------------------------------------------
  1610. function createCamera( nodeID, childID, childName ) {
  1611. var sceneNode = this.state.scenes[nodeID]
  1612. var parent = sceneNode ? sceneNode : this.state.nodes[nodeID]
  1613. if ( !sceneNode ) sceneNode = parent.glgeScene;
  1614. if ( sceneNode && parent ) {
  1615. var child = this.state.nodes[childID];
  1616. if ( child ) {
  1617. var cam = new GLGE.Camera();;
  1618. initCamera.call( this, cam );
  1619. var glgeParent = parent.glgeObject;
  1620. if ( glgeParent && ( glgeParent instanceof GLGE.Scene || glgeParent instanceof GLGE.Group )) {
  1621. glgeParent.addObject( cam );
  1622. }
  1623. child.name = childName;
  1624. child.glgeObject = cam;
  1625. child.uid = child.glgeObject.uid;
  1626. cam.name = childName;
  1627. }
  1628. }
  1629. }
  1630. // -- createParticleSystem ------------------------------------------------------------------------------
  1631. function createParticleSystem( nodeID, childID, childName ) {
  1632. var glgeParent = undefined;
  1633. var parentNode = this.state.nodes[ nodeID ];
  1634. if ( parentNode && parentNode.glgeObject && parentNode.glgeObject.getChildren ) {
  1635. glgeParent = parentNode.glgeObject;
  1636. }
  1637. if ( !glgeParent ) {
  1638. parentNode = this.state.scenes[ this.state.sceneRootID ];
  1639. glgeParent = parentNode.glgeScene;
  1640. }
  1641. if ( glgeParent ) {
  1642. var ps = new GLGE.ParticleSystem();
  1643. this.state.nodes[ childID ].glgeObject = ps;
  1644. glgeParent.addObject( ps );
  1645. }
  1646. }
  1647. // -- initCamera ------------------------------------------------------------------------------
  1648. function initCamera( glgeCamera ) {
  1649. if ( glgeCamera ) {
  1650. glgeCamera.setLoc( 0, 0, 0 );
  1651. glgeCamera.setRot( Math.PI/2, 0, 0 ); // rotate to look at +Y, VWF's default orientation
  1652. glgeCamera.setType( GLGE.C_PERSPECTIVE );
  1653. glgeCamera.setRotOrder( GLGE.ROT_XZY );
  1654. }
  1655. }
  1656. // -- getLocalBoundingBox ------------------------------------------------------------------------------
  1657. function getLocalBoundingBox( glgeObject ) {
  1658. var bBox = { xMin: Number.MAX_VALUE, xMax: -Number.MAX_VALUE,
  1659. yMin: Number.MAX_VALUE, yMax: -Number.MAX_VALUE,
  1660. zMin: Number.MAX_VALUE, zMax: -Number.MAX_VALUE };
  1661. var glgeObjectList = [];
  1662. findAllGlgeObjects.call( this, glgeObject, glgeObjectList );
  1663. for ( var j = 0; j < glgeObjectList.length; j++ ) {
  1664. var vertices = getMeshVertices.call( this, glgeObjectList[j] );
  1665. for ( var i = 0; i < vertices.length; i++ ) {
  1666. if ( vertices[i][0] < bBox.xMin )
  1667. bBox.xMin = vertices[i][0];
  1668. if ( vertices[i][0] > bBox.xMax )
  1669. bBox.xMax = vertices[i][0];
  1670. if ( vertices[i][1] < bBox.yMin )
  1671. bBox.yMin = vertices[i][1];
  1672. if ( vertices[i][1] > bBox.yMax )
  1673. bBox.yMax = vertices[i][1];
  1674. if ( vertices[i][2] < bBox.zMin )
  1675. bBox.zMin = vertices[i][2];
  1676. if ( vertices[i][2] > bBox.zMax )
  1677. bBox.zMax = vertices[i][2];
  1678. }
  1679. }
  1680. return bBox;
  1681. }
  1682. // -- getCenterOffset ------------------------------------------------------------------------------
  1683. function getCenterOffset( glgeObject ) {
  1684. var offset = [ 0, 0, 0 ];
  1685. if ( glgeObject ) {
  1686. var bBox = getLocalBoundingBox.call( this, glgeObject )
  1687. offset[0] = ( bBox.xMax + bBox.xMin ) * 0.50;
  1688. offset[1] = ( bBox.yMax + bBox.yMin ) * 0.50;
  1689. offset[2] = ( bBox.zMax + bBox.zMin ) * 0.50;
  1690. }
  1691. return offset;
  1692. }
  1693. // -- getNodeVertices ------------------------------------------------------------------------------
  1694. function getNodeVertices( nodeID ) {
  1695. if ( this.state.nodes[nodeID] ) {
  1696. return getMeshVertices.call( this, this.state.nodes[nodeID] );
  1697. }
  1698. return undefined;
  1699. }
  1700. // -- getMeshVertices ------------------------------------------------------------------------------
  1701. function getMeshVertices( glgeObject ) {
  1702. var vertices = [];
  1703. var glgeMesh;
  1704. if ( glgeObject ) {
  1705. if ( glgeObject.getChildren && !glgeObject.getMesh ) {
  1706. var objects = [];
  1707. findAllGlgeObjects.call( this, glgeObject, objects );
  1708. for ( var j = 0; j < objects.length; j++ ) {
  1709. if ( objects[j].getMesh ) {
  1710. var pos = objects[j].getMesh().positions;
  1711. if ( pos ) {
  1712. for ( var i = 0; i < pos.length; i = i + 3 ) {
  1713. vertices.push([pos[i], pos[i + 1], pos[i + 2]]);
  1714. }
  1715. }
  1716. }
  1717. }
  1718. } else if ( glgeObject.getMesh && glgeObject.getMesh() ) {
  1719. glgeMesh = glgeObject.getMesh();
  1720. } else if ( glgeObject.constructor == GLGE.Mesh ) {
  1721. glgeMesh = glgeObject;
  1722. }
  1723. if ( glgeMesh ) {
  1724. var pos = glgeMesh.positions;
  1725. if ( pos ) {
  1726. for ( var i = 0; i < pos.length; i = i + 3 ) {
  1727. vertices.push( [pos[i], pos[i + 1], pos[i + 2]] );
  1728. }
  1729. }
  1730. }
  1731. }
  1732. return vertices;
  1733. }
  1734. // -- getNodeVertexIndices ------------------------------------------------------------------------------
  1735. function getNodeVertexIndices( nodeID ) {
  1736. if ( this.state.nodes[nodeID] ) {
  1737. return getMeshVertexIndices.call( this, this.state.nodes[nodeID] );
  1738. }
  1739. return undefined;
  1740. }
  1741. // -- findAllGlgeObjects ------------------------------------------------------------------------------
  1742. function findAllGlgeObjects( glgeNode, objList ) {
  1743. if ( glgeNode ) {
  1744. if ( glgeNode.constructor == GLGE.Object )
  1745. objList.push( glgeNode );
  1746. if ( glgeNode.getChildren ) {
  1747. var nodeChildren = glgeNode.getChildren();
  1748. for (var i = 0; i < nodeChildren.length; i++) {
  1749. findAllGlgeObjects.call( this, nodeChildren[i], objList );
  1750. }
  1751. }
  1752. }
  1753. }
  1754. // -- findAllMeshes ------------------------------------------------------------------------------
  1755. function findAllMeshes( glgeNode ) {
  1756. var meshes = [];
  1757. var objs = [];
  1758. findAllGlgeObjects.call( this, glgeNode, objs );
  1759. for ( var i = 0; i < objs.length; i++ ){
  1760. if ( objs[i].getMesh && objs[i].getMesh() ) {
  1761. meshes.push( objs[i].getMesh() );
  1762. }
  1763. }
  1764. return meshes;
  1765. }
  1766. // -- getGlgeObject ------------------------------------------------------------------------------
  1767. function getGlgeObject( id ) {
  1768. var glgeObj = undefined;
  1769. var node = this.state.nodes[ id ];
  1770. if ( !node && this.state.scenes[ id ] ) {
  1771. node = this.state.scenes[ id ];
  1772. }
  1773. if ( node ) {
  1774. glgeObj = node.glgeObject;
  1775. if ( !glgeObj && node.glgeScene ) {
  1776. glgeObj = node.glgeScene;
  1777. }
  1778. }
  1779. return glgeObj;
  1780. }
  1781. // -- getObjectID ------------------------------------------------------------------------------
  1782. function getObjectID( objectToLookFor, bubbleUp, debug ) {
  1783. var objectIDFound = -1;
  1784. while (objectIDFound == -1 && objectToLookFor) {
  1785. if ( debug ) {
  1786. this.logger.info("====>>> vwf.model-glge.mousePick: searching for: " + path(objectToLookFor) );
  1787. }
  1788. jQuery.each( this.state.nodes, function (nodeID, node) {
  1789. if ( node.glgeObject == objectToLookFor && !node.glgeMaterial ) {
  1790. if ( debug ) { this.logger.info("pick object name: " + name(objectToLookFor) + " with id = " + nodeID ); }
  1791. objectIDFound = nodeID;
  1792. }
  1793. });
  1794. if ( bubbleUp ) {
  1795. objectToLookFor = objectToLookFor.parent;
  1796. } else {
  1797. objectToLookFor = undefined;
  1798. }
  1799. }
  1800. if (objectIDFound != -1)
  1801. return objectIDFound;
  1802. return undefined;
  1803. }
  1804. function nameGlge(obj) {
  1805. return obj.colladaName || obj.colladaId || obj.name || obj.id || obj.uid || "";
  1806. }
  1807. function name(obj) {
  1808. return obj.colladaName || obj.colladaId || obj.name || obj.id || "";
  1809. }
  1810. function path(obj) {
  1811. var sOut = "";
  1812. var sName = "";
  1813. while (obj && obj.parent) {
  1814. if (sOut == "")
  1815. sOut = name(obj);
  1816. else
  1817. sOut = name(obj) + "." + sOut;
  1818. obj = obj.parent;
  1819. }
  1820. return sOut;
  1821. }
  1822. function vwfColor( color ) {
  1823. var vwfColor = {};
  1824. vwfColor['r'] = color['r']*255;
  1825. vwfColor['g'] = color['g']*255;
  1826. vwfColor['b'] = color['b']*255;
  1827. if ( color['a'] !== undefined && color['a'] != 1 ) {
  1828. vwfColor['a'] = color['a'];
  1829. vwfColor = new utility.color( "rgba("+vwfColor['r']+","+vwfColor['g']+","+vwfColor['b']+","+vwfColor['a']+")" );
  1830. } else {
  1831. vwfColor = new utility.color( "rgb("+vwfColor['r']+","+vwfColor['g']+","+vwfColor['b']+")" );
  1832. }
  1833. return vwfColor;
  1834. }
  1835. function getMeshVertexIndices( glgeObject ) {
  1836. var vertexIndices = [];
  1837. var mesh;
  1838. if ( glgeObject ) {
  1839. if ( glgeObject.getMesh && glgeObject.getMesh() ) {
  1840. mesh = glgeObject.getMesh();
  1841. } else if ( glgeObject.constructor == GLGE.Mesh ) {
  1842. mesh = glgeObject;
  1843. }
  1844. if ( mesh && mesh.faces ) {
  1845. var faces = mesh.faces.data;
  1846. if ( faces ) {
  1847. for (var i = 0; i < faces.length; i = i + 3) {
  1848. vertexIndices.push( [faces[i], faces[i + 1], faces[i + 2]] );
  1849. }
  1850. }
  1851. }
  1852. }
  1853. return vertexIndices;
  1854. }
  1855. // get the list of types this ID extends
  1856. function getPrototypes( kernel, extendsID ) {
  1857. var prototypes = [];
  1858. var id = extendsID;
  1859. while ( id !== undefined ) {
  1860. prototypes.push( id );
  1861. id = kernel.prototype( id );
  1862. }
  1863. return prototypes;
  1864. }
  1865. function isPrototype( nodeID, childID ) {
  1866. var ptID;
  1867. if ( ( nodeID == 0 && childID != this.kernel.application() ) || this.state.prototypes[ nodeID ] !== undefined ) {
  1868. if ( nodeID != 0 || childID != this.kernel.application() ) {
  1869. ptID = nodeID ? nodeID : childID;
  1870. if ( this.state.prototypes[ ptID ] !== undefined ) {
  1871. ptID = childID;
  1872. }
  1873. return ptID;
  1874. }
  1875. }
  1876. return undefined;
  1877. }
  1878. function isGlgeSceneDefinition( prototypes ) {
  1879. var foundGlge = false;
  1880. if ( prototypes ) {
  1881. for ( var i = 0; i < prototypes.length && !foundGlge; i++ ) {
  1882. foundGlge = ( prototypes[i] == "http://vwf.example.com/navscene.vwf" || prototypes[i] == "http://vwf.example.com/scene.vwf" );
  1883. }
  1884. }
  1885. return foundGlge;
  1886. }
  1887. function isGlgeNodeDefinition( prototypes ) {
  1888. var foundGlge = false;
  1889. if ( prototypes ) {
  1890. for ( var i = 0; i < prototypes.length && !foundGlge; i++ ) {
  1891. foundGlge = ( prototypes[i] == "http://vwf.example.com/node3.vwf" );
  1892. }
  1893. }
  1894. return foundGlge;
  1895. }
  1896. function isGlgeCameraDefinition( prototypes ) {
  1897. var foundGlge = false;
  1898. if ( prototypes ) {
  1899. for ( var i = 0; i < prototypes.length && !foundGlge; i++ ) {
  1900. foundGlge = ( prototypes[i] == "http://vwf.example.com/camera.vwf" );
  1901. }
  1902. }
  1903. return foundGlge;
  1904. }
  1905. function isGlgeLightDefinition( prototypes ) {
  1906. var foundGlge = false;
  1907. if ( prototypes ) {
  1908. for ( var i = 0; i < prototypes.length && !foundGlge; i++ ) {
  1909. foundGlge = ( prototypes[i] == "http://vwf.example.com/light.vwf" );
  1910. }
  1911. }
  1912. return foundGlge;
  1913. }
  1914. function isGlgeParticleSystemDefinition( prototypes ) {
  1915. var foundGlge = false;
  1916. if ( prototypes ) {
  1917. for ( var i = 0; i < prototypes.length && !foundGlge; i++ ) {
  1918. foundGlge = ( prototypes[i] == "http://vwf.example.com/particlesystem.vwf" );
  1919. }
  1920. }
  1921. return foundGlge;
  1922. }
  1923. function isGlgeMaterialDefinition( prototypes ) {
  1924. var foundGlge = false;
  1925. if ( prototypes ) {
  1926. for ( var i = 0; i < prototypes.length && !foundGlge; i++ ) {
  1927. foundGlge = ( prototypes[i] == "http://vwf.example.com/material.vwf" );
  1928. }
  1929. }
  1930. return foundGlge;
  1931. }
  1932. // Search a GLGE.Scene for a child with the given name.
  1933. function glgeSceneChild(glgeScene, childName) {
  1934. var childToReturn = jQuery.grep(glgeScene.children || [], function (glgeChild) {
  1935. return (glgeChild.name || glgeChild.id || glgeChild.sourceURL || "") == childName;
  1936. }).shift();
  1937. //this.logger.info(" glgeSceneChild( " + childName + " ) returns " + childToReturn);
  1938. return childToReturn;
  1939. }
  1940. // Search a GLGE.Object, GLGE.Collada, GLGE.Light for a child with the given name. TODO: really, it's anything with children[]; could be the same as glgeSceneChild().
  1941. function glgeObjectChild( glgeObject, childName, childType, prototypes, recursive ) {
  1942. var childToReturn = jQuery.grep( glgeObject.children || [], function ( glgeChild ) {
  1943. return (glgeChild.colladaName || glgeChild.colladaId || glgeChild.name || glgeChild.id || "") == childName;
  1944. }).shift();
  1945. // to slow, and may bind to the incorrect object
  1946. if ( recursive && childToReturn === undefined ) {
  1947. if ( glgeObject.children ) {
  1948. for ( var i = 0; i < glgeObject.children.length && childToReturn === undefined; i++ )
  1949. childToReturn = glgeObjectChild.call( this, glgeObject.children[i], childName, childType, prototypes, recursive );
  1950. }
  1951. }
  1952. return childToReturn;
  1953. }
  1954. function findMaterial( parentID, materialName, materialNode ) {
  1955. var materialStringIndex, materialIndex;
  1956. var parentNode = this.state.nodes[ parentID ];
  1957. // the material name is a combination of the following information
  1958. // groupParentName + 'Material' + indexOfTheMultiMaterial
  1959. if ( parentNode ) {
  1960. if ( parentNode.glgeObject ) {
  1961. if ( parentNode.glgeObject.constructor == GLGE.Object ) {
  1962. if ( materialName == "material" ) {
  1963. materialNode.glgeObject = parentNode.glgeObject;
  1964. materialNode.glgeMaterial = materialNode.glgeObject.getMaterial();
  1965. }
  1966. } else {
  1967. var index = materialName.substr( 8 );
  1968. var glgeObjs = [];
  1969. if ( index == "" ) index = 0;
  1970. findAllGlgeObjects.call( this, parentNode.glgeObject, glgeObjs );
  1971. for ( var i = 1; i < glgeObjs.length; i++ ) {
  1972. console.info( "WARNING: passing other materials .......harding to index to 0 " );
  1973. }
  1974. if ( glgeObjs && glgeObjs.length && index < glgeObjs.length ) {
  1975. materialNode.glgeObject = glgeObjs[index];
  1976. materialNode.glgeMaterial = glgeObjs[index].getMaterial();
  1977. }
  1978. }
  1979. }
  1980. }
  1981. }
  1982. function findMesh( parentID, meshName, meshNode ) {
  1983. var materialStringIndex, materialIndex, childName;
  1984. var parentNode = this.state.nodes[ parentID ];
  1985. // the material name is a combination of the following information
  1986. // groupParentName + 'Material' + indexOfTheMultiMaterial
  1987. if ( parentNode ) {
  1988. materialStringIndex = materialName.lastIndexOf( "Material" );
  1989. materialIndex = Number( materialName.substr( materialStringIndex + 8 ) ) - 1;
  1990. childName = materialName.substr( 0, materialStringIndex );
  1991. if ( parentNode.glgeObject ) {
  1992. var glgeObjs = [];
  1993. var found = false;
  1994. findAllGlgeObjects.call( this, parentNode.glgeObject, glgeObjs );
  1995. if ( glgeObjs && glgeObjs.length ) {
  1996. for ( var i = 0; i < glgeObjs.length && !found; i++ ) {
  1997. if ( name( glgeObjs[i].parent ) == childName ) {
  1998. materialNode.glgeObject = glgeObjs[i];
  1999. materialNode.glgeMaterial = glgeObjs[i].getMaterial( materialIndex );
  2000. found = true;
  2001. }
  2002. }
  2003. } else if ( parentNode.glgeObject.children.length == 1 && parentNode.glgeObject.children[0].constructor == GLGE.Object ) {
  2004. var glgeChild = parentNode.glgeObject.children[0];
  2005. materialNode.glgeObject = glgeChild;
  2006. materialNode.glgeMaterial = glgeChild.getMaterial( materialIndex );
  2007. if ( !( materialNode.glgeMaterial ) && ( childNode.glgeObject ) ) {
  2008. materialNode.glgeMaterial = childNode.glgeObject.getMaterial();
  2009. }
  2010. }
  2011. }
  2012. }
  2013. }
  2014. function createMesh( node ) {
  2015. if ( !node.glgeParent ) {
  2016. node.glgeParent = this.state.nodes[ node.parentID ];
  2017. }
  2018. if ( node.glgeParent ) {
  2019. node.glgeObject = new GLGE.Group();
  2020. node.glgeParent.addObject( node.glgeObject );
  2021. var obj = new GLGE.Object();
  2022. obj.setMaterial( new GLGE.Material() );
  2023. obj.setMesh( new GLGE.Mesh() );
  2024. node.glgeObject.addObject( obj );
  2025. }
  2026. }
  2027. function defineMesh( def, node ) {
  2028. if ( node.glgeObject ) {
  2029. var obj = new GLGE.Object();
  2030. var mat = new GLGE.Material();
  2031. var mesh = new GLGE.Mesh();
  2032. if ( def.color ) {
  2033. mat.setColor( def.color );
  2034. }
  2035. obj.setMaterial( mat );
  2036. if ( def.positions )
  2037. mesh.setPositions( def.positions );
  2038. if ( def.normals )
  2039. mesh.setNormals( def.normals );
  2040. if ( def.uv1 )
  2041. mesh.setUV( def.uv1 );
  2042. if ( def.faces )
  2043. mesh.setFaces( def.faces );
  2044. obj.setMesh( mesh );
  2045. node.glgeObject.addObject( obj );
  2046. }
  2047. }
  2048. function BuildBox(size,offset,color)
  2049. {
  2050. var hx = size[0]/2;
  2051. var hy = size[1]/2;
  2052. var hz = size[2]/2;
  2053. var ox = offset[0];
  2054. var oy = offset[1];
  2055. var oz = offset[2];
  2056. var planemesh = new GLGE.Mesh();
  2057. var planeobj = new GLGE.Object();
  2058. planeobj.setMesh(planemesh);
  2059. var positions = [
  2060. hx + ox,hy + oy,hz + oz,
  2061. hx + ox,hy + oy,-hz + oz,
  2062. hx + ox,-hy + oy,hz + oz,
  2063. hx + ox,-hy + oy,-hz + oz,
  2064. -hx + ox,hy + oy,hz + oz,
  2065. -hx + ox,hy + oy,-hz + oz,
  2066. -hx + ox,-hy + oy,hz + oz,
  2067. -hx + ox,-hy + oy,-hz + oz
  2068. ];
  2069. var colors = [];
  2070. for(var i = 0; i < (positions.length/3); i++)
  2071. { colors.push(color[0]);
  2072. colors.push(color[1]);
  2073. colors.push(color[2]);
  2074. colors.push(color[3]);
  2075. }
  2076. var indexes = [0,2,6,6,4,0,1,3,7,7,5,1,0,1,3,3,2,0,4,5,7,7,6,4,0,1,5,5,4,0,2,3,7,7,6,2];
  2077. planemesh.setPositions(positions);
  2078. planemesh.setVertexColors(colors);
  2079. planemesh.setFaces(indexes);
  2080. var mat = new GLGE.Material();
  2081. planeobj.setPickable(true);
  2082. planeobj.setMaterial(mat);
  2083. mat.setVertexColorMode(GLGE.VC_MUL);
  2084. //mat.setColor(color);
  2085. //mat.setEmit(color);
  2086. //mat.setShadeless(true);
  2087. //mat.setAmbient([.5,.5,.5,1]);
  2088. return planeobj;
  2089. }
  2090. function BuildAxis()
  2091. {
  2092. var red = [1,.55,.55,1];
  2093. var green = [.55,1,.55,1];
  2094. var blue = [.55,.55,1,1];
  2095. var MoveGizmo = new GLGE.Group();
  2096. MoveGizmo.addChild(BuildBox([1,.030,.030],[.5,0,0],red)); //move x
  2097. MoveGizmo.addChild(BuildBox([.030,1,.030],[0,.5,0],green));//move y
  2098. MoveGizmo.addChild(BuildBox([.030,.030,1],[0,0,.5],blue));//move z
  2099. return MoveGizmo;
  2100. }
  2101. function addGlgeChild( parentID, childID ) {
  2102. var glgeParent;
  2103. var parent = this.state.nodes[ parentID ];
  2104. if ( !parent && this.state.scenes[ parentID ] ) {
  2105. parent = this.state.scenes[ parentID ];
  2106. glgeParent = parent.glgeScene;
  2107. } else {
  2108. glgeParent = parent.glgeObject;
  2109. }
  2110. if ( glgeParent && this.state.nodes[ childID ]) {
  2111. var child = this.state.nodes[ childID ];
  2112. if ( child.glgeObject ) {
  2113. glgeParent.addChild( child.glgeObject );
  2114. }
  2115. }
  2116. }
  2117. function isMovieFileRef( fileName ) {
  2118. var isMovieFile = false;
  2119. if ( fileName && fileName != "" ){
  2120. var fileSplit = fileName.split( "." );
  2121. var fileSLen = fileSplit ? fileSplit.length : 0;
  2122. if ( fileSLen > 0 ) {
  2123. switch ( fileSplit[ fileSLen-1 ] ) {
  2124. case "ogv":
  2125. isMovieFile = true;
  2126. break;
  2127. }
  2128. }
  2129. }
  2130. return isMovieFile;
  2131. }
  2132. function isImageFileRef( fileName ) {
  2133. var isImageFile = false;
  2134. if ( fileName && fileName != "" ){
  2135. var fileSplit = fileName.split( "." );
  2136. var fileSLen = fileSplit ? fileSplit.length : 0;
  2137. if ( fileSLen > 0 ) {
  2138. switch ( fileSplit[ fileSLen-1 ] ) {
  2139. case "png":
  2140. case "jpeg":
  2141. case "bmp":
  2142. case "gif":
  2143. case "tif":
  2144. case "tiff":
  2145. case "jpg":
  2146. case "tga":
  2147. isImageFile = true;
  2148. break;
  2149. }
  2150. }
  2151. }
  2152. return isImageFile;
  2153. }
  2154. function isVideoFileRef( fileName ) {
  2155. var isVideoFile = false;
  2156. if ( fileName && fileName != "" ){
  2157. var fileSplit = fileName.split( "." );
  2158. var fileSLen = fileSplit ? fileSplit.length : 0;
  2159. if ( fileSLen > 0 ) {
  2160. switch ( fileSplit[ fileSLen-1 ] ) {
  2161. case "ogg":
  2162. case "mjeg":
  2163. case "mpeg1":
  2164. case "mpeg":
  2165. case "avi":
  2166. case "mpg":
  2167. case "mp2":
  2168. case "m1v":
  2169. isVideoFile = true;
  2170. break;
  2171. }
  2172. }
  2173. }
  2174. return isVideoFile;
  2175. }
  2176. function findCamera( camNode ) {
  2177. var cam = undefined;
  2178. if ( camNode ) {
  2179. if ( camNode.glgeObject && camNode.glgeObject instanceof GLGE.Camera ){
  2180. cam = camNode.glgeObject;
  2181. } else if ( camNode.glgeObject instanceof GLGE.Group ) {
  2182. cam = new GLGE.Camera();
  2183. camNode.glgeObject.addObject( cam );
  2184. }
  2185. }
  2186. return cam;
  2187. }
  2188. } );