@deck.gl/geo-layers 9.0.0-alpha.5 → 9.0.0-alpha.7

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.
Files changed (71) hide show
  1. package/dist/dist.dev.js +16488 -2329
  2. package/dist/es5/index.js +8 -0
  3. package/dist/es5/index.js.map +1 -1
  4. package/dist/es5/mesh-layer/mesh-layer-vertex.glsl.js +1 -1
  5. package/dist/es5/mesh-layer/mesh-layer.js +217 -0
  6. package/dist/es5/mesh-layer/mesh-layer.js.map +1 -0
  7. package/dist/es5/tile-3d-layer/tile-3d-layer.js +511 -0
  8. package/dist/es5/tile-3d-layer/tile-3d-layer.js.map +1 -0
  9. package/dist/es5/trips-layer/trips-layer.js +2 -2
  10. package/dist/es5/trips-layer/trips-layer.js.map +1 -1
  11. package/dist/esm/index.js +1 -0
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/esm/mesh-layer/mesh-layer-vertex.glsl.js +5 -1
  14. package/dist/esm/mesh-layer/mesh-layer-vertex.glsl.js.map +1 -1
  15. package/dist/esm/mesh-layer/mesh-layer.js +178 -0
  16. package/dist/esm/mesh-layer/mesh-layer.js.map +1 -0
  17. package/dist/esm/tile-3d-layer/tile-3d-layer.js +438 -0
  18. package/dist/esm/tile-3d-layer/tile-3d-layer.js.map +1 -0
  19. package/dist/esm/trips-layer/trips-layer.js +4 -4
  20. package/dist/esm/trips-layer/trips-layer.js.map +1 -1
  21. package/dist.min.js +752 -33
  22. package/package.json +14 -14
  23. package/src/index.ts +2 -4
  24. package/src/mesh-layer/mesh-layer-vertex.glsl.ts +5 -1
  25. package/{dist/es5/mesh-layer/mesh-layer.ts.disabled → src/mesh-layer/mesh-layer.ts} +37 -29
  26. package/src/tile-3d-layer/{tile-3d-layer.ts.disabled → tile-3d-layer.ts} +1 -3
  27. package/src/trips-layer/trips-layer.ts +4 -4
  28. package/typed/geo-cell-layer/GeoCellLayer.d.ts +1 -1
  29. package/typed/geo-cell-layer/GeoCellLayer.d.ts.map +1 -1
  30. package/typed/geohash-layer/geohash-layer.d.ts +1 -1
  31. package/typed/geohash-layer/geohash-layer.d.ts.map +1 -1
  32. package/typed/great-circle-layer/great-circle-layer.d.ts +2 -2
  33. package/typed/great-circle-layer/great-circle-layer.d.ts.map +1 -1
  34. package/typed/h3-layers/h3-cluster-layer.d.ts +2 -2
  35. package/typed/h3-layers/h3-cluster-layer.d.ts.map +1 -1
  36. package/typed/h3-layers/h3-hexagon-layer.d.ts +2 -2
  37. package/typed/h3-layers/h3-hexagon-layer.d.ts.map +1 -1
  38. package/typed/index.d.ts +2 -0
  39. package/typed/index.d.ts.map +1 -1
  40. package/typed/mesh-layer/mesh-layer-vertex.glsl.d.ts +1 -1
  41. package/typed/mesh-layer/mesh-layer-vertex.glsl.d.ts.map +1 -1
  42. package/typed/mesh-layer/mesh-layer.d.ts +38 -0
  43. package/typed/mesh-layer/mesh-layer.d.ts.map +1 -0
  44. package/typed/mvt-layer/mvt-layer.d.ts +4 -4
  45. package/typed/mvt-layer/mvt-layer.d.ts.map +1 -1
  46. package/typed/quadkey-layer/quadkey-layer.d.ts +2 -2
  47. package/typed/quadkey-layer/quadkey-layer.d.ts.map +1 -1
  48. package/typed/s2-layer/s2-layer.d.ts +2 -2
  49. package/typed/s2-layer/s2-layer.d.ts.map +1 -1
  50. package/typed/terrain-layer/terrain-layer.d.ts +5 -5
  51. package/typed/terrain-layer/terrain-layer.d.ts.map +1 -1
  52. package/typed/tile-3d-layer/tile-3d-layer.d.ts +62 -0
  53. package/typed/tile-3d-layer/tile-3d-layer.d.ts.map +1 -0
  54. package/typed/tile-layer/tile-layer.d.ts +3 -3
  55. package/typed/tile-layer/tile-layer.d.ts.map +1 -1
  56. package/typed/tileset-2d/tile-2d-header.d.ts +1 -1
  57. package/typed/tileset-2d/tile-2d-header.d.ts.map +1 -1
  58. package/typed/tileset-2d/tileset-2d.d.ts +3 -3
  59. package/typed/tileset-2d/tileset-2d.d.ts.map +1 -1
  60. package/typed/tileset-2d/types.d.ts +7 -7
  61. package/typed/tileset-2d/types.d.ts.map +1 -1
  62. package/typed/tileset-2d/utils.d.ts +1 -1
  63. package/typed/tileset-2d/utils.d.ts.map +1 -1
  64. package/typed/trips-layer/trips-layer.d.ts +2 -2
  65. package/typed/trips-layer/trips-layer.d.ts.map +1 -1
  66. package/typed/wms-layer/wms-layer.d.ts +2 -2
  67. package/typed/wms-layer/wms-layer.d.ts.map +1 -1
  68. package/dist/es5/tile-3d-layer/tile-3d-layer.ts.disabled +0 -435
  69. package/dist/esm/mesh-layer/mesh-layer.ts.disabled +0 -176
  70. package/dist/esm/tile-3d-layer/tile-3d-layer.ts.disabled +0 -435
  71. package/src/mesh-layer/mesh-layer.ts.disabled +0 -176
