index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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. cttime:0,
  91. starttime:0,
  92. cttimefps:0
  93. },
  94. lifetimes: {
  95. async attached() {
  96. console.log('data', this.data);
  97. }
  98. },
  99. methods: {
  100. handleReady: function ({detail}) {
  101. const xrScene = this.scene = detail.value;
  102. console.log('xr-scene', xrScene);
  103. var hight = this.scene.hight;
  104. var width = this.scene.width;
  105. this.setData({sceneHight:hight});
  106. this.setData({sceneWidth:width});
  107. this.binglong = {el:this.scene.getElementById('binglong')};
  108. const scene = this.scene = detail.value;
  109. const appHide = () => this.scene.share.recordPause();
  110. const appShow = () => this.scene.share.recordResume();
  111. wx.onAppHide(appHide);
  112. wx.onAppShow(appShow);
  113. wx.offAppHide(appHide);
  114. wx.offAppShow(appShow);
  115. this.triggerEvent('sceneReady', {width: scene.width, height: scene.height});
  116. const fireworkField = xrScene.getElementById("firework");
  117. const tempSystem = fireworkField.getComponent('custom-particle')
  118. tempSystem.addSizeGradient(0,0.2);
  119. tempSystem.addSizeGradient(3,1);
  120. var myData ={}
  121. myData = {
  122. "capacity": 100,
  123. "emitRate": 0, //子发射器不进行每秒发射
  124. "burstCount": 100, // 一次爆发200粒子
  125. "burstTime": 0, // 爆发延时为0
  126. "burstCycle": 1, // 发射一次
  127. "size":[0.05],
  128. "startColor":[1,0.3,0.1,1],
  129. "endColor":[1,1,1,0],
  130. "emitterType":"SphereShape",
  131. "emitterProps": [["radius","0.5"]],
  132. "lifeTime":[1], // 粒子生命周期为3秒
  133. "stopDuration":[2], // 子发射器生命周期为3秒
  134. "speed":"2",
  135. "texture":"flarePicture"
  136. }
  137. var subEmitter = tempSystem.createSubEmitter(myData)
  138. subEmitter.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  139. //可以规定多个子发射器的阵列
  140. tempSystem.subEmitters = [subEmitter]
  141. const fireworkField2 = xrScene.getElementById("firework2");
  142. const tempSystem2 = fireworkField2.getComponent('custom-particle')
  143. tempSystem2.addSizeGradient(0,0.2);
  144. tempSystem2.addSizeGradient(3,1);
  145. var myData2 ={}
  146. myData2 = {
  147. "capacity": 100,
  148. "emitRate": 0, //子发射器不进行每秒发射
  149. "burstCount": 100, // 一次爆发200粒子
  150. "burstTime": 0.1, // 爆发延时为0
  151. "burstCycle": 1, // 发射一次
  152. "size":[0.05],
  153. "startColor":[1,0.5,0.8,1],
  154. "endColor":[1,1,1,0],
  155. "emitterType":"SphereShape",
  156. "emitterProps": [["radius","0.5"]],
  157. "lifeTime":[1], // 粒子生命周期为3秒
  158. "stopDuration":[2], // 子发射器生命周期为3秒
  159. "speed":"2",
  160. "texture":"flarePicture"
  161. }
  162. var subEmitter2 = tempSystem2.createSubEmitter(myData2)
  163. subEmitter2.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  164. //可以规定多个子发射器的阵列
  165. tempSystem2.subEmitters = [subEmitter2]
  166. const fireworkField3 = xrScene.getElementById("firework3");
  167. const tempSystem3 = fireworkField3.getComponent('custom-particle')
  168. tempSystem3.addSizeGradient(0,0.2);
  169. tempSystem3.addSizeGradient(3,1);
  170. var myData3 ={}
  171. myData3 = {
  172. "capacity": 100,
  173. "emitRate": 0, //子发射器不进行每秒发射
  174. "burstCount": 100, // 一次爆发200粒子
  175. "burstTime": 0.1, // 爆发延时为0
  176. "burstCycle": 1, // 发射一次
  177. "size":[0.05],
  178. "startColor":[1,1,0.5,1],
  179. "endColor":[1,1,1,0],
  180. "emitterType":"SphereShape",
  181. "emitterProps": [["radius","0.5"]],
  182. "lifeTime":[1], // 粒子生命周期为3秒
  183. "stopDuration":[2], // 子发射器生命周期为3秒
  184. "speed":"2",
  185. "texture":"flarePicture"
  186. }
  187. var subEmitter3 = tempSystem3.createSubEmitter(myData3)
  188. subEmitter3.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  189. //可以规定多个子发射器的阵列
  190. tempSystem3.subEmitters = [subEmitter3]
  191. const fireworkField4 = xrScene.getElementById("firework4");
  192. const tempSystem4 = fireworkField4.getComponent('custom-particle')
  193. tempSystem4.addSizeGradient(0,0.2);
  194. tempSystem4.addSizeGradient(3,1);
  195. var myData4 ={}
  196. myData4 = {
  197. "capacity": 100,
  198. "emitRate": 0, //子发射器不进行每秒发射
  199. "burstCount": 100, // 一次爆发200粒子
  200. "burstTime": 0.1, // 爆发延时为0
  201. "burstCycle": 1, // 发射一次
  202. "size":[0.05],
  203. "startColor":[1,0.5,0.8,1],
  204. "endColor":[1,1,1,0],
  205. "emitterType":"SphereShape",
  206. "emitterProps": [["radius","0.5"]],
  207. "lifeTime":[1], // 粒子生命周期为3秒
  208. "stopDuration":[2], // 子发射器生命周期为3秒
  209. "speed":"2",
  210. "texture":"flarePicture"
  211. }
  212. var subEmitter4 = tempSystem4.createSubEmitter(myData4)
  213. subEmitter4.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  214. //可以规定多个子发射器的阵列
  215. tempSystem4.subEmitters = [subEmitter4]
  216. const fireworkField5 = xrScene.getElementById("firework5");
  217. const tempSystem5 = fireworkField5.getComponent('custom-particle')
  218. tempSystem5.addSizeGradient(0,0.2);
  219. tempSystem5.addSizeGradient(3,1);
  220. var myData5 ={}
  221. myData5 = {
  222. "capacity": 100,
  223. "emitRate": 0, //子发射器不进行每秒发射
  224. "burstCount": 100, // 一次爆发200粒子
  225. "burstTime": 0.1, // 爆发延时为0
  226. "burstCycle": 1, // 发射一次
  227. "size":[0.05],
  228. "startColor":[1,1,0.5,1],
  229. "endColor":[1,1,1,0],
  230. "emitterType":"SphereShape",
  231. "emitterProps": [["radius","0.5"]],
  232. "lifeTime":[1], // 粒子生命周期为3秒
  233. "stopDuration":[2], // 子发射器生命周期为3秒
  234. "speed":"2",
  235. "texture":"flarePicture"
  236. }
  237. var subEmitter5 = tempSystem5.createSubEmitter(myData5)
  238. subEmitter5.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  239. //可以规定多个子发射器的阵列
  240. tempSystem5.subEmitters = [subEmitter5]
  241. const fireworkField6 = xrScene.getElementById("firework6");
  242. const tempSystem6 = fireworkField6.getComponent('custom-particle')
  243. tempSystem6.addSizeGradient(0,0.2);
  244. tempSystem6.addSizeGradient(3,1);
  245. var myData6 ={}
  246. myData6= {
  247. "capacity": 100,
  248. "emitRate": 0, //子发射器不进行每秒发射
  249. "burstCount": 100, // 一次爆发200粒子
  250. "burstTime": 0.1, // 爆发延时为0
  251. "burstCycle": 1, // 发射一次
  252. "size":[0.05],
  253. "startColor":[1,0.3,0.1,1],
  254. "endColor":[1,1,1,0],
  255. "emitterType":"SphereShape",
  256. "emitterProps": [["radius","0.5"]],
  257. "lifeTime":[1], // 粒子生命周期为3秒
  258. "stopDuration":[2], // 子发射器生命周期为3秒
  259. "speed":"2",
  260. "texture":"flarePicture"
  261. }
  262. var subEmitter6 = tempSystem6.createSubEmitter(myData6)
  263. subEmitter6.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  264. //可以规定多个子发射器的阵列
  265. tempSystem6.subEmitters = [subEmitter6]
  266. const fireworkField7 = xrScene.getElementById("firework7");
  267. const tempSystem7 = fireworkField7.getComponent('custom-particle')
  268. tempSystem7.addSizeGradient(0,0.2);
  269. tempSystem7.addSizeGradient(3,1);
  270. var myData7 ={}
  271. myData7 = {
  272. "capacity": 100,
  273. "emitRate": 0, //子发射器不进行每秒发射
  274. "burstCount": 100, // 一次爆发200粒子
  275. "burstTime": 0.1, // 爆发延时为0
  276. "burstCycle": 1, // 发射一次
  277. "size":[0.05],
  278. "startColor":[1,1,0.5,1],
  279. "endColor":[1,1,1,0],
  280. "emitterType":"SphereShape",
  281. "emitterProps": [["radius","0.5"]],
  282. "lifeTime":[1], // 粒子生命周期为3秒
  283. "stopDuration":[2], // 子发射器生命周期为3秒
  284. "speed":"2",
  285. "texture":"flarePicture"
  286. }
  287. var subEmitter7 = tempSystem7.createSubEmitter(myData7)
  288. subEmitter7.state = 1 // 设置为1为当粒子消失后出现作用子发射器
  289. //可以规定多个子发射器的阵列
  290. tempSystem7.subEmitters = [subEmitter7]
  291. },
  292. handleAssetsProgress: function({detail}) {
  293. this.triggerEvent('assetsProgress', detail.value);
  294. },
  295. handleAssetsLoaded: function ({detail}) {
  296. console.log('assets loaded', detail.value);
  297. this.triggerEvent('assetsLoaded', detail.value);
  298. this.setData({
  299. loaded: true
  300. });
  301. },handleGltfLoaded2: function() {
  302. },handleGltfLoaded: function() {
  303. },
  304. handleTick: function (dt) {
  305. if(starttime==0)
  306. {
  307. starttime = Date.now();
  308. }
  309. if((starttime-Date.now())>=1)
  310. {
  311. starttime= 0;
  312. cttimefps=cttime;
  313. cttime=0;
  314. }
  315. else
  316. {
  317. cttime++;
  318. }
  319. },
  320. handleTrackerSwitch: function ({detail}) {
  321. const active = detail.value;
  322. if(active)
  323. {
  324. this.setData({
  325. loaded2: true
  326. });
  327. }
  328. },handleARTrackerState({detail}) {
  329. // 事件的值即为`ARTracker`实例
  330. const tracker = detail.value;
  331. // 获取当前状态和错误信息
  332. const {state, errorMessage} = tracker;
  333. const element = detail.el;
  334. if( state==2)
  335. {
  336. this.triggerEvent('assetsstr',"state" + state);
  337. /*
  338. 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));*/
  339. }
  340. },
  341. handleAnimationStop: function() {
  342. console.log('animation Stop');
  343. },
  344. /* handleGLTFLoadedbingLong:function({detail}){
  345. const el2 = detail.value;
  346. var state = true;
  347. const xrScene = this.scene;
  348. const xrFrameSystem = wx.getXrFrameSystem();
  349. const myModel = xrScene.getElementById('binglong');
  350. this.myModelAnimator = myModel.getComponent(xrFrameSystem.Animator);
  351. const clips = this.myModelAnimator._clips;
  352. this.clipName = []
  353. clips.forEach((v, key) => {
  354. if (key.indexOf('pose') == -1) {
  355. this.clipName.push(key)
  356. }
  357. })
  358. wx.showToast({
  359. title: this.clipName[0],
  360. });
  361. this.myModelAnimator.play.play(this.clipName[0],{ loop:5,});
  362. var interval = setInterval(function() {
  363. if(false)
  364. {
  365. clearInterval(interval);
  366. }
  367. console.log(5000 +" 毫秒更新");
  368. if(state)
  369. {
  370. state = false;
  371. this.myModelAnimator.play.play(this.clipName[1],{ loop:5,});
  372. }else{
  373. state = true;
  374. this.myModelAnimator.play.play(this.clipName[2],{ loop:5,});
  375. el2.position =(0 -2.5 -40);
  376. }
  377. }, 5000)
  378. },*/
  379. capture() {
  380. this.scene.share.captureToFriends({
  381. fileType: this.data.captureType,
  382. quality: this.data.captureQuality
  383. });
  384. },
  385. recordStart() {
  386. console.log('recordStart')
  387. wx.updateShareMenu({
  388. withShareTicket: true,
  389. success () { }
  390. })
  391. this.scene.share.recordStart({
  392. fps: 15,
  393. videoBitsPerSecond: 10000,
  394. });
  395. },
  396. recordEnd() {
  397. console.log('recordEnd')
  398. //
  399. const tempFilePath = this.scene.share.recordFinishToAlbum({
  400. fps: 15,
  401. videoBitsPerSecond: 10000,
  402. });
  403. wx.shareVideoMessage({
  404. videoPath: tempFilePath,
  405. });
  406. },
  407. ShowModel(modelIndex){
  408. console.log(' ShowMoelIndex ',modelIndex);
  409. switch(modelIndex){
  410. case 1:
  411. this.setData({luanniaoShow:true});
  412. break;
  413. case 2:
  414. this.setData({yinglongShow:true});
  415. break;
  416. case 3:
  417. this.setData({fuzhuShow:true});
  418. break;
  419. case 4:
  420. this.setData({nianshouShow:true});
  421. break;
  422. }
  423. },
  424. CloseModel(){
  425. this.setData({longshow:false});
  426. this.setData({binglongshow:false});
  427. this.setData({lanjiachongshow:false});
  428. }
  429. }
  430. })