@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,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
declare function SetBackground({ backgroundColor, backgroundTextureURL, backgroundEquirectangularTextureURL, backgroundEquirectangularRGBEURL, }: {
|
|
3
|
+
backgroundColor: any;
|
|
4
|
+
backgroundTextureURL: any;
|
|
5
|
+
backgroundEquirectangularTextureURL: any;
|
|
6
|
+
backgroundEquirectangularRGBEURL: any;
|
|
7
|
+
}): null;
|
|
8
|
+
declare const SetBackgroundMemo: React.MemoExoticComponent<typeof SetBackground>;
|
|
9
|
+
export default SetBackgroundMemo;
|
|
@@ -0,0 +1,90 @@
|
|
|
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 THREE = _three;
|
|
11
|
+
var _RGBELoader = require("three/examples/jsm/loaders/RGBELoader");
|
|
12
|
+
var _utils = require("../utils");
|
|
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
|
+
// SetBackground.tsx
|
|
15
|
+
|
|
16
|
+
var useEffect = React.useEffect,
|
|
17
|
+
memo = React.memo;
|
|
18
|
+
function SetBackground(_ref) {
|
|
19
|
+
var backgroundColor = _ref.backgroundColor,
|
|
20
|
+
backgroundTextureURL = _ref.backgroundTextureURL,
|
|
21
|
+
backgroundEquirectangularTextureURL = _ref.backgroundEquirectangularTextureURL,
|
|
22
|
+
backgroundEquirectangularRGBEURL = _ref.backgroundEquirectangularRGBEURL;
|
|
23
|
+
var _useViewContext = (0, _utils.useViewContext)(),
|
|
24
|
+
gl = _useViewContext.gl,
|
|
25
|
+
scene = _useViewContext.scene,
|
|
26
|
+
setViewContext = _useViewContext.setViewContext;
|
|
27
|
+
useEffect(function updateBackground() {
|
|
28
|
+
var pmremGenerator = new _three.PMREMGenerator(gl);
|
|
29
|
+
pmremGenerator.compileEquirectangularShader();
|
|
30
|
+
if (backgroundEquirectangularRGBEURL) {
|
|
31
|
+
// HDR
|
|
32
|
+
// RGBE Equirectangular Skybox
|
|
33
|
+
var path = backgroundEquirectangularRGBEURL;
|
|
34
|
+
new _RGBELoader.RGBELoader().setDataType(THREE.FloatType).load(path, function (texture) {
|
|
35
|
+
// Mark as equirectangular
|
|
36
|
+
texture.mapping = THREE.EquirectangularReflectionMapping;
|
|
37
|
+
// For HDR normally keep colorSpace as Linear
|
|
38
|
+
texture.colorSpace = THREE.LinearSRGBColorSpace;
|
|
39
|
+
scene.background = texture;
|
|
40
|
+
|
|
41
|
+
// Using Prefiltered Mipmapped Radiance Environment Map for much smoother envmaps
|
|
42
|
+
var envMap = pmremGenerator.fromEquirectangular(texture).texture;
|
|
43
|
+
scene.environment = envMap;
|
|
44
|
+
setViewContext({
|
|
45
|
+
envMap: envMap
|
|
46
|
+
});
|
|
47
|
+
texture.dispose();
|
|
48
|
+
pmremGenerator.dispose();
|
|
49
|
+
});
|
|
50
|
+
} else if (backgroundEquirectangularTextureURL) {
|
|
51
|
+
// LDR
|
|
52
|
+
// Equirectangular Skybox
|
|
53
|
+
var _path = backgroundEquirectangularTextureURL;
|
|
54
|
+
new THREE.TextureLoader().load(_path, function (texture) {
|
|
55
|
+
texture.mapping = THREE.EquirectangularReflectionMapping;
|
|
56
|
+
texture.colorSpace = THREE.SRGBColorSpace;
|
|
57
|
+
scene.background = texture;
|
|
58
|
+
var envMap = pmremGenerator.fromEquirectangular(texture).texture;
|
|
59
|
+
scene.environment = envMap;
|
|
60
|
+
setViewContext({
|
|
61
|
+
envMap: envMap
|
|
62
|
+
});
|
|
63
|
+
texture.dispose();
|
|
64
|
+
pmremGenerator.dispose();
|
|
65
|
+
});
|
|
66
|
+
} else if (backgroundTextureURL) {
|
|
67
|
+
// 2D Background
|
|
68
|
+
// Background Image
|
|
69
|
+
var _path2 = backgroundTextureURL;
|
|
70
|
+
new THREE.TextureLoader().load(_path2, function (texture) {
|
|
71
|
+
texture.colorSpace = THREE.SRGBColorSpace;
|
|
72
|
+
scene.background = texture;
|
|
73
|
+
});
|
|
74
|
+
} else if (backgroundColor != null) {
|
|
75
|
+
// Solid Color
|
|
76
|
+
// Background Color
|
|
77
|
+
gl.setClearColor(backgroundColor);
|
|
78
|
+
scene.background = null;
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
// setViewContext causes useState to update setViewContexValue
|
|
82
|
+
// in ViewContextProvider this triggers an update in useViewContext,
|
|
83
|
+
// hence a endless update cycle will occur if updateBackground depended on setViewContext
|
|
84
|
+
/* eslint-disable-next-line react-hooks/exhaustive-deps */
|
|
85
|
+
[gl, scene, backgroundEquirectangularRGBEURL, backgroundEquirectangularTextureURL, backgroundTextureURL, backgroundColor]);
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
var SetBackgroundMemo = memo(SetBackground);
|
|
89
|
+
SetBackgroundMemo.displayName = 'SetBackground';
|
|
90
|
+
var _default = exports["default"] = SetBackgroundMemo;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
declare function SetControls({ controlsType, cameraExtrinsics, polarAngle, azimuthAngle, controlsProps, }: {
|
|
3
|
+
controlsType: any;
|
|
4
|
+
cameraExtrinsics: any;
|
|
5
|
+
polarAngle: any;
|
|
6
|
+
azimuthAngle: any;
|
|
7
|
+
controlsProps: any;
|
|
8
|
+
}): null;
|
|
9
|
+
declare const SetControlsMemo: React.MemoExoticComponent<typeof SetControls>;
|
|
10
|
+
export default SetControlsMemo;
|
|
11
|
+
/**
|
|
12
|
+
* UpdateControls
|
|
13
|
+
*
|
|
14
|
+
* Isolates the useFrame hook to avoid larger components, namely
|
|
15
|
+
* SetControls, from re-rendering up to 3 times--this is a bug
|
|
16
|
+
* from @react-three/fiber.
|
|
17
|
+
* Any @react-three/fiber hook call incurs additional renders.
|
|
18
|
+
*/
|
|
19
|
+
export declare const UpdateControls: React.NamedExoticComponent<object>;
|
|
@@ -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"] = exports.UpdateControls = void 0;
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
var THREE = _interopRequireWildcard(require("three"));
|
|
10
|
+
var _TrackballControls = require("three/examples/jsm/controls/TrackballControls");
|
|
11
|
+
var _OrbitControls = require("three/examples/jsm/controls/OrbitControls");
|
|
12
|
+
var _MapControls = require("three/examples/jsm/controls/MapControls");
|
|
13
|
+
var _hooks = require("../utils/hooks");
|
|
14
|
+
var _constants = require("../utils/constants");
|
|
15
|
+
var _math = require("../utils/math");
|
|
16
|
+
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); }
|
|
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 _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 _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
25
|
+
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."); }
|
|
26
|
+
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; } }
|
|
27
|
+
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; }
|
|
28
|
+
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; } }
|
|
29
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } // SetControls.tsx
|
|
30
|
+
var useEffect = React.useEffect,
|
|
31
|
+
useState = React.useState,
|
|
32
|
+
useMemo = React.useMemo,
|
|
33
|
+
memo = React.memo;
|
|
34
|
+
|
|
35
|
+
// Helper function for deep comparison
|
|
36
|
+
var isEqual = function isEqual(a, b) {
|
|
37
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
38
|
+
};
|
|
39
|
+
function SetControls(_ref) {
|
|
40
|
+
var controlsType = _ref.controlsType,
|
|
41
|
+
cameraExtrinsics = _ref.cameraExtrinsics,
|
|
42
|
+
polarAngle = _ref.polarAngle,
|
|
43
|
+
azimuthAngle = _ref.azimuthAngle,
|
|
44
|
+
controlsProps = _ref.controlsProps;
|
|
45
|
+
var _useViewContext = (0, _hooks.useViewContext)(),
|
|
46
|
+
camera = _useViewContext.camera,
|
|
47
|
+
gl = _useViewContext.gl;
|
|
48
|
+
|
|
49
|
+
// Set CameraControls
|
|
50
|
+
var CameraControls = useMemo(function updateCameraControls() {
|
|
51
|
+
switch (controlsType) {
|
|
52
|
+
case _constants.CONTROLS_TYPES.TRACKBALL_CONTROLS:
|
|
53
|
+
return _TrackballControls.TrackballControls;
|
|
54
|
+
case _constants.CONTROLS_TYPES.ORBIT_CONTROLS:
|
|
55
|
+
return _OrbitControls.OrbitControls;
|
|
56
|
+
case _constants.CONTROLS_TYPES.MAP_CONTROLS:
|
|
57
|
+
return _MapControls.MapControls;
|
|
58
|
+
default:
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}, [controlsType]);
|
|
62
|
+
var _useState = useState(controlsProps),
|
|
63
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
64
|
+
_controlsProps = _useState2[0],
|
|
65
|
+
setControlsProps = _useState2[1];
|
|
66
|
+
useEffect(function updateControlsProps() {
|
|
67
|
+
// Update Controls Props
|
|
68
|
+
if (!isEqual(_controlsProps, controlsProps)) {
|
|
69
|
+
setControlsProps(controlsProps);
|
|
70
|
+
}
|
|
71
|
+
}, [controlsProps, _controlsProps]);
|
|
72
|
+
var _useState3 = useState(cameraExtrinsics),
|
|
73
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
74
|
+
_cameraExtrinsics = _useState4[0],
|
|
75
|
+
setCameraExtrinsics = _useState4[1];
|
|
76
|
+
useEffect(function updateCameraExtrinsics() {
|
|
77
|
+
// Update Camera Extrinsics
|
|
78
|
+
if (!isEqual(_cameraExtrinsics, cameraExtrinsics)) {
|
|
79
|
+
setCameraExtrinsics(cameraExtrinsics);
|
|
80
|
+
}
|
|
81
|
+
}, [cameraExtrinsics, _cameraExtrinsics]);
|
|
82
|
+
useEffect(function updateCameraControls() {
|
|
83
|
+
var _camera$position;
|
|
84
|
+
// Clear Camera Controls
|
|
85
|
+
if (camera.controls != null) {
|
|
86
|
+
camera.controls.dispose();
|
|
87
|
+
camera.controls = null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Camera Extrinsics
|
|
91
|
+
var position = _cameraExtrinsics.position,
|
|
92
|
+
up = _cameraExtrinsics.up,
|
|
93
|
+
target = _cameraExtrinsics.target,
|
|
94
|
+
rotation = _cameraExtrinsics.rotation,
|
|
95
|
+
roll = _cameraExtrinsics.roll;
|
|
96
|
+
(_camera$position = camera.position).set.apply(_camera$position, _toConsumableArray(position));
|
|
97
|
+
camera.up = _construct(THREE.Vector3, _toConsumableArray(up)).normalize();
|
|
98
|
+
camera.target = _construct(THREE.Vector3, _toConsumableArray(target));
|
|
99
|
+
camera.lookAt(camera.target);
|
|
100
|
+
if (rotation) {
|
|
101
|
+
var _camera$rotation;
|
|
102
|
+
// Default rotation is camera pointing in z-axis with up as y-axis.
|
|
103
|
+
(_camera$rotation = camera.rotation).set.apply(_camera$rotation, _toConsumableArray(rotation));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Apply Camera Roll
|
|
107
|
+
camera.roll = roll;
|
|
108
|
+
var look = target.map(function (val, i) {
|
|
109
|
+
return val - position[i];
|
|
110
|
+
});
|
|
111
|
+
var lookVec = _construct(THREE.Vector3, _toConsumableArray(look)).normalize();
|
|
112
|
+
var rollQ = new THREE.Quaternion().setFromAxisAngle(lookVec, camera.roll);
|
|
113
|
+
camera.quaternion.premultiply(rollQ);
|
|
114
|
+
|
|
115
|
+
// Prevent gimble lock from parallel look and up
|
|
116
|
+
if (1 - Math.abs(camera.up.clone().dot(lookVec)) < _math.EPS) {
|
|
117
|
+
// Offset toward DEFAULT_UP or DEFAULT_NORMAL
|
|
118
|
+
var offset = 1 - Math.abs(_constants.DEFAULT_UP_VEC3.clone().dot(camera.up)) < _math.EPS ? _constants.DEFAULT_NORMAL_VEC3.clone() : _constants.DEFAULT_UP_VEC3.clone();
|
|
119
|
+
offset.multiplyScalar(_math.EPS);
|
|
120
|
+
camera.up.add(offset).normalize();
|
|
121
|
+
console.warn("[View3D.camera] up and look (target - position) directions are parallel. up has been slightly offset to prevent unexpected camera controls behavior.");
|
|
122
|
+
}
|
|
123
|
+
camera.up.applyQuaternion(rollQ);
|
|
124
|
+
|
|
125
|
+
// Initialize Camera Controls
|
|
126
|
+
if (CameraControls != null) {
|
|
127
|
+
camera.controls = new CameraControls(
|
|
128
|
+
// polarAngle,
|
|
129
|
+
// azimuthAngle,
|
|
130
|
+
camera, gl.domElement);
|
|
131
|
+
camera.controls.enabled = true;
|
|
132
|
+
}
|
|
133
|
+
camera.updateProjectionMatrix();
|
|
134
|
+
}, [CameraControls, camera, _cameraExtrinsics, polarAngle, azimuthAngle, gl.domElement]);
|
|
135
|
+
useEffect(function updateCameraControlsProps() {
|
|
136
|
+
// Update Camera Controls
|
|
137
|
+
if (CameraControls != null) {
|
|
138
|
+
if (_controlsProps) {
|
|
139
|
+
Object.entries(_controlsProps).map(function (_ref2) {
|
|
140
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
141
|
+
param = _ref3[0],
|
|
142
|
+
value = _ref3[1];
|
|
143
|
+
camera.controls[param] = value;
|
|
144
|
+
return null;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
camera.controls.update();
|
|
148
|
+
}
|
|
149
|
+
}, [CameraControls, camera, _controlsProps]);
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
var SetControlsMemo = memo(SetControls);
|
|
153
|
+
SetControlsMemo.displayName = 'SetControls';
|
|
154
|
+
var _default = exports["default"] = SetControlsMemo;
|
|
155
|
+
/**
|
|
156
|
+
* UpdateControls
|
|
157
|
+
*
|
|
158
|
+
* Isolates the useFrame hook to avoid larger components, namely
|
|
159
|
+
* SetControls, from re-rendering up to 3 times--this is a bug
|
|
160
|
+
* from @react-three/fiber.
|
|
161
|
+
* Any @react-three/fiber hook call incurs additional renders.
|
|
162
|
+
*/
|
|
163
|
+
var UpdateControls = exports.UpdateControls = memo(function UpdateControls() {
|
|
164
|
+
var _useViewContext2 = (0, _hooks.useViewContext)(),
|
|
165
|
+
camera = _useViewContext2.camera;
|
|
166
|
+
(0, _hooks.useFrame)(function updateControls() {
|
|
167
|
+
if (camera.controls != null) {
|
|
168
|
+
camera.controls.update();
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return null;
|
|
172
|
+
});
|
|
173
|
+
UpdateControls.displayName = 'UpdateControls';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
interface GLProps {
|
|
4
|
+
autoClear?: boolean;
|
|
5
|
+
autoClearColor?: boolean;
|
|
6
|
+
autoClearDepth?: boolean;
|
|
7
|
+
autoClearStencil?: boolean;
|
|
8
|
+
clippingPlanes?: Array<THREE.Plane>;
|
|
9
|
+
domElement?: React.DOMElement<any, any>;
|
|
10
|
+
gammaFactor?: number;
|
|
11
|
+
outputEncoding?: number;
|
|
12
|
+
localClippingEnabled?: boolean;
|
|
13
|
+
maxMorphTargets?: number;
|
|
14
|
+
maxMorphNormals?: number;
|
|
15
|
+
physicallyCorrectLights?: boolean;
|
|
16
|
+
sortObjects?: boolean;
|
|
17
|
+
toneMapping?: number;
|
|
18
|
+
toneMappingExposure?: number;
|
|
19
|
+
toneMappingWhitePoint?: number;
|
|
20
|
+
antialias?: boolean;
|
|
21
|
+
preserveDrawingBuffer?: boolean;
|
|
22
|
+
}
|
|
23
|
+
declare function SetRenderer(glProps: GLProps): null;
|
|
24
|
+
declare const SetRendererMemo: React.MemoExoticComponent<typeof SetRenderer>;
|
|
25
|
+
export default SetRendererMemo;
|
|
@@ -0,0 +1,66 @@
|
|
|
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 _hooks = require("../utils/hooks");
|
|
10
|
+
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); }
|
|
11
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
12
|
+
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."); }
|
|
13
|
+
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; } }
|
|
14
|
+
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; }
|
|
15
|
+
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; } }
|
|
16
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } // SetRenderer.tsx
|
|
17
|
+
var useEffect = React.useEffect,
|
|
18
|
+
memo = React.memo;
|
|
19
|
+
function SetRenderer(glProps) {
|
|
20
|
+
var _useViewContext = (0, _hooks.useViewContext)(),
|
|
21
|
+
gl = _useViewContext.gl;
|
|
22
|
+
useEffect(function initRenderer() {
|
|
23
|
+
gl.autoClear = false;
|
|
24
|
+
gl.autoClearColor = false;
|
|
25
|
+
gl.autoClearDepth = false;
|
|
26
|
+
gl.autoClearStencil = false;
|
|
27
|
+
Object.entries(glProps).map(function (_ref) {
|
|
28
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
29
|
+
key = _ref2[0],
|
|
30
|
+
value = _ref2[1];
|
|
31
|
+
gl[key] = value;
|
|
32
|
+
return null;
|
|
33
|
+
});
|
|
34
|
+
}, [glProps, gl]);
|
|
35
|
+
|
|
36
|
+
// Render Loop Head
|
|
37
|
+
(0, _hooks.useFrame)(/* eslint-disable no-shadow */
|
|
38
|
+
function renderLoopHead(_ref3) {
|
|
39
|
+
var gl = _ref3.gl,
|
|
40
|
+
scene = _ref3.scene;
|
|
41
|
+
/* eslint-enable no-shadow */
|
|
42
|
+
/* eslint-disable no-param-reassign */
|
|
43
|
+
scene.overrideMaterial = null;
|
|
44
|
+
// @ts-ignore:TS2339 cancelTailRender does not exist
|
|
45
|
+
scene.cancelTailRender = false;
|
|
46
|
+
gl.clear();
|
|
47
|
+
gl.clippingPlanes = [];
|
|
48
|
+
/* eslint-enable no-param-reassign */
|
|
49
|
+
}, 1, true);
|
|
50
|
+
|
|
51
|
+
// Render Loop Tail
|
|
52
|
+
(0, _hooks.useFrame)(/* eslint-disable-next-line no-shadow */
|
|
53
|
+
function renderLoopTall(_ref4) {
|
|
54
|
+
var gl = _ref4.gl,
|
|
55
|
+
scene = _ref4.scene,
|
|
56
|
+
camera = _ref4.camera;
|
|
57
|
+
// @ts-ignore:TS2339 cancelTailRender does not exist
|
|
58
|
+
if (!scene.cancelTailRender) {
|
|
59
|
+
gl.render(scene, camera);
|
|
60
|
+
}
|
|
61
|
+
}, 1000, true);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
var SetRendererMemo = memo(SetRenderer);
|
|
65
|
+
SetRendererMemo.displayName = 'SetRenderer';
|
|
66
|
+
var _default = exports["default"] = SetRendererMemo;
|
|
@@ -0,0 +1,48 @@
|
|
|
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 _RectAreaLightUniformsLib = require("three/examples/jsm/lights/RectAreaLightUniformsLib");
|
|
11
|
+
var _utils = require("../utils");
|
|
12
|
+
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); }
|
|
13
|
+
// SetShadows.tsx
|
|
14
|
+
|
|
15
|
+
var useEffect = React.useEffect,
|
|
16
|
+
memo = React.memo;
|
|
17
|
+
function SetShadows(_ref) {
|
|
18
|
+
var shadowMapEnabled = _ref.shadowMapEnabled,
|
|
19
|
+
shadowType = _ref.shadowType;
|
|
20
|
+
var _useViewContext = (0, _utils.useViewContext)(),
|
|
21
|
+
gl = _useViewContext.gl;
|
|
22
|
+
useEffect(function updateShadowMap() {
|
|
23
|
+
gl.shadowMap.enabled = shadowMapEnabled;
|
|
24
|
+
if (!shadowMapEnabled) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
switch (shadowType) {
|
|
28
|
+
case "basic":
|
|
29
|
+
gl.shadowMap.type = THREE.BasicShadowMap;
|
|
30
|
+
break;
|
|
31
|
+
case "pcf":
|
|
32
|
+
gl.shadowMap.type = THREE.PCFShadowMap;
|
|
33
|
+
break;
|
|
34
|
+
case "pcfsoft":
|
|
35
|
+
gl.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
gl.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
39
|
+
}
|
|
40
|
+
}, [shadowMapEnabled, shadowType, gl]);
|
|
41
|
+
useEffect(function initRectAreaLightUniforms() {
|
|
42
|
+
_RectAreaLightUniformsLib.RectAreaLightUniformsLib.init();
|
|
43
|
+
}, []);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
var SetShadowsMemo = memo(SetShadows);
|
|
47
|
+
SetShadowsMemo.displayName = "SetShadows";
|
|
48
|
+
var _default = exports["default"] = SetShadowsMemo;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
interface View3DProps {
|
|
3
|
+
backgroundColor?: string;
|
|
4
|
+
backgroundTextureURL?: string;
|
|
5
|
+
backgroundEquirectangularTextureURL?: string;
|
|
6
|
+
backgroundEquirectangularRGBEURL?: string;
|
|
7
|
+
trackballControls?: boolean;
|
|
8
|
+
orbitControls?: boolean;
|
|
9
|
+
mapControls?: boolean;
|
|
10
|
+
shadowMapEnabled?: boolean;
|
|
11
|
+
shadowType?: string;
|
|
12
|
+
orthographic?: boolean;
|
|
13
|
+
camera?: any;
|
|
14
|
+
controls?: any;
|
|
15
|
+
gl?: any;
|
|
16
|
+
contexts?: React.Context<any> | Array<React.Context<any>>;
|
|
17
|
+
style?: Record<string, any>;
|
|
18
|
+
children: any;
|
|
19
|
+
}
|
|
20
|
+
declare const View3DMemo: React.NamedExoticComponent<View3DProps>;
|
|
21
|
+
export default View3DMemo;
|