@@ -17,7 +17,9 @@ in vec3 featureIdsPickingColors;
17
17
  // Instance attributes
18
18
  in vec4 instanceColors;
19
19
  in vec3 instancePickingColors;
20
- in mat3 instanceModelMatrix;
20
+ in vec3 instanceModelMatrixCol0;
21
+ in vec3 instanceModelMatrixCol1;
22
+ in vec3 instanceModelMatrixCol2;
21
23
 
22
24
  // Outputs to fragment shader
23
25
  out vec2 vTexCoord;
@@ -45,6 +47,8 @@ void main(void) {
45
47
  geometry.pickingColor = instancePickingColors;
46
48
  }
47
49
 
50
+ mat3 instanceModelMatrix = mat3(instanceModelMatrixCol0, instanceModelMatrixCol1, instanceModelMatrixCol2);
51
+
48
52
  vTexCoord = uv;
49
53
  cameraPosition = project_uCameraPosition;
50
54
  vColor = vec4(colors * instanceColors.rgb, instanceColors.a);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/mesh-layer/mesh-layer-vertex.glsl.ts"],"names":[],"mappings":"AAAA,eAAgB;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CA/EA","sourcesContent":["export default `#version 300 es\n#define SHADER_NAME simple-mesh-layer-vs\n\n// Scale the model\nuniform float sizeScale;\nuniform bool composeModelMatrix;\nuniform bool pickFeatureIds;\n\n// Primitive attributes\nin vec3 positions;\nin vec3 normals;\nin vec3 colors;\nin vec2 texCoords;\nin vec4 uvRegions;\nin vec3 featureIdsPickingColors;\n\n// Instance attributes\nin vec4 instanceColors;\nin vec3 instancePickingColors;\nin mat3 instanceModelMatrix;\n\n// Outputs to fragment shader\nout vec2 vTexCoord;\nout vec3 cameraPosition;\nout vec3 normals_commonspace;\nout vec4 position_commonspace;\nout vec4 vColor;\n\nvec2 applyUVRegion(vec2 uv) {\n #ifdef HAS_UV_REGIONS\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md\n return fract(uv) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;\n #else\n return uv;\n #endif\n}\n\nvoid main(void) {\n vec2 uv = applyUVRegion(texCoords);\n geometry.uv = uv;\n\n if (pickFeatureIds) {\n geometry.pickingColor = featureIdsPickingColors;\n } else {\n geometry.pickingColor = instancePickingColors;\n }\n\n vTexCoord = uv;\n cameraPosition = project_uCameraPosition;\n vColor = vec4(colors * instanceColors.rgb, instanceColors.a);\n\n vec3 pos = (instanceModelMatrix * positions) * sizeScale;\n vec3 projectedPosition = project_position(positions);\n position_commonspace = vec4(projectedPosition, 1.0);\n gl_Position = project_common_position_to_clipspace(position_commonspace);\n\n geometry.position = position_commonspace;\n normals_commonspace = project_normal(instanceModelMatrix * normals);\n geometry.normal = normals_commonspace;\n\n DECKGL_FILTER_GL_POSITION(gl_Position, geometry);\n\n #ifdef MODULE_PBR\n // set PBR data\n pbr_vPosition = geometry.position.xyz;\n #ifdef HAS_NORMALS\n pbr_vNormal = geometry.normal;\n #endif\n\n #ifdef HAS_UV\n pbr_vUV = uv;\n #else\n pbr_vUV = vec2(0., 0.);\n #endif\n geometry.uv = pbr_vUV;\n #endif\n\n DECKGL_FILTER_COLOR(vColor, geometry);\n}\n`;\n"],"file":"mesh-layer-vertex.glsl.js"}
