|
@@ -1,16 +1,11 @@
|
|
|
-import { fillRectangle, rectangle, rectangleArray } from "../base/2d"
|
|
|
|
|
-import { LayerAB, Scene } from "../base/Scene"
|
|
|
|
|
-import { createProgram, createShader } from "../base/utils"
|
|
|
|
|
|
|
+import { fillRectangle, rectangle, rectangleArray } from "../base/2d";
|
|
|
|
|
+import { LayerAB, Scene } from "../base/Scene";
|
|
|
|
|
+import { createProgram, createShader } from "../base/utils";
|
|
|
import { AreaGroup, Center, Color, createTexture, TexImage } from "./common";
|
|
import { AreaGroup, Center, Color, createTexture, TexImage } from "./common";
|
|
|
import { FillerData, FillerDataListener } from "./FillerData";
|
|
import { FillerData, FillerDataListener } from "./FillerData";
|
|
|
import { Mask } from "./Mask";
|
|
import { Mask } from "./Mask";
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
export class HintLayer extends LayerAB implements FillerDataListener {
|
|
export class HintLayer extends LayerAB implements FillerDataListener {
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
private vertexShaderCode = /*glsl*/ `
|
|
private vertexShaderCode = /*glsl*/ `
|
|
|
attribute vec2 a_position;
|
|
attribute vec2 a_position;
|
|
|
attribute vec2 a_texCoord;
|
|
attribute vec2 a_texCoord;
|
|
@@ -78,106 +73,107 @@ export class HintLayer extends LayerAB implements FillerDataListener {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- `
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- program: WebGLProgram
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- aPositionLoc: number
|
|
|
|
|
- aTexcoordLoc: number
|
|
|
|
|
- uMatrixLoc: WebGLUniformLocation
|
|
|
|
|
- uScaleLoc: WebGLUniformLocation
|
|
|
|
|
- uPixelSizeLoc: WebGLUniformLocation
|
|
|
|
|
- uHintLoc: WebGLUniformLocation
|
|
|
|
|
- uMaskLoc: WebGLUniformLocation
|
|
|
|
|
- uColorDarkLoc: WebGLUniformLocation
|
|
|
|
|
- uColorLightLoc: WebGLUniformLocation
|
|
|
|
|
|
|
+ `;
|
|
|
|
|
|
|
|
- vertexBuffer: WebGLBuffer
|
|
|
|
|
- texcoordBuffer: WebGLBuffer
|
|
|
|
|
|
|
+ program: WebGLProgram;
|
|
|
|
|
|
|
|
- vertexArray: Float32Array
|
|
|
|
|
- texCoordArray: Float32Array
|
|
|
|
|
|
|
+ aPositionLoc: number;
|
|
|
|
|
+ aTexcoordLoc: number;
|
|
|
|
|
+ uMatrixLoc: WebGLUniformLocation;
|
|
|
|
|
+ uScaleLoc: WebGLUniformLocation;
|
|
|
|
|
+ uPixelSizeLoc: WebGLUniformLocation;
|
|
|
|
|
+ uHintLoc: WebGLUniformLocation;
|
|
|
|
|
+ uMaskLoc: WebGLUniformLocation;
|
|
|
|
|
+ uColorDarkLoc: WebGLUniformLocation;
|
|
|
|
|
+ uColorLightLoc: WebGLUniformLocation;
|
|
|
|
|
|
|
|
|
|
+ vertexBuffer: WebGLBuffer;
|
|
|
|
|
+ texcoordBuffer: WebGLBuffer;
|
|
|
|
|
|
|
|
- mask: Mask
|
|
|
|
|
- hintTexture: WebGLTexture
|
|
|
|
|
|
|
+ vertexArray: Float32Array;
|
|
|
|
|
+ texCoordArray: Float32Array;
|
|
|
|
|
|
|
|
- colorDarkArray = new Float32Array(4)
|
|
|
|
|
- colorLightArray = new Float32Array(4)
|
|
|
|
|
|
|
+ mask: Mask;
|
|
|
|
|
+ hintTexture: WebGLTexture;
|
|
|
|
|
|
|
|
|
|
+ colorDarkArray = new Float32Array(4);
|
|
|
|
|
+ colorLightArray = new Float32Array(4);
|
|
|
|
|
|
|
|
override dispose() {
|
|
override dispose() {
|
|
|
- this.mask.dispose()
|
|
|
|
|
- let gl = this.scene.gl
|
|
|
|
|
- gl.deleteProgram(this.program)
|
|
|
|
|
- gl.deleteBuffer(this.vertexBuffer)
|
|
|
|
|
- gl.deleteBuffer(this.texcoordBuffer)
|
|
|
|
|
- gl.deleteTexture(this.hintTexture)
|
|
|
|
|
|
|
+ this.mask.dispose();
|
|
|
|
|
+ let gl = this.scene.gl;
|
|
|
|
|
+ gl.deleteProgram(this.program);
|
|
|
|
|
+ gl.deleteBuffer(this.vertexBuffer);
|
|
|
|
|
+ gl.deleteBuffer(this.texcoordBuffer);
|
|
|
|
|
+ gl.deleteTexture(this.hintTexture);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
constructor(
|
|
constructor(
|
|
|
public readonly scene: Scene,
|
|
public readonly scene: Scene,
|
|
|
private fillerData: FillerData,
|
|
private fillerData: FillerData,
|
|
|
) {
|
|
) {
|
|
|
- super()
|
|
|
|
|
|
|
+ super();
|
|
|
|
|
|
|
|
- this.fillerData.addListener(this)
|
|
|
|
|
|
|
+ this.fillerData.addListener(this);
|
|
|
|
|
|
|
|
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.uMatrixLoc = gl.getUniformLocation(this.program, "u_matrix")!
|
|
|
|
|
-
|
|
|
|
|
- this.uScaleLoc = gl.getUniformLocation(this.program, "u_scale")!
|
|
|
|
|
- this.uPixelSizeLoc = gl.getUniformLocation(this.program, "u_pixelSize")!
|
|
|
|
|
- this.uHintLoc = gl.getUniformLocation(this.program, "u_hint")!
|
|
|
|
|
- this.uMaskLoc = gl.getUniformLocation(this.program, "u_mask")!
|
|
|
|
|
- this.uColorDarkLoc = gl.getUniformLocation(this.program, "u_colorDark")!
|
|
|
|
|
- this.uColorLightLoc = gl.getUniformLocation(this.program, "u_colorLight")!
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- this.vertexArray = rectangleArray(0, 0, fillerData.width, fillerData.height)
|
|
|
|
|
- this.texCoordArray = rectangleArray(0, 0, 1, 1)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ createShader(gl, gl.FRAGMENT_SHADER, this.fragmentShaderCode)!,
|
|
|
|
|
+ )!;
|
|
|
|
|
+
|
|
|
|
|
+ this.aPositionLoc = gl.getAttribLocation(this.program, "a_position");
|
|
|
|
|
+ this.aTexcoordLoc = gl.getAttribLocation(this.program, "a_texCoord");
|
|
|
|
|
+ this.uMatrixLoc = gl.getUniformLocation(this.program, "u_matrix")!;
|
|
|
|
|
+
|
|
|
|
|
+ this.uScaleLoc = gl.getUniformLocation(this.program, "u_scale")!;
|
|
|
|
|
+ this.uPixelSizeLoc = gl.getUniformLocation(this.program, "u_pixelSize")!;
|
|
|
|
|
+ this.uHintLoc = gl.getUniformLocation(this.program, "u_hint")!;
|
|
|
|
|
+ this.uMaskLoc = gl.getUniformLocation(this.program, "u_mask")!;
|
|
|
|
|
+ this.uColorDarkLoc = gl.getUniformLocation(this.program, "u_colorDark")!;
|
|
|
|
|
+ this.uColorLightLoc = gl.getUniformLocation(this.program, "u_colorLight")!;
|
|
|
|
|
+
|
|
|
|
|
+ this.vertexArray = rectangleArray(
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ fillerData.width,
|
|
|
|
|
+ fillerData.height,
|
|
|
|
|
+ );
|
|
|
|
|
+ this.texCoordArray = rectangleArray(0, 0, 1, 1);
|
|
|
|
|
|
|
|
this.vertexBuffer = gl.createBuffer()!;
|
|
this.vertexBuffer = gl.createBuffer()!;
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, this.vertexArray, gl.STATIC_DRAW);
|
|
gl.bufferData(gl.ARRAY_BUFFER, this.vertexArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
this.texcoordBuffer = gl.createBuffer()!;
|
|
this.texcoordBuffer = gl.createBuffer()!;
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, this.texCoordArray, gl.STATIC_DRAW);
|
|
gl.bufferData(gl.ARRAY_BUFFER, this.texCoordArray, gl.STATIC_DRAW);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- this.mask = new Mask(gl, fillerData)
|
|
|
|
|
- this.hintTexture = this.createHintTexture(gl, fillerData.width, fillerData.height)
|
|
|
|
|
|
|
+ this.mask = new Mask(gl, fillerData);
|
|
|
|
|
+ this.hintTexture = this.createHintTexture(
|
|
|
|
|
+ gl,
|
|
|
|
|
+ fillerData.width,
|
|
|
|
|
+ fillerData.height,
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
if (this.fillerData.currentGroup) {
|
|
if (this.fillerData.currentGroup) {
|
|
|
- this.setGroup(this.fillerData.currentGroup)
|
|
|
|
|
|
|
+ this.setGroup(this.fillerData.currentGroup);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- createHintTexture(gl: WebGL2RenderingContext, width: number, height: number): WebGLTexture {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ createHintTexture(
|
|
|
|
|
+ gl: WebGL2RenderingContext,
|
|
|
|
|
+ width: number,
|
|
|
|
|
+ height: number,
|
|
|
|
|
+ ): WebGLTexture {
|
|
|
let texture = gl.createTexture()!;
|
|
let texture = gl.createTexture()!;
|
|
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
|
|
|
|
|
|
const size = 10;
|
|
const size = 10;
|
|
|
- const nx = Math.floor(width / size)
|
|
|
|
|
- const ny = Math.floor(height / size)
|
|
|
|
|
|
|
+ const nx = Math.floor(width / size);
|
|
|
|
|
+ const ny = Math.floor(height / size);
|
|
|
const pixels = new Uint8Array(nx * ny);
|
|
const pixels = new Uint8Array(nx * ny);
|
|
|
for (var y = 0; y < ny; y++) {
|
|
for (var y = 0; y < ny; y++) {
|
|
|
let k = y % 2 == 0;
|
|
let k = y % 2 == 0;
|
|
@@ -189,34 +185,44 @@ export class HintLayer extends LayerAB implements FillerDataListener {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
|
|
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
|
|
|
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, nx, ny, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, pixels);
|
|
|
|
|
|
|
+ gl.texImage2D(
|
|
|
|
|
+ gl.TEXTURE_2D,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ gl.LUMINANCE,
|
|
|
|
|
+ nx,
|
|
|
|
|
+ ny,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ gl.LUMINANCE,
|
|
|
|
|
+ gl.UNSIGNED_BYTE,
|
|
|
|
|
+ pixels,
|
|
|
|
|
+ );
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
|
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);
|
|
|
|
|
|
|
|
- return texture
|
|
|
|
|
|
|
+ return texture;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** replay 阶段设为 false,隐藏 hint 覆盖层 */
|
|
|
|
|
+ public enabled: boolean = true;
|
|
|
|
|
|
|
|
setGroup(group: AreaGroup) {
|
|
setGroup(group: AreaGroup) {
|
|
|
for (var i = 0; i < group.areas.length; i++) {
|
|
for (var i = 0; i < group.areas.length; i++) {
|
|
|
- this.mask.addArea(group.areas[i])
|
|
|
|
|
|
|
+ this.mask.addArea(group.areas[i]);
|
|
|
}
|
|
}
|
|
|
- this.mask.flush(true)
|
|
|
|
|
- this.scene.invalidate()
|
|
|
|
|
|
|
+ this.mask.flush(true);
|
|
|
|
|
+ this.scene.invalidate();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
onGroupChange(group: AreaGroup | null): void {
|
|
onGroupChange(group: AreaGroup | null): void {
|
|
|
- console.log('onGroupChange', group);
|
|
|
|
|
|
|
+ console.log("onGroupChange", group);
|
|
|
|
|
|
|
|
- if (group != null) this.setGroup(group)
|
|
|
|
|
|
|
+ if (group != null) this.setGroup(group);
|
|
|
|
|
|
|
|
this.fillerData.callback?.onSwitchGroup();
|
|
this.fillerData.callback?.onSwitchGroup();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
// 注释掉,不允许随意点击自动切换group
|
|
// 注释掉,不允许随意点击自动切换group
|
|
|
// override tap(cx: number, cy: number, sx: number, sy: number): void {
|
|
// override tap(cx: number, cy: number, sx: number, sy: number): void {
|
|
|
// let area = this.fillerData.getArea(cx, cy, 40, this.fillerData.data.areaHash)
|
|
// let area = this.fillerData.getArea(cx, cy, 40, this.fillerData.data.areaHash)
|
|
@@ -227,56 +233,47 @@ export class HintLayer extends LayerAB implements FillerDataListener {
|
|
|
// }
|
|
// }
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
override draw() {
|
|
override draw() {
|
|
|
|
|
+ if (!this.enabled) return;
|
|
|
|
|
|
|
|
const gl = this.scene.gl;
|
|
const gl = this.scene.gl;
|
|
|
gl.useProgram(this.program);
|
|
gl.useProgram(this.program);
|
|
|
|
|
|
|
|
gl.enableVertexAttribArray(this.aPositionLoc);
|
|
gl.enableVertexAttribArray(this.aPositionLoc);
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
|
- gl.vertexAttribPointer(this.aPositionLoc, 2, gl.FLOAT, false, 0, 0)
|
|
|
|
|
|
|
+ gl.vertexAttribPointer(this.aPositionLoc, 2, gl.FLOAT, false, 0, 0);
|
|
|
|
|
|
|
|
gl.enableVertexAttribArray(this.aTexcoordLoc);
|
|
gl.enableVertexAttribArray(this.aTexcoordLoc);
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
|
|
|
- gl.vertexAttribPointer(this.aTexcoordLoc, 2, gl.FLOAT, false, 0, 0)
|
|
|
|
|
-
|
|
|
|
|
- gl.uniformMatrix4fv(this.uMatrixLoc, false, this.scene.drawMatrix)
|
|
|
|
|
- gl.uniform1f(this.uScaleLoc, this.scene.userMat[0])
|
|
|
|
|
- gl.uniform2f(this.uPixelSizeLoc, 1. / this.mask.width, 1. / this.mask.height)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- new Color(this.fillerData.config.hintColorDark).fillFloatArray(this.colorDarkArray, 0)
|
|
|
|
|
- new Color(this.fillerData.config.hintColorLight).fillFloatArray(this.colorLightArray, 0)
|
|
|
|
|
- gl.uniform4fv(this.uColorDarkLoc, this.colorDarkArray)
|
|
|
|
|
- gl.uniform4fv(this.uColorLightLoc, this.colorLightArray)
|
|
|
|
|
-
|
|
|
|
|
- gl.uniform1i(this.uHintLoc, 0); // texture unit 0
|
|
|
|
|
- gl.uniform1i(this.uMaskLoc, 1); // texture unit 1
|
|
|
|
|
-
|
|
|
|
|
- gl.activeTexture(gl.TEXTURE0)
|
|
|
|
|
- gl.bindTexture(gl.TEXTURE_2D, this.hintTexture)
|
|
|
|
|
- gl.activeTexture(gl.TEXTURE1)
|
|
|
|
|
- gl.bindTexture(gl.TEXTURE_2D, this.mask.texture)
|
|
|
|
|
|
|
+ gl.vertexAttribPointer(this.aTexcoordLoc, 2, gl.FLOAT, false, 0, 0);
|
|
|
|
|
+
|
|
|
|
|
+ gl.uniformMatrix4fv(this.uMatrixLoc, false, this.scene.drawMatrix);
|
|
|
|
|
+ gl.uniform1f(this.uScaleLoc, this.scene.userMat[0]);
|
|
|
|
|
+ gl.uniform2f(this.uPixelSizeLoc, 1 / this.mask.width, 1 / this.mask.height);
|
|
|
|
|
+
|
|
|
|
|
+ new Color(this.fillerData.config.hintColorDark).fillFloatArray(
|
|
|
|
|
+ this.colorDarkArray,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ );
|
|
|
|
|
+ new Color(this.fillerData.config.hintColorLight).fillFloatArray(
|
|
|
|
|
+ this.colorLightArray,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ );
|
|
|
|
|
+ gl.uniform4fv(this.uColorDarkLoc, this.colorDarkArray);
|
|
|
|
|
+ gl.uniform4fv(this.uColorLightLoc, this.colorLightArray);
|
|
|
|
|
+
|
|
|
|
|
+ gl.uniform1i(this.uHintLoc, 0); // texture unit 0
|
|
|
|
|
+ gl.uniform1i(this.uMaskLoc, 1); // texture unit 1
|
|
|
|
|
+
|
|
|
|
|
+ gl.activeTexture(gl.TEXTURE0);
|
|
|
|
|
+ gl.bindTexture(gl.TEXTURE_2D, this.hintTexture);
|
|
|
|
|
+ gl.activeTexture(gl.TEXTURE1);
|
|
|
|
|
+ gl.bindTexture(gl.TEXTURE_2D, this.mask.texture);
|
|
|
|
|
|
|
|
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
toString(): string {
|
|
toString(): string {
|
|
|
- return `HintLayer()`
|
|
|
|
|
|
|
+ return `HintLayer()`;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|