Commit 9f99bda7 authored by wangjianfeng.yz's avatar wangjianfeng.yz

2.0.50

parent 18e0dbdc
...@@ -16,4 +16,5 @@ rollup.config.js ...@@ -16,4 +16,5 @@ rollup.config.js
record.txt record.txt
test test
examples examples
docs docs
\ No newline at end of file adapters
\ No newline at end of file
This diff is collapsed.
declare namespace FYGE{export const VERSION = "2.0.49"; declare namespace FYGE{export const VERSION = "2.0.50";
export function cos(angle: number): number; export function cos(angle: number): number;
...@@ -1273,16 +1273,36 @@ export class RoundedRectangle { ...@@ -1273,16 +1273,36 @@ export class RoundedRectangle {
isPointIn(point: Point): boolean; isPointIn(point: Point): boolean;
} }
export function getEnv(): "tb" | "web" | "tt"; export enum EnvType {
/**
* 淘宝小程序,不能头部adapter是因为引擎包并不打包在项目代码里,所以头部都需要,TODO,后续考虑单独为淘宝小程序打引擎包(加入adapter),然后引擎内部就干净了,load里也要肃清
*/
tb = "tb",
/**
* web环境
*/
web = "web",
/**
* 字节helium环境,暂时废弃
* 打包的时候,
* 1、引擎一并打入,并且头部添加helium-adapter,基本和Web保持一致
* 2、客户端先loadScript(helium-adapter.js),再loadScript(引擎),最后loadScript(项目代码)
*/
/**
* 头条,抖音小程序
* 需要先执行adapter.js注入兼容的全局变量
*/
tt = "tt"
}
export function setEnv(e: "tb" | "web" | "tt"): void; export function getEnv(): EnvType;
export function setEnv(e: EnvType): void;
export function createCanvas(): HTMLCanvasElement; export function createCanvas(): HTMLCanvasElement;
export function initedByTbCanvas(canvas: any): void; export function initedByTbCanvas(canvas: any): void;
export function initedByTtEnv(): void;
export function initedByCanvas(canvas: any): void; export function initedByCanvas(canvas: any): void;
export function destroyTbCanvas(): void; export function destroyTbCanvas(): void;
...@@ -1535,13 +1555,6 @@ export class BaseTexture extends EventDispatcher { ...@@ -1535,13 +1555,6 @@ export class BaseTexture extends EventDispatcher {
textureCacheIds: string[]; textureCacheIds: string[];
/** /**
* image对象,canvas对象,或者imageData(canvas渲染模式用不了,是否考虑去掉),以后类型增多后再说 * image对象,canvas对象,或者imageData(canvas渲染模式用不了,是否考虑去掉),以后类型增多后再说
* {
* data:Uint8Array,
* width:number,
* height:number,
* type:string,
* path:string
* }
*/ */
source: any; source: any;
/** /**
...@@ -1574,10 +1587,10 @@ export class BaseTexture extends EventDispatcher { ...@@ -1574,10 +1587,10 @@ export class BaseTexture extends EventDispatcher {
*/ */
static fromUrl(url: string): any; static fromUrl(url: string): any;
/** /**
* 随便啥形式的,比如data * 随便啥形式的,比如IImageData形式
* @param data * @param data
*/ */
static fromData(data: any): BaseTexture; static fromData(data: IImageData): BaseTexture;
/** /**
* 从离屏canvas创建的,会给canvas加唯一标识_canvasId,并缓存 * 从离屏canvas创建的,会给canvas加唯一标识_canvasId,并缓存
*/ */
...@@ -1592,7 +1605,7 @@ export class BaseTexture extends EventDispatcher { ...@@ -1592,7 +1605,7 @@ export class BaseTexture extends EventDispatcher {
* @param anything * @param anything
* @returns * @returns
*/ */
static from(anything: string | HTMLCanvasElement | HTMLImageElement): any; static from(anything: string | HTMLCanvasElement | HTMLImageElement | IImageData): any;
/** /**
* 加入全局基础纹理缓存 * 加入全局基础纹理缓存
* @static * @static
...@@ -1609,6 +1622,26 @@ export class BaseTexture extends EventDispatcher { ...@@ -1609,6 +1622,26 @@ export class BaseTexture extends EventDispatcher {
static removeFromCache(baseTexture: string | BaseTexture): BaseTexture; static removeFromCache(baseTexture: string | BaseTexture): BaseTexture;
} }
export interface IImageData {
/**
* 原始图片数据
* 比如从getImageData获取的数据
* var imgData = ctx.getImageData(0, 0, w, h);
* var _data = new Uint8Array(imgData.data)
*/
_data: Uint8Array | ArrayBuffer | Float32Array | Uint8ClampedArray;
width: number;
height: number;
/**
* 暂时不必要
*/
type?: string;
/**
* 暂时不必要
*/
path?: string;
}
export class TextureUvs { export class TextureUvs {
x0: number; x0: number;
y0: number; y0: number;
...@@ -5641,7 +5674,7 @@ export class Stage extends Container { ...@@ -5641,7 +5674,7 @@ export class Stage extends Container {
*/ */
onMouseEvent(e: any): void; onMouseEvent(e: any): void;
/** /**
* 给舞台绑定canvas标签的鼠标代理事件(web环境下需要显示对象的鼠标事件时调用),tt环境貌似也行,待测试 * 给舞台绑定canvas标签的鼠标代理事件(web环境下需要显示对象的鼠标事件时调用)
* 自行调用,内部不主动调用,因为比如淘宝小程序环境方式不一致,需要用onMouseEvent * 自行调用,内部不主动调用,因为比如淘宝小程序环境方式不一致,需要用onMouseEvent
*/ */
addWebMouseEvent(): void; addWebMouseEvent(): void;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
export const VERSION = "2.0.49"; export const VERSION = "2.0.50";
export function cos(angle: number): number; export function cos(angle: number): number;
...@@ -1273,16 +1273,36 @@ export class RoundedRectangle { ...@@ -1273,16 +1273,36 @@ export class RoundedRectangle {
isPointIn(point: Point): boolean; isPointIn(point: Point): boolean;
} }
export function getEnv(): "tb" | "web" | "tt"; export enum EnvType {
/**
* 淘宝小程序,不能头部adapter是因为引擎包并不打包在项目代码里,所以头部都需要,TODO,后续考虑单独为淘宝小程序打引擎包(加入adapter),然后引擎内部就干净了,load里也要肃清
*/
tb = "tb",
/**
* web环境
*/
web = "web",
/**
* 字节helium环境,暂时废弃
* 打包的时候,
* 1、引擎一并打入,并且头部添加helium-adapter,基本和Web保持一致
* 2、客户端先loadScript(helium-adapter.js),再loadScript(引擎),最后loadScript(项目代码)
*/
/**
* 头条,抖音小程序
* 需要先执行adapter.js注入兼容的全局变量
*/
tt = "tt"
}
export function setEnv(e: "tb" | "web" | "tt"): void; export function getEnv(): EnvType;
export function setEnv(e: EnvType): void;
export function createCanvas(): HTMLCanvasElement; export function createCanvas(): HTMLCanvasElement;
export function initedByTbCanvas(canvas: any): void; export function initedByTbCanvas(canvas: any): void;
export function initedByTtEnv(): void;
export function initedByCanvas(canvas: any): void; export function initedByCanvas(canvas: any): void;
export function destroyTbCanvas(): void; export function destroyTbCanvas(): void;
...@@ -1535,13 +1555,6 @@ export class BaseTexture extends EventDispatcher { ...@@ -1535,13 +1555,6 @@ export class BaseTexture extends EventDispatcher {
textureCacheIds: string[]; textureCacheIds: string[];
/** /**
* image对象,canvas对象,或者imageData(canvas渲染模式用不了,是否考虑去掉),以后类型增多后再说 * image对象,canvas对象,或者imageData(canvas渲染模式用不了,是否考虑去掉),以后类型增多后再说
* {
* data:Uint8Array,
* width:number,
* height:number,
* type:string,
* path:string
* }
*/ */
source: any; source: any;
/** /**
...@@ -1574,10 +1587,10 @@ export class BaseTexture extends EventDispatcher { ...@@ -1574,10 +1587,10 @@ export class BaseTexture extends EventDispatcher {
*/ */
static fromUrl(url: string): any; static fromUrl(url: string): any;
/** /**
* 随便啥形式的,比如data * 随便啥形式的,比如IImageData形式
* @param data * @param data
*/ */
static fromData(data: any): BaseTexture; static fromData(data: IImageData): BaseTexture;
/** /**
* 从离屏canvas创建的,会给canvas加唯一标识_canvasId,并缓存 * 从离屏canvas创建的,会给canvas加唯一标识_canvasId,并缓存
*/ */
...@@ -1592,7 +1605,7 @@ export class BaseTexture extends EventDispatcher { ...@@ -1592,7 +1605,7 @@ export class BaseTexture extends EventDispatcher {
* @param anything * @param anything
* @returns * @returns
*/ */
static from(anything: string | HTMLCanvasElement | HTMLImageElement): any; static from(anything: string | HTMLCanvasElement | HTMLImageElement | IImageData): any;
/** /**
* 加入全局基础纹理缓存 * 加入全局基础纹理缓存
* @static * @static
...@@ -1609,6 +1622,26 @@ export class BaseTexture extends EventDispatcher { ...@@ -1609,6 +1622,26 @@ export class BaseTexture extends EventDispatcher {
static removeFromCache(baseTexture: string | BaseTexture): BaseTexture; static removeFromCache(baseTexture: string | BaseTexture): BaseTexture;
} }
export interface IImageData {
/**
* 原始图片数据
* 比如从getImageData获取的数据
* var imgData = ctx.getImageData(0, 0, w, h);
* var _data = new Uint8Array(imgData.data)
*/
_data: Uint8Array | ArrayBuffer | Float32Array | Uint8ClampedArray;
width: number;
height: number;
/**
* 暂时不必要
*/
type?: string;
/**
* 暂时不必要
*/
path?: string;
}
export class TextureUvs { export class TextureUvs {
x0: number; x0: number;
y0: number; y0: number;
...@@ -5641,7 +5674,7 @@ export class Stage extends Container { ...@@ -5641,7 +5674,7 @@ export class Stage extends Container {
*/ */
onMouseEvent(e: any): void; onMouseEvent(e: any): void;
/** /**
* 给舞台绑定canvas标签的鼠标代理事件(web环境下需要显示对象的鼠标事件时调用),tt环境貌似也行,待测试 * 给舞台绑定canvas标签的鼠标代理事件(web环境下需要显示对象的鼠标事件时调用)
* 自行调用,内部不主动调用,因为比如淘宝小程序环境方式不一致,需要用onMouseEvent * 自行调用,内部不主动调用,因为比如淘宝小程序环境方式不一致,需要用onMouseEvent
*/ */
addWebMouseEvent(): void; addWebMouseEvent(): void;
......
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
var tex = await new Promise((r) => { var tex = await new Promise((r) => {
FYGE.GlobalLoader.loadImage((s, image) => { r(FYGE.Texture.fromImage(image)) }, "res/11.png") FYGE.GlobalLoader.loadImage((s, image) => { r(FYGE.Texture.fromImage(image)) }, "res/11.png")
}) })
//好多图,iphone678/30帧以上 //好多图,iphone678/30帧以上,红米k40游戏增强版45帧以上(微信浏览器)
for (var i = 0; i < 20000; i++) { for (var i = 0; i < 20000; i++) {
let a = stage.addChild(new FYGE.Sprite(tex)) let a = stage.addChild(new FYGE.Sprite(tex))
.addEventListener(FYGE.Event.ENTER_FRAME, () => { .addEventListener(FYGE.Event.ENTER_FRAME, () => {
......
{ {
"name": "fyge", "name": "fyge",
"version": "2.0.49", "version": "2.0.50",
"description": "canvas渲染引擎", "description": "canvas渲染引擎",
"main": "./build/fyge.min.js", "main": "./build/fyge.min.js",
"module": "./build/fyge.esm.js", "module": "./build/fyge.esm.js",
......
...@@ -485,7 +485,15 @@ ...@@ -485,7 +485,15 @@
Raycaster修改为继承HashObject,添加copy,clone和destroy方法 Raycaster修改为继承HashObject,添加copy,clone和destroy方法
cameras文件夹添加index.ts文件,还没用,先加上 cameras文件夹添加index.ts文件,还没用,先加上
2.0.50 主要兼容tt小游戏
Stage的addWebMouseEvent方法改成判断canvas的addEventListener,反正addWebMouseEvent是手动调用的,报错可查
Loader删掉所有tt的判断,进else(loadRawWeb)
BaseTexture文件里添加IImageData,且图片源数据判断改成_data,涉及构造函数和static from
TextureManager的updateTexture方法判断图片数据改成_data
getTintedTexture里的tintMethod改成用到时才调用判断
tbminAdpate里改动很大。。。待测试tb,tt,web环境
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* @name VERSION * @name VERSION
* @type {string} * @type {string}
*/ */
export const VERSION = "2.0.49"; export const VERSION = "2.0.50";
/** /**
......
...@@ -664,22 +664,22 @@ export class Stage extends Container { ...@@ -664,22 +664,22 @@ export class Stage extends Container {
} }
}; };
/** /**
* 给舞台绑定canvas标签的鼠标代理事件(web环境下需要显示对象的鼠标事件时调用),tt环境貌似也行,待测试 * 给舞台绑定canvas标签的鼠标代理事件(web环境下需要显示对象的鼠标事件时调用)
* 自行调用,内部不主动调用,因为比如淘宝小程序环境方式不一致,需要用onMouseEvent * 自行调用,内部不主动调用,因为比如淘宝小程序环境方式不一致,需要用onMouseEvent
*/ */
addWebMouseEvent() { addWebMouseEvent() {
if (getEnv() == "web" || getEnv() == "tt") { var canvas = this.canvas;
var canvas = this.canvas; //有就可以执行
var mouseEvent = this.onMouseEvent.bind(this); if (!canvas || !canvas.addEventListener) return;
if (getOsType() == "pc") { var mouseEvent = this.onMouseEvent.bind(this);
canvas.addEventListener("mousedown", mouseEvent, false); if (getOsType() == "pc") {
canvas.addEventListener('mousemove', mouseEvent, false); canvas.addEventListener("mousedown", mouseEvent, false);
canvas.addEventListener('mouseup', mouseEvent, false); canvas.addEventListener('mousemove', mouseEvent, false);
} else { canvas.addEventListener('mouseup', mouseEvent, false);
canvas.addEventListener("touchstart", mouseEvent, false); } else {
canvas.addEventListener('touchmove', mouseEvent, false); canvas.addEventListener("touchstart", mouseEvent, false);
canvas.addEventListener('touchend', mouseEvent, false); canvas.addEventListener('touchmove', mouseEvent, false);
} canvas.addEventListener('touchend', mouseEvent, false);
} }
} }
/** /**
......
...@@ -91,11 +91,6 @@ export class Loader extends EventDispatcher { ...@@ -91,11 +91,6 @@ export class Loader extends EventDispatcher {
}, url, "utf8") }, url, "utf8")
return return
} }
//tt环境,TODO
if (getEnv() == "tt") {
console.error("tt环境待开发");
return
}
//web环境 //web环境
this.loadRawWeb(callback, url, "json") this.loadRawWeb(callback, url, "json")
} }
...@@ -108,10 +103,6 @@ export class Loader extends EventDispatcher { ...@@ -108,10 +103,6 @@ export class Loader extends EventDispatcher {
if (getEnv() == "tb") { if (getEnv() == "tb") {
this.tbLoad(callback, url, "ArrayBuffer") this.tbLoad(callback, url, "ArrayBuffer")
} }
//tt环境,TODO
else if (getEnv() == "tt") {
console.error("tt环境待开发")
}
else { else {
this.loadRawWeb(callback, url, "arraybuffer") this.loadRawWeb(callback, url, "arraybuffer")
} }
...@@ -125,10 +116,6 @@ export class Loader extends EventDispatcher { ...@@ -125,10 +116,6 @@ export class Loader extends EventDispatcher {
if (getEnv() == "tb") { if (getEnv() == "tb") {
this.tbLoad(callback, url, "utf8") this.tbLoad(callback, url, "utf8")
} }
//tt环境待开发,TODO
else if (getEnv() == "tt") {
console.error("tt环境待开发")
}
else { else {
this.loadRawWeb(callback, url, "text") this.loadRawWeb(callback, url, "text")
} }
......
...@@ -197,8 +197,8 @@ export default class TextureManager { ...@@ -197,8 +197,8 @@ export default class TextureManager {
//之前已经active过了,upload里也有bind,这里也许不用执行 //之前已经active过了,upload里也有bind,这里也许不用执行
// glTexture.bind(location); // glTexture.bind(location);
glTexture.premultiplyAlpha = true; glTexture.premultiplyAlpha = true;
if (texture.source.data) {//是data形式 if (texture.source._data) {//是data形式
glTexture.uploadData(texture.source.data, texture.width, texture.height) glTexture.uploadData(texture.source._data, texture.width, texture.height)
} else { } else {
glTexture.upload(texture.source); glTexture.upload(texture.source);
} }
...@@ -241,8 +241,8 @@ export default class TextureManager { ...@@ -241,8 +241,8 @@ export default class TextureManager {
texture._glRenderTargets[this.renderer.CONTEXT_UID].resize(texture.width, texture.height); texture._glRenderTargets[this.renderer.CONTEXT_UID].resize(texture.width, texture.height);
} }
else { else {
if (texture.source.data) {//是data形式 if (texture.source._data) {//是data形式
glTexture.uploadData(texture.source.data, texture.width, texture.height) glTexture.uploadData(texture.source._data, texture.width, texture.height)
} else { } else {
glTexture.upload(texture.source); glTexture.upload(texture.source);
} }
......
...@@ -628,8 +628,7 @@ export class TextField extends Sprite { ...@@ -628,8 +628,7 @@ export class TextField extends Sprite {
for (let i = 0; i < realLines.length; i++) { for (let i = 0; i < realLines.length; i++) {
let oy = (lineH - s.size) / 2; let oy = (lineH - s.size) / 2;
let ox = 0; let ox = 0;
//@ts-ignore 现在貌似小程序的textAlign有点问题,如果修复了再说
// if (my) ox = - tx;//移回去,已经修复,注释掉吧
if (s.stroke) { if (s.stroke) {
ctx.strokeStyle = s.strokeColor; ctx.strokeStyle = s.strokeColor;
ctx.lineWidth = s.stroke * 2; ctx.lineWidth = s.stroke * 2;
......
...@@ -90,13 +90,6 @@ export default class BaseTexture extends EventDispatcher { ...@@ -90,13 +90,6 @@ export default class BaseTexture extends EventDispatcher {
/** /**
* image对象,canvas对象,或者imageData(canvas渲染模式用不了,是否考虑去掉),以后类型增多后再说 * image对象,canvas对象,或者imageData(canvas渲染模式用不了,是否考虑去掉),以后类型增多后再说
* {
* data:Uint8Array,
* width:number,
* height:number,
* type:string,
* path:string
* }
*/ */
source; source;
/** /**
...@@ -124,7 +117,7 @@ export default class BaseTexture extends EventDispatcher { ...@@ -124,7 +117,7 @@ export default class BaseTexture extends EventDispatcher {
//有source要加载,构造函数不缓存baseTexture,要缓存用fromUrl //有source要加载,构造函数不缓存baseTexture,要缓存用fromUrl
if (source) { if (source) {
//是imageData //是imageData
if (source.data) { if (source._data) {
this._sourceChange(source); this._sourceChange(source);
} }
//是canvas //是canvas
...@@ -232,10 +225,10 @@ export default class BaseTexture extends EventDispatcher { ...@@ -232,10 +225,10 @@ export default class BaseTexture extends EventDispatcher {
} }
/** /**
* 随便啥形式的,比如data * 随便啥形式的,比如IImageData形式
* @param data * @param data
*/ */
static fromData(data) { static fromData(data: IImageData) {
return new BaseTexture(data); return new BaseTexture(data);
} }
...@@ -274,13 +267,14 @@ export default class BaseTexture extends EventDispatcher { ...@@ -274,13 +267,14 @@ export default class BaseTexture extends EventDispatcher {
* @param anything * @param anything
* @returns * @returns
*/ */
static from(anything: string | HTMLCanvasElement | HTMLImageElement) { static from(anything: string | HTMLCanvasElement | HTMLImageElement | IImageData) {
//路径 //路径
if (typeof anything === 'string') { if (typeof anything === 'string') {
return BaseTexture.fromUrl(anything); return BaseTexture.fromUrl(anything);
} }
//@ts-ignore //@ts-ignore
else if (anything.data) { else if (anything._data) {
//@ts-ignore
return BaseTexture.fromData(anything); return BaseTexture.fromData(anything);
} }
//@ts-ignore canvas //@ts-ignore canvas
...@@ -341,3 +335,26 @@ export default class BaseTexture extends EventDispatcher { ...@@ -341,3 +335,26 @@ export default class BaseTexture extends EventDispatcher {
return null; return null;
} }
} }
/**
* 图片原始数据形式的数据接口
*/
export interface IImageData {
//这里需要修改下data改为_data,tt里的Image对象居然有data(ArrayBuffer虽然能用,但是有偏移),导致判断有问题,需要同步修改TextureManager
/**
* 原始图片数据
* 比如从getImageData获取的数据
* var imgData = ctx.getImageData(0, 0, w, h);
* var _data = new Uint8Array(imgData.data)
*/
_data: Uint8Array | ArrayBuffer | Float32Array | Uint8ClampedArray,
width: number,
height: number,
/**
* 暂时不必要
*/
type?: string,
/**
* 暂时不必要
*/
path?: string
}
\ No newline at end of file
...@@ -503,7 +503,7 @@ removeAllHandlers(Texture.EMPTY.baseTexture); ...@@ -503,7 +503,7 @@ removeAllHandlers(Texture.EMPTY.baseTexture);
// * 16*16的数据 // * 16*16的数据
// */ // */
// const whiteSource = { // const whiteSource = {
// data: (function () { // _data: (function () {
// var arr = [] // var arr = []
// for (var i = 0; i < 16 * 16 * 4; i++) { // for (var i = 0; i < 16 * 16 * 4; i++) {
// arr.push(255); // arr.push(255);
......
...@@ -23,7 +23,7 @@ let defaultCanvas: HTMLCanvasElement; ...@@ -23,7 +23,7 @@ let defaultCanvas: HTMLCanvasElement;
/** /**
* 调色方法,根据混色是否可用 * 调色方法,根据混色是否可用
*/ */
let tintMethod: Function = canUseNewCanvasBlendModes() ? tintWithMultiply : tintWithPerPixel; let tintMethod: Function //= canUseNewCanvasBlendModes() ? tintWithMultiply : tintWithPerPixel;
/** /**
* Basically this method just needs a sprite and a color and tints the sprite with the given color. * Basically this method just needs a sprite and a color and tints the sprite with the given color.
...@@ -53,7 +53,9 @@ export function getTintedTexture(texture: Texture, color: number): HTMLCanvasEle ...@@ -53,7 +53,9 @@ export function getTintedTexture(texture: Texture, color: number): HTMLCanvasEle
else { else {
canvas = defaultCanvas || createCanvas()//document.createElement('canvas'); canvas = defaultCanvas || createCanvas()//document.createElement('canvas');
} }
//用到时才执行
if (!tintMethod) tintMethod = canUseNewCanvasBlendModes() ? tintWithMultiply : tintWithPerPixel;
tintMethod(texture, color, canvas); tintMethod(texture, color, canvas);
canvas.tintId = texture._updateID; canvas.tintId = texture._updateID;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import { RENDERER_TYPE } from "../const"; import { RENDERER_TYPE } from "../const";
// import { mapPremultipliedBlendModes } from "./mapPremultipliedBlendModes"; // import { mapPremultipliedBlendModes } from "./mapPremultipliedBlendModes";
import { createCanvas, getEnv } from "./tbminiAdapte"; import { createCanvas } from "./tbminiAdapte";
export * from './twiddle'; export * from './twiddle';
......
export enum EnvType {
/**
* 淘宝小程序,不能头部adapter是因为引擎包并不打包在项目代码里,所以头部都需要,TODO,后续考虑单独为淘宝小程序打引擎包(加入adapter),然后引擎内部就干净了,load里也要肃清
*/
tb = "tb",
/**
* web环境
*/
web = "web",
/**
* 字节helium环境,暂时废弃
* 打包的时候,
* 1、引擎一并打入,并且头部添加helium-adapter,基本和Web保持一致
* 2、客户端先loadScript(helium-adapter.js),再loadScript(引擎),最后loadScript(项目代码)
*/
// hel = "hel",
/**
* 头条,抖音小程序
* 需要先执行adapter.js注入兼容的全局变量
*/
tt = "tt"
}
let env: "tb" | "web" | "tt" = "web"; let env: EnvType = EnvType.web;
//如果是浏览器环境,声明个my为null,为了无声明不报错 //如果是浏览器环境,声明个my为null,为了无声明不报错
if (window) window["my"] = null;//在用webview的小程序环境内,只要在小程序的sdk前加js就无所谓, if (window) window["my"] = null;//在用webview的小程序环境内,只要在小程序的sdk前加js就无所谓,
export function getEnv(): "tb" | "web" | "tt" { export function getEnv(): EnvType {
return env return env
} }
/** /**
...@@ -10,7 +32,7 @@ export function getEnv(): "tb" | "web" | "tt" { ...@@ -10,7 +32,7 @@ export function getEnv(): "tb" | "web" | "tt" {
* 方法initedByTbCanvas会自行设置env为tb * 方法initedByTbCanvas会自行设置env为tb
* @param e 环境 * @param e 环境
*/ */
export function setEnv(e: "tb" | "web" | "tt") { export function setEnv(e: EnvType) {
env = e; env = e;
} }
/** /**
...@@ -19,15 +41,10 @@ export function setEnv(e: "tb" | "web" | "tt") { ...@@ -19,15 +41,10 @@ export function setEnv(e: "tb" | "web" | "tt") {
export function createCanvas(): HTMLCanvasElement { export function createCanvas(): HTMLCanvasElement {
//@ts-ignore 先这么改把,以后再改TODO,Texture.WHITE有个自执行,所以在setEnv前就会执行web的链路,以后考虑兼容document //@ts-ignore 先这么改把,以后再改TODO,Texture.WHITE有个自执行,所以在setEnv前就会执行web的链路,以后考虑兼容document
// return document && document.createElement("canvas") || createTbOffscreenCanvas()//my._createOffscreenCanvas(); // return document && document.createElement("canvas") || createTbOffscreenCanvas()//my._createOffscreenCanvas();
//web环境
if (getEnv() == "web") return document.createElement("canvas");
//淘宝小程序环境 //淘宝小程序环境
if (getEnv() == "tb") return createTbOffscreenCanvas()//my._createOffscreenCanvas(); if (getEnv() == "tb") return createTbOffscreenCanvas()//my._createOffscreenCanvas();
//tt环境,TODO //web环境或其他环境,当作兼容过document的
if (getEnv() == "tt") { /*if (getEnv() == "web" || getEnv() == "hel" || getEnv() == "tt")*/ return document.createElement("canvas");
console.error("tt环境待开发")
return
}
//提示下 //提示下
console.warn("未知环境,创建canvas失败") console.warn("未知环境,创建canvas失败")
} }
...@@ -53,14 +70,7 @@ let tbCanvas; ...@@ -53,14 +70,7 @@ let tbCanvas;
*/ */
export function initedByTbCanvas(canvas) { export function initedByTbCanvas(canvas) {
tbCanvas = canvas; tbCanvas = canvas;
setEnv("tb"); setEnv(EnvType.tb);
}
/**
* 预留方法,后续开发,主要用于初始化Canvas类和Image类,TODO
*/
export function initedByTtEnv() {
console.log("待开发")
setEnv("tt")
} }
//兼容老版本,TODO废弃 //兼容老版本,TODO废弃
export function initedByCanvas(canvas) { export function initedByCanvas(canvas) {
...@@ -85,16 +95,12 @@ export function destroyCanvasContent() { ...@@ -85,16 +95,12 @@ export function destroyCanvasContent() {
* @returns * @returns
*/ */
export function createImage(): HTMLImageElement { export function createImage(): HTMLImageElement {
if (getEnv() == "web") return new Image();
if (getEnv() == "tb") { if (getEnv() == "tb") {
if (tbCanvas) return tbCanvas.createImage(); if (tbCanvas) return tbCanvas.createImage();
console.warn("淘宝小程序初始化canvas不存在"); console.warn("淘宝小程序初始化canvas不存在");
} }
//tt环境,TODO //当作兼容过Image的
if (getEnv() == "tt") { /*if (getEnv() == "web" || getEnv() == "hel" || getEnv() == "tt")*/ return new Image();
console.error("tt环境待开发")
return
}
console.warn("未知环境,创建Image失败") console.warn("未知环境,创建Image失败")
} }
/** /**
...@@ -149,7 +155,7 @@ let webglSupported: boolean; ...@@ -149,7 +155,7 @@ let webglSupported: boolean;
*/ */
export function isWebGLSupported(): boolean { export function isWebGLSupported(): boolean {
//淘宝环境直接返回true,否则找淘宝小程序解决,tt环境待测试,TODO //淘宝环境直接返回true,否则找淘宝小程序解决,tt环境待测试,TODO
if (getEnv() == "tb" || getEnv() == "tt") return true; if (getEnv() == "tb" || getEnv() == "tt" /*|| getEnv() == "hel"*/) return true;
//已经判断过了,直接返回 //已经判断过了,直接返回
if (webglSupported !== undefined) return webglSupported; if (webglSupported !== undefined) return webglSupported;
//进入判断,加上低性能下是否使用webgl标识,pc上因为failIfMajorPerformanceCaveat设为true获取不到webgl一般是驱动问题 //进入判断,加上低性能下是否使用webgl标识,pc上因为failIfMajorPerformanceCaveat设为true获取不到webgl一般是驱动问题
...@@ -183,7 +189,16 @@ let osType: "ios" | "android" | "pc"; ...@@ -183,7 +189,16 @@ let osType: "ios" | "android" | "pc";
export function getOsType(): "ios" | "android" | "pc" { export function getOsType(): "ios" | "android" | "pc" {
//有就直接返回 //有就直接返回
if (osType) return osType; if (osType) return osType;
if (getEnv() == "web") { //淘宝小程序
if (getEnv() == "tb") {
//@ts-ignore
osType = my.getSystemInfoSync().platform.toLowerCase();
}
//如果是hel环境,直接取window上的
// else if (getEnv() == "hel") {
// osType = window && window["osType"];
// }
else /*if (getEnv() == "web")*/ {
osType = navigator && navigator.userAgent && (function () { osType = navigator && navigator.userAgent && (function () {
let n = navigator.userAgent.toLocaleLowerCase(); let n = navigator.userAgent.toLocaleLowerCase();
let reg1 = /android/; let reg1 = /android/;
...@@ -201,17 +216,6 @@ export function getOsType(): "ios" | "android" | "pc" { ...@@ -201,17 +216,6 @@ export function getOsType(): "ios" | "android" | "pc" {
//tt的再来一次,TODO //tt的再来一次,TODO
// if(!osType&&) // 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; return osType;
} }
...@@ -222,23 +226,18 @@ let devicePixelRatio: number; ...@@ -222,23 +226,18 @@ let devicePixelRatio: number;
*/ */
export function getDevicePixelRatio() { export function getDevicePixelRatio() {
if (devicePixelRatio) return devicePixelRatio; if (devicePixelRatio) return devicePixelRatio;
if (getEnv() == "web") { //淘宝小程序
if (getEnv() == "tb") {
//@ts-ignore
devicePixelRatio = my.getSystemInfoSync().pixelRatio;
}
//其他正常判断吧
else /*if (getEnv() == "web" || getEnv() == "hel")*/ {
devicePixelRatio = window && (window.devicePixelRatio || 1); devicePixelRatio = window && (window.devicePixelRatio || 1);
//@ts-ignore如果还没取到,环境切换有问题,用老方法 //@ts-ignore如果还没取到,环境切换有问题,用老方法
if (!devicePixelRatio && my) devicePixelRatio = my.getSystemInfoSync().pixelRatio; if (!devicePixelRatio && my) devicePixelRatio = my.getSystemInfoSync().pixelRatio;
//tt的再来一个,TODO //tt的再来一个,TODO
// if(!devicePixelRatio&&) // 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; return devicePixelRatio;
} }
import { EventDispatcher } from "../../2d/events"; import { EventDispatcher } from "../../2d/events";
import { GlobalLoader } from "../../2d/loader"; import { GlobalLoader } from "../../2d/loader";
import { rgb2hex, getEnv, decodeText, ArrayBufferToBase64 } from "../../2d/utils"; import { rgb2hex, decodeText, ArrayBufferToBase64 } from "../../2d/utils";
import { LightMaterial } from "../materials/LightMaterial"; import { LightMaterial } from "../materials/LightMaterial";
import { Geometry } from "../Geometry"; import { Geometry } from "../Geometry";
import { Texture } from "../../2d/texture"; import { Texture } from "../../2d/texture";
...@@ -275,11 +275,7 @@ export function loadGltf( ...@@ -275,11 +275,7 @@ export function loadGltf(
// onError && onError(res) // onError && onError(res)
// } // }
// } // }
// if (getEnv() == "tb") { // GlobalLoader.loadAB(callback, url);
// GlobalLoader.tbLoad(callback, url, "ArrayBuffer")
// } else {
// GlobalLoader.loadRawWeb(callback, url, "arraybuffer")
// }
// } // }
// parse(data: any, onLoad: (res: any) => void, onError: (err: any) => void) { // parse(data: any, onLoad: (res: any) => void, onError: (err: any) => void) {
......
import { GlobalLoader } from "../2d/loader"; import { GlobalLoader } from "../2d/loader";
import { getEnv } from "../2d/utils";
import { Texture, BaseTexture } from "../2d/texture"; import { Texture, BaseTexture } from "../2d/texture";
import { Rectangle } from "../2d/math"; import { Rectangle } from "../2d/math";
......
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