1 | import { Buffer } from "../geometry/Buffer.mjs";
|
2 | import { Geometry } from "../geometry/Geometry.mjs";
|
3 | class QuadUv extends Geometry {
|
4 | constructor() {
|
5 | super(), this.vertices = new Float32Array([
|
6 | -1,
|
7 | -1,
|
8 | 1,
|
9 | -1,
|
10 | 1,
|
11 | 1,
|
12 | -1,
|
13 | 1
|
14 | ]), this.uvs = new Float32Array([
|
15 | 0,
|
16 | 0,
|
17 | 1,
|
18 | 0,
|
19 | 1,
|
20 | 1,
|
21 | 0,
|
22 | 1
|
23 | ]), this.vertexBuffer = new Buffer(this.vertices), this.uvBuffer = new Buffer(this.uvs), this.addAttribute("aVertexPosition", this.vertexBuffer).addAttribute("aTextureCoord", this.uvBuffer).addIndex([0, 1, 2, 0, 2, 3]);
|
24 | }
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | map(targetTextureFrame, destinationFrame) {
|
32 | let x = 0, y = 0;
|
33 | return this.uvs[0] = x, this.uvs[1] = y, this.uvs[2] = x + destinationFrame.width / targetTextureFrame.width, this.uvs[3] = y, this.uvs[4] = x + destinationFrame.width / targetTextureFrame.width, this.uvs[5] = y + destinationFrame.height / targetTextureFrame.height, this.uvs[6] = x, this.uvs[7] = y + destinationFrame.height / targetTextureFrame.height, x = destinationFrame.x, y = destinationFrame.y, this.vertices[0] = x, this.vertices[1] = y, this.vertices[2] = x + destinationFrame.width, this.vertices[3] = y, this.vertices[4] = x + destinationFrame.width, this.vertices[5] = y + destinationFrame.height, this.vertices[6] = x, this.vertices[7] = y + destinationFrame.height, this.invalidate(), this;
|
34 | }
|
35 | |
36 |
|
37 |
|
38 |
|
39 | invalidate() {
|
40 | return this.vertexBuffer._updateID++, this.uvBuffer._updateID++, this;
|
41 | }
|
42 | }
|
43 | export {
|
44 | QuadUv
|
45 | };
|
46 |
|