Skip to content

Commit d3bce7c

Browse files
committed
remove per-primitive bounding spheres, clean up
1 parent 6773154 commit d3bce7c

File tree

7 files changed

+74
-58
lines changed

7 files changed

+74
-58
lines changed

packages/engine/Source/Scene/BufferPoint.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class BufferPoint extends BufferPrimitive {
4242
__BYTE_LENGTH: BufferPrimitive.Layout.__BYTE_LENGTH + 4,
4343
};
4444

45+
/////////////////////////////////////////////////////////////////////////////
46+
// LIFECYCLE
47+
4548
/**
4649
* @param {BufferPoint} point
4750
* @param {BufferPoint} result

packages/engine/Source/Scene/BufferPolygon.js

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import assert from "../Core/assert.js";
44
import BufferPrimitive from "./BufferPrimitive.js";
5-
import BoundingSphere from "../Core/BoundingSphere.js";
65
import BufferPrimitiveCollection from "./BufferPrimitiveCollection.js";
76
import defined from "../Core/defined.js";
87

@@ -31,68 +30,48 @@ class BufferPolygon extends BufferPrimitive {
3130
*/
3231
_collection = null;
3332

34-
/**
35-
* @type {BoundingSphere}
36-
* @protected
37-
* @ignore
38-
*/
39-
_boundingSphere = new BoundingSphere();
40-
4133
/** @ignore */
4234
static Layout = {
4335
...BufferPrimitive.Layout,
4436

45-
/**
46-
* Bounding sphere for polygon.
47-
* @type {number}
48-
*/
49-
BOUNDING_SPHERE: BufferPrimitive.Layout.__BYTE_LENGTH,
50-
5137
/**
5238
* Offset in position array to first vertex in polygon, number of VEC3 elements.
5339
* @type {number}
5440
*/
55-
POSITION_OFFSET_U32:
56-
BufferPrimitive.Layout.__BYTE_LENGTH + BoundingSphere.packedLength,
41+
POSITION_OFFSET_U32: BufferPrimitive.Layout.__BYTE_LENGTH,
5742

5843
/**
5944
* Count of positions (vertices) in this polygon, number of VEC3 elements.
6045
* @type {number}
6146
*/
62-
POSITION_COUNT_U32:
63-
BufferPrimitive.Layout.__BYTE_LENGTH + BoundingSphere.packedLength + 4,
47+
POSITION_COUNT_U32: BufferPrimitive.Layout.__BYTE_LENGTH + 4,
6448

6549
/**
6650
* Offset in holes array to first hole in polygon, number of integer elements.
6751
* @type {number}
6852
*/
69-
HOLE_OFFSET_U32:
70-
BufferPrimitive.Layout.__BYTE_LENGTH + BoundingSphere.packedLength + 8,
53+
HOLE_OFFSET_U32: BufferPrimitive.Layout.__BYTE_LENGTH + 8,
7154

7255
/**
7356
* Count of holes (indices) in this polygon, number of integer elements.
7457
* @type {number}
7558
*/
76-
HOLE_COUNT_U32:
77-
BufferPrimitive.Layout.__BYTE_LENGTH + BoundingSphere.packedLength + 12,
59+
HOLE_COUNT_U32: BufferPrimitive.Layout.__BYTE_LENGTH + 12,
7860

7961
/**
8062
* Offset in triangles array to first triangle in polygon, number of VEC3 elements.
8163
* @type {number}
8264
*/
83-
TRIANGLE_OFFSET_U32:
84-
BufferPrimitive.Layout.__BYTE_LENGTH + BoundingSphere.packedLength + 16,
65+
TRIANGLE_OFFSET_U32: BufferPrimitive.Layout.__BYTE_LENGTH + 16,
8566

8667
/**
8768
* Count of triangles (3x uint32) in this polygon, number of VEC3 elements.
8869
* @type {number}
8970
*/
90-
TRIANGLE_COUNT_U32:
91-
BufferPrimitive.Layout.__BYTE_LENGTH + BoundingSphere.packedLength + 20,
71+
TRIANGLE_COUNT_U32: BufferPrimitive.Layout.__BYTE_LENGTH + 20,
9272

9373
/** @type {number} */
94-
__BYTE_LENGTH:
95-
BufferPrimitive.Layout.__BYTE_LENGTH + BoundingSphere.packedLength + 24,
74+
__BYTE_LENGTH: BufferPrimitive.Layout.__BYTE_LENGTH + 24,
9675
};
9776

9877
/////////////////////////////////////////////////////////////////////////////

packages/engine/Source/Scene/BufferPolyline.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @ts-check
22

