|
<!DOCTYPE html> |
|
<html lang="en"> |
|
|
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>Edit3D-Bench Visualization</title> |
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script> |
|
<script src="https://cdn.jsdelivr.net/npm/three/examples/js/loaders/GLTFLoader.js"></script> |
|
<script src="https://cdn.jsdelivr.net/npm/three/examples/js/loaders/PLYLoader.js"></script> |
|
<script src="https://cdn.jsdelivr.net/npm/three/examples/js/controls/OrbitControls.js"></script> |
|
<script src="nav-module.js"></script> |
|
<style> |
|
* { |
|
margin: 0; |
|
padding: 0; |
|
box-sizing: border-box; |
|
} |
|
|
|
body { |
|
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; |
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); |
|
min-height: 100vh; |
|
color: #333; |
|
line-height: 1.6; |
|
} |
|
|
|
.container { |
|
max-width: 1800px; |
|
margin: 0 auto; |
|
background: rgba(255, 255, 255, 0.95); |
|
backdrop-filter: blur(10px); |
|
border-radius: 20px; |
|
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1); |
|
overflow: hidden; |
|
margin-top: 20px; |
|
margin-bottom: 20px; |
|
} |
|
|
|
.header { |
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); |
|
color: white; |
|
padding: 40px 30px; |
|
text-align: center; |
|
position: relative; |
|
overflow: hidden; |
|
} |
|
|
|
.header::before { |
|
content: ''; |
|
position: absolute; |
|
top: 0; |
|
left: 0; |
|
right: 0; |
|
bottom: 0; |
|
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="white" opacity="0.1"/><circle cx="75" cy="75" r="1" fill="white" opacity="0.1"/><circle cx="50" cy="10" r="0.5" fill="white" opacity="0.1"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>'); |
|
opacity: 0.3; |
|
} |
|
|
|
.header h1 { |
|
margin: 0; |
|
font-size: 2.5em; |
|
font-weight: 700; |
|
position: relative; |
|
z-index: 1; |
|
letter-spacing: -0.02em; |
|
} |
|
|
|
.header p { |
|
margin: 10px 0 0 0; |
|
font-size: 1.1em; |
|
opacity: 0.9; |
|
position: relative; |
|
z-index: 1; |
|
} |
|
|
|
.navigation { |
|
background: #f8fafc; |
|
padding: 25px 30px; |
|
border-bottom: 1px solid #e2e8f0; |
|
} |
|
|
|
.nav-button { |
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); |
|
color: white; |
|
border: none; |
|
padding: 12px 24px; |
|
margin: 0 8px; |
|
border-radius: 12px; |
|
cursor: pointer; |
|
font-size: 16px; |
|
font-weight: 500; |
|
transition: all 0.3s ease; |
|
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3); |
|
} |
|
|
|
.nav-button:hover { |
|
transform: translateY(-2px); |
|
box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4); |
|
} |
|
|
|
.nav-button:disabled { |
|
background: #cbd5e1; |
|
cursor: not-allowed; |
|
transform: none; |
|
box-shadow: none; |
|
} |
|
|
|
.top-controls { |
|
display: flex; |
|
align-items: center; |
|
justify-content: center; |
|
gap: 30px; |
|
margin-bottom: 20px; |
|
flex-wrap: wrap; |
|
} |
|
|
|
.control-group { |
|
display: flex; |
|
align-items: center; |
|
gap: 12px; |
|
background: white; |
|
padding: 12px 20px; |
|
border-radius: 12px; |
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05); |
|
} |
|
|
|
.control-group label { |
|
font-weight: 600; |
|
color: #475569; |
|
font-size: 14px; |
|
} |
|
|
|
.control-group select, |
|
.control-group input { |
|
padding: 10px 16px; |
|
border-radius: 8px; |
|
border: 2px solid #e2e8f0; |
|
font-size: 14px; |
|
transition: all 0.3s ease; |
|
background: white; |
|
} |
|
|
|
.control-group select:focus, |
|
.control-group input:focus { |
|
outline: none; |
|
border-color: #667eea; |
|
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); |
|
} |
|
|
|
.control-group input { |
|
width: 200px; |
|
} |
|
|
|
.search-btn { |
|
background: linear-gradient(135deg, #10b981 0%, #059669 100%); |
|
color: white; |
|
border: none; |
|
padding: 10px 20px; |
|
border-radius: 8px; |
|
cursor: pointer; |
|
font-size: 14px; |
|
font-weight: 500; |
|
transition: all 0.3s ease; |
|
} |
|
|
|
.search-btn:hover { |
|
transform: translateY(-1px); |
|
box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3); |
|
} |
|
|
|
.search-btn:disabled { |
|
background: #cbd5e1; |
|
cursor: not-allowed; |
|
transform: none; |
|
box-shadow: none; |
|
} |
|
|
|
.navigation-controls { |
|
display: flex; |
|
align-items: center; |
|
justify-content: center; |
|
gap: 20px; |
|
margin-top: 15px; |
|
} |
|
|
|
.page-input-group { |
|
display: flex; |
|
align-items: center; |
|
gap: 10px; |
|
background: white; |
|
padding: 8px 16px; |
|
border-radius: 12px; |
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05); |
|
} |
|
|
|
.page-input-group input { |
|
width: 80px; |
|
padding: 8px 12px; |
|
border: 2px solid #e2e8f0; |
|
border-radius: 8px; |
|
text-align: center; |
|
font-size: 14px; |
|
} |
|
|
|
.page-input-group input:focus { |
|
outline: none; |
|
border-color: #667eea; |
|
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); |
|
} |
|
|
|
.progress-info { |
|
font-size: 16px; |
|
color: #64748b; |
|
font-weight: 500; |
|
background: white; |
|
padding: 10px 20px; |
|
border-radius: 12px; |
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05); |
|
} |
|
|
|
.content { |
|
padding: 30px; |
|
} |
|
|
|
.sample-info { |
|
background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%); |
|
padding: 25px; |
|
border-radius: 16px; |
|
margin-bottom: 30px; |
|
border-left: 4px solid #667eea; |
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05); |
|
} |
|
|
|
.sample-info h2 { |
|
margin: 0 0 15px 0; |
|
color: #1e293b; |
|
font-size: 1.5em; |
|
font-weight: 700; |
|
} |
|
|
|
.prompt-info { |
|
background: rgba(255, 193, 7, 0.1); |
|
padding: 15px; |
|
border-radius: 12px; |
|
margin: 15px 0; |
|
border-left: 3px solid #ffc107; |
|
font-size: 15px; |
|
line-height: 1.6; |
|
} |
|
|
|
.media-grid { |
|
display: grid; |
|
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); |
|
gap: 25px; |
|
margin-top: 30px; |
|
} |
|
|
|
.media-item { |
|
background: white; |
|
border-radius: 16px; |
|
padding: 20px; |
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08); |
|
position: relative; |
|
transition: all 0.3s ease; |
|
border: 1px solid #f1f5f9; |
|
} |
|
|
|
.media-item:hover { |
|
transform: translateY(-4px); |
|
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12); |
|
} |
|
|
|
.media-item h3 { |
|
margin: 0 0 15px 0; |
|
color: #1e293b; |
|
font-size: 1.1em; |
|
font-weight: 600; |
|
line-height: 1.4; |
|
} |
|
|
|
.download-btn { |
|
position: absolute; |
|
top: 15px; |
|
right: 15px; |
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); |
|
color: white; |
|
border: none; |
|
border-radius: 50%; |
|
width: 36px; |
|
height: 36px; |
|
cursor: pointer; |
|
display: flex; |
|
align-items: center; |
|
justify-content: center; |
|
font-size: 16px; |
|
transition: all 0.3s ease; |
|
z-index: 10; |
|
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3); |
|
} |
|
|
|
.download-btn:hover { |
|
transform: scale(1.1); |
|
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4); |
|
} |
|
|
|
.download-btn:active { |
|
transform: scale(0.95); |
|
} |
|
|
|
.image-container { |
|
width: 100%; |
|
height: auto; |
|
display: flex; |
|
align-items: center; |
|
justify-content: center; |
|
background: #f8fafc; |
|
border-radius: 12px; |
|
overflow: hidden; |
|
min-height: 200px; |
|
} |
|
|
|
.image-container img { |
|
max-width: 100%; |
|
max-height: 100%; |
|
object-fit: contain; |
|
border-radius: 8px; |
|
} |
|
|
|
.viewer-3d { |
|
width: 100%; |
|
height: 350px; |
|
border: 2px solid #e2e8f0; |
|
border-radius: 12px; |
|
background: #f8fafc; |
|
overflow: hidden; |
|
} |
|
|
|
.loading { |
|
text-align: center; |
|
padding: 60px; |
|
color: #64748b; |
|
font-size: 18px; |
|
} |
|
|
|
.loading h3 { |
|
margin-bottom: 15px; |
|
color: #1e293b; |
|
} |
|
|
|
.error { |
|
color: #dc2626; |
|
background: #fef2f2; |
|
padding: 15px; |
|
border-radius: 12px; |
|
margin: 15px 0; |
|
border-left: 4px solid #dc2626; |
|
font-weight: 500; |
|
} |
|
|
|
@media (max-width: 768px) { |
|
.top-controls { |
|
flex-direction: column; |
|
gap: 15px; |
|
} |
|
|
|
.control-group { |
|
width: 100%; |
|
justify-content: space-between; |
|
} |
|
|
|
.media-grid { |
|
grid-template-columns: 1fr; |
|
} |
|
|
|
.header h1 { |
|
font-size: 2em; |
|
} |
|
} |
|
</style> |
|
</head> |
|
|
|
<body> |
|
<div class="container"> |
|
<div class="header"> |
|
<h1>Edit3D-Bench Visualization</h1> |
|
<p>Interactive 3D Model Editing Dataset Explorer</p> |
|
</div> |
|
|
|
<div class="navigation"> |
|
<div class="top-controls"> |
|
<div class="control-group"> |
|
<label for="datasetSelect">Dataset:</label> |
|
<select id="datasetSelect"> |
|
<option value="GSO">GSO</option> |
|
<option value="PartObjaverse-Tiny">PartObjaverse-Tiny</option> |
|
</select> |
|
</div> |
|
|
|
<div class="control-group"> |
|
<label for="modelSearch">Model Search:</label> |
|
<input type="text" id="modelSearch" placeholder="Enter model name..." /> |
|
<button id="searchBtn" class="search-btn">Search</button> |
|
</div> |
|
</div> |
|
|
|
<div class="navigation-controls"> |
|
<button class="nav-button" id="prevBtn">Previous</button> |
|
<div class="page-input-group"> |
|
<label for="pageInput">Go to:</label> |
|
<input type="number" id="pageInput" placeholder="Page" min="1" /> |
|
<button class="nav-button" id="goToBtn">Go</button> |
|
</div> |
|
<span class="progress-info" id="progressInfo">Loading...</span> |
|
<button class="nav-button" id="nextBtn">Next</button> |
|
</div> |
|
</div> |
|
|
|
<div class="content"> |
|
<div id="loadingDiv" class="loading"> |
|
<h3>Loading data...</h3> |
|
</div> |
|
|
|
<div id="contentDiv" style="display: none;"> |
|
<div class="sample-info" id="sampleInfo"> |
|
|
|
</div> |
|
|
|
<div class="media-grid" id="mediaGrid"> |
|
|
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
<script type="module"> |
|
class DataVisualizer { |
|
constructor() { |
|
this.datasets = { |
|
'GSO': { data: null, root: 'data/GSO' }, |
|
'PartObjaverse-Tiny': { data: null, root: 'data/PartObjaverse-Tiny' } |
|
}; |
|
this.currentDataset = 'GSO'; |
|
this.currentSampleIndex = 0; |
|
this.totalSamples = 0; |
|
this.currentModelData = null; |
|
this.currentPromptIndex = 1; |
|
|
|
this.init(); |
|
} |
|
|
|
async init() { |
|
await this.loadDatasets(); |
|
this.setupEventListeners(); |
|
this.displayCurrentSample(); |
|
} |
|
|
|
async loadDatasets() { |
|
try { |
|
const metadataResponse = await fetch('data/metadata.json'); |
|
const metadata = await metadataResponse.json(); |
|
|
|
this.datasets.GSO.data = metadata.filter(item => item.dataset === 'GSO'); |
|
this.datasets['PartObjaverse-Tiny'].data = metadata.filter(item => item.dataset === 'PartObjaverse-Tiny'); |
|
|
|
this.updateTotalSamples(); |
|
console.log('Data loaded successfully from metadata.json'); |
|
} catch (error) { |
|
console.error('Failed to load data:', error); |
|
document.getElementById('loadingDiv').innerHTML = |
|
'<div class="error">Failed to load data: ' + error.message + '</div>'; |
|
} |
|
} |
|
|
|
updateTotalSamples() { |
|
const data = this.datasets[this.currentDataset].data; |
|
this.totalSamples = data ? data.length * 3 : 0; |
|
} |
|
|
|
setupEventListeners() { |
|
document.getElementById('datasetSelect').addEventListener('change', (e) => { |
|
this.currentDataset = e.target.value; |
|
this.currentSampleIndex = 0; |
|
this.updateTotalSamples(); |
|
this.displayCurrentSample(); |
|
}); |
|
|
|
document.getElementById('prevBtn').addEventListener('click', () => { |
|
this.navigateSample(-1); |
|
}); |
|
|
|
document.getElementById('nextBtn').addEventListener('click', () => { |
|
this.navigateSample(1); |
|
}); |
|
|
|
document.getElementById('searchBtn').addEventListener('click', () => { |
|
this.searchModel(); |
|
}); |
|
|
|
document.getElementById('goToBtn').addEventListener('click', () => { |
|
this.goToPage(); |
|
}); |
|
|
|
document.getElementById('modelSearch').addEventListener('keypress', (e) => { |
|
if (e.key === 'Enter') { |
|
this.searchModel(); |
|
} |
|
}); |
|
|
|
document.getElementById('pageInput').addEventListener('keypress', (e) => { |
|
if (e.key === 'Enter') { |
|
this.goToPage(); |
|
} |
|
}); |
|
} |
|
|
|
navigateSample(direction) { |
|
if (this.totalSamples === 0) return; |
|
|
|
this.currentSampleIndex += direction; |
|
if (this.currentSampleIndex < 0) this.currentSampleIndex = this.totalSamples - 1; |
|
if (this.currentSampleIndex >= this.totalSamples) this.currentSampleIndex = 0; |
|
|
|
this.displayCurrentSample(); |
|
} |
|
|
|
goToPage() { |
|
const pageInput = document.getElementById('pageInput'); |
|
const pageNumber = parseInt(pageInput.value); |
|
|
|
if (isNaN(pageNumber) || pageNumber < 1 || pageNumber > this.totalSamples) { |
|
alert(`Please enter a valid page number between 1 and ${this.totalSamples}`); |
|
return; |
|
} |
|
|
|
this.currentSampleIndex = pageNumber - 1; |
|
this.displayCurrentSample(); |
|
pageInput.value = ''; |
|
} |
|
|
|
searchModel() { |
|
const searchTerm = document.getElementById('modelSearch').value.trim(); |
|
if (!searchTerm) { |
|
alert('Please enter a model name'); |
|
return; |
|
} |
|
|
|
const data = this.datasets[this.currentDataset].data; |
|
if (!data) return; |
|
|
|
const modelIndex = data.findIndex(item => |
|
item.source_model.toLowerCase().includes(searchTerm.toLowerCase()) |
|
); |
|
|
|
if (modelIndex === -1) { |
|
alert(`No model found containing "${searchTerm}"`); |
|
return; |
|
} |
|
|
|
this.currentSampleIndex = modelIndex * 3; |
|
this.displayCurrentSample(); |
|
document.getElementById('modelSearch').value = ''; |
|
} |
|
|
|
getCurrentModelAndPrompt() { |
|
const data = this.datasets[this.currentDataset].data; |
|
if (!data || data.length === 0) return null; |
|
|
|
const modelIndex = Math.floor(this.currentSampleIndex / 3); |
|
const promptIndex = (this.currentSampleIndex % 3) + 1; |
|
|
|
return { |
|
modelData: data[modelIndex], |
|
promptIndex: promptIndex |
|
}; |
|
} |
|
|
|
displayCurrentSample() { |
|
const current = this.getCurrentModelAndPrompt(); |
|
if (!current) { |
|
document.getElementById('loadingDiv').style.display = 'block'; |
|
document.getElementById('contentDiv').style.display = 'none'; |
|
return; |
|
} |
|
|
|
this.currentModelData = current.modelData; |
|
this.currentPromptIndex = current.promptIndex; |
|
const dataRoot = this.datasets[this.currentDataset].root; |
|
|
|
document.getElementById('progressInfo').textContent = |
|
`${this.currentSampleIndex + 1} / ${this.totalSamples}`; |
|
|
|
document.getElementById('prevBtn').disabled = false; |
|
document.getElementById('nextBtn').disabled = false; |
|
|
|
this.displaySampleInfo(); |
|
this.displayMediaContent(dataRoot); |
|
|
|
document.getElementById('loadingDiv').style.display = 'none'; |
|
document.getElementById('contentDiv').style.display = 'block'; |
|
} |
|
|
|
displaySampleInfo() { |
|
const model = this.currentModelData; |
|
const promptKey = `prompt_${this.currentPromptIndex}`; |
|
const promptText = model[promptKey]; |
|
|
|
const infoHtml = ` |
|
<h2>Model ID: ${model.source_model}</h2> |
|
<div class="prompt-info"> |
|
<strong>Source Prompt:</strong> ${model.source_prompt}<br> |
|
<strong>Edit Prompt ${this.currentPromptIndex}:</strong> ${promptText} |
|
</div> |
|
`; |
|
document.getElementById('sampleInfo').innerHTML = infoHtml; |
|
} |
|
|
|
displayMediaContent(dataRoot) { |
|
const model = this.currentModelData; |
|
const basePath = `${dataRoot}/${model.source_model}`; |
|
const promptDir = `prompt_${this.currentPromptIndex}`; |
|
|
|
const mediaItems = [ |
|
{ |
|
title: `Original Image (Prompt ${this.currentPromptIndex})`, |
|
type: 'image', |
|
path: `${basePath}/${promptDir}/2d_render.png` |
|
}, |
|
{ |
|
title: `Image Inpainting Visualization (Prompt ${this.currentPromptIndex})`, |
|
type: 'image', |
|
path: `${basePath}/${promptDir}/2d_visual.png` |
|
}, |
|
{ |
|
title: `Inpainted Image (Prompt ${this.currentPromptIndex})`, |
|
type: 'image', |
|
path: `${basePath}/${promptDir}/2d_edit.png` |
|
}, |
|
{ |
|
title: 'Source Model (GLB)', |
|
type: '3d-model', |
|
path: `${basePath}/source_model/model.glb` |
|
}, |
|
{ |
|
title: 'Edit Region (GLB)', |
|
type: '3d-model', |
|
path: `${basePath}/${promptDir}/3d_edit_region.glb` |
|
}, |
|
{ |
|
title: `Source Model + Edit Region (Prompt ${this.currentPromptIndex})`, |
|
type: '3d-combined', |
|
paths: [ |
|
`${basePath}/source_model/model.glb`, |
|
`${basePath}/${promptDir}/3d_edit_region.glb` |
|
] |
|
}, |
|
]; |
|
|
|
const mediaGrid = document.getElementById('mediaGrid'); |
|
mediaGrid.innerHTML = ''; |
|
|
|
mediaItems.forEach((item, index) => { |
|
const mediaDiv = document.createElement('div'); |
|
mediaDiv.className = 'media-item'; |
|
mediaDiv.innerHTML = `<h3>${item.title}</h3>`; |
|
|
|
const downloadBtn = document.createElement('button'); |
|
downloadBtn.className = 'download-btn'; |
|
downloadBtn.innerHTML = '⬇'; |
|
downloadBtn.title = 'Download file'; |
|
|
|
if (item.type === '3d-combined') { |
|
downloadBtn.onclick = () => this.downloadFile(item.paths[1]); |
|
} else { |
|
downloadBtn.onclick = () => this.downloadFile(item.path); |
|
} |
|
|
|
mediaDiv.appendChild(downloadBtn); |
|
|
|
if (item.type === 'image') { |
|
const imageContainer = document.createElement('div'); |
|
imageContainer.className = 'image-container'; |
|
|
|
const img = document.createElement('img'); |
|
img.src = item.path; |
|
img.onerror = () => { |
|
imageContainer.innerHTML = '<div style="color: #dc2626; padding: 20px;">Image loading failed</div>'; |
|
}; |
|
|
|
imageContainer.appendChild(img); |
|
mediaDiv.appendChild(imageContainer); |
|
} else if (item.type === '3d-model' || item.type === '3d-ply') { |
|
const viewer = document.createElement('div'); |
|
viewer.className = 'viewer-3d'; |
|
viewer.id = `viewer-${index}`; |
|
mediaDiv.appendChild(viewer); |
|
|
|
setTimeout(() => { |
|
this.load3DContent(viewer.id, item.path, item.type); |
|
}, 100 * index); |
|
} else if (item.type === '3d-combined') { |
|
const viewer = document.createElement('div'); |
|
viewer.className = 'viewer-3d'; |
|
viewer.id = `viewer-${index}`; |
|
mediaDiv.appendChild(viewer); |
|
|
|
setTimeout(() => { |
|
this.load3DCombinedContent(viewer.id, item.paths); |
|
}, 100 * index); |
|
} |
|
|
|
mediaGrid.appendChild(mediaDiv); |
|
}); |
|
} |
|
|
|
load3DContent(containerId, path, type) { |
|
const container = document.getElementById(containerId); |
|
if (!container) return; |
|
|
|
const scene = new THREE.Scene(); |
|
scene.background = new THREE.Color(0xf8fafc); |
|
|
|
let voxelColor = 0xff6b35; |
|
if (path.includes('coarse_voxels')) { |
|
voxelColor = 0x4CAF50; |
|
} else if (path.includes('precise_voxels')) { |
|
voxelColor = 0x2196F3; |
|
} |
|
|
|
const camera = new THREE.PerspectiveCamera( |
|
75, |
|
container.clientWidth / container.clientHeight, |
|
0.1, |
|
1000 |
|
); |
|
|
|
const renderer = new THREE.WebGLRenderer({ antialias: true }); |
|
renderer.setSize(container.clientWidth, container.clientHeight); |
|
renderer.setClearColor(0xffffff); |
|
renderer.outputEncoding = THREE.sRGBEncoding; |
|
renderer.physicallyCorrectLights = true; |
|
|
|
container.appendChild(renderer.domElement); |
|
|
|
const directionalLight = new THREE.DirectionalLight(0xffffff, 1); |
|
directionalLight.position.set(5, 10, 7); |
|
scene.add(directionalLight); |
|
|
|
const lightIntensity = 30; |
|
const lightDistance = 100; |
|
|
|
const directions = [ |
|
[10, 0, 0], [-10, 0, 0], [0, 10, 0], [0, -10, 0], [0, 0, 10], [0, 0, -10], |
|
]; |
|
|
|
directions.forEach((dir, index) => { |
|
const pointLight = new THREE.PointLight( |
|
0xffffff, |
|
lightIntensity, |
|
lightDistance |
|
); |
|
pointLight.position.set(...dir); |
|
pointLight.castShadow = true; |
|
scene.add(pointLight); |
|
pointLight.name = `PointLight_${index}`; |
|
}); |
|
|
|
const controls = new THREE.OrbitControls(camera, renderer.domElement); |
|
controls.enableDamping = true; |
|
|
|
if (type === '3d-model') { |
|
const loader = new THREE.GLTFLoader(); |
|
loader.load( |
|
path, |
|
(gltf) => { |
|
const model = gltf.scene; |
|
scene.add(model); |
|
|
|
const box = new THREE.Box3().setFromObject(model); |
|
const center = box.getCenter(new THREE.Vector3()); |
|
const size = box.getSize(new THREE.Vector3()); |
|
|
|
const maxDim = Math.max(size.x, size.y, size.z); |
|
camera.position.copy(center); |
|
camera.position.z += maxDim * 1.2; |
|
controls.target.copy(center); |
|
controls.update(); |
|
}, |
|
undefined, |
|
(error) => { |
|
container.innerHTML = '<div style="color: #dc2626; padding: 20px;">3D model loading failed</div>'; |
|
} |
|
); |
|
} else if (type === '3d-ply') { |
|
const loader = new THREE.PLYLoader(); |
|
loader.load( |
|
path, |
|
(geometry) => { |
|
|
|
const hasFaces = geometry.index !== null && geometry.index.count > 0; |
|
|
|
if (hasFaces) { |
|
|
|
const hasColors = geometry.attributes.color !== undefined; |
|
|
|
let material; |
|
if (hasColors) { |
|
|
|
material = new THREE.MeshLambertMaterial({ |
|
vertexColors: true, |
|
side: THREE.DoubleSide |
|
}); |
|
} else { |
|
|
|
material = new THREE.MeshLambertMaterial({ |
|
color: voxelColor, |
|
side: THREE.DoubleSide |
|
}); |
|
} |
|
|
|
const mesh = new THREE.Mesh(geometry, material); |
|
scene.add(mesh); |
|
|
|
|
|
geometry.computeBoundingBox(); |
|
const box = geometry.boundingBox; |
|
const center = box.getCenter(new THREE.Vector3()); |
|
const size = box.getSize(new THREE.Vector3()); |
|
|
|
const maxDim = Math.max(size.x, size.y, size.z); |
|
camera.position.copy(center); |
|
camera.position.z += maxDim * 1.2; |
|
controls.target.copy(center); |
|
controls.update(); |
|
} else { |
|
|
|
const hasColors = geometry.attributes.color !== undefined; |
|
|
|
const material = new THREE.PointsMaterial({ |
|
size: 0.01, |
|
vertexColors: hasColors, |
|
color: hasColors ? 0xffffff : voxelColor, |
|
opacity: 0.95, |
|
transparent: true, |
|
sizeAttenuation: true |
|
}); |
|
|
|
const points = new THREE.Points(geometry, material); |
|
scene.add(points); |
|
|
|
geometry.computeBoundingBox(); |
|
const box = geometry.boundingBox; |
|
const center = box.getCenter(new THREE.Vector3()); |
|
const size = box.getSize(new THREE.Vector3()); |
|
|
|
const maxDim = Math.max(size.x, size.y, size.z); |
|
camera.position.copy(center); |
|
camera.position.z += maxDim * 1.2; |
|
controls.target.copy(center); |
|
controls.update(); |
|
} |
|
}, |
|
undefined, |
|
(error) => { |
|
container.innerHTML = '<div style="color: #dc2626; padding: 20px;">PLY file loading failed</div>'; |
|
} |
|
); |
|
} |
|
|
|
function animate() { |
|
requestAnimationFrame(animate); |
|
controls.update(); |
|
renderer.render(scene, camera); |
|
} |
|
animate(); |
|
|
|
const resizeObserver = new ResizeObserver(() => { |
|
const width = container.clientWidth; |
|
const height = container.clientHeight; |
|
camera.aspect = width / height; |
|
camera.updateProjectionMatrix(); |
|
renderer.setSize(width, height); |
|
}); |
|
resizeObserver.observe(container); |
|
} |
|
|
|
async downloadFile(url) { |
|
|
|
const urlParts = url.split('.'); |
|
const extension = urlParts[urlParts.length - 1]; |
|
|
|
|
|
const pathParts = url.split('/'); |
|
const originalFilename = pathParts[pathParts.length - 1]; |
|
const basename = originalFilename.replace(`.${extension}`, ''); |
|
|
|
|
|
const modelId = this.currentModelData ? this.currentModelData.source_model : 'unknown'; |
|
|
|
|
|
const fullFilename = `${modelId}_${basename}.${extension}`; |
|
|
|
|
|
console.log('Download file info:', { |
|
url: url, |
|
modelId: modelId, |
|
basename: basename, |
|
extension: extension, |
|
fullFilename: fullFilename |
|
}); |
|
|
|
try { |
|
|
|
const response = await fetch(url); |
|
if (!response.ok) { |
|
throw new Error(`HTTP error! status: ${response.status}`); |
|
} |
|
|
|
const blob = await response.blob(); |
|
|
|
|
|
const blobUrl = window.URL.createObjectURL(blob); |
|
|
|
|
|
const link = document.createElement('a'); |
|
link.href = blobUrl; |
|
link.download = fullFilename; |
|
|
|
|
|
console.log('Download link created:', { |
|
href: link.href, |
|
download: link.download, |
|
fullFilename: fullFilename |
|
}); |
|
|
|
|
|
document.body.appendChild(link); |
|
link.click(); |
|
document.body.removeChild(link); |
|
|
|
|
|
setTimeout(() => { |
|
window.URL.revokeObjectURL(blobUrl); |
|
}, 100); |
|
|
|
} catch (error) { |
|
console.error('Download failed:', error); |
|
|
|
const link = document.createElement('a'); |
|
link.href = url; |
|
link.download = fullFilename; |
|
link.target = '_blank'; |
|
|
|
document.body.appendChild(link); |
|
link.click(); |
|
document.body.removeChild(link); |
|
} |
|
} |
|
|
|
load3DCombinedContent(containerId, paths) { |
|
const container = document.getElementById(containerId); |
|
if (!container) return; |
|
|
|
const scene = new THREE.Scene(); |
|
scene.background = new THREE.Color(0xf8fafc); |
|
|
|
const camera = new THREE.PerspectiveCamera( |
|
75, |
|
container.clientWidth / container.clientHeight, |
|
0.1, |
|
1000 |
|
); |
|
|
|
const renderer = new THREE.WebGLRenderer({ antialias: true }); |
|
renderer.setSize(container.clientWidth, container.clientHeight); |
|
renderer.setClearColor(0xffffff); |
|
renderer.outputEncoding = THREE.sRGBEncoding; |
|
renderer.physicallyCorrectLights = true; |
|
|
|
container.appendChild(renderer.domElement); |
|
|
|
const directionalLight = new THREE.DirectionalLight(0xffffff, 1); |
|
directionalLight.position.set(5, 10, 7); |
|
scene.add(directionalLight); |
|
|
|
const lightIntensity = 30; |
|
const lightDistance = 100; |
|
|
|
const directions = [ |
|
[10, 0, 0], [-10, 0, 0], [0, 10, 0], [0, -10, 0], [0, 0, 10], [0, 0, -10], |
|
]; |
|
|
|
directions.forEach((dir, index) => { |
|
const pointLight = new THREE.PointLight( |
|
0xffffff, |
|
lightIntensity, |
|
lightDistance |
|
); |
|
pointLight.position.set(...dir); |
|
pointLight.castShadow = true; |
|
scene.add(pointLight); |
|
pointLight.name = `PointLight_${index}`; |
|
}); |
|
|
|
const controls = new THREE.OrbitControls(camera, renderer.domElement); |
|
controls.enableDamping = true; |
|
|
|
const loader = new THREE.GLTFLoader(); |
|
let loadedModels = 0; |
|
const totalModels = paths.length; |
|
const allModels = []; |
|
|
|
paths.forEach((path, index) => { |
|
loader.load( |
|
path, |
|
(gltf) => { |
|
const model = gltf.scene; |
|
|
|
if (path.includes('3d_edit_region.glb')) { |
|
model.traverse((child) => { |
|
if (child.isMesh) { |
|
child.material = new THREE.MeshPhongMaterial({ |
|
color: 0xcccccc, |
|
transparent: true, |
|
opacity: 0.7 |
|
}); |
|
} |
|
}); |
|
} |
|
|
|
scene.add(model); |
|
allModels.push(model); |
|
loadedModels++; |
|
|
|
if (loadedModels === totalModels) { |
|
const box = new THREE.Box3(); |
|
allModels.forEach(model => { |
|
box.expandByObject(model); |
|
}); |
|
|
|
const center = box.getCenter(new THREE.Vector3()); |
|
const size = box.getSize(new THREE.Vector3()); |
|
const maxDim = Math.max(size.x, size.y, size.z); |
|
|
|
camera.position.copy(center); |
|
camera.position.z += maxDim * 1.2; |
|
controls.target.copy(center); |
|
controls.update(); |
|
} |
|
}, |
|
undefined, |
|
(error) => { |
|
console.error(`Model loading failed: ${path}`, error); |
|
loadedModels++; |
|
if (loadedModels === totalModels) { |
|
container.innerHTML = '<div style="color: #dc2626; padding: 20px;">Some 3D models failed to load</div>'; |
|
} |
|
} |
|
); |
|
}); |
|
|
|
function animate() { |
|
requestAnimationFrame(animate); |
|
controls.update(); |
|
renderer.render(scene, camera); |
|
} |
|
animate(); |
|
|
|
const resizeObserver = new ResizeObserver(() => { |
|
const width = container.clientWidth; |
|
const height = container.clientHeight; |
|
camera.aspect = width / height; |
|
camera.updateProjectionMatrix(); |
|
renderer.setSize(width, height); |
|
}); |
|
resizeObserver.observe(container); |
|
} |
|
} |
|
|
|
document.addEventListener('DOMContentLoaded', () => { |
|
new DataVisualizer(); |
|
}); |
|
</script> |
|
</body> |
|
|
|
</html> |