@needle-tools/gltf-progressive 1.2.0-alpha.2 → 1.2.0-alpha.3
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/CHANGELOG.md +1 -1
- package/README.md +4 -0
- package/examples/threejs/index.html +1 -2
- package/examples/threejs/main.js +58 -22
- package/gltf-progressive.js +232 -227
- package/gltf-progressive.min.js +4 -4
- package/gltf-progressive.umd.cjs +4 -4
- package/lib/extension.js +2 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/lods_manager.js +3 -1
- package/lib/utils.d.ts +0 -2
- package/lib/utils.internal.d.ts +4 -0
- package/lib/utils.internal.js +46 -0
- package/lib/utils.js +4 -36
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,7 @@ All notable changes to this package will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
-
## [1.2.0-alpha] - 2023-06-06
|
|
7
|
+
## [1.2.0-alpha.3] - 2023-06-06
|
|
8
8
|
- add: automatically load the highest LOD first to show a slightly better quality level as soon as possible
|
|
9
9
|
- fix: improve Texture LOD selection by taking LOD level height into account
|
|
10
10
|
- fix: correctly assign LOD level information to initially loaded texture
|
package/README.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Support for loading of glTF or GLB files with progressive mesh or texture data for three.js based engines.
|
|
4
4
|
|
|
5
|
+
## Features
|
|
6
|
+
- Automatic loading of mesh and texture LODs.
|
|
7
|
+
- High quality LOD levels are loaded on demand based on screen density.
|
|
8
|
+
- Use low-poly LOD meshes for raycasting which allows the usage of high-poly meshes with smooth interaction
|
|
5
9
|
|
|
6
10
|
|
|
7
11
|
## Examples
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
"imports": {
|
|
15
15
|
"three": "https://cdn.jsdelivr.net/npm/three@latest/build/three.module.js",
|
|
16
16
|
"three/addons/": "https://cdn.jsdelivr.net/npm/three@latest/examples/jsm/",
|
|
17
|
-
"three/examples/": "https://cdn.jsdelivr.net/npm/three@latest/examples/"
|
|
18
|
-
"@needle-engine/gltf-progressive": "https://www.unpkg.com/@needle-tools/gltf-progressive@latest"
|
|
17
|
+
"three/examples/": "https://cdn.jsdelivr.net/npm/three@latest/examples/"
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
</script>
|
package/examples/threejs/main.js
CHANGED
|
@@ -2,7 +2,9 @@ import * as THREE from 'three';
|
|
|
2
2
|
import { EXRLoader } from 'three/addons/loaders/EXRLoader.js';
|
|
3
3
|
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
4
4
|
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
|
5
|
-
import { useNeedleProgressive, } from "
|
|
5
|
+
import { useNeedleProgressive, getRaycastMesh } from "https://www.unpkg.com/@needle-tools/gltf-progressive@latest"
|
|
6
|
+
import { Pane } from 'https://cdn.jsdelivr.net/npm/tweakpane@4.0.3/dist/tweakpane.min.js';
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
const scene = new THREE.Scene();
|
|
8
10
|
scene.background = new THREE.Color(0x555555);
|
|
@@ -10,7 +12,7 @@ const renderer = new THREE.WebGLRenderer();
|
|
|
10
12
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
11
13
|
document.body.appendChild(renderer.domElement);
|
|
12
14
|
|
|
13
|
-
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.
|
|
15
|
+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.01, 200);
|
|
14
16
|
|
|
15
17
|
|
|
16
18
|
window.addEventListener('resize', () => {
|
|
@@ -20,10 +22,10 @@ window.addEventListener('resize', () => {
|
|
|
20
22
|
});
|
|
21
23
|
|
|
22
24
|
const orbit = new OrbitControls(camera, renderer.domElement);
|
|
23
|
-
orbit.target = new THREE.Vector3(0,
|
|
24
|
-
camera.position.x =
|
|
25
|
-
camera.position.y =
|
|
26
|
-
camera.position.z =
|
|
25
|
+
orbit.target = new THREE.Vector3(0, .5, 0);
|
|
26
|
+
camera.position.x = .5;
|
|
27
|
+
camera.position.y = 1.3;
|
|
28
|
+
camera.position.z = 2;
|
|
27
29
|
|
|
28
30
|
const grid = new THREE.GridHelper(50, 50, 0x444444, 0x666666);
|
|
29
31
|
scene.add(grid);
|
|
@@ -54,23 +56,57 @@ new EXRLoader().load(environmentTextureUrl, texture => {
|
|
|
54
56
|
|
|
55
57
|
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*/
|
|
66
|
-
|
|
59
|
+
const modelUrls = [
|
|
60
|
+
"https://engine.needle.tools/demos/gltf-progressive/assets/putti gruppe/model.glb",
|
|
61
|
+
"https://engine.needle.tools/demos/gltf-progressive/assets/robot/model.glb",
|
|
62
|
+
"https://engine.needle.tools/demos/gltf-progressive/assets/vase/model.glb",
|
|
63
|
+
"https://engine.needle.tools/demos/gltf-progressive/assets/jupiter_und_ganymed/model.glb",
|
|
64
|
+
"https://engine.needle.tools/demos/gltf-progressive/assets/church/model.glb",
|
|
65
|
+
]
|
|
66
|
+
let currentUrl = "";
|
|
67
|
+
/** @type {null | THREE.Scene} */
|
|
68
|
+
let currentScene = null;
|
|
69
|
+
|
|
70
|
+
function loadScene() {
|
|
71
|
+
let currentIndex = modelUrls.indexOf(currentUrl);
|
|
72
|
+
currentIndex += 1;
|
|
73
|
+
if (currentIndex >= modelUrls.length) {
|
|
74
|
+
currentIndex = 0;
|
|
75
|
+
}
|
|
76
|
+
const url = modelUrls[currentIndex];
|
|
77
|
+
currentUrl = url;
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
// Integrate @needle-tools/gltf-progressive
|
|
81
|
+
// Create a new GLTFLoader instance
|
|
82
|
+
const gltfLoader = new GLTFLoader();
|
|
83
|
+
/** Call this method to register the progressive loader */
|
|
84
|
+
useNeedleProgressive(url, renderer, gltfLoader)
|
|
85
|
+
|
|
86
|
+
// just call the load method as usual
|
|
87
|
+
gltfLoader.load(url, gltf => {
|
|
88
|
+
// we're basically just adding our glTF to the scene here
|
|
89
|
+
// the rest of the code is just for the demo
|
|
90
|
+
console.log(gltf)
|
|
91
|
+
if (currentUrl != url) return;
|
|
92
|
+
currentScene?.removeFromParent();
|
|
93
|
+
currentScene = gltf.scene;
|
|
94
|
+
scene.add(gltf.scene)
|
|
95
|
+
gltf.scene.position.y += .01;
|
|
96
|
+
|
|
97
|
+
// the church is huge - scaling it down so we don't have a big difference between the models
|
|
98
|
+
if (url.includes("church")) {
|
|
99
|
+
gltf.scene.scale.multiplyScalar(.1);
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
loadScene();
|
|
67
104
|
|
|
68
|
-
// just call the load method as usual
|
|
69
|
-
gltfLoader.load(url, gltf => {
|
|
70
|
-
console.log(gltf)
|
|
71
|
-
scene.add(gltf.scene)
|
|
72
|
-
gltf.scene.position.y += .95;
|
|
73
|
-
})
|
|
74
105
|
|
|
75
106
|
|
|
107
|
+
const pane = new Pane();
|
|
108
|
+
const btn = pane.addButton({
|
|
109
|
+
title: 'Change Scene',
|
|
110
|
+
});
|
|
76
111
|
|
|
112
|
+
btn.on('click', loadScene);
|