@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.
- package/.prettierignore +67 -0
- package/.prettierrc +12 -0
- package/CHANGELOG.md +42 -0
- package/LICENSE +8 -0
- package/README.md +199 -0
- package/debug-storybook.log +179 -0
- package/declarations.d.ts +17 -0
- package/dist/standard-view.es.js +9522 -0
- package/dist/standard-view.es.js.map +1 -0
- package/dist/standard-view.umd.js +41 -0
- package/dist/standard-view.umd.js.map +1 -0
- package/fonts/gentilis.bold.typeface.json +1 -0
- package/fonts/gentilis.typeface.json +1 -0
- package/fonts/helvetiker.bold.typeface.json +1 -0
- package/fonts/helvetiker.typeface.json +1 -0
- package/fonts/optimer.bold.typeface.json +1 -0
- package/fonts/optimer.typeface.json +1 -0
- package/images.d.ts +7 -0
- package/index.js +10 -0
- package/lib/controls/OrbitControls.d.ts +9 -0
- package/lib/controls/OrbitControls.js +761 -0
- package/lib/controls/index.d.ts +1 -0
- package/lib/controls/index.js +18 -0
- package/lib/groups/Arrow.d.ts +19 -0
- package/lib/groups/Arrow.js +134 -0
- package/lib/groups/Axis.d.ts +20 -0
- package/lib/groups/Axis.js +147 -0
- package/lib/groups/BoundingBox.d.ts +9 -0
- package/lib/groups/BoundingBox.js +143 -0
- package/lib/groups/Camera.d.ts +32 -0
- package/lib/groups/Camera.js +477 -0
- package/lib/groups/Capsule.d.ts +9 -0
- package/lib/groups/Capsule.js +112 -0
- package/lib/groups/FBX.d.ts +9 -0
- package/lib/groups/FBX.js +213 -0
- package/lib/groups/GLTF.d.ts +9 -0
- package/lib/groups/GLTF.js +198 -0
- package/lib/groups/Group.d.ts +63 -0
- package/lib/groups/Group.js +426 -0
- package/lib/groups/OBJ.d.ts +11 -0
- package/lib/groups/OBJ.js +252 -0
- package/lib/groups/PCD.d.ts +9 -0
- package/lib/groups/PCD.js +82 -0
- package/lib/groups/Path.d.ts +19 -0
- package/lib/groups/Path.js +160 -0
- package/lib/groups/index.d.ts +11 -0
- package/lib/groups/index.js +91 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +298 -0
- package/lib/lights/AmbientLight.d.ts +8 -0
- package/lib/lights/AmbientLight.js +37 -0
- package/lib/lights/DirectionalLight.d.ts +8 -0
- package/lib/lights/DirectionalLight.js +43 -0
- package/lib/lights/HemisphereLight.d.ts +13 -0
- package/lib/lights/HemisphereLight.js +108 -0
- package/lib/lights/LightWithShadows.d.ts +24 -0
- package/lib/lights/LightWithShadows.js +188 -0
- package/lib/lights/PointLight.d.ts +9 -0
- package/lib/lights/PointLight.js +47 -0
- package/lib/lights/RectAreaLight.d.ts +13 -0
- package/lib/lights/RectAreaLight.js +177 -0
- package/lib/lights/SpotLight.d.ts +10 -0
- package/lib/lights/SpotLight.js +49 -0
- package/lib/lights/index.d.ts +6 -0
- package/lib/lights/index.js +48 -0
- package/lib/primitives/Box.d.ts +6 -0
- package/lib/primitives/Box.js +43 -0
- package/lib/primitives/Circle.d.ts +10 -0
- package/lib/primitives/Circle.js +85 -0
- package/lib/primitives/Cylinder.d.ts +15 -0
- package/lib/primitives/Cylinder.js +180 -0
- package/lib/primitives/Label.d.ts +18 -0
- package/lib/primitives/Label.js +189 -0
- package/lib/primitives/Line.d.ts +19 -0
- package/lib/primitives/Line.js +173 -0
- package/lib/primitives/Mesh.d.ts +72 -0
- package/lib/primitives/Mesh.js +642 -0
- package/lib/primitives/Plane.d.ts +7 -0
- package/lib/primitives/Plane.js +47 -0
- package/lib/primitives/Polygon.d.ts +8 -0
- package/lib/primitives/Polygon.js +75 -0
- package/lib/primitives/Quad.d.ts +9 -0
- package/lib/primitives/Quad.js +110 -0
- package/lib/primitives/Sphere.d.ts +14 -0
- package/lib/primitives/Sphere.js +92 -0
- package/lib/primitives/Text.d.ts +20 -0
- package/lib/primitives/Text.js +285 -0
- package/lib/primitives/Triangle.d.ts +8 -0
- package/lib/primitives/Triangle.js +83 -0
- package/lib/primitives/index.d.ts +12 -0
- package/lib/primitives/index.js +90 -0
- package/lib/shaders/index.d.ts +0 -0
- package/lib/shaders/index.js +2 -0
- package/lib/types/three-jsx.d.js +5 -0
- package/lib/utils/constants.js +181 -0
- package/lib/utils/events.d.ts +22 -0
- package/lib/utils/events.js +98 -0
- package/lib/utils/hooks.d.ts +8 -0
- package/lib/utils/hooks.js +96 -0
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/index.js +110 -0
- package/lib/utils/interfaces.d.ts +9 -0
- package/lib/utils/interfaces.js +5 -0
- package/lib/utils/math.d.ts +12 -0
- package/lib/utils/math.js +31 -0
- package/lib/utils/performance.d.ts +7 -0
- package/lib/utils/performance.js +114 -0
- package/lib/utils/styles.js +10 -0
- package/lib/utils/util.d.ts +76 -0
- package/lib/utils/util.js +290 -0
- package/lib/views/ContextBridge.d.ts +23 -0
- package/lib/views/ContextBridge.js +98 -0
- package/lib/views/SceneCamera.d.ts +7 -0
- package/lib/views/SceneCamera.js +52 -0
- package/lib/views/SetBackground.d.ts +9 -0
- package/lib/views/SetBackground.js +90 -0
- package/lib/views/SetControls.d.ts +19 -0
- package/lib/views/SetControls.js +173 -0
- package/lib/views/SetRenderer.d.ts +25 -0
- package/lib/views/SetRenderer.js +66 -0
- package/lib/views/SetShadows.d.ts +7 -0
- package/lib/views/SetShadows.js +48 -0
- package/lib/views/View3D.d.ts +21 -0
- package/lib/views/View3D.js +289 -0
- package/lib/views/ViewContext.d.ts +23 -0
- package/lib/views/ViewContext.js +55 -0
- package/lib/views/index.d.ts +2 -0
- package/lib/views/index.js +20 -0
- package/netlify.toml +15 -0
- package/package.json +110 -0
- package/tsconfig.json +42 -0
- package/tsconfig.prod.json +3 -0
- package/tsconfig.test.json +6 -0
- package/vite.config.ts +37 -0
|
@@ -0,0 +1,85 @@
|
|
|
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 _excluded = ["radius", "scale", "segments", "thetaStart", "thetaLength", "side", "children"]; // Circle.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 useMemo = React.useMemo,
|
|
28
|
+
memo = React.memo;
|
|
29
|
+
/**
|
|
30
|
+
* Circle
|
|
31
|
+
*
|
|
32
|
+
* A Circle's radius property is used to scale the Mesh to the desired
|
|
33
|
+
* size. The geometry is constructed with the default radius of 1.
|
|
34
|
+
* The number of segments, however is passed into the geometry's constructor.
|
|
35
|
+
* More segments make the circle look smoother, but also result in more
|
|
36
|
+
* triangles to render.
|
|
37
|
+
*
|
|
38
|
+
* @param {CircleProps} props
|
|
39
|
+
*/
|
|
40
|
+
var Circle = function Circle(_ref) {
|
|
41
|
+
var _ref$radius = _ref.radius,
|
|
42
|
+
radius = _ref$radius === void 0 ? 1 : _ref$radius,
|
|
43
|
+
scale = _ref.scale,
|
|
44
|
+
_ref$segments = _ref.segments,
|
|
45
|
+
segments = _ref$segments === void 0 ? 32 : _ref$segments,
|
|
46
|
+
_ref$thetaStart = _ref.thetaStart,
|
|
47
|
+
thetaStart = _ref$thetaStart === void 0 ? 0 : _ref$thetaStart,
|
|
48
|
+
_ref$thetaLength = _ref.thetaLength,
|
|
49
|
+
thetaLength = _ref$thetaLength === void 0 ? Math.PI * 2 : _ref$thetaLength,
|
|
50
|
+
_ref$side = _ref.side,
|
|
51
|
+
side = _ref$side === void 0 ? "double" : _ref$side,
|
|
52
|
+
children = _ref.children,
|
|
53
|
+
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
54
|
+
// Radius
|
|
55
|
+
var _scale = useMemo(function updateScale() {
|
|
56
|
+
var r = Math.max(radius, _math.EPS);
|
|
57
|
+
|
|
58
|
+
// Zero Radius Warning
|
|
59
|
+
if (r === _math.EPS) {
|
|
60
|
+
/* eslint-disable-next-line no-console */
|
|
61
|
+
console.warn("[Circle] Zero radius!");
|
|
62
|
+
}
|
|
63
|
+
return scale || [r, r, 1];
|
|
64
|
+
}, [scale, radius]);
|
|
65
|
+
|
|
66
|
+
// Cirle Arguments
|
|
67
|
+
var circleArgs = useMemo(function updateCircleArgs() {
|
|
68
|
+
return [1,
|
|
69
|
+
// radius at scale 1
|
|
70
|
+
segments, thetaStart, thetaLength];
|
|
71
|
+
}, [segments, thetaStart, thetaLength]);
|
|
72
|
+
|
|
73
|
+
// Circle Buffer Geometry
|
|
74
|
+
var geometry = useMemo(function initGeometry() {
|
|
75
|
+
return _construct(THREE.CircleGeometry, _toConsumableArray(circleArgs));
|
|
76
|
+
}, [circleArgs]);
|
|
77
|
+
return /*#__PURE__*/React.createElement(_Mesh["default"], _extends({
|
|
78
|
+
scale: _scale,
|
|
79
|
+
side: side,
|
|
80
|
+
geometry: geometry
|
|
81
|
+
}, otherProps), children);
|
|
82
|
+
};
|
|
83
|
+
var CircleMemo = memo(Circle);
|
|
84
|
+
CircleMemo.displayName = "Circle";
|
|
85
|
+
var _default = exports["default"] = CircleMemo;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { MeshProps } from './Mesh';
|
|
3
|
+
interface CylinderProps extends MeshProps {
|
|
4
|
+
start?: Array<number>;
|
|
5
|
+
end?: Array<number>;
|
|
6
|
+
radius?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
radiusTop?: number;
|
|
9
|
+
radiusBottom?: number;
|
|
10
|
+
radialSegments?: number;
|
|
11
|
+
heightSegments?: number;
|
|
12
|
+
openEnded?: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare const CylinderMemo: React.NamedExoticComponent<CylinderProps>;
|
|
15
|
+
export default CylinderMemo;
|
|
@@ -0,0 +1,180 @@
|
|
|
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 _constants = require("../utils/constants");
|
|
12
|
+
var _math = require("../utils/math");
|
|
13
|
+
var _excluded = ["position", "start", "end", "quaternion", "rotation", "scale", "radius", "radiusTop", "radiusBottom", "height", "radialSegments", "heightSegments", "openEnded", "children"]; // Cylinder.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
|
+
* Cylinder
|
|
32
|
+
*
|
|
33
|
+
* A Cylinder's start and end points are used to determine the height,
|
|
34
|
+
* and rotation of the mesh to represent a cylinder along the start to end
|
|
35
|
+
* vector. The radius is used to scale the mesh for the appropriate thickness.
|
|
36
|
+
* Cylinder's may also have radiusBottom and radiusTop which correspond to the
|
|
37
|
+
* start and end faces respectively. The scale parameter takes least priority if
|
|
38
|
+
* start, end, and radius are provided.
|
|
39
|
+
*
|
|
40
|
+
* @param {CylinderProps} props
|
|
41
|
+
*/
|
|
42
|
+
var Cylinder = function Cylinder(_ref) {
|
|
43
|
+
var position = _ref.position,
|
|
44
|
+
start = _ref.start,
|
|
45
|
+
end = _ref.end,
|
|
46
|
+
quaternion = _ref.quaternion,
|
|
47
|
+
rotation = _ref.rotation,
|
|
48
|
+
_ref$scale = _ref.scale,
|
|
49
|
+
scale = _ref$scale === void 0 ? [1, 1, 1] : _ref$scale,
|
|
50
|
+
radius = _ref.radius,
|
|
51
|
+
_ref$radiusTop = _ref.radiusTop,
|
|
52
|
+
radiusTop = _ref$radiusTop === void 0 ? 1 : _ref$radiusTop,
|
|
53
|
+
_ref$radiusBottom = _ref.radiusBottom,
|
|
54
|
+
radiusBottom = _ref$radiusBottom === void 0 ? 1 : _ref$radiusBottom,
|
|
55
|
+
height = _ref.height,
|
|
56
|
+
_ref$radialSegments = _ref.radialSegments,
|
|
57
|
+
radialSegments = _ref$radialSegments === void 0 ? 32 : _ref$radialSegments,
|
|
58
|
+
_ref$heightSegments = _ref.heightSegments,
|
|
59
|
+
heightSegments = _ref$heightSegments === void 0 ? 1 : _ref$heightSegments,
|
|
60
|
+
_ref$openEnded = _ref.openEnded,
|
|
61
|
+
openEnded = _ref$openEnded === void 0 ? false : _ref$openEnded,
|
|
62
|
+
children = _ref.children,
|
|
63
|
+
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
64
|
+
// Start and End Determine Position (Center), Quaternion, and Height of Cylinder
|
|
65
|
+
var _useMemo = useMemo(function updateDispAndPosition() {
|
|
66
|
+
var _start = start;
|
|
67
|
+
var _end = end;
|
|
68
|
+
|
|
69
|
+
// Generate Start and End if not provided
|
|
70
|
+
if (_start == null || _end == null) {
|
|
71
|
+
if (position) {
|
|
72
|
+
_start = [position[0], position[1] - 0.5, position[2]];
|
|
73
|
+
_end = [position[0], position[1] + 0.5, position[2]];
|
|
74
|
+
} else {
|
|
75
|
+
_start = [0, -0.5, 0];
|
|
76
|
+
_end = [0, 0.5, 0];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
var startV = _construct(THREE.Vector3, _toConsumableArray(_start));
|
|
80
|
+
var endV = _construct(THREE.Vector3, _toConsumableArray(_end));
|
|
81
|
+
|
|
82
|
+
// Displacement
|
|
83
|
+
var dispV = endV.clone().sub(startV);
|
|
84
|
+
|
|
85
|
+
// Center is at the mid-point between start and end
|
|
86
|
+
var posVec = startV.clone().add(endV).multiplyScalar(0.5);
|
|
87
|
+
return {
|
|
88
|
+
dispVec: dispV,
|
|
89
|
+
_position: [posVec.x, posVec.y, posVec.z]
|
|
90
|
+
};
|
|
91
|
+
}, [start, end, position]),
|
|
92
|
+
dispVec = _useMemo.dispVec,
|
|
93
|
+
_position = _useMemo._position;
|
|
94
|
+
|
|
95
|
+
// Quaternion
|
|
96
|
+
var _quaternion = useMemo(function updateQuaternion() {
|
|
97
|
+
if (quaternion) {
|
|
98
|
+
return quaternion;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Cylinder's rotation should line up along start to end direction
|
|
102
|
+
// by default the cylinder is parallel to y-axis
|
|
103
|
+
var normal = dispVec.clone().normalize();
|
|
104
|
+
var q = new THREE.Quaternion().setFromUnitVectors(_constants.Y_AXIS, normal);
|
|
105
|
+
|
|
106
|
+
// Apply additional rotation
|
|
107
|
+
if (rotation) {
|
|
108
|
+
var rot = new THREE.Quaternion().setFromEuler(// @ts-ignore:T2345 // spread
|
|
109
|
+
_construct(THREE.Euler, _toConsumableArray(rotation).concat(['XYZ'])));
|
|
110
|
+
q.premultiply(rot);
|
|
111
|
+
}
|
|
112
|
+
return q;
|
|
113
|
+
}, [dispVec, quaternion, rotation]);
|
|
114
|
+
|
|
115
|
+
// Scale
|
|
116
|
+
var _scale = useMemo(function updateScale() {
|
|
117
|
+
var s = scale;
|
|
118
|
+
if (!Array.isArray(scale) || scale.length !== 3) {
|
|
119
|
+
/* eslint-disable-next-line no-console */
|
|
120
|
+
console.warn("[Cylinder] scale must be a 3x1 array of numbers! scale: ".concat(scale));
|
|
121
|
+
s = [1, 1, 1];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Scale Cylinder height to match distance between start and end
|
|
125
|
+
s[1] = Math.max(dispVec.length(), _math.EPS);
|
|
126
|
+
|
|
127
|
+
// Scale Cylinder to match height
|
|
128
|
+
if (height != null) {
|
|
129
|
+
s[1] = Math.max(height, _math.EPS);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Scale Cylinder to match radius
|
|
133
|
+
if (radius != null) {
|
|
134
|
+
var r = Math.max(radius, _math.EPS);
|
|
135
|
+
s[0] = r;
|
|
136
|
+
s[2] = r;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Zero Radius Warning
|
|
140
|
+
if (s[0] <= _math.EPS && s[2] <= _math.EPS) {
|
|
141
|
+
/* eslint-disable-next-line no-console */
|
|
142
|
+
console.warn("[Cylinder] Zero radius!");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Zero Height Warning
|
|
146
|
+
if (s[1] <= _math.EPS) {
|
|
147
|
+
/* eslint-disable-next-line no-console */
|
|
148
|
+
console.warn("[Cylinder] Zero height!");
|
|
149
|
+
}
|
|
150
|
+
return s;
|
|
151
|
+
}, [dispVec, scale, radius, height]);
|
|
152
|
+
|
|
153
|
+
// Cylinder Arguments
|
|
154
|
+
var cylinderArgs = useMemo(function updateCylinderArgs() {
|
|
155
|
+
// Zero Radius Warning
|
|
156
|
+
if (radiusTop <= _math.EPS && radiusBottom <= _math.EPS) {
|
|
157
|
+
/* eslint-disable-next-line no-console */
|
|
158
|
+
console.warn("[Cylinder] Both top and bottom radius are zero!");
|
|
159
|
+
}
|
|
160
|
+
return [radiusTop, radiusBottom, 1,
|
|
161
|
+
// height at scale 1
|
|
162
|
+
radialSegments, heightSegments, openEnded];
|
|
163
|
+
}, [radiusTop, radiusBottom, radialSegments, heightSegments, openEnded]);
|
|
164
|
+
|
|
165
|
+
// Cylinder Buffer Geometry
|
|
166
|
+
var geometry = useMemo(function initGeometry() {
|
|
167
|
+
// @ts-ignore:T2345 // spread
|
|
168
|
+
return _construct(THREE.CylinderGeometry, _toConsumableArray(cylinderArgs));
|
|
169
|
+
}, [cylinderArgs]);
|
|
170
|
+
return /*#__PURE__*/React.createElement(_Mesh["default"], _extends({
|
|
171
|
+
position: _position,
|
|
172
|
+
scale: _scale,
|
|
173
|
+
quaternion: _quaternion,
|
|
174
|
+
rotation: rotation,
|
|
175
|
+
geometry: geometry
|
|
176
|
+
}, otherProps), children);
|
|
177
|
+
};
|
|
178
|
+
var CylinderMemo = memo(Cylinder);
|
|
179
|
+
CylinderMemo.displayName = 'Cylinder';
|
|
180
|
+
var _default = exports["default"] = CylinderMemo;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { MeshProps } from "./Mesh";
|
|
3
|
+
interface LabelProps extends MeshProps {
|
|
4
|
+
text?: string;
|
|
5
|
+
fontName?: string;
|
|
6
|
+
fontStyle?: string;
|
|
7
|
+
backgroundColor?: string;
|
|
8
|
+
noBackground?: boolean;
|
|
9
|
+
borderColor?: string;
|
|
10
|
+
borderThickness?: number;
|
|
11
|
+
noBorder?: boolean;
|
|
12
|
+
textColor?: string;
|
|
13
|
+
resolution?: number;
|
|
14
|
+
align?: string;
|
|
15
|
+
billboard?: boolean;
|
|
16
|
+
}
|
|
17
|
+
declare const LabelMemo: React.NamedExoticComponent<LabelProps>;
|
|
18
|
+
export default LabelMemo;
|
|
@@ -0,0 +1,189 @@
|
|
|
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 _Plane = _interopRequireDefault(require("./Plane"));
|
|
11
|
+
var _math = require("../utils/math");
|
|
12
|
+
var _util = require("../utils/util");
|
|
13
|
+
var _excluded = ["text", "fontName", "fontStyle", "color", "backgroundColor", "noBackground", "borderColor", "borderThickness", "noBorder", "transparent", "opacity", "textColor", "anisotropy", "resolution", "align", "billboard", "children"]; // Label.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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
18
|
+
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."); }
|
|
19
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
20
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
21
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
22
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
23
|
+
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; } }
|
|
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 _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
26
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
27
|
+
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; }
|
|
28
|
+
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; }
|
|
29
|
+
var useRef = React.useRef,
|
|
30
|
+
useEffect = React.useEffect,
|
|
31
|
+
useMemo = React.useMemo,
|
|
32
|
+
memo = React.memo;
|
|
33
|
+
/**
|
|
34
|
+
* Label
|
|
35
|
+
*
|
|
36
|
+
* Label is composed within a Plane. The text is drawn on a canvas element
|
|
37
|
+
* which is then converted to a texture for a plane. Unlike Text, the
|
|
38
|
+
* geometric complexity of Label does not increase with the number of
|
|
39
|
+
* letters in the text, since there is always just a plane segment rendered.
|
|
40
|
+
* There is a slight overhead for creating the canvas and applying it as
|
|
41
|
+
* a texture. Label may accept any HTML canvas fontName and fontStyle.
|
|
42
|
+
* The resolution of the texture may also be controlled. Keep in mind that
|
|
43
|
+
* higher resolution does look crisp even at high zooms, but requires more memory
|
|
44
|
+
* for storing the texture.
|
|
45
|
+
*
|
|
46
|
+
* The Label's position may be aligned to a specific anchor point of the label
|
|
47
|
+
* with the align prop. The anchor point of the label is what the position refers to.
|
|
48
|
+
*
|
|
49
|
+
* The ◼'s represent the anchor points.
|
|
50
|
+
*
|
|
51
|
+
* ◼----◼----◼
|
|
52
|
+
* | |
|
|
53
|
+
* ◼ ◼ ◼
|
|
54
|
+
* | |
|
|
55
|
+
* ◼----◼----◼
|
|
56
|
+
*
|
|
57
|
+
* @param {LabelProps} props
|
|
58
|
+
*/
|
|
59
|
+
var Label = function Label(_ref) {
|
|
60
|
+
var _ref$text = _ref.text,
|
|
61
|
+
text = _ref$text === void 0 ? "Label" : _ref$text,
|
|
62
|
+
_ref$fontName = _ref.fontName,
|
|
63
|
+
fontName = _ref$fontName === void 0 ? "san-serif" : _ref$fontName,
|
|
64
|
+
_ref$fontStyle = _ref.fontStyle,
|
|
65
|
+
fontStyle = _ref$fontStyle === void 0 ? "" : _ref$fontStyle,
|
|
66
|
+
_ref$color = _ref.color,
|
|
67
|
+
color = _ref$color === void 0 ? "white" : _ref$color,
|
|
68
|
+
_ref$backgroundColor = _ref.backgroundColor,
|
|
69
|
+
backgroundColor = _ref$backgroundColor === void 0 ? "black" : _ref$backgroundColor,
|
|
70
|
+
_ref$noBackground = _ref.noBackground,
|
|
71
|
+
noBackground = _ref$noBackground === void 0 ? false : _ref$noBackground,
|
|
72
|
+
_ref$borderColor = _ref.borderColor,
|
|
73
|
+
borderColor = _ref$borderColor === void 0 ? "white" : _ref$borderColor,
|
|
74
|
+
_ref$borderThickness = _ref.borderThickness,
|
|
75
|
+
borderThickness = _ref$borderThickness === void 0 ? 10 : _ref$borderThickness,
|
|
76
|
+
_ref$noBorder = _ref.noBorder,
|
|
77
|
+
noBorder = _ref$noBorder === void 0 ? false : _ref$noBorder,
|
|
78
|
+
transparent = _ref.transparent,
|
|
79
|
+
_ref$opacity = _ref.opacity,
|
|
80
|
+
opacity = _ref$opacity === void 0 ? 1 : _ref$opacity,
|
|
81
|
+
_ref$textColor = _ref.textColor,
|
|
82
|
+
textColor = _ref$textColor === void 0 ? "white" : _ref$textColor,
|
|
83
|
+
_ref$anisotropy = _ref.anisotropy,
|
|
84
|
+
anisotropy = _ref$anisotropy === void 0 ? 16 : _ref$anisotropy,
|
|
85
|
+
_ref$resolution = _ref.resolution,
|
|
86
|
+
resolution = _ref$resolution === void 0 ? 32 : _ref$resolution,
|
|
87
|
+
_ref$align = _ref.align,
|
|
88
|
+
align = _ref$align === void 0 ? "center" : _ref$align,
|
|
89
|
+
_ref$billboard = _ref.billboard,
|
|
90
|
+
billboard = _ref$billboard === void 0 ? false : _ref$billboard,
|
|
91
|
+
children = _ref.children,
|
|
92
|
+
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
93
|
+
var _transparent = transparent != null ? transparent : opacity < 1 - _math.EPS;
|
|
94
|
+
_transparent = noBackground ? true : _transparent;
|
|
95
|
+
|
|
96
|
+
// Font
|
|
97
|
+
var font = useMemo(function updateFont() {
|
|
98
|
+
return "".concat(fontStyle, " ").concat(resolution, "px ").concat(fontName);
|
|
99
|
+
}, [fontStyle, resolution, fontName]);
|
|
100
|
+
var _useMemo = useMemo(function updateTexture() {
|
|
101
|
+
// Init Canvas
|
|
102
|
+
var canvas = document.createElement("canvas");
|
|
103
|
+
var ctx = canvas.getContext("2d");
|
|
104
|
+
if (!ctx) {
|
|
105
|
+
/* eslint-disable-next-line no-console */
|
|
106
|
+
console.warn('[Label] Failed to getContext("2d") of canvas');
|
|
107
|
+
return [undefined, 1];
|
|
108
|
+
}
|
|
109
|
+
canvas.width = 2;
|
|
110
|
+
canvas.height = 2;
|
|
111
|
+
|
|
112
|
+
// Label Width
|
|
113
|
+
ctx.font = font;
|
|
114
|
+
var textWidth = ctx.measureText(text).width;
|
|
115
|
+
var width = (0, _math.nextPowerOfTwo)(textWidth);
|
|
116
|
+
var height = (0, _math.nextPowerOfTwo)(resolution) * 2;
|
|
117
|
+
var asp = width / height;
|
|
118
|
+
|
|
119
|
+
// Resize Canvas to Fit Label
|
|
120
|
+
canvas.width = width;
|
|
121
|
+
canvas.height = height;
|
|
122
|
+
ctx.font = font; // Reset font
|
|
123
|
+
|
|
124
|
+
// Clear
|
|
125
|
+
ctx.clearRect(0, 0, width, height);
|
|
126
|
+
|
|
127
|
+
// Background
|
|
128
|
+
if (!noBackground) {
|
|
129
|
+
ctx.fillStyle = backgroundColor;
|
|
130
|
+
ctx.fillRect(0, 0, width, height);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Border
|
|
134
|
+
if (!noBorder) {
|
|
135
|
+
ctx.strokeStyle = borderColor;
|
|
136
|
+
ctx.lineWidth = borderThickness;
|
|
137
|
+
ctx.strokeRect(0, 0, width, height);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Fill Text
|
|
141
|
+
ctx.fillStyle = textColor;
|
|
142
|
+
ctx.fillText(text, (width - textWidth) / 2, height * 0.666);
|
|
143
|
+
|
|
144
|
+
// Label Texture
|
|
145
|
+
var tex = new THREE.CanvasTexture(canvas);
|
|
146
|
+
tex.anisotropy = anisotropy;
|
|
147
|
+
return [tex, asp];
|
|
148
|
+
}, [text, resolution, font, backgroundColor, noBackground, borderColor, borderThickness, noBorder, textColor, anisotropy]),
|
|
149
|
+
_useMemo2 = _slicedToArray(_useMemo, 2),
|
|
150
|
+
texture = _useMemo2[0],
|
|
151
|
+
aspect = _useMemo2[1];
|
|
152
|
+
|
|
153
|
+
// Label Geometry
|
|
154
|
+
var labelGeometry = useRef(new THREE.PlaneGeometry());
|
|
155
|
+
|
|
156
|
+
// Align
|
|
157
|
+
var prevAspect = useRef(1);
|
|
158
|
+
var prevAlign = useRef("center");
|
|
159
|
+
useEffect(function updateAlign() {
|
|
160
|
+
var _labelGeometry$curren;
|
|
161
|
+
// Align
|
|
162
|
+
var diagonal = [prevAspect.current, 1, 1];
|
|
163
|
+
var alignmentOffset = (0, _util.getAlignmentOffset)(prevAlign.current, align, diagonal);
|
|
164
|
+
// @ts-ignore:TS2556 // spread
|
|
165
|
+
(_labelGeometry$curren = labelGeometry.current).translate.apply(_labelGeometry$curren, _toConsumableArray(alignmentOffset));
|
|
166
|
+
prevAlign.current = align;
|
|
167
|
+
}, [labelGeometry, align]);
|
|
168
|
+
|
|
169
|
+
// Aspect
|
|
170
|
+
useEffect(function updateScale() {
|
|
171
|
+
// Scale Plane to Label Text Width (textwidth x 1 x 1)
|
|
172
|
+
// Reset
|
|
173
|
+
labelGeometry.current.scale(1 / prevAspect.current, 1, 1);
|
|
174
|
+
// Aspect
|
|
175
|
+
labelGeometry.current.scale(aspect, 1, 1);
|
|
176
|
+
prevAspect.current = aspect;
|
|
177
|
+
}, [labelGeometry, aspect]);
|
|
178
|
+
return /*#__PURE__*/React.createElement(_Plane["default"], _extends({
|
|
179
|
+
map: texture,
|
|
180
|
+
transparent: _transparent,
|
|
181
|
+
opacity: opacity,
|
|
182
|
+
color: color,
|
|
183
|
+
geometry: labelGeometry.current,
|
|
184
|
+
animation: billboard ? _util.billboard : undefined
|
|
185
|
+
}, otherProps), children);
|
|
186
|
+
};
|
|
187
|
+
var LabelMemo = memo(Label);
|
|
188
|
+
LabelMemo.displayName = "Label";
|
|
189
|
+
var _default = exports["default"] = LabelMemo;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
export interface LineProps {
|
|
4
|
+
start?: Array<number>;
|
|
5
|
+
end?: Array<number>;
|
|
6
|
+
points?: Array<Array<number>>;
|
|
7
|
+
color?: string | THREE.Color;
|
|
8
|
+
hoverColor?: string;
|
|
9
|
+
hoverable?: boolean;
|
|
10
|
+
opacity?: number;
|
|
11
|
+
transparent?: boolean;
|
|
12
|
+
groupMember?: boolean;
|
|
13
|
+
castShadow?: boolean;
|
|
14
|
+
geometry?: THREE.BufferGeometry;
|
|
15
|
+
material?: THREE.Material;
|
|
16
|
+
children?: any;
|
|
17
|
+
}
|
|
18
|
+
declare const LineMemo: React.NamedExoticComponent<LineProps>;
|
|
19
|
+
export default LineMemo;
|