This commit is contained in:
Zemledelec 2025-12-04 16:17:44 +04:00
parent e9fc88feaf
commit 667262ba21
12 changed files with 138 additions and 18 deletions

BIN
sandbox/polyline/green.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

View File

@ -0,0 +1,21 @@
<html>
<head>
<title>Draco loader sample</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="./polyline.js" type="module"></script>
<link rel="stylesheet" href="../../css/og.css" type="text/css" />
<style>
body {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div style="width: 100%; height: 100%">
<canvas id="frame" style="width: 100%; height: 100%"> </canvas>
</div>
</body>
</html>

View File

@ -0,0 +1,60 @@
import {
control,
Entity,
Object3d,
Renderer,
Vec3,
Mat4,
RenderNode,
EntityCollection,
scene,
} from "../../lib/og.es.js";
let renderer = new Renderer("frame", {
msaa: 8,
controls: [new control.SimpleNavigation({ speed: 0.01 })],
autoActivate: true
});
class MyScene extends RenderNode {
constructor() {
super("MyScene");
}
init() {
let e1 = new Entity({
polyline: {
path3v: [[[1, 0, 1], [3, 5, 3], [0, 10, 0]]],
thickness: 12.5,
src: "./template3.png",
isClosed: false
}
});
let e2 = new Entity({
polyline: {
path3v: [[[5, 0, 5], [5, 15, 5]]],
thickness: 5.5,
src: "./template2.png",
isClosed: true
}
});
let collection = new EntityCollection({
entities: [e1, e2]
});
collection.addTo(this);
window.collection = collection;
this.renderer.activeCamera.set(new Vec3(-4, 11, 13), new Vec3(1, 0, 0));
this.renderer.activeCamera.update();
}
}
renderer.addNodes([
new scene.Axes(),
new MyScene()
]);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 B

View File

@ -658,14 +658,12 @@ class EntityCollection {
* @public
*/
public updateStrokeTextureAtlas() {
// Rays
let r = this.rayHandler.rays;
for (let i = 0; i < r.length; i++) {
r[i].setSrc(r[i].getSrc());
}
this.rayHandler.reloadTextures();
//Polylines
//@todo
this.polylineHandler.reloadTextures();
//Strips
//@todo
@ -746,6 +744,8 @@ class EntityCollection {
this._clearEntity(entity.childEntities[i]);
}
}
}
type EntityCollectionEventList = [

View File

@ -338,12 +338,12 @@ class Polyline {
ta.addImage(img);
ta.createTexture();
this._image = img;
rn!.updateTexCoords();
rn!.updateStrokeTexCoords();
}
});
} else {
this.setTextureDisabled();
rn!.updateTexCoords();
rn!.updateStrokeTexCoords();
}
}
}
@ -370,6 +370,7 @@ class Polyline {
let index = 0;
let i = index * 24;
let a = this._texCoordArr;
debugger;
// a[i] = tcoordArr[0];
// a[i + 1] = tcoordArr[1];
@ -2014,6 +2015,7 @@ class Polyline {
this._orders = [];
this._indexes = [];
this._colors = [];
this._texCoordArr = [];
this._path3v.length = 0;
this._pathLonLat.length = 0;

View File

@ -132,6 +132,36 @@ class PolylineHandler {
Vec3.doubleToTwoFloat32Array(rtcEyePosition, this._rtcEyePositionHigh, this._rtcEyePositionLow);
}
}
public reloadTextures() {
for (let i = 0; i < this._polylines.length; i++) {
let ri = this._polylines[i];
ri.setSrc(ri.getSrc());
}
}
public get polylines(): Polyline[] {
return [...this._polylines];
}
public refreshTexCoordsArr() {
let bc = this._entityCollection;
if (bc && this._renderer) {
let ta = this._renderer.strokeTextureAtlas;
for (let i = 0; i < this._polylines.length; i++) {
let ri = this._polylines[i];
let img = ri.getImage();
if (img) {
let taData = ta.get(img.__nodeIndex!);
if (taData) {
let minY = taData.texCoords[1],
imgHeight = taData.texCoords[3] - minY;
ri._setTexCoordArr(taData.texCoords, minY, imgHeight);
}
}
}
}
}
}
export {PolylineHandler};

View File

@ -198,12 +198,12 @@ class Ray {
ta.addImage(img);
ta.createTexture();
this._image = img;
rn!.updateTexCoords();
rn!.updateStrokeTexCoords();
}
});
} else {
bh!.setTextureDisabled(this._handlerIndex);
rn!.updateTexCoords();
rn!.updateStrokeTexCoords();
}
}
}

View File

@ -131,6 +131,13 @@ class RayHandler {
}
}
public reloadTextures() {
for (let i = 0; i < this._rays.length; i++) {
let ri = this._rays[i];
ri.setSrc(ri.getSrc());
}
}
public get rays(): Ray[] {
return [...this._rays];
}

View File

@ -313,23 +313,23 @@ class RenderNode extends BaseNode {
// // }
// }
/*
@todo: use one atlas for both handlers?
*/
public updateBillboardsTexCoords() {
for (let i = 0; i < this.entityCollections.length; i++) {
this.entityCollections[i].billboardHandler.refreshTexCoordsArr();
}
}
public updateTexCoords() {
//Ray
public updateStrokeTexCoords() {
for (let i = 0; i < this.entityCollections.length; i++) {
this.entityCollections[i].rayHandler.refreshTexCoordsArr();
let ei = this.entityCollections[i];
ei.rayHandler.refreshTexCoordsArr();
ei.polylineHandler.refreshTexCoordsArr();
//Strips etc.
//@todo
}
//Polyline
//@todo
//Strips
//@todo
}
public frame() {