index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. Component({
  2. behaviors: [require('../common/share-behavior').default],
  3. properties: {
  4. captureState: {
  5. type: Number,
  6. value: 0,
  7. observer: function (newVal, oldVal) {
  8. if (newVal !== oldVal) {
  9. if (newVal === 1) {
  10. this.capture();
  11. }
  12. }
  13. },
  14. },
  15. recordState: {
  16. type: Number,
  17. value: 0,
  18. observer: function (newVal, oldVal) {
  19. if (newVal !== oldVal) {
  20. if (newVal === 0) {
  21. this.recordEnd();
  22. } else {
  23. this.recordStart();
  24. }
  25. }
  26. }
  27. },
  28. captureQuality: {
  29. type: Number,
  30. value: 0.8,
  31. },
  32. captureType: {
  33. type: String,
  34. value: 'jpg',
  35. },
  36. recordFPS: {
  37. type: Number,
  38. value: 30,
  39. },
  40. recordWidth: {
  41. type: Number,
  42. value: undefined,
  43. },
  44. recordHeight: {
  45. type: Number,
  46. value: undefined,
  47. },
  48. recordBPS: {
  49. type: Number,
  50. value: 1000,
  51. },
  52. uiShowModelView:{
  53. type: Boolean,
  54. value: false,
  55. observer: function (newVal, oldVal) {
  56. if (newVal !== oldVal) {
  57. if(newVal){
  58. //this.ShowModel(1);
  59. }else{
  60. this.CloseModel();
  61. }
  62. }
  63. },
  64. },
  65. uiShowIndex:{
  66. type: Number,
  67. value: 0,
  68. observer: function (newVal, oldVal) {
  69. if (newVal !== oldVal) {
  70. this.ShowModel(newVal);
  71. }
  72. },
  73. }
  74. },
  75. data: {
  76. loaded: false,
  77. loadedSaoMiao:false,
  78. loaded: false,
  79. arReady: false,
  80. loaded2:false,
  81. position2:[0,0,0],
  82. rot:0,
  83. str:"1",
  84. luanniaoShow:false,
  85. fuzhuShow:false,
  86. yinglongShow:false,
  87. nianshouShow:false,
  88. sceneHight:600,
  89. sceneWidth:600
  90. },
  91. lifetimes: {
  92. async attached() {
  93. console.log('data', this.data);
  94. }
  95. },
  96. methods: {
  97. handleReady: function ({detail}) {
  98. const xrScene = this.scene = detail.value;
  99. console.log('xr-scene', xrScene);
  100. var hight = this.scene.hight;
  101. var width = this.scene.width;
  102. this.setData({sceneHight:hight});
  103. this.setData({sceneWidth:width});
  104. this.binglong = {el:this.scene.getElementById('binglong')};
  105. const scene = this.scene = detail.value;
  106. const appHide = () => this.scene.share.recordPause();
  107. const appShow = () => this.scene.share.recordResume();
  108. wx.onAppHide(appHide);
  109. wx.onAppShow(appShow);
  110. wx.offAppHide(appHide);
  111. wx.offAppShow(appShow);
  112. this.triggerEvent('sceneReady', {width: scene.width, height: scene.height});
  113. const fireworkField = xrScene.getElementById("firework");
  114. const tempSystem = fireworkField.getComponent('custom-particle')
  115. tempSystem.addSizeGradient(0,0.2);
  116. tempSystem.addSizeGradient(3,1);
  117. var myData ={}
  118. myData = {
  119. "capacity": 100,
  120. "emitRate": 0, //子发射器不进行每秒发射
  121. "burstCount": 100, // 一次爆发200粒子
  122. "burstTime": 0, // 爆发延时为0
  123. "burstCycle": 1, // 发射一次
  124. "size":[0.05],
  125. "startColor":[1,0.3,0.1,1],
  126. "endColor":[1,1,1,0],
  127. "emitterType":"SphereShape",
  128. "emitterProps": [["radius","0.5"]],
  129. "lifeTime":[1], // 粒子生命周期为3秒
  130. "stopDuration":[2], // 子发射器生命周期为3秒
  131. "speed":"2",
  132. "texture":"flarePicture"
  133. }
  134. var subEmitter = tempSystem.createSubEmitter(myData)
  135. subEmitter.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  136. //可以规定多个子发射器的阵列
  137. tempSystem.subEmitters = [subEmitter]
  138. const fireworkField2 = xrScene.getElementById("firework2");
  139. const tempSystem2 = fireworkField2.getComponent('custom-particle')
  140. tempSystem2.addSizeGradient(0,0.2);
  141. tempSystem2.addSizeGradient(3,1);
  142. var myData2 ={}
  143. myData2 = {
  144. "capacity": 100,
  145. "emitRate": 0, //子发射器不进行每秒发射
  146. "burstCount": 100, // 一次爆发200粒子
  147. "burstTime": 0.1, // 爆发延时为0
  148. "burstCycle": 1, // 发射一次
  149. "size":[0.05],
  150. "startColor":[1,0.5,0.8,1],
  151. "endColor":[1,1,1,0],
  152. "emitterType":"SphereShape",
  153. "emitterProps": [["radius","0.5"]],
  154. "lifeTime":[1], // 粒子生命周期为3秒
  155. "stopDuration":[2], // 子发射器生命周期为3秒
  156. "speed":"2",
  157. "texture":"flarePicture"
  158. }
  159. var subEmitter2 = tempSystem2.createSubEmitter(myData2)
  160. subEmitter2.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  161. //可以规定多个子发射器的阵列
  162. tempSystem2.subEmitters = [subEmitter2]
  163. const fireworkField3 = xrScene.getElementById("firework3");
  164. const tempSystem3 = fireworkField3.getComponent('custom-particle')
  165. tempSystem3.addSizeGradient(0,0.2);
  166. tempSystem3.addSizeGradient(3,1);
  167. var myData3 ={}
  168. myData3 = {
  169. "capacity": 100,
  170. "emitRate": 0, //子发射器不进行每秒发射
  171. "burstCount": 100, // 一次爆发200粒子
  172. "burstTime": 0.1, // 爆发延时为0
  173. "burstCycle": 1, // 发射一次
  174. "size":[0.05],
  175. "startColor":[1,1,0.5,1],
  176. "endColor":[1,1,1,0],
  177. "emitterType":"SphereShape",
  178. "emitterProps": [["radius","0.5"]],
  179. "lifeTime":[1], // 粒子生命周期为3秒
  180. "stopDuration":[2], // 子发射器生命周期为3秒
  181. "speed":"2",
  182. "texture":"flarePicture"
  183. }
  184. var subEmitter3 = tempSystem3.createSubEmitter(myData3)
  185. subEmitter3.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  186. //可以规定多个子发射器的阵列
  187. tempSystem3.subEmitters = [subEmitter3]
  188. const fireworkField4 = xrScene.getElementById("firework4");
  189. const tempSystem4 = fireworkField4.getComponent('custom-particle')
  190. tempSystem4.addSizeGradient(0,0.2);
  191. tempSystem4.addSizeGradient(3,1);
  192. var myData4 ={}
  193. myData4 = {
  194. "capacity": 100,
  195. "emitRate": 0, //子发射器不进行每秒发射
  196. "burstCount": 100, // 一次爆发200粒子
  197. "burstTime": 0.1, // 爆发延时为0
  198. "burstCycle": 1, // 发射一次
  199. "size":[0.05],
  200. "startColor":[1,0.5,0.8,1],
  201. "endColor":[1,1,1,0],
  202. "emitterType":"SphereShape",
  203. "emitterProps": [["radius","0.5"]],
  204. "lifeTime":[1], // 粒子生命周期为3秒
  205. "stopDuration":[2], // 子发射器生命周期为3秒
  206. "speed":"2",
  207. "texture":"flarePicture"
  208. }
  209. var subEmitter4 = tempSystem4.createSubEmitter(myData4)
  210. subEmitter4.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  211. //可以规定多个子发射器的阵列
  212. tempSystem4.subEmitters = [subEmitter4]
  213. const fireworkField5 = xrScene.getElementById("firework5");
  214. const tempSystem5 = fireworkField5.getComponent('custom-particle')
  215. tempSystem5.addSizeGradient(0,0.2);
  216. tempSystem5.addSizeGradient(3,1);
  217. var myData5 ={}
  218. myData5 = {
  219. "capacity": 100,
  220. "emitRate": 0, //子发射器不进行每秒发射
  221. "burstCount": 100, // 一次爆发200粒子
  222. "burstTime": 0.1, // 爆发延时为0
  223. "burstCycle": 1, // 发射一次
  224. "size":[0.05],
  225. "startColor":[1,1,0.5,1],
  226. "endColor":[1,1,1,0],
  227. "emitterType":"SphereShape",
  228. "emitterProps": [["radius","0.5"]],
  229. "lifeTime":[1], // 粒子生命周期为3秒
  230. "stopDuration":[2], // 子发射器生命周期为3秒
  231. "speed":"2",
  232. "texture":"flarePicture"
  233. }
  234. var subEmitter5 = tempSystem5.createSubEmitter(myData5)
  235. subEmitter5.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  236. //可以规定多个子发射器的阵列
  237. tempSystem5.subEmitters = [subEmitter5]
  238. const fireworkField6 = xrScene.getElementById("firework6");
  239. const tempSystem6 = fireworkField6.getComponent('custom-particle')
  240. tempSystem6.addSizeGradient(0,0.2);
  241. tempSystem6.addSizeGradient(3,1);
  242. var myData6 ={}
  243. myData6= {
  244. "capacity": 100,
  245. "emitRate": 0, //子发射器不进行每秒发射
  246. "burstCount": 100, // 一次爆发200粒子
  247. "burstTime": 0.1, // 爆发延时为0
  248. "burstCycle": 1, // 发射一次
  249. "size":[0.05],
  250. "startColor":[1,0.3,0.1,1],
  251. "endColor":[1,1,1,0],
  252. "emitterType":"SphereShape",
  253. "emitterProps": [["radius","0.5"]],
  254. "lifeTime":[1], // 粒子生命周期为3秒
  255. "stopDuration":[2], // 子发射器生命周期为3秒
  256. "speed":"2",
  257. "texture":"flarePicture"
  258. }
  259. var subEmitter6 = tempSystem6.createSubEmitter(myData6)
  260. subEmitter6.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  261. //可以规定多个子发射器的阵列
  262. tempSystem6.subEmitters = [subEmitter6]
  263. const fireworkField7 = xrScene.getElementById("firework7");
  264. const tempSystem7 = fireworkField7.getComponent('custom-particle')
  265. tempSystem7.addSizeGradient(0,0.2);
  266. tempSystem7.addSizeGradient(3,1);
  267. var myData7 ={}
  268. myData7 = {
  269. "capacity": 100,
  270. "emitRate": 0, //子发射器不进行每秒发射
  271. "burstCount": 100, // 一次爆发200粒子
  272. "burstTime": 0.1, // 爆发延时为0
  273. "burstCycle": 1, // 发射一次
  274. "size":[0.05],
  275. "startColor":[1,1,0.5,1],
  276. "endColor":[1,1,1,0],
  277. "emitterType":"SphereShape",
  278. "emitterProps": [["radius","0.5"]],
  279. "lifeTime":[1], // 粒子生命周期为3秒
  280. "stopDuration":[2], // 子发射器生命周期为3秒
  281. "speed":"2",
  282. "texture":"flarePicture"
  283. }
  284. var subEmitter7 = tempSystem7.createSubEmitter(myData7)
  285. subEmitter7.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  286. //可以规定多个子发射器的阵列
  287. tempSystem7.subEmitters = [subEmitter7]
  288. },
  289. handleAssetsProgress: function({detail}) {
  290. this.triggerEvent('assetsProgress', detail.value);
  291. },
  292. handleAssetsLoaded: function ({detail}) {
  293. console.log('assets loaded', detail.value);
  294. this.triggerEvent('assetsLoaded', detail.value);
  295. this.setData({
  296. loaded: true
  297. });
  298. },handleGltfLoaded2: function() {
  299. },handleGltfLoaded: function() {
  300. },
  301. handleTrackerSwitch: function ({detail}) {
  302. const active = detail.value;
  303. if(active)
  304. {
  305. this.setData({
  306. loaded2: true
  307. });
  308. }
  309. },handleARTrackerState({detail}) {
  310. // 事件的值即为`ARTracker`实例
  311. const tracker = detail.value;
  312. // 获取当前状态和错误信息
  313. const {state, errorMessage} = tracker;
  314. const element = detail.el;
  315. if( state==2)
  316. {
  317. this.triggerEvent('assetsstr',"state" + state);
  318. /*
  319. this.triggerEvent('assetsstr',"x:" + (180/Math.PI* element.scene.getNodeById("Marker").rotation.x) +"\ny:" + (180/Math.PI*element.scene.getNodeById("Marker").rotation.y)+"\nz:" + (180/Math.PI*element.scene.getNodeById("Marker").rotation.z));*/
  320. }
  321. },
  322. handleAnimationStop: function() {
  323. console.log('animation Stop');
  324. },
  325. /* handleGLTFLoadedbingLong:function({detail}){
  326. const el2 = detail.value;
  327. var state = true;
  328. const xrScene = this.scene;
  329. const xrFrameSystem = wx.getXrFrameSystem();
  330. const myModel = xrScene.getElementById('binglong');
  331. this.myModelAnimator = myModel.getComponent(xrFrameSystem.Animator);
  332. const clips = this.myModelAnimator._clips;
  333. this.clipName = []
  334. clips.forEach((v, key) => {
  335. if (key.indexOf('pose') == -1) {
  336. this.clipName.push(key)
  337. }
  338. })
  339. wx.showToast({
  340. title: this.clipName[0],
  341. });
  342. this.myModelAnimator.play.play(this.clipName[0],{ loop:5,});
  343. var interval = setInterval(function() {
  344. if(false)
  345. {
  346. clearInterval(interval);
  347. }
  348. console.log(5000 +" 毫秒更新");
  349. if(state)
  350. {
  351. state = false;
  352. this.myModelAnimator.play.play(this.clipName[1],{ loop:5,});
  353. }else{
  354. state = true;
  355. this.myModelAnimator.play.play(this.clipName[2],{ loop:5,});
  356. el2.position =(0 -2.5 -40);
  357. }
  358. }, 5000)
  359. },*/
  360. capture() {
  361. this.scene.share.captureToFriends({
  362. fileType: this.data.captureType,
  363. quality: this.data.captureQuality
  364. });
  365. },
  366. recordStart() {
  367. console.log('recordStart')
  368. wx.updateShareMenu({
  369. withShareTicket: true,
  370. success () { }
  371. })
  372. this.scene.share.recordStart({
  373. fps: 15,
  374. videoBitsPerSecond: 10000,
  375. });
  376. },
  377. recordEnd() {
  378. console.log('recordEnd')
  379. //
  380. const tempFilePath = this.scene.share.recordFinishToAlbum({
  381. fps: 15,
  382. videoBitsPerSecond: 10000,
  383. });
  384. wx.shareVideoMessage({
  385. videoPath: tempFilePath,
  386. });
  387. },
  388. ShowModel(modelIndex){
  389. console.log(' ShowMoelIndex ',modelIndex);
  390. switch(modelIndex){
  391. case 1:
  392. this.setData({luanniaoShow:true});
  393. break;
  394. case 2:
  395. this.setData({yinglongShow:true});
  396. break;
  397. case 3:
  398. this.setData({fuzhuShow:true});
  399. break;
  400. case 4:
  401. this.setData({nianshouShow:true});
  402. break;
  403. }
  404. },
  405. CloseModel(){
  406. this.setData({longshow:false});
  407. this.setData({binglongshow:false});
  408. this.setData({lanjiachongshow:false});
  409. }
  410. }
  411. })