@ifiwas/standard-view 2.0.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 (134) hide show
  1. package/.prettierignore +67 -0
  2. package/.prettierrc +12 -0
  3. package/CHANGELOG.md +42 -0
  4. package/LICENSE +8 -0
  5. package/README.md +199 -0
  6. package/debug-storybook.log +179 -0
  7. package/declarations.d.ts +17 -0
  8. package/dist/standard-view.es.js +9522 -0
  9. package/dist/standard-view.es.js.map +1 -0
  10. package/dist/standard-view.umd.js +41 -0
  11. package/dist/standard-view.umd.js.map +1 -0
  12. package/fonts/gentilis.bold.typeface.json +1 -0
  13. package/fonts/gentilis.typeface.json +1 -0
  14. package/fonts/helvetiker.bold.typeface.json +1 -0
  15. package/fonts/helvetiker.typeface.json +1 -0
  16. package/fonts/optimer.bold.typeface.json +1 -0
  17. package/fonts/optimer.typeface.json +1 -0
  18. package/images.d.ts +7 -0
  19. package/index.js +10 -0
  20. package/lib/controls/OrbitControls.d.ts +9 -0
  21. package/lib/controls/OrbitControls.js +761 -0
  22. package/lib/controls/index.d.ts +1 -0
  23. package/lib/controls/index.js +18 -0
  24. package/lib/groups/Arrow.d.ts +19 -0
  25. package/lib/groups/Arrow.js +134 -0
  26. package/lib/groups/Axis.d.ts +20 -0
  27. package/lib/groups/Axis.js +147 -0
  28. package/lib/groups/BoundingBox.d.ts +9 -0
  29. package/lib/groups/BoundingBox.js +143 -0
  30. package/lib/groups/Camera.d.ts +32 -0
  31. package/lib/groups/Camera.js +477 -0
  32. package/lib/groups/Capsule.d.ts +9 -0
  33. package/lib/groups/Capsule.js +112 -0
  34. package/lib/groups/FBX.d.ts +9 -0
  35. package/lib/groups/FBX.js +213 -0
  36. package/lib/groups/GLTF.d.ts +9 -0
  37. package/lib/groups/GLTF.js +198 -0
  38. package/lib/groups/Group.d.ts +63 -0
  39. package/lib/groups/Group.js +426 -0
  40. package/lib/groups/OBJ.d.ts +11 -0
  41. package/lib/groups/OBJ.js +252 -0
  42. package/lib/groups/PCD.d.ts +9 -0
  43. package/lib/groups/PCD.js +82 -0
  44. package/lib/groups/Path.d.ts +19 -0
  45. package/lib/groups/Path.js +160 -0
  46. package/lib/groups/index.d.ts +11 -0
  47. package/lib/groups/index.js +91 -0
  48. package/lib/index.d.ts +6 -0
  49. package/lib/index.js +298 -0
  50. package/lib/lights/AmbientLight.d.ts +8 -0
  51. package/lib/lights/AmbientLight.js +37 -0
  52. package/lib/lights/DirectionalLight.d.ts +8 -0
  53. package/lib/lights/DirectionalLight.js +43 -0
  54. package/lib/lights/HemisphereLight.d.ts +13 -0
  55. package/lib/lights/HemisphereLight.js +108 -0
  56. package/lib/lights/LightWithShadows.d.ts +24 -0
  57. package/lib/lights/LightWithShadows.js +188 -0
  58. package/lib/lights/PointLight.d.ts +9 -0
  59. package/lib/lights/PointLight.js +47 -0
  60. package/lib/lights/RectAreaLight.d.ts +13 -0
  61. package/lib/lights/RectAreaLight.js +177 -0
  62. package/lib/lights/SpotLight.d.ts +10 -0
  63. package/lib/lights/SpotLight.js +49 -0
  64. package/lib/lights/index.d.ts +6 -0
  65. package/lib/lights/index.js +48 -0
  66. package/lib/primitives/Box.d.ts +6 -0
  67. package/lib/primitives/Box.js +43 -0
  68. package/lib/primitives/Circle.d.ts +10 -0
  69. package/lib/primitives/Circle.js +85 -0
  70. package/lib/primitives/Cylinder.d.ts +15 -0
  71. package/lib/primitives/Cylinder.js +180 -0
  72. package/lib/primitives/Label.d.ts +18 -0
  73. package/lib/primitives/Label.js +189 -0
  74. package/lib/primitives/Line.d.ts +19 -0
  75. package/lib/primitives/Line.js +173 -0
  76. package/lib/primitives/Mesh.d.ts +72 -0
  77. package/lib/primitives/Mesh.js +642 -0
  78. package/lib/primitives/Plane.d.ts +7 -0
  79. package/lib/primitives/Plane.js +47 -0
  80. package/lib/primitives/Polygon.d.ts +8 -0
  81. package/lib/primitives/Polygon.js +75 -0
  82. package/lib/primitives/Quad.d.ts +9 -0
  83. package/lib/primitives/Quad.js +110 -0
  84. package/lib/primitives/Sphere.d.ts +14 -0
  85. package/lib/primitives/Sphere.js +92 -0
  86. package/lib/primitives/Text.d.ts +20 -0
  87. package/lib/primitives/Text.js +285 -0
  88. package/lib/primitives/Triangle.d.ts +8 -0
  89. package/lib/primitives/Triangle.js +83 -0
  90. package/lib/primitives/index.d.ts +12 -0
  91. package/lib/primitives/index.js +90 -0
  92. package/lib/shaders/index.d.ts +0 -0
  93. package/lib/shaders/index.js +2 -0
  94. package/lib/types/three-jsx.d.js +5 -0
  95. package/lib/utils/constants.js +181 -0
  96. package/lib/utils/events.d.ts +22 -0
  97. package/lib/utils/events.js +98 -0
  98. package/lib/utils/hooks.d.ts +8 -0
  99. package/lib/utils/hooks.js +96 -0
  100. package/lib/utils/index.d.ts +3 -0
  101. package/lib/utils/index.js +110 -0
  102. package/lib/utils/interfaces.d.ts +9 -0
  103. package/lib/utils/interfaces.js +5 -0
  104. package/lib/utils/math.d.ts +12 -0
  105. package/lib/utils/math.js +31 -0
  106. package/lib/utils/performance.d.ts +7 -0
  107. package/lib/utils/performance.js +114 -0
  108. package/lib/utils/styles.js +10 -0
  109. package/lib/utils/util.d.ts +76 -0
  110. package/lib/utils/util.js +290 -0
  111. package/lib/views/ContextBridge.d.ts +23 -0
  112. package/lib/views/ContextBridge.js +98 -0
  113. package/lib/views/SceneCamera.d.ts +7 -0
  114. package/lib/views/SceneCamera.js +52 -0
  115. package/lib/views/SetBackground.d.ts +9 -0
  116. package/lib/views/SetBackground.js +90 -0
  117. package/lib/views/SetControls.d.ts +19 -0
  118. package/lib/views/SetControls.js +173 -0
  119. package/lib/views/SetRenderer.d.ts +25 -0
  120. package/lib/views/SetRenderer.js +66 -0
  121. package/lib/views/SetShadows.d.ts +7 -0
  122. package/lib/views/SetShadows.js +48 -0
  123. package/lib/views/View3D.d.ts +21 -0
  124. package/lib/views/View3D.js +289 -0
  125. package/lib/views/ViewContext.d.ts +23 -0
  126. package/lib/views/ViewContext.js +55 -0
  127. package/lib/views/index.d.ts +2 -0
  128. package/lib/views/index.js +20 -0
  129. package/netlify.toml +15 -0
  130. package/package.json +110 -0
  131. package/tsconfig.json +42 -0
  132. package/tsconfig.prod.json +3 -0
  133. package/tsconfig.test.json +6 -0
  134. package/vite.config.ts +37 -0
