Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>3D Model Generator</title> | |
| <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/build/three.min.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/controls/OrbitControls.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/loaders/GLTFLoader.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/export/GLTFExporter.js"></script> | |
| <style> | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| body { | |
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| min-height: 100vh; | |
| display: flex; | |
| flex-direction: column; | |
| } | |
| .header { | |
| background: rgba(255, 255, 255, 0.95); | |
| backdrop-filter: blur(10px); | |
| padding: 1rem 2rem; | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1); | |
| } | |
| .logo { | |
| display: flex; | |
| align-items: center; | |
| gap: 0.5rem; | |
| } | |
| .logo-icon { | |
| width: 32px; | |
| height: 32px; | |
| background: linear-gradient(45deg, #667eea, #764ba2); | |
| border-radius: 50%; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| color: white; | |
| font-weight: bold; | |
| } | |
| .logo-text { | |
| font-size: 1.2rem; | |
| font-weight: 600; | |
| color: #333; | |
| } | |
| .anycoder-link { | |
| color: #667eea; | |
| text-decoration: none; | |
| font-size: 0.9rem; | |
| display: flex; | |
| align-items: center; | |
| gap: 0.3rem; | |
| } | |
| .anycoder-link:hover { | |
| text-decoration: underline; | |
| } | |
| .main-content { | |
| flex: 1; | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| justify-content: center; | |
| padding: 2rem; | |
| gap: 2rem; | |
| } | |
| .container { | |
| background: rgba(255, 255, 255, 0.95); | |
| backdrop-filter: blur(10px); | |
| border-radius: 16px; | |
| padding: 2rem; | |
| width: 100%; | |
| max-width: 800px; | |
| box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1); | |
| } | |
| .input-section { | |
| display: flex; | |
| gap: 1rem; | |
| margin-bottom: 2rem; | |
| } | |
| .input-field { | |
| flex: 1; | |
| padding: 1rem; | |
| border: 2px solid #e0e0e0; | |
| border-radius: 8px; | |
| font-size: 1rem; | |
| transition: all 0.3s ease; | |
| } | |
| .input-field:focus { | |
| outline: none; | |
| border-color: #667eea; | |
| box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); | |
| } | |
| .generate-btn { | |
| background: linear-gradient(45deg, #667eea, #764ba2); | |
| color: white; | |
| border: none; | |
| padding: 1rem 2rem; | |
| border-radius: 8px; | |
| font-size: 1rem; | |
| font-weight: 600; | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| white-space: nowrap; | |
| } | |
| .generate-btn:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3); | |
| } | |
| .generate-btn:active { | |
| transform: translateY(0); | |
| } | |
| .model-container { | |
| width: 100%; | |
| height: 400px; | |
| background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); | |
| border-radius: 12px; | |
| position: relative; | |
| overflow: hidden; | |
| } | |
| .loading-overlay { | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 100%; | |
| background: rgba(255, 255, 255, 0.9); | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| flex-direction: column; | |
| gap: 1rem; | |
| z-index: 10; | |
| } | |
| .spinner { | |
| width: 50px; | |
| height: 50px; | |
| border: 4px solid rgba(102, 126, 234, 0.2); | |
| border-top-color: #667eea; | |
| border-radius: 50%; | |
| animation: spin 1s linear infinite; | |
| } | |
| @keyframes spin { | |
| to { transform: rotate(360deg); } | |
| } | |
| .loading-text { | |
| color: #667eea; | |
| font-size: 1rem; | |
| font-weight: 500; | |
| } | |
| .controls { | |
| display: flex; | |
| justify-content: center; | |
| gap: 1rem; | |
| margin-top: 1rem; | |
| } | |
| .control-btn { | |
| padding: 0.75rem 1.5rem; | |
| border: 2px solid #e0e0e0; | |
| background: white; | |
| border-radius: 8px; | |
| font-weight: 500; | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| } | |
| .control-btn:hover { | |
| border-color: #667eea; | |
| color: #667eea; | |
| } | |
| .footer { | |
| background: rgba(255, 255, 255, 0.95); | |
| backdrop-filter: blur(10px); | |
| padding: 1rem; | |
| text-align: center; | |
| color: #666; | |
| font-size: 0.9rem; | |
| } | |
| @media (max-width: 768px) { | |
| .header { | |
| padding: 1rem; | |
| } | |
| .input-section { | |
| flex-direction: column; | |
| } | |
| .model-container { | |
| height: 300px; | |
| } | |
| .container { | |
| padding: 1.5rem; | |
| } | |
| } | |
| @media (max-width: 480px) { | |
| .main-content { | |
| padding: 1rem; | |
| } | |
| .model-container { | |
| height: 250px; | |
| } | |
| .generate-btn { | |
| padding: 0.75rem 1.5rem; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <header class="header"> | |
| <div class="logo"> | |
| <div class="logo-icon">🎯</div> | |
| <span class="logo-text">3D Model Generator</span> | |
| </div> | |
| <a href="https://huggingface.co/spaces/akhaliq/anycoder" class="anycoder-link" target="_blank"> | |
| Built with anycoder | |
| </a> | |
| </header> | |
| <main class="main-content"> | |
| <div class="container"> | |
| <div class="input-section"> | |
| <input type="text" class="input-field" id="model-input" placeholder="Enter object name (e.g., soccer ball)"> | |
| <button class="generate-btn" id="generate-btn">Generate 3D Model</button> | |
| </div> | |
| <div class="model-container"> | |
| <div class="loading-overlay" id="loading-overlay"> | |
| <div class="spinner"></div> | |
| <div class="loading-text">Generating 3D model...</div> | |
| </div> | |
| <canvas id="model-canvas"></canvas> | |
| </div> | |
| <div class="controls"> | |
| <button class="control-btn" id="export-btn">Export GLB</button> | |
| </div> | |
| </div> | |
| </main> | |
| <footer class="footer"> | |
| © 2024 3D Model Generator. All rights reserved. | |
| </footer> | |
| <script> | |
| // Scene setup | |
| const scene = new THREE.Scene(); | |
| scene.background = new THREE.Color(0xf5f7fa); | |
| // Camera setup | |
| const camera = new THREE.PerspectiveCamera(75, 1, 0.1, 1000); | |
| camera.position.set(0, 0, 5); | |
| // Renderer setup | |
| const renderer = new THREE.WebGLRenderer({ | |
| canvas: document.getElementById('model-canvas'), | |
| antialias: true, | |
| alpha: true | |
| }); | |
| renderer.setSize(800, 400); | |
| renderer.setPixelRatio(window.devicePixelRatio); | |
| // Lighting | |
| const ambientLight = new THREE.AmbientLight(0xffffff, 0.5); | |
| scene.add(ambientLight); | |
| const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8); | |
| directionalLight.position.set(1, 1, 1); | |
| scene.add(directionalLight); | |
| // Orbit controls | |
| const controls = new THREE.OrbitControls(camera, renderer.domElement); | |
| controls.enableDamping = true; | |
| controls.dampingFactor = 0.05; | |
| // Grid helper | |
| const gridHelper = new THREE.GridHelper(10, 10); | |
| scene.add(gridHelper); | |
| // Axes helper | |
| const axesHelper = new THREE.AxesHelper(3); | |
| scene.add(axesHelper); | |
| // Animation loop | |
| function animate() { | |
| requestAnimationFrame(animate); | |
| controls.update(); | |
| renderer.render(scene, camera); | |
| } | |
| // Handle window resize | |
| function handleResize() { | |
| const container = document.querySelector('.model-container'); | |
| const width = container.clientWidth; | |
| const height = container.clientHeight; | |
| camera.aspect = width / height; | |
| camera.updateProjectionMatrix(); | |
| renderer.setSize(width, height); | |
| } | |
| // Initialize | |
| window.addEventListener('resize', handleResize); | |
| handleResize(); | |
| animate(); | |
| // Generate button click handler | |
| document.getElementById('generate-btn').addEventListener('click', function() { | |
| const input = document.getElementById('model-input').value.trim(); | |
| if (!input) return; | |
| // Show loading overlay | |
| document.getElementById('loading-overlay').style.display = 'flex'; | |
| // Simulate generation process | |
| setTimeout(() => { | |
| generateModel(input); | |
| document.getElementById('loading-overlay').style.display = 'none'; | |
| }, 2000); | |
| }); | |
| // Export button click handler | |
| document.getElementById('export-btn').addEventListener('click', function() { | |
| exportModel(); | |
| }); | |
| // Generate model function | |
| function generateModel(name) { | |
| // Clear existing model | |
| const existingModel = scene.getObjectByName('generated-model'); | |
| if (existingModel) { | |
| scene.remove(existingModel); | |
| } | |
| // Create a simple sphere as placeholder | |
| const geometry = new THREE.SphereGeometry(1, 32, 32); | |
| const material = new THREE.MeshStandardMaterial({ | |
| color: 0xffff00, | |
| roughness: 0.2, | |
| metalness: 0.5 | |
| }); | |
| const sphere = new THREE.Mesh(geometry, material); | |
| sphere.name = 'generated-model'; | |
| sphere.position.set(0, 0, 0); | |
| scene.add(sphere); | |
| // Add some texture based on input | |
| if (name.toLowerCase().includes('soccer') || name.toLowerCase().includes('ball')) { | |
| // Create a simple soccer ball pattern | |
| const textureLoader = new THREE.TextureLoader(); | |
| const texture = textureLoader.load('data:image/svg+xml;base64,' + btoa(` | |
| <svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"> | |
| <defs> | |
| <pattern id="hexagon" patternUnits="userSpaceOnUse" width="20" height="17.32"> | |
| <polygon points="10,0 20,5.77 20,11.55 10,17.32 0,11.55 0,5.77" fill="black"/> | |
| </pattern> | |
| </defs> | |
| <rect width="100" height="100" fill="white"/> | |
| <rect width="100" height="100" fill="url(#hexagon)" opacity="0.3"/> | |
| </svg> | |
| `)); | |
| material.map = texture; | |
| material.needsUpdate = true; | |
| } | |
| } | |
| // Export model function | |
| function exportModel() { | |
| const model = scene.getObjectByName('generated-model'); | |
| if (!model) { | |
| alert('No model to export. Please generate a model first.'); | |
| return; | |
| } | |
| const exporter = new THREE.GLTFExporter(); | |
| exporter.parse( | |
| model, | |
| function (gltf) { | |
| const blob = new Blob([JSON.stringify(gltf)], { type: 'application/json' }); | |
| const url = URL.createObjectURL(blob); | |
| const a = document.createElement('a'); | |
| a.href = url; | |
| a.download = 'model.glb'; | |
| document.body.appendChild(a); | |
| a.click(); | |
| document.body.removeChild(a); | |
| URL.revokeObjectURL(url); | |
| }, | |
| { binary: true } | |
| ); | |
| } | |
| // Initialize with a default model | |
| generateModel('soccer ball'); | |
| </script> | |
| </body> | |
| </html> |