@openglobus/og 0.22.2 → 0.24.0

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 (205) hide show
  1. package/css/og.css +137 -1
  2. package/lib/@openglobus/js/Globe.d.ts +0 -1
  3. package/lib/@openglobus/js/Object3d.d.ts +20 -10
  4. package/lib/@openglobus/js/camera/Camera.d.ts +57 -15
  5. package/lib/@openglobus/js/camera/Frustum.d.ts +3 -0
  6. package/lib/@openglobus/js/camera/PlanetCamera.d.ts +13 -0
  7. package/lib/@openglobus/js/control/CameraLock.d.ts +38 -0
  8. package/lib/@openglobus/js/control/MouseNavigation.d.ts +62 -51
  9. package/lib/@openglobus/js/control/OldMouseNavigation.d.ts +64 -0
  10. package/lib/@openglobus/js/control/SimpleNavigation.d.ts +27 -10
  11. package/lib/@openglobus/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
  12. package/lib/@openglobus/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
  13. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
  14. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
  15. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
  16. package/lib/@openglobus/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
  17. package/lib/@openglobus/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
  18. package/lib/@openglobus/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
  19. package/lib/@openglobus/js/control/geoObjectEditor/colors.d.ts +8 -0
  20. package/lib/@openglobus/js/control/index.d.ts +3 -2
  21. package/lib/@openglobus/js/entity/Entity.d.ts +282 -19
  22. package/lib/@openglobus/js/entity/EntityCollection.d.ts +8 -9
  23. package/lib/@openglobus/js/entity/GeoObject.d.ts +135 -39
  24. package/lib/@openglobus/js/entity/GeoObjectHandler.d.ts +39 -63
  25. package/lib/@openglobus/js/entity/InstanceData.d.ts +76 -0
  26. package/lib/@openglobus/js/entity/Polyline.d.ts +19 -6
  27. package/lib/@openglobus/js/entity/PolylineHandler.d.ts +7 -0
  28. package/lib/@openglobus/js/index.d.ts +2 -1
  29. package/lib/@openglobus/js/input/MouseHandler.d.ts +1 -0
  30. package/lib/@openglobus/js/layer/Vector.d.ts +4 -0
  31. package/lib/@openglobus/js/light/LightSource.d.ts +1 -139
  32. package/lib/@openglobus/js/math/Mat3.d.ts +1 -1
  33. package/lib/@openglobus/js/math/Mat4.d.ts +10 -1
  34. package/lib/@openglobus/js/math/Plane.d.ts +3 -1
  35. package/lib/@openglobus/js/math/Quat.d.ts +47 -33
  36. package/lib/@openglobus/js/math/Ray.d.ts +10 -14
  37. package/lib/@openglobus/js/math/Vec2.d.ts +22 -0
  38. package/lib/@openglobus/js/math/Vec3.d.ts +15 -0
  39. package/lib/@openglobus/js/math.d.ts +2 -2
  40. package/lib/@openglobus/js/quadTree/EntityCollectionNode.d.ts +2 -2
  41. package/lib/@openglobus/js/quadTree/Node.d.ts +1 -1
  42. package/lib/@openglobus/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
  43. package/lib/@openglobus/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
  44. package/lib/@openglobus/js/renderer/Renderer.d.ts +63 -44
  45. package/lib/@openglobus/js/renderer/RendererEvents.d.ts +2 -0
  46. package/lib/@openglobus/js/scene/Planet.d.ts +15 -7
  47. package/lib/@openglobus/js/scene/RenderNode.d.ts +10 -25
  48. package/lib/@openglobus/js/shaders/drawnode.d.ts +1 -0
  49. package/lib/@openglobus/js/shaders/geoObject.d.ts +1 -0
  50. package/lib/@openglobus/js/shaders/utils.d.ts +1 -1
  51. package/lib/@openglobus/js/ui/Checkbox.d.ts +31 -0
  52. package/lib/@openglobus/js/ui/Dialog.d.ts +3 -0
  53. package/lib/@openglobus/js/ui/Input.d.ts +32 -0
  54. package/lib/@openglobus/js/ui/View.d.ts +3 -1
  55. package/lib/@openglobus/js/utils/objParser.d.ts +44 -12
  56. package/lib/@openglobus/js/utils/shared.d.ts +22 -0
  57. package/lib/@openglobus/js/webgl/BaseFramebuffer.d.ts +0 -1
  58. package/lib/@openglobus/js/webgl/Framebuffer.d.ts +35 -8
  59. package/lib/@openglobus/js/webgl/Handler.d.ts +22 -12
  60. package/lib/@openglobus/og.css +1 -1
  61. package/lib/@openglobus/og.esm.js +1 -1
  62. package/lib/@openglobus/og.esm.js.map +1 -1
  63. package/lib/@openglobus/og.umd.js +1 -1
  64. package/lib/@openglobus/og.umd.js.map +1 -1
  65. package/lib/js/Globe.d.ts +0 -1
  66. package/lib/js/Globe.js +4 -2
  67. package/lib/js/Object3d.d.ts +20 -10
  68. package/lib/js/Object3d.js +124 -48
  69. package/lib/js/Popup.js +1 -1
  70. package/lib/js/camera/Camera.d.ts +57 -15
  71. package/lib/js/camera/Camera.js +109 -29
  72. package/lib/js/camera/Frustum.d.ts +3 -0
  73. package/lib/js/camera/Frustum.js +7 -0
  74. package/lib/js/camera/PlanetCamera.d.ts +13 -0
  75. package/lib/js/camera/PlanetCamera.js +52 -5
  76. package/lib/js/control/Atmosphere.js +10 -6
  77. package/lib/js/control/CameraLock.d.ts +38 -0
  78. package/lib/js/control/CameraLock.js +216 -0
  79. package/lib/js/control/Control.js +1 -1
  80. package/lib/js/control/DebugInfo.js +38 -8
  81. package/lib/js/control/KeyboardNavigation.js +9 -9
  82. package/lib/js/control/MouseNavigation.d.ts +62 -51
  83. package/lib/js/control/MouseNavigation.js +361 -305
  84. package/lib/js/control/MouseWheelZoomControl.d.ts +0 -44
  85. package/lib/js/control/MouseWheelZoomControl.js +270 -181
  86. package/lib/js/control/OldMouseNavigation.d.ts +64 -0
  87. package/lib/js/control/OldMouseNavigation.js +368 -0
  88. package/lib/js/control/ScaleControl.js +11 -5
  89. package/lib/js/control/SimpleNavigation.d.ts +27 -10
  90. package/lib/js/control/SimpleNavigation.js +149 -49
  91. package/lib/js/control/Sun.js +6 -6
  92. package/lib/js/control/TouchNavigation.js +11 -8
  93. package/lib/js/control/elevationProfile/ElevationProfileScene.js +6 -5
  94. package/lib/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
  95. package/lib/js/control/geoObjectEditor/ArrowEntity.js +59 -0
  96. package/lib/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
  97. package/lib/js/control/geoObjectEditor/AxisTrackEntity.js +93 -0
  98. package/lib/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
  99. package/lib/js/control/geoObjectEditor/GeoObjectEditor.js +30 -0
  100. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
  101. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.js +488 -0
  102. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
  103. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.js +487 -43
  104. package/lib/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
  105. package/lib/js/control/geoObjectEditor/MoveAxisEntity.js +107 -0
  106. package/lib/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
  107. package/lib/js/control/geoObjectEditor/MovePlaneEntity.js +31 -0
  108. package/lib/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
  109. package/lib/js/control/geoObjectEditor/RotateEntity.js +105 -0
  110. package/lib/js/control/geoObjectEditor/colors.d.ts +8 -0
  111. package/lib/js/control/geoObjectEditor/colors.js +8 -0
  112. package/lib/js/control/index.d.ts +3 -2
  113. package/lib/js/control/index.js +3 -2
  114. package/lib/js/control/timeline/TimelineControl.js +2 -0
  115. package/lib/js/control/visibleExtent/Segment.js +4 -4
  116. package/lib/js/entity/Entity.d.ts +282 -19
  117. package/lib/js/entity/Entity.js +497 -62
  118. package/lib/js/entity/EntityCollection.d.ts +8 -9
  119. package/lib/js/entity/EntityCollection.js +48 -45
  120. package/lib/js/entity/GeoObject.d.ts +135 -39
  121. package/lib/js/entity/GeoObject.js +150 -90
  122. package/lib/js/entity/GeoObjectHandler.d.ts +39 -63
  123. package/lib/js/entity/GeoObjectHandler.js +198 -295
  124. package/lib/js/entity/InstanceData.d.ts +76 -0
  125. package/lib/js/entity/InstanceData.js +347 -0
  126. package/lib/js/entity/Polyline.d.ts +19 -6
  127. package/lib/js/entity/Polyline.js +76 -36
  128. package/lib/js/entity/PolylineHandler.d.ts +7 -0
  129. package/lib/js/entity/PolylineHandler.js +26 -1
  130. package/lib/js/index.d.ts +2 -1
  131. package/lib/js/index.js +2 -1
  132. package/lib/js/input/MouseHandler.d.ts +1 -0
  133. package/lib/js/input/MouseHandler.js +12 -1
  134. package/lib/js/layer/Bing.js +2 -2
  135. package/lib/js/layer/Vector.d.ts +4 -0
  136. package/lib/js/layer/Vector.js +16 -0
  137. package/lib/js/light/LightSource.d.ts +1 -139
  138. package/lib/js/light/LightSource.js +21 -227
  139. package/lib/js/math/Mat3.d.ts +1 -1
  140. package/lib/js/math/Mat3.js +1 -1
  141. package/lib/js/math/Mat4.d.ts +10 -1
  142. package/lib/js/math/Mat4.js +17 -1
  143. package/lib/js/math/Plane.d.ts +3 -1
  144. package/lib/js/math/Plane.js +11 -1
  145. package/lib/js/math/Quat.d.ts +47 -33
  146. package/lib/js/math/Quat.js +92 -90
  147. package/lib/js/math/Ray.d.ts +10 -14
  148. package/lib/js/math/Ray.js +56 -33
  149. package/lib/js/math/Vec2.d.ts +22 -0
  150. package/lib/js/math/Vec2.js +32 -0
  151. package/lib/js/math/Vec3.d.ts +15 -0
  152. package/lib/js/math/Vec3.js +30 -1
  153. package/lib/js/math.d.ts +2 -2
  154. package/lib/js/math.js +3 -3
  155. package/lib/js/quadTree/EntityCollectionNode.d.ts +2 -2
  156. package/lib/js/quadTree/EntityCollectionNode.js +8 -8
  157. package/lib/js/quadTree/Node.d.ts +1 -1
  158. package/lib/js/quadTree/Node.js +2 -2
  159. package/lib/js/quadTree/QuadTreeStrategy.js +1 -1
  160. package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
  161. package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.js +2 -2
  162. package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
  163. package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.js +2 -2
  164. package/lib/js/renderer/Renderer.d.ts +63 -44
  165. package/lib/js/renderer/Renderer.js +267 -266
  166. package/lib/js/renderer/RendererEvents.d.ts +2 -0
  167. package/lib/js/renderer/RendererEvents.js +5 -2
  168. package/lib/js/scene/Planet.d.ts +15 -7
  169. package/lib/js/scene/Planet.js +133 -90
  170. package/lib/js/scene/RenderNode.d.ts +10 -25
  171. package/lib/js/scene/RenderNode.js +70 -58
  172. package/lib/js/segment/Segment.js +4 -4
  173. package/lib/js/shaders/depth.js +2 -5
  174. package/lib/js/shaders/drawnode.d.ts +1 -0
  175. package/lib/js/shaders/drawnode.js +51 -52
  176. package/lib/js/shaders/geoObject.d.ts +1 -0
  177. package/lib/js/shaders/geoObject.js +154 -91
  178. package/lib/js/shaders/polyline.js +68 -51
  179. package/lib/js/shaders/utils.d.ts +1 -1
  180. package/lib/js/shaders/utils.js +11 -0
  181. package/lib/js/terrain/GlobusTerrain.js +2 -2
  182. package/lib/js/ui/Checkbox.d.ts +31 -0
  183. package/lib/js/ui/Checkbox.js +110 -0
  184. package/lib/js/ui/Color.js +2 -1
  185. package/lib/js/ui/Dialog.d.ts +3 -0
  186. package/lib/js/ui/Dialog.js +20 -0
  187. package/lib/js/ui/Input.d.ts +32 -0
  188. package/lib/js/ui/Input.js +107 -0
  189. package/lib/js/ui/View.d.ts +3 -1
  190. package/lib/js/ui/View.js +6 -0
  191. package/lib/js/utils/objParser.d.ts +44 -12
  192. package/lib/js/utils/objParser.js +241 -149
  193. package/lib/js/utils/shared.d.ts +22 -0
  194. package/lib/js/utils/shared.js +34 -0
  195. package/lib/js/webgl/BaseFramebuffer.d.ts +0 -1
  196. package/lib/js/webgl/Framebuffer.d.ts +35 -8
  197. package/lib/js/webgl/Framebuffer.js +136 -29
  198. package/lib/js/webgl/Handler.d.ts +22 -12
  199. package/lib/js/webgl/Handler.js +53 -34
  200. package/lib/js/webgl/Program.js +0 -8
  201. package/package.json +5 -3
  202. package/lib/@openglobus/js/control/EarthNavigation.d.ts +0 -50
  203. package/lib/@openglobus/js/control/MouseWheelZoomControl.d.ts +0 -44
  204. package/lib/js/control/EarthNavigation.d.ts +0 -50
  205. package/lib/js/control/EarthNavigation.js +0 -202