3-
import BoundingSphere from "../Core/BoundingSphere.js";
43
import BufferPrimitive from "./BufferPrimitive.js";
54
import assert from "../Core/assert.js";
65
import BufferPrimitiveCollection from "./BufferPrimitiveCollection.js";
@@ -32,35 +31,25 @@ class BufferPolyline extends BufferPrimitive {
3231
...BufferPrimitive.Layout,
3332

3433
/**
35-
* Bounding sphere for polygon.
36-
* @type {number}
37-
*/
38-
BOUNDING_SPHERE: BufferPrimitive.Layout.__BYTE_LENGTH,
39-
40-
/**
41-
* Width of polyline, 0–255.
34+
* Offset in position array to first vertex in polyline, number of VEC3 elements.
4235
* @type {number}
4336
*/
44-
WIDTH_U8:
45-
BufferPrimitive.Layout.__BYTE_LENGTH + BoundingSphere.packedLength,
37+
POSITION_OFFSET_U32: BufferPrimitive.Layout.__BYTE_LENGTH,
4638

4739
/**
48-
* Offset in position array to first vertex in polyline, number of VEC3 elements.
40+
* Count of positions (vertices) in this polyline, number of VEC3 elements.
4941
* @type {number}
5042
*/
51-
POSITION_OFFSET_U32:
52-
BufferPrimitive.Layout.__BYTE_LENGTH + BoundingSphere.packedLength + 4,
43+
POSITION_COUNT_U32: BufferPrimitive.Layout.__BYTE_LENGTH + 4,
5344

5445
/**
55-
* Count of positions (vertices) in this polyline, number of VEC3 elements.
46+
* Width of polyline, 0–255.
5647
* @type {number}
5748
*/
58-
POSITION_COUNT_U32:
59-
BufferPrimitive.Layout.__BYTE_LENGTH + BoundingSphere.packedLength + 8,
49+
WIDTH_U8: BufferPrimitive.Layout.__BYTE_LENGTH + 8,
6050

6151
/** @type {number} */
62-
__BYTE_LENGTH:
63-
BufferPrimitive.Layout.__BYTE_LENGTH + BoundingSphere.packedLength + 12,
52+
__BYTE_LENGTH: BufferPrimitive.Layout.__BYTE_LENGTH + 12,
6453
};
6554

6655
/////////////////////////////////////////////////////////////////////////////

