@pirireis/webglobeplugins 0.13.0-alpha → 0.15.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Math/arc-cdf-points.js +20 -0
- package/Math/arc-generate-points copy.js +1 -0
- package/Math/arc.js +21 -8
- package/Math/circle.js +35 -16
- package/Math/templete-shapes/grid-visually-equal.js +66 -0
- package/altitude-locator/plugin.js +3 -2
- package/bearing-line/plugin.js +1 -2
- package/circle-line-chain/plugin.js +4 -7
- package/compass-rose/compass-rose-padding-flat.js +12 -0
- package/package.json +1 -1
- package/programs/line-on-globe/degree-padding-around-circle-3d.js +1 -1
- package/programs/line-on-globe/linestrip/linestrip.js +6 -4
- package/programs/line-on-globe/naive-accurate-flexible.js +23 -16
- package/programs/picking/pickable-renderer.js +1 -2
- package/programs/rings/partial-ring/piece-of-pie copy.js +286 -0
- package/programs/rings/partial-ring/piece-of-pie.js +26 -13
- package/programs/totems/camerauniformblock.js +1 -1
- package/programs/totems/index.js +1 -1
- package/range-tools-on-terrain/bearing-line/adapters.js +111 -0
- package/range-tools-on-terrain/bearing-line/plugin.js +360 -0
- package/range-tools-on-terrain/circle-line-chain/adapters.js +83 -0
- package/range-tools-on-terrain/circle-line-chain/chain-list-map.js +351 -0
- package/range-tools-on-terrain/circle-line-chain/plugin.js +388 -0
- package/range-tools-on-terrain/circle-line-chain/types.js +1 -0
- package/range-tools-on-terrain/range-ring/adapters.js +25 -0
- package/range-tools-on-terrain/range-ring/plugin.js +31 -0
- package/range-tools-on-terrain/range-ring/types.js +1 -0
- package/rangerings/plugin.js +7 -11
- package/semiplugins/lightweight/line-plugin.js +195 -0
- package/semiplugins/lightweight/piece-of-pie-plugin.js +175 -0
- package/semiplugins/shape-on-terrain/arc-plugin.js +368 -0
- package/{shape-on-terrain/circle/plugin.js → semiplugins/shape-on-terrain/circle-plugin.js} +67 -38
- package/semiplugins/shape-on-terrain/derived/padding-plugin.js +101 -0
- package/semiplugins/shape-on-terrain/one-degree-padding.js +85 -0
- package/semiplugins/type.js +1 -0
- package/types.js +0 -11
- package/util/account/create-buffermap-orchastration.js +39 -0
- package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +14 -3
- package/util/check/typecheck.js +15 -1
- package/util/geometry/index.js +3 -2
- package/util/gl-util/buffer/attribute-loader.js +2 -5
- package/util/gl-util/draw-options/methods.js +4 -5
- package/util/webglobjectbuilders.js +5 -10
- package/write-text/context-text3.js +17 -0
- package/write-text/context-text3old.js +152 -0
- package/programs/line-on-globe/circle-accurate.js +0 -176
- package/programs/line-on-globe/circle.js +0 -166
- package/programs/line-on-globe/to-the-surface.js +0 -111
- package/programs/totems/canvas-webglobe-info1.js +0 -106
- package/shape-on-terrain/arc/naive/plugin.js +0 -250
- package/util/check/get.js +0 -14
- package/util/gl-util/draw-options/types.js +0 -15
- package/util/webglobjectbuilders1.js +0 -219
- /package/{util/gl-util/buffer/types.js → programs/line-on-globe/paddings/paddings.js} +0 -0
- /package/{shape-on-terrain/type.js → range-tools-on-terrain/bearing-line/types.js} +0 -0
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import { LineStripProgramCache } from "../../../programs/line-on-globe/linestrip/linestrip";
|
|
2
|
-
import { createBufferAndReadInfo } from '../../../util/gl-util/buffer/attribute-loader';
|
|
3
|
-
// import { populateFloat32Array } from "../../../util/jshelpers/data-filler";
|
|
4
|
-
import { BufferManager, BufferOrchestrator } from "../../../util/account/single-attribute-buffer-management/index";
|
|
5
|
-
import { globe3Dcoordinates, globe2Dcoordinates, RADIANS } from "../../../Math/methods";
|
|
6
|
-
import { generateArcPoints } from "../../../Math/arc-cdf-points";
|
|
7
|
-
import { StaticDynamicState, StaticDynamicStrategy } from "../../../util/build-strategy/static-dynamic";
|
|
8
|
-
import * as vec3 from "../../../Math/vec3";
|
|
9
|
-
import * as arc from "../../../Math/arc";
|
|
10
|
-
import { CameraUniformBlockTotemCache } from "../../../programs/totems/camerauniformblock";
|
|
11
|
-
import { WORLD_RADIUS_3D } from "../../../Math/constants";
|
|
12
|
-
const VERTEX_COUNT = 70;
|
|
13
|
-
const INITAL_CAPACITY = 10;
|
|
14
|
-
const _attractionPoint = [0, 0, 0];
|
|
15
|
-
const _start = [0, 0, 0];
|
|
16
|
-
const _end = [0, 0, 0];
|
|
17
|
-
const _0arc = arc.create([1, 0, 0], [0, 1, 0]); // zero arc for intersection tests
|
|
18
|
-
const _colorArray = new Float32Array(4); // For color buffer
|
|
19
|
-
export class NaiveLineOnTerrainPlugin {
|
|
20
|
-
id;
|
|
21
|
-
program = null;
|
|
22
|
-
bufferManagerMap = null;
|
|
23
|
-
_bufferOrchestrator = new BufferOrchestrator({ capacity: INITAL_CAPACITY });
|
|
24
|
-
_opacity = 1;
|
|
25
|
-
_arcUBOHandler = null;
|
|
26
|
-
_vao = null;
|
|
27
|
-
globe = null;
|
|
28
|
-
gl = null;
|
|
29
|
-
_arcMap;
|
|
30
|
-
_cameraUniformBlock = null;
|
|
31
|
-
_staticDynamicStrategy = null;
|
|
32
|
-
_styleOptions = {
|
|
33
|
-
variativeColorsOn: false,
|
|
34
|
-
defaultColor: [0.1, 0.1, 1, 1], // Default color in RGBA format
|
|
35
|
-
defaultHeightFromGroundIn3D: 30.0 // Default height from ground in
|
|
36
|
-
};
|
|
37
|
-
constructor(id, drawStyleOptions = null) {
|
|
38
|
-
this.id = id;
|
|
39
|
-
this._arcMap = new Map();
|
|
40
|
-
if (drawStyleOptions) {
|
|
41
|
-
this._styleOptions = drawStyleOptions;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
insertArcFromLongLat(key, startPoint, endPoint, height = null) {
|
|
45
|
-
if (this._arcMap.has(key)) {
|
|
46
|
-
this._arcMap.delete(key);
|
|
47
|
-
}
|
|
48
|
-
vec3.fromLongLatToUnitVector(_start, [startPoint.long * RADIANS, startPoint.lat * RADIANS]);
|
|
49
|
-
vec3.fromLongLatToUnitVector(_end, [endPoint.long * RADIANS, endPoint.lat * RADIANS]);
|
|
50
|
-
const _arc = arc.create(_start, _end);
|
|
51
|
-
this._arcMap.set(key, [_arc, height]);
|
|
52
|
-
// TODO: insert into buffer if NOT DYNAMIC state
|
|
53
|
-
if (this._staticDynamicStrategy?.getState() !== StaticDynamicState.DYNAMIC) {
|
|
54
|
-
this.__buildStaticArcs([key]);
|
|
55
|
-
}
|
|
56
|
-
this.globe.DrawRender();
|
|
57
|
-
}
|
|
58
|
-
deleteArcs(keys) {
|
|
59
|
-
for (const key of keys) {
|
|
60
|
-
if (this._arcMap.has(key)) {
|
|
61
|
-
this._arcMap.delete(key);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// DELETE FROM BUFFER IF not DYNAMIC state
|
|
65
|
-
this.globe.DrawRender();
|
|
66
|
-
}
|
|
67
|
-
init(globe, gl) {
|
|
68
|
-
this.globe = globe;
|
|
69
|
-
this.gl = gl;
|
|
70
|
-
this.program = LineStripProgramCache.get(globe);
|
|
71
|
-
this._staticDynamicStrategy = new StaticDynamicStrategy(globe, 8); // Initialize static-dynamic strategy with a transition level of 8
|
|
72
|
-
const g2D = globe2Dcoordinates(globe);
|
|
73
|
-
this._cameraUniformBlock = CameraUniformBlockTotemCache.get(globe);
|
|
74
|
-
this._staticDynamicStrategy = new StaticDynamicStrategy(globe, 8); // Initialize static-dynamic strategy with a transition level of 8
|
|
75
|
-
this.bufferManagerMap = new Map([
|
|
76
|
-
["position3d", {
|
|
77
|
-
bufferManager: new BufferManager(gl, 3 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
|
|
78
|
-
adaptor: (item) => {
|
|
79
|
-
const { longLatArr, height = this._styleOptions.defaultHeightFromGroundIn3D } = item;
|
|
80
|
-
const result = globe3Dcoordinates(globe, height)(longLatArr, { paddingCount: 1 });
|
|
81
|
-
// console.log("result", result);
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
}],
|
|
85
|
-
["position2d", {
|
|
86
|
-
bufferManager: new BufferManager(gl, 2 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
|
|
87
|
-
adaptor: (item) => {
|
|
88
|
-
const { longLatArr } = item;
|
|
89
|
-
return g2D(longLatArr, { paddingCount: 1 });
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
],
|
|
93
|
-
]);
|
|
94
|
-
if (this._styleOptions.variativeColorsOn) {
|
|
95
|
-
this.bufferManagerMap.set("color", {
|
|
96
|
-
bufferManager: new BufferManager(gl, 4, { initialCapacity: INITAL_CAPACITY }),
|
|
97
|
-
adaptor: (item) => {
|
|
98
|
-
const { radius } = item;
|
|
99
|
-
// Calculate color based on radius
|
|
100
|
-
if (item.color) {
|
|
101
|
-
_colorArray.set(item.color);
|
|
102
|
-
return _colorArray;
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
return this._styleOptions.defaultColor;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
this._bufferOrchestrator = new BufferOrchestrator();
|
|
111
|
-
this._arcUBOHandler = this.program.createUBO();
|
|
112
|
-
this._arcUBOHandler.update(new Map([
|
|
113
|
-
["u_color", new Float32Array([1, 0, 0, 1])],
|
|
114
|
-
]));
|
|
115
|
-
this._vao = this.program.createVAO(createBufferAndReadInfo(this.bufferManagerMap.get("position3d")?.bufferManager.buffer), createBufferAndReadInfo(this.bufferManagerMap.get("position2d")?.bufferManager.buffer), null);
|
|
116
|
-
}
|
|
117
|
-
draw3D() {
|
|
118
|
-
// Drawing logic here
|
|
119
|
-
if (!this.globe || !this.gl) {
|
|
120
|
-
console.warn("Globe or WebGL context is not initialized.");
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
this._staticDynamicStrategy?.updateState();
|
|
124
|
-
this._buildArcs(); // can be async
|
|
125
|
-
const { gl, program, _bufferOrchestrator, _vao, _arcUBOHandler, } = this;
|
|
126
|
-
if (!gl || !program || !_bufferOrchestrator || !_vao || !_arcUBOHandler) {
|
|
127
|
-
console.warn("WebGL context, program, or buffer orchestrator is not initialized.");
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
gl.disable(gl.DEPTH_TEST);
|
|
131
|
-
const drawOptions = {
|
|
132
|
-
drawRange: {
|
|
133
|
-
first: 0,
|
|
134
|
-
count: _bufferOrchestrator.length * (VERTEX_COUNT + 1)
|
|
135
|
-
},
|
|
136
|
-
indexes: null
|
|
137
|
-
};
|
|
138
|
-
program.draw(_vao, drawOptions, this._opacity, _arcUBOHandler);
|
|
139
|
-
gl.enable(gl.DEPTH_TEST);
|
|
140
|
-
}
|
|
141
|
-
_buildArcs() {
|
|
142
|
-
const state = this._staticDynamicStrategy?.getState();
|
|
143
|
-
if (state === StaticDynamicState.TO_STATIC) {
|
|
144
|
-
this.__buildStaticArcs();
|
|
145
|
-
}
|
|
146
|
-
else if (state === StaticDynamicState.DYNAMIC) {
|
|
147
|
-
this.__buildArcs();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
__buildStaticArcs(keys = []) {
|
|
151
|
-
const { globe, _arcMap, _cameraUniformBlock, bufferManagerMap, _bufferOrchestrator } = this;
|
|
152
|
-
if (!globe || !_cameraUniformBlock || !bufferManagerMap || !_bufferOrchestrator) {
|
|
153
|
-
console.warn("Globe or camera uniform block is not initialized.");
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const longLat = [0, 0];
|
|
157
|
-
const _attractionStrength = 0;
|
|
158
|
-
const longLatArr = new Float32Array(2 * VERTEX_COUNT);
|
|
159
|
-
const data = [{
|
|
160
|
-
key: "staticArcs",
|
|
161
|
-
longLatArr: longLatArr,
|
|
162
|
-
height: null
|
|
163
|
-
}];
|
|
164
|
-
if (keys.length == 0) {
|
|
165
|
-
for (const [key, [arcInstance, height]] of _arcMap) {
|
|
166
|
-
arc.copy(_0arc, arcInstance);
|
|
167
|
-
const generatedPoints = generateArcPoints(_0arc.p0, _0arc.p1, _0arc.normal, _attractionPoint, VERTEX_COUNT, _attractionStrength);
|
|
168
|
-
for (let i = 0; i < generatedPoints.length; i++) {
|
|
169
|
-
const point = generatedPoints[i];
|
|
170
|
-
vec3.fromUnitVectorToLongLat(longLat, point);
|
|
171
|
-
longLatArr.set([longLat[0] / RADIANS, longLat[1] / RADIANS], i * 2);
|
|
172
|
-
}
|
|
173
|
-
data[0].key = key;
|
|
174
|
-
data[0].height = height;
|
|
175
|
-
this._bufferOrchestrator.insertBulk(data, bufferManagerMap);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
for (let key of keys) {
|
|
180
|
-
if (!_arcMap.has(key)) {
|
|
181
|
-
console.warn(`Arc with key ${key} not found in arcMap.`);
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
const [arcInstance, height] = _arcMap.get(key);
|
|
185
|
-
arc.copy(_0arc, arcInstance);
|
|
186
|
-
const generatedPoints = generateArcPoints(_0arc.p0, _0arc.p1, _0arc.normal, _attractionPoint, VERTEX_COUNT, _attractionStrength);
|
|
187
|
-
for (let i = 0; i < generatedPoints.length; i++) {
|
|
188
|
-
const point = generatedPoints[i];
|
|
189
|
-
vec3.fromUnitVectorToLongLat(longLat, point);
|
|
190
|
-
longLatArr.set([longLat[0] / RADIANS, longLat[1] / RADIANS], i * 2);
|
|
191
|
-
}
|
|
192
|
-
data[0].key = key;
|
|
193
|
-
data[0].height = height;
|
|
194
|
-
this._bufferOrchestrator.insertBulk(data, bufferManagerMap);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
__buildArcs() {
|
|
199
|
-
const { globe, _arcMap, _cameraUniformBlock, bufferManagerMap } = this;
|
|
200
|
-
if (!globe || !_cameraUniformBlock || !bufferManagerMap) {
|
|
201
|
-
console.warn("Globe or camera uniform block is not initialized.");
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
const lookAtPosition = _cameraUniformBlock.getLookAtVector();
|
|
205
|
-
const cameraPosition = _cameraUniformBlock.getCameraVector();
|
|
206
|
-
vec3.divideScalar(cameraPosition, cameraPosition, WORLD_RADIUS_3D);
|
|
207
|
-
vec3.add(cameraPosition, cameraPosition, lookAtPosition);
|
|
208
|
-
// vec3.normalize(cameraPosition, cameraPosition);
|
|
209
|
-
vec3.divideScalar(cameraPosition, cameraPosition, 2);
|
|
210
|
-
// vec3.multiplyScalar(cameraPosition, cameraPosition, 1.3);
|
|
211
|
-
const _attractionStrength = (() => {
|
|
212
|
-
const lod = globe.api_GetCurrentLODWithDecimal();
|
|
213
|
-
if (lod < 11) {
|
|
214
|
-
return 1;
|
|
215
|
-
}
|
|
216
|
-
return lod * (lod - 8.5);
|
|
217
|
-
})();
|
|
218
|
-
console.log("Attraction strength: ", _attractionStrength);
|
|
219
|
-
const result = [];
|
|
220
|
-
const longLat = [0, 0];
|
|
221
|
-
for (const [key, [arcInstance, height]] of _arcMap) {
|
|
222
|
-
arc.copy(_0arc, arcInstance);
|
|
223
|
-
const isOnArc = arc.closestPoint(_attractionPoint, _0arc, cameraPosition);
|
|
224
|
-
if (!isOnArc) {
|
|
225
|
-
if (vec3.distanceSquared(cameraPosition, _0arc.p0) < vec3.distanceSquared(cameraPosition, _0arc.p1)) {
|
|
226
|
-
vec3.copy(_attractionPoint, _0arc.p0);
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
vec3.copy(_attractionPoint, _0arc.p1);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
const generatedPoints = generateArcPoints(_0arc.p0, _0arc.p1, _0arc.normal, _attractionPoint, VERTEX_COUNT, _attractionStrength);
|
|
233
|
-
const longLatArr = new Float32Array(2 * VERTEX_COUNT);
|
|
234
|
-
for (let i = 0; i < generatedPoints.length; i++) {
|
|
235
|
-
const point = generatedPoints[i];
|
|
236
|
-
vec3.fromUnitVectorToLongLat(longLat, point);
|
|
237
|
-
longLatArr.set([longLat[0] / RADIANS, longLat[1] / RADIANS], i * 2);
|
|
238
|
-
}
|
|
239
|
-
result.push({
|
|
240
|
-
key: key,
|
|
241
|
-
longLatArr: longLatArr,
|
|
242
|
-
height: height
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
this._bufferOrchestrator.resetWithCapacity(bufferManagerMap, result.length);
|
|
246
|
-
this._bufferOrchestrator.insertBulk(result, bufferManagerMap);
|
|
247
|
-
}
|
|
248
|
-
_buildStaticArc() {
|
|
249
|
-
}
|
|
250
|
-
}
|
package/util/check/get.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const mapGetOrThrow = (errorNote) => {
|
|
2
|
-
return (mapInstance, ids) => {
|
|
3
|
-
if (!ids)
|
|
4
|
-
throw new Error("There is no map keys to get");
|
|
5
|
-
const result = [];
|
|
6
|
-
for (let i = 0; i < ids.length; i++) {
|
|
7
|
-
const e = mapInstance.get(ids[i]);
|
|
8
|
-
if (e === undefined)
|
|
9
|
-
throw new Error(errorNote + " " + ids[i]);
|
|
10
|
-
result.push(e);
|
|
11
|
-
}
|
|
12
|
-
return result;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef DrawRange
|
|
3
|
-
* @type {Object}
|
|
4
|
-
* @property {int} first
|
|
5
|
-
* @property {int} count
|
|
6
|
-
*
|
|
7
|
-
* @typedef DrawRangeIndexParams
|
|
8
|
-
* @type {Object}
|
|
9
|
-
* @property {null|DrawRange} drawRange
|
|
10
|
-
* @property {null|ElementBuffer} elementBuffer
|
|
11
|
-
* @property {null|indexType} indexType
|
|
12
|
-
* @property {null|int} drawMode
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
export {};
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
// export function createShader(gl, type, source) {
|
|
2
|
-
// const shader = gl.createShader(type);
|
|
3
|
-
// gl.shaderSource(shader, source);
|
|
4
|
-
// gl.compileShader(shader);
|
|
5
|
-
// if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
6
|
-
// throw new Error(gl.getShaderInfoLog(shader));
|
|
7
|
-
// }
|
|
8
|
-
// return shader;
|
|
9
|
-
// }
|
|
10
|
-
export function createShader(gl, type, source) {
|
|
11
|
-
const shader = gl.createShader(type);
|
|
12
|
-
gl.shaderSource(shader, source);
|
|
13
|
-
gl.compileShader(shader);
|
|
14
|
-
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
15
|
-
const errorLog = gl.getShaderInfoLog(shader);
|
|
16
|
-
const shaderType = type === gl.VERTEX_SHADER ? 'VERTEX_SHADER' : 'FRAGMENT_SHADER';
|
|
17
|
-
const sourceWithLineNumbers = source.split('\n').map((line, i) => `${i + 1}: ${line}`).join('\n');
|
|
18
|
-
throw new Error(`Error compiling ${shaderType}:\n${errorLog}\nSource:\n${sourceWithLineNumbers}`);
|
|
19
|
-
}
|
|
20
|
-
return shader;
|
|
21
|
-
}
|
|
22
|
-
export function createProgram(gl, vertexSource, fragmentSource) {
|
|
23
|
-
const program = gl.createProgram();
|
|
24
|
-
const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexSource);
|
|
25
|
-
const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
|
|
26
|
-
gl.compileShader(vertexShader);
|
|
27
|
-
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
|
|
28
|
-
console.error(gl.getShaderInfoLog(vertexShader));
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
gl.compileShader(fragmentShader);
|
|
32
|
-
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
|
|
33
|
-
console.error(gl.getShaderInfoLog(fragmentShader));
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
gl.attachShader(program, vertexShader);
|
|
37
|
-
gl.attachShader(program, fragmentShader);
|
|
38
|
-
gl.linkProgram(program);
|
|
39
|
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
40
|
-
console.error(gl.getProgramInfoLog(program));
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
return program;
|
|
44
|
-
}
|
|
45
|
-
export function createProgramWrapper(gl, vertexSource, fragmentSource) {
|
|
46
|
-
const program = gl.createProgram();
|
|
47
|
-
const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexSource);
|
|
48
|
-
const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
|
|
49
|
-
gl.attachShader(program, vertexShader);
|
|
50
|
-
gl.attachShader(program, fragmentShader);
|
|
51
|
-
gl.linkProgram(program);
|
|
52
|
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
53
|
-
// console.log(gl.getProgramInfoLog(program));
|
|
54
|
-
throw new Error(gl.getProgramInfoLog(program));
|
|
55
|
-
}
|
|
56
|
-
const wrapper = { program: program };
|
|
57
|
-
const numAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
|
|
58
|
-
for (let i = 0; i < numAttributes; i++) {
|
|
59
|
-
const attribute = gl.getActiveAttrib(program, i);
|
|
60
|
-
wrapper[attribute.name] = gl.getAttribLocation(program, attribute.name);
|
|
61
|
-
}
|
|
62
|
-
const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
|
|
63
|
-
for (let i = 0; i < numUniforms; i++) {
|
|
64
|
-
const uniform = gl.getActiveUniform(program, i);
|
|
65
|
-
wrapper[uniform.name] = gl.getUniformLocation(program, uniform.name);
|
|
66
|
-
}
|
|
67
|
-
return wrapper;
|
|
68
|
-
}
|
|
69
|
-
export function createTexture(gl, filter, data, width, height) {
|
|
70
|
-
const texture = gl.createTexture();
|
|
71
|
-
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
72
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
73
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
74
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
|
|
75
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
|
|
76
|
-
if (data instanceof Uint8Array) {
|
|
77
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
|
81
|
-
}
|
|
82
|
-
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
83
|
-
return texture;
|
|
84
|
-
}
|
|
85
|
-
export function bindTexture(gl, texture, unit) {
|
|
86
|
-
gl.activeTexture(gl.TEXTURE0 + unit);
|
|
87
|
-
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
88
|
-
}
|
|
89
|
-
export function createBuffer(gl, data) {
|
|
90
|
-
const buffer = gl.createBuffer();
|
|
91
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
92
|
-
gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
|
|
93
|
-
return buffer;
|
|
94
|
-
}
|
|
95
|
-
export function bindAttribute(gl, buffer, attribute, numComponents) {
|
|
96
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
97
|
-
gl.enableVertexAttribArray(attribute);
|
|
98
|
-
gl.vertexAttribPointer(attribute, numComponents, gl.FLOAT, false, 0, 0);
|
|
99
|
-
}
|
|
100
|
-
export function bindFramebuffer(gl, framebuffer, texture) {
|
|
101
|
-
if (texture) {
|
|
102
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
103
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
export function decodeBase64(data) {
|
|
110
|
-
const binary_string = atob(data);
|
|
111
|
-
const len = binary_string.length;
|
|
112
|
-
const bytes = new Uint8Array(len);
|
|
113
|
-
for (let i = 0; i < len; i++) {
|
|
114
|
-
bytes[i] = binary_string.charCodeAt(i);
|
|
115
|
-
}
|
|
116
|
-
return bytes;
|
|
117
|
-
}
|
|
118
|
-
export function createImageFromBase64(encodedData) {
|
|
119
|
-
const bytes = decodeBase64(encodedData);
|
|
120
|
-
const blob = new Blob([bytes.buffer], { type: "image/png" });
|
|
121
|
-
const urlCreator = window.URL || window.webkitURL;
|
|
122
|
-
const imageUrl = urlCreator.createObjectURL(blob);
|
|
123
|
-
const image = new Image();
|
|
124
|
-
image.src = imageUrl;
|
|
125
|
-
return image;
|
|
126
|
-
}
|
|
127
|
-
export function getColorRamp(colors) {
|
|
128
|
-
// console.log("getColorRamp", colors)
|
|
129
|
-
const canvas = document.createElement('canvas');
|
|
130
|
-
const ctx = canvas.getContext('2d');
|
|
131
|
-
canvas.width = 256;
|
|
132
|
-
canvas.height = 1;
|
|
133
|
-
const gradient = ctx.createLinearGradient(0, 0, 256, 0);
|
|
134
|
-
for (const stop in colors) {
|
|
135
|
-
// console.log("stop", stop);
|
|
136
|
-
gradient.addColorStop(colors[stop][0], colors[stop][1]);
|
|
137
|
-
// Alttaki satir ile gradienti cevirip, shaderda ki `speed_t = 1.0 - speed_t`' kaldirdim.
|
|
138
|
-
// gradientin en dusuk olmasi gereken siyah - mavi aralikta, mor renk gozlemledim.
|
|
139
|
-
// gradient.addColorStop( 1.0 - colors[stop][0], colors[stop][1]);
|
|
140
|
-
}
|
|
141
|
-
ctx.fillStyle = gradient;
|
|
142
|
-
ctx.fillRect(0, 0, 256, 1);
|
|
143
|
-
return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);
|
|
144
|
-
}
|
|
145
|
-
export function getColorRampDiscrate(values, thresholds) {
|
|
146
|
-
const canvas = document.createElement('canvas');
|
|
147
|
-
const ctx = canvas.getContext('2d');
|
|
148
|
-
canvas.width = 256;
|
|
149
|
-
canvas.height = 1;
|
|
150
|
-
const gap = 1.0 / 256;
|
|
151
|
-
const gradient = ctx.createLinearGradient(0, 0, 256, 0);
|
|
152
|
-
for (let i = 0; i < thresholds.length - 1; i++) {
|
|
153
|
-
gradient.addColorStop(thresholds[i], values[i]);
|
|
154
|
-
gradient.addColorStop(thresholds[i + 1] - gap, values[i]);
|
|
155
|
-
}
|
|
156
|
-
gradient.addColorStop(thresholds[thresholds.length - 1], values[values.length - 1]);
|
|
157
|
-
ctx.fillStyle = gradient;
|
|
158
|
-
ctx.fillRect(0, 0, 256, 1);
|
|
159
|
-
return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);
|
|
160
|
-
}
|
|
161
|
-
export function getColorRampInterpolated(values, thresholds) {
|
|
162
|
-
const canvas = document.createElement('canvas');
|
|
163
|
-
const ctx = canvas.getContext('2d');
|
|
164
|
-
canvas.width = 256;
|
|
165
|
-
canvas.height = 1;
|
|
166
|
-
const gradient = ctx.createLinearGradient(0, 0, 256, 0);
|
|
167
|
-
// const gap = 1.0 / 256;
|
|
168
|
-
// gradient.addColorStop(thresholds[0], values[0]);
|
|
169
|
-
// gradient.addColorStop(thresholds[0] + gap, values[1]);
|
|
170
|
-
for (let i = 0; i < thresholds.length; i++) {
|
|
171
|
-
gradient.addColorStop(thresholds[i], values[i]);
|
|
172
|
-
}
|
|
173
|
-
// gradient.addColorStop(thresholds[thresholds.length - 1] - gap, values[values.length - 1]);
|
|
174
|
-
ctx.fillStyle = gradient;
|
|
175
|
-
ctx.fillRect(0, 0, 256, 1);
|
|
176
|
-
return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* values: n + 1 number of color hex values without alpha channel. Ex: ["#ff0000", "#00ff00", "#0000ff"]
|
|
180
|
-
* thresholds: n number of thresholds. Ex: [0, 10, 20]
|
|
181
|
-
* mode: [discrete, interpolated,]
|
|
182
|
-
*/
|
|
183
|
-
export function getColorRampModed(values, thresholds, mode = "interpolated") {
|
|
184
|
-
if (mode === "discrete") {
|
|
185
|
-
return getColorRampDiscrate(values, thresholds);
|
|
186
|
-
}
|
|
187
|
-
else if (mode === "interpolated") {
|
|
188
|
-
return getColorRampInterpolated(values, thresholds);
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
throw new Error("mode is not valid");
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
export function defaultColorRamp() {
|
|
195
|
-
const defaultRampColors = [
|
|
196
|
-
[0.0, '#5e4fa2'],
|
|
197
|
-
[0.15, '#3288bd'],
|
|
198
|
-
[0.20, '#66c2a5'],
|
|
199
|
-
[0.25, '#66c2a5'],
|
|
200
|
-
[0.3, '#abdda4'],
|
|
201
|
-
[0.4, '#e6f598'],
|
|
202
|
-
[0.5, '#fee08b'],
|
|
203
|
-
[0.6, '#fdae61'],
|
|
204
|
-
[0.7, '#f46d43'],
|
|
205
|
-
[1.0, '#ff1e13']
|
|
206
|
-
];
|
|
207
|
-
return getColorRamp(defaultRampColors);
|
|
208
|
-
}
|
|
209
|
-
export function reloadCurrentGLProgram() {
|
|
210
|
-
return function (target, key, descriptor) {
|
|
211
|
-
const originalMethod = descriptor.value;
|
|
212
|
-
descriptor.value = function () {
|
|
213
|
-
const gl = target.gl;
|
|
214
|
-
const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
215
|
-
originalMethod.apply(this, arguments);
|
|
216
|
-
gl.useProgram(currentProgram);
|
|
217
|
-
};
|
|
218
|
-
};
|
|
219
|
-
}
|
|
File without changes
|
|
File without changes
|