Spaces:
Running
Running
Add 2 files
Browse files- README.md +7 -5
- index.html +229 -19
README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: static
|
7 |
pinned: false
|
|
|
|
|
8 |
---
|
9 |
|
10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: rotate-cube
|
3 |
+
emoji: 🐳
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: red
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
+
tags:
|
9 |
+
- deepsite
|
10 |
---
|
11 |
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
@@ -1,19 +1,229 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Three.js 3D Cube Demo</title>
|
7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
9 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.min.js"></script>
|
10 |
+
<style>
|
11 |
+
body {
|
12 |
+
margin: 0;
|
13 |
+
overflow: hidden;
|
14 |
+
font-family: 'Inter', sans-serif;
|
15 |
+
}
|
16 |
+
#info {
|
17 |
+
position: absolute;
|
18 |
+
top: 20px;
|
19 |
+
left: 20px;
|
20 |
+
color: white;
|
21 |
+
background: rgba(0,0,0,0.7);
|
22 |
+
padding: 15px;
|
23 |
+
border-radius: 10px;
|
24 |
+
z-index: 100;
|
25 |
+
pointer-events: none;
|
26 |
+
}
|
27 |
+
#loading {
|
28 |
+
position: absolute;
|
29 |
+
top: 0;
|
30 |
+
left: 0;
|
31 |
+
width: 100%;
|
32 |
+
height: 100%;
|
33 |
+
background: #000;
|
34 |
+
display: flex;
|
35 |
+
justify-content: center;
|
36 |
+
align-items: center;
|
37 |
+
z-index: 1000;
|
38 |
+
color: white;
|
39 |
+
font-size: 24px;
|
40 |
+
}
|
41 |
+
canvas {
|
42 |
+
display: block;
|
43 |
+
}
|
44 |
+
.control-panel {
|
45 |
+
position: absolute;
|
46 |
+
bottom: 20px;
|
47 |
+
left: 20px;
|
48 |
+
background: rgba(0,0,0,0.7);
|
49 |
+
padding: 15px;
|
50 |
+
border-radius: 10px;
|
51 |
+
color: white;
|
52 |
+
z-index: 100;
|
53 |
+
}
|
54 |
+
.control-panel label {
|
55 |
+
display: block;
|
56 |
+
margin-bottom: 5px;
|
57 |
+
}
|
58 |
+
.control-panel input {
|
59 |
+
width: 100%;
|
60 |
+
margin-bottom: 10px;
|
61 |
+
}
|
62 |
+
</style>
|
63 |
+
</head>
|
64 |
+
<body class="bg-gray-900">
|
65 |
+
<div id="loading">Loading Three.js scene...</div>
|
66 |
+
<div id="info">
|
67 |
+
<h1 class="text-xl font-bold mb-2">Three.js 3D Cube Demo</h1>
|
68 |
+
<p>Drag to rotate the view</p>
|
69 |
+
<p>Scroll to zoom in/out</p>
|
70 |
+
</div>
|
71 |
+
<div class="control-panel">
|
72 |
+
<label for="rotationSpeed">Rotation Speed</label>
|
73 |
+
<input type="range" id="rotationSpeed" min="0" max="0.1" step="0.001" value="0.01">
|
74 |
+
|
75 |
+
<label for="cubeColor">Cube Color</label>
|
76 |
+
<input type="color" id="cubeColor" value="#ff6347">
|
77 |
+
|
78 |
+
<button id="addCube" class="mt-2 bg-blue-500 hover:bg-blue-700 text-white font-bold py-1 px-3 rounded">
|
79 |
+
Add Random Cube
|
80 |
+
</button>
|
81 |
+
</div>
|
82 |
+
|
83 |
+
<script>
|
84 |
+
// Wait for everything to load
|
85 |
+
window.addEventListener('load', init);
|
86 |
+
|
87 |
+
function init() {
|
88 |
+
// Hide loading screen
|
89 |
+
document.getElementById('loading').style.display = 'none';
|
90 |
+
|
91 |
+
// Create scene
|
92 |
+
const scene = new THREE.Scene();
|
93 |
+
scene.background = new THREE.Color(0x111122);
|
94 |
+
|
95 |
+
// Create camera
|
96 |
+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
97 |
+
camera.position.z = 5;
|
98 |
+
|
99 |
+
// Create renderer
|
100 |
+
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
101 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
102 |
+
renderer.shadowMap.enabled = true;
|
103 |
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
104 |
+
document.body.appendChild(renderer.domElement);
|
105 |
+
|
106 |
+
// Add orbit controls
|
107 |
+
const controls = new THREE.OrbitControls(camera, renderer.domElement);
|
108 |
+
controls.enableDamping = true;
|
109 |
+
controls.dampingFactor = 0.05;
|
110 |
+
|
111 |
+
// Add lights
|
112 |
+
const ambientLight = new THREE.AmbientLight(0x404040);
|
113 |
+
scene.add(ambientLight);
|
114 |
+
|
115 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
|
116 |
+
directionalLight.position.set(5, 10, 7);
|
117 |
+
directionalLight.castShadow = true;
|
118 |
+
directionalLight.shadow.mapSize.width = 2048;
|
119 |
+
directionalLight.shadow.mapSize.height = 2048;
|
120 |
+
scene.add(directionalLight);
|
121 |
+
|
122 |
+
// Add hemisphere light for more natural lighting
|
123 |
+
const hemisphereLight = new THREE.HemisphereLight(0xffffbb, 0x080820, 0.5);
|
124 |
+
scene.add(hemisphereLight);
|
125 |
+
|
126 |
+
// Create floor
|
127 |
+
const floorGeometry = new THREE.PlaneGeometry(20, 20);
|
128 |
+
const floorMaterial = new THREE.MeshStandardMaterial({
|
129 |
+
color: 0x333333,
|
130 |
+
roughness: 0.8,
|
131 |
+
metalness: 0.2
|
132 |
+
});
|
133 |
+
const floor = new THREE.Mesh(floorGeometry, floorMaterial);
|
134 |
+
floor.rotation.x = -Math.PI / 2;
|
135 |
+
floor.receiveShadow = true;
|
136 |
+
scene.add(floor);
|
137 |
+
|
138 |
+
// Create initial cube
|
139 |
+
let cubeColor = 0xff6347;
|
140 |
+
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
|
141 |
+
const cubeMaterial = new THREE.MeshStandardMaterial({
|
142 |
+
color: cubeColor,
|
143 |
+
roughness: 0.4,
|
144 |
+
metalness: 0.6
|
145 |
+
});
|
146 |
+
const cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
|
147 |
+
cube.castShadow = true;
|
148 |
+
cube.position.y = 0.5;
|
149 |
+
scene.add(cube);
|
150 |
+
|
151 |
+
// Array to store additional cubes
|
152 |
+
const cubes = [cube];
|
153 |
+
|
154 |
+
// Handle window resize
|
155 |
+
window.addEventListener('resize', () => {
|
156 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
157 |
+
camera.updateProjectionMatrix();
|
158 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
159 |
+
});
|
160 |
+
|
161 |
+
// UI controls
|
162 |
+
const rotationSpeedControl = document.getElementById('rotationSpeed');
|
163 |
+
const cubeColorControl = document.getElementById('cubeColor');
|
164 |
+
const addCubeButton = document.getElementById('addCube');
|
165 |
+
|
166 |
+
let rotationSpeed = parseFloat(rotationSpeedControl.value);
|
167 |
+
|
168 |
+
rotationSpeedControl.addEventListener('input', (e) => {
|
169 |
+
rotationSpeed = parseFloat(e.target.value);
|
170 |
+
});
|
171 |
+
|
172 |
+
cubeColorControl.addEventListener('input', (e) => {
|
173 |
+
cubeColor = new THREE.Color(e.target.value);
|
174 |
+
cube.material.color = cubeColor;
|
175 |
+
});
|
176 |
+
|
177 |
+
addCubeButton.addEventListener('click', () => {
|
178 |
+
const size = Math.random() * 0.5 + 0.3;
|
179 |
+
const geometry = new THREE.BoxGeometry(size, size, size);
|
180 |
+
const material = new THREE.MeshStandardMaterial({
|
181 |
+
color: Math.random() * 0xffffff,
|
182 |
+
roughness: Math.random(),
|
183 |
+
metalness: Math.random()
|
184 |
+
});
|
185 |
+
|
186 |
+
const newCube = new THREE.Mesh(geometry, material);
|
187 |
+
newCube.castShadow = true;
|
188 |
+
|
189 |
+
// Random position above floor
|
190 |
+
newCube.position.x = (Math.random() - 0.5) * 10;
|
191 |
+
newCube.position.z = (Math.random() - 0.5) * 10;
|
192 |
+
newCube.position.y = size / 2;
|
193 |
+
|
194 |
+
// Random rotation
|
195 |
+
newCube.rotation.x = Math.random() * Math.PI;
|
196 |
+
newCube.rotation.y = Math.random() * Math.PI;
|
197 |
+
|
198 |
+
scene.add(newCube);
|
199 |
+
cubes.push(newCube);
|
200 |
+
});
|
201 |
+
|
202 |
+
// Animation loop
|
203 |
+
function animate() {
|
204 |
+
requestAnimationFrame(animate);
|
205 |
+
|
206 |
+
// Rotate cubes
|
207 |
+
cubes.forEach((c, i) => {
|
208 |
+
if (i === 0) {
|
209 |
+
// Main cube rotates on all axes
|
210 |
+
c.rotation.x += rotationSpeed;
|
211 |
+
c.rotation.y += rotationSpeed * 0.7;
|
212 |
+
c.rotation.z += rotationSpeed * 0.3;
|
213 |
+
} else {
|
214 |
+
// Other cubes rotate more slowly
|
215 |
+
c.rotation.y += rotationSpeed * 0.3;
|
216 |
+
}
|
217 |
+
});
|
218 |
+
|
219 |
+
// Required if controls.enableDamping or controls.autoRotate are set to true
|
220 |
+
controls.update();
|
221 |
+
|
222 |
+
renderer.render(scene, camera);
|
223 |
+
}
|
224 |
+
|
225 |
+
animate();
|
226 |
+
}
|
227 |
+
</script>
|
228 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - <a href="https://enzostvs-deepsite.hf.space?remix=wenju/rotate-cube" style="color: #fff;text-decoration: underline;" target="_blank" >🧬 Remix</a></p></body>
|
229 |
+
</html>
|