@geoblocks/cesium-walk 0.1.0 → 0.1.1

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/cesium-walk.js CHANGED
@@ -172,10 +172,10 @@ export default class CesiumWalk {
172
172
 
173
173
  /**
174
174
  * The height of the ground under a position, in meters above the ellipsoid, or undefined when unknown
175
- * yet. The terrain by default; a model's floors otherwise, for a walker on several levels.
175
+ * yet. The terrain by default, none without a globe; a model's floors otherwise, for a walker on several levels.
176
176
  * @type {(position: import('@cesium/core').Cartographic) => number | undefined}
177
177
  */
178
- this.groundHeight = position => viewer.scene.globe.getHeight(position);
178
+ this.groundHeight = position => viewer.scene.globe?.getHeight(position);
179
179
 
180
180
  // whether the walker sprinted on the last tick
181
181
  this.sprinting_ = false;
@@ -379,6 +379,6 @@ export default class CesiumWalk {
379
379
  */
380
380
  surfaceNormal_() {
381
381
  const scene = this.viewer.scene;
382
- return scene.globe.ellipsoid.geodeticSurfaceNormal(scene.camera.position, normalScratch);
382
+ return scene.ellipsoid.geodeticSurfaceNormal(scene.camera.position, normalScratch);
383
383
  }
384
384
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geoblocks/cesium-walk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "license": "BSD-3-Clause",
5
5
  "type": "module",
6
6
  "repository": {
@@ -26,10 +26,11 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@geoblocks/cesium-input": "^0.1.0",
29
- "@geoblocks/cesium-obstacles": "^0.1.0"
29
+ "@geoblocks/cesium-obstacles": "^0.1.1"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@cesium/core": ">=0.1.0",
33
33
  "@cesium/engine": ">=10"
34
- }
34
+ },
35
+ "gitHead": "430bbbb63bf3d60221d670f65d5e51fdb6d5b944"
35
36
  }
package/walk-mesh.js CHANGED
@@ -36,9 +36,9 @@ const floorCartographicScratch = new Cartographic();
36
36
  */
37
37
 
38
38
  /**
39
- * The flat shaded model of the triangles, untextured, in glTF's y up, quantized (KHR_mesh_quantization):
40
- * the positions in 16 bits, scaled back to meters by the node; the normals in 8 bits; each vertex padded to
41
- * 4 bytes, 12 in all, as against 24 in floats. Exported for the tests.
39
+ * The flat shaded model of the triangles, untextured, in glTF's y up: the positions in floats, a corner the same
40
+ * in every model sharing it, no crack between them; the normals quantized (KHR_mesh_quantization) in 8 bits,
41
+ * padded to 4 bytes, 16 in all, as against 24 in floats. Exported for the tests.
42
42
  * @param {Float32Array} vertices
43
43
  * @param {Uint32Array} triangles
44
44
  * @param {number[]} color
@@ -49,23 +49,8 @@ const floorCartographicScratch = new Cartographic();
49
49
  */
