Commit 69e93f3b authored by wangjianfeng.yz's avatar wangjianfeng.yz

2.0.44

parent aa212051
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
svga-egret @ 6b35f026
Subproject commit 6b35f026b4e9b4ebdb6616519e492a7f824d9a22
......@@ -8,6 +8,9 @@
"name": "fyge",
"version": "2.0.43",
"license": "ISC",
"dependencies": {
"rollup": "^1.32.1"
},
"devDependencies": {
"dts-bundle": "^0.7.3",
"glob": "^7.1.6",
......@@ -59,8 +62,7 @@
"node_modules/@types/estree": {
"version": "0.0.45",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.45.tgz",
"integrity": "sha512-jnqIUKDUqJbDIUxm0Uj7bnlMnRm1T/eZ9N+AVMqhPgzrba2GhGG5o/jCTwmdPK709nEZsGoMzXEDUjcXHa3W0g==",
"dev": true
"integrity": "sha512-jnqIUKDUqJbDIUxm0Uj7bnlMnRm1T/eZ9N+AVMqhPgzrba2GhGG5o/jCTwmdPK709nEZsGoMzXEDUjcXHa3W0g=="
},
"node_modules/@types/glob": {
"version": "5.0.30",
......@@ -87,8 +89,7 @@
"node_modules/@types/node": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.0.tgz",
"integrity": "sha512-j2tekvJCO7j22cs+LO6i0kRPhmQ9MXaPZ55TzOc1lzkN5b6BWqq4AFjl04s1oRRQ1v5rSe+KEvnLUSTonuls/A==",
"dev": true
"integrity": "sha512-j2tekvJCO7j22cs+LO6i0kRPhmQ9MXaPZ55TzOc1lzkN5b6BWqq4AFjl04s1oRRQ1v5rSe+KEvnLUSTonuls/A=="
},
"node_modules/@types/resolve": {
"version": "0.0.8",
......@@ -3648,6 +3649,19 @@
"inherits": "^2.0.1"
}
},
"node_modules/rollup": {
"version": "1.32.1",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-1.32.1.tgz",
"integrity": "sha512-/2HA0Ec70TvQnXdzynFffkjA6XN+1e2pEv/uKS5Ulca40g2L7KuOE3riasHoNVHOsFD5KKZgDsMk1CP3Tw9s+A==",
"dependencies": {
"@types/estree": "*",
"@types/node": "*",
"acorn": "^7.1.0"
},
"bin": {
"rollup": "dist/bin/rollup"
}
},
"node_modules/rollup-plugin-commonjs": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.1.0.tgz",
......@@ -3765,6 +3779,17 @@
"estree-walker": "^0.6.1"
}
},
"node_modules/rollup/node_modules/acorn": {
"version": "7.4.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz",
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==",
"bin": {
"acorn": "bin/acorn"
},
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/run-queue": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/run-queue/-/run-queue-1.0.3.tgz",
......@@ -5316,8 +5341,7 @@
"@types/estree": {
"version": "0.0.45",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.45.tgz",
"integrity": "sha512-jnqIUKDUqJbDIUxm0Uj7bnlMnRm1T/eZ9N+AVMqhPgzrba2GhGG5o/jCTwmdPK709nEZsGoMzXEDUjcXHa3W0g==",
"dev": true
"integrity": "sha512-jnqIUKDUqJbDIUxm0Uj7bnlMnRm1T/eZ9N+AVMqhPgzrba2GhGG5o/jCTwmdPK709nEZsGoMzXEDUjcXHa3W0g=="
},
"@types/glob": {
"version": "5.0.30",
......@@ -5344,8 +5368,7 @@
"@types/node": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.0.tgz",
"integrity": "sha512-j2tekvJCO7j22cs+LO6i0kRPhmQ9MXaPZ55TzOc1lzkN5b6BWqq4AFjl04s1oRRQ1v5rSe+KEvnLUSTonuls/A==",
"dev": true
"integrity": "sha512-j2tekvJCO7j22cs+LO6i0kRPhmQ9MXaPZ55TzOc1lzkN5b6BWqq4AFjl04s1oRRQ1v5rSe+KEvnLUSTonuls/A=="
},
"@types/resolve": {
"version": "0.0.8",
......@@ -8314,6 +8337,23 @@
"inherits": "^2.0.1"
}
},
"rollup": {
"version": "1.32.1",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-1.32.1.tgz",
"integrity": "sha512-/2HA0Ec70TvQnXdzynFffkjA6XN+1e2pEv/uKS5Ulca40g2L7KuOE3riasHoNVHOsFD5KKZgDsMk1CP3Tw9s+A==",
"requires": {
"@types/estree": "*",
"@types/node": "*",
"acorn": "^7.1.0"
},
"dependencies": {
"acorn": {
"version": "7.4.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz",
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A=="
}
}
},
"rollup-plugin-commonjs": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.1.0.tgz",
......
{
"name": "fyge",
"version": "2.0.43",
"version": "2.0.44",
"description": "canvas渲染引擎",
"main": "./build/fyge.min.js",
"types": "./build/types.d.ts",
......@@ -19,21 +19,22 @@
"author": "MrKwon",
"license": "ISC",
"devDependencies": {
"rollup-plugin-progress": "^1.1.2",
"ts-loader": "^4.0.0",
"webpack": "^4.1.0",
"webpack-cli": "^3.3.2",
"dts-bundle": "^0.7.3",
"glob": "^7.1.6",
"rollup": "^1.32.1",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-progress": "^1.1.2",
"rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-typescript2": "^0.25.2",
"rollup-plugin-uglify": "^6.0.3",
"ts-loader": "^4.0.0",
"typedoc": "^0.20.20",
"typescript": "^3.5.1",
"typedoc": "^0.20.20"
"webpack": "^4.1.0",
"webpack-cli": "^3.3.2"
},
"keywords": [
"h5,淘宝小程序,canvas,webgl,3d,gltf,spine,lottie,svga"
]
}
\ No newline at end of file
}
......@@ -460,6 +460,17 @@
2.0.43 Spine添加属性fps帧率,同时update方法里delta乘上fps/60
还没发布
2.0.44 引擎单独导出toDisplayDataURL,该文件移入renderers文件夹内
const注释掉osType,tbminAdpate里新增getOsType方法,同时BatchRenderer、EditableText和InputText里osType改成getOsType()
Stage关于osType和getEnv相关修改
Loader的loadJson和loadAB方法加上tt的预留,新增loadText方法(待测试,目前就loadAtlas里用到)
loadAtlas修改加载时判断getEnv改成直接用loadText
utile的index里去掉toDisplayDataURL导出,isWebGLSupported方法移到tbminAdpate里
tbminAdpate里新增tt,改动较大,待测试,且新增getDevicePixelRatio,getOsType,预留initedByTtEnv方法
外层canvas标签的transform数据在获取鼠标坐标时并未考虑,比如旋转
......
......@@ -7,7 +7,7 @@
* @name VERSION
* @type {string}
*/
export const VERSION = "2.0.43";
export const VERSION = "2.0.44";
/**
......@@ -21,20 +21,20 @@ export const VERSION = "2.0.43";
* 获取设备号iOS Android
* 先判断浏览器环境设备号,没有就是小程序环境
*/
export const osType: "ios" | "android" | "pc" = navigator && navigator.userAgent && (function () {
let n = navigator.userAgent.toLocaleLowerCase();
let reg1 = /android/;
let reg2 = /iphone|ipod|ipad/;
if (reg1.test(n)) {
return "android";
} else if (reg2.test(n)) {
return "ios"
} else {
return "pc";
}
})()
//@ts-ignore //以后加了其他环境再改,现在除了web就是淘宝小程序
|| my.getSystemInfoSync().platform.toLowerCase()
// export const osType: "ios" | "android" | "pc" = navigator && navigator.userAgent && (function () {
// let n = navigator.userAgent.toLocaleLowerCase();
// let reg1 = /android/;
// let reg2 = /iphone|ipod|ipad/;
// if (reg1.test(n)) {
// return "android";
// } else if (reg2.test(n)) {
// return "ios"
// } else {
// return "pc";
// }
// })()
// //@ts-ignore //以后加了其他环境再改,现在除了web就是淘宝小程序
// || my.getSystemInfoSync().platform.toLowerCase()
let PI: number = Math.PI;
......
import Container from "./Container";
import { RENDERER_TYPE, VERSION, osType } from "../const"
import { RENDERER_TYPE, VERSION/*, osType*/ } from "../const"
// import SystemRenderer from "../renderers/SystemRenderer";
import { Rectangle, Point } from "../math";
import { EventDispatcher } from "../events/EventDispatcher";
......@@ -12,7 +12,7 @@ import { WebglRenderer } from "../renderers/WebglRenderer";
import { CanvasRenderer } from "../renderers/CanvasRenderer";
import { SystemRenderer } from "../renderers/SystemRenderer";
import { getEnv, isWebGLSupported } from "../utils";
import { getEnv, getOsType, isWebGLSupported } from "../utils";
export class Stage extends Container {
......@@ -142,7 +142,7 @@ export class Stage extends Container {
* 淘宝小程序环境canvas的偏移,淘宝环境才用,web环境实时,字段保留,但是不会计算了
*/
private canvasOffsetTb: { x: number, y: number } = { x: 0, y: 0 };
private offsetTimeId: any
// private offsetTimeId: any
get stageWidth() {
return this.viewRect.width;
......@@ -455,7 +455,7 @@ export class Stage extends Container {
//事件个数
let eLen: number;
let identifier: any;
if (osType == "pc") {
if (getOsType() == "pc") {
e.identifier = 0;
points = [e];
} else {
......@@ -664,22 +664,22 @@ export class Stage extends Container {
}
};
/**
* 给舞台绑定canvas标签的鼠标代理事件(web环境下需要显示对象的鼠标事件时调用)
* 给舞台绑定canvas标签的鼠标代理事件(web环境下需要显示对象的鼠标事件时调用),tt环境貌似也行,待测试
* 自行调用,内部不主动调用,因为比如淘宝小程序环境方式不一致,需要用onMouseEvent
*/
addWebMouseEvent() {
//非网页环境直接return
if (getEnv() !== "web") return;
var canvas = this.canvas;
var mouseEvent = this.onMouseEvent.bind(this);
if (osType == "pc") {
canvas.addEventListener("mousedown", mouseEvent, false);
canvas.addEventListener('mousemove', mouseEvent, false);
canvas.addEventListener('mouseup', mouseEvent, false);
} else {
canvas.addEventListener("touchstart", mouseEvent, false);
canvas.addEventListener('touchmove', mouseEvent, false);
canvas.addEventListener('touchend', mouseEvent, false);
if (getEnv() == "web" || getEnv() == "tt") {
var canvas = this.canvas;
var mouseEvent = this.onMouseEvent.bind(this);
if (getOsType() == "pc") {
canvas.addEventListener("mousedown", mouseEvent, false);
canvas.addEventListener('mousemove', mouseEvent, false);
canvas.addEventListener('mouseup', mouseEvent, false);
} else {
canvas.addEventListener("touchstart", mouseEvent, false);
canvas.addEventListener('touchmove', mouseEvent, false);
canvas.addEventListener('touchend', mouseEvent, false);
}
}
}
/**
......
......@@ -91,6 +91,12 @@ export class Loader extends EventDispatcher {
}, url, "utf8")
return
}
//tt环境,TODO
if (getEnv() == "tt") {
console.error("tt环境待开发");
return
}
//web环境
this.loadRawWeb(callback, url, "json")
}
/**
......@@ -101,10 +107,32 @@ export class Loader extends EventDispatcher {
loadAB(callback: (s: boolean, res: ArrayBuffer) => void, url: string) {
if (getEnv() == "tb") {
this.tbLoad(callback, url, "ArrayBuffer")
} else {
}
//tt环境,TODO
else if (getEnv() == "tt") {
console.error("tt环境待开发")
}
else {
this.loadRawWeb(callback, url, "arraybuffer")
}
}
/**
* 加载文本
* @param callback
* @param url
*/
loadText(callback: (s: boolean, res: string) => void, url: string) {
if (getEnv() == "tb") {
this.tbLoad(callback, url, "utf8")
}
//tt环境待开发,TODO
else if (getEnv() == "tt") {
console.error("tt环境待开发")
}
else {
this.loadRawWeb(callback, url, "text")
}
}
/**
* web环境原生加载方式
* @param callback
......
import BatchDrawCall from '../webgl/BatchDrawCall';
import { osType, BLEND_MODES } from "../../const"
import { /*osType,*/ BLEND_MODES } from "../../const"
// import State from '../state/State';
import ObjectRenderer from '../webgl/ObjectRenderer';
import { checkMaxIfStatementsInShader } from '../../../glCore/checkMaxIfStatementsInShader';
......@@ -8,7 +8,7 @@ import { BatchBuffer } from '../webgl/BatchBuffer';
import { generateMultiTextureShader } from '../webgl/generateMultiTextureShader';
import { WebglRenderer } from '../WebglRenderer';
import { GLShader, GLBuffer, VertexArrayObject } from '../../../glCore';
import { nextPow2, log2, premultiplyTint } from '../../utils';
import { nextPow2, log2, premultiplyTint, getOsType } from '../../utils';
import { DisplayObject } from '../../display/DisplayObject';
import Texture from '../../texture/Texture';
import BaseTexture from '../../texture/BaseTexture';
......@@ -361,7 +361,7 @@ export class BatchRenderer extends ObjectRenderer {
// this.indexBuffer.update();
//暂时出现了bug,ios不做特殊处理先,以后有时间排查,暂时应该影响不大
//貌似没问题了(20210601),但是感觉性能差别不大,先不加了,到时要加的话,也要打开start方法里的注释
if (osType == "ios" && false) {
if (getOsType() == "ios" && false) {
//可能有一帧,在多个地方执行flush
// this is still needed for IOS performance..
// it really does not like uploading to the same buffer in a single frame!
......@@ -476,7 +476,7 @@ export class BatchRenderer extends ObjectRenderer {
this.renderer.bindShader(this.shader);
// if (osType != "ios") {//暂时出现了bug,ios不做特殊处理先
// if (getOsType() != "ios") {//暂时出现了bug,ios不做特殊处理先
this.renderer.bindVao(this.vaos[this.vertexCount]);
this.vertexBuffers[this.vertexCount].bind();
this.indexBuffers[this.vertexCount].bind();
......
import { CanvasRenderer } from "../renderers/CanvasRenderer";
import { CanvasRenderer } from "./CanvasRenderer";
import RenderTexture from "../texture/RenderTexture";
import { Matrix, Rectangle } from "../math";
import { DisplayObject } from "../display/DisplayObject";
import { createCanvas } from "./tbminiAdapte";
import { createCanvas } from "../utils";
// 作为将显示对象导出成图片的render渲染器,所以无法截取3d场景,3d场景暂时自己处理显隐裁切,用toDataURL获取,以后考虑改成WebglRenderer
......
import { TextField } from "./TextField";
import { Event, MouseEvent } from "../events";
import { osType } from "../const";
import { getOsType } from "../utils";
// import { osType } from "../const";
/**
......@@ -162,7 +163,7 @@ export class EditableText extends TextField {
}
//添加
htmlElement.onblur = function (e) {
if (osType == "ios") {
if (getOsType() == "ios") {
//部分app里的webview有兼容问题用window.scrollTo(0, 0)
window.scrollTo({ top: 0, left: 0, behavior: "smooth" });
}
......
import { osType, TEXT_lINETYPE } from "../const";
import { /*osType,*/ TEXT_lINETYPE } from "../const";
import { Event } from "../events/Event";
import { MouseEvent } from "../events/MouseEvent";
import { FloatDisplay } from "../display/FloatDisplay";
import { TextField } from "./TextField";
import { getOsType } from "../utils";
/**
* 纯dom的输入文本,待测试
......@@ -59,7 +60,7 @@ export class InputText extends FloatDisplay {
}
s.inputType = inputType;
var remove = function () {
if (s.isAutoDownKeyBoard && osType != "pc") {
if (s.isAutoDownKeyBoard && getOsType() != "pc") {
s.htmlElement && s.htmlElement.blur();
window.scrollTo(0, 0)
}
......
import { SCALE_MODES, TEXT_ALIGN, TEXT_lINETYPE, VERTICAL_ALIGN, osType } from "../const";
import { SCALE_MODES, TEXT_ALIGN, TEXT_lINETYPE, VERTICAL_ALIGN } from "../const";
import Texture from "../texture/Texture";
import { getRGBA, createCanvas, getEnv } from "../utils";
import { Rectangle } from "../math";
......@@ -518,7 +518,7 @@ export class TextField extends Sprite {
s.texture.update()
return
}
let can = s.canvas;
let ctx: CanvasRenderingContext2D = /*backupCanvasContext*/s.context;
// ctx.save();
......@@ -623,7 +623,7 @@ export class TextField extends Sprite {
upY = s._textHeight - trueHeight;
}
}
//
//还没测试是否已修复
getEnv() == "tb" && (upY -= 4);
for (let i = 0; i < realLines.length; i++) {
let oy = (lineH - s.size) / 2;
......
......@@ -7,7 +7,6 @@ import { RENDERER_TYPE } from "../const";
import { createCanvas, getEnv } from "./tbminiAdapte";
export * from './twiddle';
export * from "./toDisplayDataURL";
// export * from "./getTintedTexture";//外部用不到
// export * from "./mapWebGLBlendModes";//只在webglState里使用一次,外部用不到
......@@ -257,40 +256,6 @@ export function clearTextureCache() {
// padding: 2,
// }
let webglSupported: boolean;
/**
* 判断是否支持webgl
* @function isWebGLSupported
* @return {boolean}
*/
export function isWebGLSupported(): boolean {
//淘宝环境直接返回true,否则找淘宝小程序解决
if (getEnv() == "tb") return true;
//已经判断过了,直接返回
if (webglSupported !== undefined) return webglSupported;
//进入判断,加上低性能下是否使用webgl标识,pc上因为failIfMajorPerformanceCaveat设为true获取不到webgl一般是驱动问题
const contextOptions = { stencil: true, failIfMajorPerformanceCaveat: true };
try {
if (!window["WebGLRenderingContext"]) {
return false;
}
const canvas = createCanvas()// document.createElement('canvas');
let gl = canvas.getContext('webgl', contextOptions) || canvas.getContext('experimental-webgl', contextOptions);
const success = !!(gl && gl["getContextAttributes"]().stencil);
if (gl) {
const loseContext = gl["getExtension"]('WEBGL_lose_context');
if (loseContext) {
loseContext.loseContext();
}
}
gl = null;
return webglSupported = success;
}
catch (e) {
return webglSupported = false;
}
}
/**
* 从数组中移除元素
* @param arr 原数组
......
// let env: "tb" | "web" = "web";
// //如果是浏览器环境,声明个my为null,为了无声明不报错
// if (window) window["my"] = null;//在用webview的小程序环境内,只要在小程序的sdk前加js就无所谓,
// export function getEnv(): "tb" | "web" {
// return env
// }
// /**
// * 创建一个离屏的canvas
// */
// export function createCanvas(): HTMLCanvasElement {
// //@ts-ignore
// return document && document.createElement("canvas") || my._createOffscreenCanvas();
// }
// let contentByCanvas: {
// createImage: () => HTMLImageElement,
// requestAnimationFrame: (fun: Function) => number,
// cancelAnimationFrame: (id) => void,
// };
// /**
// * 淘宝小程序项目,拿到canvas先执行这个,,,TODO为啥不直接记录canvas.也许有问题,暂时不改
// * @param canvas
// */
// export function initedByCanvas(canvas) {
// contentByCanvas = {
// createImage: canvas.createImage.bind(canvas),
// //必须加bind,函数内存在this指向
// requestAnimationFrame: canvas.requestAnimationFrame.bind(canvas),
// cancelAnimationFrame: canvas.cancelAnimationFrame.bind(canvas),
// }
// env = "tb";
// }
// export function destroyCanvasContent() {
// if (contentByCanvas) {
// contentByCanvas.createImage = null;
// contentByCanvas.requestAnimationFrame = null;
// contentByCanvas.cancelAnimationFrame = null;
// contentByCanvas = null
// }
// }
// export function createImage() {
// return contentByCanvas && contentByCanvas.createImage() || new Image();
// }
// //下面两个尽量自己外层写循环,不用这里的,因为淘宝小程序不同page用了canvas,最好都用各自的requestAnimationFrame,不相互覆盖
// export function getRequestAnimationFrame() {
// return contentByCanvas && contentByCanvas.requestAnimationFrame || window.requestAnimationFrame.bind(window)
// }
// export function getCancelAnimationFrame() {
// return contentByCanvas && contentByCanvas.cancelAnimationFrame || window.cancelAnimationFrame.bind(window)
// }
//TODO上面所有的以后考虑这么些写,待测试
let env: "tb" | "web" = "web";
let env: "tb" | "web" | "tt" = "web";
//如果是浏览器环境,声明个my为null,为了无声明不报错
if (window) window["my"] = null;//在用webview的小程序环境内,只要在小程序的sdk前加js就无所谓,
export function getEnv(): "tb" | "web" {
export function getEnv(): "tb" | "web" | "tt" {
return env
}
/**
......@@ -64,7 +10,7 @@ export function getEnv(): "tb" | "web" {
* 方法initedByTbCanvas会自行设置env为tb
* @param e 环境
*/
export function setEnv(e: "tb" | "web") {
export function setEnv(e: "tb" | "web" | "tt") {
env = e;
}
/**
......@@ -75,8 +21,13 @@ export function createCanvas(): HTMLCanvasElement {
// return document && document.createElement("canvas") || createTbOffscreenCanvas()//my._createOffscreenCanvas();
//web环境
if (getEnv() == "web") return document.createElement("canvas");
//@ts-ignore
//淘宝小程序环境
if (getEnv() == "tb") return createTbOffscreenCanvas()//my._createOffscreenCanvas();
//tt环境,TODO
if (getEnv() == "tt") {
console.error("tt环境待开发")
return
}
//提示下
console.warn("未知环境,创建canvas失败")
}
......@@ -104,6 +55,13 @@ export function initedByTbCanvas(canvas) {
tbCanvas = canvas;
setEnv("tb");
}
/**
* 预留方法,后续开发,主要用于初始化Canvas类和Image类,TODO
*/
export function initedByTtEnv() {
console.log("待开发")
setEnv("tt")
}
//兼容老版本,TODO废弃
export function initedByCanvas(canvas) {
console.warn("方法initedByCanvas即将废弃,请使用方法initedByTbCanvas代替")
......@@ -132,6 +90,11 @@ export function createImage(): HTMLImageElement {
if (tbCanvas) return tbCanvas.createImage();
console.warn("淘宝小程序初始化canvas不存在");
}
//tt环境,TODO
if (getEnv() == "tt") {
console.error("tt环境待开发")
return
}
console.warn("未知环境,创建Image失败")
}
/**
......@@ -147,6 +110,9 @@ export function requestAnimationFrame(callback) {
if (tbCanvas) return tbCanvas.requestAnimationFrame(callback);
console.warn("淘宝小程序初始化canvas不存在");
}
//tt环境,待测试,js运行环境可能默认有,TODO
if (getEnv() == "tt") return requestAnimationFrame(callback);
console.warn("未知环境,requestAnimationFrame调用无效")
}
export function cancelAnimationFrame(id: number) {
......@@ -162,10 +128,117 @@ export function cancelAnimationFrame(id: number) {
}
console.warn("淘宝小程序初始化canvas不存在");
}
//tt环境,待测试,js运行环境可能默认有,TODO
else if (getEnv() == "tt") {
cancelAnimationFrame(id);
return;
}
console.warn("未知环境,cancelAnimationFrame调用无效")
}
//老版本使用提示,TODO废弃
export function getRequestAnimationFrame() {
console.error("requestAnimationFrame,cancelAnimationFrame统统外部自行调用,引擎内不给方法,淘宝小程序在canvas上,web环境在window上")
}
\ No newline at end of file
}
let webglSupported: boolean;
/**
* 判断是否支持webgl
* @function isWebGLSupported
* @return {boolean}
*/
export function isWebGLSupported(): boolean {
//淘宝环境直接返回true,否则找淘宝小程序解决,tt环境待测试,TODO
if (getEnv() == "tb" || getEnv() == "tt") return true;
//已经判断过了,直接返回
if (webglSupported !== undefined) return webglSupported;
//进入判断,加上低性能下是否使用webgl标识,pc上因为failIfMajorPerformanceCaveat设为true获取不到webgl一般是驱动问题
const contextOptions = { stencil: true, failIfMajorPerformanceCaveat: true };
try {
if (!window["WebGLRenderingContext"]) {
return false;
}
const canvas = createCanvas()// document.createElement('canvas');
let gl = canvas.getContext('webgl', contextOptions) || canvas.getContext('experimental-webgl', contextOptions);
const success = !!(gl && gl["getContextAttributes"]().stencil);
if (gl) {
const loseContext = gl["getExtension"]('WEBGL_lose_context');
if (loseContext) {
loseContext.loseContext();
}
}
gl = null;
return webglSupported = success;
}
catch (e) {
return webglSupported = false;
}
}
//缓存的操作系统类型
let osType: "ios" | "android" | "pc";
/**
* 获取操作系统类型,"ios" | "android" | "pc";
* @returns
*/
export function getOsType(): "ios" | "android" | "pc" {
//有就直接返回
if (osType) return osType;
if (getEnv() == "web") {
osType = navigator && navigator.userAgent && (function () {
let n = navigator.userAgent.toLocaleLowerCase();
let reg1 = /android/;
let reg2 = /iphone|ipod|ipad/;
if (reg1.test(n)) {
return "android";
} else if (reg2.test(n)) {
return "ios"
} else {
return "pc";
}
})() || null;
//@ts-ignore 如果没取到,有可能环境还没切换,直接用老方法获取,或者直接给个提示
if (!osType && my) osType = my.getSystemInfoSync().platform.toLowerCase();
//tt的再来一次,TODO
// if(!osType&&)
}
else if (getEnv() == "tb") {
//@ts-ignore
osType = my.getSystemInfoSync().platform.toLowerCase();
}
//tt环境待开发,TODO
else if (getEnv() == "tt") {
console.error("tt环境待开发")
}
else {
console.warn("未知环境,获取失败")
}
return osType;
}
let devicePixelRatio: number;
/**
* 获取屏幕像素比dpr
* @returns
*/
export function getDevicePixelRatio() {
if (devicePixelRatio) return devicePixelRatio;
if (getEnv() == "web") {
devicePixelRatio = window && (window.devicePixelRatio || 1);
//@ts-ignore如果还没取到,环境切换有问题,用老方法
if (!devicePixelRatio && my) devicePixelRatio = my.getSystemInfoSync().pixelRatio;
//tt的再来一个,TODO
// if(!devicePixelRatio&&)
}
else if (getEnv() == "tb") {
//@ts-ignore
devicePixelRatio = my.getSystemInfoSync().pixelRatio;
}
//tt环境待开发,TODO
else if (getEnv() == "tt") {
console.error("tt环境待开发")
}
else {
console.warn("未知环境,获取失败")
}
return devicePixelRatio;
}
import { Geometry } from "../Geometry";
import { Vector3 } from "..";
import { Vector3 } from "../math/Vector3";
import { Sphere } from "../math/Sphere";
/**
......
......@@ -10,7 +10,7 @@ import { BaseMaterial, BaseMaterialParamsInt, RenderSideType } from "../material
import { Mesh3D } from "../Mesh3D";
import { PerspectiveCamera } from "../cameras/PerspectiveCamera";
import { RAD_TO_DEG } from "../../2d/const";
import { Matrix4 } from "..";
import { Matrix4 } from "../math/Matrix4";
import { arraySlice } from "../animation/utils";
import { InterpolateSmooth, InterpolateLinear, InterpolateDiscrete } from "../animation/utils";
......@@ -244,11 +244,6 @@ export function loadGltf(
onError && onError(res)
}
}
// if (getEnv() == "tb") {
// GlobalLoader.tbLoad(callback, url, "ArrayBuffer")
// } else {
// GlobalLoader.loadRawWeb(callback, url, "arraybuffer")
// }
GlobalLoader.loadAB(callback, url);
}
......
......@@ -18,6 +18,7 @@ export * from "./2d/mesh";
export * from "./2d/renderers/CanvasRenderer";
export * from "./2d/renderers/WebglRenderer";
export * from "./2d/renderers/toDisplayDataURL";//单独导出
export * from "./2d/text";
......
......@@ -22,15 +22,9 @@ export function loadAtlas(
Promise.all([
//数据
new Promise((r) => {
if (getEnv() == "tb") {
GlobalLoader.tbLoad((s, res) => {
r(s ? res : null)
}, url, "utf8")
} else {
GlobalLoader.loadRawWeb((s, res) => {
r(s ? res : null)
}, url, "text")
}
GlobalLoader.loadText((s, res) => {
r(s ? res : null)
}, url)
}) as Promise<string>,
//图片
new Promise((r) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment