avatar.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. this.simpleBodyDef = {
  2. "extends": "http://vwf.example.com/aframe/abox.vwf",
  3. "properties": {
  4. "color": "white",
  5. "position": "0 0.66 0.5",
  6. "height": 1.3,
  7. "width": 0.65,
  8. "depth": 0.1,
  9. }
  10. }
  11. this.modelBodyDef = {
  12. "extends": "http://vwf.example.com/aframe/agltfmodel.vwf",
  13. "properties": {
  14. "src": "#avatar",
  15. "position": "0 0 0.7",
  16. "rotation": "0 180 0"
  17. },
  18. "children": {
  19. "animation-mixer": {
  20. "extends": "http://vwf.example.com/aframe/anim-mixer-component.vwf",
  21. "properties": {
  22. "clip": "*",
  23. "duration": 1
  24. }
  25. }
  26. }
  27. }
  28. this.createAvatarBody = function (modelSrc) {
  29. let avatarControl = document.querySelector('#avatarControl');
  30. //let userHeight = avatarControl.getAttribute('camera').userHeight;
  31. var userHeight = avatarControl.getAttribute('look-controls').userHeight; //avatarControl.getAttribute('position').y;
  32. // if (AFRAME.utils.device.isGearVR()) {
  33. // userHeight = 0
  34. // }
  35. let myColor = this.getRandomColor();
  36. let myBodyDef = this.simpleBodyDef;
  37. //let myHandDef = this.simpleVrControllerDef;
  38. myBodyDef.properties.color = myColor;
  39. var newNode = {
  40. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  41. "properties": {
  42. "position": [0, -userHeight, 0]
  43. },
  44. children: {
  45. "myBody": myBodyDef,
  46. //"myHand": myHandDef,
  47. "myHead": {
  48. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  49. "properties": {
  50. "position": "0 1.6 0.5",
  51. "visible": true
  52. },
  53. children: {
  54. "interpolation":
  55. {
  56. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  57. "type": "component",
  58. "properties": {
  59. "enabled": true
  60. }
  61. },
  62. "visual": {
  63. "extends": "http://vwf.example.com/aframe/abox.vwf",
  64. "properties": {
  65. "color": myColor,
  66. "height": 0.5,
  67. "width": 0.5,
  68. "depth": 0.1,
  69. "visible": true
  70. }
  71. },
  72. "myCamera":
  73. {
  74. "id": 'camera-' + this.id,
  75. "extends": "http://vwf.example.com/aframe/acamera.vwf",
  76. "properties": {
  77. "position": "0 0 -0.5",
  78. "look-controls-enabled": false,
  79. "wasd-controls-enabled": false,
  80. "user-height": 0
  81. }
  82. },
  83. "myCursor":
  84. {
  85. "id": 'myCursor-' + this.id,
  86. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  87. "properties": {},
  88. "children": {
  89. "vis": {
  90. "extends": "http://vwf.example.com/aframe/abox.vwf",
  91. "properties": {
  92. "color": myColor,
  93. "position": "0 0 -3",
  94. "height": 0.05,
  95. "width": 0.05,
  96. "depth": 0.01,
  97. "visible": true
  98. }
  99. },
  100. "line": {
  101. "extends": "http://vwf.example.com/aframe/lineComponent.vwf",
  102. "type": "component",
  103. "properties": {
  104. "start": "0 0 -1",
  105. "end": "0 0 -3",
  106. "color": myColor
  107. }
  108. },
  109. // "realCursor":{
  110. // "extends": "http://vwf.example.com/aframe/acursor.vwf",
  111. // "properties": {
  112. // visible: false
  113. // },
  114. // "children": {
  115. // "raycaster": {
  116. // "extends": "http://vwf.example.com/aframe/raycasterComponent.vwf",
  117. // "type": "component",
  118. // "properties": {
  119. // //recursive: false,
  120. // //interval: 1000,
  121. // far: 100,
  122. // //objects: ".intersectable"
  123. // }
  124. // }
  125. // }
  126. // },
  127. "myRayCaster": {
  128. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  129. "properties": {},
  130. "children": {
  131. "raycaster": {
  132. "extends": "http://vwf.example.com/aframe/raycasterComponent.vwf",
  133. "type": "component",
  134. "properties": {
  135. recursive: false,
  136. interval: 1000,
  137. far: 3,
  138. objects: ".intersectable"
  139. }
  140. }
  141. }
  142. },
  143. // "raycaster-listener": {
  144. // "extends": "http://vwf.example.com/aframe/app-raycaster-listener-component.vwf",
  145. // "type": "component"
  146. // }
  147. }
  148. }
  149. }
  150. },
  151. "myName": {
  152. "extends": "http://vwf.example.com/aframe/atext.vwf",
  153. "properties": {
  154. "color": myColor,
  155. "value": this.id,
  156. "side": "double",
  157. "rotation": "0 180 0",
  158. "position": "0.3 2.05 0.5"
  159. }
  160. }
  161. }
  162. }
  163. if (modelSrc) {
  164. let myBodyDef = this.modelBodyDef;
  165. myBodyDef.properties.src = modelSrc;
  166. newNode.children.myBody = myBodyDef;
  167. newNode.children.myHead.children.visual.properties.visible = false;
  168. newNode.children.myHead.children.myCursor.properties.visible = true;
  169. }
  170. //let cursor =
  171. //{
  172. // "id": 'cursor-' + this.id,
  173. // "extends": "http://vwf.example.com/aframe/acursor.vwf",
  174. //}
  175. let interpolation = {
  176. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  177. "type": "component",
  178. "properties": {
  179. "enabled": true
  180. }
  181. }
  182. this.children.create( "interpolation", interpolation );
  183. //this.children.create( "myCursor", myCursor );
  184. //this.children.create( "avatarCamera", camera );
  185. // this.children.create( "avatarNameNode", avatarNameNode );
  186. this.children.create("avatarNode", newNode);
  187. // this.localUrl = '';
  188. // this.remoteUrl = '';
  189. // this.displayName = this.id;
  190. // this.sharing = { audio: true, video: true };
  191. // this.children.create("avatarNode", newNode);
  192. // this.children.create( "avatarBodyModel", newNodeModel );
  193. //this.interpolation = "50ms";
  194. //vwf_view.kernel.createChild(this.id, "avatarCursor", cursorVis);
  195. }
  196. this.getRandomColor = function () {
  197. var letters = '0123456789ABCDEF';
  198. var color = '#';
  199. for (var i = 0; i < 6; i++) {
  200. color += letters[Math.floor(this.random() * 16)];
  201. }
  202. return color;
  203. }
  204. this.followAvatarControl = function (position, rotation) {
  205. // this.position = AFRAME.utils.coordinates.stringify(position);
  206. // this.rotation = AFRAME.utils.coordinates.stringify(rotation);
  207. //debugger;
  208. this.position = AFRAME.utils.coordinates.stringify(position);
  209. let myRot = AFRAME.utils.coordinates.parse(this.rotation);
  210. let myHeadRot = AFRAME.utils.coordinates.parse(this.avatarNode.myHead.rotation);
  211. let myBodyRot = AFRAME.utils.coordinates.parse(this.avatarNode.myBody.rotation);
  212. this.rotation = [myRot.x, rotation.y, myRot.z];
  213. // let myRot = this.avatarBodyModel.rotation;
  214. // this.avatarBodyModel.rotation = [myRot.x, -rotation.y, myRot.z];
  215. //this.avatarBody.rotation = [rotation.x, myRot.y, rotation.z];
  216. //this.avatarNameNode.rotation = [myRot.x, myRot.y, rotation.z];
  217. this.avatarNode.myHead.rotation = [rotation.x, myHeadRot.y, rotation.z];
  218. // this.avatarNode.myCursor.rotation = [rotation.x, myHeadRot.y, rotation.z];
  219. // this.avatarCamera.rotation = [rotation.x, myHeadRot.y, rotation.z];
  220. }
  221. this.createSimpleAvatar = function(){
  222. if (this.avatarNode.myBody) {
  223. this.avatarNode.children.delete(this.avatarNode.myBody);
  224. var myColor = this.getRandomColor();
  225. if (this.avatarNode.myHead){
  226. myColor = this.avatarNode.myHead.visual.properties.color;
  227. }
  228. let myBodyDef = this.simpleBodyDef;
  229. myBodyDef.properties.color = myColor;
  230. this.avatarNode.children.create("myBody", myBodyDef);
  231. this.avatarNode.myHead.visual.properties.visible = true;
  232. }
  233. }
  234. this.createAvatarFromGLTF = function(modelSrc){
  235. if (this.avatarNode.myBody) {
  236. this.avatarNode.children.delete(this.avatarNode.myBody);
  237. let myBodyDef = this.modelBodyDef;
  238. myBodyDef.properties.src = modelSrc;
  239. this.avatarNode.children.create("myBody", myBodyDef);
  240. this.avatarNode.myHead.visual.properties.visible = false;
  241. this.avatarNode.myHead.myCursor.properties.visible = true;
  242. }
  243. }
  244. this.showHideCursor = function(bool){
  245. this.avatarNode.myHead.myCursor.properties.visible = bool;
  246. }
  247. this.setBigVideoHead = function(val){
  248. this.avatarNode.myHead.visual.height = 4;
  249. this.avatarNode.myHead.visual.width = 3;
  250. this.avatarNode.myBody.visible = false;
  251. }
  252. this.setSmallVideoHead = function(val){
  253. this.avatarNode.myHead.visual.height = 0.5;
  254. this.avatarNode.myHead.visual.width = 0.5;
  255. this.avatarNode.myBody.visible = true;
  256. }
  257. this.setVideoTexture = function(val){
  258. console.log(val);
  259. // this.setSmallVideoHead();
  260. this.avatarNode.myHead.visual.color = "white";
  261. this.avatarNode.myHead.visual.src = '#temp';
  262. this.avatarNode.myHead.visual.src = '#'+val;
  263. }
  264. this.webrtcTurnOnOff = function(val){
  265. console.log('WEBRTC is ', val);
  266. }
  267. this.webrtcMuteAudio = function(val){
  268. console.log('WEBRTC Audio is ', val);
  269. }
  270. this.webrtcMuteVideo = function(val){
  271. console.log('WEBRTC Video is ', val);
  272. }
  273. this.initialize = function() {
  274. // this.future(0).updateAvatar();
  275. };