@fc3/wireframe-renderer 0.0.0-stage → 0.2.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 (343) hide show
  1. package/LICENSE +673 -0
  2. package/README.md +165 -2
  3. package/bin/bootstrap/terminal-demo +7 -0
  4. package/bin/compile +55 -0
  5. package/bin/install +5 -0
  6. package/bin/lint +12 -0
  7. package/bin/postpublish +5 -0
  8. package/bin/precompile +71 -0
  9. package/bin/prepublish +7 -0
  10. package/bin/remap-paths +172 -0
  11. package/bin/test +9 -0
  12. package/bin/test-one +32 -0
  13. package/dist/.last-compile-time +1 -0
  14. package/dist/.last-publish-time +1 -0
  15. package/dist/src/bootstrap/terminal-demo.d.ts +1 -0
  16. package/dist/src/bootstrap/terminal-demo.js +14 -0
  17. package/dist/src/bootstrap/terminal-demo.js.map +1 -0
  18. package/dist/src/camera.d.ts +26 -0
  19. package/dist/src/camera.js +90 -0
  20. package/dist/src/camera.js.map +1 -0
  21. package/dist/src/canvas-renderer.d.ts +20 -0
  22. package/dist/src/canvas-renderer.js +137 -0
  23. package/dist/src/canvas-renderer.js.map +1 -0
  24. package/dist/src/constant/axis-colors.d.ts +3 -0
  25. package/dist/src/constant/axis-colors.js +13 -0
  26. package/dist/src/constant/axis-colors.js.map +1 -0
  27. package/dist/src/constant/box-edge-index-pairs.d.ts +2 -0
  28. package/dist/src/constant/box-edge-index-pairs.js +18 -0
  29. package/dist/src/constant/box-edge-index-pairs.js.map +1 -0
  30. package/dist/src/constant/camera-limits.d.ts +7 -0
  31. package/dist/src/constant/camera-limits.js +10 -0
  32. package/dist/src/constant/camera-limits.js.map +1 -0
  33. package/dist/src/constant/default-camera-state.d.ts +3 -0
  34. package/dist/src/constant/default-camera-state.js +19 -0
  35. package/dist/src/constant/default-camera-state.js.map +1 -0
  36. package/dist/src/constant/default-palette.d.ts +2 -0
  37. package/dist/src/constant/default-palette.js +17 -0
  38. package/dist/src/constant/default-palette.js.map +1 -0
  39. package/dist/src/constant/default-render-options.d.ts +3 -0
  40. package/dist/src/constant/default-render-options.js +8 -0
  41. package/dist/src/constant/default-render-options.js.map +1 -0
  42. package/dist/src/constant/interaction-rates.d.ts +5 -0
  43. package/dist/src/constant/interaction-rates.js +8 -0
  44. package/dist/src/constant/interaction-rates.js.map +1 -0
  45. package/dist/src/constant/rendering-defaults.d.ts +11 -0
  46. package/dist/src/constant/rendering-defaults.js +14 -0
  47. package/dist/src/constant/rendering-defaults.js.map +1 -0
  48. package/dist/src/constant/stylesheet.d.ts +2 -0
  49. package/dist/src/constant/stylesheet.js +140 -0
  50. package/dist/src/constant/stylesheet.js.map +1 -0
  51. package/dist/src/constant/theme.d.ts +9 -0
  52. package/dist/src/constant/theme.js +12 -0
  53. package/dist/src/constant/theme.js.map +1 -0
  54. package/dist/src/constant/view-orientations.d.ts +4 -0
  55. package/dist/src/constant/view-orientations.js +19 -0
  56. package/dist/src/constant/view-orientations.js.map +1 -0
  57. package/dist/src/enum/axis.d.ts +6 -0
  58. package/dist/src/enum/axis.js +10 -0
  59. package/dist/src/enum/axis.js.map +1 -0
  60. package/dist/src/enum/opening-shape.d.ts +5 -0
  61. package/dist/src/enum/opening-shape.js +9 -0
  62. package/dist/src/enum/opening-shape.js.map +1 -0
  63. package/dist/src/enum/plane.d.ts +6 -0
  64. package/dist/src/enum/plane.js +10 -0
  65. package/dist/src/enum/plane.js.map +1 -0
  66. package/dist/src/enum/primitive-type.d.ts +8 -0
  67. package/dist/src/enum/primitive-type.js +12 -0
  68. package/dist/src/enum/primitive-type.js.map +1 -0
  69. package/dist/src/enum/view-preset.d.ts +10 -0
  70. package/dist/src/enum/view-preset.js +14 -0
  71. package/dist/src/enum/view-preset.js.map +1 -0
  72. package/dist/src/enum/viewer-class-name.d.ts +15 -0
  73. package/dist/src/enum/viewer-class-name.js +19 -0
  74. package/dist/src/enum/viewer-class-name.js.map +1 -0
  75. package/dist/src/example/house-computer.d.ts +3 -0
  76. package/dist/src/example/house-computer.js +2081 -0
  77. package/dist/src/example/house-computer.js.map +1 -0
  78. package/dist/src/index.d.ts +20 -0
  79. package/dist/src/index.js +27 -0
  80. package/dist/src/index.js.map +1 -0
  81. package/dist/src/interaction-controller.d.ts +17 -0
  82. package/dist/src/interaction-controller.js +106 -0
  83. package/dist/src/interaction-controller.js.map +1 -0
  84. package/dist/src/sidebar.d.ts +24 -0
  85. package/dist/src/sidebar.js +121 -0
  86. package/dist/src/sidebar.js.map +1 -0
  87. package/dist/src/terminal/braille-canvas.d.ts +17 -0
  88. package/dist/src/terminal/braille-canvas.js +137 -0
  89. package/dist/src/terminal/braille-canvas.js.map +1 -0
  90. package/dist/src/terminal/constant/terminal-key-rates.d.ts +6 -0
  91. package/dist/src/terminal/constant/terminal-key-rates.js +9 -0
  92. package/dist/src/terminal/constant/terminal-key-rates.js.map +1 -0
  93. package/dist/src/terminal/constant/view-preset-keys.d.ts +3 -0
  94. package/dist/src/terminal/constant/view-preset-keys.js +17 -0
  95. package/dist/src/terminal/constant/view-preset-keys.js.map +1 -0
  96. package/dist/src/terminal/enum/terminal-focus.d.ts +5 -0
  97. package/dist/src/terminal/enum/terminal-focus.js +9 -0
  98. package/dist/src/terminal/enum/terminal-focus.js.map +1 -0
  99. package/dist/src/terminal/index.d.ts +3 -0
  100. package/dist/src/terminal/index.js +11 -0
  101. package/dist/src/terminal/index.js.map +1 -0
  102. package/dist/src/terminal/render-frame.d.ts +6 -0
  103. package/dist/src/terminal/render-frame.js +46 -0
  104. package/dist/src/terminal/render-frame.js.map +1 -0
  105. package/dist/src/terminal/terminal-viewer.d.ts +38 -0
  106. package/dist/src/terminal/terminal-viewer.js +290 -0
  107. package/dist/src/terminal/terminal-viewer.js.map +1 -0
  108. package/dist/src/terminal/type/rgb-color.d.ts +6 -0
  109. package/dist/src/terminal/type/rgb-color.js +3 -0
  110. package/dist/src/terminal/type/rgb-color.js.map +1 -0
  111. package/dist/src/terminal/utility/blend-color.d.ts +3 -0
  112. package/dist/src/terminal/utility/blend-color.js +19 -0
  113. package/dist/src/terminal/utility/blend-color.js.map +1 -0
  114. package/dist/src/terminal/utility/clip-segment.d.ts +5 -0
  115. package/dist/src/terminal/utility/clip-segment.js +38 -0
  116. package/dist/src/terminal/utility/clip-segment.js.map +1 -0
  117. package/dist/src/terminal/utility/escape-tags.d.ts +2 -0
  118. package/dist/src/terminal/utility/escape-tags.js +14 -0
  119. package/dist/src/terminal/utility/escape-tags.js.map +1 -0
  120. package/dist/src/terminal/utility/format-component-row.d.ts +3 -0
  121. package/dist/src/terminal/utility/format-component-row.js +32 -0
  122. package/dist/src/terminal/utility/format-component-row.js.map +1 -0
  123. package/dist/src/terminal/utility/format-hex-color.d.ts +3 -0
  124. package/dist/src/terminal/utility/format-hex-color.js +14 -0
  125. package/dist/src/terminal/utility/format-hex-color.js.map +1 -0
  126. package/dist/src/terminal/utility/format-status-line.d.ts +3 -0
  127. package/dist/src/terminal/utility/format-status-line.js +24 -0
  128. package/dist/src/terminal/utility/format-status-line.js.map +1 -0
  129. package/dist/src/terminal/utility/parse-color.d.ts +3 -0
  130. package/dist/src/terminal/utility/parse-color.js +45 -0
  131. package/dist/src/terminal/utility/parse-color.js.map +1 -0
  132. package/dist/src/terminal/utility/resolve-terminal-color.d.ts +2 -0
  133. package/dist/src/terminal/utility/resolve-terminal-color.js +20 -0
  134. package/dist/src/terminal/utility/resolve-terminal-color.js.map +1 -0
  135. package/dist/src/type/bounding-box.d.ts +6 -0
  136. package/dist/src/type/bounding-box.js +3 -0
  137. package/dist/src/type/bounding-box.js.map +1 -0
  138. package/dist/src/type/camera-state.d.ts +10 -0
  139. package/dist/src/type/camera-state.js +3 -0
  140. package/dist/src/type/camera-state.js.map +1 -0
  141. package/dist/src/type/display-component.d.ts +18 -0
  142. package/dist/src/type/display-component.js +3 -0
  143. package/dist/src/type/display-component.js.map +1 -0
  144. package/dist/src/type/drag-state.d.ts +6 -0
  145. package/dist/src/type/drag-state.js +3 -0
  146. package/dist/src/type/drag-state.js.map +1 -0
  147. package/dist/src/type/frame-dot.d.ts +6 -0
  148. package/dist/src/type/frame-dot.js +3 -0
  149. package/dist/src/type/frame-dot.js.map +1 -0
  150. package/dist/src/type/frame-label.d.ts +7 -0
  151. package/dist/src/type/frame-label.js +3 -0
  152. package/dist/src/type/frame-label.js.map +1 -0
  153. package/dist/src/type/frame-path.d.ts +8 -0
  154. package/dist/src/type/frame-path.js +3 -0
  155. package/dist/src/type/frame-path.js.map +1 -0
  156. package/dist/src/type/frame.d.ts +9 -0
  157. package/dist/src/type/frame.js +3 -0
  158. package/dist/src/type/frame.js.map +1 -0
  159. package/dist/src/type/inherited-style.d.ts +8 -0
  160. package/dist/src/type/inherited-style.js +3 -0
  161. package/dist/src/type/inherited-style.js.map +1 -0
  162. package/dist/src/type/plane-axes.d.ts +7 -0
  163. package/dist/src/type/plane-axes.js +3 -0
  164. package/dist/src/type/plane-axes.js.map +1 -0
  165. package/dist/src/type/polyline.d.ts +3 -0
  166. package/dist/src/type/polyline.js +3 -0
  167. package/dist/src/type/polyline.js.map +1 -0
  168. package/dist/src/type/primitive/box.d.ts +8 -0
  169. package/dist/src/type/primitive/box.js +3 -0
  170. package/dist/src/type/primitive/box.js.map +1 -0
  171. package/dist/src/type/primitive/cylinder.d.ts +11 -0
  172. package/dist/src/type/primitive/cylinder.js +3 -0
  173. package/dist/src/type/primitive/cylinder.js.map +1 -0
  174. package/dist/src/type/primitive/opening.d.ts +24 -0
  175. package/dist/src/type/primitive/opening.js +3 -0
  176. package/dist/src/type/primitive/opening.js.map +1 -0
  177. package/dist/src/type/primitive/polyline.d.ts +8 -0
  178. package/dist/src/type/primitive/polyline.js +3 -0
  179. package/dist/src/type/primitive/polyline.js.map +1 -0
  180. package/dist/src/type/primitive/sphere.d.ts +8 -0
  181. package/dist/src/type/primitive/sphere.js +3 -0
  182. package/dist/src/type/primitive/sphere.js.map +1 -0
  183. package/dist/src/type/primitive-geometry.d.ts +9 -0
  184. package/dist/src/type/primitive-geometry.js +3 -0
  185. package/dist/src/type/primitive-geometry.js.map +1 -0
  186. package/dist/src/type/primitive.d.ts +7 -0
  187. package/dist/src/type/primitive.js +3 -0
  188. package/dist/src/type/primitive.js.map +1 -0
  189. package/dist/src/type/render-options.d.ts +5 -0
  190. package/dist/src/type/render-options.js +3 -0
  191. package/dist/src/type/render-options.js.map +1 -0
  192. package/dist/src/type/screen-point.d.ts +5 -0
  193. package/dist/src/type/screen-point.js +3 -0
  194. package/dist/src/type/screen-point.js.map +1 -0
  195. package/dist/src/type/sidebar-callbacks.d.ts +9 -0
  196. package/dist/src/type/sidebar-callbacks.js +3 -0
  197. package/dist/src/type/sidebar-callbacks.js.map +1 -0
  198. package/dist/src/type/stroke.d.ts +6 -0
  199. package/dist/src/type/stroke.js +3 -0
  200. package/dist/src/type/stroke.js.map +1 -0
  201. package/dist/src/type/vector3.d.ts +6 -0
  202. package/dist/src/type/vector3.js +3 -0
  203. package/dist/src/type/vector3.js.map +1 -0
  204. package/dist/src/type/view-orientation.d.ts +5 -0
  205. package/dist/src/type/view-orientation.js +3 -0
  206. package/dist/src/type/view-orientation.js.map +1 -0
  207. package/dist/src/type/viewer-state.d.ts +11 -0
  208. package/dist/src/type/viewer-state.js +3 -0
  209. package/dist/src/type/viewer-state.js.map +1 -0
  210. package/dist/src/type/viewport.d.ts +5 -0
  211. package/dist/src/type/viewport.js +3 -0
  212. package/dist/src/type/viewport.js.map +1 -0
  213. package/dist/src/type/visibility-map.d.ts +2 -0
  214. package/dist/src/type/visibility-map.js +3 -0
  215. package/dist/src/type/visibility-map.js.map +1 -0
  216. package/dist/src/type/wireframe-component.d.ts +13 -0
  217. package/dist/src/type/wireframe-component.js +3 -0
  218. package/dist/src/type/wireframe-component.js.map +1 -0
  219. package/dist/src/type/wireframe-scene.d.ts +10 -0
  220. package/dist/src/type/wireframe-scene.js +3 -0
  221. package/dist/src/type/wireframe-scene.js.map +1 -0
  222. package/dist/src/utility/add-vectors.d.ts +3 -0
  223. package/dist/src/utility/add-vectors.js +11 -0
  224. package/dist/src/utility/add-vectors.js.map +1 -0
  225. package/dist/src/utility/build-box-outlines.d.ts +4 -0
  226. package/dist/src/utility/build-box-outlines.js +32 -0
  227. package/dist/src/utility/build-box-outlines.js.map +1 -0
  228. package/dist/src/utility/build-circle-outline.d.ts +5 -0
  229. package/dist/src/utility/build-circle-outline.js +25 -0
  230. package/dist/src/utility/build-circle-outline.js.map +1 -0
  231. package/dist/src/utility/build-cylinder-outlines.d.ts +4 -0
  232. package/dist/src/utility/build-cylinder-outlines.js +34 -0
  233. package/dist/src/utility/build-cylinder-outlines.js.map +1 -0
  234. package/dist/src/utility/build-frame.d.ts +8 -0
  235. package/dist/src/utility/build-frame.js +75 -0
  236. package/dist/src/utility/build-frame.js.map +1 -0
  237. package/dist/src/utility/build-initial-visibility.d.ts +4 -0
  238. package/dist/src/utility/build-initial-visibility.js +11 -0
  239. package/dist/src/utility/build-initial-visibility.js.map +1 -0
  240. package/dist/src/utility/build-opening-outlines.d.ts +4 -0
  241. package/dist/src/utility/build-opening-outlines.js +31 -0
  242. package/dist/src/utility/build-opening-outlines.js.map +1 -0
  243. package/dist/src/utility/build-primitive-geometry.d.ts +4 -0
  244. package/dist/src/utility/build-primitive-geometry.js +40 -0
  245. package/dist/src/utility/build-primitive-geometry.js.map +1 -0
  246. package/dist/src/utility/build-rectangle-outline.d.ts +5 -0
  247. package/dist/src/utility/build-rectangle-outline.js +23 -0
  248. package/dist/src/utility/build-rectangle-outline.js.map +1 -0
  249. package/dist/src/utility/build-sphere-outlines.d.ts +4 -0
  250. package/dist/src/utility/build-sphere-outlines.js +16 -0
  251. package/dist/src/utility/build-sphere-outlines.js.map +1 -0
  252. package/dist/src/utility/clamp.d.ts +2 -0
  253. package/dist/src/utility/clamp.js +7 -0
  254. package/dist/src/utility/clamp.js.map +1 -0
  255. package/dist/src/utility/collect-display-points.d.ts +4 -0
  256. package/dist/src/utility/collect-display-points.js +13 -0
  257. package/dist/src/utility/collect-display-points.js.map +1 -0
  258. package/dist/src/utility/compute-bounding-box.d.ts +4 -0
  259. package/dist/src/utility/compute-bounding-box.js +29 -0
  260. package/dist/src/utility/compute-bounding-box.js.map +1 -0
  261. package/dist/src/utility/compute-centroid.d.ts +3 -0
  262. package/dist/src/utility/compute-centroid.js +17 -0
  263. package/dist/src/utility/compute-centroid.js.map +1 -0
  264. package/dist/src/utility/create-element.d.ts +2 -0
  265. package/dist/src/utility/create-element.js +11 -0
  266. package/dist/src/utility/create-element.js.map +1 -0
  267. package/dist/src/utility/create-viewer-state.d.ts +4 -0
  268. package/dist/src/utility/create-viewer-state.js +29 -0
  269. package/dist/src/utility/create-viewer-state.js.map +1 -0
  270. package/dist/src/utility/fit-camera-to-bounding-box.d.ts +4 -0
  271. package/dist/src/utility/fit-camera-to-bounding-box.js +23 -0
  272. package/dist/src/utility/fit-camera-to-bounding-box.js.map +1 -0
  273. package/dist/src/utility/flatten-components.d.ts +4 -0
  274. package/dist/src/utility/flatten-components.js +70 -0
  275. package/dist/src/utility/flatten-components.js.map +1 -0
  276. package/dist/src/utility/get-bounding-box-center.d.ts +4 -0
  277. package/dist/src/utility/get-bounding-box-center.js +14 -0
  278. package/dist/src/utility/get-bounding-box-center.js.map +1 -0
  279. package/dist/src/utility/get-bounding-box-size.d.ts +4 -0
  280. package/dist/src/utility/get-bounding-box-size.js +12 -0
  281. package/dist/src/utility/get-bounding-box-size.js.map +1 -0
  282. package/dist/src/utility/get-focal-length.d.ts +2 -0
  283. package/dist/src/utility/get-focal-length.js +9 -0
  284. package/dist/src/utility/get-focal-length.js.map +1 -0
  285. package/dist/src/utility/get-perpendicular-axes.d.ts +3 -0
  286. package/dist/src/utility/get-perpendicular-axes.js +18 -0
  287. package/dist/src/utility/get-perpendicular-axes.js.map +1 -0
  288. package/dist/src/utility/get-plane-axes.d.ts +4 -0
  289. package/dist/src/utility/get-plane-axes.js +19 -0
  290. package/dist/src/utility/get-plane-axes.js.map +1 -0
  291. package/dist/src/utility/get-primitive-anchor.d.ts +4 -0
  292. package/dist/src/utility/get-primitive-anchor.js +20 -0
  293. package/dist/src/utility/get-primitive-anchor.js.map +1 -0
  294. package/dist/src/utility/get-vector-component.d.ts +4 -0
  295. package/dist/src/utility/get-vector-component.js +18 -0
  296. package/dist/src/utility/get-vector-component.js.map +1 -0
  297. package/dist/src/utility/get-vector-length.d.ts +3 -0
  298. package/dist/src/utility/get-vector-length.js +7 -0
  299. package/dist/src/utility/get-vector-length.js.map +1 -0
  300. package/dist/src/utility/has-hidden-ancestor.d.ts +4 -0
  301. package/dist/src/utility/has-hidden-ancestor.js +9 -0
  302. package/dist/src/utility/has-hidden-ancestor.js.map +1 -0
  303. package/dist/src/utility/inject-stylesheet.d.ts +2 -0
  304. package/dist/src/utility/inject-stylesheet.js +21 -0
  305. package/dist/src/utility/inject-stylesheet.js.map +1 -0
  306. package/dist/src/utility/is-component-shown.d.ts +4 -0
  307. package/dist/src/utility/is-component-shown.js +10 -0
  308. package/dist/src/utility/is-component-shown.js.map +1 -0
  309. package/dist/src/utility/offset-vector-along-axis.d.ts +4 -0
  310. package/dist/src/utility/offset-vector-along-axis.js +14 -0
  311. package/dist/src/utility/offset-vector-along-axis.js.map +1 -0
  312. package/dist/src/utility/pick-palette-color.d.ts +2 -0
  313. package/dist/src/utility/pick-palette-color.js +12 -0
  314. package/dist/src/utility/pick-palette-color.js.map +1 -0
  315. package/dist/src/utility/project-polyline.d.ts +5 -0
  316. package/dist/src/utility/project-polyline.js +22 -0
  317. package/dist/src/utility/project-polyline.js.map +1 -0
  318. package/dist/src/utility/project-vector.d.ts +6 -0
  319. package/dist/src/utility/project-vector.js +30 -0
  320. package/dist/src/utility/project-vector.js.map +1 -0
  321. package/dist/src/utility/rotate-vector.d.ts +3 -0
  322. package/dist/src/utility/rotate-vector.js +17 -0
  323. package/dist/src/utility/rotate-vector.js.map +1 -0
  324. package/dist/src/utility/scale-vector.d.ts +3 -0
  325. package/dist/src/utility/scale-vector.js +11 -0
  326. package/dist/src/utility/scale-vector.js.map +1 -0
  327. package/dist/src/utility/subtract-vectors.d.ts +3 -0
  328. package/dist/src/utility/subtract-vectors.js +11 -0
  329. package/dist/src/utility/subtract-vectors.js.map +1 -0
  330. package/dist/src/utility/unrotate-vector.d.ts +3 -0
  331. package/dist/src/utility/unrotate-vector.js +17 -0
  332. package/dist/src/utility/unrotate-vector.js.map +1 -0
  333. package/dist/src/utility/validate-scene.d.ts +3 -0
  334. package/dist/src/utility/validate-scene.js +70 -0
  335. package/dist/src/utility/validate-scene.js.map +1 -0
  336. package/dist/src/utility/with-vector-component.d.ts +4 -0
  337. package/dist/src/utility/with-vector-component.js +18 -0
  338. package/dist/src/utility/with-vector-component.js.map +1 -0
  339. package/dist/src/wireframe-viewer.d.ts +27 -0
  340. package/dist/src/wireframe-viewer.js +128 -0
  341. package/dist/src/wireframe-viewer.js.map +1 -0
  342. package/dist/tsconfig.tsbuildinfo +1 -0
  343. package/package.json +64 -5
