Skip to content

Commit 5405c83

Browse files
authored
Add files via upload
1 parent 834fbca commit 5405c83

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

3d-world-js/app.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function main() {
2+
//scene camera render
3+
const canvas = document.querySelector('#c')
4+
5+
const fov = 50
6+
//const aspect = 2
7+
const aspect = canvas.clientWidth / canvas.clientHeight
8+
const near = 0.1
9+
const far = 2000 //default
10+
11+
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far)
12+
camera.position.z = 1
13+
14+
const renderer = new THREE.WebGLRenderer({
15+
canvas
16+
})
17+
new THREE.OrbitControls(camera, canvas)
18+
19+
const scene = new THREE.Scene()
20+
const loader = new THREE.TextureLoader()
21+
const texture = loader.load('https://threejs.org/manual/examples/resources/images/equirectangularmaps/tears_of_steel_bridge_2k.jpg', () => {
22+
const rt = new THREE.WebGLCubeRenderTarget(texture.image.height)
23+
rt.fromEquirectangularTexture(renderer, texture)
24+
scene.background = rt.texture
25+
})
26+
27+
function render() {
28+
const width = canvas.clientWidth
29+
const height = canvas.clientHeight
30+
camera.aspect = width / height
31+
camera.updateProjectionMatrix()
32+
renderer.setSize(width, height)
33+
renderer.render(scene, camera)
34+
requestAnimationFrame(render)
35+
}
36+
requestAnimationFrame(render)
37+
38+
}
39+
40+
main()

3d-world-js/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="style.css">
8+
<title>Document</title>
9+
</head>
10+
<body>
11+
<canvas id="c"></canvas>
12+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
13+
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
14+
<script src="app.js"></script>
15+
</body>
16+
</html>

3d-world-js/style.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
html,
2+
body {
3+
height: 100%;
4+
margin: 0;
5+
}
6+
7+
#c {
8+
width: 100%;
9+
height: 100%;
10+
display: block;
11+
}

0 commit comments

Comments
 (0)