@@ -1,179 +1,271 @@
1
- export function objParser(text) {
2
- const objPositions = [[0, 0, 0]];
3
- const objTexcoords = [[0, 0]];
4
- const objNormals = [[0, 0, 0]];
5
- // same order as `f` indices
6
- const objVertexData = [
7
- objPositions,
8
- objTexcoords,
9
- objNormals,
10
- ];
11
- // same order as `f` indices
12
- let vertexData = [
13
- [], // positions
14
- [], // texcoords
15
- [], // normals
16
- ];
17
- const materialLibs = [];
18
- const geometries = [];
19
- let geometry;
20
- let groups = ['default'];
21
- let material = 'default';
22
- let object = 'default';
23
- function newGeometry() {
1
+ function getTexturePath(path) {
2
+ let p = path.split('/');
3
+ let filename = p[p.length - 1];
4
+ let folder = p[p.length - 2];
5
+ return `${folder ? folder + "/" : ""}${filename}`;
6
+ }
7
+ export class Obj {
8
+ constructor() {
9
+ this.objPositions = [];
10
+ this.objTexcoords = [];
11
+ this.objNormals = [];
12
+ // same order as `f` indices
13
+ this.objVertexData = [
14
+ this.objPositions,
15
+ this.objTexcoords,
16
+ this.objNormals,
17
+ ];
18
+ // same order as `f` indices
19
+ this.vertexData = [
20
+ [], // positions
21
+ [], // texcoords
22
+ [], // normals
23
+ ];
24
+ this._materialLibs = [];
25
+ this.geometries = [];
26
+ this.geometry = null;
27
+ this.materials = {};
28
+ this.material = {};
29
+ this.object = 'default';
30
+ this.groups = ['default'];
31
+ this._path = "";
32
+ this.keywords = {
33
+ v: (parts) => {
34
+ this.objPositions.push(parts.map(parseFloat));
35
+ },
36
+ vn: (parts) => {
37
+ this.objNormals.push(parts.map(parseFloat));
38
+ },
39
+ vt: (parts) => {
40
+ // should check for missing v and extra w?
41
+ this.objTexcoords.push([parseFloat(parts[0]), 1.0 - parseFloat(parts[1])]);
42
+ },
43
+ f: (parts) => {
44
+ this.setGeometry();
45
+ const numTriangles = parts.length - 2;
46
+ for (let tri = 0; tri < numTriangles; ++tri) {
47
+ this.addVertex(parts[0]);
48
+ this.addVertex(parts[tri + 1]);
49
+ this.addVertex(parts[tri + 2]);
50
+ }
51
+ },
52
+ s: () => {
53
+ // skip texture scale
54
+ },
55
+ mtllib: (parts, unparsedArgs) => {
56
+ // the spec says there can be multiple filenames here
57
+ // but many exist with spaces in a single filename
58
+ this._materialLibs.push(unparsedArgs);
59
+ },
60
+ usemtl: (parts, unparsedArgs) => {
61
+ this.newGeometry();
62
+ this.setGeometry();
63
+ if (this.geometry) {
64
+ this.geometry.material = unparsedArgs;
65
+ }
66
+ },
67
+ g: (parts) => {
68
+ this.groups = parts;
69
+ this.newGeometry();
70
+ },
71
+ o: (parts, unparsedArgs) => {
72
+ this.object = unparsedArgs;
73
+ this.newGeometry();
74
+ },
75
+ newmtl: (parts, unparsedArgs) => {
76
+ const material = {};
77
+ this.material = material;
78
+ this.materials[unparsedArgs] = material;
79
+ },
80
+ Ns: (parts, unparsedArgs) => {
81
+ this.material.shininess = parseFloat(unparsedArgs);
82
+ },
83
+ Ni: (parts, unparsedArgs) => {
84
+ // skip refraction
85
+ },
86
+ Ka: (parts, unparsedArgs) => {
87
+ this.material.ambient = parts.map(v => parseFloat(v));
88
+ },
89
+ Kd: (parts, unparsedArgs) => {
90
+ this.material.diffuse = parts.map(v => parseFloat(v));
91
+ },
92
+ Ks: (parts, unparsedArgs) => {
93
+ this.material.specular = parts.map(v => parseFloat(v));
94
+ },
95
+ Ke: (parts, unparsedArgs) => {
96
+ this.material.color = parts.map(v => parseFloat(v));
97
+ },
98
+ illum: (parts, unparsedArgs) => {
99
+ this.material.illum = parseFloat(unparsedArgs);
100
+ },
101
+ d: (parts, unparsedArgs) => {
102
+ this.material.opacity = parseFloat(unparsedArgs);
103
+ },
104
+ Tr: (parts, unparsedArgs) => {
105
+ this.material.opacity = parseFloat(unparsedArgs);
106
+ },
107
+ Tf: (parts, unparsedArgs) => {
108
+ // skip transmission filter
109
+ },
110
+ map_Ka: (parts, unparsedArgs) => {
111
+ // skip ambient texture
112
+ },
113
+ map_Kd: (parts, unparsedArgs) => {
114
+ this.material.colorTexture = `${this._path}/${getTexturePath(unparsedArgs)}`;
115
+ },
116
+ map_Bump: (parts, unparsedArgs) => {
117
+ this.material.normalTexture = `${this._path}/${getTexturePath(unparsedArgs)}`;
118
+ },
119
+ map_Ns: (parts, unparsedArgs) => {
120
+ this.material.metallicRoughnessTexture = `${this._path}/${getTexturePath(unparsedArgs)}`;
121
+ },
122
+ };
123
+ }
124
+ newGeometry() {
24
125
  // If there is an existing geometry and it's
25
126
  // not empty then start a new one.
26
- if (geometry && geometry.data.vertices.length) {
27
- geometry = null;
127
+ if (this.geometry && this.geometry.data.vertices.length) {
128
+ this.geometry = null;
28
129
  }
29
130
  }
30
- function setGeometry() {
31
- if (!geometry) {
131
+ setGeometry() {
132
+ if (!this.geometry) {
32
133
  const vertices = [];
33
- const textures = [];
134
+ const texCoords = [];
34
135
  const normals = [];
35
- vertexData = [
136
+ this.vertexData = [
36
137
  vertices,
37
- textures,
138
+ texCoords,
38
139
  normals,
39
140
  ];
40
- geometry = {
41
- object,
42
- groups,
43
- material,
141
+ this.geometry = {
142
+ object: this.object,
143
+ groups: this.groups,
144
+ material: "",
44
145
  data: {
45
146
  vertices,
46
- textures,
147
+ texCoords,
47
148
  normals,
48
149
  },
49
150
  };
50
- geometries.push(geometry);
151
+ this.geometries.push(this.geometry);
51
152
  }
52
153
  }
53
- function addVertex(vert) {
54
- const ptn = vert.split('/');
55
- ptn.forEach((objIndexStr, i) => {
154
+ addVertex(vert) {
155
+ let ptn = vert.split('/');
156
+ for (let i = 0; i < ptn.length; i++) {
157
+ let objIndexStr = ptn[i];
56
158
  if (!objIndexStr) {
57
- return;
159
+ continue;
58
160
  }
59
- const objIndex = parseInt(objIndexStr);
60
- const index = objIndex + (objIndex >= 0 ? 0 : objVertexData[i].length);
61
- vertexData[i].push(...objVertexData[i][index]);
62
- });
63
- }
64
- const keywords = {
65
- v(parts) {
66
- objPositions.push(parts.map(parseFloat));
67
- },
68
- vn(parts) {
69
- objNormals.push(parts.map(parseFloat));
70
- },
71
- vt(parts) {
72
- // should check for missing v and extra w?
73
- objTexcoords.push(parts.map(parseFloat));
74
- },
75
- f(parts) {
76
- setGeometry();
77
- const numTriangles = parts.length - 2;
78
- for (let tri = 0; tri < numTriangles; ++tri) {
79
- addVertex(parts[0]);
80
- addVertex(parts[tri + 1]);
81
- addVertex(parts[tri + 2]);
161
+ let index = parseInt(objIndexStr) - 1;
162
+ let v = this.vertexData[i];
163
+ let len = v.length;
164
+ let d = this.objVertexData[i][index];
165
+ let dlen = d.length;
166
+ this.vertexData[i].length = len + dlen;
167
+ for (let j = 0; j < dlen; j++) {
168
+ v[len + j] = d[j];
82
169
  }
83
- },
84
- s: () => {
85
- }, // smoothing group
86
- mtllib(parts, unparsedArgs) {
87
- // the spec says there can be multiple filenames here
88
- // but many exist with spaces in a single filename
89
- materialLibs.push(unparsedArgs);
90
- },
91
- usemtl(parts, unparsedArgs) {
92
- material = unparsedArgs;
93
- newGeometry();
94
- },
95
- g(parts) {
96
- groups = parts;
97
- newGeometry();
98
- },
99
- o(parts, unparsedArgs) {
100
- object = unparsedArgs;
101
- newGeometry();
102
- },
103
- };
104
- const keywordRE = /(\w*)(?: )*(.*)/;
105
- const lines = text.split('\n');
106
- for (let lineNo = 0; lineNo < lines.length; ++lineNo) {
107
- const line = lines[lineNo].trim();
108
- if (line === '' || line.startsWith('#')) {
109
- continue;
110
170
  }
111
- const m = keywordRE.exec(line);
112
- if (!m) {
113
- continue;
114
- }
115
- const [, keyword, unparsedArgs] = m;
116
- const parts = line.split(/\s+/).slice(1);
117
- const handler = keywords[keyword];
118
- if (!handler) {
119
- console.warn('unhandled keyword:', keyword); // eslint-disable-line no-console
120
- continue;
171
+ }
172
+ _innerParser(text, fileName) {
173
+ const keywordRE = /(\w*)(?: )*(.*)/;
174
+ const lines = text.split('\n');
175
+ for (let lineNo = 0; lineNo < lines.length; ++lineNo) {
176
+ const line = lines[lineNo].trim();
177
+ if (line === '' || line.startsWith('#')) {
178
+ continue;
179
+ }
180
+ const m = keywordRE.exec(line);
181
+ if (!m) {
182
+ continue;
183
+ }
184
+ const [, keyword, unparsedArgs] = m;
185
+ const parts = line.split(/\s+/).slice(1);
186
+ const handler = this.keywords[keyword];
187
+ if (!handler) {
188
+ console.warn(`Unknown keyword '${keyword}' in '${fileName}:${lineNo}'`); // eslint-disable-line no-console
189
+ continue;
190
+ }
191
+ handler(parts, unparsedArgs);
121
192
  }
122
- handler(parts, unparsedArgs);
123
193
  }
124
- // remove any arrays that have no entries.
125
- for (const geometry of geometries) {
126
- geometry.data = Object.fromEntries(Object.entries(geometry.data).filter(([key, array]) => array.length > 0));
194
+ get data() {
195
+ return {
196
+ geometries: this.geometries,
197
+ materials: this.materials
198
+ };
127
199
  }
128
- return {
129
- geometries,
130
- materialLibs,
131
- };
132
- }
133
- export function transformLeftToRightCoordinateSystem(objData) {
134
- const convertedGeometries = objData.geometries.map(geometry => {
135
- const vertices = geometry.data.vertices;
136
- const normals = geometry.data.normals;
137
- const textures = geometry.data.textures;
138
- rotateObject(geometry.data, 0);
139
- let convertedVertices = [];
140
- let convertedNormals = [];
141
- let convertedTextures = [];
142
- // Convert positions
143
- for (let i = 0; i < vertices.length; i += 3) {
144
- const x = vertices[i];
145
- const y = vertices[i + 1];
146
- const z = vertices[i + 2];
147
- convertedVertices.push(x, y, z);
200
+ async load(src) {
201
+ this._path = src.substring(0, src.lastIndexOf("/"));
202
+ const response = await fetch(src);
203
+ if (!response.ok) {
204
+ throw new Error(`Unable to load '${src}'`);
148
205
  }
149
- // Convert normals
150
- for (let i = 0; i < normals.length; i += 3) {
151
- const x = normals[i];
152
- const y = normals[i + 1];
153
- const z = normals[i + 2];
154
- convertedNormals.push(x, y, -z);
206
+ const reader = response.body.getReader();
207
+ const decoder = new TextDecoder();
208
+ let { value, done } = await reader.read();
209
+ let partialLine = '';
210
+ while (!done) {
211
+ const text = decoder.decode(value, { stream: true });
212
+ const lines = (partialLine + text).split('\n');
213
+ partialLine = lines.pop();
214
+ for (const line of lines) {
215
+ this._innerParser(line, src);
216
+ }
217
+ ({ value, done } = await reader.read());
155
218
  }
156
- // Convert textures
157
- for (let i = 0; i < textures.length; i += 2) {
158
- const s = textures[i];
159
- const t = 1 - textures[i + 1];
160
- convertedTextures.push(s, t);
219
+ if (partialLine) {
220
+ this._innerParser(partialLine, src);
161
221
  }
162
- return {
163
- object: geometry.object,
164
- groups: geometry.groups,
165
- material: geometry.material,
166
- data: {
167
- vertices: convertedVertices,
168
- normals: convertedNormals,
169
- textures: convertedTextures
222
+ this._cleanupGeometryArrays();
223
+ let defArr = this._materialLibs.map(filename => {
224
+ filename = `${this._path}/${filename}`;
225
+ return fetch(filename)
226
+ .then((response) => response.text())
227
+ .then((text) => {
228
+ return { text, filename };
229
+ });
230
+ });
231
+ await Promise.all(defArr).then((mtlArr) => {
232
+ mtlArr.forEach(mtl => this._innerParser(mtl.text, mtl.filename));
233
+ });
234
+ return this.data;
235
+ }
236
+ async _readAndParse(file) {
237
+ const stream = file.stream();
238
+ const reader = stream.getReader();
239
+ const decoder = new TextDecoder();
240
+ let { value, done } = await reader.read();
241
+ let partialLine = "";
242
+ while (!done) {
243
+ const text = decoder.decode(value, { stream: true });
244
+ const lines = (partialLine + text).split("\n");
245
+ partialLine = lines.pop();
246
+ for (const line of lines) {
247
+ this._innerParser(line, file.name);
170
248
  }
171
- };
172
- });
173
- return {
174
- geometries: convertedGeometries,
175
- materialLibs: objData.materialLibs
176
- };
249
+ ({ value, done } = await reader.read());
250
+ }
251
+ if (partialLine) {
252
+ this._innerParser(partialLine, file.name);
253
+ }
254
+ }
255
+ async readFile(objFile, mtlFile) {
256
+ this._path = "";
257
+ await this._readAndParse(objFile);
258
+ this._cleanupGeometryArrays();
259
+ if (mtlFile) {
260
+ await this._readAndParse(mtlFile);
261
+ }
262
+ return this.data;
263
+ }
264
+ _cleanupGeometryArrays() {
265
+ for (const geometry of this.geometries) {
266
+ geometry.data = Object.fromEntries(Object.entries(geometry.data).filter(([key, array]) => array.length > 0));
267
+ }
268
+ }
177
269
  }
178
270
  function rotateObject(obj, angle) {
179
271
  const cosA = Math.cos(angle);
@@ -7,6 +7,7 @@ import { Vec2 } from "../math/Vec2";
7
7
  import { NumberArray2 } from "../math/Vec2";
8
8
  import { NumberArray3, Vec3 } from "../math/Vec3";
9
9
  import { NumberArray4, Vec4 } from "../math/Vec4";
10
+ import { Ellipsoid } from "../ellipsoid/Ellipsoid";
10
11
  export declare function getDefault(param?: any, def?: any): boolean;
11
12
  export declare function isEmpty(v: any): boolean;
12
13
  /**
@@ -261,3 +262,24 @@ export declare function isImageLoaded(image: HTMLImageElement): boolean;
261
262
  export declare function distanceFormat(v: number): string;
262
263
  export declare function distanceFormatExt(v: number): [string, string];
263
264
  export declare function getUrlParam(paramName: string): number | undefined;
265
+ /**
266
+ *
267
+ * @param x
268
+ * @param y
269
+ * @param z
270
+ * @param imageSize
271
+ * @param ellipsoid
272
+ *
273
+ * console.log(1, getTileImageResolution(0, 0, 1));
274
+ * console.log(7, getTileImageResolution(66, 44, 7));
275
+ * console.log(10, getTileImageResolution(536, 358, 10));
276
+ * console.log(12, getTileImageResolution(2149, 1446, 12));
277
+ * console.log(13, getTileImageResolution(4301, 2892, 13));
278
+ * console.log(14, getTileImageResolution(8582, 5736, 14));
279
+ * console.log(15, getTileImageResolution(17205, 11569, 15));
280
+ * console.log(16, getTileImageResolution(34419, 23138, 16));
281
+ * console.log(17, getTileImageResolution(68661, 45892, 17));
282
+ * console.log(18, getTileImageResolution(137650, 92555, 18));
283
+ */
284
+ export declare function getTileImageResolution(x: number, y: number, z: number, imageSize?: number, ellipsoid?: Ellipsoid): number[];
285
+ export declare function toFixedMax(value: number, maxFixed?: number): string;
@@ -7,6 +7,8 @@ import { Vec2 } from "../math/Vec2";
7
7
  import { Vec3 } from "../math/Vec3";
8
8
  import { Vec4 } from "../math/Vec4";
9
9
  import { colorTable } from "./colorTable";
10
+ import { wgs84 } from "../ellipsoid/wgs84";
11
+ import * as mercator from "../mercator";
10
12
  export function getDefault(param, def) {
11
13
  return param != undefined ? param : def;
12
14
  }
@@ -925,3 +927,35 @@ export function getUrlParam(paramName) {
925
927
  return Number(param);
926
928
  }
927
929
  }
930
+ /**
931
+ *
932
+ * @param x
933
+ * @param y
934
+ * @param z
935
+ * @param imageSize
936
+ * @param ellipsoid
937
+ *
938
+ * console.log(1, getTileImageResolution(0, 0, 1));
939
+ * console.log(7, getTileImageResolution(66, 44, 7));
940
+ * console.log(10, getTileImageResolution(536, 358, 10));
941
+ * console.log(12, getTileImageResolution(2149, 1446, 12));
942
+ * console.log(13, getTileImageResolution(4301, 2892, 13));
943
+ * console.log(14, getTileImageResolution(8582, 5736, 14));
944
+ * console.log(15, getTileImageResolution(17205, 11569, 15));
945
+ * console.log(16, getTileImageResolution(34419, 23138, 16));
946
+ * console.log(17, getTileImageResolution(68661, 45892, 17));
947
+ * console.log(18, getTileImageResolution(137650, 92555, 18));
948
+ */
949
+ export function getTileImageResolution(x, y, z, imageSize = 256, ellipsoid = wgs84) {
950
+ let ext = mercator.getTileExtent(x, y, z);
951
+ let b0 = ext.getSouthWest().inverseMercator(), b1 = ext.getNorthEast().inverseMercator();
952
+ let width = ellipsoid.getGreatCircleDistance(b0, new LonLat(b1.lon, b0.lat)), height = ellipsoid.getGreatCircleDistance(b0, new LonLat(b0.lon, b1.lat));
953
+ return [width / imageSize, height / imageSize];
954
+ }
955
+ export function toFixedMax(value, maxFixed = -1) {
956
+ if (maxFixed < 0) {
957
+ return value.toString();
958
+ }
959
+ const factor = Math.pow(10, maxFixed);
960
+ return (Math.round(value * factor) / factor).toString();
961
+ }
@@ -1,6 +1,5 @@
1
1
  import { Handler } from "./Handler";
2
2
  export interface IBaseFramebufferParams {
3
- internalFormat?: string | string[];
4
3
  width?: number;
5
4
  height?: number;
6
5
  useDepth?: boolean;
@@ -1,13 +1,37 @@
1
1
  import { BaseFramebuffer, IBaseFramebufferParams } from "./BaseFramebuffer";
2
2
  import { Handler } from "./Handler";
3
+ import { TypedArray } from "../utils/shared";
4
+ export interface ITargetParams {
5
+ internalFormat?: string;
6
+ format?: string;
7
+ type?: string;
8
+ attachment?: string;
9
+ filter?: string;
10
+ readAsync?: boolean;
11
+ }
3
12
  export interface IFrameBufferParams extends IBaseFramebufferParams {
4
13
  isBare?: boolean;
5
- format?: string | string[];
6
- type?: string | string[];
7
- attachment?: string | string[];
8
14
  renderbufferTarget?: string;
9
15
  textures?: WebGLTexture[];
16
+ targets?: ITargetParams[];
17
+ }
18
+ type TypedArrayConstructor = Uint8ArrayConstructor | Float32ArrayConstructor;
19
+ interface ITarget {
20
+ internalFormat: string;
21
+ format: string;
22
+ type: string;
23
+ attachment: string;
24
+ filter: string;
25
+ pixelBufferIndex: number;
26
+ TypeArrayConstructor: TypedArrayConstructor;
27
+ }
28
+ interface IPixelBuffer {
29
+ buffer: WebGLBuffer | null;
30
+ data: TypedArray | null;
31
+ glType: number;
32
+ glAttachment: number;
10
33
  }
34
+ export declare function clientWaitAsync(gl: WebGL2RenderingContext, sync: WebGLSync, flags: number): Promise<void>;
11
35
  /**
12
36
  * Class represents framebuffer.
13
37
  * @class
@@ -15,19 +39,18 @@ export interface IFrameBufferParams extends IBaseFramebufferParams {
15
39
  * @param {IFrameBufferParams} [options] - Framebuffer options:
16
40
  */
17
41
  export declare class Framebuffer extends BaseFramebuffer {
18
- protected _isBare: boolean;
19
- protected _internalFormatArr: string[];
20
- protected _formatArr: string[];
21
- protected _typeArr: string[];
22
- protected _attachmentArr: string[];
23
42
  protected _renderbufferTarget: string;
43
+ protected _targets: ITarget[];
24
44
  /**
25
45
  * Framebuffer texture.
26
46
  * @public
27
47
  * @type {number}
28
48
  */
29
49
  textures: WebGLTexture[];
50
+ pixelBuffers: IPixelBuffer[];
51
+ protected _skipFrame: boolean;
30
52
  constructor(handler: Handler, options?: IFrameBufferParams);
53
+ static createTargets(targets?: ITargetParams[]): ITarget[];
31
54
  destroy(): void;
32
55
  /**
33
56
  * Framebuffer initialization.
@@ -35,6 +58,9 @@ export declare class Framebuffer extends BaseFramebuffer {
35
58
  * @override
36
59
  */
37
60
  init(): void;
61
+ readPixelBuffersAsync: () => void;
62
+ getPixelBufferData(targetIndex: number): TypedArray | null;
63
+ protected _createPixelBuffer(target: ITarget): void;
38
64
  /**
39
65
  * Bind buffer texture.
40
66
  * @public
@@ -67,3 +93,4 @@ export declare class Framebuffer extends BaseFramebuffer {
67
93
  */
68
94
  getImage(): HTMLImageElement;
69
95
  }
96
+ export {};