package/README.md CHANGED
@@ -1,3 +1,166 @@
1
- # Temporary Holding Version
1
+ # @fc3/wireframe-renderer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A dependency-light 3D wireframe viewer for the browser and the terminal. It
4
+ takes a typed scene object describing nested components built from a
5
+ handful of primitives, and renders them with an orbit camera and a list of
6
+ components that can each be toggled on and off: to a 2D canvas with a
7
+ sidebar in the browser, or in braille characters in a terminal.
8
+
9
+ The renderer knows nothing about what it is drawing. Grouping, colors,
10
+ labels, and default visibility all come from the scene you hand it.
11
+
12
+ ## Usage
13
+
14
+ ```ts
15
+ import {WireframeViewer, WireframeScene} from '@fc3/wireframe-renderer';
16
+
17
+ const scene: WireframeScene = {
18
+ title: 'Enclosure',
19
+ subtitle: 'Rev A',
20
+ units: 'mm',
21
+ components: [
22
+ /* see below */
23
+ ]
24
+ };
25
+
26
+ const container = document.getElementById('viewer');
27
+ const viewer = new WireframeViewer(container, scene);
28
+
29
+ viewer.mount();
30
+ ```
31
+
32
+ The viewer fills its container, so give the container a size. Call
33
+ `viewer.unmount()` to tear it down. `viewer.setComponentVisible(id, visible)`
34
+ toggles a component programmatically, and `viewer.getCamera()` exposes the
35
+ camera for scripted views.
36
+
37
+ This package ships CommonJS output under `dist/`. Bundling for the browser is
38
+ left to the consuming project.
39
+
40
+ ## Terminal
41
+
42
+ The terminal viewer lives under its own entry point, so browser bundles never
43
+ pull in its terminal dependency:
44
+
45
+ ```ts
46
+ import {HOUSE_COMPUTER_SCENE} from '@fc3/wireframe-renderer';
47
+ import {TerminalViewer} from '@fc3/wireframe-renderer/terminal';
48
+
49
+ const viewer = new TerminalViewer(HOUSE_COMPUTER_SCENE, {
50
+ onExit: () => process.exit(0)
51
+ });
52
+
53
+ viewer.mount();
54
+ ```
55
+
56
+ It takes the same scene as the browser viewer and draws it with braille
57
+ characters, two dots wide and four tall per cell, which keeps proportions
58
+ square in a typical terminal font. Colors are matched to the nearest of the
59
+ terminal's 256 colors; translucent components are faded toward the
60
+ background, since a terminal cannot blend.
61
+
62
+ | key | action |
63
+ | ------------------ | ----------------------------------------------- |
64
+ | arrows | orbit (while the scene has focus) |
65
+ | `w` `a` `s` `d` | pan |
66
+ | `+` / `-` | zoom in / out |
67
+ | `1`–`7` | front, back, left, right, top, under, isometric |
68
+ | `p` / `t` / `g` | perspective, labels, ground reference |
69
+ | tab | move focus between the scene and the components |
70
+ | space / enter | show or hide the selected component |
71
+ | `q` / ctrl-c | quit |
72
+
73
+ `input` and `output` options accept streams other than the process's own,
74
+ `setComponentVisible(id, visible)` and `getCamera()` work as in the browser
75
+ viewer, and `unmount()` restores the terminal. `renderFrame(frame, columns,
76
+ rows)` is also exported for drawing a single frame to tagged text.
77
+
78
+ Try it with `./bin/bootstrap/terminal-demo`.
79
+
80
+ ## Scene shape
81
+
82
+ ```ts
83
+ type WireframeScene = {
84
+ title: string;
85
+ subtitle?: string;
86
+ units?: string;
87
+ components: WireframeComponent[];
88
+ camera?: Partial<CameraState>;
89
+ };
90
+
91
+ interface WireframeComponent {
92
+ id: string;
93
+ label?: string;
94
+ note?: string;
95
+ color?: string;
96
+ alpha?: number;
97
+ line_width?: number;
98
+ visible?: boolean;
99
+ primitives?: Primitive[];
100
+ children?: WireframeComponent[];
101
+ }
102
+ ```
103
+
104
+ Components nest to any depth. The sidebar lists them depth first, indented by
105
+ level, each with a checkbox. Hiding a component hides its whole subtree and
106
+ disables the descendants' checkboxes until it is shown again.
107
+
108
+ Ids must be unique across the whole tree. `label` defaults to the id. `note`
109
+ appears as a tooltip on the sidebar row.
110
+
111
+ Top-level components without a `color` take successive colors from a built-in
112
+ palette. Children inherit `color`, `alpha`, and `line_width` from their parent
113
+ unless they set their own.
114
+
115
+ `visible` defaults to `true`. Set it to `false` for alternatives that should
116
+ start hidden; the viewer can switch them on.
117
+
118
+ The camera fits itself to the bounding box of every component on load.
119
+ Anything in `camera` overrides the fitted values.
120
+
121
+ ## Primitives
122
+
123
+ All coordinates are world units. Vectors are `{x, y, z}`.
124
+
125
+ | type | fields |
126
+ | ---------- | -------------------------------------------------------- |
127
+ | `box` | `center`, `size` |
128
+ | `cylinder` | `center`, `axis` (`Axis.X`, `Axis.Y`, `Axis.Z`), `radius`, `length` |
129
+ | `sphere` | `center`, `radius` |
130
+ | `polyline` | `points` (two or more), optional `width` |
131
+ | `opening` | `shape`, `plane`, `center`, `depth`, plus `width` and `height` for `OpeningShape.RECTANGLE` or `radius` for `OpeningShape.CIRCLE` |
132
+
133
+ An opening is a hole through a wall. `plane` names the wall's face
134
+ (`Plane.XY`, `Plane.XZ`, `Plane.YZ`), `center` sits in the middle of the
135
+ wall's thickness, and `depth` is that thickness. The outline is drawn on both
136
+ faces. Openings are ordinary primitives, so put them in their own child
137
+ component to make them toggleable on their own.
138
+
139
+ Polylines are drawn thicker than outlines, with a dot at each end.
140
+
141
+ ## Sidebar
142
+
143
+ - View buttons for front, back, left, right, top, under, and isometric.
144
+ - Perspective toggle.
145
+ - Labels toggle, drawing each shown component's label at its centroid.
146
+ - Ground reference toggle, drawing a faint rectangle under the scene.
147
+ - The component tree.
148
+
149
+ Drag to orbit, shift-drag or right-drag to pan, wheel or pinch to zoom.
150
+
151
+ ## Example
152
+
153
+ `HOUSE_COMPUTER_SCENE` is exported as a worked example: a small enclosure
154
+ with nine top-level groups and a few alternatives that start hidden.
155
+
156
+ ## Development
157
+
158
+ ```
159
+ npm install
160
+ ./bin/test
161
+ ./bin/lint
162
+ ```
163
+
164
+ Unit tests live under `test/unit/` mirroring `src/`. The canvas and DOM
165
+ classes are not unit tested; everything beneath them is, including the
166
+ terminal viewer, which runs against in-memory streams.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ ./bin/compile
6
+
7
+ node dist/src/bootstrap/terminal-demo $@
package/bin/compile ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+
3
+ if [[ $1 == '--help' ]]; then
4
+ echo "Triggers recompilation of the source code for the current project."
5
+ echo "Supported flags:"
6
+ echo "--force : Bypasses any precompilation checks (cache, mutex, etc)"
7
+ echo " Use this if you want to recompile no matter what."
8
+ echo " "
9
+ exit 0
10
+ fi
11
+
12
+ if [[ $1 != '--force' ]]; then
13
+ ./bin/precompile
14
+
15
+ case $? in
16
+ 1)
17
+ exit 1
18
+ ;;
19
+ 3)
20
+ exit 0
21
+ ;;
22
+ esac
23
+ fi
24
+
25
+ echo "Recompiling..."
26
+ mkdir -p dist
27
+ echo $$ > dist/.compile-lock
28
+ rm -f dist/.last-compile-time
29
+
30
+ project_dir="$(dirname $(dirname "$0"))"
31
+
32
+ if [[ $1 == '--force' ]]; then
33
+ rm -rf dist/src
34
+ rm -rf dist/test
35
+ ./node_modules/.bin/tsc --declaration --project "$project_dir/config/tsconfig.json"
36
+ else
37
+ ./node_modules/.bin/tsc --declaration --incremental --project "$project_dir/config/tsconfig.json"
38
+ fi
39
+
40
+ exit_status=$?
41
+
42
+ if [[ $exit_status -eq 0 ]]; then
43
+ ./bin/remap-paths
44
+ echo $(date +%s) > dist/.last-compile-time
45
+ fi
46
+
47
+ pid=$(cat dist/.compile-lock)
48
+
49
+ if [[ $pid == $$ ]]; then
50
+ rm dist/.compile-lock
51
+ exit $exit_status
52
+ else
53
+ echo "Detected a conflicting compile lock..."
54
+ exit 1
55
+ fi
package/bin/install ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ ./bin/compile
package/bin/lint ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ if [[ "${1:-}" == "--fix" ]]; then
6
+ ./node_modules/.bin/eslint "src/**/*.{ts,tsx}" "test/unit/**/*.{ts,tsx}" --fix
7
+ ./node_modules/.bin/prettier --write "src/**/*.{ts,tsx}" "test/unit/**/*.{ts,tsx}"
8
+ else
9
+ ./node_modules/.bin/eslint "src/**/*.{ts,tsx}" "test/unit/**/*.{ts,tsx}"
10
+ ./node_modules/.bin/prettier --check "src/**/*.{ts,tsx}" "test/unit/**/*.{ts,tsx}"
11
+ fi
12
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ rm ./dist/.last-publish-time
package/bin/precompile ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env bash
2
+
3
+ mkdir -p dist
4
+
5
+ if [ -f dist/.compile-lock ]; then
6
+ pid=$(cat dist/.compile-lock)
7
+ ticks=0
8
+ max_ticks=10
9
+
10
+ if ! ps -p $pid > /dev/null; then
11
+ echo "Detected a stale compile lock; deleting..."
12
+ rm -f dist/.compile-lock
13
+ else
14
+ echo "Compilation already in progress; waiting up to $max_ticks seconds..."
15
+ fi
16
+
17
+ while [ -f dist/.compile-lock ]; do
18
+ sleep 1
19
+ let ticks=ticks+1
20
+
21
+ if [ $ticks -ge $max_ticks ]; then
22
+ echo "Timed out waiting for compilation to clear"
23
+ exit 1
24
+ fi
25
+ done
26
+ fi
27
+
28
+ if [[ -f ./dist/.last-publish-time && ! -d src ]]; then
29
+ echo "Found publication compile artifact; skipping recompilation."
30
+ exit 3
31
+ fi
32
+
33
+ missing_output=false
34
+
35
+ if [ -d src ] && [ ! -d dist/src ]; then
36
+ missing_output=true
37
+ fi
38
+
39
+ if [ -d test ] && [ ! -d dist/test ]; then
40
+ missing_output=true
41
+ fi
42
+
43
+ if [[ $missing_output == true ]]; then
44
+ # The incremental build cache would otherwise skip re-emitting files.
45
+ rm -f dist/tsconfig.tsbuildinfo
46
+ exit 0
47
+ fi
48
+
49
+ if [ -f dist/.last-compile-time ]; then
50
+ if [ ! -d src ]; then
51
+ # TODO: Confirm we're within a deploy environment
52
+ echo "src folder does not exist; skipping recompilation."
53
+ exit 3
54
+ fi
55
+
56
+ typeset -i last_modification_time=$(find src test -type f -print0 |
57
+ xargs -0 stat -c "%Y %N" |
58
+ sort -rn |
59
+ head -1 |
60
+ awk '{ print $1 }')
61
+
62
+ typeset -i last_compile_time=$(cat dist/.last-compile-time)
63
+
64
+ if (( $last_compile_time > $last_modification_time )); then
65
+ echo "No changes since last compile; skipping recompilation."
66
+ exit 3
67
+ fi
68
+ fi
69
+
70
+ # Compilation should occur.
71
+ exit 0
package/bin/prepublish ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ ./bin/compile
6
+
7
+ date +%s > ./dist/.last-publish-time
@@ -0,0 +1,172 @@
1
+ #!/usr/bin/env node
2
+
3
+ const FS = require('fs');
4
+ const Path = require('path');
5
+
6
+ const JAVASCRIPT_EXTENSION = '.js';
7
+ const DECLARATION_EXTENSION = '.d.ts';
8
+ const UTF8_ENCODING = 'utf8';
9
+ const DIST_PATH = Path.resolve(__dirname, '../dist');
10
+
11
+ function processDirectory(directoryPath) {
12
+ const children = FS.readdirSync(directoryPath);
13
+
14
+ children.forEach(function each(child) {
15
+ // Ignore hidden files.
16
+ if (child[0] === '.') {
17
+ return;
18
+ }
19
+
20
+ const
21
+ childPath = Path.resolve(directoryPath, child),
22
+ parsedPath = Path.parse(childPath);
23
+
24
+ if (!parsedPath.ext) {
25
+ processDirectory(childPath);
26
+ } else if (parsedPath.ext === JAVASCRIPT_EXTENSION) {
27
+ processSourceFile(childPath);
28
+ } else if (childPath.slice(-5) === DECLARATION_EXTENSION) {
29
+ processDeclarationFile(childPath);
30
+ }
31
+ });
32
+ }
33
+
34
+ function processSourceFile(filePath) {
35
+ const contents = FS.readFileSync(filePath, UTF8_ENCODING);
36
+
37
+ const lines = contents.split('\n').map(function map(line) {
38
+ return line.replace(/require\((["'])([^"']+)/g, function replacer(match, quote, path) {
39
+ if (path[0] === '.') {
40
+ return match;
41
+ }
42
+
43
+ let dependencyPath = DIST_PATH + '/src/' + path + '.js';
44
+
45
+ if (!FS.existsSync(dependencyPath)) {
46
+ // Fall back to checking whether there's an index.js in a directory
47
+ // of this name, instead of a toplevel .js source file directly.
48
+ dependencyPath = DIST_PATH + '/src/' + path + '/index.js';
49
+
50
+ if (!FS.existsSync(dependencyPath)) {
51
+ // Well, we tried.
52
+ return match;
53
+ }
54
+ }
55
+
56
+ const parsedFile = Path.parse(filePath);
57
+ const parsedDependency = Path.parse(dependencyPath);
58
+
59
+ let relativeDirectory = Path.relative(parsedFile.dir, parsedDependency.dir);
60
+
61
+ if (relativeDirectory === '') {
62
+ relativeDirectory = '.';
63
+ } else {
64
+ relativeDirectory = './' + relativeDirectory;
65
+ }
66
+
67
+ const relativePath = relativeDirectory + '/' + parsedDependency.base;
68
+
69
+ return 'require(' + quote + relativePath;
70
+ });
71
+ });
72
+
73
+ FS.writeFileSync(filePath, lines.join('\n'), UTF8_ENCODING);
74
+ }
75
+
76
+ function processDeclarationFile(filePath) {
77
+ const contents = FS.readFileSync(filePath, UTF8_ENCODING);
78
+
79
+ const lines = contents.split('\n').map(function map(line) {
80
+ return line.replace(/from '([^']+)/g, function replacer(match, path) {
81
+ if (path[0] === '.') {
82
+ return match;
83
+ }
84
+
85
+ let dependencyPath = DIST_PATH + '/src/' + path + '.d.ts';
86
+
87
+ if (!FS.existsSync(dependencyPath)) {
88
+ // Fall back to checking whether there's an index.js in a directory
89
+ // of this name, instead of a toplevel .d.ts source file directly.
90
+ dependencyPath = DIST_PATH + '/src/' + path + '/index.d.ts';
91
+
92
+ if (!FS.existsSync(dependencyPath)) {
93
+ // Well, we tried.
94
+ return match;
95
+ }
96
+ }
97
+
98
+ const parsedFile = Path.parse(filePath);
99
+ const parsedDependency = Path.parse(dependencyPath);
100
+
101
+ let relativeDirectory = Path.relative(parsedFile.dir, parsedDependency.dir);
102
+
103
+ if (relativeDirectory === '') {
104
+ relativeDirectory = '.';
105
+ } else {
106
+ relativeDirectory = './' + relativeDirectory;
107
+ }
108
+
109
+ let relativePath = relativeDirectory + '/' + parsedDependency.base;
110
+
111
+ relativePath = relativePath.replace(DECLARATION_EXTENSION, '');
112
+
113
+ return "from '" + relativePath;
114
+ });
115
+ });
116
+
117
+ FS.writeFileSync(filePath, lines.join('\n'), UTF8_ENCODING);
118
+ }
119
+
120
+ const OUTPUT_SUFFIXES = ['.d.ts', '.js.map', '.js'];
121
+ const SOURCE_EXTENSIONS = ['.ts', '.tsx'];
122
+
123
+ function getSourceStem(output_path) {
124
+ const suffix = OUTPUT_SUFFIXES.find(function find(candidate) {
125
+ return output_path.endsWith(candidate);
126
+ });
127
+
128
+ if (suffix === undefined) {
129
+ return null;
130
+ }
131
+
132
+ return output_path.slice(0, -suffix.length);
133
+ }
134
+
135
+ function hasSource(source_stem) {
136
+ return SOURCE_EXTENSIONS.some(function some(extension) {
137
+ return FS.existsSync(source_stem + extension);
138
+ });
139
+ }
140
+
141
+ function pruneOrphanedOutputs(output_directory, source_directory) {
142
+ if (!FS.existsSync(output_directory)) {
143
+ return;
144
+ }
145
+
146
+ FS.readdirSync(output_directory).forEach(function each(child) {
147
+ const output_path = Path.resolve(output_directory, child);
148
+ const source_path = Path.resolve(source_directory, child);
149
+
150
+ if (FS.statSync(output_path).isDirectory()) {
151
+ pruneOrphanedOutputs(output_path, source_path);
152
+ return;
153
+ }
154
+
155
+ const output_stem = getSourceStem(child);
156
+
157
+ if (output_stem === null) {
158
+ return;
159
+ }
160
+
161
+ const source_stem = Path.resolve(source_directory, output_stem);
162
+
163
+ if (!hasSource(source_stem)) {
164
+ FS.unlinkSync(output_path);
165
+ }
166
+ });
167
+ }
168
+
169
+ pruneOrphanedOutputs('./dist/src', './src');
170
+ pruneOrphanedOutputs('./dist/test', './test');
171
+
172
+ processDirectory('./dist', 0);
package/bin/test ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ bin/compile
6
+
7
+ # It's important that the glob be quoted so that the Node engine
8
+ # can evaluate it rather than it being done by the shell.
9
+ NODE_ENV=test node --test "dist/test/**/*.js"
package/bin/test-one ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ RED='\033[0;31m'
6
+ YELLOW='\033[0;33m'
7
+ RESET='\033[0m'
8
+
9
+ bin/compile
10
+
11
+ FILE_TO_TEST=$1
12
+
13
+ if [ -f "dist/$1.js" ]; then
14
+ TEST_FILEPATH="$FILE_TO_TEST.js"
15
+ else
16
+ # If someone enters the path to the corresponding Typescript file for a test,
17
+ # we should map this to the associated JS file in the dist/test directory:
18
+ FILE_WITH_CORRECTED_EXTENSION=${FILE_TO_TEST/.ts/.js}
19
+
20
+ if [ -f "dist/$FILE_WITH_CORRECTED_EXTENSION" ]; then
21
+ TEST_FILEPATH=$FILE_WITH_CORRECTED_EXTENSION
22
+ fi
23
+ fi
24
+
25
+ if [ -f "dist/$TEST_FILEPATH" ]; then
26
+ NODE_ENV=test node --test dist/$TEST_FILEPATH
27
+ else
28
+ echo ""
29
+ echo -e "${RED}[ERROR]${RESET} No test file(s) found matching '$1'"
30
+ echo -e "${YELLOW}Example:${RESET} dev test test/unit/logger"
31
+ echo ""
32
+ fi
@@ -0,0 +1 @@
1
+ 1795107207
@@ -0,0 +1 @@
1
+ 1795107952
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const terminal_viewer_1 = __importDefault(require("./../terminal/terminal-viewer.js"));
7
+ const house_computer_1 = __importDefault(require("./../example/house-computer.js"));
8
+ const viewer = new terminal_viewer_1.default(house_computer_1.default, {
9
+ onExit: () => {
10
+ process.exit(0);
11
+ }
12
+ });
13
+ viewer.mount();
14
+ //# sourceMappingURL=terminal-demo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal-demo.js","sourceRoot":"","sources":["../../../src/bootstrap/terminal-demo.ts"],"names":[],"mappings":";;;;;AAAA,+EAAsD;AACtD,4EAA0D;AAE1D,MAAM,MAAM,GAAG,IAAI,yBAAc,CAAC,wBAAoB,EAAE;IACvD,MAAM,EAAE,GAAG,EAAE;QACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;CACD,CAAC,CAAC;AAEH,MAAM,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,26 @@
1
+ import Vector3 from './type/vector3';
2
+ import Viewport from './type/viewport';
3
+ import CameraState from './type/camera-state';
4
+ import ScreenPoint from './type/screen-point';
5
+ import ViewOrientation from './type/view-orientation';
6
+ declare class Camera {
7
+ private state;
8
+ private viewport;
9
+ constructor(state: CameraState);
10
+ getState(): CameraState;
11
+ setState(state: CameraState): void;
12
+ getViewport(): Viewport;
13
+ setViewport(viewport: Viewport): void;
14
+ applyOrientation(orientation: ViewOrientation): void;
15
+ setPerspective(perspective: boolean): void;
16
+ orbit(pixel_dx: number, pixel_dy: number): void;
17
+ pan(pixel_dx: number, pixel_dy: number): void;
18
+ zoomBy(factor: number): void;
19
+ rotateDirection(direction: Vector3): Vector3;
20
+ unrotateDirection(direction: Vector3): Vector3;
21
+ toCameraSpace(point: Vector3): Vector3;
22
+ project(point: Vector3): ScreenPoint | null;
23
+ getFocalLength(): number;
24
+ getWorldUnitsPerPixel(): number;
25
+ }
26
+ export default Camera;