Download script.js from Kdkdhdhfdk/soliddream-3d-modeler: direct link, hf CLI and curl.
- Browser
- Download file 3.82 kB
-
https://huggingface.co/spaces/Kdkdhdhfdk/soliddream-3d-modeler/resolve/main/script.js
- Command line
-
hf download hf://spaces/Kdkdhdhfdk/soliddream-3d-modeler/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Kdkdhdhfdk/soliddream-3d-modeler/resolve/main/script.js
3.82 kB
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialisation de la scène Three.js | |
| const scene = new THREE.Scene(); | |
| scene.background = new THREE.Color(0xe9e9e9); | |
| // Configuration du rendu | |
| const renderer = new THREE.WebGLRenderer({ antialias: true }); | |
| renderer.setPixelRatio(window.devicePixelRatio); | |
| renderer.setSize(window.innerWidth - 550, window.innerHeight - 60); | |
| document.getElementById('render-container').appendChild(renderer.domElement); | |
| // Configuration de la caméra | |
| const camera = new THREE.PerspectiveCamera(75, (window.innerWidth - 550) / (window.innerHeight - 60), 0.1, 1000); | |
| camera.position.set(5, 5, 5); | |
| // Contrôles de la caméra | |
| const controls = new THREE.OrbitControls(camera, renderer.domElement); | |
| controls.enableDamping = true; | |
| controls.dampingFactor = 0.05; | |
| // Lumière | |
| 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); | |
| // Grille | |
| const gridHelper = new THREE.GridHelper(20, 20); | |
| scene.add(gridHelper); | |
| // Axes | |
| const axesHelper = new THREE.AxesHelper(5); | |
| scene.add(axesHelper); | |
| // Animation | |
| function animate() { | |
| requestAnimationFrame(animate); | |
| controls.update(); | |
| renderer.render(scene, camera); | |
| } | |
| animate(); | |
| // Redimensionnement | |
| window.addEventListener('resize', function() { | |
| camera.aspect = (window.innerWidth - 550) / (window.innerHeight - 60); | |
| camera.updateProjectionMatrix(); | |
| renderer.setSize(window.innerWidth - 550, window.innerHeight - 60); | |
| }); | |
| // Gestion des boutons de formes | |
| document.querySelectorAll('.shape-btn').forEach(button => { | |
| button.addEventListener('click', function() { | |
| const shapeType = this.getAttribute('data-shape'); | |
| let geometry; | |
| switch(shapeType) { | |
| case 'cube': | |
| geometry = new THREE.BoxGeometry(1, 1, 1); | |
| break; | |
| case 'sphere': | |
| geometry = new THREE.SphereGeometry(0.5, 32, 32); | |
| break; | |
| case 'cylinder': | |
| geometry = new THREE.CylinderGeometry(0.5, 0.5, 1, 32); | |
| break; | |
| case 'cone': | |
| geometry = new THREE.ConeGeometry(0.5, 1, 32); | |
| break; | |
| } | |
| const material = new THREE.MeshStandardMaterial({ | |
| color: Math.random() * 0xffffff, | |
| metalness: 0.2, | |
| roughness: 0.7 | |
| }); | |
| const mesh = new THREE.Mesh(geometry, material); | |
| scene.add(mesh); | |
| // Ajout à l'historique | |
| addToHistory(`Création: ${shapeType}`); | |
| }); | |
| }); | |
| // Fonction pour ajouter à l'historique | |
| function addToHistory(action) { | |
| const historyList = document.getElementById('history-list'); | |
| const li = document.createElement('li'); | |
| li.textContent = action; | |
| historyList.appendChild(li); | |
| } | |
| // Bouton Nouveau | |
| document.getElementById('new-model').addEventListener('click', function() { | |
| // Suppression de tous les objets sauf les aides | |
| scene.children.forEach(object => { | |
| if (!(object instanceof THREE.GridHelper) && | |
| !(object instanceof THREE.AxesHelper) && | |
| !(object instanceof THREE.Light)) { | |
| scene.remove(object); | |
| } | |
| }); | |
| addToHistory('Nouvelle scène créée'); | |
| }); | |
| }); |