three-base 0.0.1

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/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
@@ -0,0 +1,22 @@
1
+ name: Node.js Package
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ publish-npm:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: actions/setup-node@v2
14
+ with:
15
+ node-version: 14
16
+ registry-url: https://registry.npmjs.org/
17
+ - run: npm install
18
+ - run: npm build
19
+ - run: npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
20
+ - run: npm publish
21
+ env:
22
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 肛肠科冯主任
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # NPM-THREE
2
+ > 对THREE简单的封装.....
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Document</title>
8
+ <style>
9
+ * {
10
+ padding: 0;
11
+ margin: 0;
12
+ }
13
+ #app {
14
+ width: 100vw;
15
+ height: 100vh;
16
+ }
17
+ </style>
18
+ </head>
19
+ <body>
20
+ <div id="app"></div>
21
+ </body>
22
+ <script type="module">
23
+ import Three from "../dist/index.js";
24
+ const app = document.querySelector("#app");
25
+ const three = new Three(app);
26
+ </script>
27
+ </html>
File without changes
package/lib/index.ts ADDED
@@ -0,0 +1,112 @@
1
+ import * as THREE from "three";
2
+ import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
3
+ import { CSS2DRenderer } from "three/examples/jsm/renderers/CSS2DRenderer";
4
+ import { GLTFLoader, GLTF } from "three/examples/jsm/loaders/GLTFLoader";
5
+ import { AnimationClip } from "three";
6
+ import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
7
+ import Stats from "three/examples/jsm/libs/stats.module.js";
8
+ //@ts-ignore
9
+ import TWEEN from "@tweenjs/tween.js";
10
+ class Three {
11
+ scene: THREE.Scene;
12
+ camera: THREE.PerspectiveCamera;
13
+ renderer: THREE.WebGLRenderer;
14
+ control: OrbitControls;
15
+ CSSRender: CSS2DRenderer;
16
+ element: HTMLElement;
17
+ mixers: THREE.AnimationMixer[];
18
+ composers: Array<EffectComposer>;
19
+ clock: THREE.Clock;
20
+ renderMixins: Array<Function>;
21
+ stats: any;
22
+ constructor(element: HTMLElement) {
23
+ this.element = element;
24
+ this.scene = this.initScene();
25
+ this.camera = this.initCamera(element);
26
+ this.renderer = this.initRenderer(element);
27
+ this.CSSRender = this.initCSSRender(element);
28
+ this.control = this.initControl();
29
+ this.stats = null;
30
+ this.mixers = [];
31
+ this.composers = [];
32
+ this.renderMixins = [];
33
+ this.clock = new THREE.Clock();
34
+ }
35
+ initScene(): THREE.Scene {
36
+ const scene = new THREE.Scene();
37
+ return scene;
38
+ }
39
+ initCSSRender(element: HTMLElement): CSS2DRenderer {
40
+ const CSSRender = new CSS2DRenderer();
41
+ CSSRender.setSize(element.offsetWidth, element.offsetHeight);
42
+ CSSRender.domElement.style.position = "absolute";
43
+ CSSRender.domElement.style.top = "0px";
44
+ element.appendChild(CSSRender.domElement);
45
+ return CSSRender;
46
+ }
47
+ initCamera(element: HTMLElement): THREE.PerspectiveCamera {
48
+ const fov = 20;
49
+ const aspect = element.offsetWidth / element.offsetHeight;
50
+ const near = 0.1;
51
+ const far = 5 * 1000;
52
+ const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
53
+ camera.position.set(0, 0, 3);
54
+ return camera;
55
+ }
56
+ initRenderer(element: HTMLElement) {
57
+ const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
58
+ renderer.outputEncoding = THREE.sRGBEncoding;
59
+ renderer.localClippingEnabled = true;
60
+ renderer.shadowMap.enabled = true;
61
+ renderer.setSize(element.offsetWidth, element.offsetHeight);
62
+ element.appendChild(renderer.domElement);
63
+ return renderer;
64
+ }
65
+ initControl() {
66
+ const control = new OrbitControls(this.camera, this.CSSRender.domElement);
67
+ return control;
68
+ }
69
+ initHelp(size: number) {
70
+ const axesHelper = new THREE.AxesHelper(size);
71
+ this.scene.add(axesHelper);
72
+ }
73
+ initStats() {
74
+ //@ts-ignore
75
+ this.stats = new Stats();
76
+ this.element.appendChild(this.stats.dom);
77
+ }
78
+ loadGLTF(url: string, onProgress = (progress: number) => {}): Promise<GLTF> {
79
+ const loader = new GLTFLoader();
80
+ return new Promise<GLTF>((resolve) => {
81
+ loader.load(
82
+ url,
83
+ (object: any) => resolve(object),
84
+ (xhr: any) => onProgress(Number((xhr.loaded / xhr.total) * 100))
85
+ );
86
+ });
87
+ }
88
+ playModelAnimate(
89
+ mesh: THREE.Object3D | THREE.AnimationObjectGroup,
90
+ animations: AnimationClip[],
91
+ animationName: string
92
+ ) {
93
+ const mixer = new THREE.AnimationMixer(mesh);
94
+ const clip = THREE.AnimationClip.findByName(animations, animationName);
95
+ if (!clip) return void 0;
96
+ const action = mixer.clipAction(clip);
97
+ action.play();
98
+ this.mixers.push(mixer);
99
+ }
100
+ render() {
101
+ const delta = new THREE.Clock().getDelta();
102
+ this.renderer.render(this.scene, this.camera);
103
+ requestAnimationFrame(() => this.render());
104
+ const mixerUpdateDelta = this.clock.getDelta();
105
+ this.mixers.forEach((mixer) => mixer.update(mixerUpdateDelta));
106
+ this.composers.forEach((composer) => composer.render(delta));
107
+ this.renderMixins.forEach((mixin) => mixin());
108
+ TWEEN.update();
109
+ this.stats && this.stats?.update();
110
+ }
111
+ }
112
+ export default Three;
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "three-base",
3
+ "version": "0.0.1",
4
+ "description": "three base",
5
+ "main": "./dist/index.js",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "example": "tsc && node ./example/index.js"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/fengtianxi001/NPM-THREE.git"
13
+ },
14
+ "author": "fengtianxi001",
15
+ "license": "ISC",
16
+ "homepage": "https://github.com/fengtianxi001/NPM-THREE",
17
+ "dependencies": {
18
+ "@tweenjs/tween.js": "^18.6.4",
19
+ "@types/three": "^0.141.0",
20
+ "three": "^0.141.0",
21
+ "tsc": "^2.0.4",
22
+ "typescript": "^4.7.3"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^17.0.8"
26
+ }
27
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "include": ["lib"],
3
+ "moduleResolution": "node",
4
+ "compilerOptions": {
5
+ "target": "es5",
6
+ "module": "es6",
7
+ "declaration": true,
8
+ "outDir": "./dist",
9
+ "strict": true
10
+ }
11
+ }