avatar.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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.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. myBodyDef.properties.color = myColor;
  34. var newNode = {
  35. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  36. "properties": {
  37. position: [0, -userHeight, 0]
  38. },
  39. children: {
  40. "myBody": myBodyDef,
  41. "myHead": {
  42. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  43. "properties": {
  44. "position": "0 1.6 0.5",
  45. "visible": true
  46. },
  47. children: {
  48. "visual": {
  49. "extends": "http://vwf.example.com/aframe/abox.vwf",
  50. "properties": {
  51. "color": myColor,
  52. "height": 0.5,
  53. "width": 0.5,
  54. "depth": 0.1,
  55. "visible": true
  56. }
  57. },
  58. "interpolation":
  59. {
  60. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  61. "type": "component",
  62. "properties": {
  63. "enabled": true,
  64. "duration": 50,
  65. "deltaPos": 0,
  66. "deltaRot": 0
  67. }
  68. },
  69. "myCamera":
  70. {
  71. "id": 'camera-' + this.id,
  72. "extends": "http://vwf.example.com/aframe/acamera.vwf",
  73. "properties": {
  74. "position": "0 0 -0.5",
  75. "look-controls-enabled": false,
  76. "wasd-controls": false,
  77. "userHeight": 0,
  78. }
  79. },
  80. "myCursor":
  81. {
  82. "id": 'myCursor-' + this.id,
  83. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  84. "properties": {},
  85. "children": {
  86. "line": {
  87. "extends": "http://vwf.example.com/aframe/lineComponent.vwf",
  88. "type": "component",
  89. "properties": {
  90. "start": "0 0 -1",
  91. "end": "0 0 -3",
  92. "color": myColor
  93. }
  94. }
  95. }
  96. }
  97. }
  98. },
  99. "myName": {
  100. "extends": "http://vwf.example.com/aframe/atext.vwf",
  101. "properties": {
  102. "color": myColor,
  103. "value": this.id,
  104. "side": "double",
  105. "rotation": "0 180 0",
  106. "position": "0.3 2.05 0.5"
  107. }
  108. }
  109. }
  110. }
  111. if (modelSrc) {
  112. let myBodyDef = this.modelBodyDef;
  113. myBodyDef.properties.src = modelSrc;
  114. newNode.children.myBody = myBodyDef;
  115. newNode.children.myHead.children.visual.properties.visible = false;
  116. newNode.children.myHead.children.myCursor.properties.visible = true;
  117. }
  118. //let cursor =
  119. //{
  120. // "id": 'cursor-' + this.id,
  121. // "extends": "http://vwf.example.com/aframe/acursor.vwf",
  122. //}
  123. let interpolation = {
  124. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  125. "type": "component",
  126. "properties": {
  127. "enabled": true,
  128. "duration": 50,
  129. "deltaPos": 0,
  130. "deltaRot": 0
  131. }
  132. }
  133. this.children.create( "interpolation", interpolation );
  134. //this.children.create( "myCursor", myCursor );
  135. //this.children.create( "avatarCamera", camera );
  136. // this.children.create( "avatarNameNode", avatarNameNode );
  137. this.children.create("avatarNode", newNode);
  138. // this.children.create( "avatarBodyModel", newNodeModel );
  139. //this.interpolation = "50ms";
  140. //vwf_view.kernel.createChild(this.id, "avatarCursor", cursorVis);
  141. }
  142. this.getRandomColor = function () {
  143. var letters = '0123456789ABCDEF';
  144. var color = '#';
  145. for (var i = 0; i < 6; i++) {
  146. color += letters[Math.floor(this.random() * 16)];
  147. }
  148. return color;
  149. }
  150. this.followAvatarControl = function (position, rotation) {
  151. // this.position = AFRAME.utils.coordinates.stringify(position);
  152. // this.rotation = AFRAME.utils.coordinates.stringify(rotation);
  153. this.position = AFRAME.utils.coordinates.stringify(position);
  154. let myRot = AFRAME.utils.coordinates.parse(this.rotation);
  155. let myHeadRot = AFRAME.utils.coordinates.parse(this.avatarNode.myHead.rotation);
  156. let myBodyRot = AFRAME.utils.coordinates.parse(this.avatarNode.myBody.rotation);
  157. this.rotation = [myRot.x, rotation.y, myRot.z];
  158. // let myRot = this.avatarBodyModel.rotation;
  159. // this.avatarBodyModel.rotation = [myRot.x, -rotation.y, myRot.z];
  160. //this.avatarBody.rotation = [rotation.x, myRot.y, rotation.z];
  161. //this.avatarNameNode.rotation = [myRot.x, myRot.y, rotation.z];
  162. this.avatarNode.myHead.rotation = [rotation.x, myHeadRot.y, rotation.z];
  163. // this.avatarNode.myCursor.rotation = [rotation.x, myHeadRot.y, rotation.z];
  164. // this.avatarCamera.rotation = [rotation.x, myHeadRot.y, rotation.z];
  165. }
  166. this.createSimpleAvatar = function(){
  167. if (this.avatarNode.myBody) {
  168. this.avatarNode.children.delete(this.avatarNode.myBody);
  169. var myColor = this.getRandomColor();
  170. if (this.avatarNode.myHead){
  171. myColor = this.avatarNode.myHead.visual.properties.color;
  172. }
  173. let myBodyDef = this.simpleBodyDef;
  174. myBodyDef.properties.color = myColor;
  175. this.avatarNode.children.create("myBody", myBodyDef);
  176. this.avatarNode.myHead.visual.properties.visible = true;
  177. }
  178. }
  179. this.createAvatarFromGLTF = function(modelSrc){
  180. if (this.avatarNode.myBody) {
  181. this.avatarNode.children.delete(this.avatarNode.myBody);
  182. let myBodyDef = this.modelBodyDef;
  183. myBodyDef.properties.src = modelSrc;
  184. this.avatarNode.children.create("myBody", myBodyDef);
  185. this.avatarNode.myHead.visual.properties.visible = false;
  186. this.avatarNode.myHead.myCursor.properties.visible = true;
  187. }
  188. }
  189. this.showHideCursor = function(bool){
  190. this.avatarNode.myHead.myCursor.properties.visible = bool;
  191. }