avatar.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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 (nodeDef, 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 defaultNode = {
  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.displayName,
  178. "side": "double",
  179. "rotation": "0 180 0",
  180. "position": "0.3 2.05 0.5"
  181. }
  182. }
  183. }
  184. }
  185. var newNode = Object.assign({}, defaultNode);
  186. if (nodeDef){
  187. newNode = Object.assign(defaultNode, nodeDef);
  188. }
  189. if (modelSrc) {
  190. let myBodyDef = this.modelBodyDef;
  191. myBodyDef.properties.src = modelSrc;
  192. newNode.children.myBody = myBodyDef;
  193. newNode.children.myHead.children.visual.properties.visible = false;
  194. newNode.children.myHead.children.myCursor.properties.visible = true;
  195. }
  196. //let cursor =
  197. //{
  198. // "id": 'cursor-' + this.id,
  199. // "extends": "http://vwf.example.com/aframe/acursor.vwf",
  200. //}
  201. let interpolation = {
  202. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  203. "type": "component",
  204. "properties": {
  205. "enabled": true
  206. }
  207. }
  208. this.children.create( "interpolation", interpolation );
  209. //this.children.create( "myCursor", myCursor );
  210. //this.children.create( "avatarCamera", camera );
  211. // this.children.create( "avatarNameNode", avatarNameNode );
  212. this.children.create("avatarNode", newNode);
  213. // this.localUrl = '';
  214. // this.remoteUrl = '';
  215. // this.displayName = this.id;
  216. // this.sharing = { audio: true, video: true };
  217. // this.children.create("avatarNode", newNode);
  218. // this.children.create( "avatarBodyModel", newNodeModel );
  219. //this.interpolation = "50ms";
  220. //vwf_view.kernel.createChild(this.id, "avatarCursor", cursorVis);
  221. }
  222. this.getRandomColor = function () {
  223. var letters = '0123456789ABCDEF';
  224. var color = '#';
  225. for (var i = 0; i < 6; i++) {
  226. color += letters[Math.floor(this.random() * 16)];
  227. }
  228. return color;
  229. }
  230. this.followAvatarControl = function (position, rotation) {
  231. // this.position = AFRAME.utils.coordinates.stringify(position);
  232. // this.rotation = AFRAME.utils.coordinates.stringify(rotation);
  233. //debugger;
  234. this.position = AFRAME.utils.coordinates.stringify(position);
  235. let myRot = AFRAME.utils.coordinates.parse(this.rotation);
  236. let myHeadRot = AFRAME.utils.coordinates.parse(this.avatarNode.myHead.rotation);
  237. let myBodyRot = AFRAME.utils.coordinates.parse(this.avatarNode.myBody.rotation);
  238. this.rotation = [myRot.x, rotation.y, myRot.z];
  239. // let myRot = this.avatarBodyModel.rotation;
  240. // this.avatarBodyModel.rotation = [myRot.x, -rotation.y, myRot.z];
  241. //this.avatarBody.rotation = [rotation.x, myRot.y, rotation.z];
  242. //this.avatarNameNode.rotation = [myRot.x, myRot.y, rotation.z];
  243. this.avatarNode.myHead.rotation = [rotation.x, myHeadRot.y, rotation.z];
  244. // this.avatarNode.myCursor.rotation = [rotation.x, myHeadRot.y, rotation.z];
  245. // this.avatarCamera.rotation = [rotation.x, myHeadRot.y, rotation.z];
  246. }
  247. this.setUserAvatar = function(aName){
  248. this.displayName = aName;
  249. this.avatarNode.myName.value = aName;
  250. }
  251. this.createSimpleAvatar = function(){
  252. if (this.avatarNode.myBody) {
  253. this.avatarNode.children.delete(this.avatarNode.myBody);
  254. var myColor = this.getRandomColor();
  255. if (this.avatarNode.myHead){
  256. myColor = this.avatarNode.myHead.visual.material.color;
  257. }
  258. let myBodyDef = this.simpleBodyDef;
  259. myBodyDef.children.material.properties.color = myColor;
  260. this.avatarNode.children.create("myBody", myBodyDef);
  261. this.avatarNode.myHead.visual.properties.visible = true;
  262. }
  263. }
  264. this.createAvatarFromGLTF = function(modelSrc){
  265. if (this.avatarNode.myBody) {
  266. this.avatarNode.children.delete(this.avatarNode.myBody);
  267. let myBodyDef = this.modelBodyDef;
  268. myBodyDef.properties.src = modelSrc;
  269. this.avatarNode.children.create("myBody", myBodyDef);
  270. this.avatarNode.myHead.visual.properties.visible = false;
  271. this.avatarNode.myHead.myCursor.properties.visible = true;
  272. }
  273. }
  274. this.showHideCursor = function(bool){
  275. this.avatarNode.myHead.myCursor.properties.visible = bool;
  276. }
  277. this.showHideAvatar = function(bool){
  278. this.properties.visible = bool;
  279. }
  280. this.setBigVideoHead = function(val){
  281. this.avatarNode.myHead.visual.height = 4;
  282. this.avatarNode.myHead.visual.width = 3;
  283. this.avatarNode.myBody.visible = false;
  284. }
  285. this.setSmallVideoHead = function(val){
  286. this.avatarNode.myHead.visual.height = 0.5;
  287. this.avatarNode.myHead.visual.width = 0.5;
  288. this.avatarNode.myBody.visible = true;
  289. }
  290. this.setVideoTexture = function(val){
  291. console.log(val);
  292. // this.setSmallVideoHead();
  293. this.avatarNode.myHead.visual.material.color = "white";
  294. this.avatarNode.myHead.visual.material.src = '#temp';
  295. this.avatarNode.myHead.visual.material.src = '#'+val;
  296. }
  297. this.removeVideoTexture = function(){
  298. // this.setSmallVideoHead();
  299. this.avatarNode.myHead.visual.material.color = this.avatarNode.myBody.material.color;
  300. this.avatarNode.myHead.visual.material.src = "";
  301. // this.avatarNode.myHead.visual.src = '#'+val;
  302. }
  303. this.removeSoundWebRTC = function(){
  304. if (this.avatarNode.audio)
  305. this.avatarNode.children.delete(this.avatarNode.audio);
  306. }
  307. this.setSoundWebRTC = function(val){
  308. console.log(val);
  309. if (this.avatarNode.audio) this.removeSoundWebRTC();
  310. var soundNode = {
  311. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  312. "properties": {
  313. },
  314. "children":{
  315. "streamsound":{
  316. "extends": "http://vwf.example.com/aframe/streamSoundComponent.vwf",
  317. "type": "component",
  318. "properties": {
  319. }
  320. }
  321. }
  322. }
  323. this.avatarNode.children.create("audio", soundNode );
  324. // this.setSmallVideoHead();
  325. //this.avatarNode.audio.src = '#tempAudio';
  326. //this.avatarNode.audio.src = '#'+val;
  327. }
  328. this.webrtcTurnOnOff = function(val){
  329. console.log('WEBRTC is ', val);
  330. }
  331. this.webrtcMuteAudio = function(val){
  332. console.log('WEBRTC Audio is ', val);
  333. }
  334. this.webrtcMuteVideo = function(val){
  335. console.log('WEBRTC Video is ', val);
  336. }
  337. this.initialize = function() {
  338. // this.future(0).updateAvatar();
  339. };