@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,47 @@
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 _Mesh = _interopRequireDefault(require("./Mesh"));
11
+ var _util = require("../utils/util");
12
+ var _excluded = ["side", "billboard", "children"]; // Plane.tsx
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
14
+ 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); }
15
+ 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); }
16
+ 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; }
17
+ 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; }
18
+ var useMemo = React.useMemo,
19
+ memo = React.memo;
20
+ /**
21
+ * Plane
22
+ *
23
+ * In Standard View, the Plane mesh is rotated to match the normal
24
+ * property if provided. This allows for easier create of Planes.
25
+ * All other properties are pass along to the Plane's Mesh.
26
+ *
27
+ * @param {PlaneProps} props
28
+ */
29
+ var Plane = function Plane(_ref) {
30
+ var _ref$side = _ref.side,
31
+ side = _ref$side === void 0 ? "double" : _ref$side,
32
+ billboard = _ref.billboard,
33
+ children = _ref.children,
34
+ otherProps = _objectWithoutProperties(_ref, _excluded);
35
+ // Plane Buffer Geometry
36
+ var geometry = useMemo(function initGeometry() {
37
+ return new THREE.PlaneGeometry(1, 1, 1);
38
+ }, []);
39
+ return /*#__PURE__*/React.createElement(_Mesh["default"], _extends({
40
+ side: side,
41
+ geometry: geometry,
42
+ animation: billboard ? _util.billboard : undefined
43
+ }, otherProps), children);
44
+ };
45
+ var PlaneMemo = memo(Plane);
46
+ PlaneMemo.displayName = "Plane";
47
+ var _default = exports["default"] = PlaneMemo;
@@ -0,0 +1,8 @@
1
+ import * as React from "react";
2
+ import { MeshProps } from "./Mesh";
3
+ interface PolygonProps extends MeshProps {
4
+ points?: Array<Array<number>>;
5
+ depth?: number;
6
+ }
7
+ declare const PolygonMemo: React.NamedExoticComponent<PolygonProps>;
8
+ export default PolygonMemo;
@@ -0,0 +1,75 @@
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 _Mesh = _interopRequireDefault(require("./Mesh"));
11
+ var _excluded = ["points", "depth", "children"]; // Polygon.tsx
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
13
+ 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); }
14
+ 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); }
15
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
16
+ 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."); }
17
+ 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; } }
18
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
19
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
20
+ 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; }
21
+ 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; }
22
+ 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; }
23
+ var memo = React.memo;
24
+ /**
25
+ * Polygon
26
+ *
27
+ * In Standard View, Polygon actually composes a THREE.ExtrudeBufferGeometry.
28
+ * The points need to be 2d and passed in drawing order.
29
+ * By providing depth, we can create the polygonal prism.
30
+ * Like most other 3D objects, this is also composed with Mesh and so all
31
+ * Mesh properties may be applied.
32
+ *
33
+ * @param {PolygonProps} props
34
+ */
35
+ var Polygon = function Polygon(_ref) {
36
+ var _ref$points = _ref.points,
37
+ points = _ref$points === void 0 ? [[0, 0], [2, 0], [3, 1], [2, 2], [0, 2]] : _ref$points,
38
+ _ref$depth = _ref.depth,
39
+ depth = _ref$depth === void 0 ? 0 : _ref$depth,
40
+ children = _ref.children,
41
+ otherProps = _objectWithoutProperties(_ref, _excluded);
42
+ var shape = React.useMemo(function initShape() {
43
+ /* eslint-disable-next-line no-shadow */
44
+ var shape = new THREE.Shape();
45
+ if (points.length <= 2) return shape;
46
+
47
+ // Move to start point
48
+ // @ts-ignore:T2345
49
+ shape.moveTo.apply(shape, _toConsumableArray(points[0]));
50
+ // Connect points except for start point
51
+ // @ts-ignore:T2345
52
+ points.slice(1).forEach(function (point) {
53
+ return shape.lineTo.apply(shape, _toConsumableArray(point));
54
+ });
55
+ return shape;
56
+ }, [points]);
57
+ var options = React.useMemo(function initOptions() {
58
+ return {
59
+ steps: 1,
60
+ depth: depth,
61
+ bevelEnabled: false
62
+ };
63
+ }, [depth]);
64
+
65
+ // Extrude Buffer Geometry
66
+ var geometry = React.useMemo(function initGeometry() {
67
+ return new THREE.ExtrudeGeometry(shape, options);
68
+ }, [shape, options]);
69
+ return /*#__PURE__*/React.createElement(_Mesh["default"], _extends({
70
+ geometry: geometry
71
+ }, otherProps), children);
72
+ };
73
+ var PolygonMemo = memo(Polygon);
74
+ PolygonMemo.displayName = "Polygon";
75
+ var _default = exports["default"] = PolygonMemo;
@@ -0,0 +1,9 @@
1
+ import * as React from "react";
2
+ import { MeshProps } from "./Mesh";
3
+ interface QuadProps extends MeshProps {
4
+ points?: Array<Array<number>>;
5
+ indices?: Array<Array<number>>;
6
+ coplanarThreshold?: number;
7
+ }
8
+ declare const QuadMemo: React.NamedExoticComponent<QuadProps>;
9
+ export default QuadMemo;
@@ -0,0 +1,110 @@
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 _Triangle = _interopRequireDefault(require("./Triangle"));
11
+ var _math = require("../utils/math");
12
+ var _excluded = ["points", "indices", "coplanarThreshold", "side", "children"]; // Quad.tsx
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
14
+ 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); }
15
+ 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); }
16
+ 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; }
17
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
18
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
19
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
20
+ 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."); }
21
+ 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; } }
22
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
23
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
24
+ 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; }
25
+ 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; }
26
+ 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; }
27
+ var useEffect = React.useEffect,
28
+ useMemo = React.useMemo,
29
+ memo = React.memo;
30
+ /**
31
+ * Quad
32
+ *
33
+ * In Standard View, Quad is actually composed with a Triangle,
34
+ * employing THREE.BufferGeometry underneath. Unlike Triangle,
35
+ * which can take an arbitrary number of vertices, Quad is
36
+ * limited to exactly 4.
37
+ *
38
+ * @param {QuadProps} props
39
+ */
40
+ var Quad = function Quad(_ref) {
41
+ var _ref$points = _ref.points,
42
+ points = _ref$points === void 0 ? [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]] : _ref$points,
43
+ _ref$indices = _ref.indices,
44
+ indices = _ref$indices === void 0 ? [[0, 1, 2], [2, 3, 0]] : _ref$indices,
45
+ _ref$coplanarThreshol = _ref.coplanarThreshold,
46
+ coplanarThreshold = _ref$coplanarThreshol === void 0 ? _math.EPS_NANO : _ref$coplanarThreshol,
47
+ _ref$side = _ref.side,
48
+ side = _ref$side === void 0 ? "double" : _ref$side,
49
+ children = _ref.children,
50
+ otherProps = _objectWithoutProperties(_ref, _excluded);
51
+ // Points
52
+ var _points = useMemo(function updatePoints() {
53
+ // Default Points
54
+ var p = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]];
55
+
56
+ // Valid points
57
+ if (Array.isArray(points)) {
58
+ p = points;
59
+ }
60
+
61
+ // Exactly 4 Points
62
+ if (p.length > 4) {
63
+ // Too Many Points
64
+ p = p.slice(0, 4);
65
+ } else if (p.length < 4) {
66
+ // Too Few Points
67
+ while (p.length < 4) {
68
+ p.push([0, 0, 0]);
69
+ }
70
+ }
71
+ return p;
72
+ }, [points]);
73
+
74
+ // Indices
75
+ var _indices = useMemo(function updateIndices() {
76
+ // Default Indices
77
+ var ind = [[0, 1, 2], [2, 3, 0]];
78
+
79
+ // Valid indices
80
+ if (Array.isArray(indices) && indices.length === 2) {
81
+ ind = indices;
82
+ }
83
+ return ind;
84
+ }, [indices]);
85
+
86
+ // Planarity
87
+ useEffect(function checkPlanarity() {
88
+ var p0 = _construct(THREE.Vector3, _toConsumableArray(_points[0]));
89
+ var p1 = _construct(THREE.Vector3, _toConsumableArray(_points[1]));
90
+ var p2 = _construct(THREE.Vector3, _toConsumableArray(_points[2]));
91
+ var p3 = _construct(THREE.Vector3, _toConsumableArray(_points[3]));
92
+ var p01 = p1.clone().sub(p0);
93
+ var p02 = p2.clone().sub(p0);
94
+ var p03 = p3.clone().sub(p0);
95
+ var p01x02 = p01.clone().cross(p02).normalize();
96
+ var p01x03 = p01.clone().cross(p03).normalize();
97
+ if (Math.abs(p01x02.dot(p01x03)) < 1 - coplanarThreshold) {
98
+ /* eslint-disable-next-line no-console */
99
+ console.warn("[Quad] Points are not co-planar!");
100
+ }
101
+ }, [_points, coplanarThreshold]);
102
+ return /*#__PURE__*/React.createElement(_Triangle["default"], _extends({
103
+ points: _points,
104
+ indices: _indices,
105
+ side: side
106
+ }, otherProps), children);
107
+ };
108
+ var QuadMemo = memo(Quad);
109
+ QuadMemo.displayName = "Quad";
110
+ var _default = exports["default"] = QuadMemo;
@@ -0,0 +1,14 @@
1
+ import * as React from "react";
2
+ import { MeshProps } from "./Mesh";
3
+ interface SphereProps extends MeshProps {
4
+ radius?: number;
5
+ widthSegments?: number;
6
+ heightSegments?: number;
7
+ phiStart?: number;
8
+ phiLength?: number;
9
+ thetaStart?: number;
10
+ thetaLength?: number;
11
+ scale?: Array<number>;
12
+ }
13
+ declare const SphereMemo: React.NamedExoticComponent<SphereProps>;
14
+ export default SphereMemo;
@@ -0,0 +1,92 @@
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 _Mesh = _interopRequireDefault(require("./Mesh"));
11
+ var _math = require("../utils/math");
12
+ var _performance = require("../utils/performance");
13
+ var _excluded = ["radius", "widthSegments", "heightSegments", "phiStart", "phiLength", "thetaStart", "thetaLength", "scale", "children"]; // Sphere.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
+ forwardRef = React.forwardRef;
31
+ /**
32
+ * Sphere
33
+ *
34
+ * In Standard View, the radius property of Sphere is used to scale the
35
+ * Mesh appropriately. The actual geometry is constructed with unit radius.
36
+ * The number of widthSegments and heightSegments, however may be specified
37
+ * to determine how smooth the sphere looks. More segments will incur
38
+ * renderring more triangles.
39
+ *
40
+ * @param {SphereProps} props
41
+ */
42
+ var Sphere = forwardRef(function Sphere(_ref, ref) {
43
+ var _ref$radius = _ref.radius,
44
+ radius = _ref$radius === void 0 ? 1 : _ref$radius,
45
+ _ref$widthSegments = _ref.widthSegments,
46
+ widthSegments = _ref$widthSegments === void 0 ? 32 : _ref$widthSegments,
47
+ _ref$heightSegments = _ref.heightSegments,
48
+ heightSegments = _ref$heightSegments === void 0 ? 32 : _ref$heightSegments,
49
+ _ref$phiStart = _ref.phiStart,
50
+ phiStart = _ref$phiStart === void 0 ? 0 : _ref$phiStart,
51
+ _ref$phiLength = _ref.phiLength,
52
+ phiLength = _ref$phiLength === void 0 ? Math.PI * 2 : _ref$phiLength,
53
+ _ref$thetaStart = _ref.thetaStart,
54
+ thetaStart = _ref$thetaStart === void 0 ? 0 : _ref$thetaStart,
55
+ _ref$thetaLength = _ref.thetaLength,
56
+ thetaLength = _ref$thetaLength === void 0 ? Math.PI : _ref$thetaLength,
57
+ scale = _ref.scale,
58
+ children = _ref.children,
59
+ otherProps = _objectWithoutProperties(_ref, _excluded);
60
+ (0, _performance.performanceStart)("Sphere");
61
+
62
+ // Radius
63
+ var _scale = useMemo(function updateScale() {
64
+ var r = Math.max(radius, _math.EPS);
65
+
66
+ // Zero Radius Warning
67
+ if (r === _math.EPS) {
68
+ /* eslint-disable-next-line no-console */
69
+ console.warn("[Sphere] Zero radius!");
70
+ }
71
+ return scale || [r, r, r];
72
+ }, [scale, radius]);
73
+
74
+ // Sphere Arguments
75
+ var sphereArgs = useMemo(function updateSphereArgs() {
76
+ return [1, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength];
77
+ }, [widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength]);
78
+
79
+ // Sphere Buffer Geometry
80
+ var geometry = useMemo(function initGeometry() {
81
+ return _construct(THREE.SphereGeometry, _toConsumableArray(sphereArgs));
82
+ }, [sphereArgs]);
83
+ (0, _performance.performanceEnd)("Sphere");
84
+ return /*#__PURE__*/React.createElement(React.Fragment, null, (0, _performance.performanceStart)("Around Mesh"), /*#__PURE__*/React.createElement(_Mesh["default"], _extends({
85
+ ref: ref,
86
+ scale: _scale,
87
+ geometry: geometry
88
+ }, otherProps), children), (0, _performance.performanceEnd)("Around Mesh"));
89
+ });
90
+ var SphereMemo = memo(Sphere);
91
+ SphereMemo.displayName = "Sphere";
92
+ var _default = exports["default"] = SphereMemo;
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ import { MeshProps } from './Mesh';
3
+ interface TextProps extends MeshProps {
4
+ text?: string;
5
+ fontName?: string;
6
+ fontFile?: string;
7
+ size?: number;
8
+ height?: number;
9
+ depth?: number;
10
+ align?: string;
11
+ curveSegments?: number;
12
+ bevelEnabled?: boolean;
13
+ bevelThickness?: number;
14
+ bevelSize?: number;
15
+ bevelOffset?: number;
16
+ bevelSegments?: number;
17
+ billboard?: boolean;
18
+ }
19
+ declare const TextMemo: React.NamedExoticComponent<TextProps>;
20
+ export default TextMemo;