@anov/3d 0.0.1-alpha.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/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # anov-3d
2
+
3
+ > anov 3d 核心包
4
+
5
+ ### usage
6
+
7
+ install
8
+
9
+ ```bash
10
+ pnpm add @anov/3d
11
+ ```
12
+
13
+ init a base scene 「wip」
14
+
15
+ ```ts
16
+ import { Anov3DMesh, Anove3DScene } from '@anov/3d'
17
+ import { BoxGeometry, MeshBasicMaterial } from 'three'
18
+
19
+ const scene = new Anove3DScene({
20
+ orbitControls: true,
21
+ })
22
+
23
+ const geometry = new BoxGeometry(2, 2, 2)
24
+ const material = new MeshBasicMaterial({ color: 0x00FF00 })
25
+ const box = new Anov3DMesh(geometry, material)
26
+
27
+ box.addNatureEventListener('pointerdown', (object3D) => {
28
+ (object3D.material as any).color.set(0xFF0000)
29
+ })
30
+
31
+ scene.add(box)
32
+
33
+ scene.render(document.querySelector('#app')!)
34
+ scene.startFrameAnimate()
35
+ ```
36
+
37
+ base object3d motion 「wip」
38
+
39
+ ```ts
40
+ import { Anov3DMesh, Anove3DScene, utils } from '@anov/3d'
41
+ import { AxesHelper, BoxGeometry, GridHelper, MeshBasicMaterial } from 'three'
42
+
43
+ const scene = new Anove3DScene({
44
+ orbitControls: true,
45
+ })
46
+
47
+ const geometry = new BoxGeometry(2, 2, 2)
48
+ const material = new MeshBasicMaterial({ color: 0x00FF00 })
49
+ const box = new Anov3DMesh(geometry, material)
50
+
51
+ const geometry2 = new BoxGeometry(2, 2, 2)
52
+ const materia2 = new MeshBasicMaterial({ color: '#ccc' })
53
+ const box2 = new Anov3DMesh(geometry2, materia2)
54
+
55
+ box.position.set(0, 0, 0)
56
+ box2.position.set(10, 30, -30)
57
+
58
+ scene.add(box)
59
+ scene.add(box2)
60
+
61
+ utils.moveWithRound(box2, 0.2, 100000)
62
+
63
+ scene.render(document.querySelector('#app')!)
64
+ scene.startFrameAnimate()
65
+ ```
@@ -0,0 +1,5 @@
1
+ export declare enum ModelType {
2
+ GLTF = "gltf",
3
+ GLB = "glb",
4
+ FBX = "fbx"
5
+ }
@@ -0,0 +1,6 @@
1
+ export var ModelType;
2
+ (function (ModelType) {
3
+ ModelType["GLTF"] = "gltf";
4
+ ModelType["GLB"] = "glb";
5
+ ModelType["FBX"] = "fbx";
6
+ })(ModelType || (ModelType = {}));
@@ -0,0 +1,16 @@
1
+ import type { Object3D, Vector3 } from 'three';
2
+ import { PerspectiveCamera } from 'three';
3
+ declare class Anov3DPerspectiveCamera extends PerspectiveCamera {
4
+ constructor(fov: number, aspect: number, near: number, far: number);
5
+ /**
6
+ * 向目标物体推进
7
+ * @param targetObject3D
8
+ * @param distance
9
+ * @param duration
10
+ * @param animationMethod
11
+ */
12
+ promote(targetObject3D: Object3D, distance: number, duration?: number, animationMethod?: string): void;
13
+ demote: (targetObject3D: Object3D<import("three").Event>, distance: number, animationMethod: string, duration: number) => void;
14
+ surround: (targetObject3D: Object3D<import("three").Event>, radius: number, toward: Vector3) => void;
15
+ }
16
+ export { Anov3DPerspectiveCamera };
@@ -0,0 +1,61 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
6
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
7
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
9
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
10
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
11
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
12
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
14
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
15
+ import { PerspectiveCamera } from 'three';
16
+ import { Direction, moveTo } from "../utils/move";
17
+
18
+ /**
19
+ * 向目标物体后退
20
+ * @param targetObject3D
21
+ * @param distance
22
+ * @param animationMethod
23
+ * @param duration
24
+ */
25
+ var demote = function demote(targetObject3D, distance, animationMethod, duration) {};
26
+
27
+ /**
28
+ * 相机围绕目标物体旋转
29
+ * @param targetObject3D
30
+ * @param radius
31
+ * @param toward
32
+ */
33
+ var surround = function surround(targetObject3D, radius, toward) {};
34
+ var Anov3DPerspectiveCamera = /*#__PURE__*/function (_PerspectiveCamera) {
35
+ _inherits(Anov3DPerspectiveCamera, _PerspectiveCamera);
36
+ var _super = _createSuper(Anov3DPerspectiveCamera);
37
+ function Anov3DPerspectiveCamera(fov, aspect, near, far) {
38
+ var _this;
39
+ _classCallCheck(this, Anov3DPerspectiveCamera);
40
+ _this = _super.call(this, fov, aspect, near, far);
41
+ _defineProperty(_assertThisInitialized(_this), "demote", demote);
42
+ _defineProperty(_assertThisInitialized(_this), "surround", surround);
43
+ return _this;
44
+ }
45
+
46
+ /**
47
+ * 向目标物体推进
48
+ * @param targetObject3D
49
+ * @param distance
50
+ * @param duration
51
+ * @param animationMethod
52
+ */
53
+ _createClass(Anov3DPerspectiveCamera, [{
54
+ key: "promote",
55
+ value: function promote(targetObject3D, distance, duration, animationMethod) {
56
+ moveTo(this, targetObject3D, distance, Direction.plus, duration, animationMethod);
57
+ }
58
+ }]);
59
+ return Anov3DPerspectiveCamera;
60
+ }(PerspectiveCamera);
61
+ export { Anov3DPerspectiveCamera };
@@ -0,0 +1,8 @@
1
+ import type { Scene } from 'three';
2
+ declare class GlobalObjectManage {
3
+ scene: Scene | null;
4
+ constructor();
5
+ addScene(object3d: Scene): void;
6
+ }
7
+ declare const _default: GlobalObjectManage;
8
+ export default _default;
@@ -0,0 +1,21 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ var GlobalObjectManage = /*#__PURE__*/function () {
9
+ function GlobalObjectManage() {
10
+ _classCallCheck(this, GlobalObjectManage);
11
+ _defineProperty(this, "scene", null);
12
+ }
13
+ _createClass(GlobalObjectManage, [{
14
+ key: "addScene",
15
+ value: function addScene(object3d) {
16
+ this.scene = object3d;
17
+ }
18
+ }]);
19
+ return GlobalObjectManage;
20
+ }();
21
+ export default new GlobalObjectManage();
@@ -0,0 +1,17 @@
1
+ /// <reference types="node" />
2
+ interface CallbackType {
3
+ cb: () => void;
4
+ duration: number;
5
+ }
6
+ declare class GlobalControl {
7
+ callback: CallbackType;
8
+ task: Map<() => void, NodeJS.Timer>;
9
+ constructor();
10
+ update(): void;
11
+ add(cb: () => void, duration?: number): void;
12
+ remove(cb: () => void): void;
13
+ start(): void;
14
+ private timerControl;
15
+ }
16
+ declare const _default: GlobalControl;
17
+ export default _default;
@@ -0,0 +1,63 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ 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."); }
4
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
10
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
13
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
14
+ var GlobalControl = /*#__PURE__*/function () {
15
+ function GlobalControl() {
16
+ _classCallCheck(this, GlobalControl);
17
+ _defineProperty(this, "callback", {});
18
+ _defineProperty(this, "task", new Map());
19
+ }
20
+ _createClass(GlobalControl, [{
21
+ key: "update",
22
+ value: function update() {
23
+ if (this.task.size > 0) {
24
+ // @ts-ignore
25
+ _toConsumableArray(this.task.keys()).forEach(function (cb) {
26
+ cb();
27
+ });
28
+ }
29
+ }
30
+ }, {
31
+ key: "add",
32
+ value: function add(cb, duration) {
33
+ this.callback.cb = cb;
34
+ this.callback.duration = duration || 1000;
35
+ }
36
+ }, {
37
+ key: "remove",
38
+ value: function remove(cb) {
39
+ if (this.task.get(cb)) {
40
+ clearTimeout(this.task.get(cb));
41
+ this.task.delete(cb);
42
+ }
43
+ }
44
+ }, {
45
+ key: "start",
46
+ value: function start() {
47
+ if (!this.task.get(this.callback.cb)) {
48
+ var timer = this.timerControl();
49
+ this.task.set(this.callback.cb, timer);
50
+ }
51
+ }
52
+ }, {
53
+ key: "timerControl",
54
+ value: function timerControl() {
55
+ var _this = this;
56
+ return setTimeout(function () {
57
+ _this.task.delete(_this.callback.cb);
58
+ }, this.callback.duration);
59
+ }
60
+ }]);
61
+ return GlobalControl;
62
+ }();
63
+ export default new GlobalControl();
@@ -0,0 +1,5 @@
1
+ import { Group } from 'three';
2
+ declare class Anov3DGroup extends Group {
3
+ constructor();
4
+ }
5
+ export default Anov3DGroup;
@@ -0,0 +1,24 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
3
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
5
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
6
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
8
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
9
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
11
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
12
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
14
+ import { Group } from 'three';
15
+ var Anov3DGroup = /*#__PURE__*/function (_Group) {
16
+ _inherits(Anov3DGroup, _Group);
17
+ var _super = _createSuper(Anov3DGroup);
18
+ function Anov3DGroup() {
19
+ _classCallCheck(this, Anov3DGroup);
20
+ return _super.call(this);
21
+ }
22
+ return _createClass(Anov3DGroup);
23
+ }(Group);
24
+ export default Anov3DGroup;
@@ -0,0 +1,44 @@
1
+ import type { Intersection, Raycaster } from 'three';
2
+ import { Mesh } from 'three';
3
+ import type { CubeEventType, EventHandleFn } from '../type';
4
+ declare class Anov3DMesh extends Mesh {
5
+ private natureEventMap;
6
+ private isMove;
7
+ constructor(geometry?: ConstructorParameters<typeof Mesh>[0], material?: ConstructorParameters<typeof Mesh>[1]);
8
+ /**
9
+ * addNatureEventListener
10
+ * @param type
11
+ * @param handlefn
12
+ */
13
+ addNatureEventListener<T extends CubeEventType>(type: T, handlefn: EventHandleFn<T>): void;
14
+ /**
15
+ * removeNatureEventListener
16
+ * @param type
17
+ * @param handlefn
18
+ */
19
+ removeNatureEventListener<T extends CubeEventType>(type: T, handlefn: EventHandleFn<T>): void;
20
+ /**
21
+ * removeAllNatureEventListener
22
+ */
23
+ removeAllNatureEventListener(): void;
24
+ /**
25
+ * handle intersect event
26
+ * @param intersects
27
+ * @param eventType
28
+ */
29
+ private eventHandle;
30
+ private debounceEventHandle;
31
+ /**
32
+ * handle pointerleave event
33
+ * @param intersects
34
+ * @param natureEvent
35
+ */
36
+ private handlePointerleave;
37
+ /**
38
+ * handle mesh raycaster
39
+ * @param raycaster
40
+ * @param intersects
41
+ */
42
+ raycast(raycaster: Raycaster, intersects: Intersection[]): void;
43
+ }
44
+ export default Anov3DMesh;
@@ -0,0 +1,142 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
6
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
7
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
8
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
9
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
11
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
12
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
14
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
16
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
+ import { Mesh } from 'three';
18
+ import { debounce } from 'lodash';
19
+ import { emitter } from "../utils";
20
+ var Anov3DMesh = /*#__PURE__*/function (_Mesh) {
21
+ _inherits(Anov3DMesh, _Mesh);
22
+ var _super = _createSuper(Anov3DMesh);
23
+ function Anov3DMesh(geometry, material) {
24
+ var _this;
25
+ _classCallCheck(this, Anov3DMesh);
26
+ _this = _super.call(this, geometry, material);
27
+ _defineProperty(_assertThisInitialized(_this), "natureEventMap", new Map());
28
+ _defineProperty(_assertThisInitialized(_this), "isMove", false);
29
+ _defineProperty(_assertThisInitialized(_this), "debounceEventHandle", debounce(_this.eventHandle, 50));
30
+ return _this;
31
+ }
32
+
33
+ /**
34
+ * addNatureEventListener
35
+ * @param type
36
+ * @param handlefn
37
+ */
38
+ _createClass(Anov3DMesh, [{
39
+ key: "addNatureEventListener",
40
+ value: function addNatureEventListener(type, handlefn) {
41
+ if (!this.natureEventMap.has(type)) this.natureEventMap.set(type, []);
42
+ this.natureEventMap.get(type).push(handlefn);
43
+ }
44
+
45
+ /**
46
+ * removeNatureEventListener
47
+ * @param type
48
+ * @param handlefn
49
+ */
50
+ }, {
51
+ key: "removeNatureEventListener",
52
+ value: function removeNatureEventListener(type, handlefn) {
53
+ if (!this.natureEventMap.has(type)) return;
54
+ var handlefns = this.natureEventMap.get(type);
55
+ var index = handlefns.findIndex(function (fn) {
56
+ return fn === handlefn;
57
+ });
58
+ if (index > -1) handlefns.splice(index, 1);
59
+ }
60
+
61
+ /**
62
+ * removeAllNatureEventListener
63
+ */
64
+ }, {
65
+ key: "removeAllNatureEventListener",
66
+ value: function removeAllNatureEventListener() {
67
+ this.natureEventMap.clear();
68
+ }
69
+
70
+ /**
71
+ * handle intersect event
72
+ * @param intersects
73
+ * @param eventType
74
+ */
75
+ }, {
76
+ key: "eventHandle",
77
+ value: function eventHandle(intersects, natureEvent) {
78
+ var intersect = intersects[0];
79
+ var object = intersect.object;
80
+ if (object === this) {
81
+ // get nature event
82
+ natureEvent.forEach(function (handlefn) {
83
+ handlefn(object);
84
+ });
85
+ }
86
+ }
87
+ }, {
88
+ key: "handlePointerleave",
89
+ value:
90
+ /**
91
+ * handle pointerleave event
92
+ * @param intersects
93
+ * @param natureEvent
94
+ */
95
+ function handlePointerleave(intersects, natureEvent) {
96
+ var _this2 = this;
97
+ if (this.isMove) {
98
+ this.isMove = false;
99
+ natureEvent.forEach(function (handlefn) {
100
+ handlefn(_this2);
101
+ });
102
+ }
103
+ }
104
+
105
+ /**
106
+ * handle mesh raycaster
107
+ * @param raycaster
108
+ * @param intersects
109
+ */
110
+ }, {
111
+ key: "raycast",
112
+ value: function raycast(raycaster, intersects) {
113
+ var _this3 = this;
114
+ if (this.natureEventMap.size === 0) return;
115
+ _get(_getPrototypeOf(Anov3DMesh.prototype), "raycast", this).call(this, raycaster, intersects);
116
+ var pointerupCallback = this.natureEventMap.get('pointerup');
117
+ var pointerdownCallback = this.natureEventMap.get('pointerdown');
118
+ var pointermoveCallback = this.natureEventMap.get('pointermove');
119
+ var pointerleaveCallback = this.natureEventMap.get('pointerleave');
120
+ if (intersects.length > 0) {
121
+ emitter.on('pointerup', function () {
122
+ return pointerupCallback && pointerupCallback.length > 0 && _this3.debounceEventHandle(intersects, pointerupCallback);
123
+ });
124
+ emitter.on('pointerdown', function () {
125
+ return pointerdownCallback && pointerdownCallback.length > 0 && _this3.debounceEventHandle(intersects, pointerdownCallback);
126
+ });
127
+ emitter.on('pointermove', function () {
128
+ if (pointermoveCallback && pointermoveCallback.length > 0) {
129
+ _this3.isMove = true;
130
+ _this3.eventHandle(intersects, pointermoveCallback);
131
+ }
132
+ });
133
+ } else {
134
+ emitter.on('pointerleave', function () {
135
+ if (pointerleaveCallback && pointerleaveCallback.length > 0 && _this3.isMove) _this3.handlePointerleave(intersects, pointerleaveCallback);
136
+ });
137
+ }
138
+ }
139
+ }]);
140
+ return Anov3DMesh;
141
+ }(Mesh);
142
+ export default Anov3DMesh;
@@ -0,0 +1,21 @@
1
+ import type { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
2
+ declare class Anov3DModelLoader {
3
+ /**
4
+ * load gltf model
5
+ * @param url
6
+ * @param onLoad
7
+ * @param onProgress
8
+ * @param onError
9
+ * @returns
10
+ */
11
+ loadGLTF(url: string, onLoad?: (result: GLTF) => GLTF, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void): Promise<unknown>;
12
+ /**
13
+ * fbx model loader
14
+ * @param url
15
+ * @param onLoad
16
+ * @param onProgress
17
+ * @param onError
18
+ */
19
+ loadFbx(url: string, onLoad?: (result: GLTF) => GLTF, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void): void;
20
+ }
21
+ export default Anov3DModelLoader;
@@ -0,0 +1,58 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
8
+ import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
9
+ var Anov3DModelLoader = /*#__PURE__*/function () {
10
+ function Anov3DModelLoader() {
11
+ _classCallCheck(this, Anov3DModelLoader);
12
+ }
13
+ _createClass(Anov3DModelLoader, [{
14
+ key: "loadGLTF",
15
+ value:
16
+ /**
17
+ * load gltf model
18
+ * @param url
19
+ * @param onLoad
20
+ * @param onProgress
21
+ * @param onError
22
+ * @returns
23
+ */
24
+ function loadGLTF(url, onLoad, onProgress, onError) {
25
+ var loader = new GLTFLoader();
26
+ var dracoLoader = new DRACOLoader();
27
+ dracoLoader.setDecoderPath('./draco/');
28
+ dracoLoader.setDecoderConfig({
29
+ type: 'js'
30
+ });
31
+ dracoLoader.preload();
32
+ loader.setDRACOLoader(dracoLoader);
33
+ return new Promise(function (resolve, reject) {
34
+ loader.load(url, function (gltf) {
35
+ onLoad ? resolve(onLoad(gltf)) : resolve(gltf);
36
+ }, function (xhr) {
37
+ onProgress && onProgress(xhr);
38
+ }, function (err) {
39
+ onError && onError(err);
40
+ reject(err);
41
+ });
42
+ });
43
+ }
44
+
45
+ /**
46
+ * fbx model loader
47
+ * @param url
48
+ * @param onLoad
49
+ * @param onProgress
50
+ * @param onError
51
+ */
52
+ }, {
53
+ key: "loadFbx",
54
+ value: function loadFbx(url, onLoad, onProgress, onError) {}
55
+ }]);
56
+ return Anov3DModelLoader;
57
+ }();
58
+ export default Anov3DModelLoader;
@@ -0,0 +1,122 @@
1
+ import type { Color, Object3D } from 'three';
2
+ import { AmbientLight, Raycaster, Scene, Vector3, WebGLRenderer } from 'three';
3
+ import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
4
+ import { Anov3DPerspectiveCamera } from './camera';
5
+ interface Anov3DSceneOptions {
6
+ /**
7
+ * renderer options
8
+ */
9
+ rendererOps?: {
10
+ antialias?: boolean;
11
+ logarithmicDepthBuffer?: boolean;
12
+ };
13
+ /**
14
+ * default camera options
15
+ */
16
+ defCameraOps?: {
17
+ position?: Vector3;
18
+ fov?: number;
19
+ aspect?: number;
20
+ near?: number;
21
+ far?: number;
22
+ };
23
+ /**
24
+ * default ambient light options
25
+ */
26
+ defAmbientLightOps?: {
27
+ position?: Vector3;
28
+ color?: Color;
29
+ intensity?: number;
30
+ };
31
+ /**
32
+ * controls
33
+ */
34
+ orbitControls?: boolean;
35
+ /**
36
+ * 是否需要默认环境光
37
+ */
38
+ ambientLight?: boolean;
39
+ /**
40
+ * on demand render scene, 按需渲染
41
+ */
42
+ onDemand?: boolean;
43
+ }
44
+ declare class Anov3DScene {
45
+ private opts;
46
+ private pointer;
47
+ scene: Scene | null;
48
+ raycaster: Raycaster | null;
49
+ ambientLight: AmbientLight | null;
50
+ camera: Anov3DPerspectiveCamera | null;
51
+ renderer: WebGLRenderer | null;
52
+ controls: OrbitControls | null;
53
+ constructor(opts?: Anov3DSceneOptions);
54
+ /**
55
+ * init default scene components
56
+ */
57
+ private defaultInit;
58
+ /**
59
+ * init scene
60
+ * @param camera
61
+ * @param renderer
62
+ */
63
+ resetScene(camera: Anov3DPerspectiveCamera, renderer: WebGLRenderer): void;
64
+ /**
65
+ * init renderer
66
+ */
67
+ private initRenderer;
68
+ /**
69
+ * init default camera
70
+ */
71
+ private initDefaultPerspectiveCamera;
72
+ /**
73
+ * init ambient light
74
+ * @param position
75
+ * @param color
76
+ * @param intensity
77
+ * @returns
78
+ */
79
+ private initAmbientLight;
80
+ /**
81
+ * frame render
82
+ */
83
+ startFrameAnimate(frameAnimate?: (renderer: WebGLRenderer) => void): void;
84
+ /**
85
+ * scene add object3d
86
+ * @param object3d
87
+ */
88
+ add(object3d: Object3D): void;
89
+ /**
90
+ * update raycaster
91
+ */
92
+ private updateRaycaster;
93
+ private getPointerPosition;
94
+ /**
95
+ * handle pointerup event
96
+ * @param event
97
+ */
98
+ private onPointerPointerup;
99
+ /**
100
+ * handle pointerdown event
101
+ * @param event
102
+ */
103
+ private onPointerDown;
104
+ /**
105
+ * handle pointermove event
106
+ * @param event
107
+ */
108
+ private onPointerMove;
109
+ /**
110
+ * handle pointerleave event
111
+ * @param event
112
+ */
113
+ private onPointerLeave;
114
+ /**
115
+ * handle event register
116
+ * @param target
117
+ */
118
+ private registerEvent;
119
+ render(target: HTMLElement): void;
120
+ destroy(): void;
121
+ }
122
+ export default Anov3DScene;
@@ -0,0 +1,250 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ import { ACESFilmicToneMapping, AmbientLight, Raycaster, Scene, Vector2, Vector3, WebGLRenderer } from 'three';
9
+ import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
10
+ import * as TWEEN from '@tweenjs/tween.js';
11
+ import { emitter } from "../utils";
12
+ import globalControl from "./globalControl";
13
+ import globalObjectManage from "./global";
14
+ import { Anov3DPerspectiveCamera } from "./camera";
15
+ var Anov3DScene = /*#__PURE__*/function () {
16
+ function Anov3DScene(opts) {
17
+ _classCallCheck(this, Anov3DScene);
18
+ _defineProperty(this, "opts", {});
19
+ _defineProperty(this, "pointer", new Vector2());
20
+ _defineProperty(this, "scene", null);
21
+ _defineProperty(this, "raycaster", null);
22
+ _defineProperty(this, "ambientLight", null);
23
+ _defineProperty(this, "camera", null);
24
+ _defineProperty(this, "renderer", null);
25
+ _defineProperty(this, "controls", null);
26
+ this.opts = opts !== null && opts !== void 0 ? opts : {};
27
+ this.scene = new Scene();
28
+ this.raycaster = new Raycaster();
29
+ globalObjectManage.addScene(this.scene);
30
+ this.defaultInit();
31
+ }
32
+
33
+ /**
34
+ * init default scene components
35
+ */
36
+ _createClass(Anov3DScene, [{
37
+ key: "defaultInit",
38
+ value: function defaultInit() {
39
+ var camera = this.initDefaultPerspectiveCamera();
40
+ this.camera = camera;
41
+ this.scene.add(camera);
42
+ var renderer = this.initRenderer();
43
+ this.renderer = renderer;
44
+ if (this.opts.ambientLight) {
45
+ var ambientLight = this.initAmbientLight();
46
+ this.ambientLight = ambientLight;
47
+ this.scene.add(ambientLight);
48
+ }
49
+ }
50
+
51
+ /**
52
+ * init scene
53
+ * @param camera
54
+ * @param renderer
55
+ */
56
+ }, {
57
+ key: "resetScene",
58
+ value: function resetScene(camera, renderer) {
59
+ camera.aspect = window.innerWidth / window.innerHeight;
60
+ camera.updateProjectionMatrix();
61
+ renderer.setSize(window.innerWidth, window.innerHeight);
62
+ renderer.setPixelRatio(window.devicePixelRatio);
63
+ }
64
+
65
+ /**
66
+ * init renderer
67
+ */
68
+ }, {
69
+ key: "initRenderer",
70
+ value: function initRenderer() {
71
+ var _rendererOps$antialia, _rendererOps$logarith;
72
+ var rendererOps = this.opts.rendererOps || {};
73
+ var renderer = new WebGLRenderer({
74
+ antialias: (_rendererOps$antialia = rendererOps.antialias) !== null && _rendererOps$antialia !== void 0 ? _rendererOps$antialia : true,
75
+ logarithmicDepthBuffer: (_rendererOps$logarith = rendererOps.logarithmicDepthBuffer) !== null && _rendererOps$logarith !== void 0 ? _rendererOps$logarith : true
76
+ });
77
+ renderer.setSize(window.innerWidth, window.innerHeight);
78
+ renderer.shadowMap.enabled = true;
79
+ renderer.toneMapping = ACESFilmicToneMapping;
80
+ renderer.toneMappingExposure = 0.3;
81
+ renderer.setPixelRatio(window.devicePixelRatio);
82
+ return renderer;
83
+ }
84
+
85
+ /**
86
+ * init default camera
87
+ */
88
+ }, {
89
+ key: "initDefaultPerspectiveCamera",
90
+ value: function initDefaultPerspectiveCamera() {
91
+ var rendererOps = this.opts.defCameraOps || {};
92
+ var camera = new Anov3DPerspectiveCamera(rendererOps.fov || 90, window.innerWidth / window.innerHeight, rendererOps.near || 0.1, rendererOps.far || 1000);
93
+ var position = rendererOps.position || new Vector3(0, 10, 10);
94
+ camera.position.set(position.x, position.y, position.z);
95
+ return camera;
96
+ }
97
+
98
+ /**
99
+ * init ambient light
100
+ * @param position
101
+ * @param color
102
+ * @param intensity
103
+ * @returns
104
+ */
105
+ }, {
106
+ key: "initAmbientLight",
107
+ value: function initAmbientLight() {
108
+ var defConfigOps = this.opts.defAmbientLightOps || {};
109
+ var position = defConfigOps.position || new Vector3(0, 3, 10);
110
+ var ambientLight = new AmbientLight(defConfigOps.color || 0xFFFFFF, defConfigOps.intensity || 1);
111
+ ambientLight.position.set(position.x, position.y, position.z);
112
+ return ambientLight;
113
+ }
114
+
115
+ /**
116
+ * frame render
117
+ */
118
+ }, {
119
+ key: "startFrameAnimate",
120
+ value: function startFrameAnimate(frameAnimate) {
121
+ var _this = this;
122
+ if (!this.renderer || !this.scene || !this.camera) throw new Error('scene or camera or renderer is not init');
123
+ if (frameAnimate) frameAnimate(this.renderer);
124
+ this.renderer.render(this.scene, this.camera);
125
+ TWEEN.update();
126
+ globalControl.update();
127
+ this.controls && this.controls.update();
128
+ requestAnimationFrame(function () {
129
+ return _this.startFrameAnimate(frameAnimate);
130
+ });
131
+ }
132
+
133
+ /**
134
+ * scene add object3d
135
+ * @param object3d
136
+ */
137
+ }, {
138
+ key: "add",
139
+ value: function add(object3d) {
140
+ this.scene.add(object3d);
141
+ }
142
+
143
+ /**
144
+ * update raycaster
145
+ */
146
+ }, {
147
+ key: "updateRaycaster",
148
+ value: function updateRaycaster() {
149
+ this.raycaster.setFromCamera(this.pointer, this.camera);
150
+ this.raycaster.intersectObjects(this.scene.children);
151
+ }
152
+ }, {
153
+ key: "getPointerPosition",
154
+ value: function getPointerPosition(event) {
155
+ this.pointer.setX(event.clientX / window.innerWidth * 2 - 1);
156
+ this.pointer.setY(-(event.clientY / window.innerHeight) * 2 + 1);
157
+ }
158
+
159
+ /**
160
+ * handle pointerup event
161
+ * @param event
162
+ */
163
+ }, {
164
+ key: "onPointerPointerup",
165
+ value: function onPointerPointerup(event) {
166
+ this.getPointerPosition(event);
167
+ emitter.emit('pointerup');
168
+ this.updateRaycaster();
169
+ }
170
+
171
+ /**
172
+ * handle pointerdown event
173
+ * @param event
174
+ */
175
+ }, {
176
+ key: "onPointerDown",
177
+ value: function onPointerDown(event) {
178
+ this.getPointerPosition(event);
179
+ emitter.emit('pointerdown');
180
+ this.updateRaycaster();
181
+ }
182
+
183
+ /**
184
+ * handle pointermove event
185
+ * @param event
186
+ */
187
+ }, {
188
+ key: "onPointerMove",
189
+ value: function onPointerMove(event) {
190
+ this.getPointerPosition(event);
191
+ emitter.emit('pointermove');
192
+ this.updateRaycaster();
193
+ }
194
+
195
+ /**
196
+ * handle pointerleave event
197
+ * @param event
198
+ */
199
+ }, {
200
+ key: "onPointerLeave",
201
+ value: function onPointerLeave(event) {
202
+ this.getPointerPosition(event);
203
+ emitter.emit('pointerleave');
204
+ this.updateRaycaster();
205
+ }
206
+
207
+ /**
208
+ * handle event register
209
+ * @param target
210
+ */
211
+ }, {
212
+ key: "registerEvent",
213
+ value: function registerEvent(target) {
214
+ var _this2 = this;
215
+ target.addEventListener('pointerup', function (e) {
216
+ return _this2.onPointerPointerup(e);
217
+ });
218
+ target.addEventListener('pointerdown', function (e) {
219
+ return _this2.onPointerDown(e);
220
+ });
221
+ target.addEventListener('pointermove', function (e) {
222
+ return _this2.onPointerMove(e);
223
+ });
224
+ target.addEventListener('pointerleave', function (e) {
225
+ return _this2.onPointerLeave(e);
226
+ });
227
+ }
228
+ }, {
229
+ key: "render",
230
+ value: function render(target) {
231
+ var _this3 = this;
232
+ if (this.opts.orbitControls) this.controls = new OrbitControls(this.camera, this.renderer.domElement);
233
+ target.appendChild(this.renderer.domElement);
234
+ this.registerEvent(this.renderer.domElement);
235
+ target.addEventListener('resize', function () {
236
+ return _this3.resetScene(_this3.camera, _this3.renderer);
237
+ });
238
+ }
239
+ }, {
240
+ key: "destroy",
241
+ value: function destroy() {
242
+ var _this4 = this;
243
+ window.removeEventListener('resize', function () {
244
+ return _this4.resetScene(_this4.camera, _this4.renderer);
245
+ });
246
+ }
247
+ }]);
248
+ return Anov3DScene;
249
+ }();
250
+ export default Anov3DScene;
@@ -0,0 +1,12 @@
1
+ import Anove3DScene from './core/scene';
2
+ import Anov3DMesh from './core/mesh';
3
+ import { Anov3DPerspectiveCamera } from './core/camera';
4
+ import Anov3DModelLoader from './core/model';
5
+ import { ModelType } from './commonEnu';
6
+ import { Direction } from './utils/move';
7
+ declare const utils: {
8
+ moveTo: (currentObject3D: import("three").Object3D<import("three").Event>, targetObject3D: import("three").Object3D<import("three").Event>, distance: number, direction: Direction, duration?: number | undefined, animationMethod?: string | undefined) => void;
9
+ moveLine: (currentObject3D: import("three").Object3D<import("three").Event>, targetObject3D: import("three").Object3D<import("three").Event>) => void;
10
+ moveWithRound: (currentObject3d: import("three").Object3D<import("three").Event>, speed?: number, duration?: number | undefined) => void;
11
+ };
12
+ export { Anove3DScene, Anov3DMesh, Anov3DPerspectiveCamera, Anov3DModelLoader, ModelType, Direction, utils, };
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import Anove3DScene from "./core/scene";
2
+ import Anov3DMesh from "./core/mesh";
3
+ import { Anov3DPerspectiveCamera } from "./core/camera";
4
+ import Anov3DModelLoader from "./core/model";
5
+ import { ModelType } from "./commonEnu";
6
+ import { Direction, moveLine, moveTo, moveWithRound } from "./utils/move";
7
+ var utils = {
8
+ moveTo: moveTo,
9
+ moveLine: moveLine,
10
+ moveWithRound: moveWithRound
11
+ };
12
+ export { Anove3DScene, Anov3DMesh, Anov3DPerspectiveCamera, Anov3DModelLoader, ModelType, Direction, utils };
package/dist/type.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type TwinsThreeMesh from './core/mesh';
2
+ export declare type CubeEventType = 'pointerup' | 'pointerdown' | 'pointermove' | 'pointerleave';
3
+ export declare type EventHandleFn<T> = (event: TwinsThreeMesh) => void;
package/dist/type.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ export declare const emitter: {
2
+ on: {
3
+ <Key extends import("mitt").EventType>(type: Key, handler: import("mitt").Handler<Record<import("mitt").EventType, unknown>[Key]>): void;
4
+ (type: "*", handler: import("mitt").WildcardHandler<Record<import("mitt").EventType, unknown>>): void;
5
+ };
6
+ off: {
7
+ <Key_1 extends import("mitt").EventType>(type: Key_1, handler?: import("mitt").Handler<Record<import("mitt").EventType, unknown>[Key_1]> | undefined): void;
8
+ (type: "*", handler: import("mitt").WildcardHandler<Record<import("mitt").EventType, unknown>>): void;
9
+ };
10
+ emit: {
11
+ <Key_2 extends import("mitt").EventType>(type: Key_2, event: Record<import("mitt").EventType, unknown>[Key_2]): void;
12
+ <Key_3 extends import("mitt").EventType>(type: undefined extends Record<import("mitt").EventType, unknown>[Key_3] ? Key_3 : never): void;
13
+ };
14
+ all: import("mitt").EventHandlerMap<Record<import("mitt").EventType, unknown>>;
15
+ };
@@ -0,0 +1,8 @@
1
+ import mitt from 'mitt';
2
+ var emitterHandle = mitt();
3
+ export var emitter = {
4
+ on: emitterHandle.on,
5
+ off: emitterHandle.off,
6
+ emit: emitterHandle.emit,
7
+ all: emitterHandle.all
8
+ };
@@ -0,0 +1,39 @@
1
+ import type { Object3D, Vector3 } from 'three';
2
+ export declare enum Direction {
3
+ plus = "plus",
4
+ minus = "minus"
5
+ }
6
+ /**
7
+ * moveTo 直线移动
8
+ * @param currentObject3D
9
+ * @param targetObject3D
10
+ * @param direction
11
+ * @param distance
12
+ * @param duration
13
+ * @param animationMethod
14
+ */
15
+ export declare const moveTo: (currentObject3D: Object3D, targetObject3D: Object3D, distance: number, direction: Direction, duration?: number, animationMethod?: string) => void;
16
+ export declare const moveWithLine: (points: Vector3[], duration?: number) => void;
17
+ /**
18
+ * 圆周运动
19
+ * 1. 一个法向量
20
+ * 2. 一个半径
21
+ * 3. 圆心位置
22
+ * 4. 需要运动的物体
23
+ * 5. 运动的时间
24
+ * 6. 运动的方式
25
+ */
26
+ /**
27
+ * base 圆周运动
28
+ * @param currentObject3d
29
+ * @param speed
30
+ * @param duration
31
+ */
32
+ export declare const moveWithRound: (currentObject3d: Object3D, speed?: number, duration?: number) => void;
33
+ /**
34
+ * move 方法2 移动辅助线
35
+ * todo bug待修复
36
+ * @param currentObject3D
37
+ * @param targetObject3D
38
+ */
39
+ export declare const moveLine: (currentObject3D: Object3D, targetObject3D: Object3D) => void;
@@ -0,0 +1,111 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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."); }
3
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
4
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
+ 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."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ import { BufferGeometry, CatmullRomCurve3, Line, LineBasicMaterial } from 'three';
12
+ import * as TWEEN from '@tweenjs/tween.js';
13
+ import globalObjectManage from "../core/global";
14
+ import globalControl from "../core/globalControl";
15
+ var AnimationMethod;
16
+ (function (AnimationMethod) {})(AnimationMethod || (AnimationMethod = {}));
17
+ export var Direction;
18
+
19
+ /**
20
+ * moveTo 直线移动
21
+ * @param currentObject3D
22
+ * @param targetObject3D
23
+ * @param direction
24
+ * @param distance
25
+ * @param duration
26
+ * @param animationMethod
27
+ */
28
+ (function (Direction) {
29
+ Direction["plus"] = "plus";
30
+ Direction["minus"] = "minus";
31
+ })(Direction || (Direction = {}));
32
+ export var moveTo = function moveTo(currentObject3D, targetObject3D, distance, direction, duration, animationMethod) {
33
+ var targetPosition = targetObject3D.position;
34
+ var cameraPosition = currentObject3D.position;
35
+
36
+ // 单位方向向量
37
+ var toward = targetPosition.clone().sub(cameraPosition).normalize();
38
+ if (direction === Direction.minus) toward = toward.negate();
39
+ var target = cameraPosition.clone().add(toward.multiplyScalar(distance));
40
+ var totalDistance = cameraPosition.distanceTo(targetPosition);
41
+ var currentDistance = cameraPosition.distanceTo(target);
42
+ var lastPosition = target.clone();
43
+ if (direction === Direction.minus && currentDistance > totalDistance) lastPosition = targetPosition;
44
+ var tween = new TWEEN.Tween(cameraPosition);
45
+ tween.to(lastPosition, duration || 1000);
46
+ tween.start();
47
+ };
48
+
49
+ /**
50
+ * create line
51
+ * @param points
52
+ * @returns
53
+ */
54
+ var createLine = function createLine(points) {
55
+ var curve = new CatmullRomCurve3(_toConsumableArray(points));
56
+ var curvePoints = curve.getPoints(50);
57
+ var geometry = new BufferGeometry().setFromPoints(curvePoints);
58
+ var material = new LineBasicMaterial({
59
+ opacity: 1
60
+ });
61
+ return [new Line(geometry, material), curve];
62
+ };
63
+ export var moveWithLine = function moveWithLine(points, duration) {
64
+ // const line = createLine(points)
65
+ };
66
+
67
+ /**
68
+ * 圆周运动
69
+ * 1. 一个法向量
70
+ * 2. 一个半径
71
+ * 3. 圆心位置
72
+ * 4. 需要运动的物体
73
+ * 5. 运动的时间
74
+ * 6. 运动的方式
75
+ */
76
+
77
+ /**
78
+ * base 圆周运动
79
+ * @param currentObject3d
80
+ * @param speed
81
+ * @param duration
82
+ */
83
+ export var moveWithRound = function moveWithRound(currentObject3d) {
84
+ var speed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.1;
85
+ var duration = arguments.length > 2 ? arguments[2] : undefined;
86
+ var angle = 0;
87
+ var x = 0;
88
+ var z = 0;
89
+ var handleCallback = function handleCallback() {
90
+ angle += speed;
91
+ x = 4 * Math.sin(angle);
92
+ z = 4 * Math.cos(angle);
93
+ currentObject3d.position.set(x, 0, z);
94
+ };
95
+ globalControl.add(handleCallback, duration);
96
+ globalControl.start();
97
+ };
98
+
99
+ /**
100
+ * move 方法2 移动辅助线
101
+ * todo bug待修复
102
+ * @param currentObject3D
103
+ * @param targetObject3D
104
+ */
105
+ export var moveLine = function moveLine(currentObject3D, targetObject3D) {
106
+ var _createLine = createLine([currentObject3D.position, targetObject3D.position]),
107
+ _createLine2 = _slicedToArray(_createLine, 2),
108
+ curveObject = _createLine2[0],
109
+ curve = _createLine2[1];
110
+ globalObjectManage.scene.add(curveObject);
111
+ };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@anov/3d",
3
+ "version": "0.0.1-alpha.0",
4
+ "description": "",
5
+ "author": "",
6
+ "license": "MIT",
7
+ "keywords": [],
8
+ "module": "dist/index.js",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "readme.md",
15
+ "package.json"
16
+ ],
17
+ "peerDependencies": {
18
+ "three": "^0.155.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/lodash": "^4.14.196",
22
+ "@types/three": "^0.155.0",
23
+ "three": "^0.155.0"
24
+ },
25
+ "dependencies": {
26
+ "@tweenjs/tween.js": "^21.0.0",
27
+ "lodash": "^4.17.21",
28
+ "mitt": "^3.0.1"
29
+ },
30
+ "scripts": {
31
+ "build": "father build",
32
+ "build:deps": "father prebundle",
33
+ "test": "jest --maxWorkers 2"
34
+ }
35
+ }