avatar.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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: 100,
  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. this.position = goog.vec.Vec3.createFromValues(position.x, position.y, position.z);
  236. let myRot = goog.vec.Vec3.clone(this.rotation);
  237. let myHeadRot = goog.vec.Vec3.clone(this.avatarNode.myHead.rotation);
  238. let myBodyRot = goog.vec.Vec3.clone(this.avatarNode.myBody.rotation);
  239. //let myRot = AFRAME.utils.coordinates.parse(this.rotation);
  240. //let myHeadRot = AFRAME.utils.coordinates.parse(this.avatarNode.myHead.rotation);
  241. //let myBodyRot = AFRAME.utils.coordinates.parse(this.avatarNode.myBody.rotation);
  242. // if(myRot[0] == null || myRot[2] == null) {
  243. // debugger
  244. // }
  245. this.rotation = [myRot[0], rotation.y, myRot[2]];
  246. //this.rotation = [myRot.x, rotation.y, myRot.z];
  247. // let myRot = this.avatarBodyModel.rotation;
  248. // this.avatarBodyModel.rotation = [myRot.x, -rotation.y, myRot.z];
  249. //this.avatarBody.rotation = [rotation.x, myRot.y, rotation.z];
  250. //this.avatarNameNode.rotation = [myRot.x, myRot.y, rotation.z];
  251. this.avatarNode.myHead.rotation = [rotation.x, myHeadRot[1], rotation.z];
  252. //this.avatarNode.myHead.rotation = [rotation.x, myHeadRot.y, rotation.z];
  253. // this.avatarNode.myCursor.rotation = [rotation.x, myHeadRot.y, rotation.z];
  254. // this.avatarCamera.rotation = [rotation.x, myHeadRot.y, rotation.z];
  255. }
  256. this.setUserAvatar = function(aName){
  257. this.displayName = aName;
  258. this.avatarNode.myName.value = aName;
  259. }
  260. this.createSimpleAvatar = function(){
  261. if (this.avatarNode.myBody) {
  262. this.avatarNode.children.delete(this.avatarNode.myBody);
  263. var myColor = this.getRandomColor();
  264. if (this.avatarNode.myHead){
  265. myColor = this.avatarNode.myHead.visual.material.color;
  266. }
  267. let myBodyDef = this.simpleBodyDef;
  268. myBodyDef.children.material.properties.color = myColor;
  269. this.avatarNode.children.create("myBody", myBodyDef);
  270. this.avatarNode.myHead.visual.properties.visible = true;
  271. }
  272. }
  273. this.createAvatarFromGLTF = function(modelSrc){
  274. if (this.avatarNode.myBody) {
  275. this.avatarNode.children.delete(this.avatarNode.myBody);
  276. let myBodyDef = this.modelBodyDef;
  277. myBodyDef.properties.src = modelSrc;
  278. this.avatarNode.children.create("myBody", myBodyDef);
  279. this.avatarNode.myHead.visual.properties.visible = false;
  280. this.avatarNode.myHead.myCursor.properties.visible = true;
  281. }
  282. }
  283. this.showHideCursor = function(bool){
  284. this.avatarNode.myHead.myCursor.properties.visible = bool;
  285. }
  286. this.showHideAvatar = function(bool){
  287. this.properties.visible = bool;
  288. }
  289. this.setBigVideoHead = function(val){
  290. this.avatarNode.myHead.visual.height = 4;
  291. this.avatarNode.myHead.visual.width = 3;
  292. this.avatarNode.myBody.visible = false;
  293. }
  294. this.setSmallVideoHead = function(val){
  295. this.avatarNode.myHead.visual.height = 0.5;
  296. this.avatarNode.myHead.visual.width = 0.5;
  297. this.avatarNode.myBody.visible = true;
  298. }
  299. this.setVideoTexture = function(val){
  300. console.log(val);
  301. // this.setSmallVideoHead();
  302. this.avatarNode.myHead.visual.material.color = "white";
  303. this.avatarNode.myHead.visual.material.src = '#temp';
  304. this.avatarNode.myHead.visual.material.src = '#'+val;
  305. }
  306. this.removeVideoTexture = function(){
  307. // this.setSmallVideoHead();
  308. this.avatarNode.myHead.visual.material.color = this.avatarNode.myBody.material.color;
  309. this.avatarNode.myHead.visual.material.src = "";
  310. // this.avatarNode.myHead.visual.src = '#'+val;
  311. }
  312. this.removeSoundWebRTC = function(){
  313. if (this.avatarNode.audio)
  314. this.avatarNode.children.delete(this.avatarNode.audio);
  315. }
  316. this.setSoundWebRTC = function(val){
  317. console.log(val);
  318. if (this.avatarNode.audio) this.removeSoundWebRTC();
  319. var soundNode = {
  320. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  321. "properties": {
  322. },
  323. "children":{
  324. "streamsound":{
  325. "extends": "http://vwf.example.com/aframe/streamSoundComponent.vwf",
  326. "type": "component",
  327. "properties": {
  328. }
  329. }
  330. }
  331. }
  332. this.avatarNode.children.create("audio", soundNode );
  333. // this.setSmallVideoHead();
  334. //this.avatarNode.audio.src = '#tempAudio';
  335. //this.avatarNode.audio.src = '#'+val;
  336. }
  337. this.webrtcTurnOnOff = function(val){
  338. console.log('WEBRTC is ', val);
  339. }
  340. this.webrtcMuteAudio = function(val){
  341. console.log('WEBRTC Audio is ', val);
  342. }
  343. this.webrtcMuteVideo = function(val){
  344. console.log('WEBRTC Video is ', val);
  345. }
  346. this.initialize = function() {
  347. // this.future(0).updateAvatar();
  348. };