50
50
  export function toGlb(vertices, triangles, color, emissive, uv, lightmap) {
51
51
  const count = triangles.length;
52
- // the extent of the map, in glTF's axes
53
52
  const toGltf = (/** @type {number} */ v) => [vertices[v], vertices[v + 2], -vertices[v + 1]];
54
- const low = [Infinity, Infinity, Infinity];
55
- const high = [-Infinity, -Infinity, -Infinity];
56
- for (let v = 0; v < vertices.length; v += 3) {
57
- toGltf(v).forEach((value, axis) => {
58
- low[axis] = Math.min(low[axis], value);
59
- high[axis] = Math.max(high[axis], value);
60
- });
61
- }
62
- // the node maps -32767..32767 back to the widest extent, the same on every axis, which leaves the
63
- // normals as they are
64
- const translation = low.map((value, axis) => (value + high[axis]) / 2);
65
- // a single point: any step keeps it at the node's translation
66
- const step = Math.max(...low.map((value, axis) => high[axis] - value)) / 65534 || 1;
67
- const scale = [step, step, step];
68
- const positions = new Int16Array(count * 4);
53
+ const positions = new Float32Array(count * 3);
69
54
  const normals = new Int8Array(count * 4);
70
55
  const texCoords = new Float32Array(uv ? count * 2 : 0);
71
56
  const lightmapCoords = new Float32Array(lightmap ? count * 2 : 0);
@@ -79,12 +64,11 @@ export function toGlb(vertices, triangles, color, emissive, uv, lightmap) {
79
64
  Cartesian3.normalize(normal, normal);
80
65
  }
81
66
  corners.forEach((corner, k) => {
82
- const quantized = corner.map((value, axis) => Math.round((value - translation[axis]) / step));
83
- positions.set(quantized, (i + k) * 4);
67
+ positions.set(corner, (i + k) * 3);
84
68
  normals.set([normal.x, normal.y, normal.z].map(n => Math.round(n * 127)), (i + k) * 4);
85
69
  for (let axis = 0; axis < 3; axis++) {
86
- min[axis] = Math.min(min[axis], quantized[axis]);
87
- max[axis] = Math.max(max[axis], quantized[axis]);
70
+ min[axis] = Math.min(min[axis], Math.fround(corner[axis]));
71
+ max[axis] = Math.max(max[axis], Math.fround(corner[axis]));
88
72
  }
89
73
  if (uv) {
90
74
  const v = triangles[i + k] * 3;
@@ -106,7 +90,7 @@ export function toGlb(vertices, triangles, color, emissive, uv, lightmap) {
106
90
  extensionsRequired: ['KHR_mesh_quantization'],
107
91
  scene: 0,
108
92
  scenes: [{nodes: [0]}],
109
- nodes: [{mesh: 0, translation, scale}],
93
+ nodes: [{mesh: 0}],
110
94
  meshes: [{primitives: [{attributes: {POSITION: 0, NORMAL: 1, ...Object.fromEntries(floats.map(([name], k) => [name, 2 + k]))}, material: 0}]}],
111
95
  materials: [{
112
96
  pbrMetallicRoughness: {baseColorFactor: color, metallicFactor: 0, roughnessFactor: 1},
@@ -118,7 +102,7 @@ export function toGlb(vertices, triangles, color, emissive, uv, lightmap) {
118
102
  }],
119
103
  buffers: [{byteLength: positions.byteLength + normals.byteLength + floatsLength}],
120
104
  bufferViews: [
121
- {buffer: 0, byteOffset: 0, byteLength: positions.byteLength, byteStride: 8, target: 34962},
105
+ {buffer: 0, byteOffset: 0, byteLength: positions.byteLength, target: 34962},
122
106
  {buffer: 0, byteOffset: positions.byteLength, byteLength: normals.byteLength, byteStride: 4, target: 34962},
123
107
  ...floats.map(([, array]) => {
124
108
  const view = {buffer: 0, byteOffset: floatOffset, byteLength: array.byteLength, target: 34962};
@@ -127,7 +111,7 @@ export function toGlb(vertices, triangles, color, emissive, uv, lightmap) {
127
111
  }),
128
112
  ],
129
113
  accessors: [
130
- {bufferView: 0, componentType: 5122, count, type: 'VEC3', min, max},
114
+ {bufferView: 0, componentType: 5126, count, type: 'VEC3', min, max},
131
115
  {bufferView: 1, componentType: 5120, normalized: true, count, type: 'VEC3'},
132
116
  ...floats.map((_, k) => ({bufferView: 2 + k, componentType: 5126, count, type: 'VEC2'})),
133
117
  ],
@@ -144,7 +128,7 @@ export function toGlb(vertices, triangles, color, emissive, uv, lightmap) {
144
128
  new Uint8Array(glb, 20, jsonLength).fill(0x20).set(json);
145
129
  view.setUint32(20 + jsonLength, binLength, true);
146
130
  view.setUint32(24 + jsonLength, 0x004e4942, true);
147
- new Int16Array(glb, 28 + jsonLength, count * 4).set(positions);
131
+ new Float32Array(glb, 28 + jsonLength, count * 3).set(positions);
148
132
  new Int8Array(glb, 28 + jsonLength + positions.byteLength, count * 4).set(normals);
149
133
  let offset = 28 + jsonLength + positions.byteLength + normals.byteLength;
150
134
  for (const [, array] of floats) {