-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
144 lines (124 loc) · 4.71 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zen</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="The Zen mode." />
<meta name="keywords" content="peace, zen mode, zen" />
<meta name="author" content="Joel Jolly" />
<script src="https://cdn.babylonjs.com/babylon.js"></script>
<style>
html,
body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#renderCanvas {
width: 100%;
height: 100%;
touch-action: none;
background-color: black
}
</style>
</head>
<body>
<canvas id="renderCanvas"></canvas>
</body>
<script>
// Create a new audio element
var audio = new Audio('Audio/Birds.mp3'); // Replace with the path to your audio file
// Set properties
audio.loop = true; // Loop the audio
audio.autoplay = true; // Start playing immediately
// Append the audio element to the body (optional)
document.body.appendChild(audio);
const cubeSize = 500;
var canvas = document.getElementById("renderCanvas");
var engine = new BABYLON.Engine(canvas, true, {
preserveDrawingBuffer: true, stencil: true, disableWebGL2Support: true
});
var scene = new BABYLON.Scene(engine);
//Create light
var light2 = new BABYLON.HemisphericLight('light1',
new BABYLON.Vector3(0, 1, 0), scene);
var light2 = new BABYLON.HemisphericLight('light1',
new BABYLON.Vector3(0, -1, 0), scene);
//Create an Arc Rotate Camera
var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI, 1.0, 110, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, true);
var skyBox = BABYLON.Mesh.CreateBox("skyBox", cubeSize, scene);
var cubeMaterial = new BABYLON.StandardMaterial("skyBoxMat", scene);
skyBox.material = cubeMaterial;
cubeMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
cubeMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
let images = [
"Images/image+107.jpg", //Front
"Images/image+108.jpg", //Left
"Images/image+109.jpg", //top
"Images/image+110.jpg", //bottom
"Images/image+112.jpg", //back
"Images/image+111.jpg"] //right
//front
var frontMaterial = new BABYLON.StandardMaterial("frontMaterial", scene);
frontMaterial.diffuseTexture = new BABYLON.Texture(images[0], scene);
frontMaterial.diffuseTexture.uScale = frontMaterial.diffuseTexture.vScale = -1;
frontMaterial.backFaceCulling = false
//back
var backMaterial = new BABYLON.StandardMaterial("backMaterial", scene);
backMaterial.diffuseTexture = new BABYLON.Texture(images[4], scene);
backMaterial.diffuseTexture.uScale = backMaterial.diffuseTexture.vScale = 1;
backMaterial.backFaceCulling = false
//left
var leftMaterial = new BABYLON.StandardMaterial("leftMaterial", scene);
leftMaterial.diffuseTexture = new BABYLON.Texture(images[1], scene);
leftMaterial.diffuseTexture.wAng = 0.5 * Math.PI;
leftMaterial.backFaceCulling = false
var rightMaterial = new BABYLON.StandardMaterial("rightMaterial", scene);
rightMaterial.diffuseTexture = new BABYLON.Texture(images[5], scene);
rightMaterial.diffuseTexture.wAng = 0.5 * Math.PI;
rightMaterial.backFaceCulling = false
//top
var topMaterial = new BABYLON.StandardMaterial("topMaterial", scene);
topMaterial.diffuseTexture = new BABYLON.Texture(images[2], scene);
topMaterial.diffuseTexture.wAng = -0.5 * Math.PI;
topMaterial.backFaceCulling = false
//bottom
var bottomMaterial = new BABYLON.StandardMaterial("bottomMaterial", scene);
bottomMaterial.diffuseTexture = new BABYLON.Texture(images[3], scene);
bottomMaterial.diffuseTexture.wAng = 0.5 * Math.PI;
bottomMaterial.diffuseTexture.uScale = 1;
bottomMaterial.backFaceCulling = false
//put into one
var multiMaterial = new BABYLON.MultiMaterial("cubetexture", scene);
multiMaterial.subMaterials.push(
frontMaterial, backMaterial,
leftMaterial, rightMaterial,
topMaterial, bottomMaterial);
//apply material
skyBox.subMeshes = [];
var verticesCount = skyBox.getTotalVertices();
skyBox.subMeshes.push(
new BABYLON.SubMesh(0, 0, verticesCount, 0, 6, skyBox),
new BABYLON.SubMesh(1, 1, verticesCount, 6, 6, skyBox),
new BABYLON.SubMesh(2, 2, verticesCount, 12, 6, skyBox),
new BABYLON.SubMesh(3, 3, verticesCount, 18, 6, skyBox),
new BABYLON.SubMesh(4, 4, verticesCount, 24, 6, skyBox),
new BABYLON.SubMesh(5, 5, verticesCount, 30, 6, skyBox));
skyBox.material = multiMaterial;
engine.runRenderLoop(() => {
if (scene && scene.activeCamera) {
scene.render();
}
});
// Resize
window.addEventListener("resize", () => {
engine.resize();
});
</script>
</html>