forked from jowens/webgpu-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreejs-objload.html
56 lines (52 loc) · 1.74 KB
/
threejs-objload.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>.obj load test (three.js)</title>
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/"
}
}
</script>
</head>
<body>
<script type="module">
import { OBJLoader } from "three/addons/loaders/OBJLoader.js";
import * as BufferGeometryUtils from "three/addons/utils/BufferGeometryUtils.js";
// instantiate a loader
const loader = new OBJLoader();
// load a resource
loader.load(
// resource URL
"http://localhost:8000/square-pyramid.obj",
// called when resource is loaded
function (object) {
console.log(object);
console.log(object.children);
console.log(object.children[0]);
console.log(object.children[0].geometry);
const bg = object.children[0].geometry;
console.log(bg);
object.children[0].geometry = BufferGeometryUtils.mergeVertices(bg);
console.log(object);
// const object_geometry = object.children[0].geometry;
// const bufferGeometry = new THREE.BufferGeometry().fromGeometry(
// object_geometry
// );
// console.log(geometry);
},
// called when loading is in progresses
function (xhr) {
console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
},
// called when loading has errors
function (error) {
console.log("Load error");
}
);
</script>
</body>
</html>