@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,642 @@
|
|
|
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 _styles = require("../utils/styles");
|
|
11
|
+
var _constants = require("../utils/constants");
|
|
12
|
+
var _math = require("../utils/math");
|
|
13
|
+
var _events = require("../utils/events");
|
|
14
|
+
var _hooks = require("../utils/hooks");
|
|
15
|
+
var _util = require("../utils/util");
|
|
16
|
+
var _performance = require("../utils/performance");
|
|
17
|
+
var _excluded = ["geometry", "position", "scale", "rotation", "eulerOrder", "normal", "roll", "quaternion", "material", "materialType", "color", "hoverColor", "opacity", "transparent", "roughness", "metalness", "reflectivity", "texturePath", "textureURL", "map", "aoMap", "aoMapIntensity", "bumpMap", "bumpScale", "normalMap", "normalMapType", "normalMapScale", "displacementMap", "displacementMapScale", "displacementBias", "roughnessMap", "metalnessMap", "alphaMap", "envMap", "envMapIntensity", "view3DEnvMap", "wireframe", "side", "depthWrite", "depthTest", "anisotropy", "groupMember", "onClick", "onDoubleClick", "onWheel", "onPointerUp", "onPointerDown", "onPointerOver", "onPointerOut", "onPointerMove", "hoverable", "mousePropagation", "clickSensitivity", "ignoreMouseEvents", "receiveShadow", "animation", "state", "children"],
|
|
18
|
+
_excluded2 = ["envMap"]; // Mesh.tsx
|
|
19
|
+
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); }
|
|
20
|
+
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); }
|
|
21
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
22
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
23
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
24
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
25
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
26
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
27
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
28
|
+
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."); }
|
|
29
|
+
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; } }
|
|
30
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
31
|
+
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; }
|
|
32
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
33
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
34
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
35
|
+
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."); }
|
|
36
|
+
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; } }
|
|
37
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
38
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
39
|
+
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; }
|
|
40
|
+
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; }
|
|
41
|
+
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; }
|
|
42
|
+
var useState = React.useState,
|
|
43
|
+
useRef = React.useRef,
|
|
44
|
+
useEffect = React.useEffect,
|
|
45
|
+
useMemo = React.useMemo,
|
|
46
|
+
useCallback = React.useCallback,
|
|
47
|
+
forwardRef = React.forwardRef,
|
|
48
|
+
memo = React.memo;
|
|
49
|
+
/**
|
|
50
|
+
* Material Component
|
|
51
|
+
*
|
|
52
|
+
* Creates custom material based on materialType and material props
|
|
53
|
+
* if no material child exists.
|
|
54
|
+
*/
|
|
55
|
+
var MaterialComponent = memo(/* eslint-disable react/prop-types */
|
|
56
|
+
function MaterialComponent(_ref) {
|
|
57
|
+
var materialType = _ref.materialType,
|
|
58
|
+
material = _ref.material,
|
|
59
|
+
hasMaterialChild = _ref.hasMaterialChild,
|
|
60
|
+
materialProps = _ref.materialProps;
|
|
61
|
+
var MeshMaterial = useMemo(function updateMeshMaterial() {
|
|
62
|
+
// Validated materialType
|
|
63
|
+
if (!_constants.MATERIAL_TYPES[materialType]) {
|
|
64
|
+
return _constants.MATERIAL_TYPES.basic;
|
|
65
|
+
}
|
|
66
|
+
return _constants.MATERIAL_TYPES[materialType];
|
|
67
|
+
}, [materialType]);
|
|
68
|
+
if (hasMaterialChild || material) {
|
|
69
|
+
return null;
|
|
70
|
+
} else {
|
|
71
|
+
return /*#__PURE__*/React.createElement(MeshMaterial, {
|
|
72
|
+
attach: "material",
|
|
73
|
+
args: [materialProps]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/* eslint-enable react/prop-types */);
|
|
78
|
+
MaterialComponent.displayName = 'MaterialComponent';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Mesh
|
|
82
|
+
*
|
|
83
|
+
* This is a wrapper for @react-three/fiber/three.js's mesh.
|
|
84
|
+
* In three.js Mesh extends Object3D which is essentially the root of
|
|
85
|
+
* all 3D objects. With this wrapper, Standard View users need not
|
|
86
|
+
* get tangled with the intricacies of geometries and materials and
|
|
87
|
+
* may treat primitives as singular objects with properties. Standard View
|
|
88
|
+
* manages which property is assigned to geometry or materials.
|
|
89
|
+
* However, just as @react-three/fiber allows for manipulation of all the
|
|
90
|
+
* three.js properties, so does Standard View. A primitive or shape may be
|
|
91
|
+
* loaded with custom geometry or materials or even composed with custom
|
|
92
|
+
* child components.
|
|
93
|
+
*
|
|
94
|
+
* In Standard View, nearly all the primitives are composed within Mesh.
|
|
95
|
+
* The common properties of all Meshes are applied in this component.
|
|
96
|
+
*
|
|
97
|
+
* Mesh has two important child components: material and geometry.
|
|
98
|
+
* These components may also be passed as material and geometry props.
|
|
99
|
+
* The type of geometry and material depend on the primitive.
|
|
100
|
+
* The geometry must be passed in either as a property or composed
|
|
101
|
+
* within the component as a child.
|
|
102
|
+
*
|
|
103
|
+
* If no material is passed in, a default meshBasicMaterial is created.
|
|
104
|
+
* The properties that Mesh accepts include those defined in the
|
|
105
|
+
* MeshProps type (and also anything that three.js Mesh has a setter for)
|
|
106
|
+
*
|
|
107
|
+
* Note that most geometry are initialized with unit lengths and parameters,
|
|
108
|
+
* and it is actually the mesh that is scaled, rotated, translated to get
|
|
109
|
+
* the particular shape and orientation desired. Fortunately, all parameters
|
|
110
|
+
* passed into the Prefab primitives will be drilled down to Mesh and applied.
|
|
111
|
+
*
|
|
112
|
+
* Mesh can also support animations via the animation property. A function with
|
|
113
|
+
* one argument that may be destructured to include mesh, state, setState, and any
|
|
114
|
+
* Canvas props desired for the animation.
|
|
115
|
+
* All primitives and shapes may have animation. These animations are reactive,
|
|
116
|
+
* infinite requestAnimationFrame loops, so they incur many render calls,
|
|
117
|
+
* but also maintain react-three-renderer's native raycasting for the
|
|
118
|
+
* event property functions, onPointerHover, onPointerOut, onPointerClick,
|
|
119
|
+
* onPointerMove, onPointerDown, onPointerUp, onWheel,
|
|
120
|
+
* and other mouse-handling events.
|
|
121
|
+
*
|
|
122
|
+
* Mesh also exposes @react-three/fiber's the event property functions but with
|
|
123
|
+
* a constrained argument set, same as animation. All event property functions
|
|
124
|
+
* take one arguement that may be destructured to include mesh, state, setState,
|
|
125
|
+
* and any Canvas prop. The benefit of this design, just like
|
|
126
|
+
* animations, is that a reference to mesh is automatically provided and also
|
|
127
|
+
* access to all props are available. Moreover, @react-three/fiber's Canvas
|
|
128
|
+
* state properties are exposed. This allows event functions to reach right
|
|
129
|
+
* into the @react-three/fiber/three.js's scene, camera, gl. Hence all shapes
|
|
130
|
+
* that are Meshes may have these event property functions.
|
|
131
|
+
*
|
|
132
|
+
* @param {MeshProps} props
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
var Mesh = forwardRef(function Mesh(_ref2, ref) {
|
|
136
|
+
var geometry = _ref2.geometry,
|
|
137
|
+
_ref2$position = _ref2.position,
|
|
138
|
+
position = _ref2$position === void 0 ? [0, 0, 0] : _ref2$position,
|
|
139
|
+
_ref2$scale = _ref2.scale,
|
|
140
|
+
scale = _ref2$scale === void 0 ? [1, 1, 1] : _ref2$scale,
|
|
141
|
+
_ref2$rotation = _ref2.rotation,
|
|
142
|
+
rotation = _ref2$rotation === void 0 ? [0, 0, 0] : _ref2$rotation,
|
|
143
|
+
_ref2$eulerOrder = _ref2.eulerOrder,
|
|
144
|
+
eulerOrder = _ref2$eulerOrder === void 0 ? _constants.EULER_ORDERS.XYZ : _ref2$eulerOrder,
|
|
145
|
+
_ref2$normal = _ref2.normal,
|
|
146
|
+
normal = _ref2$normal === void 0 ? _constants.DEFAULT_NORMAL : _ref2$normal,
|
|
147
|
+
_ref2$roll = _ref2.roll,
|
|
148
|
+
roll = _ref2$roll === void 0 ? 0 : _ref2$roll,
|
|
149
|
+
quaternion = _ref2.quaternion,
|
|
150
|
+
material = _ref2.material,
|
|
151
|
+
_ref2$materialType = _ref2.materialType,
|
|
152
|
+
materialType = _ref2$materialType === void 0 ? 'basic' : _ref2$materialType,
|
|
153
|
+
_ref2$color = _ref2.color,
|
|
154
|
+
color = _ref2$color === void 0 ? _styles.DEFAULT_COLOR : _ref2$color,
|
|
155
|
+
hoverColor = _ref2.hoverColor,
|
|
156
|
+
_ref2$opacity = _ref2.opacity,
|
|
157
|
+
opacity = _ref2$opacity === void 0 ? 1 : _ref2$opacity,
|
|
158
|
+
transparent = _ref2.transparent,
|
|
159
|
+
_ref2$roughness = _ref2.roughness,
|
|
160
|
+
roughness = _ref2$roughness === void 0 ? 0.5 : _ref2$roughness,
|
|
161
|
+
_ref2$metalness = _ref2.metalness,
|
|
162
|
+
metalness = _ref2$metalness === void 0 ? 0.5 : _ref2$metalness,
|
|
163
|
+
_ref2$reflectivity = _ref2.reflectivity,
|
|
164
|
+
reflectivity = _ref2$reflectivity === void 0 ? 0.5 : _ref2$reflectivity,
|
|
165
|
+
texturePath = _ref2.texturePath,
|
|
166
|
+
textureURL = _ref2.textureURL,
|
|
167
|
+
map = _ref2.map,
|
|
168
|
+
aoMap = _ref2.aoMap,
|
|
169
|
+
aoMapIntensity = _ref2.aoMapIntensity,
|
|
170
|
+
bumpMap = _ref2.bumpMap,
|
|
171
|
+
bumpScale = _ref2.bumpScale,
|
|
172
|
+
normalMap = _ref2.normalMap,
|
|
173
|
+
normalMapType = _ref2.normalMapType,
|
|
174
|
+
normalMapScale = _ref2.normalMapScale,
|
|
175
|
+
displacementMap = _ref2.displacementMap,
|
|
176
|
+
displacementMapScale = _ref2.displacementMapScale,
|
|
177
|
+
displacementBias = _ref2.displacementBias,
|
|
178
|
+
roughnessMap = _ref2.roughnessMap,
|
|
179
|
+
metalnessMap = _ref2.metalnessMap,
|
|
180
|
+
alphaMap = _ref2.alphaMap,
|
|
181
|
+
envMap = _ref2.envMap,
|
|
182
|
+
envMapIntensity = _ref2.envMapIntensity,
|
|
183
|
+
_ref2$view3DEnvMap = _ref2.view3DEnvMap,
|
|
184
|
+
view3DEnvMap = _ref2$view3DEnvMap === void 0 ? false : _ref2$view3DEnvMap,
|
|
185
|
+
_ref2$wireframe = _ref2.wireframe,
|
|
186
|
+
wireframe = _ref2$wireframe === void 0 ? false : _ref2$wireframe,
|
|
187
|
+
_ref2$side = _ref2.side,
|
|
188
|
+
side = _ref2$side === void 0 ? 'front' : _ref2$side,
|
|
189
|
+
_ref2$depthWrite = _ref2.depthWrite,
|
|
190
|
+
depthWrite = _ref2$depthWrite === void 0 ? true : _ref2$depthWrite,
|
|
191
|
+
_ref2$depthTest = _ref2.depthTest,
|
|
192
|
+
depthTest = _ref2$depthTest === void 0 ? true : _ref2$depthTest,
|
|
193
|
+
_ref2$anisotropy = _ref2.anisotropy,
|
|
194
|
+
anisotropy = _ref2$anisotropy === void 0 ? 1 : _ref2$anisotropy,
|
|
195
|
+
_ref2$groupMember = _ref2.groupMember,
|
|
196
|
+
groupMember = _ref2$groupMember === void 0 ? false : _ref2$groupMember,
|
|
197
|
+
onClick = _ref2.onClick,
|
|
198
|
+
onDoubleClick = _ref2.onDoubleClick,
|
|
199
|
+
onWheel = _ref2.onWheel,
|
|
200
|
+
onPointerUp = _ref2.onPointerUp,
|
|
201
|
+
onPointerDown = _ref2.onPointerDown,
|
|
202
|
+
onPointerOver = _ref2.onPointerOver,
|
|
203
|
+
onPointerOut = _ref2.onPointerOut,
|
|
204
|
+
onPointerMove = _ref2.onPointerMove,
|
|
205
|
+
_ref2$hoverable = _ref2.hoverable,
|
|
206
|
+
hoverable = _ref2$hoverable === void 0 ? true : _ref2$hoverable,
|
|
207
|
+
_ref2$mousePropagatio = _ref2.mousePropagation,
|
|
208
|
+
mousePropagation = _ref2$mousePropagatio === void 0 ? false : _ref2$mousePropagatio,
|
|
209
|
+
_ref2$clickSensitivit = _ref2.clickSensitivity,
|
|
210
|
+
clickSensitivity = _ref2$clickSensitivit === void 0 ? 250 : _ref2$clickSensitivit,
|
|
211
|
+
_ref2$ignoreMouseEven = _ref2.ignoreMouseEvents,
|
|
212
|
+
ignoreMouseEvents = _ref2$ignoreMouseEven === void 0 ? false : _ref2$ignoreMouseEven,
|
|
213
|
+
receiveShadow = _ref2.receiveShadow,
|
|
214
|
+
animation = _ref2.animation,
|
|
215
|
+
state = _ref2.state,
|
|
216
|
+
children = _ref2.children,
|
|
217
|
+
otherProps = _objectWithoutProperties(_ref2, _excluded);
|
|
218
|
+
(0, _performance.performanceStart)('Mesh');
|
|
219
|
+
|
|
220
|
+
// Canvas Properties
|
|
221
|
+
// const canvasProps = useContext(ViewContext);
|
|
222
|
+
var _useViewContext = (0, _hooks.useViewContext)(),
|
|
223
|
+
viewContextEnvMap = _useViewContext.envMap,
|
|
224
|
+
canvasProps = _objectWithoutProperties(_useViewContext, _excluded2);
|
|
225
|
+
|
|
226
|
+
// Position
|
|
227
|
+
var _position = useMemo(function updatePosition() {
|
|
228
|
+
if (position) {
|
|
229
|
+
return (0, _util.filterArrayLength)((0, _util.objectToArray)(position), 3, [0, 0, 0]);
|
|
230
|
+
}
|
|
231
|
+
return undefined;
|
|
232
|
+
}, [position]);
|
|
233
|
+
|
|
234
|
+
// Rotations
|
|
235
|
+
// Intuitively, the component is aligned to the given normal in world space.
|
|
236
|
+
// Then, it is rotated by the rotation / quaternion in the component's local space.
|
|
237
|
+
// Then, it is rotated by the roll about the normal in the component's local space.
|
|
238
|
+
// Since all quaternions are applied in world space, the rotations must all occur in reverse order.
|
|
239
|
+
// So, first apply the roll about the DEFAULT_NORMAL, then rotate by the rotation / quaternion,
|
|
240
|
+
// then apply the normal. This is equivalent to doing local rotations in the intuitive order.
|
|
241
|
+
// Hence q = normalQ * rotationQ * rollQ
|
|
242
|
+
var _quaternion = useMemo(function updateQuaternion() {
|
|
243
|
+
// Normal
|
|
244
|
+
// @ts-ignore:T2345 // spread
|
|
245
|
+
var normalVec = _construct(THREE.Vector3, _toConsumableArray(normal)).normalize();
|
|
246
|
+
var normalQ = new THREE.Quaternion().setFromUnitVectors(_constants.DEFAULT_NORMAL_VEC3, normalVec);
|
|
247
|
+
|
|
248
|
+
// Rotation / Quaternion
|
|
249
|
+
var rotationQ = new THREE.Quaternion();
|
|
250
|
+
if (quaternion == null) {
|
|
251
|
+
// Convert Euler Rotation to Quaternion
|
|
252
|
+
// @ts-ignore:T2345
|
|
253
|
+
var _eulerOrder = eulerOrder.toUpperCase();
|
|
254
|
+
_eulerOrder = _constants.EULER_ORDERS[_eulerOrder] ? _eulerOrder : _constants.EULER_ORDERS.XYZ;
|
|
255
|
+
var euler = _construct(THREE.Euler, _toConsumableArray(rotation).concat([_eulerOrder]));
|
|
256
|
+
rotationQ = new THREE.Quaternion().setFromEuler(euler);
|
|
257
|
+
} else {
|
|
258
|
+
rotationQ = (0, _util.toQuaternion)(quaternion);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Roll
|
|
262
|
+
var rollQ = new THREE.Quaternion().setFromAxisAngle(_constants.DEFAULT_NORMAL_VEC3, roll);
|
|
263
|
+
|
|
264
|
+
// q = normalQ * rotationQ * rollQ
|
|
265
|
+
var q = new THREE.Quaternion(); // Identity
|
|
266
|
+
q.premultiply(rollQ);
|
|
267
|
+
q.premultiply(rotationQ);
|
|
268
|
+
q.premultiply(normalQ);
|
|
269
|
+
return q;
|
|
270
|
+
}, [quaternion, rotation, eulerOrder, normal, roll]);
|
|
271
|
+
|
|
272
|
+
// Scale
|
|
273
|
+
var _scale = useMemo(function updateScale() {
|
|
274
|
+
// Invalid Scale Warning
|
|
275
|
+
if (!Array.isArray(scale) || scale.length !== 3) {
|
|
276
|
+
/* eslint-disable-next-line no-console */
|
|
277
|
+
console.warn("[Mesh] scale must be a 3x1 array of numbers! scale: ".concat(scale));
|
|
278
|
+
return [1, 1, 1];
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Handle Zero Scale Input
|
|
282
|
+
if (!scale[0] || !scale[1] || !scale[2] || Math.abs(scale[0]) < _math.EPS || Math.abs(scale[1]) < _math.EPS || Math.abs(scale[2]) < _math.EPS) {
|
|
283
|
+
/* eslint-disable-next-line no-console */
|
|
284
|
+
console.warn("[Mesh] scale elements must be non-zero! scale: ".concat(scale));
|
|
285
|
+
return scale.map(function (value) {
|
|
286
|
+
return Math.max(value, _math.EPS);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
return scale;
|
|
290
|
+
}, [scale]);
|
|
291
|
+
|
|
292
|
+
// Color
|
|
293
|
+
|
|
294
|
+
// Prevent DEFAULT_COLOR blend into texture with given color
|
|
295
|
+
if (textureURL && color == _styles.DEFAULT_COLOR) {
|
|
296
|
+
color = undefined;
|
|
297
|
+
}
|
|
298
|
+
var _useState = useState(color),
|
|
299
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
300
|
+
_color = _useState2[0],
|
|
301
|
+
setColor = _useState2[1];
|
|
302
|
+
useEffect(function updateColor() {
|
|
303
|
+
setColor(color);
|
|
304
|
+
}, [color]);
|
|
305
|
+
|
|
306
|
+
// Map Props
|
|
307
|
+
var mapProps = useMemo(function initMapProps() {
|
|
308
|
+
return {
|
|
309
|
+
anisotropy: anisotropy
|
|
310
|
+
};
|
|
311
|
+
}, [anisotropy]);
|
|
312
|
+
|
|
313
|
+
// TextureURL
|
|
314
|
+
var _textureURL = useMemo(function updateTextureURL() {
|
|
315
|
+
return texturePath ? texturePath + textureURL : textureURL;
|
|
316
|
+
}, [texturePath, textureURL]);
|
|
317
|
+
|
|
318
|
+
// Load Texture
|
|
319
|
+
var _map = useMemo(function updateMap() {
|
|
320
|
+
if (_textureURL) {
|
|
321
|
+
// Create Texture
|
|
322
|
+
var tex = new THREE.TextureLoader().load(_textureURL);
|
|
323
|
+
// Set Map Props
|
|
324
|
+
Object.entries(mapProps).map(function (_ref3) {
|
|
325
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
326
|
+
prop = _ref4[0],
|
|
327
|
+
value = _ref4[1];
|
|
328
|
+
tex[prop] = value;
|
|
329
|
+
return null;
|
|
330
|
+
});
|
|
331
|
+
tex.colorSpace = THREE.SRGBColorSpace;
|
|
332
|
+
return tex;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Set color space to sRGB if not set
|
|
336
|
+
if ((map === null || map === void 0 ? void 0 : map.colorSpace) == THREE.NoColorSpace) {
|
|
337
|
+
map.colorSpace = THREE.SRGBColorSpace;
|
|
338
|
+
}
|
|
339
|
+
return map;
|
|
340
|
+
}, [map, mapProps, _textureURL]);
|
|
341
|
+
|
|
342
|
+
// Environment Map
|
|
343
|
+
var _envMap = useMemo(function updateEnvMap() {
|
|
344
|
+
var compatibleMaterials = ['basic', 'physical', 'standard'];
|
|
345
|
+
return view3DEnvMap && compatibleMaterials.includes(materialType) ? viewContextEnvMap : envMap;
|
|
346
|
+
}, [viewContextEnvMap, view3DEnvMap, envMap, materialType]);
|
|
347
|
+
|
|
348
|
+
// Other Maps
|
|
349
|
+
var otherMaps = useMemo(function initOtherMap() {
|
|
350
|
+
var otherMapProps = {
|
|
351
|
+
aoMap: aoMap,
|
|
352
|
+
aoMapIntensity: aoMapIntensity,
|
|
353
|
+
bumpMap: bumpMap,
|
|
354
|
+
bumpScale: bumpScale,
|
|
355
|
+
normalMap: normalMap,
|
|
356
|
+
normalMapType: normalMapType,
|
|
357
|
+
normalMapScale: normalMapScale,
|
|
358
|
+
displacementMap: displacementMap,
|
|
359
|
+
displacementMapScale: displacementMapScale,
|
|
360
|
+
displacementBias: displacementBias,
|
|
361
|
+
roughnessMap: roughnessMap,
|
|
362
|
+
metalnessMap: metalnessMap,
|
|
363
|
+
alphaMap: alphaMap,
|
|
364
|
+
envMap: _envMap,
|
|
365
|
+
envMapIntensity: envMapIntensity
|
|
366
|
+
};
|
|
367
|
+
return otherMapProps;
|
|
368
|
+
}, [aoMap, aoMapIntensity, bumpMap, bumpScale, normalMap, normalMapType, normalMapScale, displacementMap, displacementMapScale, displacementBias, roughnessMap, metalnessMap, alphaMap, _envMap, envMapIntensity]);
|
|
369
|
+
|
|
370
|
+
// Side
|
|
371
|
+
var _side = useMemo(function updateSide() {
|
|
372
|
+
if (typeof side === 'string') {
|
|
373
|
+
return _constants.SIDE_TYPES[side];
|
|
374
|
+
} else {
|
|
375
|
+
// THREE.Side
|
|
376
|
+
return side;
|
|
377
|
+
}
|
|
378
|
+
}, [side]);
|
|
379
|
+
|
|
380
|
+
// Material Props
|
|
381
|
+
var materialProps = useMemo(function updateMaterialProps() {
|
|
382
|
+
// Metalness
|
|
383
|
+
var _metalness = materialType === 'standard' || materialType === 'physical' ? metalness : undefined;
|
|
384
|
+
// Roughness
|
|
385
|
+
var _roughness = materialType === 'standard' || materialType === 'physical' ? roughness : undefined;
|
|
386
|
+
// Reflectivity
|
|
387
|
+
var reflectiveMaterials = ['basic', 'lambert', 'phong', 'physical'];
|
|
388
|
+
var _reflectivity = reflectiveMaterials.includes(materialType) ? reflectivity : undefined;
|
|
389
|
+
// Collect All Material Props
|
|
390
|
+
var allMaterialProps = _objectSpread(_objectSpread({
|
|
391
|
+
color: _color,
|
|
392
|
+
map: _map
|
|
393
|
+
}, otherMaps), {}, {
|
|
394
|
+
wireframe: wireframe,
|
|
395
|
+
opacity: opacity,
|
|
396
|
+
transparent: transparent != null ? transparent : opacity < 1 - _math.EPS,
|
|
397
|
+
roughness: _roughness,
|
|
398
|
+
metalness: _metalness,
|
|
399
|
+
reflectivity: _reflectivity,
|
|
400
|
+
side: _side,
|
|
401
|
+
depthWrite: depthWrite,
|
|
402
|
+
depthTest: depthTest
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
// Clean undefined and null
|
|
406
|
+
var cleanedMaterialProps = {};
|
|
407
|
+
Object.entries(allMaterialProps).map(function (_ref5) {
|
|
408
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
409
|
+
key = _ref6[0],
|
|
410
|
+
value = _ref6[1];
|
|
411
|
+
if (value != null) {
|
|
412
|
+
cleanedMaterialProps[key] = value;
|
|
413
|
+
}
|
|
414
|
+
return null;
|
|
415
|
+
});
|
|
416
|
+
return cleanedMaterialProps;
|
|
417
|
+
}, [materialType, metalness, roughness, reflectivity, _color, _map, otherMaps, wireframe, opacity, transparent, _side, depthWrite, depthTest]);
|
|
418
|
+
|
|
419
|
+
// Children
|
|
420
|
+
var _children = useMemo(function updateChildren() {
|
|
421
|
+
return children || null;
|
|
422
|
+
}, [children]);
|
|
423
|
+
|
|
424
|
+
// Check Children for Material
|
|
425
|
+
// Only checks on load. If material children are add later,
|
|
426
|
+
// will not rerender.
|
|
427
|
+
var hasMaterialChild = useMemo(function checkMaterialChild() {
|
|
428
|
+
// No Children
|
|
429
|
+
if (_children == null) {
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Check Children
|
|
434
|
+
if (_children.length == null) {
|
|
435
|
+
// Check The Only Child for Material
|
|
436
|
+
// Separate check necessary because when there is only one child,
|
|
437
|
+
// react stores children as a variable instead of an array.
|
|
438
|
+
if (Object.values(_constants.MATERIAL_TYPES).includes(_children.type)) {
|
|
439
|
+
// Update props.color with child material's color
|
|
440
|
+
if (_children.props.color) {
|
|
441
|
+
setColor(_children.props.color);
|
|
442
|
+
}
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
} else {
|
|
446
|
+
// Check Each Child for Material
|
|
447
|
+
/* eslint-disable no-restricted-syntax */
|
|
448
|
+
// loop
|
|
449
|
+
var _iterator = _createForOfIteratorHelper(_children),
|
|
450
|
+
_step;
|
|
451
|
+
try {
|
|
452
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
453
|
+
var child = _step.value;
|
|
454
|
+
if (child != null && Object.values(_constants.MATERIAL_TYPES).includes(child.type)) {
|
|
455
|
+
// Update props.color with child material's color
|
|
456
|
+
if (child.props.color) {
|
|
457
|
+
setColor(child.props.color);
|
|
458
|
+
}
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
/* eslint-enable no-restricted-syntax */
|
|
463
|
+
} catch (err) {
|
|
464
|
+
_iterator.e(err);
|
|
465
|
+
} finally {
|
|
466
|
+
_iterator.f();
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// No Material Children
|
|
471
|
+
return false;
|
|
472
|
+
}, [_children]);
|
|
473
|
+
|
|
474
|
+
// Material
|
|
475
|
+
var _material = useMemo(function updateMaterial() {
|
|
476
|
+
return material || null;
|
|
477
|
+
}, [material]);
|
|
478
|
+
|
|
479
|
+
// Ref
|
|
480
|
+
var meshRef = useRef(null); // Hooks must be deterministic
|
|
481
|
+
var mesh = ref || meshRef;
|
|
482
|
+
|
|
483
|
+
// State
|
|
484
|
+
var _useState3 = useState(state != null ? _objectSpread({
|
|
485
|
+
lastClickTime: 0
|
|
486
|
+
}, state) : {
|
|
487
|
+
lastClickTime: 0
|
|
488
|
+
}),
|
|
489
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
490
|
+
_state = _useState4[0],
|
|
491
|
+
setState = _useState4[1];
|
|
492
|
+
|
|
493
|
+
// ignoreMouseEvents
|
|
494
|
+
var _ignoreMouseEvents = useMemo(function updateIgnoreMouseEvents() {
|
|
495
|
+
return ignoreMouseEvents || groupMember && !hoverColor && !onClick && !onDoubleClick && !onPointerOver && !onPointerOut && !onPointerDown && !onPointerUp && !onPointerMove && !onWheel;
|
|
496
|
+
}, [ignoreMouseEvents, groupMember, hoverColor, onClick, onDoubleClick, onPointerOver, onPointerOut, onPointerDown, onPointerUp, onPointerMove, onWheel]);
|
|
497
|
+
|
|
498
|
+
// ---------------------- //
|
|
499
|
+
// ----- Events ----- //
|
|
500
|
+
// ---------------------- //
|
|
501
|
+
// Event Props
|
|
502
|
+
var eventProps = useMemo(function updateEventProps() {
|
|
503
|
+
return _objectSpread({
|
|
504
|
+
mesh: mesh,
|
|
505
|
+
state: _state,
|
|
506
|
+
setState: setState
|
|
507
|
+
}, canvasProps);
|
|
508
|
+
}, [mesh, _state, setState, canvasProps]);
|
|
509
|
+
|
|
510
|
+
// Click Props
|
|
511
|
+
var clickProps = useMemo(function updateClickProps() {
|
|
512
|
+
return {
|
|
513
|
+
mousePropagation: mousePropagation,
|
|
514
|
+
clickSensitivity: clickSensitivity,
|
|
515
|
+
mesh: mesh,
|
|
516
|
+
eventProps: eventProps,
|
|
517
|
+
onClick: onClick,
|
|
518
|
+
onDoubleClick: onDoubleClick
|
|
519
|
+
};
|
|
520
|
+
}, [mousePropagation, clickSensitivity, mesh, eventProps, onClick, onDoubleClick]);
|
|
521
|
+
|
|
522
|
+
// onPointerOver
|
|
523
|
+
var _onPointerOver = useCallback(function onHoverOver(e) {
|
|
524
|
+
// Mouse Propagation
|
|
525
|
+
(0, _events.checkPropagation)(e, mousePropagation);
|
|
526
|
+
if (hoverable) {
|
|
527
|
+
if (hoverColor != null) {
|
|
528
|
+
setColor(hoverColor);
|
|
529
|
+
}
|
|
530
|
+
if (onPointerOver) {
|
|
531
|
+
onPointerOver(_objectSpread(_objectSpread({}, e), eventProps));
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}, [onPointerOver, hoverable, hoverColor, eventProps, mousePropagation]);
|
|
535
|
+
|
|
536
|
+
// onPointerOut
|
|
537
|
+
var _onPointerOut = useCallback(function onHoverOut(e) {
|
|
538
|
+
// Mouse Propagation
|
|
539
|
+
(0, _events.checkPropagation)(e, mousePropagation);
|
|
540
|
+
if (hoverable) {
|
|
541
|
+
if (hoverColor != null) {
|
|
542
|
+
setColor(color);
|
|
543
|
+
}
|
|
544
|
+
if (onPointerOut) {
|
|
545
|
+
onPointerOut(_objectSpread(_objectSpread({}, e), eventProps));
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}, [onPointerOut, hoverable, hoverColor, color, eventProps, mousePropagation]);
|
|
549
|
+
|
|
550
|
+
// onPointerDown
|
|
551
|
+
var _onPointerDown = useCallback(function onMouseDown(e) {
|
|
552
|
+
// Mouse Propagation
|
|
553
|
+
(0, _events.checkPropagation)(e, mousePropagation);
|
|
554
|
+
if (onPointerDown) {
|
|
555
|
+
onPointerDown(_objectSpread(_objectSpread({}, e), eventProps));
|
|
556
|
+
}
|
|
557
|
+
}, [onPointerDown, mousePropagation, eventProps]);
|
|
558
|
+
|
|
559
|
+
// onPointerUp
|
|
560
|
+
var _onPointerUp = useCallback(function onMouseUp(e) {
|
|
561
|
+
// Mouse Propagation
|
|
562
|
+
(0, _events.checkPropagation)(e, mousePropagation);
|
|
563
|
+
if (onPointerUp) {
|
|
564
|
+
onPointerUp(_objectSpread(_objectSpread({}, e), eventProps));
|
|
565
|
+
}
|
|
566
|
+
}, [onPointerUp, mousePropagation, eventProps]);
|
|
567
|
+
|
|
568
|
+
// onPointerMove
|
|
569
|
+
var _onPointerMove = useCallback(function onMouseMove(e) {
|
|
570
|
+
// Mouse Propagation
|
|
571
|
+
(0, _events.checkPropagation)(e, mousePropagation);
|
|
572
|
+
if (onPointerMove) {
|
|
573
|
+
onPointerMove(_objectSpread(_objectSpread({}, e), eventProps));
|
|
574
|
+
}
|
|
575
|
+
}, [onPointerMove, mousePropagation, eventProps]);
|
|
576
|
+
|
|
577
|
+
// onWheel
|
|
578
|
+
var _onWheel = useCallback(function onScroll(e) {
|
|
579
|
+
// Mouse Propagation
|
|
580
|
+
(0, _events.checkPropagation)(e, mousePropagation);
|
|
581
|
+
if (onWheel) {
|
|
582
|
+
onWheel(_objectSpread(_objectSpread({}, e), eventProps));
|
|
583
|
+
}
|
|
584
|
+
}, [onWheel, mousePropagation, eventProps]);
|
|
585
|
+
|
|
586
|
+
// onClick + onDoubleClick
|
|
587
|
+
var _onClick = useCallback((0, _events.handleClick)(clickProps), [clickProps]);
|
|
588
|
+
|
|
589
|
+
// ------------------------- //
|
|
590
|
+
// ----- Animation ----- //
|
|
591
|
+
// ------------------------- //
|
|
592
|
+
// Animatiom Function
|
|
593
|
+
var _animation = useCallback(function onAnimation() {
|
|
594
|
+
// @ts-ignore:TS2339 // current not in RefObject<any> | null
|
|
595
|
+
if (animation && mesh.current) {
|
|
596
|
+
animation(eventProps);
|
|
597
|
+
}
|
|
598
|
+
}, [mesh, animation, eventProps]);
|
|
599
|
+
|
|
600
|
+
// ----------------------- //
|
|
601
|
+
// ----- Shadows ----- //
|
|
602
|
+
// ----------------------- //
|
|
603
|
+
var _receiveShadow = useMemo(function updateReceiveShadow() {
|
|
604
|
+
// @ts-ignore:TS2339 // current not in RefObject<any> | null
|
|
605
|
+
if (mesh && mesh.current) {
|
|
606
|
+
// @ts-ignore:TS2339 // current not in RefObject<any> | null
|
|
607
|
+
mesh.current.material.needsUpdate = true;
|
|
608
|
+
}
|
|
609
|
+
return receiveShadow;
|
|
610
|
+
}, [receiveShadow, mesh]);
|
|
611
|
+
(0, _performance.performanceEnd)('Mesh');
|
|
612
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, (0, _performance.performanceStart)('Around mesh'), /*#__PURE__*/React.createElement("mesh", _extends({
|
|
613
|
+
ref: mesh
|
|
614
|
+
// Event Functions
|
|
615
|
+
,
|
|
616
|
+
onPointerOver: _ignoreMouseEvents ? undefined : _onPointerOver,
|
|
617
|
+
onPointerOut: _ignoreMouseEvents ? undefined : _onPointerOut,
|
|
618
|
+
onPointerDown: _ignoreMouseEvents ? undefined : _onPointerDown,
|
|
619
|
+
onPointerUp: _ignoreMouseEvents ? undefined : _onPointerUp,
|
|
620
|
+
onPointerMove: _ignoreMouseEvents ? undefined : _onPointerMove,
|
|
621
|
+
onWheel: _ignoreMouseEvents ? undefined : _onWheel,
|
|
622
|
+
onClick: _ignoreMouseEvents ? undefined : _onClick
|
|
623
|
+
// Geometry
|
|
624
|
+
,
|
|
625
|
+
geometry: geometry || undefined,
|
|
626
|
+
position: _position,
|
|
627
|
+
scale: _scale,
|
|
628
|
+
quaternion: _quaternion,
|
|
629
|
+
material: _material,
|
|
630
|
+
receiveShadow: _receiveShadow
|
|
631
|
+
}, otherProps), /*#__PURE__*/React.createElement(MaterialComponent, {
|
|
632
|
+
materialType: materialType,
|
|
633
|
+
hasMaterialChild: hasMaterialChild,
|
|
634
|
+
material: _material,
|
|
635
|
+
materialProps: materialProps
|
|
636
|
+
}), animation && /*#__PURE__*/React.createElement(_events.AnimationComponent, {
|
|
637
|
+
animation: _animation
|
|
638
|
+
}), _children), (0, _performance.performanceEnd)('Around mesh'));
|
|
639
|
+
});
|
|
640
|
+
var MeshMemo = memo(Mesh);
|
|
641
|
+
MeshMemo.displayName = 'Mesh';
|
|
642
|
+
var _default = exports["default"] = MeshMemo;
|