-
Notifications
You must be signed in to change notification settings - Fork 316
Expand file tree
/
Copy pathPotreeNodeBase.ts
More file actions
113 lines (93 loc) · 3.57 KB
/
PotreeNodeBase.ts
File metadata and controls
113 lines (93 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { Vector3, type Box3, type Group } from 'three';
import PointCloudNode from './PointCloudNode';
// Create an A(xis)A(ligned)B(ounding)B(ox) for the child `childIndex`
// of one aabb. (PotreeConverter protocol builds implicit octree hierarchy
// by applying the same subdivision algo recursively)
const dHalfLength = new Vector3();
export function computeChildBBox(voxelBBox: Box3, childIndex: number) {
// Code inspired from potree
const childVoxelBBox = voxelBBox.clone();
voxelBBox.getCenter(childVoxelBBox.max);
dHalfLength.copy(childVoxelBBox.max).sub(voxelBBox.min);
if (childIndex === 1) {
childVoxelBBox.min.z += dHalfLength.z;
childVoxelBBox.max.z += dHalfLength.z;
} else if (childIndex === 3) {
childVoxelBBox.min.z += dHalfLength.z;
childVoxelBBox.max.z += dHalfLength.z;
childVoxelBBox.min.y += dHalfLength.y;
childVoxelBBox.max.y += dHalfLength.y;
} else if (childIndex === 0) {
//
} else if (childIndex === 2) {
childVoxelBBox.min.y += dHalfLength.y;
childVoxelBBox.max.y += dHalfLength.y;
} else if (childIndex === 5) {
childVoxelBBox.min.z += dHalfLength.z;
childVoxelBBox.max.z += dHalfLength.z;
childVoxelBBox.min.x += dHalfLength.x;
childVoxelBBox.max.x += dHalfLength.x;
} else if (childIndex === 7) {
childVoxelBBox.min.add(dHalfLength);
childVoxelBBox.max.add(dHalfLength);
} else if (childIndex === 4) {
childVoxelBBox.min.x += dHalfLength.x;
childVoxelBBox.max.x += dHalfLength.x;
} else if (childIndex === 6) {
childVoxelBBox.min.y += dHalfLength.y;
childVoxelBBox.max.y += dHalfLength.y;
childVoxelBBox.min.x += dHalfLength.x;
childVoxelBBox.max.x += dHalfLength.x;
}
return childVoxelBBox;
}
export abstract class PotreeNodeBase extends PointCloudNode {
index: number;
childrenBitField: number;
baseurl: string;
offsetBBox?: Box3;
crs: string;
private _hierarchyKey: string | undefined;
constructor(
depth: number,
index: number,
numPoints = 0,
childrenBitField = 0,
source: { baseurl: string },
crs: string,
) {
super(depth, numPoints);
this.childrenBitField = childrenBitField;
this.index = index;
this.baseurl = source.baseurl;
this.crs = crs;
}
override get octreeIsLoaded(): boolean {
return !(this.childrenBitField && this.children.length === 0);
}
override get id(): string {
return this.hierarchyKey;
}
get hierarchyKey(): string {
if (this._hierarchyKey != undefined) { return this._hierarchyKey; }
if (this.depth === 0) {
this._hierarchyKey = 'r';
} else {
this._hierarchyKey = `${this.parent?.hierarchyKey}${this.index}`;
}
return this._hierarchyKey;
}
override fetcher(url: string, networkOptions: RequestInit): Promise<ArrayBuffer> {
return this.source.fetcher(url, networkOptions);
}
override createChildAABB(childNode: this, childIndex: number): void {
childNode.voxelOBB.copy(this.voxelOBB);
childNode.voxelOBB.box3D = computeChildBBox(this.voxelOBB.box3D, childIndex);
childNode.clampOBB.copy(childNode.voxelOBB);
childNode.clampOBB.clampZ(this.source.zmin, this.source.zmax);
(this.clampOBB.parent as Group).add(childNode.clampOBB);
childNode.clampOBB.updateMatrixWorld(true);
childNode.voxelOBB.updateMatrixWorld(true);
}
}
export default PotreeNodeBase;