This commit is contained in:
Zemledelec 2025-12-06 12:14:28 +04:00
parent 7b094e5e4d
commit 6cdaff8c1b
6 changed files with 55 additions and 20 deletions

View File

@ -26,7 +26,7 @@ class MyScene extends RenderNode {
let e1 = new Entity({
polyline: {
path3v: [[[1, 0, 1], [3, 5, 3], [0, 10, 0]]],
thickness: 12.5,
thickness: 30.5,
src: "./template3.png",
isClosed: false
}
@ -35,9 +35,9 @@ class MyScene extends RenderNode {
let e2 = new Entity({
polyline: {
path3v: [[[5, 0, 5], [5, 15, 5]]],
thickness: 5.5,
thickness: 50.5,
src: "./template2.png",
isClosed: true
isClosed: false
}
});

View File

@ -1,6 +1,7 @@
import {Entity} from "./Entity";
import {Extent} from "../Extent";
import {LonLat} from "../LonLat";
import {Vec2} from "../math/Vec2";
import {Vec3} from "../math/Vec3";
import type {NumberArray3} from "../math/Vec3";
import type {NumberArray2} from "../math/Vec2";
@ -847,14 +848,14 @@ class Polyline {
/**
[1, -1, 2, -2] - orders for triangle strip line segment
t2 t3
(2)-------(-2)
| |
| |
| |
| |
(1)-------(-1)
t0 t1
*/
static setPathTexCoords(
path3v: SegmentPath3vExt[],
@ -863,6 +864,11 @@ class Polyline {
imgHeight: number,
outTexCoords: number[]
) {
let t0 = new Vec2(tCoordArr[0], tCoordArr[1]),
t1 = new Vec2(tCoordArr[8], tCoordArr[9]),
t2 = new Vec2(tCoordArr[2], tCoordArr[3]),
t3 = new Vec2(tCoordArr[4], tCoordArr[5]);
for (let j = 0, len = path3v.length; j < len; j++) {
var path = path3v[j];
@ -871,14 +877,14 @@ class Polyline {
}
if (j > 0) {
outTexCoords.push(0, 0, 1, 0, 1, 0, 1, 1);
outTexCoords.push(t0.x, t0.y, t1.x, t1.y, t2.x, t2.y, t3.x, t3.y);
}
for (let i = 0, len = path.length; i < len; i++) {
outTexCoords.push(0, 0, 1, 0, 1, 0, 1, 1);
outTexCoords.push(t0.x, t0.y, t1.x, t1.y, t2.x, t2.y, t3.x, t3.y);
}
outTexCoords.push(0, 0, 1, 0, 1, 0, 1, 1);
outTexCoords.push(t0.x, t0.y, t1.x, t1.y, t2.x, t2.y, t3.x, t3.y);
}
}
@ -1931,7 +1937,6 @@ class Polyline {
/**
* Gets polyline opacity.
* @public
* @param {number} opacity - Opacity.
*/
public getOpacity(): number {
return this._opacity;
@ -1940,7 +1945,7 @@ class Polyline {
/**
* Sets Polyline thickness in screen pixels.
* @public
* @param {number} thickness - Thickness.
* @param {number} altitude - ALtitude value.
*/
public setAltitude(altitude: number) {
this.altitude = altitude;
@ -2167,7 +2172,7 @@ class Polyline {
/**
* Sets polyline color
* @param {string} htmlColor- HTML color
* @param {string} htmlColor - HTML color.
*/
public setColorHTML(htmlColor: string) {
this._defaultColor = htmlColorToFloat32Array(htmlColor);
@ -2305,7 +2310,7 @@ class Polyline {
gl.vertexAttribPointer(sha.color, this._colorsBuffer!.itemSize, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, this._texCoordBuffer!);
gl.vertexAttribPointer(sha.a_texCoord, this._texCoordBuffer!.itemSize, gl.FLOAT, false, 0, 0);
gl.vertexAttribPointer(sha.texCoord, this._texCoordBuffer!.itemSize, gl.FLOAT, false, 0, 0);
let v = this._verticesHighBuffer!;
gl.bindBuffer(gl.ARRAY_BUFFER, v);
@ -2491,7 +2496,7 @@ class Polyline {
let h = this._renderNode!.renderer!.handler;
h.gl!.deleteBuffer(this._texCoordBuffer!);
this._texCoordArr = makeArrayTyped(this._texCoordArr);
this._texCoordBuffer = h.createArrayBuffer(this._texCoordArr as TypedArray, 4, this._texCoordArr.length / 4);
this._texCoordBuffer = h.createArrayBuffer(this._texCoordArr as TypedArray, 2, this._texCoordArr.length / 2);
}
public setVisibleSphere(p: Vec3, r: number) {

View File

@ -18,6 +18,7 @@ export function polyline_screen(): Program {
opacity: "float",
depthOffset: "float",
visibleSphere: "vec4",
texAtlas: "sampler2d"
},
attributes: {
prevHigh: "vec3",
@ -27,7 +28,8 @@ export function polyline_screen(): Program {
currentLow: "vec3",
nextLow: "vec3",
order: "float",
color: "vec4"
color: "vec4",
texCoord: "vec2"
},
vertexShader: polyline_screen_vert,
fragmentShader: polyline_screen_frag

View File

@ -1,10 +1,12 @@
precision highp float;
uniform sampler2D texAtlas;
uniform vec4 visibleSphere;
varying vec3 uCamPos;
varying vec4 vColor;
varying vec4 v_rgba;
varying vec3 vPos;
varying vec2 vTexCoord;
//${UTILS}
@ -18,5 +20,11 @@ void main() {
}
}
gl_FragColor = vec4(vColor.rgb, vColor.a);
vec2 uv = vTexCoord.xy;
//float min = v_texCoord.z;
//float height = v_texCoord.w;
vec4 color = texture2D(texAtlas, uv);
//gl_FragColor = vec4(v_rgba.rgb, v_rgba.a);
gl_FragColor = color;
}

View File

@ -8,6 +8,8 @@ attribute vec3 prevLow;
attribute vec3 currentLow;
attribute vec3 nextLow;
attribute vec2 texCoord;
attribute float order;
attribute vec4 color;
@ -22,9 +24,10 @@ uniform float opacity;
uniform float depthOffset;
varying vec4 vColor;
varying vec4 v_rgba;
varying vec3 vPos;
varying vec3 uCamPos;
varying vec2 vTexCoord;
const float NEAR = -1.0;
@ -50,7 +53,7 @@ void main() {
uCamPos = rtcEyePositionHigh + rtcEyePositionLow;
vPos = currentHigh + currentLow;
vColor = vec4(color.rgb, color.a * opacity);
v_rgba = vec4(color.rgb, color.a * opacity);
mat4 viewMatrixRTE = view;
viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);
@ -72,7 +75,7 @@ void main() {
lowDiff = nextLow - rtcEyePositionLow;
vec4 vNext = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);
/*Clip near plane, the point behind view plane*/
/*Clip near plane, the point behind view plane*/
if (vCurrent.z > NEAR) {
if (vPrev.z < NEAR && abs(order) == 1.0) {
vCurrent = vPrev + (vCurrent - vPrev) * (NEAR - vPrev.z) / (vCurrent.z - vPrev.z);
@ -112,6 +115,8 @@ void main() {
float d = thickness * sign(order);
vTexCoord = texCoord;
vec2 m;
if (dotNP >= 0.99991) {
m = sCurrent - normalPrev * d;

View File

@ -129,7 +129,7 @@ class TextureAtlas {
return this.get(image.__nodeIndex);
}
}
protected _completeNode(nodes: Map<number, TextureAtlasNode>, node?: TextureAtlasNode | null) {
if (node) {
@ -143,21 +143,36 @@ class TextureAtlas {
let tc = node.texCoords;
/**
* V0=V5-_--------V4
* | |
* | |
* | |
* | |
* V1------------V2=V3
*/
// V0
tc[0] = (r.left + bs) / w;
tc[1] = (r.top + bs) / h;
// V1
tc[2] = (r.left + bs) / w;
tc[3] = (r.bottom - bs) / h;
// V2
tc[4] = (r.right - bs) / w;
tc[5] = (r.bottom - bs) / h;
// V3 = V2
tc[6] = (r.right - bs) / w;
tc[7] = (r.bottom - bs) / h;
// V4
tc[8] = (r.right - bs) / w;
tc[9] = (r.top + bs) / h;
// V5 = V0
tc[10] = (r.left + bs) / w;
tc[11] = (r.top + bs) / h;