@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,173 @@
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 _math = require("../utils/math");
11
+ var _styles = require("../utils/styles");
12
+ var _excluded = ["start", "end", "points", "color", "hoverColor", "hoverable", "transparent", "opacity", "castShadow", "geometry", "material", "children"]; // LineSegment.tsx
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 _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; }
16
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
17
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
18
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
19
+ 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."); }
20
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
21
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
22
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
23
+ 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."); }
24
+ 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; } }
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 _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; } }
27
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
28
+ 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; }
29
+ 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; }
30
+ var useState = React.useState,
31
+ useEffect = React.useEffect,
32
+ useMemo = React.useMemo,
33
+ memo = React.memo;
34
+ /**
35
+ * Line
36
+ *
37
+ * Unlike most 3D objects that are meshes underneath, Line is another
38
+ * type of object. Line is a wrapper component of
39
+ * @react-three/fiber/three.js's Line.
40
+ *
41
+ * In Standard View, Lines may be defined with a start and end position.
42
+ * A line may also have more than just the end points. If an array of
43
+ * points are provided, the start and end points are ignored and the line
44
+ * is createed as an ordered path from the first point to the last.
45
+ *
46
+ * If no geometry nor material is passed in, default geometry and
47
+ * lineBasicMaterial will be generated based on the properties provided.
48
+ *
49
+ * @param {LineProps} props
50
+ */
51
+ var Line = function Line(_ref) {
52
+ var _ref$start = _ref.start,
53
+ start = _ref$start === void 0 ? [0, 0, 0] : _ref$start,
54
+ _ref$end = _ref.end,
55
+ end = _ref$end === void 0 ? [1, 0, 0] : _ref$end,
56
+ _ref$points = _ref.points,
57
+ points = _ref$points === void 0 ? [] : _ref$points,
58
+ _ref$color = _ref.color,
59
+ color = _ref$color === void 0 ? _styles.DEFAULT_COLOR : _ref$color,
60
+ hoverColor = _ref.hoverColor,
61
+ _ref$hoverable = _ref.hoverable,
62
+ hoverable = _ref$hoverable === void 0 ? true : _ref$hoverable,
63
+ transparent = _ref.transparent,
64
+ _ref$opacity = _ref.opacity,
65
+ opacity = _ref$opacity === void 0 ? 1 : _ref$opacity,
66
+ _ref$castShadow = _ref.castShadow,
67
+ castShadow = _ref$castShadow === void 0 ? false : _ref$castShadow,
68
+ geometry = _ref.geometry,
69
+ material = _ref.material,
70
+ children = _ref.children,
71
+ otherProps = _objectWithoutProperties(_ref, _excluded);
72
+ // Color
73
+ var _useState = useState(color),
74
+ _useState2 = _slicedToArray(_useState, 2),
75
+ _color = _useState2[0],
76
+ setColor = _useState2[1];
77
+ useEffect(function updateColor() {
78
+ setColor(color);
79
+ }, [color]);
80
+
81
+ // Vertices
82
+ var vertices = useMemo(function updateVertices() {
83
+ var v = [];
84
+ if (points == null || points.length === 0) {
85
+ // @ts-ignore:2345 // spread
86
+ v.push(_construct(THREE.Vector3, _toConsumableArray(start)));
87
+ // @ts-ignore:2345 // spread
88
+ v.push(_construct(THREE.Vector3, _toConsumableArray(end)));
89
+ } else {
90
+ // @ts-ignore:2345 // spread
91
+ points.map(function (point) {
92
+ return v.push(_construct(THREE.Vector3, _toConsumableArray(point)));
93
+ });
94
+ }
95
+ return v;
96
+ }, [start, end, points]);
97
+
98
+ // Memoized BufferGeometry for the line
99
+ var lineGeometry = useMemo(function createLineGeometry() {
100
+ if (geometry) {
101
+ return geometry;
102
+ }
103
+ var geom = new THREE.BufferGeometry();
104
+ geom.setFromPoints(vertices);
105
+ return geom;
106
+ }, [geometry, vertices]);
107
+
108
+ // Geometry Component always uses BufferGeometry
109
+ var GeometryComponent = memo(function GeometryComponent() {
110
+ // Always use a BufferGeometry (either provided or generated)
111
+ // @ts-ignore: property primitive does not exist on IntrinsicElements
112
+ return /*#__PURE__*/React.createElement("primitive", {
113
+ attach: "geometry",
114
+ object: lineGeometry
115
+ });
116
+ });
117
+
118
+ // Material Props
119
+ var materialProps = useMemo(function updateMaterialProps() {
120
+ return {
121
+ material: material,
122
+ color: _color,
123
+ transparent: transparent != null ? transparent : opacity < 1 - _math.EPS,
124
+ opacity: opacity
125
+ };
126
+ }, [material, _color, transparent, opacity]);
127
+ return (
128
+ /*#__PURE__*/
129
+ // @ts-ignore:TS2322 line type clash
130
+ // @ts-ignore: Type '{ children: any[]; groupMember?: boolean | undefined; onPointerOver: () => void; onPointerOut: () => void; castShadow: boolean; }' is not assignable to type 'SVGLineElementAttributes<SVGLineElement>'
131
+ React.createElement("line", _extends({
132
+ onPointerOver: function setHover() {
133
+ if (hoverable && hoverColor != null) {
134
+ setColor(hoverColor);
135
+ }
136
+ },
137
+ onPointerOut: function unsetHover() {
138
+ if (hoverable && hoverColor != null) {
139
+ setColor(color);
140
+ }
141
+ }
142
+ // @ts-ignore: Property 'castShadow' does not exist on type 'SVGLineElementAttributes<SVGLineElement>'
143
+ ,
144
+ castShadow: castShadow
145
+ }, otherProps), /*#__PURE__*/React.createElement(GeometryComponent, null), /*#__PURE__*/React.createElement(MaterialComponent, materialProps), children)
146
+ );
147
+ };
148
+ var LineMemo = memo(Line);
149
+ LineMemo.displayName = 'Line';
150
+ var _default = exports["default"] = LineMemo;
151
+ var MaterialComponent = memo(function MaterialComponent(_ref2) {
152
+ var material = _ref2.material,
153
+ color = _ref2.color,
154
+ transparent = _ref2.transparent,
155
+ opacity = _ref2.opacity;
156
+ if (material) {
157
+ // @ts-ignore:2339 property primitive does not exist
158
+ return /*#__PURE__*/React.createElement("primitive", {
159
+ object: material
160
+ });
161
+ }
162
+ return (
163
+ /*#__PURE__*/
164
+ // @ts-ignore: Property 'lineBasicMaterial' does not exist on type 'JSX.IntrinsicElements'
165
+ React.createElement("lineBasicMaterial", {
166
+ attach: "material",
167
+ color: color,
168
+ transparent: transparent,
169
+ opacity: opacity
170
+ })
171
+ );
172
+ });
173
+ MaterialComponent.displayName = 'MaterialComponent';
@@ -0,0 +1,72 @@
1
+ import * as React from 'react';
2
+ import * as THREE from 'three';
3
+ import { StandardViewTypes } from '../utils/interfaces';
4
+ export interface MeshProps {
5
+ position?: Array<number>;
6
+ scale?: Array<number>;
7
+ geometry?: StandardViewTypes.Geometries;
8
+ rotation?: Array<number>;
9
+ eulerOrder?: string;
10
+ normal?: Array<number>;
11
+ up?: Array<number>;
12
+ roll?: number;
13
+ quaternion?: Array<number> | THREE.Quaternion;
14
+ materialType?: string;
15
+ material?: THREE.Material;
16
+ view3DEnvMap?: boolean;
17
+ color?: string | THREE.Color;
18
+ hoverColor?: string;
19
+ opacity?: number;
20
+ transparent?: boolean;
21
+ roughness?: number;
22
+ metalness?: number;
23
+ reflectivity?: number;
24
+ anisotropy?: number;
25
+ texturePath?: string;
26
+ textureURL?: string;
27
+ map?: THREE.Texture;
28
+ aoMap?: THREE.Texture;
29
+ aoMapIntensity?: number;
30
+ bumpMap?: THREE.Texture;
31
+ bumpScale?: number;
32
+ normalMap?: THREE.Texture;
33
+ normalMapType?: number;
34
+ normalMapScale?: number;
35
+ displacementMap?: THREE.Texture;
36
+ displacementMapScale?: number;
37
+ displacementBias?: number;
38
+ roughnessMap?: THREE.Texture;
39
+ metalnessMap?: THREE.Texture;
40
+ alphaMap?: THREE.Texture;
41
+ envMap?: THREE.Texture;
42
+ envMapIntensity?: number;
43
+ wireframe?: boolean;
44
+ side?: string | THREE.Side;
45
+ depthWrite?: boolean;
46
+ depthTest?: boolean;
47
+ renderOrder?: number;
48
+ visible?: boolean;
49
+ groupMember?: boolean;
50
+ castShadow?: boolean;
51
+ receiveShadow?: boolean;
52
+ animation?: Function;
53
+ ref?: React.Ref<any>;
54
+ state?: object;
55
+ onClick?: Function;
56
+ onDoubleClick?: Function;
57
+ onWheel?: Function;
58
+ onPointerUp?: Function;
59
+ onPointerDown?: Function;
60
+ onPointerOver?: Function;
61
+ onPointerOut?: Function;
62
+ onPointerMove?: Function;
63
+ hoverable?: boolean;
64
+ mousePropagation?: boolean;
65
+ clickSensitivity?: number;
66
+ ignoreMouseEvents?: boolean;
67
+ track?: boolean;
68
+ frame?: number;
69
+ children?: any;
70
+ }
71
+ declare const MeshMemo: React.NamedExoticComponent<MeshProps>;
72
+ export default MeshMemo;