forked from repalash/xatlas-three
-
Notifications
You must be signed in to change notification settings - Fork 1
/
uvs-debug.html
165 lines (126 loc) · 4.92 KB
/
uvs-debug.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<html lang="en">
<head>
<title>xatlas.js - uv mapping tests</title>
<meta charset=utf-8/>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
background: #ffffff;
color: #000000;
text-align: center;
font-family: sans-serif;
}
h3 {
margin-top: 60px;
margin-bottom: 30px;
font-weight: normal;
font-size: 1rem;
}
canvas {
width: 100%;
}
</style>
</head>
<body>
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<div id="info">
xatlas.js - <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - UV Unwrapping - <a
href="https://repalash.com" target="_blank" rel="noopener">repalash</a><br/>
<a href="https://github.com/repalash/xatlas-three/tree/master/public/uvs-debug.html" target="_blank" rel="noopener">View
source</a><br/>
</div>
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js",
"xatlas-three": "./build/index.js"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import {UVUnwrapper} from 'xatlas-three';
import {UVsDebug} from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/utils/UVsDebug.js';
import {mergeVertices} from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/utils/BufferGeometryUtils.js';
/*
* This is to help debug UVs problems in geometry,
* as well as allow a new user to visualize what UVs are about.
*/
const unwrapper = new UVUnwrapper({BufferAttribute: THREE.BufferAttribute});
unwrapper.chartOptions = {
fixWinding: false,
maxBoundaryLength: 0,
maxChartArea: 0,
maxCost: 3,
maxIterations: 1,
normalDeviationWeight: 2,
normalSeamWeight: 4,
roundnessWeight: 0.001,
straightnessWeight: 6,
textureSeamWeight: 0.5,
useInputMeshUvs: false,
}
unwrapper.packOptions = {
bilinear: true,
blockAlign: false,
bruteForce: false,
createImage: false,
maxChartSize: 0,
padding: 0,
resolution: 0,
rotateCharts: true,
rotateChartsToAxis: true,
texelsPerUnit: 0
}
unwrapper.useNormals = true
unwrapper.timeUnwrap = true // Logs time of unwrapping
unwrapper.logProgress = true // Logs unwrapping progress bar
async function test(name, geometry) {
if (!geometry.index) {
geometry = mergeVertices(geometry); // convert to indexed geometry
}
const d = document.createElement('div');
const d1 = document.createElement('div');
const d2 = document.createElement('div');
d.style.display = 'flex'
d.style.gap = '2rem'
d1.style.flex = '1'
d2.style.flex = '1'
d1.innerHTML = '<h3>' + name + '</h3>';
d1.appendChild(UVsDebug(geometry));
await unwrapper.unwrapGeometry(geometry);
d2.innerHTML = '<h3> Unwrapped </h3>';
d2.appendChild(UVsDebug(geometry));
document.body.appendChild(d);
d.appendChild(d1);
d.appendChild(d2);
}
const points = [];
for (let i = 0; i < 10; i++) {
points.push(new THREE.Vector2(Math.sin(i * 0.2) * 15 + 50, (i - 5) * 2));
}
//
unwrapper.loadLibrary((mode, progress) => {
// console.log(mode, progress);
},
// window.location.origin + '/node_modules/xatlasjs/dist/xatlas.wasm',
// window.location.origin + '/node_modules/xatlasjs/dist/xatlas.js',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/xatlas.wasm',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/xatlas.js',
).then(async function () {
await test('PlaneGeometry( 100, 100, 4, 4 )', new THREE.PlaneGeometry(100, 100, 4, 4));
await test('SphereGeometry( 75, 12, 6 )', new THREE.SphereGeometry(75, 12, 6));
await test('IcosahedronGeometry( 30, 1 )', new THREE.IcosahedronGeometry(30, 1));
await test('OctahedronGeometry( 30, 2 )', new THREE.OctahedronGeometry(30, 2));
await test('CylinderGeometry( 25, 75, 100, 10, 5 )', new THREE.CylinderGeometry(25, 75, 100, 10, 5));
await test('BoxGeometry( 100, 100, 100, 4, 4, 4 )', new THREE.BoxGeometry(100, 100, 100, 4, 4, 4));
await test('LatheGeometry( points, 8 )', new THREE.LatheGeometry(points, 8));
await test('TorusGeometry( 50, 20, 8, 8 )', new THREE.TorusGeometry(50, 20, 8, 8));
await test('TorusKnotGeometry( 50, 10, 12, 6 )', new THREE.TorusKnotGeometry(50, 10, 12, 6));
});
</script>
</body>
</html>