363 lines
13 KiB
HTML
363 lines
13 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>31 - Stanford Buddha</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
body {
|
|
overflow: hidden;
|
|
background: #0f0f0f;
|
|
font-family: 'Segoe UI', Arial, sans-serif;
|
|
}
|
|
#canvas-container {
|
|
position: fixed;
|
|
top: 0; left: 0;
|
|
width: 100%; height: 100%;
|
|
}
|
|
#ui {
|
|
position: fixed;
|
|
top: 0; left: 0;
|
|
width: 100%; height: 100%;
|
|
pointer-events: none;
|
|
z-index: 10;
|
|
}
|
|
#title {
|
|
position: absolute;
|
|
top: 25px; left: 30px;
|
|
color: #fff;
|
|
font-size: 20px;
|
|
letter-spacing: 2px;
|
|
}
|
|
#title span {
|
|
color: #ffd700;
|
|
font-size: 14px;
|
|
}
|
|
#model-info {
|
|
position: absolute;
|
|
top: 25px; right: 30px;
|
|
color: #ffd700;
|
|
text-align: right;
|
|
}
|
|
#model-info .name {
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
color: #fff;
|
|
}
|
|
#model-info .stats {
|
|
font-size: 12px;
|
|
color: #888;
|
|
margin-top: 5px;
|
|
}
|
|
#controls {
|
|
position: absolute;
|
|
bottom: 30px; left: 30px;
|
|
pointer-events: auto;
|
|
background: rgba(0,0,0,0.85);
|
|
padding: 20px;
|
|
border-radius: 12px;
|
|
border: 1px solid rgba(255,215,0,0.2);
|
|
}
|
|
#controls button {
|
|
background: rgba(255,255,255,0.08);
|
|
border: 1px solid rgba(255,255,255,0.15);
|
|
color: #fff;
|
|
padding: 10px 18px;
|
|
margin: 5px;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
font-size: 12px;
|
|
}
|
|
#controls button:hover {
|
|
background: rgba(255,215,0,0.2);
|
|
border-color: #ffd700;
|
|
}
|
|
#controls button.active {
|
|
background: rgba(255,215,0,0.4);
|
|
border-color: #ffd700;
|
|
}
|
|
#loading {
|
|
position: fixed;
|
|
top: 50%; left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
color: #ffd700;
|
|
font-size: 24px;
|
|
text-align: center;
|
|
z-index: 100;
|
|
}
|
|
#loading .progress {
|
|
font-size: 14px;
|
|
color: #666;
|
|
margin-top: 10px;
|
|
}
|
|
#quality-selector {
|
|
position: absolute;
|
|
top: 80px; left: 30px;
|
|
pointer-events: auto;
|
|
}
|
|
#quality-selector button {
|
|
background: rgba(255,255,255,0.05);
|
|
border: 1px solid rgba(255,255,255,0.1);
|
|
color: #888;
|
|
padding: 5px 12px;
|
|
margin-right: 5px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 11px;
|
|
}
|
|
#quality-selector button:hover {
|
|
color: #fff;
|
|
border-color: #ffd700;
|
|
}
|
|
#quality-selector button.active {
|
|
color: #ffd700;
|
|
border-color: #ffd700;
|
|
}
|
|
#buddha-quote {
|
|
position: absolute;
|
|
bottom: 150px;
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
color: rgba(255,215,0,0.4);
|
|
font-size: 14px;
|
|
font-style: italic;
|
|
letter-spacing: 1px;
|
|
pointer-events: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="loading">
|
|
<div>🧘 加载 Happy Buddha...</div>
|
|
<div class="progress" id="loading-text">初始化</div>
|
|
</div>
|
|
|
|
<div id="canvas-container"></div>
|
|
|
|
<div id="ui">
|
|
<div id="title">31 - Stanford Buddha <span>🧘</span></div>
|
|
|
|
<div id="quality-selector">
|
|
<button onclick="loadQuality('res4')" id="btn-res4">极简 (488KB)</button>
|
|
<button onclick="loadQuality('res3')" class="active" id="btn-res3">低质量 (2.3MB)</button>
|
|
<button onclick="loadQuality('res2')" id="btn-res2">中等 (11MB)</button>
|
|
<button onclick="loadQuality('full')" id="btn-full">完整 (41MB)</button>
|
|
</div>
|
|
|
|
<div id="model-info">
|
|
<div class="name">Happy Buddha</div>
|
|
<div class="stats">
|
|
顶点: <span id="vertex-count">-</span> |
|
|
面数: <span id="face-count">-</span><br>
|
|
文件: <span id="file-info">happy_vrip_res3.ply</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="buddha-quote">"Peace comes from within. Do not seek it without."</div>
|
|
|
|
<div id="controls">
|
|
<div style="color: #ffd700; margin-bottom: 10px; font-size: 13px;">🎨 渲染模式</div>
|
|
<button onclick="setMode('jade')" class="active" id="btn-jade">翡翠材质</button>
|
|
<button onclick="setMode('bronze')" id="btn-bronze">古铜材质</button>
|
|
<button onclick="setMode('gold')" id="btn-gold">鎏金材质</button>
|
|
<button onclick="setMode('normal')" id="btn-normal">法线着色</button>
|
|
<button onclick="setMode('wireframe')" id="btn-wireframe">线框模式</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/PLYLoader.js"></script>
|
|
|
|
<script>
|
|
// ========== 场景 ==========
|
|
const scene = new THREE.Scene();
|
|
scene.background = new THREE.Color(0x0f0f0f);
|
|
scene.fog = new THREE.Fog(0x0f0f0f, 0.5, 5);
|
|
|
|
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.01, 100);
|
|
camera.position.set(0, 0.2, 0.8);
|
|
|
|
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
renderer.setPixelRatio(window.devicePixelRatio);
|
|
renderer.shadowMap.enabled = true;
|
|
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
document.getElementById('canvas-container').appendChild(renderer.domElement);
|
|
|
|
// 控制器
|
|
const controls = new THREE.OrbitControls(camera, renderer.domElement);
|
|
controls.enableDamping = true;
|
|
controls.dampingFactor = 0.05;
|
|
controls.autoRotate = true;
|
|
controls.autoRotateSpeed = 0.3;
|
|
controls.target.set(0, 0.1, 0);
|
|
|
|
// 灯光 - 营造庄严氛围
|
|
const ambientLight = new THREE.AmbientLight(0xffffff, 0.3);
|
|
scene.add(ambientLight);
|
|
|
|
const mainLight = new THREE.DirectionalLight(0xfffaed, 1.2);
|
|
mainLight.position.set(0.5, 2, 1);
|
|
mainLight.castShadow = true;
|
|
scene.add(mainLight);
|
|
|
|
const fillLight = new THREE.DirectionalLight(0xccddff, 0.4);
|
|
fillLight.position.set(-1, 0.5, -0.5);
|
|
scene.add(fillLight);
|
|
|
|
const rimLight = new THREE.SpotLight(0xffd700, 0.8);
|
|
rimLight.position.set(0, 2, -2);
|
|
rimLight.lookAt(0, 0, 0);
|
|
scene.add(rimLight);
|
|
|
|
// ========== 材质 - 佛像专用 ==========
|
|
const materials = {
|
|
jade: () => new THREE.MeshPhysicalMaterial({
|
|
color: 0x4a7c59,
|
|
metalness: 0.1,
|
|
roughness: 0.2,
|
|
transmission: 0.1,
|
|
thickness: 0.5,
|
|
clearcoat: 1,
|
|
clearcoatRoughness: 0.1
|
|
}),
|
|
bronze: () => new THREE.MeshStandardMaterial({
|
|
color: 0x8b7355,
|
|
metalness: 0.8,
|
|
roughness: 0.4
|
|
}),
|
|
gold: () => new THREE.MeshStandardMaterial({
|
|
color: 0xffd700,
|
|
metalness: 0.9,
|
|
roughness: 0.15
|
|
}),
|
|
normal: () => new THREE.MeshNormalMaterial(),
|
|
wireframe: () => new THREE.MeshBasicMaterial({
|
|
color: 0xffd700,
|
|
wireframe: true,
|
|
transparent: true,
|
|
opacity: 0.3
|
|
})
|
|
};
|
|
|
|
// ========== 模型配置 ==========
|
|
const modelConfigs = {
|
|
res4: { file: 'happy_vrip_res4.ply', size: '488KB', scale: 0.5 },
|
|
res3: { file: 'happy_vrip_res3.ply', size: '2.3MB', scale: 0.5 },
|
|
res2: { file: 'happy_vrip_res2.ply', size: '11MB', scale: 0.5 },
|
|
full: { file: 'happy_vrip.ply', size: '41MB', scale: 0.5 }
|
|
};
|
|
|
|
let currentMesh = null;
|
|
let currentMode = 'jade';
|
|
let currentQuality = 'res3';
|
|
const loader = new THREE.PLYLoader();
|
|
|
|
// ========== 加载 ==========
|
|
function loadQuality(quality) {
|
|
currentQuality = quality;
|
|
const config = modelConfigs[quality];
|
|
|
|
document.querySelectorAll('#quality-selector button').forEach(btn => {
|
|
btn.classList.remove('active');
|
|
});
|
|
document.getElementById(`btn-${quality}`).classList.add('active');
|
|
document.getElementById('file-info').textContent = `${config.file} (${config.size})`;
|
|
|
|
document.getElementById('loading').style.display = 'block';
|
|
document.getElementById('loading-text').textContent = `加载 ${config.size}...`;
|
|
|
|
if (currentMesh) {
|
|
scene.remove(currentMesh);
|
|
currentMesh.geometry.dispose();
|
|
currentMesh.material.dispose();
|
|
}
|
|
|
|
loader.load(
|
|
`../../stanfordRecon/happy_recon/${config.file}`,
|
|
function(geometry) {
|
|
geometry.computeVertexNormals();
|
|
|
|
const material = materials[currentMode]();
|
|
currentMesh = new THREE.Mesh(geometry, material);
|
|
currentMesh.scale.set(config.scale, config.scale, config.scale);
|
|
|
|
geometry.center();
|
|
currentMesh.position.y = -0.1;
|
|
currentMesh.castShadow = true;
|
|
currentMesh.receiveShadow = true;
|
|
|
|
scene.add(currentMesh);
|
|
|
|
document.getElementById('vertex-count').textContent =
|
|
geometry.attributes.position.count.toLocaleString();
|
|
document.getElementById('face-count').textContent =
|
|
geometry.index ? (geometry.index.count / 3).toLocaleString() : 'N/A';
|
|
|
|
document.getElementById('loading').style.display = 'none';
|
|
},
|
|
function(progress) {
|
|
if (progress.lengthComputable) {
|
|
const pct = Math.round(progress.loaded / progress.total * 100);
|
|
document.getElementById('loading-text').textContent =
|
|
`${config.size} - ${pct}%`;
|
|
}
|
|
},
|
|
function(error) {
|
|
console.error(error);
|
|
document.getElementById('loading-text').textContent = '加载失败';
|
|
}
|
|
);
|
|
}
|
|
|
|
// ========== 切换材质 ==========
|
|
function setMode(mode) {
|
|
currentMode = mode;
|
|
|
|
document.querySelectorAll('#controls button').forEach(btn => {
|
|
btn.classList.remove('active');
|
|
});
|
|
document.getElementById(`btn-${mode}`).classList.add('active');
|
|
|
|
if (currentMesh) {
|
|
currentMesh.material.dispose();
|
|
currentMesh.material = materials[mode]();
|
|
}
|
|
}
|
|
|
|
// ========== 地面 ==========
|
|
const planeGeometry = new THREE.PlaneGeometry(5, 5);
|
|
const planeMaterial = new THREE.MeshStandardMaterial({
|
|
color: 0x1a1a1a,
|
|
roughness: 0.8
|
|
});
|
|
const plane = new THREE.Mesh(planeGeometry, planeMaterial);
|
|
plane.rotation.x = -Math.PI / 2;
|
|
plane.position.y = -0.2;
|
|
plane.receiveShadow = true;
|
|
scene.add(plane);
|
|
|
|
// ========== 窗口调整 ==========
|
|
window.addEventListener('resize', () => {
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
camera.updateProjectionMatrix();
|
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
});
|
|
|
|
// ========== 动画 ==========
|
|
function animate() {
|
|
requestAnimationFrame(animate);
|
|
controls.update();
|
|
renderer.render(scene, camera);
|
|
}
|
|
|
|
// 初始化
|
|
loadQuality('res3');
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html>
|