scene.vwf.yaml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. # Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  2. # Secretary of Defense (Personnel & Readiness).
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  5. # in compliance with the License. You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software distributed under the License
  10. # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  11. # or implied. See the License for the specific language governing permissions and limitations under
  12. # the License.
  13. ## The component representation of a scene
  14. ##
  15. ## @name scene.vwf
  16. ## @namespace
  17. ---
  18. extends: http://vwf.example.com/node2.vwf
  19. properties:
  20. ## Cast Shadows
  21. ##
  22. ## @name scene.vwf#enableShadows
  23. ## @property
  24. enableShadows:
  25. ## Active camera
  26. ##
  27. ## @name scene.vwf#activeCamera
  28. ## @property
  29. activeCamera:
  30. set: |
  31. if ( this.activeCameraComp ) {
  32. if ( this.getChild ) {
  33. var cam = this.getChild( value );
  34. if ( cam ) {
  35. this.activeCameraComp = cam;
  36. this.lastActiveCamera = this.activeCamera;
  37. this.activeCamera = value;
  38. }
  39. }
  40. } else {
  41. if ( this.activeCamera != value ) {
  42. this.lastActiveCamera = this.activeCamera;
  43. this.activeCamera = value;
  44. if ( this.getChild ) {
  45. var temp = this.getChild( value );
  46. if ( temp ) this.activeCameraComp = temp;
  47. }
  48. }
  49. } //@ sourceURL=scene.set.activeCamera.vwf
  50. value: ""
  51. ## Ambient color
  52. ##
  53. ## @name scene.vwf#ambientColor
  54. ## @property
  55. ambientColor:
  56. ## Back ground color
  57. ##
  58. ## @name scene.vwf#backgroundColor
  59. ## @property
  60. backgroundColor: [ 200, 200, 200 ]
  61. ## Boolean determines whether the use wants a shared camera (true) or independent views (false).
  62. ## Defaults to true
  63. ##
  64. ## @name navscene.vwf#usersShareView
  65. ## @property
  66. usersShareView: true
  67. ## Object to be instantiated to represent a user.
  68. ## If usersShareView is true, only one is created
  69. ## Else, one is created per user
  70. ## Defaults to a camera w/ the navigable behavior attached
  71. ##
  72. ## @name navscene.vwf#userObject
  73. ## @property
  74. userObject:
  75. extends: http://vwf.example.com/camera.vwf
  76. implements: [ "http://vwf.example.com/navigable.vwf" ]
  77. properties:
  78. name: camera
  79. navmode: fly
  80. ## Boolean determines whether the users own avatars should be visible to themselves
  81. ## Defaults to false
  82. ##
  83. ## @name navscene.vwf#makeOwnAvatarVisible
  84. ## @property
  85. makeOwnAvatarVisible: false
  86. ## Determine which face will be culled when working with the shadow map
  87. ## Possible options are "none", "back", "front" and "both",
  88. ## which map to 0, 1, 2 and 3
  89. ## Defaults to "front"
  90. ##
  91. ## @name navscene.vwf#shadowMapCullFace
  92. ## @property
  93. shadowMapCullFace:
  94. set: |
  95. switch(value) {
  96. case "none":
  97. case 0:
  98. this.shadowMapCullFace = "none";
  99. break;
  100. case "back":
  101. case 1:
  102. this.shadowMapCullFace = "back";
  103. break;
  104. case "front":
  105. case 2:
  106. this.shadowMapCullFace = "front";
  107. break;
  108. case "both":
  109. case 3:
  110. this.shadowMapCullFace = "both";
  111. break;
  112. }
  113. value: "front"
  114. ## Determines the type of shadow map to use
  115. ## Possible options are "basic", "PCF" and "PCFSoft",
  116. ## which map to 0, 1, and 2
  117. ## Defaults to "PCFSoft"
  118. ##
  119. ## @name navscene.vwf#shadowMapType
  120. ## @property
  121. shadowMapType:
  122. set: |
  123. switch(value) {
  124. case "basic":
  125. case 0:
  126. this.shadowMapType = "basic";
  127. break;
  128. case "PCF":
  129. case 1:
  130. this.shadowMapType = "PCF";
  131. break;
  132. case "PCFSoft":
  133. case 2:
  134. this.shadowMapType = "PCFSoft";
  135. break;
  136. }
  137. value: "PCFSoft"
  138. methods:
  139. initializeActiveCamera:
  140. getActiveCameraComp:
  141. getChild:
  142. getActiveCamera:
  143. lastActiveCameraID:
  144. findByID:
  145. isChildOf:
  146. raycast:
  147. parameters:
  148. - origin
  149. - direction
  150. - near
  151. - far
  152. - recursive
  153. - objectIDs
  154. scripts:
  155. - |
  156. this.activeCameraComp = undefined;
  157. this.initialize = function() {
  158. if ( this.usersShareView && this.userObject ) {
  159. var scene = this;
  160. this.children.create( this.userObject.properties.name, this.userObject, function( child ) {
  161. scene.initializeActiveCamera( child );
  162. } );
  163. }
  164. }
  165. this.initializeActiveCamera = function( userObjectWithCamera ) {
  166. var cameras = userObjectWithCamera.find( "descendant-or-self::element(*,'http://vwf.example.com/camera.vwf')" );
  167. if ( cameras.length ) {
  168. this.lastActiveCamera = this.activeCamera;
  169. this.activeCamera = cameras[ 0 ].id;
  170. }
  171. }
  172. this.getActiveCameraComp = function() {
  173. return this.activeCameraComp;
  174. }
  175. this.getChild = function( childName, startingNode ) {
  176. if(!startingNode) {
  177. startingNode = this;
  178. }
  179. var len = startingNode.children.length
  180. for ( var i = 0; i < len; i++ ) {
  181. if ( startingNode.children[i].id == childName ) {
  182. return startingNode.children[i];
  183. } else if ( startingNode.children[i].name && startingNode.children[i].name == childName ) {
  184. return startingNode.children[i];
  185. } else {
  186. var childNode = this.getChild( childName, startingNode.children[i]);
  187. if(childNode) {
  188. return childNode;
  189. }
  190. }
  191. }
  192. //console.info( "WARNING: SCENE.getChild CHILD NOT FOUND: " + childName );
  193. return undefined;
  194. }
  195. this.findByID = function( node, id ) {
  196. var idNode = undefined;
  197. //console.info( "findByID( "+node.id+", "+id+" )" );
  198. if ( node ) {
  199. if ( node.id == id ) return node;
  200. for ( var i = 0; i < node.children.length && idNode === undefined; i++ ) {
  201. idNode = this.findByID( node.children[i], id );
  202. }
  203. }
  204. return idNode;
  205. }
  206. this.isChildOf = function( node, parent ) {
  207. var nodeToCheck = node.parent;
  208. var isParent = false;
  209. while ( !isParent && nodeToCheck !== undefined ) {
  210. isParent = ( nodeToCheck === parent );
  211. nodeToCheck = nodeToCheck.parent;
  212. }
  213. return isParent;
  214. }
  215. this.getActiveCameraComp = function() {
  216. return this.activeCameraComp;
  217. }
  218. this.lastActiveCameraID = function() {
  219. return this.lastActiveCamera;
  220. }
  221. this.getActiveCamera = function() {
  222. if ( !this.activeCameraComp ) {
  223. if ( this.getChild ) {
  224. this.activeCameraComp = this.getChild( this.activeCamera );
  225. }
  226. }
  227. return this.activeCameraComp;
  228. }
  229. this.lastActiveCameraID = function() {
  230. return this.lastActiveCamera;
  231. }
  232. this.load = function( obj, objName ){
  233. this.children.create( objName, obj );
  234. } //@ sourceURL=scene.vwf