193 lines
6.1 KiB
HTML
193 lines
6.1 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-TW">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Pure JavaScript RenderingCanvas Demo</title>
|
||
<script src="https://cdn.jsdelivr.net/npm/@microsoft/signalr@latest/dist/browser/signalr.min.js"></script>
|
||
<style>
|
||
body {
|
||
margin: 0;
|
||
padding: 20px;
|
||
font-family: Arial, sans-serif;
|
||
background-color: #f0f0f0;
|
||
}
|
||
|
||
.container {
|
||
max-width: 1200px;
|
||
margin: 0 auto;
|
||
background-color: white;
|
||
border-radius: 8px;
|
||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||
padding: 20px;
|
||
}
|
||
|
||
h1 {
|
||
color: #333;
|
||
text-align: center;
|
||
}
|
||
|
||
.info-box {
|
||
padding: 10px;
|
||
background-color: #e3f2fd;
|
||
color: #1565c0;
|
||
border: 1px solid #90caf9;
|
||
border-radius: 4px;
|
||
margin: 10px 0;
|
||
}
|
||
|
||
.controls {
|
||
margin: 20px 0;
|
||
display: flex;
|
||
gap: 10px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.controls button {
|
||
padding: 10px 20px;
|
||
border: none;
|
||
border-radius: 4px;
|
||
background-color: #2196F3;
|
||
color: white;
|
||
cursor: pointer;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.controls button:hover {
|
||
background-color: #1976D2;
|
||
}
|
||
|
||
#canvas-container {
|
||
height: 600px;
|
||
border: 1px solid #ddd;
|
||
margin: 20px 0;
|
||
position: relative;
|
||
}
|
||
|
||
.status {
|
||
padding: 10px;
|
||
margin: 10px 0;
|
||
border-radius: 4px;
|
||
background-color: #f5f5f5;
|
||
}
|
||
|
||
.status.connected {
|
||
background-color: #c8e6c9;
|
||
color: #2e7d32;
|
||
}
|
||
|
||
.status.error {
|
||
background-color: #ffcdd2;
|
||
color: #c62828;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="container">
|
||
<h1>Pure JavaScript RenderingCanvas Demo</h1>
|
||
|
||
<div class="info-box">
|
||
<strong>使用說明:</strong>
|
||
<br>這是使用純 JavaScript 類的 RenderingCanvas 示例
|
||
<br><strong>滑鼠:</strong>左鍵拖動旋轉,右鍵拖動平移,滾輪縮放
|
||
<br><strong>鍵盤:</strong>F1-F4切換視圖,方向鍵旋轉,PageUp/PageDown縮放,Home重置視圖
|
||
<br><strong>觸控:</strong>單指拖動平移,雙指捏合縮放,雙指旋轉,三指上下滑動縮放
|
||
</div>
|
||
|
||
<div id="status" class="status">
|
||
連接狀態:未連接
|
||
</div>
|
||
|
||
<div class="controls">
|
||
<button onclick="setView('front')">前視圖</button>
|
||
<button onclick="setView('back')">後視圖</button>
|
||
<button onclick="setView('left')">左視圖</button>
|
||
<button onclick="setView('right')">右視圖</button>
|
||
<button onclick="setView('top')">頂視圖</button>
|
||
<button onclick="setView('bottom')">底視圖</button>
|
||
<button onclick="setView('isometric')">等角視圖</button>
|
||
<button onclick="setView('home')">主視圖</button>
|
||
</div>
|
||
|
||
<div id="canvas-container"></div>
|
||
</div>
|
||
|
||
<script src="/_content/hi.webapi/disp/rendering-canvas.js"></script>
|
||
<script>
|
||
let renderingCanvas = null;
|
||
|
||
// Initialize when page loads
|
||
window.addEventListener('load', () => {
|
||
// Create RenderingCanvas instance
|
||
renderingCanvas = new RenderingCanvas('canvas-container', {
|
||
autoConnect: true,
|
||
width: 800,
|
||
height: 600
|
||
});
|
||
|
||
// Set up event handlers
|
||
renderingCanvas.on('connected', () => {
|
||
updateStatus('已連接到服務器', 'connected');
|
||
});
|
||
|
||
renderingCanvas.on('disconnected', () => {
|
||
updateStatus('連接已斷開', '');
|
||
});
|
||
|
||
renderingCanvas.on('serverInitialized', (sessionId) => {
|
||
console.log('Server initialized with session:', sessionId);
|
||
loadTestObjects(sessionId);
|
||
});
|
||
|
||
renderingCanvas.on('error', (error) => {
|
||
updateStatus(`錯誤:${error}`, 'error');
|
||
console.error('RenderingCanvas error:', error);
|
||
});
|
||
|
||
renderingCanvas.on('viewChanged', (viewType) => {
|
||
console.log('View changed to:', viewType);
|
||
});
|
||
});
|
||
|
||
// Clean up when page unloads
|
||
window.addEventListener('beforeunload', () => {
|
||
if (renderingCanvas) {
|
||
renderingCanvas.destroy();
|
||
}
|
||
});
|
||
|
||
// Helper functions
|
||
function updateStatus(message, className) {
|
||
const statusEl = document.getElementById('status');
|
||
statusEl.textContent = `連接狀態:${message}`;
|
||
statusEl.className = 'status ' + className;
|
||
}
|
||
|
||
function setView(viewType) {
|
||
if (renderingCanvas) {
|
||
renderingCanvas.setView(viewType);
|
||
}
|
||
}
|
||
|
||
async function loadTestObjects(sessionId) {
|
||
try {
|
||
const response = await fetch(`/api/rendering/test-objects/${sessionId}`, {
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/json'
|
||
}
|
||
});
|
||
|
||
if (response.ok) {
|
||
console.log('Test objects loaded successfully');
|
||
} else {
|
||
const errorText = await response.text();
|
||
console.error(`Failed to load test objects: ${response.status} - ${errorText}`);
|
||
}
|
||
} catch (err) {
|
||
console.error(`Error loading test objects: ${err}`);
|
||
}
|
||
}
|
||
</script>
|
||
</body>
|
||
</html> |