1
+ {"version":3,"sources":["../../../src/mesh-layer/mesh-layer-vertex.glsl.ts"],"names":[],"mappings":"AAAA,eAAgB;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAnFA","sourcesContent":["export default `#version 300 es\n#define SHADER_NAME simple-mesh-layer-vs\n\n// Scale the model\nuniform float sizeScale;\nuniform bool composeModelMatrix;\nuniform bool pickFeatureIds;\n\n// Primitive attributes\nin vec3 positions;\nin vec3 normals;\nin vec3 colors;\nin vec2 texCoords;\nin vec4 uvRegions;\nin vec3 featureIdsPickingColors;\n\n// Instance attributes\nin vec4 instanceColors;\nin vec3 instancePickingColors;\nin vec3 instanceModelMatrixCol0;\nin vec3 instanceModelMatrixCol1;\nin vec3 instanceModelMatrixCol2;\n\n// Outputs to fragment shader\nout vec2 vTexCoord;\nout vec3 cameraPosition;\nout vec3 normals_commonspace;\nout vec4 position_commonspace;\nout vec4 vColor;\n\nvec2 applyUVRegion(vec2 uv) {\n #ifdef HAS_UV_REGIONS\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md\n return fract(uv) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;\n #else\n return uv;\n #endif\n}\n\nvoid main(void) {\n vec2 uv = applyUVRegion(texCoords);\n geometry.uv = uv;\n\n if (pickFeatureIds) {\n geometry.pickingColor = featureIdsPickingColors;\n } else {\n geometry.pickingColor = instancePickingColors;\n }\n\n mat3 instanceModelMatrix = mat3(instanceModelMatrixCol0, instanceModelMatrixCol1, instanceModelMatrixCol2);\n\n vTexCoord = uv;\n cameraPosition = project_uCameraPosition;\n vColor = vec4(colors * instanceColors.rgb, instanceColors.a);\n\n vec3 pos = (instanceModelMatrix * positions) * sizeScale;\n vec3 projectedPosition = project_position(positions);\n position_commonspace = vec4(projectedPosition, 1.0);\n gl_Position = project_common_position_to_clipspace(position_commonspace);\n\n geometry.position = position_commonspace;\n normals_commonspace = project_normal(instanceModelMatrix * normals);\n geometry.normal = normals_commonspace;\n\n DECKGL_FILTER_GL_POSITION(gl_Position, geometry);\n\n #ifdef MODULE_PBR\n // set PBR data\n pbr_vPosition = geometry.position.xyz;\n #ifdef HAS_NORMALS\n pbr_vNormal = geometry.normal;\n #endif\n\n #ifdef HAS_UV\n pbr_vUV = uv;\n #else\n pbr_vUV = vec2(0., 0.);\n #endif\n geometry.uv = pbr_vUV;\n #endif\n\n DECKGL_FILTER_COLOR(vColor, geometry);\n}\n`;\n"],"file":"mesh-layer-vertex.glsl.js"}
@@ -0,0 +1,178 @@
1
+ import { parsePBRMaterial } from '@luma.gl/gltf';
2
+ import { pbr } from '@luma.gl/shadertools';
3
+ import { Model } from '@luma.gl/engine';
4
+ import { GL } from '@luma.gl/constants';
5
+ import { SimpleMeshLayer } from '@deck.gl/mesh-layers';
6
+ import vs from './mesh-layer-vertex.glsl';
7
+ import fs from './mesh-layer-fragment.glsl';
8
+
9
+ function validateGeometryAttributes(attributes) {
10
+ const positionAttribute = attributes.positions || attributes.POSITION;
11
+ const vertexCount = positionAttribute.value.length / positionAttribute.size;
12
+ const hasColorAttribute = attributes.COLOR_0 || attributes.colors;
13
+
14
+ if (!hasColorAttribute) {
15
+ attributes.colors = {
16
+ size: 4,
17
+ value: new Uint8Array(vertexCount * 4).fill(255),
18
+ normalized: true
19
+ };
20
+ }
21
+ }
22
+
23
+ const defaultProps = {
24
+ pbrMaterial: {
25
+ type: 'object',
26
+ value: null
27
+ },
28
+ featureIds: {
29
+ type: 'array',
30
+ value: null,
31
+ optional: true
32
+ }
33
+ };
34
+ export default class MeshLayer extends SimpleMeshLayer {
35
+ getShaders() {
36
+ const shaders = super.getShaders();
37
+ const modules = shaders.modules;
38
+ modules.push(pbr);
39
+ return { ...shaders,
40
+ vs,
41
+ fs
42
+ };
43
+ }
44
+
45
+ initializeState() {
46
+ const {
47
+ featureIds
48
+ } = this.props;
49
+ super.initializeState();
50
+ const attributeManager = this.getAttributeManager();
51
+
52
+ if (featureIds) {
53
+ attributeManager.add({
54
+ featureIdsPickingColors: {
55
+ type: 5121,
56
+ size: 3,
57
+ noAlloc: true,
58
+ update: this.calculateFeatureIdsPickingColors
59
+ }
60
+ });
61
+ }
62
+ }
63
+
64
+ updateState(params) {
65
+ super.updateState(params);
66
+ const {
67
+ props,
68
+ oldProps
69
+ } = params;
70
+
71
+ if (props.pbrMaterial !== oldProps.pbrMaterial) {
72
+ this.updatePbrMaterialUniforms(props.pbrMaterial);
73
+ }
74
+ }
75
+
76
+ draw(opts) {
77
+ const {
78
+ featureIds
79
+ } = this.props;
80
+
81
+ if (!this.state.model) {
82
+ return;
83
+ }
84
+
85
+ this.state.model.setUniforms({
86
+ u_Camera: this.state.model.uniforms.project_uCameraPosition,
87
+ pickFeatureIds: Boolean(featureIds)
88
+ });
89
+ super.draw(opts);
90
+ }
91
+
92
+ getModel(mesh) {
93
+ const {
94
+ id,
95
+ pbrMaterial
96
+ } = this.props;
97
+ const parsedPBRMaterial = this.parseMaterial(pbrMaterial, mesh);
98
+ this.setState({
99
+ parsedPBRMaterial
100
+ });
101
+ const shaders = this.getShaders();
102
+ validateGeometryAttributes(mesh.attributes);
103
+ const model = new Model(this.context.device, { ...this.getShaders(),
104
+ id,
105
+ geometry: mesh,
106
+ bufferLayout: this.getAttributeManager().getBufferLayouts(),
107
+ defines: { ...shaders.defines,
108
+ ...(parsedPBRMaterial === null || parsedPBRMaterial === void 0 ? void 0 : parsedPBRMaterial.defines),
109
+ HAS_UV_REGIONS: mesh.attributes.uvRegions ? 1 : 0
110
+ },
111
+ parameters: parsedPBRMaterial === null || parsedPBRMaterial === void 0 ? void 0 : parsedPBRMaterial.parameters,
112
+ isInstanced: true
113
+ });
114
+ return model;
115
+ }
116
+
117
+ updatePbrMaterialUniforms(pbrMaterial) {
118
+ const {
119
+ model
120
+ } = this.state;
121
+
122
+ if (model) {
123
+ const {
124
+ mesh
125
+ } = this.props;
126
+ const parsedPBRMaterial = this.parseMaterial(pbrMaterial, mesh);
127
+ this.setState({
128
+ parsedPBRMaterial
129
+ });
130
+ model.setBindings(parsedPBRMaterial.bindings);
131
+ model.setUniforms(parsedPBRMaterial.uniforms);
132
+ }
133
+ }
134
+
135
+ parseMaterial(pbrMaterial, mesh) {
136
+ const unlit = Boolean(pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorTexture);
137
+ return parsePBRMaterial(this.context.device, {
138
+ unlit,
139
+ ...pbrMaterial
140
+ }, {
141
+ NORMAL: mesh.attributes.normals,
142
+ TEXCOORD_0: mesh.attributes.texCoords
143
+ }, {
144
+ pbrDebug: false,
145
+ lights: true,
146
+ useTangents: false
147
+ });
148
+ }
149
+
150
+ calculateFeatureIdsPickingColors(attribute) {
151
+ const featureIds = this.props.featureIds;
152
+ const value = new Uint8ClampedArray(featureIds.length * attribute.size);
153
+ const pickingColor = [];
154
+
155
+ for (let index = 0; index < featureIds.length; index++) {
156
+ this.encodePickingColor(featureIds[index], pickingColor);
157
+ value[index * 3] = pickingColor[0];
158
+ value[index * 3 + 1] = pickingColor[1];
159
+ value[index * 3 + 2] = pickingColor[2];
160
+ }
161
+
162
+ attribute.value = value;
163
+ }
164
+
165
+ finalizeState(context) {
166
+ var _this$state$parsedPBR;
167
+
168
+ super.finalizeState(context);
169
+ (_this$state$parsedPBR = this.state.parsedPBRMaterial) === null || _this$state$parsedPBR === void 0 ? void 0 : _this$state$parsedPBR.generatedTextures.forEach(texture => texture.destroy());
170
+ this.setState({
171
+ parsedPBRMaterial: null
172
+ });
173
+ }
174
+
175
+ }
176
+ MeshLayer.layerName = 'MeshLayer';
177
+ MeshLayer.defaultProps = defaultProps;
178
+ //# sourceMappingURL=mesh-layer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/mesh-layer/mesh-layer.ts"],"names":["parsePBRMaterial","pbr","Model","GL","SimpleMeshLayer","vs","fs","validateGeometryAttributes","attributes","positionAttribute","positions","POSITION","vertexCount","value","length","size","hasColorAttribute","COLOR_0","colors","Uint8Array","fill","normalized","defaultProps","pbrMaterial","type","featureIds","optional","MeshLayer","getShaders","shaders","modules","push","initializeState","props","attributeManager","getAttributeManager","add","featureIdsPickingColors","noAlloc","update","calculateFeatureIdsPickingColors","updateState","params","oldProps","updatePbrMaterialUniforms","draw","opts","state","model","setUniforms","u_Camera","uniforms","project_uCameraPosition","pickFeatureIds","Boolean","getModel","mesh","id","parsedPBRMaterial","parseMaterial","setState","context","device","geometry","bufferLayout","getBufferLayouts","defines","HAS_UV_REGIONS","uvRegions","parameters","isInstanced","setBindings","bindings","unlit","pbrMetallicRoughness","baseColorTexture","NORMAL","normals","TEXCOORD_0","texCoords","pbrDebug","lights","useTangents","attribute","Uint8ClampedArray","pickingColor","index","encodePickingColor","finalizeState","generatedTextures","forEach","texture","destroy","layerName"],"mappings":"AACA,SAAQA,gBAAR,QAAkD,eAAlD;AACA,SAAQC,GAAR,QAAkB,sBAAlB;AACA,SAAQC,KAAR,QAAoB,iBAApB;AACA,SAAQC,EAAR,QAAi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GAAY,CAAb,CAAL,GAAuBD,YAAY,CAAC,CAAD,CAAnC;AACD;;AAEDF,IAAAA,SAAS,CAACtE,KAAV,GAAkBA,KAAlB;AACD;;AAED2E,EAAAA,aAAa,CAAC3B,OAAD,EAAwB;AAAA;;AACnC,UAAM2B,aAAN,CAAoB3B,OAApB;AACA,kCAAKd,KAAL,CAAWW,iBAAX,gFAA8B+B,iBAA9B,CAAgDC,OAAhD,CAAwDC,OAAO,IAAIA,OAAO,CAACC,OAAR,EAAnE;AACA,SAAKhC,QAAL,CAAc;AAACF,MAAAA,iBAAiB,EAAE;AAApB,KAAd;AACD;;AAhID;AAHmB/B,S,CAIZkE,S,GAAY,W;AAJAlE,S,CAKZL,Y,GAAeA,Y","sourcesContent":["import type {NumericArray} from '@math.gl/core';\nimport {parsePBRMaterial, ParsedPBRMaterial} from '@luma.gl/gltf';\nimport {pbr} from '@luma.gl/shadertools';\nimport {Model} from '@luma.gl/engine';\nimport {GL} from '@luma.gl/constants';\nimport type {MeshAttribute, MeshAttributes} from '@loaders.gl/schema';\nimport type {UpdateParameters, DefaultProps, LayerContext} from '@deck.gl/core';\nimport {SimpleMeshLayer, SimpleMeshLayerProps} from '@deck.gl/mesh-layers';\n\nimport vs from './mesh-layer-vertex.glsl';\nimport fs from './mesh-layer-fragment.glsl';\n\nexport type Mesh = {\n attributes: MeshAttributes;\n indices?: MeshAttribute;\n};\n\nfunction validateGeometryAttributes(attributes: MeshAttributes) {\n const positionAttribute = attributes.positions || attributes.POSITION;\n const vertexCount = positionAttribute.value.length / positionAttribute.size;\n const hasColorAttribute = attributes.COLOR_0 || attributes.colors;\n if (!hasColorAttribute) {\n attributes.colors = {\n size: 4,\n value: new Uint8Array(vertexCount * 4).fill(255),\n normalized: true\n };\n }\n}\n\nconst defaultProps: DefaultProps<MeshLayerProps> = {\n pbrMaterial: {type: 'object', value: null},\n featureIds: {type: 'array', value: null, optional: true}\n};\n\n/** All properties supported by MeshLayer. */\nexport type MeshLayerProps<DataT = unknown> = _MeshLayerProps & SimpleMeshLayerProps<DataT>;\n\n/** Properties added by MeshLayer. */\ntype _MeshLayerProps = {\n /**\n * PBR material object. _lighting must be pbr for this to work\n */\n pbrMaterial?: any; // TODO add type when converting Tile3DLayer\n\n /**\n * List of feature ids.\n */\n featureIds?: NumericArray | null;\n};\n\nexport default class MeshLayer<DataT = any, ExtraProps extends {} = {}> extends SimpleMeshLayer<\n DataT,\n Required<_MeshLayerProps> & ExtraProps\n> {\n static layerName = 'MeshLayer';\n static defaultProps = defaultProps;\n\n getShaders() {\n const shaders = super.getShaders();\n const modules = shaders.modules;\n modules.push(pbr);\n return {...shaders, vs, fs};\n }\n\n initializeState() {\n const {featureIds} = this.props;\n super.initializeState();\n\n const attributeManager = this.getAttributeManager();\n if (featureIds) {\n // attributeManager is always defined in a primitive layer\n attributeManager!.add({\n featureIdsPickingColors: {\n type: GL.UNSIGNED_BYTE,\n size: 3,\n noAlloc: true,\n // eslint-disable-next-line @typescript-eslint/unbound-method\n update: this.calculateFeatureIdsPickingColors\n }\n });\n }\n }\n\n updateState(params: UpdateParameters<this>) {\n super.updateState(params);\n\n const {props, oldProps} = params;\n if (props.pbrMaterial !== oldProps.pbrMaterial) {\n this.updatePbrMaterialUniforms(props.pbrMaterial);\n }\n }\n\n draw(opts) {\n const {featureIds} = this.props;\n if (!this.state.model) {\n return;\n }\n this.state.model.setUniforms({\n // Needed for PBR (TODO: find better way to get it)\n // eslint-disable-next-line camelcase\n u_Camera: this.state.model.uniforms.project_uCameraPosition,\n pickFeatureIds: Boolean(featureIds)\n });\n\n super.draw(opts);\n }\n\n protected getModel(mesh: Mesh): Model {\n const {id, pbrMaterial} = this.props;\n const parsedPBRMaterial = this.parseMaterial(pbrMaterial, mesh);\n // Keep material to explicitly remove textures\n this.setState({parsedPBRMaterial});\n const shaders = this.getShaders();\n validateGeometryAttributes(mesh.attributes);\n const model = new Model(this.context.device, {\n ...this.getShaders(),\n id,\n geometry: mesh,\n bufferLayout: this.getAttributeManager()!.getBufferLayouts(),\n defines: {\n ...shaders.defines,\n ...parsedPBRMaterial?.defines,\n HAS_UV_REGIONS: mesh.attributes.uvRegions ? 1 : 0\n },\n parameters: parsedPBRMaterial?.parameters,\n isInstanced: true\n });\n\n return model;\n }\n\n updatePbrMaterialUniforms(pbrMaterial) {\n const {model} = this.state;\n if (model) {\n const {mesh} = this.props;\n const parsedPBRMaterial = this.parseMaterial(pbrMaterial, mesh as Mesh);\n // Keep material to explicitly remove textures\n this.setState({parsedPBRMaterial});\n model.setBindings(parsedPBRMaterial.bindings);\n model.setUniforms(parsedPBRMaterial.uniforms);\n }\n }\n\n parseMaterial(pbrMaterial, mesh: Mesh): ParsedPBRMaterial {\n const unlit = Boolean(\n pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorTexture\n );\n\n return parsePBRMaterial(\n this.context.device,\n {unlit, ...pbrMaterial},\n {NORMAL: mesh.attributes.normals, TEXCOORD_0: mesh.attributes.texCoords},\n {\n pbrDebug: false,\n lights: true,\n useTangents: false\n }\n );\n }\n\n calculateFeatureIdsPickingColors(attribute) {\n // This updater is only called if featureIds is not null\n const featureIds = this.props.featureIds!;\n const value = new Uint8ClampedArray(featureIds.length * attribute.size);\n\n const pickingColor = [];\n for (let index = 0; index < featureIds.length; index++) {\n this.encodePickingColor(featureIds[index], pickingColor);\n\n value[index * 3] = pickingColor[0];\n value[index * 3 + 1] = pickingColor[1];\n value[index * 3 + 2] = pickingColor[2];\n }\n\n attribute.value = value;\n }\n\n finalizeState(context: LayerContext) {\n super.finalizeState(context);\n this.state.parsedPBRMaterial?.generatedTextures.forEach(texture => texture.destroy());\n this.setState({parsedPBRMaterial: null});\n }\n}\n"],"file":"mesh-layer.js"}
@@ -0,0 +1,438 @@
1
+ import { Geometry } from '@luma.gl/engine';
2
+ import { CompositeLayer, COORDINATE_SYSTEM, log } from '@deck.gl/core';
3
+ import { PointCloudLayer } from '@deck.gl/layers';
4
+ import { ScenegraphLayer } from '@deck.gl/mesh-layers';
5
+ import { default as MeshLayer } from '../mesh-layer/mesh-layer';
6
+ import { load } from '@loaders.gl/core';
7
+ import { Tileset3D, TILE_TYPE } from '@loaders.gl/tiles';
8
+ import { Tiles3DLoader } from '@loaders.gl/3d-tiles';
9
+ const SINGLE_DATA = [0];
10
+ const defaultProps = {
11
+ getPointColor: {
12
+ type: 'accessor',
13
+ value: [0, 0, 0, 255]
14
+ },
15
+ pointSize: 1.0,
16
+ data: '',
17
+ loader: Tiles3DLoader,
18
+ onTilesetLoad: {
19
+ type: 'function',
20
+ value: tileset3d => {}
21
+ },
22
+ onTileLoad: {
23
+ type: 'function',
24
+ value: tileHeader => {}
25
+ },
26
+ onTileUnload: {
27
+ type: 'function',
28
+ value: tileHeader => {}
29
+ },
30
+ onTileError: {
31
+ type: 'function',
32
+ value: (tile, message, url) => {}
33
+ },
34
+ _getMeshColor: {
35
+ type: 'function',
36
+ value: tileHeader => [255, 255, 255]
37
+ }
38
+ };
39
+ export default class Tile3DLayer extends CompositeLayer {
40
+ constructor(...args) {
41
+ super(...args);
42
+ this.state = void 0;
43
+ }
44
+
45
+ initializeState() {
46
+ if ('onTileLoadFail' in this.props) {
47
+ log.removed('onTileLoadFail', 'onTileError')();
48
+ }
49
+
50
+ this.state = {
51
+ layerMap: {},
52
+ tileset3d: null,
53
+ activeViewports: {},
54
+ lastUpdatedViewports: null
55
+ };
56
+ }
57
+
58
+ get isLoaded() {
59
+ var _this$state, _this$state$tileset3d;
60
+
61
+ return Boolean(((_this$state = this.state) === null || _this$state === void 0 ? void 0 : (_this$state$tileset3d = _this$state.tileset3d) === null || _this$state$tileset3d === void 0 ? void 0 : _this$state$tileset3d.isLoaded()) && super.isLoaded);
62
+ }
63
+
64
+ shouldUpdateState({
65
+ changeFlags
66
+ }) {
67
+ return changeFlags.somethingChanged;
68
+ }
69
+
70
+ updateState({
71
+ props,
72
+ oldProps,
73
+ changeFlags
74
+ }) {
75
+ if (props.data && props.data !== oldProps.data) {
76
+ this._loadTileset(props.data);
77
+ }
78
+
79
+ if (changeFlags.viewportChanged) {
80
+ const {
81
+ activeViewports
82
+ } = this.state;
83
+ const viewportsNumber = Object.keys(activeViewports).length;
84
+
85
+ if (viewportsNumber) {
86
+ this._updateTileset(activeViewports);
87
+
88
+ this.state.lastUpdatedViewports = activeViewports;
89
+ this.state.activeViewports = {};
90
+ }
91
+ }
92
+
93
+ if (changeFlags.propsChanged) {
94
+ const {
95
+ layerMap
96
+ } = this.state;
97
+
98
+ for (const key in layerMap) {
99
+ layerMap[key].needsUpdate = true;
100
+ }
101
+ }
102
+ }
103
+
104
+ activateViewport(viewport) {
105
+ const {
106
+ activeViewports,
107
+ lastUpdatedViewports
108
+ } = this.state;
109
+ this.internalState.viewport = viewport;
110
+ activeViewports[viewport.id] = viewport;
111
+ const lastViewport = lastUpdatedViewports === null || lastUpdatedViewports === void 0 ? void 0 : lastUpdatedViewports[viewport.id];
112
+
113
+ if (!lastViewport || !viewport.equals(lastViewport)) {
114
+ this.setChangeFlags({
115
+ viewportChanged: true
116
+ });
117
+ this.setNeedsUpdate();
118
+ }
119
+ }
120
+
121
+ getPickingInfo({
122
+ info,
123
+ sourceLayer
124
+ }) {
125
+ const sourceTile = sourceLayer && sourceLayer.props.tile;
126
+
127
+ if (info.picked) {
128
+ info.object = sourceTile;
129
+ }
130
+
131
+ info.sourceTile = sourceTile;
132
+ return info;
133
+ }
134
+
135
+ filterSubLayer({
136
+ layer,
137
+ viewport
138
+ }) {
139
+ const {
140
+ tile
141
+ } = layer.props;
142
+ const {
143
+ id: viewportId
144
+ } = viewport;
145
+ return tile.selected && tile.viewportIds.includes(viewportId);
146
+ }
147
+
148
+ _updateAutoHighlight(info) {
149
+ const sourceTile = info.sourceTile;
150
+ const layerCache = this.state.layerMap[sourceTile === null || sourceTile === void 0 ? void 0 : sourceTile.id];
151
+
152
+ if (layerCache && layerCache.layer) {
153
+ layerCache.layer.updateAutoHighlight(info);
154
+ }
155
+ }
156
+
157
+ async _loadTileset(tilesetUrl) {
158
+ const {
159
+ loadOptions = {}
160
+ } = this.props;
161
+ const loaders = this.props.loader || this.props.loaders;
162
+ const loader = Array.isArray(loaders) ? loaders[0] : loaders;
163
+ const options = {
164
+ loadOptions: { ...loadOptions
165
+ }
166
+ };
167
+ let actualTilesetUrl = tilesetUrl;
168
+
169
+ if (loader.preload) {
170
+ const preloadOptions = await loader.preload(tilesetUrl, loadOptions);
171
+
172
+ if (preloadOptions.url) {
173
+ actualTilesetUrl = preloadOptions.url;
174
+ }
175
+
176
+ if (preloadOptions.headers) {
177
+ options.loadOptions.fetch = { ...options.loadOptions.fetch,
178
+ headers: preloadOptions.headers
179
+ };
180
+ }
181
+
182
+ Object.assign(options, preloadOptions);
183
+ }
184
+
185
+ const tilesetJson = await load(actualTilesetUrl, loader, options.loadOptions);
186
+ const tileset3d = new Tileset3D(tilesetJson, {
187
+ onTileLoad: this._onTileLoad.bind(this),
188
+ onTileUnload: this._onTileUnload.bind(this),
189
+ onTileError: this.props.onTileError,
190
+ ...options
191
+ });
192
+ this.setState({
193
+ tileset3d,
194
+ layerMap: {}
195
+ });
196
+
197
+ this._updateTileset(this.state.activeViewports);
198
+
199
+ this.props.onTilesetLoad(tileset3d);
200
+ }
201
+
202
+ _onTileLoad(tileHeader) {
203
+ const {
204
+ lastUpdatedViewports
205
+ } = this.state;
206
+ this.props.onTileLoad(tileHeader);
207
+
208
+ this._updateTileset(lastUpdatedViewports);
209
+
210
+ this.setNeedsUpdate();
211
+ }
212
+
213
+ _onTileUnload(tileHeader) {
214
+ delete this.state.layerMap[tileHeader.id];
215
+ this.props.onTileUnload(tileHeader);
216
+ }
217
+
218
+ _updateTileset(viewports) {
219
+ if (!viewports) {
220
+ return;
221
+ }
222
+
223
+ const {
224
+ tileset3d
225
+ } = this.state;
226
+ const {
227
+ timeline
228
+ } = this.context;
229
+ const viewportsNumber = Object.keys(viewports).length;
230
+
231
+ if (!timeline || !viewportsNumber || !tileset3d) {
232
+ return;
233
+ }
234
+
235
+ tileset3d.selectTiles(Object.values(viewports)).then(frameNumber => {
236
+ const tilesetChanged = this.state.frameNumber !== frameNumber;
237
+
238
+ if (tilesetChanged) {
239
+ this.setState({
240
+ frameNumber
241
+ });
242
+ }
243
+ });
244
+ }
245
+
246
+ _getSubLayer(tileHeader, oldLayer) {
247
+ if (!tileHeader.content) {
248
+ return null;
249
+ }
250
+
251
+ switch (tileHeader.type) {
252
+ case TILE_TYPE.POINTCLOUD:
253
+ return this._makePointCloudLayer(tileHeader, oldLayer);
254
+
255
+ case TILE_TYPE.SCENEGRAPH:
256
+ return this._make3DModelLayer(tileHeader);
257
+
258
+ case TILE_TYPE.MESH:
259
+ return this._makeSimpleMeshLayer(tileHeader, oldLayer);
260
+
261
+ default:
262
+ throw new Error(`Tile3DLayer: Failed to render layer of type ${tileHeader.content.type}`);
263
+ }
264
+ }
265
+
266
+ _makePointCloudLayer(tileHeader, oldLayer) {
267
+ const {
268
+ attributes,
269
+ pointCount,
270
+ constantRGBA,
271
+ cartographicOrigin,
272
+ modelMatrix
273
+ } = tileHeader.content;
274
+ const {
275
+ positions,
276
+ normals,
277
+ colors
278
+ } = attributes;
279
+
280
+ if (!positions) {
281
+ return null;
282
+ }
283
+
284
+ const data = oldLayer && oldLayer.props.data || {
285
+ header: {
286
+ vertexCount: pointCount
287
+ },
288
+ attributes: {
289
+ POSITION: positions,
290
+ NORMAL: normals,
291
+ COLOR_0: colors
292
+ }
293
+ };
294
+ const {
295
+ pointSize,
296
+ getPointColor
297
+ } = this.props;
298
+ const SubLayerClass = this.getSubLayerClass('pointcloud', PointCloudLayer);
299
+ return new SubLayerClass({
300
+ pointSize
301
+ }, this.getSubLayerProps({
302
+ id: 'pointcloud'
303
+ }), {
304
+ id: `${this.id}-pointcloud-${tileHeader.id}`,
305
+ tile: tileHeader,
306
+ data,
307
+ coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS,
308
+ coordinateOrigin: cartographicOrigin,
309
+ modelMatrix,
310
+ getColor: constantRGBA || getPointColor,
311
+ _offset: 0
312
+ });
313
+ }
314
+
315
+ _make3DModelLayer(tileHeader) {
316
+ const {
317
+ gltf,
318
+ instances,
319
+ cartographicOrigin,
320
+ modelMatrix
321
+ } = tileHeader.content;
322
+ const SubLayerClass = this.getSubLayerClass('scenegraph', ScenegraphLayer);
323
+ return new SubLayerClass({
324
+ _lighting: 'pbr'
325
+ }, this.getSubLayerProps({
326
+ id: 'scenegraph'
327
+ }), {
328
+ id: `${this.id}-scenegraph-${tileHeader.id}`,
329
+ tile: tileHeader,
330
+ data: instances || SINGLE_DATA,
331
+ scenegraph: gltf,
332
+ coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS,
333
+ coordinateOrigin: cartographicOrigin,
334
+ modelMatrix,
335
+ getTransformMatrix: instance => instance.modelMatrix,
336
+ getPosition: [0, 0, 0],
337
+ _offset: 0
338
+ });
339
+ }
340
+
341
+ _makeSimpleMeshLayer(tileHeader, oldLayer) {
342
+ const content = tileHeader.content;
343
+ const {
344
+ attributes,
345
+ indices,
346
+ modelMatrix,
347
+ cartographicOrigin,
348
+ coordinateSystem = COORDINATE_SYSTEM.METER_OFFSETS,
349
+ material,
350
+ featureIds
351
+ } = content;
352
+ const {
353
+ _getMeshColor
354
+ } = this.props;
355
+ const geometry = oldLayer && oldLayer.props.mesh || new Geometry({
356
+ topology: 'triangle-list',
357
+ attributes: getMeshGeometry(attributes),
358
+ indices
359
+ });
360
+ const SubLayerClass = this.getSubLayerClass('mesh', MeshLayer);
361
+ return new SubLayerClass(this.getSubLayerProps({
362
+ id: 'mesh'
363
+ }), {
364
+ id: `${this.id}-mesh-${tileHeader.id}`,
365
+ tile: tileHeader,
366
+ mesh: geometry,
367
+ data: SINGLE_DATA,
368
+ getColor: _getMeshColor(tileHeader),
369
+ pbrMaterial: material,
370
+ modelMatrix,
371
+ coordinateOrigin: cartographicOrigin,
372
+ coordinateSystem,
373
+ featureIds,
374
+ _offset: 0
375
+ });
376
+ }
377
+
378
+ renderLayers() {
379
+ const {
380
+ tileset3d,
381
+ layerMap
382
+ } = this.state;
383
+
384
+ if (!tileset3d) {
385
+ return null;
386
+ }
387
+
388
+ return tileset3d.tiles.map(tile => {
389
+ const layerCache = layerMap[tile.id] = layerMap[tile.id] || {
390
+ tile
391
+ };
392
+ let {
393
+ layer
394
+ } = layerCache;
395
+
396
+ if (tile.selected) {
397
+ if (!layer) {
398
+ layer = this._getSubLayer(tile);
399
+ } else if (layerCache.needsUpdate) {
400
+ layer = this._getSubLayer(tile, layer);
401
+ layerCache.needsUpdate = false;
402
+ }
403
+ }
404
+
405
+ layerCache.layer = layer;
406
+ return layer;
407
+ }).filter(Boolean);
408
+ }
409
+
410
+ }
411
+ Tile3DLayer.defaultProps = defaultProps;
412
+ Tile3DLayer.layerName = 'Tile3DLayer';
413
+
414
+ function getMeshGeometry(contentAttributes) {
415
+ const attributes = {};
416
+ attributes.positions = { ...contentAttributes.positions,
417
+ value: new Float32Array(contentAttributes.positions.value)
418
+ };
419
+
420
+ if (contentAttributes.normals) {
421
+ attributes.normals = contentAttributes.normals;
422
+ }
423
+
424
+ if (contentAttributes.texCoords) {
425
+ attributes.texCoords = contentAttributes.texCoords;
426
+ }
427
+
428
+ if (contentAttributes.colors) {
429
+ attributes.colors = contentAttributes.colors;
430
+ }
431
+
432
+ if (contentAttributes.uvRegions) {
433
+ attributes.uvRegions = contentAttributes.uvRegions;
434
+ }
435
+
436
+ return attributes;
437
+ }
438
+ //# sourceMappingURL=tile-3d-layer.js.map