@@ -0,0 +1,477 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var THREE = _interopRequireWildcard(require("three"));
10
+ var _Box = _interopRequireDefault(require("../primitives/Box"));
11
+ var _Circle = _interopRequireDefault(require("../primitives/Circle"));
12
+ var _Cylinder = _interopRequireDefault(require("../primitives/Cylinder"));
13
+ var _Label = _interopRequireDefault(require("../primitives/Label"));
14
+ var _Arrow = _interopRequireDefault(require("./Arrow"));
15
+ var _Text = _interopRequireDefault(require("../primitives/Text"));
16
+ var _Group = _interopRequireDefault(require("./Group"));
17
+ var _util = require("../utils/util");
18
+ var _math = require("../utils/math");
19
+ var _hooks = require("../utils/hooks");
20
+ var _constants = require("../utils/constants");
21
+ var _excluded = ["type", "left", "right", "top", "bottom", "near", "far", "fov", "width", "height", "aspect", "position", "normal", "target", "rotation", "eulerOrder", "quaternion", "up", "roll", "helper", "showUp", "showNormal", "showRoll", "showLookAt", "showLabel", "labelOffset", "labelText", "cull", "coverageColor", "coverageOpacity", "castShadow", "receiveShadow", "wireframeColor", "children"]; // Camera.tsx
22
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
23
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
24
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
25
+ function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
26
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
27
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
28
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
29
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
30
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
31
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
32
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
33
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
34
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
35
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
36
+ var useMemo = React.useMemo,
37
+ memo = React.memo;
38
+ function updateAllOpacity(_ref) {
39
+ var children = _ref.children,
40
+ originalOpacity = _ref.originalOpacity,
41
+ _ref$newOpacity = _ref.newOpacity,
42
+ newOpacity = _ref$newOpacity === void 0 ? 0.5 : _ref$newOpacity,
43
+ _ref$restore = _ref.restore,
44
+ restore = _ref$restore === void 0 ? false : _ref$restore;
45
+ // Validation
46
+ if (!children) {
47
+ return;
48
+ }
49
+ var _children = Array.isArray(children) ? children : [children];
50
+
51
+ // Update Meshes
52
+ _children.filter(function (child) {
53
+ return child.constructor.name === '';
54
+ }).map(function (mesh) {
55
+ /* eslint-disable no-param-reassign */
56
+ if (restore) {
57
+ // Restore
58
+ mesh.material.opacity = originalOpacity.pop();
59
+ } else {
60
+ // Enable Transparency
61
+ mesh.material.transparent = true;
62
+ // Update Opacity
63
+ var oldOpacity = mesh.material.opacity != null ? mesh.material.opacity : 1;
64
+ originalOpacity.push(oldOpacity);
65
+ mesh.material.opacity = newOpacity;
66
+ }
67
+
68
+ // Update Material
69
+ mesh.material.needsUpdate = true;
70
+ return null;
71
+ /* eslint-enable no-param-reassign */
72
+ });
73
+
74
+ // Recurse into Groups
75
+ _children.filter(function (child) {
76
+ return child.constructor.name === 'Group';
77
+ }).map(function (group) {
78
+ return updateAllOpacity({
79
+ children: group.children,
80
+ originalOpacity: originalOpacity,
81
+ newOpacity: newOpacity,
82
+ restore: restore
83
+ });
84
+ });
85
+
86
+ // Recurse into Scenes
87
+ _children.filter(function (child) {
88
+ return child.constructor.name === 'Scene';
89
+ }).map(function (scene) {
90
+ return updateAllOpacity({
91
+ children: scene.children,
92
+ originalOpacity: originalOpacity,
93
+ newOpacity: newOpacity,
94
+ restore: restore
95
+ });
96
+ });
97
+ }
98
+
99
+ /**
100
+ * setAllOpacity
101
+ *
102
+ * Recursively call updateAllOpacity on groups and sets material opacity
103
+ * and transparennt for all meshes
104
+ * originalCapacity needs to be reverse since, restoreAllOpacity will
105
+ * pop elements from originalCapacity in the same order in which they
106
+ * were pushed to the array.
107
+ */
108
+ function setAllOpacity(children, newOpacity) {
109
+ var originalOpacity = [];
110
+ updateAllOpacity({
111
+ children: children,
112
+ originalOpacity: originalOpacity,
113
+ newOpacity: newOpacity,
114
+ restore: false
115
+ });
116
+ originalOpacity = originalOpacity.reverse();
117
+
118
+ // restoreAllOpacity closure
119
+ // Something screwy is happening in the restore
120
+ return function restoreAllOpacity() {
121
+ updateAllOpacity({
122
+ children: children,
123
+ originalOpacity: originalOpacity,
124
+ newOpacity: newOpacity,
125
+ restore: true
126
+ });
127
+ };
128
+ }
129
+ function CullCoverage(_ref2) {
130
+ var frustum = _ref2.frustum,
131
+ cull = _ref2.cull,
132
+ coverageColor = _ref2.coverageColor,
133
+ coverageOpacity = _ref2.coverageOpacity;
134
+ (0, _hooks.useFrame)(function updateRenderLoop(_ref3) {
135
+ var gl = _ref3.gl,
136
+ scene = _ref3.scene,
137
+ camera = _ref3.camera;
138
+ /* eslint-disable no-param-reassign */
139
+ if (!cull) {
140
+ return;
141
+ }
142
+
143
+ // Prevent Render of Full Scene after Culling
144
+ // @ts-ignore:TS2339 cancelTailRender does not exist on scene
145
+ scene.cancelTailRender = true;
146
+
147
+ // Original Color Coverage with Custom Coverage Opacity
148
+ if (coverageColor == null && coverageOpacity < 1) {
149
+ var restoreAllOpacity = setAllOpacity(scene.children, coverageOpacity);
150
+ gl.clippingPlanes = frustum.planes;
151
+ gl.render(scene, camera);
152
+
153
+ // Restore WebGLRender Options
154
+ restoreAllOpacity();
155
+ scene.overrideMaterial = null;
156
+ gl.clippingPlanes = [];
157
+ return;
158
+ }
159
+
160
+ // Override Color
161
+ if (coverageColor != null) {
162
+ scene.overrideMaterial = new THREE.MeshBasicMaterial({
163
+ color: coverageColor,
164
+ transparent: true,
165
+ opacity: coverageOpacity
166
+ });
167
+ }
168
+ gl.clippingPlanes = frustum.planes;
169
+ gl.render(scene, camera);
170
+
171
+ // Restore WebGLRender Options
172
+ scene.overrideMaterial = null;
173
+ gl.clippingPlanes = [];
174
+
175
+ /* eslint-enable no-param-reassign */
176
+ }, 10);
177
+ return null;
178
+ }
179
+ /**
180
+ * Camera
181
+ *
182
+ * Camera's up prop may be given by the user. The camera's true up will be a projection of the
183
+ * given up. This way you can have a tilted camera and just provide the up of the world space and
184
+ * the camera will orient such that the project of the true up is aligned with the world space up.
185
+ */
186
+ var Camera = function Camera(_ref4) {
187
+ var _ref4$type = _ref4.type,
188
+ type = _ref4$type === void 0 ? 'perspective' : _ref4$type,
189
+ left = _ref4.left,
190
+ right = _ref4.right,
191
+ top = _ref4.top,
192
+ bottom = _ref4.bottom,
193
+ _ref4$near = _ref4.near,
194
+ near = _ref4$near === void 0 ? _math.EPS : _ref4$near,
195
+ _ref4$far = _ref4.far,
196
+ far = _ref4$far === void 0 ? 1000 : _ref4$far,
197
+ _ref4$fov = _ref4.fov,
198
+ fov = _ref4$fov === void 0 ? 50 : _ref4$fov,
199
+ _ref4$width = _ref4.width,
200
+ width = _ref4$width === void 0 ? 1 : _ref4$width,
201
+ _ref4$height = _ref4.height,
202
+ height = _ref4$height === void 0 ? 1 : _ref4$height,
203
+ _ref4$aspect = _ref4.aspect,
204
+ aspect = _ref4$aspect === void 0 ? width / height : _ref4$aspect,
205
+ _ref4$position = _ref4.position,
206
+ position = _ref4$position === void 0 ? [0, 0, 0] : _ref4$position,
207
+ _ref4$normal = _ref4.normal,
208
+ normal = _ref4$normal === void 0 ? _constants.DEFAULT_NORMAL : _ref4$normal,
209
+ target = _ref4.target,
210
+ _ref4$rotation = _ref4.rotation,
211
+ rotation = _ref4$rotation === void 0 ? [0, 0, 0] : _ref4$rotation,
212
+ _ref4$eulerOrder = _ref4.eulerOrder,
213
+ eulerOrder = _ref4$eulerOrder === void 0 ? _constants.EULER_ORDERS.XYZ : _ref4$eulerOrder,
214
+ quaternion = _ref4.quaternion,
215
+ up = _ref4.up,
216
+ _ref4$roll = _ref4.roll,
217
+ roll = _ref4$roll === void 0 ? 0 : _ref4$roll,
218
+ _ref4$helper = _ref4.helper,
219
+ helper = _ref4$helper === void 0 ? false : _ref4$helper,
220
+ _ref4$showUp = _ref4.showUp,
221
+ showUp = _ref4$showUp === void 0 ? false : _ref4$showUp,
222
+ _ref4$showNormal = _ref4.showNormal,
223
+ showNormal = _ref4$showNormal === void 0 ? false : _ref4$showNormal,
224
+ _ref4$showRoll = _ref4.showRoll,
225
+ showRoll = _ref4$showRoll === void 0 ? false : _ref4$showRoll,
226
+ _ref4$showLookAt = _ref4.showLookAt,
227
+ showLookAt = _ref4$showLookAt === void 0 ? false : _ref4$showLookAt,
228
+ _ref4$showLabel = _ref4.showLabel,
229
+ showLabel = _ref4$showLabel === void 0 ? true : _ref4$showLabel,
230
+ _ref4$labelOffset = _ref4.labelOffset,
231
+ labelOffset = _ref4$labelOffset === void 0 ? [0, 0, 1.5] : _ref4$labelOffset,
232
+ _ref4$labelText = _ref4.labelText,
233
+ labelText = _ref4$labelText === void 0 ? 'cam' : _ref4$labelText,
234
+ _ref4$cull = _ref4.cull,
235
+ cull = _ref4$cull === void 0 ? false : _ref4$cull,
236
+ coverageColor = _ref4.coverageColor,
237
+ _ref4$coverageOpacity = _ref4.coverageOpacity,
238
+ coverageOpacity = _ref4$coverageOpacity === void 0 ? 1 : _ref4$coverageOpacity,
239
+ _ref4$castShadow = _ref4.castShadow,
240
+ castShadow = _ref4$castShadow === void 0 ? false : _ref4$castShadow,
241
+ _ref4$receiveShadow = _ref4.receiveShadow,
242
+ receiveShadow = _ref4$receiveShadow === void 0 ? false : _ref4$receiveShadow,
243
+ wireframeColor = _ref4.wireframeColor,
244
+ children = _ref4.children,
245
+ otherProps = _objectWithoutProperties(_ref4, _excluded);
246
+ // Target / Normal
247
+ var initialNormal = useMemo(function updateNormal() {
248
+ if (target) {
249
+ var posVec = _construct(THREE.Vector3, _toConsumableArray(position));
250
+ var targetVec = _construct(THREE.Vector3, _toConsumableArray(target));
251
+ var lookAtVec = targetVec.clone().sub(posVec).normalize();
252
+ // LookAt is opposite direction of Normal
253
+ return [-lookAtVec.x, -lookAtVec.y, -lookAtVec.z];
254
+ }
255
+ return (0, _util.objectToArray)(_construct(THREE.Vector3, _toConsumableArray(normal)).normalize());
256
+ }, [target, normal, position]);
257
+
258
+ // THREE.Camera
259
+ var camera = useMemo(function updateCamera() {
260
+ var _cam$position, _cam;
261
+ var cam;
262
+ var _left = left != null ? left : -width * 0.5;
263
+ var _right = right != null ? right : width * 0.5;
264
+ var _top = top != null ? top : height * 0.5;
265
+ var _bottom = bottom != null ? bottom : -height * 0.5;
266
+ switch (type) {
267
+ case 'orthographic':
268
+ cam = new THREE.OrthographicCamera(_left, _right, _top, _bottom, near, far);
269
+ break;
270
+ case 'perspective':
271
+ cam = new THREE.PerspectiveCamera(fov, aspect, near, far);
272
+ break;
273
+ default:
274
+ /* eslint-disable-next-line no-console */
275
+ console.warn("[Camera] Invalid camera type: ".concat(type));
276
+ }
277
+
278
+ // Camera Extrinsics
279
+ (_cam$position = cam.position).set.apply(_cam$position, _toConsumableArray(position));
280
+ // cam.up is only used for determining the axis of rotaion for orbitControls or mapControls,
281
+ // this up does not affect the quaternion of the Camera
282
+ if (up != null) {
283
+ var _cam$up;
284
+ (_cam$up = cam.up).set.apply(_cam$up, _toConsumableArray(up));
285
+ } else {
286
+ var _cam$up2;
287
+ (_cam$up2 = cam.up).set.apply(_cam$up2, _toConsumableArray(_constants.DEFAULT_UP));
288
+ }
289
+ // Note: THREE's Camera's actual normal is inverse of the lookAt
290
+ // Since THREE Camera's quaternion is readOnly and may only be manipulated by methods,
291
+ // must use lookAt().
292
+ // Reset LookAt
293
+ (_cam = cam).lookAt.apply(_cam, _toConsumableArray(position.map(function (val, i) {
294
+ return val - _constants.DEFAULT_NORMAL[i];
295
+ })));
296
+
297
+ // Normal
298
+ // @ts-ignore:T2345 // spread
299
+ var normalVec = _construct(THREE.Vector3, _toConsumableArray(initialNormal));
300
+ var normalQ = new THREE.Quaternion().setFromUnitVectors(_constants.DEFAULT_NORMAL_VEC3, normalVec);
301
+
302
+ // Rotation / Quaternion
303
+ var rotationQ = new THREE.Quaternion();
304
+ if (quaternion == null) {
305
+ var _eulerOrder = eulerOrder.toUpperCase();
306
+ _eulerOrder = _constants.EULER_ORDERS[_eulerOrder] ? _eulerOrder : _constants.EULER_ORDERS.XYZ;
307
+ var euler = _construct(THREE.Euler, _toConsumableArray(rotation).concat([_eulerOrder]));
308
+ rotationQ = new THREE.Quaternion().setFromEuler(euler);
309
+ } else {
310
+ rotationQ = (0, _util.toQuaternion)(quaternion);
311
+ }
312
+
313
+ // Up
314
+ // If an up prop is provided, the camera with align the roll so that the true up vector of
315
+ // the Camera is aligned with the projection of the given up vector in the
316
+ // Camera's image plane.
317
+ var upAlignAngle = 0;
318
+ if (up != null) {
319
+ var qNormalAndRotation = cam.quaternion.clone().premultiply(rotationQ).premultiply(normalQ);
320
+ var givenUpVec = _construct(THREE.Vector3, _toConsumableArray(up)).normalize();
321
+ var lookAtVec = _constants.DEFAULT_NORMAL_VEC3.clone().applyQuaternion(qNormalAndRotation).multiplyScalar(-1);
322
+ var rightVec = new THREE.Vector3().crossVectors(givenUpVec, lookAtVec);
323
+ var projectedUpVec = new THREE.Vector3().crossVectors(lookAtVec, rightVec);
324
+ var trueUpVec = _constants.DEFAULT_UP_VEC3.clone().applyQuaternion(qNormalAndRotation);
325
+ var upAlignSign = trueUpVec.clone().dot(rightVec) > 0 ? -1 : 1;
326
+ upAlignAngle = trueUpVec.angleTo(projectedUpVec) * upAlignSign;
327
+ }
328
+
329
+ // Roll
330
+ // The normal is inverse of the lookAt so the roll must be negated
331
+ var _roll = (-roll + upAlignAngle) % (Math.PI * 2);
332
+ var rollQ = new THREE.Quaternion().setFromAxisAngle(_constants.DEFAULT_NORMAL_VEC3, _roll);
333
+
334
+ // cam.quaternion = normalQ * rotationQ * rollQ
335
+ cam.quaternion.premultiply(rollQ);
336
+ cam.quaternion.premultiply(rotationQ);
337
+ cam.quaternion.premultiply(normalQ);
338
+ cam.updateMatrixWorld();
339
+ return cam;
340
+ }, [position, up, initialNormal, quaternion, roll, left, width, right, top, height, bottom, type, near, far, fov, aspect, eulerOrder, rotation]);
341
+ var cameraNormal = useMemo(function updateNormal() {
342
+ return (0, _util.objectToArray)(_constants.DEFAULT_NORMAL_VEC3.clone().applyQuaternion(camera.quaternion));
343
+ }, [camera]);
344
+ var cameraLookAt = useMemo(function updateLookAt() {
345
+ return [-cameraNormal[0], -cameraNormal[1], -cameraNormal[2]];
346
+ }, [cameraNormal]);
347
+
348
+ // Camera Helper
349
+ var cameraHelper = useMemo(function updateCameraHelper() {
350
+ if (!helper || !camera) {
351
+ return null;
352
+ }
353
+ return new THREE.CameraHelper(camera);
354
+ }, [camera, helper]);
355
+
356
+ // Frustum
357
+ var frustum = useMemo(function updateFrustum() {
358
+ // Camera Frustum
359
+ var frus = new THREE.Frustum();
360
+ frus.setFromProjectionMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse));
361
+ return frus;
362
+ }, [camera]);
363
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Group["default"], _extends({
364
+ position: position
365
+ }, otherProps), /*#__PURE__*/React.createElement(_Group["default"], {
366
+ quaternion: camera.quaternion
367
+ }, /*#__PURE__*/React.createElement(_Box["default"], {
368
+ scale: [1, 1, 1.4],
369
+ castShadow: castShadow,
370
+ receiveShadow: receiveShadow
371
+ }), /*#__PURE__*/React.createElement(_Cylinder["default"], {
372
+ start: [0, 0, -0.7],
373
+ end: [0, 0, -1],
374
+ radiusBottom: 0.3,
375
+ radiusTop: 0.3,
376
+ castShadow: castShadow,
377
+ receiveShadow: receiveShadow
378
+ }), showRoll && /*#__PURE__*/React.createElement(_Group["default"], null, /*#__PURE__*/React.createElement(_Arrow["default"], {
379
+ head: _constants.DEFAULT_UP.map(function (val) {
380
+ return val * 2;
381
+ }),
382
+ color: "yellow"
383
+ }), /*#__PURE__*/React.createElement(_Arrow["default"], {
384
+ head: _constants.DEFAULT_UP.map(function (val) {
385
+ return val * 2;
386
+ }),
387
+ color: "yellow",
388
+ opacity: 0.3,
389
+ roll: roll
390
+ }), /*#__PURE__*/React.createElement(_Circle["default"], {
391
+ color: "yellow",
392
+ thetaLength: roll % (Math.PI * 2),
393
+ thetaStart: Math.PI * 0.5 - roll,
394
+ normal: [0, 0, -1],
395
+ opacity: 0.3
396
+ }), /*#__PURE__*/React.createElement(_Text["default"], {
397
+ text: "local roll: ".concat(roll),
398
+ position: _constants.DEFAULT_UP.map(function (val) {
399
+ return val * 2.2;
400
+ }),
401
+ color: "yellow",
402
+ align: "center",
403
+ size: 0.2,
404
+ billboard: true
405
+ }))), wireframeColor && /*#__PURE__*/React.createElement(_Group["default"], {
406
+ quaternion: camera.quaternion
407
+ }, /*#__PURE__*/React.createElement(_Box["default"], {
408
+ scale: [1, 1, 1.4],
409
+ color: wireframeColor,
410
+ wireframe: true,
411
+ ignoreMouseEvents: true
412
+ }), /*#__PURE__*/React.createElement(_Cylinder["default"], {
413
+ start: [0, 0, -0.7],
414
+ end: [0, 0, -1],
415
+ radiusBottom: 0.3,
416
+ radiusTop: 0.3,
417
+ color: wireframeColor,
418
+ wireframe: true,
419
+ ignoreMouseEvents: true
420
+ })), showUp && /*#__PURE__*/React.createElement(_Group["default"], null, /*#__PURE__*/React.createElement(_Arrow["default"], {
421
+ head: [camera.up.x * 2, camera.up.y * 2, camera.up.z * 2],
422
+ color: "cyan"
423
+ }), /*#__PURE__*/React.createElement(_Text["default"], {
424
+ text: "up",
425
+ position: [camera.up.x * 2.2, camera.up.y * 2.2, camera.up.z * 2.2],
426
+ color: "cyan",
427
+ align: "center",
428
+ size: camera.up.length() * 0.2,
429
+ billboard: true
430
+ })), showNormal && /*#__PURE__*/React.createElement(_Group["default"], null, /*#__PURE__*/React.createElement(_Arrow["default"], {
431
+ head: cameraNormal.map(function (val) {
432
+ return val * 2;
433
+ }),
434
+ color: "lime"
435
+ }), /*#__PURE__*/React.createElement(_Text["default"], {
436
+ text: "normal",
437
+ position: cameraNormal.map(function (val) {
438
+ return val * 2.2;
439
+ }),
440
+ color: "lime",
441
+ align: "center",
442
+ size: 0.2,
443
+ billboard: true
444
+ })), showLookAt && /*#__PURE__*/React.createElement(_Group["default"], null, /*#__PURE__*/React.createElement(_Arrow["default"], {
445
+ head: cameraLookAt.map(function (val) {
446
+ return val * 2;
447
+ }),
448
+ color: "magenta"
449
+ }), /*#__PURE__*/React.createElement(_Text["default"], {
450
+ text: "look",
451
+ position: cameraLookAt.map(function (val) {
452
+ return val * 2.2;
453
+ }),
454
+ color: "magenta",
455
+ align: "center",
456
+ size: 0.2,
457
+ billboard: true
458
+ })), showLabel && /*#__PURE__*/React.createElement(_Label["default"], {
459
+ position: labelOffset,
460
+ up: [0, 0, 1],
461
+ text: labelText,
462
+ animation: _util.billboard
463
+ }), children), helper &&
464
+ /*#__PURE__*/
465
+ // @ts-ignore: Property 'primitive' does not exist on type 'JSX.IntrinsicElements'
466
+ React.createElement("primitive", {
467
+ object: cameraHelper
468
+ }), /*#__PURE__*/React.createElement(CullCoverage, {
469
+ frustum: frustum,
470
+ cull: cull,
471
+ coverageColor: coverageColor,
472
+ coverageOpacity: coverageOpacity
473
+ }));
474
+ };
475
+ var CameraMemo = memo(Camera);
476
+ CameraMemo.displayName = 'Camera';
477
+ var _default = exports["default"] = CameraMemo;
@@ -0,0 +1,9 @@
1
+ import * as React from "react";
2
+ import { MeshProps } from "../primitives/Mesh";
3
+ interface CapsuleProps extends MeshProps {
4
+ start?: Array<number>;
5
+ end?: Array<number>;
6
+ radius?: number;
7
+ }
8
+ declare const CapsuleMemo: React.NamedExoticComponent<CapsuleProps>;
9
+ export default CapsuleMemo;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var THREE = _interopRequireWildcard(require("three"));
10
+ var _Group = _interopRequireWildcard(require("./Group"));
11
+ var _Sphere = _interopRequireDefault(require("../primitives/Sphere"));
12
+ var _Cylinder = _interopRequireDefault(require("../primitives/Cylinder"));
13
+ var _excluded = ["start", "end", "radius", "color", "hoverColor", "children"]; // Capsule.tsx
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
15
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
16
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
17
+ function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
18
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
19
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
20
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
21
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
22
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
23
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
24
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
25
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
26
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
27
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
28
+ var useMemo = React.useMemo,
29
+ memo = React.memo;
30
+ /**
31
+ * Capsule
32
+ *
33
+ * In Standard View, Capsule is a Group comprised of two Spheres and a Cylinder.
34
+ * The Sphere and Cylinder all have the same radius, radiusTop, and radiusBottom.
35
+ * The geometries are constructed with unit radii but these primitives are scaled
36
+ * according to the provided radius property. The start and end properties determine
37
+ * the centers of the bottom and top Spheres and also the start and end of the
38
+ * Cylinder.
39
+ * The position, scale, rotation, quaternion, and other Group properties are extracted
40
+ * and applied to the group.
41
+ *
42
+ * @param {CapsuleProps} props
43
+ */
44
+ var Capsule = function Capsule(props) {
45
+ var _generateGroupProps = (0, _Group.generateGroupProps)(props),
46
+ cleanedProps = _generateGroupProps.cleanedProps,
47
+ groupProps = _generateGroupProps.groupProps;
48
+ var start = cleanedProps.start,
49
+ end = cleanedProps.end,
50
+ radius = cleanedProps.radius,
51
+ color = cleanedProps.color,
52
+ hoverColor = cleanedProps.hoverColor,
53
+ children = cleanedProps.children,
54
+ otherProps = _objectWithoutProperties(cleanedProps, _excluded);
55
+ var _position = groupProps.position;
56
+ var _useMemo = useMemo(function updateStartAndEnd() {
57
+ var _start = start;
58
+ var _end = end;
59
+
60
+ // Generate Start and End if not provided
61
+ if (_start == null || _end == null) {
62
+ if (_position) {
63
+ _start = [_position[0], _position[1] - 0.5, _position[2]];
64
+ _end = [_position[0], _position[1] + 0.5, _position[2]];
65
+ } else {
66
+ _start = [0, -0.5, 0];
67
+ _end = [0, 0.5, 0];
68
+ }
69
+ }
70
+
71
+ // Normalize start and end around center
72
+ // Let Group manage the position
73
+ var startVec = _construct(THREE.Vector3, _toConsumableArray(_start));
74
+ var endVec = _construct(THREE.Vector3, _toConsumableArray(_end));
75
+ var center = startVec.clone().add(endVec).multiplyScalar(0.5);
76
+ // Normalize around center
77
+ startVec.sub(center);
78
+ endVec.sub(center);
79
+ // Vector to Array
80
+ var startN = [startVec.x, startVec.y, startVec.z];
81
+ var endN = [endVec.x, endVec.y, endVec.z];
82
+ return {
83
+ startNorm: startN,
84
+ endNorm: endN,
85
+ centerVec: center
86
+ };
87
+ }, [start, end, _position]),
88
+ startNorm = _useMemo.startNorm,
89
+ endNorm = _useMemo.endNorm,
90
+ centerVec = _useMemo.centerVec;
91
+ groupProps.position = [centerVec.x, centerVec.y, centerVec.z];
92
+ var _radius = useMemo(function updateRadius() {
93
+ return radius || 1;
94
+ }, [radius]);
95
+ return /*#__PURE__*/React.createElement(_Group["default"], _extends({
96
+ color: color,
97
+ hoverColor: hoverColor
98
+ }, groupProps), /*#__PURE__*/React.createElement(_Sphere["default"], _extends({
99
+ radius: _radius,
100
+ position: startNorm
101
+ }, otherProps), children), /*#__PURE__*/React.createElement(_Cylinder["default"], _extends({
102
+ radius: _radius,
103
+ start: startNorm,
104
+ end: endNorm
105
+ }, otherProps), children), /*#__PURE__*/React.createElement(_Sphere["default"], _extends({
106
+ position: endNorm,
107
+ radius: _radius
108
+ }, otherProps), children));
109
+ };
110
+ var CapsuleMemo = memo(Capsule);
111
+ CapsuleMemo.displayName = "Capsule";
112
+ var _default = exports["default"] = CapsuleMemo;
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { GroupProps } from "./Group";
3
+ interface FBXProps extends GroupProps {
4
+ fbxPath?: string;
5
+ fbxURL: string;
6
+ actionIndex?: number;
7
+ }
8
+ declare const FBXMemo: React.NamedExoticComponent<FBXProps>;
9
+ export default FBXMemo;