|
@@ -4,10 +4,7 @@ import { m4 } from "../base/m4";
|
|
|
import { Disposable, Scene } from "../base/Scene";
|
|
import { Disposable, Scene } from "../base/Scene";
|
|
|
import { createProgram, createShader } from "../base/utils";
|
|
import { createProgram, createShader } from "../base/utils";
|
|
|
import { Area, Color } from "./common";
|
|
import { Area, Color } from "./common";
|
|
|
-import { FillerData } from "./FillerData"
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+import { FillerData } from "./FillerData";
|
|
|
|
|
|
|
|
export class AnimatingArea {
|
|
export class AnimatingArea {
|
|
|
constructor(
|
|
constructor(
|
|
@@ -15,16 +12,10 @@ export class AnimatingArea {
|
|
|
readonly x: number,
|
|
readonly x: number,
|
|
|
readonly y: number,
|
|
readonly y: number,
|
|
|
public progress: number,
|
|
public progress: number,
|
|
|
- ) { }
|
|
|
|
|
|
|
+ ) {}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
export class AnimatableMask implements Disposable {
|
|
export class AnimatableMask implements Disposable {
|
|
|
-
|
|
|
|
|
private vertexShaderCode = /*glsl*/ `
|
|
private vertexShaderCode = /*glsl*/ `
|
|
|
attribute vec2 a_position;
|
|
attribute vec2 a_position;
|
|
|
attribute vec2 a_texCoord;
|
|
attribute vec2 a_texCoord;
|
|
@@ -123,109 +114,106 @@ export class AnimatableMask implements Disposable {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- `
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- program: WebGLProgram
|
|
|
|
|
-
|
|
|
|
|
|
|
+ `;
|
|
|
|
|
|
|
|
- aPositionLoc: number
|
|
|
|
|
- aTexcoordLoc: number
|
|
|
|
|
- aAreaIdLoc: number
|
|
|
|
|
- aCenterLoc: number
|
|
|
|
|
- aProgressLoc: number
|
|
|
|
|
- aMaxRadiusLoc: number
|
|
|
|
|
- uMatrixLoc: WebGLUniformLocation
|
|
|
|
|
|
|
+ program: WebGLProgram;
|
|
|
|
|
|
|
|
- positionBuffer: WebGLBuffer
|
|
|
|
|
- texCoordBuffer: WebGLBuffer
|
|
|
|
|
- areaIdBuffer: WebGLBuffer
|
|
|
|
|
- centerBuffer: WebGLBuffer
|
|
|
|
|
- progressBuffer: WebGLBuffer
|
|
|
|
|
- maxRadiusBuffer: WebGLBuffer
|
|
|
|
|
|
|
+ aPositionLoc: number;
|
|
|
|
|
+ aTexcoordLoc: number;
|
|
|
|
|
+ aAreaIdLoc: number;
|
|
|
|
|
+ aCenterLoc: number;
|
|
|
|
|
+ aProgressLoc: number;
|
|
|
|
|
+ aMaxRadiusLoc: number;
|
|
|
|
|
+ uMatrixLoc: WebGLUniformLocation;
|
|
|
|
|
|
|
|
|
|
+ positionBuffer: WebGLBuffer;
|
|
|
|
|
+ texCoordBuffer: WebGLBuffer;
|
|
|
|
|
+ areaIdBuffer: WebGLBuffer;
|
|
|
|
|
+ centerBuffer: WebGLBuffer;
|
|
|
|
|
+ progressBuffer: WebGLBuffer;
|
|
|
|
|
+ maxRadiusBuffer: WebGLBuffer;
|
|
|
|
|
|
|
|
dispose(): void {
|
|
dispose(): void {
|
|
|
- let gl = this.scene.gl
|
|
|
|
|
-
|
|
|
|
|
- gl.deleteBuffer(this.positionBuffer)
|
|
|
|
|
- gl.deleteBuffer(this.texCoordBuffer)
|
|
|
|
|
- gl.deleteBuffer(this.areaIdBuffer)
|
|
|
|
|
- gl.deleteBuffer(this.centerBuffer)
|
|
|
|
|
- gl.deleteBuffer(this.progressBuffer)
|
|
|
|
|
- gl.deleteBuffer(this.maxRadiusBuffer)
|
|
|
|
|
- gl.deleteProgram(this.program)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ let gl = this.scene.gl;
|
|
|
|
|
+
|
|
|
|
|
+ gl.deleteBuffer(this.positionBuffer);
|
|
|
|
|
+ gl.deleteBuffer(this.texCoordBuffer);
|
|
|
|
|
+ gl.deleteBuffer(this.areaIdBuffer);
|
|
|
|
|
+ gl.deleteBuffer(this.centerBuffer);
|
|
|
|
|
+ gl.deleteBuffer(this.progressBuffer);
|
|
|
|
|
+ gl.deleteBuffer(this.maxRadiusBuffer);
|
|
|
|
|
+ gl.deleteProgram(this.program);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ positionArray: Float32Array;
|
|
|
|
|
+ texCoordArray: Float32Array;
|
|
|
|
|
+ areaIdArray: Float32Array;
|
|
|
|
|
+ centerArray: Float32Array;
|
|
|
|
|
+ progressArray: Float32Array;
|
|
|
|
|
+ maxRadiusArray: Float32Array;
|
|
|
|
|
|
|
|
|
|
+ matrix: m4.Matrix4;
|
|
|
|
|
|
|
|
- positionArray: Float32Array
|
|
|
|
|
- texCoordArray: Float32Array
|
|
|
|
|
- areaIdArray: Float32Array
|
|
|
|
|
- centerArray: Float32Array
|
|
|
|
|
- progressArray: Float32Array
|
|
|
|
|
- maxRadiusArray: Float32Array
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- matrix: m4.Matrix4
|
|
|
|
|
-
|
|
|
|
|
|
|
+ texture: WebGLTexture;
|
|
|
|
|
+ fb: WebGLFramebuffer;
|
|
|
|
|
|
|
|
- texture: WebGLTexture
|
|
|
|
|
- fb: WebGLFramebuffer
|
|
|
|
|
-
|
|
|
|
|
- private animatingAreas: Array<AnimatingArea> = []
|
|
|
|
|
-
|
|
|
|
|
- get width(): number { return this.fillerData.width }
|
|
|
|
|
- get height(): number { return this.fillerData.height }
|
|
|
|
|
|
|
+ private animatingAreas: Array<AnimatingArea> = [];
|
|
|
|
|
|
|
|
|
|
+ get width(): number {
|
|
|
|
|
+ return this.fillerData.width;
|
|
|
|
|
+ }
|
|
|
|
|
+ get height(): number {
|
|
|
|
|
+ return this.fillerData.height;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- maxCount: number
|
|
|
|
|
|
|
+ maxCount: number;
|
|
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
|
private scene: Scene,
|
|
private scene: Scene,
|
|
|
private fillerData: FillerData,
|
|
private fillerData: FillerData,
|
|
|
-
|
|
|
|
|
) {
|
|
) {
|
|
|
|
|
+ const gl = scene.gl;
|
|
|
|
|
|
|
|
- const gl = scene.gl
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- this.program = createProgram(gl,
|
|
|
|
|
|
|
+ this.program = createProgram(
|
|
|
|
|
+ gl,
|
|
|
createShader(gl, gl.VERTEX_SHADER, this.vertexShaderCode)!,
|
|
createShader(gl, gl.VERTEX_SHADER, this.vertexShaderCode)!,
|
|
|
- createShader(gl, gl.FRAGMENT_SHADER, this.fragmentShaderCode)!)!
|
|
|
|
|
-
|
|
|
|
|
- this.aPositionLoc = gl.getAttribLocation(this.program, "a_position")
|
|
|
|
|
- this.aTexcoordLoc = gl.getAttribLocation(this.program, "a_texCoord")
|
|
|
|
|
- this.aAreaIdLoc = gl.getAttribLocation(this.program, "a_areaId")
|
|
|
|
|
- this.aCenterLoc = gl.getAttribLocation(this.program, "a_center")
|
|
|
|
|
- this.aProgressLoc = gl.getAttribLocation(this.program, "a_progress")
|
|
|
|
|
- this.aMaxRadiusLoc = gl.getAttribLocation(this.program, "a_maxRadius")
|
|
|
|
|
- this.uMatrixLoc = gl.getUniformLocation(this.program, "u_matrix")!
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- this.maxCount = fillerData.data.maxAreaCountOfGroup
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- this.positionBuffer = gl.createBuffer()!
|
|
|
|
|
- this.texCoordBuffer = gl.createBuffer()!
|
|
|
|
|
- this.areaIdBuffer = gl.createBuffer()!
|
|
|
|
|
- this.centerBuffer = gl.createBuffer()!
|
|
|
|
|
- this.progressBuffer = gl.createBuffer()!
|
|
|
|
|
- this.maxRadiusBuffer = gl.createBuffer()!
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- this.matrix = m4.projectionNoflipY(fillerData.width, fillerData.height)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- this.texture = gl.createTexture()!
|
|
|
|
|
- gl.bindTexture(gl.TEXTURE_2D, this.texture)
|
|
|
|
|
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.fillerData.width, this.fillerData.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null)
|
|
|
|
|
|
|
+ createShader(gl, gl.FRAGMENT_SHADER, this.fragmentShaderCode)!,
|
|
|
|
|
+ )!;
|
|
|
|
|
+
|
|
|
|
|
+ this.aPositionLoc = gl.getAttribLocation(this.program, "a_position");
|
|
|
|
|
+ this.aTexcoordLoc = gl.getAttribLocation(this.program, "a_texCoord");
|
|
|
|
|
+ this.aAreaIdLoc = gl.getAttribLocation(this.program, "a_areaId");
|
|
|
|
|
+ this.aCenterLoc = gl.getAttribLocation(this.program, "a_center");
|
|
|
|
|
+ this.aProgressLoc = gl.getAttribLocation(this.program, "a_progress");
|
|
|
|
|
+ this.aMaxRadiusLoc = gl.getAttribLocation(this.program, "a_maxRadius");
|
|
|
|
|
+ this.uMatrixLoc = gl.getUniformLocation(this.program, "u_matrix")!;
|
|
|
|
|
+
|
|
|
|
|
+ // 此处maxCount 等于分组最大区块数并不合理,假设每个颜色分组都是一个区块, 此处maxCount会等于1, 如果用户快速点击多个区块,会造成上一个区块的晕染无法完成
|
|
|
|
|
+ // this.maxCount = fillerData.data.maxAreaCountOfGroup;
|
|
|
|
|
+ this.maxCount = 5;
|
|
|
|
|
+
|
|
|
|
|
+ this.positionBuffer = gl.createBuffer()!;
|
|
|
|
|
+ this.texCoordBuffer = gl.createBuffer()!;
|
|
|
|
|
+ this.areaIdBuffer = gl.createBuffer()!;
|
|
|
|
|
+ this.centerBuffer = gl.createBuffer()!;
|
|
|
|
|
+ this.progressBuffer = gl.createBuffer()!;
|
|
|
|
|
+ this.maxRadiusBuffer = gl.createBuffer()!;
|
|
|
|
|
+
|
|
|
|
|
+ this.matrix = m4.projectionNoflipY(fillerData.width, fillerData.height);
|
|
|
|
|
+
|
|
|
|
|
+ this.texture = gl.createTexture()!;
|
|
|
|
|
+ gl.bindTexture(gl.TEXTURE_2D, this.texture);
|
|
|
|
|
+ gl.texImage2D(
|
|
|
|
|
+ gl.TEXTURE_2D,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ gl.RGBA,
|
|
|
|
|
+ this.fillerData.width,
|
|
|
|
|
+ this.fillerData.height,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ gl.RGBA,
|
|
|
|
|
+ gl.UNSIGNED_BYTE,
|
|
|
|
|
+ null,
|
|
|
|
|
+ );
|
|
|
//gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, this.fillerData.width, this.fillerData.height, 0, gl.RGB, gl.UNSIGNED_SHORT_5_6_5, null)
|
|
//gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, this.fillerData.width, this.fillerData.height, 0, gl.RGB, gl.UNSIGNED_SHORT_5_6_5, null)
|
|
|
|
|
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
@@ -233,135 +221,143 @@ export class AnimatableMask implements Disposable {
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- this.fb = gl.createFramebuffer()!
|
|
|
|
|
- gl.bindFramebuffer(gl.FRAMEBUFFER, this.fb)
|
|
|
|
|
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0)
|
|
|
|
|
- gl.bindFramebuffer(gl.FRAMEBUFFER, null)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- this.positionArray = new Float32Array(this.maxCount * 12)
|
|
|
|
|
- this.texCoordArray = new Float32Array(this.maxCount * 12)
|
|
|
|
|
- this.areaIdArray = new Float32Array(this.maxCount * 24)
|
|
|
|
|
- this.centerArray = new Float32Array(this.maxCount * 12)
|
|
|
|
|
- this.progressArray = new Float32Array(this.maxCount * 6)
|
|
|
|
|
- this.maxRadiusArray = new Float32Array(this.maxCount * 6)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ this.fb = gl.createFramebuffer()!;
|
|
|
|
|
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.fb);
|
|
|
|
|
+ gl.framebufferTexture2D(
|
|
|
|
|
+ gl.FRAMEBUFFER,
|
|
|
|
|
+ gl.COLOR_ATTACHMENT0,
|
|
|
|
|
+ gl.TEXTURE_2D,
|
|
|
|
|
+ this.texture,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ );
|
|
|
|
|
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
|
|
|
+
|
|
|
|
|
+ this.positionArray = new Float32Array(this.maxCount * 12);
|
|
|
|
|
+ this.texCoordArray = new Float32Array(this.maxCount * 12);
|
|
|
|
|
+ this.areaIdArray = new Float32Array(this.maxCount * 24);
|
|
|
|
|
+ this.centerArray = new Float32Array(this.maxCount * 12);
|
|
|
|
|
+ this.progressArray = new Float32Array(this.maxCount * 6);
|
|
|
|
|
+ this.maxRadiusArray = new Float32Array(this.maxCount * 6);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
addArea(area: Area, cx: number, cy: number, duration = 800) {
|
|
addArea(area: Area, cx: number, cy: number, duration = 800) {
|
|
|
- let aa = new AnimatingArea(area, cx, cy, 0)
|
|
|
|
|
- let animator = new Animator(duration, () => {
|
|
|
|
|
- aa.progress = animator.value()
|
|
|
|
|
- }, () => {
|
|
|
|
|
-
|
|
|
|
|
- })
|
|
|
|
|
- this.scene.addAnimator(animator)
|
|
|
|
|
|
|
+ let aa = new AnimatingArea(area, cx, cy, 0);
|
|
|
|
|
+ let animator = new Animator(
|
|
|
|
|
+ duration,
|
|
|
|
|
+ () => {
|
|
|
|
|
+ aa.progress = animator.value();
|
|
|
|
|
+ },
|
|
|
|
|
+ () => {},
|
|
|
|
|
+ );
|
|
|
|
|
+ this.scene.addAnimator(animator);
|
|
|
this.animatingAreas.push(aa);
|
|
this.animatingAreas.push(aa);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- fillPoint(arr: Float32Array, offset: number, x: number, y: number, count: number) {
|
|
|
|
|
|
|
+ fillPoint(
|
|
|
|
|
+ arr: Float32Array,
|
|
|
|
|
+ offset: number,
|
|
|
|
|
+ x: number,
|
|
|
|
|
+ y: number,
|
|
|
|
|
+ count: number,
|
|
|
|
|
+ ) {
|
|
|
for (var i = 0; i < count; i++) {
|
|
for (var i = 0; i < count; i++) {
|
|
|
- arr[offset + i * 2] = x
|
|
|
|
|
- arr[offset + i * 2 + 1] = y
|
|
|
|
|
|
|
+ arr[offset + i * 2] = x;
|
|
|
|
|
+ arr[offset + i * 2 + 1] = y;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
fillNumber(arr: Float32Array, offset: number, n: number, count: number) {
|
|
fillNumber(arr: Float32Array, offset: number, n: number, count: number) {
|
|
|
for (var i = 0; i < count; i++) {
|
|
for (var i = 0; i < count; i++) {
|
|
|
- arr[offset + i] = n
|
|
|
|
|
|
|
+ arr[offset + i] = n;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
flush() {
|
|
flush() {
|
|
|
- // console.log('animationAreas.length=', this.animatingAreas.length)
|
|
|
|
|
|
|
+ console.log("animationAreas.length=", this.animatingAreas.length);
|
|
|
|
|
|
|
|
- if (this.animatingAreas.length <= 0) return
|
|
|
|
|
|
|
+ if (this.animatingAreas.length <= 0) return;
|
|
|
|
|
|
|
|
- var vertexOffset = 0
|
|
|
|
|
- var colorOffset = 0
|
|
|
|
|
- var nOffset = 0
|
|
|
|
|
|
|
+ var vertexOffset = 0;
|
|
|
|
|
+ var colorOffset = 0;
|
|
|
|
|
+ var nOffset = 0;
|
|
|
|
|
|
|
|
- const width = this.fillerData.width
|
|
|
|
|
- const height = this.fillerData.height
|
|
|
|
|
|
|
+ const width = this.fillerData.width;
|
|
|
|
|
+ const height = this.fillerData.height;
|
|
|
|
|
|
|
|
for (var i = 0; i < this.animatingAreas.length; i++) {
|
|
for (var i = 0; i < this.animatingAreas.length; i++) {
|
|
|
-
|
|
|
|
|
- var aa = this.animatingAreas[i]
|
|
|
|
|
- var area = aa.area
|
|
|
|
|
-
|
|
|
|
|
- fillRectangle(this.positionArray, vertexOffset, area.rect.x, area.rect.y, area.rect.width, area.rect.height)
|
|
|
|
|
- fillRectangle(this.texCoordArray, vertexOffset, area.rect.x / width, area.rect.y / height, area.rect.width / width, area.rect.height / height)
|
|
|
|
|
- this.fillPoint(this.centerArray, vertexOffset, aa.x, aa.y, 6)
|
|
|
|
|
-
|
|
|
|
|
- var color = new Color(area.id)
|
|
|
|
|
- color.fillFloatArray(this.areaIdArray, colorOffset, 6)
|
|
|
|
|
-
|
|
|
|
|
- var maxRadius = coverRadius(area.rect, aa.x, aa.y)
|
|
|
|
|
|
|
+ var aa = this.animatingAreas[i];
|
|
|
|
|
+ var area = aa.area;
|
|
|
|
|
+
|
|
|
|
|
+ fillRectangle(
|
|
|
|
|
+ this.positionArray,
|
|
|
|
|
+ vertexOffset,
|
|
|
|
|
+ area.rect.x,
|
|
|
|
|
+ area.rect.y,
|
|
|
|
|
+ area.rect.width,
|
|
|
|
|
+ area.rect.height,
|
|
|
|
|
+ );
|
|
|
|
|
+ fillRectangle(
|
|
|
|
|
+ this.texCoordArray,
|
|
|
|
|
+ vertexOffset,
|
|
|
|
|
+ area.rect.x / width,
|
|
|
|
|
+ area.rect.y / height,
|
|
|
|
|
+ area.rect.width / width,
|
|
|
|
|
+ area.rect.height / height,
|
|
|
|
|
+ );
|
|
|
|
|
+ this.fillPoint(this.centerArray, vertexOffset, aa.x, aa.y, 6);
|
|
|
|
|
+
|
|
|
|
|
+ var color = new Color(area.id);
|
|
|
|
|
+ color.fillFloatArray(this.areaIdArray, colorOffset, 6);
|
|
|
|
|
+
|
|
|
|
|
+ var maxRadius = coverRadius(area.rect, aa.x, aa.y);
|
|
|
// console.log('rect=', area.rect, maxRadius, aa.x, aa.y);
|
|
// console.log('rect=', area.rect, maxRadius, aa.x, aa.y);
|
|
|
- //maxRadius =
|
|
|
|
|
|
|
+ //maxRadius =
|
|
|
|
|
|
|
|
- this.fillNumber(this.progressArray, nOffset, aa.progress, 6)
|
|
|
|
|
- this.fillNumber(this.maxRadiusArray, nOffset, maxRadius, 6)
|
|
|
|
|
|
|
+ this.fillNumber(this.progressArray, nOffset, aa.progress, 6);
|
|
|
|
|
+ this.fillNumber(this.maxRadiusArray, nOffset, maxRadius, 6);
|
|
|
|
|
|
|
|
- vertexOffset += 12
|
|
|
|
|
- colorOffset += 24
|
|
|
|
|
- nOffset += 6
|
|
|
|
|
|
|
+ vertexOffset += 12;
|
|
|
|
|
+ colorOffset += 24;
|
|
|
|
|
+ nOffset += 6;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//console.log('areaIdArray', this.areaIdArray)
|
|
//console.log('areaIdArray', this.areaIdArray)
|
|
|
|
|
|
|
|
|
|
+ const gl = this.scene.gl;
|
|
|
|
|
|
|
|
- const gl = this.scene.gl
|
|
|
|
|
-
|
|
|
|
|
- gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer)
|
|
|
|
|
- gl.bufferData(gl.ARRAY_BUFFER, this.positionArray, gl.STATIC_DRAW)
|
|
|
|
|
|
|
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
|
|
|
|
|
+ gl.bufferData(gl.ARRAY_BUFFER, this.positionArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
- gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer)
|
|
|
|
|
- gl.bufferData(gl.ARRAY_BUFFER, this.texCoordArray, gl.STATIC_DRAW)
|
|
|
|
|
|
|
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer);
|
|
|
|
|
+ gl.bufferData(gl.ARRAY_BUFFER, this.texCoordArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.areaIdBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.areaIdBuffer);
|
|
|
- gl.bufferData(gl.ARRAY_BUFFER, this.areaIdArray, gl.STATIC_DRAW)
|
|
|
|
|
|
|
+ gl.bufferData(gl.ARRAY_BUFFER, this.areaIdArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.centerBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.centerBuffer);
|
|
|
- gl.bufferData(gl.ARRAY_BUFFER, this.centerArray, gl.STATIC_DRAW)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ gl.bufferData(gl.ARRAY_BUFFER, this.centerArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.progressBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.progressBuffer);
|
|
|
- gl.bufferData(gl.ARRAY_BUFFER, this.progressArray, gl.STATIC_DRAW)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ gl.bufferData(gl.ARRAY_BUFFER, this.progressArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.maxRadiusBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.maxRadiusBuffer);
|
|
|
- gl.bufferData(gl.ARRAY_BUFFER, this.maxRadiusArray, gl.STATIC_DRAW)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ gl.bufferData(gl.ARRAY_BUFFER, this.maxRadiusArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
- this.draw(this.animatingAreas.length * 6)
|
|
|
|
|
-
|
|
|
|
|
- this.animatingAreas = this.animatingAreas.filter(aa => aa.progress < 1)
|
|
|
|
|
|
|
+ this.draw(this.animatingAreas.length * 6);
|
|
|
|
|
|
|
|
|
|
+ this.animatingAreas = this.animatingAreas.filter((aa) => aa.progress < 1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
private draw(n: number) {
|
|
private draw(n: number) {
|
|
|
const gl = this.scene.gl;
|
|
const gl = this.scene.gl;
|
|
|
|
|
|
|
|
- gl.bindFramebuffer(gl.FRAMEBUFFER, this.fb)
|
|
|
|
|
|
|
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.fb);
|
|
|
|
|
|
|
|
//console.log('fb=', this.progressArray)
|
|
//console.log('fb=', this.progressArray)
|
|
|
|
|
|
|
|
gl.useProgram(this.program);
|
|
gl.useProgram(this.program);
|
|
|
|
|
|
|
|
- gl.viewport(0, 0, this.fillerData.width, this.fillerData.height)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ gl.viewport(0, 0, this.fillerData.width, this.fillerData.height);
|
|
|
|
|
|
|
|
gl.enableVertexAttribArray(this.aPositionLoc);
|
|
gl.enableVertexAttribArray(this.aPositionLoc);
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
|
|
@@ -375,7 +371,6 @@ export class AnimatableMask implements Disposable {
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.areaIdBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.areaIdBuffer);
|
|
|
gl.vertexAttribPointer(this.aAreaIdLoc, 4, gl.FLOAT, false, 0, 0);
|
|
gl.vertexAttribPointer(this.aAreaIdLoc, 4, gl.FLOAT, false, 0, 0);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
gl.enableVertexAttribArray(this.aCenterLoc);
|
|
gl.enableVertexAttribArray(this.aCenterLoc);
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.centerBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.centerBuffer);
|
|
|
gl.vertexAttribPointer(this.aCenterLoc, 2, gl.FLOAT, false, 0, 0);
|
|
gl.vertexAttribPointer(this.aCenterLoc, 2, gl.FLOAT, false, 0, 0);
|
|
@@ -384,92 +379,79 @@ export class AnimatableMask implements Disposable {
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.progressBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.progressBuffer);
|
|
|
gl.vertexAttribPointer(this.aProgressLoc, 1, gl.FLOAT, false, 0, 0);
|
|
gl.vertexAttribPointer(this.aProgressLoc, 1, gl.FLOAT, false, 0, 0);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
gl.enableVertexAttribArray(this.aMaxRadiusLoc);
|
|
gl.enableVertexAttribArray(this.aMaxRadiusLoc);
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.maxRadiusBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.maxRadiusBuffer);
|
|
|
gl.vertexAttribPointer(this.aMaxRadiusLoc, 1, gl.FLOAT, false, 0, 0);
|
|
gl.vertexAttribPointer(this.aMaxRadiusLoc, 1, gl.FLOAT, false, 0, 0);
|
|
|
|
|
|
|
|
|
|
+ gl.uniformMatrix4fv(this.uMatrixLoc, false, this.matrix);
|
|
|
|
|
|
|
|
- gl.uniformMatrix4fv(this.uMatrixLoc, false, this.matrix)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- gl.activeTexture(gl.TEXTURE0)
|
|
|
|
|
- gl.bindTexture(gl.TEXTURE_2D, this.fillerData.mapTexure)
|
|
|
|
|
-
|
|
|
|
|
- gl.drawArrays(gl.TRIANGLES, 0, n)
|
|
|
|
|
-
|
|
|
|
|
- gl.bindFramebuffer(gl.FRAMEBUFFER, null)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ gl.activeTexture(gl.TEXTURE0);
|
|
|
|
|
+ gl.bindTexture(gl.TEXTURE_2D, this.fillerData.mapTexure);
|
|
|
|
|
|
|
|
|
|
+ gl.drawArrays(gl.TRIANGLES, 0, n);
|
|
|
|
|
|
|
|
|
|
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
// 恢复上次已填色的部分
|
|
// 恢复上次已填色的部分
|
|
|
initTask() {
|
|
initTask() {
|
|
|
let taskLisk = this.fillerData.taskList;
|
|
let taskLisk = this.fillerData.taskList;
|
|
|
|
|
|
|
|
- const width = this.fillerData.width
|
|
|
|
|
- const height = this.fillerData.height
|
|
|
|
|
|
|
+ const width = this.fillerData.width;
|
|
|
|
|
+ const height = this.fillerData.height;
|
|
|
|
|
|
|
|
for (let task of taskLisk) {
|
|
for (let task of taskLisk) {
|
|
|
let area = this.fillerData.data.areaHash.get(task);
|
|
let area = this.fillerData.data.areaHash.get(task);
|
|
|
if (area) {
|
|
if (area) {
|
|
|
- fillRectangle(this.positionArray, 0, area.rect.x, area.rect.y, area.rect.width, area.rect.height)
|
|
|
|
|
- fillRectangle(this.texCoordArray, 0, area.rect.x / width, area.rect.y / height, area.rect.width / width, area.rect.height / height)
|
|
|
|
|
- this.fillPoint(this.centerArray, 0, area.center.x, area.center.y, 6)
|
|
|
|
|
-
|
|
|
|
|
- var color = new Color(area.id)
|
|
|
|
|
- color.fillFloatArray(this.areaIdArray, 0, 6)
|
|
|
|
|
-
|
|
|
|
|
- var maxRadius = coverRadius(area.rect, area.center.x, area.center.y)
|
|
|
|
|
|
|
+ fillRectangle(
|
|
|
|
|
+ this.positionArray,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ area.rect.x,
|
|
|
|
|
+ area.rect.y,
|
|
|
|
|
+ area.rect.width,
|
|
|
|
|
+ area.rect.height,
|
|
|
|
|
+ );
|
|
|
|
|
+ fillRectangle(
|
|
|
|
|
+ this.texCoordArray,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ area.rect.x / width,
|
|
|
|
|
+ area.rect.y / height,
|
|
|
|
|
+ area.rect.width / width,
|
|
|
|
|
+ area.rect.height / height,
|
|
|
|
|
+ );
|
|
|
|
|
+ this.fillPoint(this.centerArray, 0, area.center.x, area.center.y, 6);
|
|
|
|
|
+
|
|
|
|
|
+ var color = new Color(area.id);
|
|
|
|
|
+ color.fillFloatArray(this.areaIdArray, 0, 6);
|
|
|
|
|
+
|
|
|
|
|
+ var maxRadius = coverRadius(area.rect, area.center.x, area.center.y);
|
|
|
// console.log('rect=', area.rect, maxRadius, area.center.x, area.center.y);
|
|
// console.log('rect=', area.rect, maxRadius, area.center.x, area.center.y);
|
|
|
|
|
|
|
|
- this.fillNumber(this.progressArray, 0, 1, 6)
|
|
|
|
|
- this.fillNumber(this.maxRadiusArray, 0, maxRadius, 6)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ this.fillNumber(this.progressArray, 0, 1, 6);
|
|
|
|
|
+ this.fillNumber(this.maxRadiusArray, 0, maxRadius, 6);
|
|
|
|
|
|
|
|
- const gl = this.scene.gl
|
|
|
|
|
|
|
+ const gl = this.scene.gl;
|
|
|
|
|
|
|
|
- gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer)
|
|
|
|
|
- gl.bufferData(gl.ARRAY_BUFFER, this.positionArray, gl.STATIC_DRAW)
|
|
|
|
|
|
|
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
|
|
|
|
|
+ gl.bufferData(gl.ARRAY_BUFFER, this.positionArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
- gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer)
|
|
|
|
|
- gl.bufferData(gl.ARRAY_BUFFER, this.texCoordArray, gl.STATIC_DRAW)
|
|
|
|
|
|
|
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer);
|
|
|
|
|
+ gl.bufferData(gl.ARRAY_BUFFER, this.texCoordArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.areaIdBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.areaIdBuffer);
|
|
|
- gl.bufferData(gl.ARRAY_BUFFER, this.areaIdArray, gl.STATIC_DRAW)
|
|
|
|
|
|
|
+ gl.bufferData(gl.ARRAY_BUFFER, this.areaIdArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.centerBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.centerBuffer);
|
|
|
- gl.bufferData(gl.ARRAY_BUFFER, this.centerArray, gl.STATIC_DRAW)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ gl.bufferData(gl.ARRAY_BUFFER, this.centerArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.progressBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.progressBuffer);
|
|
|
- gl.bufferData(gl.ARRAY_BUFFER, this.progressArray, gl.STATIC_DRAW)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ gl.bufferData(gl.ARRAY_BUFFER, this.progressArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.maxRadiusBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.maxRadiusBuffer);
|
|
|
- gl.bufferData(gl.ARRAY_BUFFER, this.maxRadiusArray, gl.STATIC_DRAW)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- this.draw(6)
|
|
|
|
|
|
|
+ gl.bufferData(gl.ARRAY_BUFFER, this.maxRadiusArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
|
|
+ this.draw(6);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|