|
|
<!DOCTYPE html> |
|
|
<head> |
|
|
<meta charset="utf-8"> |
|
|
<title>GVRM Viewer</title> |
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
|
<style> |
|
|
body { |
|
|
margin: 0; |
|
|
padding: 0; |
|
|
overflow: hidden; |
|
|
font-family: Arial, sans-serif; |
|
|
background-color: black; |
|
|
color: white; |
|
|
} |
|
|
#threejs-container { |
|
|
position: absolute; |
|
|
width: 100%; |
|
|
height: 100%; |
|
|
} |
|
|
#controls { |
|
|
position: absolute; |
|
|
top: 20px; |
|
|
left: 20px; |
|
|
background: rgba(0, 0, 0, 0.8); |
|
|
padding: 15px; |
|
|
border-radius: 8px; |
|
|
color: white; |
|
|
min-width: 250px; |
|
|
} |
|
|
#controls label { |
|
|
display: block; |
|
|
margin-bottom: 8px; |
|
|
font-weight: bold; |
|
|
font-size: 14px; |
|
|
} |
|
|
#controls input[type="file"] { |
|
|
width: 100%; |
|
|
padding: 8px; |
|
|
margin-bottom: 15px; |
|
|
border-radius: 4px; |
|
|
border: none; |
|
|
font-size: 13px; |
|
|
background: white; |
|
|
color: black; |
|
|
} |
|
|
#info { |
|
|
margin-top: 15px; |
|
|
padding-top: 15px; |
|
|
border-top: 1px solid rgba(255, 255, 255, 0.3); |
|
|
font-size: 12px; |
|
|
line-height: 1.6; |
|
|
color: #aaa; |
|
|
} |
|
|
#info .loaded { |
|
|
color: #4CAF50; |
|
|
font-weight: bold; |
|
|
} |
|
|
#info .warning { |
|
|
color: #ff9800; |
|
|
font-size: 11px; |
|
|
margin-top: 5px; |
|
|
} |
|
|
</style> |
|
|
</head> |
|
|
<body> |
|
|
<div id="threejs-container"></div> |
|
|
|
|
|
<div id="controls"> |
|
|
<label for="gvrmFile">GVRM File:</label> |
|
|
<input type="file" id="gvrmFile" accept=".gvrm"> |
|
|
|
|
|
<label for="fbxFile">FBX Motion:</label> |
|
|
<input type="file" id="fbxFile" accept=".fbx"> |
|
|
|
|
|
<div id="info"> |
|
|
Load a GVRM file, then optionally load an FBX motion file. |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
<script type="importmap"> |
|
|
{ |
|
|
"imports": { |
|
|
"three": "https://cdn.jsdelivr.net/npm/three@0.170.0/build/three.module.min.js", |
|
|
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.170.0/examples/jsm/", |
|
|
"@pixiv/three-vrm": "https://cdn.jsdelivr.net/npm/@pixiv/three-vrm@2.1.0/lib/three-vrm.module.js", |
|
|
"gaussian-splats-3d": "https://naruya.github.io/gs-edit/lib/gaussian-splats-3d.module.js", |
|
|
"jszip": "https://cdn.jsdelivr.net/npm/jszip@3.10.1/+esm" |
|
|
} |
|
|
} |
|
|
</script> |
|
|
|
|
|
<script type="module"> |
|
|
import * as THREE from 'three'; |
|
|
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; |
|
|
import { TrackballControls } from 'three/addons/controls/TrackballControls.js'; |
|
|
|
|
|
import { GVRM } from '../gvrm-format/gvrm.js'; |
|
|
|
|
|
|
|
|
const container = document.getElementById('threejs-container'); |
|
|
let width = window.innerWidth; |
|
|
let height = window.innerHeight; |
|
|
|
|
|
|
|
|
const renderer = new THREE.WebGLRenderer({ antialias: true }); |
|
|
container.appendChild(renderer.domElement); |
|
|
renderer.setSize(width, height); |
|
|
|
|
|
|
|
|
const camera = new THREE.PerspectiveCamera(65.0, width / height, 0.01, 2000.0); |
|
|
camera.position.set(0.0, 0.8, 2.4); |
|
|
camera.updateProjectionMatrix(); |
|
|
|
|
|
|
|
|
const controls = new OrbitControls(camera, renderer.domElement); |
|
|
controls.screenSpacePanning = true; |
|
|
controls.target.set(0.0, 0.0, 0.0); |
|
|
controls.minDistance = 0.1; |
|
|
controls.maxDistance = 1000; |
|
|
controls.enableDamping = true; |
|
|
controls.enableZoom = false; |
|
|
controls.enablePan = false; |
|
|
controls.update(); |
|
|
|
|
|
|
|
|
const controls2 = new TrackballControls(camera, renderer.domElement); |
|
|
controls2.noRotate = true; |
|
|
controls2.target.set(0.0, 0.0, 0.0); |
|
|
controls2.noPan = false; |
|
|
controls2.noZoom = false; |
|
|
controls2.zoomSpeed = 0.25; |
|
|
controls2.useDummyMouseWheel = true; |
|
|
controls2.update(); |
|
|
|
|
|
|
|
|
const scene = new THREE.Scene(); |
|
|
scene.background = new THREE.Color(0x000000); |
|
|
const light = new THREE.DirectionalLight(0xffffff, Math.PI); |
|
|
light.position.set(10.0, 10.0, 10.0); |
|
|
scene.add(light); |
|
|
|
|
|
let gvrm = null; |
|
|
let hasUpdateError = false; |
|
|
const infoDiv = document.getElementById('info'); |
|
|
|
|
|
|
|
|
document.getElementById('gvrmFile').addEventListener('change', async (e) => { |
|
|
const file = e.target.files[0]; |
|
|
if (!file) return; |
|
|
|
|
|
if (!file.name.endsWith('.gvrm')) { |
|
|
console.warn('Please select a .gvrm file'); |
|
|
infoDiv.innerHTML = 'Please select a .gvrm file'; |
|
|
return; |
|
|
} |
|
|
|
|
|
try { |
|
|
infoDiv.innerHTML = 'Loading GVRM...'; |
|
|
const url = URL.createObjectURL(file); |
|
|
|
|
|
|
|
|
if (gvrm) { |
|
|
if (gvrm.remove) { |
|
|
await gvrm.remove(scene); |
|
|
} |
|
|
gvrm = null; |
|
|
} |
|
|
|
|
|
|
|
|
gvrm = await GVRM.load(url, scene, camera, renderer, file.name); |
|
|
window.gvrm = gvrm; |
|
|
hasUpdateError = false; |
|
|
|
|
|
console.log('β GVRM loaded:', file.name); |
|
|
console.log('GVRM object:', gvrm); |
|
|
|
|
|
|
|
|
if (gvrm.character && gvrm.character.currentVrm) { |
|
|
console.log('β VRM character found'); |
|
|
console.log('Humanoid bones:', gvrm.character.currentVrm.humanoid.humanBones); |
|
|
} else { |
|
|
console.warn('β No VRM character found in GVRM'); |
|
|
} |
|
|
|
|
|
infoDiv.innerHTML = `<span class="loaded">β GVRM loaded:</span> ${file.name}<br>Now load an FBX file for motion`; |
|
|
|
|
|
URL.revokeObjectURL(url); |
|
|
|
|
|
} catch (err) { |
|
|
console.error('Failed to load GVRM:', err); |
|
|
infoDiv.innerHTML = `Error: ${err.message}`; |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
document.getElementById('fbxFile').addEventListener('change', async (e) => { |
|
|
const file = e.target.files[0]; |
|
|
if (!file) return; |
|
|
|
|
|
if (!gvrm) { |
|
|
console.warn('Load GVRM first'); |
|
|
infoDiv.innerHTML = 'Please load a GVRM file first'; |
|
|
return; |
|
|
} |
|
|
|
|
|
if (!file.name.endsWith('.fbx')) { |
|
|
console.warn('Please select a .fbx file'); |
|
|
infoDiv.innerHTML = 'Please select a .fbx file'; |
|
|
return; |
|
|
} |
|
|
|
|
|
try { |
|
|
infoDiv.innerHTML = 'Loading FBX motion...'; |
|
|
const url = URL.createObjectURL(file); |
|
|
|
|
|
|
|
|
if (gvrm.changeFBX) { |
|
|
await gvrm.changeFBX(url); |
|
|
} |
|
|
|
|
|
console.log('β FBX motion loaded:', file.name); |
|
|
|
|
|
|
|
|
if (hasUpdateError) { |
|
|
infoDiv.innerHTML = `<span class="loaded">β Motion loaded:</span> ${file.name}<br><span class="warning">β Static display mode (animation data incomplete)</span>`; |
|
|
} else { |
|
|
infoDiv.innerHTML = `<span class="loaded">β Motion loaded:</span> ${file.name}`; |
|
|
} |
|
|
|
|
|
URL.revokeObjectURL(url); |
|
|
|
|
|
} catch (err) { |
|
|
console.error('Failed to load FBX:', err); |
|
|
infoDiv.innerHTML = `FBX Error: ${err.message}`; |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
window.addEventListener('resize', () => { |
|
|
width = window.innerWidth; |
|
|
height = window.innerHeight; |
|
|
renderer.setSize(width, height); |
|
|
camera.aspect = width / height; |
|
|
camera.updateProjectionMatrix(); |
|
|
renderer.render(scene, camera); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function animate() { |
|
|
|
|
|
if (!gvrm) { |
|
|
controls.update(); |
|
|
controls2.update(); |
|
|
renderer.render(scene, camera); |
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (gvrm.update) { |
|
|
try { |
|
|
gvrm.update(); |
|
|
|
|
|
if (hasUpdateError) { |
|
|
hasUpdateError = false; |
|
|
console.log('β GVRM update working again'); |
|
|
} |
|
|
} catch (err) { |
|
|
|
|
|
if (!hasUpdateError) { |
|
|
hasUpdateError = true; |
|
|
console.warn('β GVRM update error (will continue rendering):', err.message); |
|
|
console.log('This is normal for some manually-created GVRM files'); |
|
|
console.log('The model will display correctly but may not animate'); |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
controls.update(); |
|
|
controls2.update(); |
|
|
renderer.render(scene, camera); |
|
|
} |
|
|
|
|
|
renderer.setAnimationLoop(animate); |
|
|
</script> |
|
|
</body> |
|
|
</html> |