URL和blob需要模拟;建议使用gltf模型,glb纹理都需要blob // Blob文件 export default class $Blob { constructor(parts, options) { this.parts = parts; this.options = options; // 目前仅适配如下 // var blob = new Blob([bufferView], { type: source.mimeType }); // sourceURI = URL.createObjectURL(blob); // var base64 = ArrayBufferToBase64(bufferView); // var url = `data:${options.type};base64,${base64}`; } } // url文件 import Blob from './Blob'; import { encode as ArrayBufferToBase64 } from './base64-arraybuffer'; export default class $URL { createObjectURL(obj) { if (obj instanceof Blob) { // TODO: use wasm to improve decode performance // 经测试主要耗时在于字符串拼接,使用assemblyscript的字符串拼接比js拼接慢非常多 // 组长找到更好的方式,使用wx.fileSystemManager写入临时文件来获取url,但是需要手动管理临时文件 // const t = Date.now(); const base64 = ArrayBufferToBase64(obj.parts[0]); const url = `data:${obj.options.type};base64,${base64}`; // console.log('createObjectURL', Date.now() - t); return url; } return ''; } revokeObjectURL() {} } // base64-arraybuffer文件 /* * base64-arraybuffer * https://github.com/niklasvh/base64-arraybuffer * * Copyright (c) 2012 Niklas von Hertzen * Licensed under the MIT license. */ var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; // Use a lookup table to find the index. var lookup = new Uint8Array(256); for (var i = 0; i < chars.length; i++) { lookup[chars.charCodeAt(i)] = i; } // 有点慢 // export function encode(arraybuffer) { // var bytes = new Uint8Array(arraybuffer), // i, // len = bytes.length, // base64 = ''; // for (i = 0; i < len; i += 3) { // base64 += chars[bytes[i] >> 2]; // base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)]; // base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)]; // base64 += chars[bytes[i + 2] & 63]; // } // if (len % 3 === 2) { // base64 = base64.substring(0, base64.length - 1) + '='; // } else if (len % 3 === 1) { // base64 = base64.substring(0, base64.length - 2) + '=='; // } // return base64; // } // 快一点 export function encode(arrayBuffer) { var base64 = ''; var bytes = new Uint8Array(arrayBuffer); var byteLength = bytes.byteLength; var byteRemainder = byteLength % 3; var mainLength = byteLength - byteRemainder; var a, b, c, d; var chunk; // Main loop deals with bytes in chunks of 3 for (var i = 0; i < mainLength; i = i + 3) { // Combine the three bytes into a single integer chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]; // Use bitmasks to extract 6-bit segments from the triplet a = (chunk & 16515072) >> 18; // 16515072 = (2^6 - 1) << 18 b = (chunk & 258048) >> 12; // 258048 = (2^6 - 1) << 12 c = (chunk & 4032) >> 6; // 4032 = (2^6 - 1) << 6 d = chunk & 63; // 63 = 2^6 - 1 // Convert the raw binary segments to the appropriate ASCII encoding base64 += chars[a] + chars[b] + chars[c] + chars[d]; } // Deal with the remaining bytes and padding if (byteRemainder == 1) { chunk = bytes[mainLength]; a = (chunk & 252) >> 2; // 252 = (2^6 - 1) << 2 // Set the 4 least significant bits to zero b = (chunk & 3) << 4; // 3 = 2^2 - 1 base64 += chars[a] + chars[b] + '=='; } else if (byteRemainder == 2) { chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]; a = (chunk & 64512) >> 10; // 64512 = (2^6 - 1) << 10 b = (chunk & 1008) >> 4; // 1008 = (2^6 - 1) << 4 // Set the 2 least significant bits to zero c = (chunk & 15) << 2; // 15 = 2^4 - 1 base64 += chars[a] + chars[b] + chars[c] + '='; } return base64; } export function decode(base64) { var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4; if (base64[base64.length - 1] === '=') { bufferLength--; if (base64[base64.length - 2] === '=') { bufferLength--; } } var arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer); for (i = 0; i < len; i += 4) { encoded1 = lookup[base64.charCodeAt(i)]; encoded2 = lookup[base64.charCodeAt(i + 1)]; encoded3 = lookup[base64.charCodeAt(i + 2)]; encoded4 = lookup[base64.charCodeAt(i + 3)]; bytes[p++] = (encoded1 << 2) | (encoded2 >> 4); bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2); bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63); } return arraybuffer; }
threejs-miniprogram引入gltf或者glb模型在gltf-loader报错,怎搞?我是用了官方推荐的模板案例,可以正常加载 [图片] 但是当替换成我这边自己的glb或者gltf文件的时候,直接报错 [图片] 我从网上搜到,说是要在gltf-loader.js里把 var URL = window.URL || window.webkitURL; 改成 var URL = {}; 但是又报了新的错误 [图片] 请问要如何解决啊?先谢过
2022-02-28怎么回收页面呢?路由跳转A=>B=>A ;B页面默认并不会被微信销毁并回收
小程序运行中,会提示内存不足,请问怎么解决?小程序运行中,会提示内存不足,请问怎么解决?
2022-01-21https://developers.weixin.qq.com/s/e0S67fmk7Pwp 这个是子包1中添加直播插件,子包2是独立子包;子包3是普通子包。小米10-小米11中子包2和子包3仍然崩溃
VKSession的官方api和直播插件(任意插件)在安卓小米11冲突,AR直接崩溃?目前看到子包中官方直播插件的存在,会导致另外一个子包中的AR项目(官方VKSession的api)的40秒后直接崩溃,在小米11以及小米10 https://developers.weixin.qq.com/s/dZQnifm27wwb 代码如下,直接用的官方的vksession代码;只是增加了直播插件引用,小米11打开30秒左右直接崩哭i[图片] ======== 最新看到的结论,无论是什么插件,只要是plugins里面有插件 VKSession都会崩溃; [图片]
2022-01-12https://developers.weixin.qq.com/community/develop/doc/0000881e734068f7414d643af57000?highLine=VKSession 相同问题
使用官方vksession案例在真机上出现部分区域花屏现象[图片]如图,左上角有一块一直存在的雪花屏内容,机型是小米11Pro
2021-12-30已解决; 小程序管理后台,添加request白名单,在真机预览模式下
webgl在安卓或ios真机预览中gltf加载失败?代码链接https://developers.weixin.qq.com/s/HQcIIjmv7ChG 开发者工具gltf加载正常 真机预览模式下gltf加载失败 真机预览模式打开调试 gltf加载正常 相同问题:https://developers.weixin.qq.com/community/develop/doc/000082a0b880e84e7e5a5282050000?highline=webgl%E5%9C%A8%E5%AE%89%E5%8D%93%2Fios%E4%B8%ADgltf%E5%8A%A0%E8%BD%BD%E5%A4%B1%E8%B4%A5
2021-12-15相同问题遇到了 已解决; 小程序管理后台,添加request白名单,在真机预览模式下
小程序canvas设置为webgl,加载的gltf或glb模型在微信开发工具没问题,真机不显示?运行环境; 微信版本号7.0.14,小程序调试基础库2.11.0. 代码用的官方threejs示例https://github.com/wechat-miniprogram/threejs-miniprogram/tree/master/example, 代码片段:https://developers.weixin.qq.com/s/HQcIIjmv7ChG 问题描述: 该代码示例在模拟器正常显示,真机不显示。但如果真机打开调试,又能正常显示模型 [图片][图片][图片][图片]
2021-12-15遇到同样的坑,真机预览和开发工具都没问题,结果真机调试不行 https://developers.weixin.qq.com/community/develop/doc/000e0ea25cc5b0c1082bc06165b800?highLine=ontouchstart 原因是上面链接中官方说不支持真机调试,这个问题可以关闭了
Cannot set property 'ontouchstart' of undefined?webgi 真机调试模式 Cannot set property 'ontouchstart' of undefined
2021-11-17