packages/engine/Source/Scene/BufferPrimitive.js

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const scratchColor = new Color();
1010
* View bound to the underlying buffer data of a {@link BufferPrimitiveCollection}. Abstract.
1111
*
1212
* <p>BufferPrimitive instances are intended to be reused when iterating over large collections,
13-
* and temporarily bound to a primitive index while performing read/write operations on that primitive.</p>
13+
* and temporarily bound to a primitive index while performing read/write operations on that primitive,
14+
* before being rebound to the next primitive, using the
15+
* {@link https://en.wikipedia.org/wiki/Flyweight_pattern|flyweight pattern}.</p>
1416
*
1517
* @example
1618
* const primitive = new BufferPrimitive();
@@ -34,24 +36,43 @@ const scratchColor = new Color();
3436
*/
3537
class BufferPrimitive {
3638
/**
39+
* Collecton containing the primitive(s) for which this instance currently
40+
* provides a view.
41+
*
3742
* @type {BufferPrimitiveCollection<BufferPrimitive>}
3843
* @ignore
3944
*/
4045
_collection = null;
4146

4247
/**
48+
* Index of the primitive for which this instance currently provides a view.
49+
*
4350
* @type {number}
4451
* @ignore
4552
*/
4653
_index = -1;
4754

4855
/**
56+
* Byte offset, into the collection's primitive buffer, of the primitive for
57+
* which this instance currently provides a view,
58+
*
4959
* @type {number}
5060
* @ignore
5161
*/
5262
_byteOffset = -1;
5363

54-
/** @ignore */
64+
/**
65+
* Binary layout for this primitive type in collection's primitive buffer.
66+
* Each `Layout.MY_KEY_U32` entry is an offset in bytes, relative to the
67+
* start offset of the primitive, with the suffix indicating the data type
68+
* stored at that offset.
69+
*
70+
* The final entry, `__BYTE_LENGTH`, is not a pointer into a buffer — its
71+
* literal value is the total byte length of one primitive in the primitive
72+
* buffer, exclusive of other buffers.
73+
*
74+
* @ignore
75+
*/
5576
static Layout = {
5677
/**
5778
* Feature ID associated with the primitive; not required to be unique.
@@ -77,7 +98,11 @@ class BufferPrimitive {
7798
*/
7899
COLOR_U32: 8,
79100

80-
/** @type {number} */
101+
/**
102+
* Byte length of one primitive in the primitive buffer, exclusive of
103+
* other buffers. Literal value, not a pointer.
104+
* @type {number}
105+
*/
81106
__BYTE_LENGTH: 12,
82107
};
83108

@@ -101,6 +126,10 @@ class BufferPrimitive {
101126
}
102127

103128
/**
129+
* Returns true if this primitive's memory footprint is resizable. Only the
130+
* newest (most recently created) primitive in a collection can be resized,
131+
* to guarantee fast and stable performance.
132+
*
104133
* @returns {boolean}
105134
* @protected
106135
* @ignore
@@ -112,7 +141,10 @@ class BufferPrimitive {
112141
/////////////////////////////////////////////////////////////////////////////
113142
// ACCESSORS
114143

115-
/** @type {number} */
144+
/**
145+
* Feature ID associated with the primitive; not required to be unique.
146+
* @type {number}
147+
*/
116148
get featureId() {
117149
return this._getUint32(BufferPrimitive.Layout.FEATURE_ID_U32);
118150
}
@@ -121,7 +153,10 @@ class BufferPrimitive {
121153
this._setUint32(BufferPrimitive.Layout.FEATURE_ID_U32, featureId);
122154
}
123155

124-
/** @type {boolean} */
156+
/**
157+
* Whether primitive is shown.
158+
* @type {boolean}
159+
*/
125160
get show() {
126161
return this._getUint8(BufferPrimitive.Layout.SHOW_U8) === 1;
127162
}
@@ -131,8 +166,16 @@ class BufferPrimitive {
131166
}
132167

133168
/**
169+
* Whether the primitive requires an update on next render. Renderers should
170+
* _not_ iterate over all primitives each frame, but must instead inspect
171+
* only the dirty range of the parent collection. This flag is managed
172+
* automatically, by primitive setters and collection renderers.
173+
*
134174
* @type {boolean}
135175
* @ignore
176+
*
177+
* @see BufferPrimitiveCollection#_dirtyOffset
178+
* @see BufferPrimitiveCollection#_dirtyCount
136179
*/
137180
get _dirty() {
138181
return this._getUint8(BufferPrimitive.Layout.DIRTY_U8) === 1;
@@ -154,6 +197,7 @@ class BufferPrimitive {
154197
}
155198

156199
/**
200+
* Returns the color of primitive.
157201
* @param {Color} result
158202
* @returns {Color}
159203
*/
@@ -165,14 +209,15 @@ class BufferPrimitive {
165209
}
166210

167211
/**
212+
* Updates the color of primitive.
168213
* @param {Color} color
169214
*/
170215
setColor(color) {
171216
this._setUint32(BufferPrimitive.Layout.COLOR_U32, color.toRgba());
172217
}
173218

174219
/////////////////////////////////////////////////////////////////////////////
175-
// DATAVIEW ACCESSORS
220+
// BUFFER ACCESSORS
176221

177222
/**
178223
* @param {number} itemByteOffset

packages/engine/Source/Scene/BufferPrimitiveCollection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import assert from "../Core/assert.js";
2222
*
2323
* To get the full performance benefit of using a BufferPrimitiveCollection containing "N" primitives,
2424
* be careful to avoid allocating "N" instances of any related JavaScript object. {@link BufferPrimitive},
25-
* {@link Color}, {@link Cartesian3}, and other objects can all be reused when working with large collections. See
26-
* {@linkcode BufferPrimitiveCollection#add} and {@linkcode BufferPrimitiveCollection#get}.
25+
* {@link Color}, {@link Cartesian3}, and other objects can all be reused when working with large collections,
26+
* using the {@link https://en.wikipedia.org/wiki/Flyweight_pattern|flyweight pattern}.
2727
*
2828
* @abstract
2929
* @template T extends BufferPrimitive

packages/engine/Specs/Scene/BufferPolygonCollectionSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe("BufferPolygonCollection", () => {
164164
triangleCountMax: 1,
165165
});
166166

167-
expect(collection.sizeInBytes).toBe(40 + 72 + 12);
167+
expect(collection.sizeInBytes).toBe(36 + 72 + 12);
168168

169169
collection = new BufferPolygonCollection({
170170
primitiveCountMax: 128,
@@ -173,7 +173,7 @@ describe("BufferPolygonCollection", () => {
173173
triangleCountMax: 1024,
174174
});
175175

176-
expect(collection.sizeInBytes).toBe(5120 + 24576 + 512 + 12288);
176+
expect(collection.sizeInBytes).toBe(4608 + 24576 + 512 + 12288);
177177
});
178178

179179
it("clone", () => {

packages/engine/Specs/Scene/BufferPolylineCollectionSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ describe("BufferPolylineCollection", () => {
9191
vertexCountMax: 1,
9292
});
9393

94-
expect(collection.sizeInBytes).toBe(28 + 24);
94+
expect(collection.sizeInBytes).toBe(24 + 24);
9595

9696
collection = new BufferPolylineCollection({
9797
primitiveCountMax: 128,
9898
vertexCountMax: 128,
9999
});
100100

101-
expect(collection.sizeInBytes).toBe((28 + 24) * 128);
101+
expect(collection.sizeInBytes).toBe((24 + 24) * 128);
102102
});
103103

104104
it("clone", () => {

0 commit comments

Comments
 (0)