@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,213 @@
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 _FBXLoader = require("three/examples/jsm/loaders/FBXLoader");
11
+ var _hooks = require("../utils/hooks");
12
+ var _Group = _interopRequireDefault(require("./Group"));
13
+ var _primitives = require("../primitives");
14
+ var _excluded = ["color"],
15
+ _excluded2 = ["fbxPath", "fbxURL", "actionIndex", "view3DEnvMap", "castShadow", "receiveShadow"];
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
17
+ 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); }
18
+ 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); }
19
+ 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; }
20
+ 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; }
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; } // FBX.tsx
27
+ function updateAllMaterials(color, /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
28
+ children, /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
29
+ materialProps) {
30
+ if (children == null) {
31
+ return;
32
+ }
33
+ var _children = Array.isArray(children) ? children : [children];
34
+ _children.map(function (object) {
35
+ // Recurse into Groups
36
+ if (object.constructor.name === "Group" && object.children) {
37
+ updateAllMaterials(color, object.children, materialProps);
38
+ }
39
+
40
+ // @ts-ignore:TS2339 material does not exist on Object3D
41
+ if (object.material) {
42
+ if (color) {
43
+ // @ts-ignore:TS2339 material does not exist on Object3D
44
+ object.material.color.set(color);
45
+ }
46
+ Object.entries(materialProps).map(function (_ref) {
47
+ var _ref2 = _slicedToArray(_ref, 2),
48
+ propName = _ref2[0],
49
+ value = _ref2[1];
50
+ /* eslint-disable no-param-reassign */
51
+ // @ts-ignore:TS2339 material does not exist on Object3D
52
+ object.material[propName] = value;
53
+ /* eslint-enable no-param-reassign */
54
+ return null;
55
+ });
56
+ }
57
+ return null;
58
+ });
59
+ }
60
+ function loadFBX(_ref3) {
61
+ var group = _ref3.group,
62
+ fbxPath = _ref3.fbxPath,
63
+ fbxURL = _ref3.fbxURL,
64
+ mixer = _ref3.mixer,
65
+ envMap = _ref3.envMap,
66
+ castShadow = _ref3.castShadow,
67
+ receiveShadow = _ref3.receiveShadow,
68
+ materialProps = _ref3.materialProps,
69
+ _ref3$actionIndex = _ref3.actionIndex,
70
+ actionIndex = _ref3$actionIndex === void 0 ? 0 : _ref3$actionIndex;
71
+ // No FBX
72
+ if (fbxURL == null) {
73
+ /* eslint-disable no-console */
74
+ console.warn("[FBX] No fbxURL");
75
+ /* eslint-enable no-console */
76
+ return;
77
+ }
78
+
79
+ // FBX
80
+ var fbxLoader = new _FBXLoader.FBXLoader();
81
+ fbxLoader.setPath(fbxPath);
82
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
83
+ fbxLoader.load(fbxURL, function (fbx) {
84
+ if (group.current && fbx) {
85
+ // Remove Loading Label or Previous OBJ
86
+ if (group.current.children) {
87
+ group.current.children.map(function (child) {
88
+ return group.current.remove(child);
89
+ });
90
+ }
91
+
92
+ // Material Props
93
+ if (materialProps) {
94
+ var color = materialProps.color,
95
+ otherMaterialProps = _objectWithoutProperties(materialProps, _excluded);
96
+ updateAllMaterials(color, fbx.scene.children, otherMaterialProps);
97
+ }
98
+
99
+ // Animation
100
+ /* eslint-disable-next-line no-param-reassign */
101
+ mixer.current = new THREE.AnimationMixer(fbx);
102
+ if (fbx.animations && fbx.animations.length > 0) {
103
+ var action = mixer.current.clipAction(fbx.animations[actionIndex]);
104
+ action.play();
105
+ }
106
+
107
+ // Env Map + Shadows
108
+ fbx.traverse(function (mesh) {
109
+ /* eslint-disable no-param-reassign */
110
+ // @ts-ignore
111
+ if (mesh.isMesh) {
112
+ if (envMap) {
113
+ // @ts-ignore
114
+ mesh.material.envMap = envMap;
115
+ }
116
+ mesh.castShadow = castShadow;
117
+ mesh.receiveShadow = receiveShadow;
118
+ }
119
+ /* eslint-enable no-param-reassign */
120
+ });
121
+
122
+ // Add FBX
123
+ group.current.add(fbx);
124
+ }
125
+ });
126
+ }
127
+ var FBX = function FBX(_ref4) {
128
+ var _ref4$fbxPath = _ref4.fbxPath,
129
+ fbxPath = _ref4$fbxPath === void 0 ? "" : _ref4$fbxPath,
130
+ fbxURL = _ref4.fbxURL,
131
+ _ref4$actionIndex = _ref4.actionIndex,
132
+ actionIndex = _ref4$actionIndex === void 0 ? 0 : _ref4$actionIndex,
133
+ _ref4$view3DEnvMap = _ref4.view3DEnvMap,
134
+ view3DEnvMap = _ref4$view3DEnvMap === void 0 ? false : _ref4$view3DEnvMap,
135
+ _ref4$castShadow = _ref4.castShadow,
136
+ castShadow = _ref4$castShadow === void 0 ? false : _ref4$castShadow,
137
+ _ref4$receiveShadow = _ref4.receiveShadow,
138
+ receiveShadow = _ref4$receiveShadow === void 0 ? false : _ref4$receiveShadow,
139
+ otherProps = _objectWithoutProperties(_ref4, _excluded2);
140
+ var group = (0, _react.useRef)(null);
141
+ var mixer = (0, _react.useRef)(null);
142
+ var _useViewContext = (0, _hooks.useViewContext)(),
143
+ envMap = _useViewContext.envMap;
144
+
145
+ // Material Props
146
+ var materialProps = (0, _react.useMemo)(function updateMaterialProps() {
147
+ // No Material Props
148
+ if (!otherProps || Object.keys(otherProps).length === 0) {
149
+ return undefined;
150
+ }
151
+
152
+ // Acceptable Material Props
153
+ var materialPropsKeys = ["color", "wireframe", "opacity", "transparent", "side", "depthWrite", "depthTest"];
154
+
155
+ // Extract Acceptable Props
156
+ var props = {};
157
+ materialPropsKeys.map(function (propName) {
158
+ if (otherProps[propName]) {
159
+ props[propName] = otherProps[propName];
160
+ }
161
+ return null;
162
+ });
163
+ return Object.keys(props).length > 0 ? props : undefined;
164
+ }, [otherProps]);
165
+
166
+ // Environment Map
167
+ var _envMap = (0, _react.useMemo)(function updateEnvMap() {
168
+ if (view3DEnvMap) {
169
+ return envMap;
170
+ }
171
+ return null;
172
+ }, [view3DEnvMap, envMap]);
173
+
174
+ // Loading Text
175
+ var loadingText = (0, _react.useMemo)(function updateLoadText() {
176
+ return fbxURL || "No fbxURL";
177
+ }, [fbxURL]);
178
+
179
+ // Load FBX and Animation Mixer
180
+ (0, _react.useEffect)(function updateFBXandMixer() {
181
+ if (group) {
182
+ loadFBX({
183
+ group: group,
184
+ fbxPath: fbxPath,
185
+ fbxURL: fbxURL,
186
+ mixer: mixer,
187
+ envMap: _envMap,
188
+ castShadow: castShadow,
189
+ receiveShadow: receiveShadow,
190
+ materialProps: materialProps,
191
+ actionIndex: actionIndex
192
+ });
193
+ }
194
+ }, [group, fbxPath, fbxURL, actionIndex, _envMap, castShadow, receiveShadow, materialProps]);
195
+
196
+ // Animation Mixer Update
197
+ var clock = new THREE.Clock();
198
+ (0, _hooks.useFrame)(function updateMixer() {
199
+ var delta = clock.getDelta();
200
+ if (mixer.current) {
201
+ mixer.current.update(delta);
202
+ }
203
+ });
204
+ return /*#__PURE__*/_react["default"].createElement(_Group["default"], _extends({
205
+ ref: group
206
+ }, otherProps), /*#__PURE__*/_react["default"].createElement(_primitives.Label, {
207
+ text: loadingText,
208
+ textColor: "red"
209
+ }));
210
+ };
211
+ var FBXMemo = /*#__PURE__*/(0, _react.memo)(FBX);
212
+ FBXMemo.displayName = "FBX";
213
+ var _default = exports["default"] = FBXMemo;
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ import { GroupProps } from './Group';
3
+ interface GLTFProps extends GroupProps {
4
+ gltfPath?: string;
5
+ gltfURL: string;
6
+ dracoDecoderPath?: string;
7
+ }
8
+ declare const GLTFMemo: React.NamedExoticComponent<GLTFProps>;
9
+ export default GLTFMemo;
@@ -0,0 +1,198 @@
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 _GLTFLoader = require("three/examples/jsm/loaders/GLTFLoader");
10
+ var _DRACOLoader = require("three/examples/jsm/loaders/DRACOLoader");
11
+ var _Label = _interopRequireDefault(require("../primitives/Label"));
12
+ var _Group = _interopRequireDefault(require("./Group"));
13
+ var _hooks = require("../utils/hooks");
14
+ var _excluded = ["color"],
15
+ _excluded2 = ["gltfPath", "gltfURL", "dracoDecoderPath", "view3DEnvMap", "castShadow", "receiveShadow"];
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
17
+ 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); }
18
+ 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); }
19
+ 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; }
20
+ 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; }
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; } // GLTF.tsx
27
+ var useEffect = React.useEffect,
28
+ useMemo = React.useMemo,
29
+ useRef = React.useRef,
30
+ memo = React.memo;
31
+ var DRACO_DECODER_SOURCE = 'https://raw.githubusercontent.com/mrdoob/three.js/master/examples/jsm/libs/draco/';
32
+ function updateAllMaterials(color, /* eslint-disable @typescript-eslint/no-explicit-any */
33
+ children, materialProps) {
34
+ if (children == null) {
35
+ return;
36
+ }
37
+ var _children = Array.isArray(children) ? children : [children];
38
+ _children.map(function (object) {
39
+ // Recurse into Groups
40
+ if (object.constructor.name === 'Group' && object.children) {
41
+ updateAllMaterials(color, object.children, materialProps);
42
+ }
43
+
44
+ // @ts-ignore:TS2339 material does not exist on Object3D
45
+ if (object.material) {
46
+ if (color) {
47
+ // @ts-ignore:TS2339 material does not exist on Object3D
48
+ object.material.color.set(color);
49
+ }
50
+ Object.entries(materialProps).map(function (_ref) {
51
+ var _ref2 = _slicedToArray(_ref, 2),
52
+ propName = _ref2[0],
53
+ value = _ref2[1];
54
+ /* eslint-disable no-param-reassign */
55
+ // @ts-ignore:TS2339 material does not exist on Object3D
56
+ object.material[propName] = value;
57
+ /* eslint-enable no-param-reassign */
58
+ return null;
59
+ });
60
+ }
61
+ return null;
62
+ });
63
+ }
64
+ function loadGLTF(_ref3) {
65
+ var group = _ref3.group,
66
+ gltfPath = _ref3.gltfPath,
67
+ gltfURL = _ref3.gltfURL,
68
+ dracoDecoderPath = _ref3.dracoDecoderPath,
69
+ envMap = _ref3.envMap,
70
+ castShadow = _ref3.castShadow,
71
+ receiveShadow = _ref3.receiveShadow,
72
+ materialProps = _ref3.materialProps;
73
+ // No GLTF
74
+ if (gltfURL == null) {
75
+ /* eslint-disable no-console */
76
+ console.warn('[GLTF] No gltfURL');
77
+ /* eslint-enable no-console */
78
+ return;
79
+ }
80
+
81
+ // GLTF
82
+ var gltfLoader = new _GLTFLoader.GLTFLoader();
83
+ var dracoLoader = new _DRACOLoader.DRACOLoader();
84
+ dracoLoader.setDecoderPath(dracoDecoderPath);
85
+ gltfLoader.setDRACOLoader(dracoLoader);
86
+ gltfLoader.setPath(gltfPath);
87
+ gltfLoader.load(gltfURL, function (gltf) {
88
+ if (group.current && gltf.scene && gltf.scene.children) {
89
+ // Remove Loading Label or Previous OBJ
90
+ if (group.current.children) {
91
+ group.current.children.map(function (child) {
92
+ return group.current.remove(child);
93
+ });
94
+ }
95
+
96
+ // Material Props
97
+ if (materialProps) {
98
+ var color = materialProps.color,
99
+ otherMaterialProps = _objectWithoutProperties(materialProps, _excluded);
100
+ updateAllMaterials(color, gltf.scene.children, otherMaterialProps);
101
+ }
102
+
103
+ // Env Map + Shadows
104
+ gltf.scene.traverse(function (mesh) {
105
+ /* eslint-disable no-param-reassign */
106
+ // @ts-ignore
107
+ if (mesh.isMesh) {
108
+ if (envMap) {
109
+ // @ts-ignore
110
+ mesh.material.envMap = envMap;
111
+ }
112
+ mesh.castShadow = castShadow;
113
+ mesh.receiveShadow = receiveShadow;
114
+ }
115
+ /* eslint-enable no-param-reassign */
116
+ });
117
+
118
+ // Add GLTF
119
+ group.current.add(gltf.scene);
120
+ }
121
+ });
122
+ }
123
+ var GLTF = function GLTF(_ref4) {
124
+ var _ref4$gltfPath = _ref4.gltfPath,
125
+ gltfPath = _ref4$gltfPath === void 0 ? '' : _ref4$gltfPath,
126
+ gltfURL = _ref4.gltfURL,
127
+ _ref4$dracoDecoderPat = _ref4.dracoDecoderPath,
128
+ dracoDecoderPath = _ref4$dracoDecoderPat === void 0 ? DRACO_DECODER_SOURCE : _ref4$dracoDecoderPat,
129
+ _ref4$view3DEnvMap = _ref4.view3DEnvMap,
130
+ view3DEnvMap = _ref4$view3DEnvMap === void 0 ? false : _ref4$view3DEnvMap,
131
+ _ref4$castShadow = _ref4.castShadow,
132
+ castShadow = _ref4$castShadow === void 0 ? false : _ref4$castShadow,
133
+ _ref4$receiveShadow = _ref4.receiveShadow,
134
+ receiveShadow = _ref4$receiveShadow === void 0 ? false : _ref4$receiveShadow,
135
+ otherProps = _objectWithoutProperties(_ref4, _excluded2);
136
+ var group = useRef(null);
137
+ var _useViewContext = (0, _hooks.useViewContext)(),
138
+ envMap = _useViewContext.envMap;
139
+
140
+ // Material Props
141
+ var materialProps = useMemo(function updateMaterialProps() {
142
+ // No Material Props
143
+ if (!otherProps || Object.keys(otherProps).length === 0) {
144
+ return undefined;
145
+ }
146
+
147
+ // Acceptable Material Props
148
+ var materialPropsKeys = ['color', 'wireframe', 'opacity', 'transparent', 'side', 'depthWrite', 'depthTest'];
149
+
150
+ // Extract Acceptable Props
151
+ var props = {};
152
+ materialPropsKeys.map(function (propName) {
153
+ if (otherProps[propName]) {
154
+ props[propName] = otherProps[propName];
155
+ }
156
+ return null;
157
+ });
158
+ return Object.keys(props).length > 0 ? props : undefined;
159
+ }, [otherProps]);
160
+
161
+ // Environment Map
162
+ var _envMap = useMemo(function updateEnvMap() {
163
+ if (view3DEnvMap) {
164
+ return envMap;
165
+ }
166
+ return null;
167
+ }, [view3DEnvMap, envMap]);
168
+
169
+ // Loading Text
170
+ var loadingText = useMemo(function updateLoadText() {
171
+ return gltfURL || 'No gltfURL';
172
+ }, [gltfURL]);
173
+
174
+ // Load GLTF
175
+ useEffect(function updateGLTF() {
176
+ if (group) {
177
+ loadGLTF({
178
+ group: group,
179
+ gltfPath: gltfPath,
180
+ gltfURL: gltfURL,
181
+ dracoDecoderPath: dracoDecoderPath,
182
+ envMap: _envMap,
183
+ castShadow: castShadow,
184
+ receiveShadow: receiveShadow,
185
+ materialProps: materialProps
186
+ });
187
+ }
188
+ }, [group, gltfPath, gltfURL, dracoDecoderPath, _envMap, castShadow, receiveShadow, materialProps]);
189
+ return /*#__PURE__*/React.createElement(_Group["default"], _extends({
190
+ ref: group
191
+ }, otherProps), /*#__PURE__*/React.createElement(_Label["default"], {
192
+ text: loadingText,
193
+ textColor: "red"
194
+ }));
195
+ };
196
+ var GLTFMemo = memo(GLTF);
197
+ GLTFMemo.displayName = 'GLTF';
198
+ var _default = exports["default"] = GLTFMemo;
@@ -0,0 +1,63 @@
1
+ import * as React from "react";
2
+ import * as THREE from "three";
3
+ export interface GroupProps {
4
+ position?: Array<number>;
5
+ scale?: Array<number>;
6
+ rotation?: Array<number>;
7
+ eulerOrder?: string;
8
+ normal?: Array<number>;
9
+ roll?: number;
10
+ up?: Array<number>;
11
+ quaternion?: Array<number> | THREE.Quaternion;
12
+ materialType?: string;
13
+ edges?: boolean;
14
+ edgeColor?: string;
15
+ edgeThresholdAngle?: number;
16
+ view3DEnvMap?: boolean;
17
+ color?: string | THREE.Color;
18
+ hoverColor?: string;
19
+ opacity?: number;
20
+ transparent?: boolean;
21
+ wireframe?: boolean;
22
+ visible?: boolean;
23
+ side?: string | THREE.Side;
24
+ castShadow?: boolean;
25
+ receiveShadow?: boolean;
26
+ groupMember?: boolean;
27
+ animation?: Function;
28
+ state?: object;
29
+ ref?: React.Ref<any>;
30
+ onClick?: Function;
31
+ onDoubleClick?: Function;
32
+ onWheel?: Function;
33
+ onPointerUp?: Function;
34
+ onPointerDown?: Function;
35
+ onPointerOver?: Function;
36
+ onPointerOut?: Function;
37
+ onPointerMove?: Function;
38
+ hoverable?: boolean;
39
+ mousePropagation?: boolean;
40
+ clickSensitivity?: number;
41
+ ignoreMouseEvents?: boolean;
42
+ children?: any;
43
+ }
44
+ declare const GroupMemo: React.NamedExoticComponent<GroupProps>;
45
+ export default GroupMemo;
46
+ /**
47
+ * Generate Group Props
48
+ *
49
+ * For shapes composed of multiple primitives, like the Capsule,
50
+ * the meshes are grouped together. In order to rotate, scale,
51
+ * translate, and animate the entire group rather than each individual primitive,
52
+ * the group properties are extracted out and nulled for the primitives.
53
+ *
54
+ * Other properties, such as material related properties are passed down
55
+ * so the appearance of the group is uniform.
56
+ *
57
+ * @param {any} props
58
+ * @returns {GroupProps}
59
+ */
60
+ export declare function generateGroupProps(props: any): {
61
+ cleanedProps: any;
62
+ groupProps: any;
63
+ };