avatar.js 11 KB

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