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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<head>
|
| 3 |
+
<meta charset="utf-8">
|
| 4 |
+
<title>GVRM Viewer</title>
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<style>
|
| 7 |
+
body {
|
| 8 |
+
margin: 0;
|
| 9 |
+
padding: 0;
|
| 10 |
+
overflow: hidden;
|
| 11 |
+
font-family: Arial, sans-serif;
|
| 12 |
+
background-color: black;
|
| 13 |
+
color: white;
|
| 14 |
+
}
|
| 15 |
+
#threejs-container {
|
| 16 |
+
position: absolute;
|
| 17 |
+
width: 100%;
|
| 18 |
+
height: 100%;
|
| 19 |
+
}
|
| 20 |
+
#controls {
|
| 21 |
+
position: absolute;
|
| 22 |
+
top: 20px;
|
| 23 |
+
left: 20px;
|
| 24 |
+
background: rgba(0, 0, 0, 0.8);
|
| 25 |
+
padding: 15px;
|
| 26 |
+
border-radius: 8px;
|
| 27 |
+
color: white;
|
| 28 |
+
min-width: 250px;
|
| 29 |
+
}
|
| 30 |
+
#controls label {
|
| 31 |
+
display: block;
|
| 32 |
+
margin-bottom: 8px;
|
| 33 |
+
font-weight: bold;
|
| 34 |
+
font-size: 14px;
|
| 35 |
+
}
|
| 36 |
+
#controls input[type="file"] {
|
| 37 |
+
width: 100%;
|
| 38 |
+
padding: 8px;
|
| 39 |
+
margin-bottom: 15px;
|
| 40 |
+
border-radius: 4px;
|
| 41 |
+
border: none;
|
| 42 |
+
font-size: 13px;
|
| 43 |
+
background: white;
|
| 44 |
+
color: black;
|
| 45 |
+
}
|
| 46 |
+
#info {
|
| 47 |
+
margin-top: 15px;
|
| 48 |
+
padding-top: 15px;
|
| 49 |
+
border-top: 1px solid rgba(255, 255, 255, 0.3);
|
| 50 |
+
font-size: 12px;
|
| 51 |
+
line-height: 1.6;
|
| 52 |
+
color: #aaa;
|
| 53 |
+
}
|
| 54 |
+
#info .loaded {
|
| 55 |
+
color: #4CAF50;
|
| 56 |
+
font-weight: bold;
|
| 57 |
+
}
|
| 58 |
+
#info .warning {
|
| 59 |
+
color: #ff9800;
|
| 60 |
+
font-size: 11px;
|
| 61 |
+
margin-top: 5px;
|
| 62 |
+
}
|
| 63 |
+
</style>
|
| 64 |
+
</head>
|
| 65 |
+
<body>
|
| 66 |
+
<div id="threejs-container"></div>
|
| 67 |
+
|
| 68 |
+
<div id="controls">
|
| 69 |
+
<label for="gvrmFile">GVRM File:</label>
|
| 70 |
+
<input type="file" id="gvrmFile" accept=".gvrm">
|
| 71 |
+
|
| 72 |
+
<label for="fbxFile">FBX Motion:</label>
|
| 73 |
+
<input type="file" id="fbxFile" accept=".fbx">
|
| 74 |
+
|
| 75 |
+
<div id="info">
|
| 76 |
+
Load a GVRM file, then optionally load an FBX motion file.
|
| 77 |
+
</div>
|
| 78 |
+
</div>
|
| 79 |
+
|
| 80 |
+
<script type="importmap">
|
| 81 |
+
{
|
| 82 |
+
"imports": {
|
| 83 |
+
"three": "https://cdn.jsdelivr.net/npm/three@0.170.0/build/three.module.min.js",
|
| 84 |
+
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.170.0/examples/jsm/",
|
| 85 |
+
"@pixiv/three-vrm": "https://cdn.jsdelivr.net/npm/@pixiv/three-vrm@2.1.0/lib/three-vrm.module.js",
|
| 86 |
+
"gaussian-splats-3d": "https://naruya.github.io/gs-edit/lib/gaussian-splats-3d.module.js",
|
| 87 |
+
"jszip": "https://cdn.jsdelivr.net/npm/jszip@3.10.1/+esm"
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
</script>
|
| 91 |
+
|
| 92 |
+
<script type="module">
|
| 93 |
+
import * as THREE from 'three';
|
| 94 |
+
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
| 95 |
+
import { TrackballControls } from 'three/addons/controls/TrackballControls.js';
|
| 96 |
+
// π§ FIXED: Use local gvrm.js instead of external minified version
|
| 97 |
+
import { GVRM } from '../gvrm-format/gvrm.js';
|
| 98 |
+
|
| 99 |
+
// Setup
|
| 100 |
+
const container = document.getElementById('threejs-container');
|
| 101 |
+
let width = window.innerWidth;
|
| 102 |
+
let height = window.innerHeight;
|
| 103 |
+
|
| 104 |
+
// Renderer (same as main.js)
|
| 105 |
+
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
| 106 |
+
container.appendChild(renderer.domElement);
|
| 107 |
+
renderer.setSize(width, height);
|
| 108 |
+
|
| 109 |
+
// Camera (same as main.js)
|
| 110 |
+
const camera = new THREE.PerspectiveCamera(65.0, width / height, 0.01, 2000.0);
|
| 111 |
+
camera.position.set(0.0, 0.8, 2.4);
|
| 112 |
+
camera.updateProjectionMatrix();
|
| 113 |
+
|
| 114 |
+
// OrbitControls (same as main.js)
|
| 115 |
+
const controls = new OrbitControls(camera, renderer.domElement);
|
| 116 |
+
controls.screenSpacePanning = true;
|
| 117 |
+
controls.target.set(0.0, 0.0, 0.0);
|
| 118 |
+
controls.minDistance = 0.1;
|
| 119 |
+
controls.maxDistance = 1000;
|
| 120 |
+
controls.enableDamping = true;
|
| 121 |
+
controls.enableZoom = false;
|
| 122 |
+
controls.enablePan = false;
|
| 123 |
+
controls.update();
|
| 124 |
+
|
| 125 |
+
// TrackballControls (same as main.js)
|
| 126 |
+
const controls2 = new TrackballControls(camera, renderer.domElement);
|
| 127 |
+
controls2.noRotate = true;
|
| 128 |
+
controls2.target.set(0.0, 0.0, 0.0);
|
| 129 |
+
controls2.noPan = false;
|
| 130 |
+
controls2.noZoom = false;
|
| 131 |
+
controls2.zoomSpeed = 0.25;
|
| 132 |
+
controls2.useDummyMouseWheel = true;
|
| 133 |
+
controls2.update();
|
| 134 |
+
|
| 135 |
+
// Scene (same as main.js)
|
| 136 |
+
const scene = new THREE.Scene();
|
| 137 |
+
scene.background = new THREE.Color(0x000000);
|
| 138 |
+
const light = new THREE.DirectionalLight(0xffffff, Math.PI);
|
| 139 |
+
light.position.set(10.0, 10.0, 10.0);
|
| 140 |
+
scene.add(light);
|
| 141 |
+
|
| 142 |
+
let gvrm = null;
|
| 143 |
+
let hasUpdateError = false;
|
| 144 |
+
const infoDiv = document.getElementById('info');
|
| 145 |
+
|
| 146 |
+
// GVRM file loader
|
| 147 |
+
document.getElementById('gvrmFile').addEventListener('change', async (e) => {
|
| 148 |
+
const file = e.target.files[0];
|
| 149 |
+
if (!file) return;
|
| 150 |
+
|
| 151 |
+
if (!file.name.endsWith('.gvrm')) {
|
| 152 |
+
console.warn('Please select a .gvrm file');
|
| 153 |
+
infoDiv.innerHTML = 'Please select a .gvrm file';
|
| 154 |
+
return;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
try {
|
| 158 |
+
infoDiv.innerHTML = 'Loading GVRM...';
|
| 159 |
+
const url = URL.createObjectURL(file);
|
| 160 |
+
|
| 161 |
+
// Remove old GVRM (same as main.js)
|
| 162 |
+
if (gvrm) {
|
| 163 |
+
if (gvrm.remove) {
|
| 164 |
+
await gvrm.remove(scene);
|
| 165 |
+
}
|
| 166 |
+
gvrm = null;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
// Load GVRM (same call signature as main.js)
|
| 170 |
+
gvrm = await GVRM.load(url, scene, camera, renderer, file.name);
|
| 171 |
+
window.gvrm = gvrm;
|
| 172 |
+
hasUpdateError = false;
|
| 173 |
+
|
| 174 |
+
console.log('β GVRM loaded:', file.name);
|
| 175 |
+
console.log('GVRM object:', gvrm);
|
| 176 |
+
|
| 177 |
+
// Check for bone structure
|
| 178 |
+
if (gvrm.character && gvrm.character.currentVrm) {
|
| 179 |
+
console.log('β VRM character found');
|
| 180 |
+
console.log('Humanoid bones:', gvrm.character.currentVrm.humanoid.humanBones);
|
| 181 |
+
} else {
|
| 182 |
+
console.warn('β No VRM character found in GVRM');
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
infoDiv.innerHTML = `<span class="loaded">β GVRM loaded:</span> ${file.name}<br>Now load an FBX file for motion`;
|
| 186 |
+
|
| 187 |
+
URL.revokeObjectURL(url);
|
| 188 |
+
|
| 189 |
+
} catch (err) {
|
| 190 |
+
console.error('Failed to load GVRM:', err);
|
| 191 |
+
infoDiv.innerHTML = `Error: ${err.message}`;
|
| 192 |
+
}
|
| 193 |
+
});
|
| 194 |
+
|
| 195 |
+
// FBX file loader
|
| 196 |
+
document.getElementById('fbxFile').addEventListener('change', async (e) => {
|
| 197 |
+
const file = e.target.files[0];
|
| 198 |
+
if (!file) return;
|
| 199 |
+
|
| 200 |
+
if (!gvrm) {
|
| 201 |
+
console.warn('Load GVRM first');
|
| 202 |
+
infoDiv.innerHTML = 'Please load a GVRM file first';
|
| 203 |
+
return;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
if (!file.name.endsWith('.fbx')) {
|
| 207 |
+
console.warn('Please select a .fbx file');
|
| 208 |
+
infoDiv.innerHTML = 'Please select a .fbx file';
|
| 209 |
+
return;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
try {
|
| 213 |
+
infoDiv.innerHTML = 'Loading FBX motion...';
|
| 214 |
+
const url = URL.createObjectURL(file);
|
| 215 |
+
|
| 216 |
+
// Change FBX (same as main.js)
|
| 217 |
+
if (gvrm.changeFBX) {
|
| 218 |
+
await gvrm.changeFBX(url);
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
console.log('β FBX motion loaded:', file.name);
|
| 222 |
+
|
| 223 |
+
// Check if update will work
|
| 224 |
+
if (hasUpdateError) {
|
| 225 |
+
infoDiv.innerHTML = `<span class="loaded">β Motion loaded:</span> ${file.name}<br><span class="warning">β Static display mode (animation data incomplete)</span>`;
|
| 226 |
+
} else {
|
| 227 |
+
infoDiv.innerHTML = `<span class="loaded">β Motion loaded:</span> ${file.name}`;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
URL.revokeObjectURL(url);
|
| 231 |
+
|
| 232 |
+
} catch (err) {
|
| 233 |
+
console.error('Failed to load FBX:', err);
|
| 234 |
+
infoDiv.innerHTML = `FBX Error: ${err.message}`;
|
| 235 |
+
}
|
| 236 |
+
});
|
| 237 |
+
|
| 238 |
+
// Window resize
|
| 239 |
+
window.addEventListener('resize', () => {
|
| 240 |
+
width = window.innerWidth;
|
| 241 |
+
height = window.innerHeight;
|
| 242 |
+
renderer.setSize(width, height);
|
| 243 |
+
camera.aspect = width / height;
|
| 244 |
+
camera.updateProjectionMatrix();
|
| 245 |
+
renderer.render(scene, camera);
|
| 246 |
+
});
|
| 247 |
+
|
| 248 |
+
// ========================================
|
| 249 |
+
// π§ FIXED: Animation loop like main.js
|
| 250 |
+
// No error handling - just continue rendering
|
| 251 |
+
// ========================================
|
| 252 |
+
function animate() {
|
| 253 |
+
// Always continue animation loop, even if gvrm is null
|
| 254 |
+
if (!gvrm) {
|
| 255 |
+
controls.update();
|
| 256 |
+
controls2.update();
|
| 257 |
+
renderer.render(scene, camera);
|
| 258 |
+
return;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// Try to update GVRM animation
|
| 262 |
+
// If it fails, just log once and continue rendering
|
| 263 |
+
if (gvrm.update) {
|
| 264 |
+
try {
|
| 265 |
+
gvrm.update();
|
| 266 |
+
// Reset error flag if update succeeds
|
| 267 |
+
if (hasUpdateError) {
|
| 268 |
+
hasUpdateError = false;
|
| 269 |
+
console.log('β GVRM update working again');
|
| 270 |
+
}
|
| 271 |
+
} catch (err) {
|
| 272 |
+
// Only log error once
|
| 273 |
+
if (!hasUpdateError) {
|
| 274 |
+
hasUpdateError = true;
|
| 275 |
+
console.warn('β GVRM update error (will continue rendering):', err.message);
|
| 276 |
+
console.log('This is normal for some manually-created GVRM files');
|
| 277 |
+
console.log('The model will display correctly but may not animate');
|
| 278 |
+
}
|
| 279 |
+
// Continue rendering even with error
|
| 280 |
+
}
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
controls.update();
|
| 284 |
+
controls2.update();
|
| 285 |
+
renderer.render(scene, camera);
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
renderer.setAnimationLoop(animate);
|
| 289 |
+
</script>
|
| 290 |
+
</body>
|
| 291 |
+
</html>
|