Spaces:
Running
Running
Make it a game engine, with basic shapes to add, lights, and JS scripts with tutorial in comments. - Initial Deployment
Browse files- README.md +7 -5
- index.html +208 -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: webgame-engine
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: yellow
|
| 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,208 @@
|
|
| 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>3D Cube with Sun Flare</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<style>
|
| 9 |
+
.hidden { display: none; }
|
| 10 |
+
</style>
|
| 11 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
| 12 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.min.js"></script>
|
| 13 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/objects/Lensflare.min.js"></script>
|
| 14 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/GLTFLoader.min.js"></script>
|
| 15 |
+
<style>
|
| 16 |
+
body {
|
| 17 |
+
margin: 0;
|
| 18 |
+
overflow: hidden;
|
| 19 |
+
font-family: 'Inter', sans-serif;
|
| 20 |
+
}
|
| 21 |
+
canvas {
|
| 22 |
+
display: block;
|
| 23 |
+
}
|
| 24 |
+
#info {
|
| 25 |
+
position: absolute;
|
| 26 |
+
bottom: 20px;
|
| 27 |
+
width: 100%;
|
| 28 |
+
text-align: center;
|
| 29 |
+
color: white;
|
| 30 |
+
background-color: rgba(0,0,0,0.5);
|
| 31 |
+
padding: 10px;
|
| 32 |
+
border-radius: 8px;
|
| 33 |
+
max-width: 500px;
|
| 34 |
+
margin: 0 auto;
|
| 35 |
+
left: 0;
|
| 36 |
+
right: 0;
|
| 37 |
+
}
|
| 38 |
+
#loading {
|
| 39 |
+
position: fixed;
|
| 40 |
+
top: 0;
|
| 41 |
+
left: 0;
|
| 42 |
+
width: 100%;
|
| 43 |
+
height: 100%;
|
| 44 |
+
background: rgba(0,0,0,0.8);
|
| 45 |
+
display: flex;
|
| 46 |
+
justify-content: center;
|
| 47 |
+
align-items: center;
|
| 48 |
+
color: white;
|
| 49 |
+
font-size: 24px;
|
| 50 |
+
z-index: 1000;
|
| 51 |
+
}
|
| 52 |
+
</style>
|
| 53 |
+
</head>
|
| 54 |
+
<body class="bg-gray-900">
|
| 55 |
+
<div id="loading">Loading 3D scene...</div>
|
| 56 |
+
<div id="info" class="hidden">
|
| 57 |
+
<p>Click and drag to rotate view</p>
|
| 58 |
+
<p>Scroll to zoom in/out</p>
|
| 59 |
+
</div>
|
| 60 |
+
|
| 61 |
+
<script>
|
| 62 |
+
// Wait for everything to load
|
| 63 |
+
window.addEventListener('load', init);
|
| 64 |
+
|
| 65 |
+
function init() {
|
| 66 |
+
// Hide loading screen
|
| 67 |
+
document.getElementById('loading').style.display = 'none';
|
| 68 |
+
document.getElementById('info').classList.remove('hidden');
|
| 69 |
+
|
| 70 |
+
// Scene setup
|
| 71 |
+
const scene = new THREE.Scene();
|
| 72 |
+
scene.background = new THREE.Color(0x87CEEB); // Sky blue skybox
|
| 73 |
+
scene.fog = new THREE.FogExp2(0x87CEEB, 0.005); // Less dense fog
|
| 74 |
+
|
| 75 |
+
// Camera setup
|
| 76 |
+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 77 |
+
camera.position.set(5, 5, 5);
|
| 78 |
+
|
| 79 |
+
// Renderer setup
|
| 80 |
+
const renderer = new THREE.WebGLRenderer({
|
| 81 |
+
antialias: true,
|
| 82 |
+
powerPreference: "high-performance"
|
| 83 |
+
});
|
| 84 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 85 |
+
renderer.shadowMap.enabled = true;
|
| 86 |
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
| 87 |
+
renderer.outputEncoding = THREE.sRGBEncoding;
|
| 88 |
+
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
| 89 |
+
renderer.toneMappingExposure = 1.0;
|
| 90 |
+
renderer.physicallyCorrectLights = true;
|
| 91 |
+
document.body.appendChild(renderer.domElement);
|
| 92 |
+
|
| 93 |
+
// Controls
|
| 94 |
+
const controls = new THREE.OrbitControls(camera, renderer.domElement);
|
| 95 |
+
controls.enableDamping = true;
|
| 96 |
+
controls.dampingFactor = 0.05;
|
| 97 |
+
|
| 98 |
+
// Available sample models from KhronosGroup/glTF-Sample-Models:
|
| 99 |
+
// - Duck: https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Duck/glTF/Duck.gltf
|
| 100 |
+
// - 2CylinderEngine: https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/2CylinderEngine/glTF/2CylinderEngine.gltf
|
| 101 |
+
// - Avocado: https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Avocado/glTF/Avocado.gltf
|
| 102 |
+
// - BarramundiFish: https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/BarramundiFish/glTF/BarramundiFish.gltf
|
| 103 |
+
// - BrainStem: https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/BrainStem/glTF/BrainStem.gltf
|
| 104 |
+
// - Buggy: https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Buggy/glTF/Buggy.gltf
|
| 105 |
+
// - CesiumMan: https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/CesiumMan/glTF/CesiumMan.gltf
|
| 106 |
+
// - Corset: https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Corset/glTF/Corset.gltf
|
| 107 |
+
// - FlightHelmet: https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/FlightHelmet/glTF/FlightHelmet.gltf
|
| 108 |
+
// - Lantern: https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Lantern/glTF/Lantern.gltf
|
| 109 |
+
// - MosquitoInAmber: https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/MosquitoInAmber/glTF/MosquitoInAmber.gltf
|
| 110 |
+
// - WaterBottle: https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/WaterBottle/glTF/WaterBottle.gltf
|
| 111 |
+
|
| 112 |
+
const loader = new THREE.GLTFLoader();
|
| 113 |
+
loader.load(
|
| 114 |
+
'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Avocado/glTF/Avocado.gltf',
|
| 115 |
+
(gltf) => {
|
| 116 |
+
const model = gltf.scene;
|
| 117 |
+
model.scale.set(0.5, 0.5, 0.5);
|
| 118 |
+
model.position.set(0, 0, 0);
|
| 119 |
+
model.rotation.y = Math.PI;
|
| 120 |
+
model.traverse((child) => {
|
| 121 |
+
if (child.isMesh) {
|
| 122 |
+
child.castShadow = true;
|
| 123 |
+
child.receiveShadow = true;
|
| 124 |
+
}
|
| 125 |
+
});
|
| 126 |
+
scene.add(model);
|
| 127 |
+
|
| 128 |
+
// Animation loop
|
| 129 |
+
function animate() {
|
| 130 |
+
requestAnimationFrame(animate);
|
| 131 |
+
|
| 132 |
+
// Rotate model slightly
|
| 133 |
+
model.rotation.y += 0.005;
|
| 134 |
+
|
| 135 |
+
// Update controls
|
| 136 |
+
controls.update();
|
| 137 |
+
|
| 138 |
+
// Render
|
| 139 |
+
renderer.render(scene, camera);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
animate();
|
| 143 |
+
},
|
| 144 |
+
undefined,
|
| 145 |
+
(error) => {
|
| 146 |
+
console.error('Error loading model:', error);
|
| 147 |
+
// Fallback to simple geometry if model fails
|
| 148 |
+
const geometry = new THREE.ConeGeometry(1, 2, 4);
|
| 149 |
+
const material = new THREE.MeshStandardMaterial({ color: 0x00ffff });
|
| 150 |
+
const cone = new THREE.Mesh(geometry, material);
|
| 151 |
+
scene.add(cone);
|
| 152 |
+
}
|
| 153 |
+
);
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
// Ambient light matching skybox
|
| 157 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 0.8);
|
| 158 |
+
scene.add(ambientLight);
|
| 159 |
+
|
| 160 |
+
// Sun light (directional)
|
| 161 |
+
const sunLight = new THREE.DirectionalLight(0xffffcc, 1.5);
|
| 162 |
+
sunLight.position.set(10, 15, 10);
|
| 163 |
+
sunLight.castShadow = true;
|
| 164 |
+
sunLight.shadow.mapSize.width = 4096;
|
| 165 |
+
sunLight.shadow.mapSize.height = 4096;
|
| 166 |
+
sunLight.shadow.camera.near = 0.5;
|
| 167 |
+
sunLight.shadow.camera.far = 50;
|
| 168 |
+
sunLight.shadow.camera.left = -15;
|
| 169 |
+
sunLight.shadow.camera.right = 15;
|
| 170 |
+
sunLight.shadow.camera.top = 15;
|
| 171 |
+
sunLight.shadow.camera.bottom = -15;
|
| 172 |
+
sunLight.shadow.bias = -0.0001;
|
| 173 |
+
scene.add(sunLight);
|
| 174 |
+
|
| 175 |
+
// Fill light
|
| 176 |
+
const fillLight = new THREE.DirectionalLight(0xccffff, 0.5);
|
| 177 |
+
fillLight.position.set(-10, 10, -10);
|
| 178 |
+
scene.add(fillLight);
|
| 179 |
+
|
| 180 |
+
// Back light
|
| 181 |
+
const backLight = new THREE.DirectionalLight(0xffffff, 0.3);
|
| 182 |
+
backLight.position.set(0, 5, -15);
|
| 183 |
+
scene.add(backLight);
|
| 184 |
+
|
| 185 |
+
// Lens flare effect
|
| 186 |
+
const textureLoader = new THREE.TextureLoader();
|
| 187 |
+
const textureFlare0 = textureLoader.load('https://threejs.org/examples/textures/lensflare/lensflare0.png');
|
| 188 |
+
const textureFlare3 = textureLoader.load('https://threejs.org/examples/textures/lensflare/lensflare3.png');
|
| 189 |
+
|
| 190 |
+
const lensflare = new THREE.Lensflare();
|
| 191 |
+
lensflare.addElement(new THREE.LensflareElement(textureFlare0, 700, 0, sunLight.color));
|
| 192 |
+
lensflare.addElement(new THREE.LensflareElement(textureFlare3, 60, 0.6));
|
| 193 |
+
lensflare.addElement(new THREE.LensflareElement(textureFlare3, 70, 0.7));
|
| 194 |
+
lensflare.addElement(new THREE.LensflareElement(textureFlare3, 120, 0.9));
|
| 195 |
+
lensflare.addElement(new THREE.LensflareElement(textureFlare3, 70, 1));
|
| 196 |
+
sunLight.add(lensflare);
|
| 197 |
+
|
| 198 |
+
// Window resize handler
|
| 199 |
+
window.addEventListener('resize', () => {
|
| 200 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 201 |
+
camera.updateProjectionMatrix();
|
| 202 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 203 |
+
});
|
| 204 |
+
|
| 205 |
+
}
|
| 206 |
+
</script>
|
| 207 |
+
<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=iCoderX/webgame-engine" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 208 |
+
</html>
|