avatar.js 13 KB

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