-
Notifications
You must be signed in to change notification settings - Fork 0
/
全景图.html
248 lines (240 loc) · 8.41 KB
/
全景图.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
</style>
<!--引入three.js三维引擎-->
<script src="http://www.yanhuangxueyuan.com/versions/threejsR92/build/three.js"></script>
<!-- 引入threejs扩展控件OrbitControls.js -->
<script src="http://www.yanhuangxueyuan.com/versions/threejsR92/examples/js/controls/OrbitControls.js"></script>
</head>
<body>
<script>
var scene = new THREE.Scene();
var box = new THREE.SphereGeometry(25, 50, 50);
var material = new THREE.MeshBasicMaterial({
color: 0xffffff,
side: THREE.BackSide,
});
var mesh = new THREE.Mesh(box, material);
scene.add(mesh);
var textureLoader = new THREE.TextureLoader();
var listener = new THREE.AudioListener();
var audio = new THREE.Audio(listener);
var texture = textureLoader.load('preller_drive_4k.hdr', function(obj) {
console.log(vm.loading);
vm.loading.close();
var audioLoader = new THREE.AudioLoader();
audioLoader.load('./音乐/琵琶语.mp3', function(AudioBuffer) {
audio.setBuffer(AudioBuffer);
audio.setLoop(true);
audio.setVolume(0.3);
audio.play()
});
render()
});
mesh.material.map = texture;
var width = window.innerWidth;
var height = window.innerHeight;
var k = width / height;
var camera = new THREE.PerspectiveCamera(60, width / height, 1, 1000);
camera.zoom = 1;
camera.updateProjectionMatrix();
camera.position.set(-0.87, 0.03, 0.4);
camera.lookAt(scene.position);
var renderer = new THREE.WebGLRenderer({
antialias: true,
});
renderer.setSize(width, height);
document.body.appendChild(renderer.domElement);
var clock = new THREE.Clock();
var FPS = 30;
var 刷新时间 = 1 / FPS;
var timeS = 0;
function render() {
requestAnimationFrame(render);
var 渲染间隔 = clock.getDelta();
timeS = timeS + 渲染间隔;
if (timeS > 刷新时间) {
renderer.render(scene, camera);
if (vm.rotateBoool) {
mesh.rotateY(0.002)
}
timeS = 0
}
}
render();
var controls = new THREE.OrbitControls(camera);
controls.enablePan = false;
var styleObjArr = path();
var vm = new Vue({
el: "#app",
data: {
loading: null,
styleArr: styleObjArr,
styleChoose: null,
posArr: null,
posChoose: null,
width: window.innerWidth,
height: window.innerHeight,
classPath: '中式/客餐厅',
path: '',
audioBoool: true,
ScreenBoool: true,
rotateBoool: true,
N: styleObjArr[0].children[0].jpgNameArr.length,
num: 1,
},
methods: {
audioClick: function() {
if (this.audioBoool) {
this.audioBoool = false;
audio.pause()
} else {
this.audioBoool = true;
audio.play()
}
},
ScreenClick: function() {
if (this.ScreenBoool) {
this.ScreenBoool = false;
requestFullScreen()
} else {
this.ScreenBoool = true;
exitFullscreen()
}
},
questionClick: function() {
this.$alert('按住左键不放上下左右拖动,可以旋转整个场景', '旋转操作', {})
},
rotateClick: function() {
if (this.rotateBoool) {
this.rotateBoool = false
} else {
this.rotateBoool = true
}
},
nextClick: function() {
if (this.num < this.N) {
this.num += 1
} else {
this.num = 1
}
},
upClick: function() {
if (this.num > 1) {
this.num -= 1
} else {
this.num = this.N
}
},
styleClick: function(styleObj) {
this.loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
this.num = 1;
this.styleChoose.styleObj.background = null;
this.posChoose.styleObj.background = null;
this.styleChoose = styleObj;
this.styleChoose.styleObj.background = '#409EFF';
this.posArr = this.styleChoose.children;
this.posChoose = this.posArr[0];
this.posArr[0].styleObj.background = '#409EFF';
this.N = this.posChoose.jpgNameArr.length;
this.classPath = this.styleChoose.name + '/' + this.posChoose.name;
this.path = this.classPath + '/' + this.posChoose.jpgNameArr[this.num - 1];
var texture = textureLoader.load('./风格/' + this.path, function(obj) {
vm.loading.close();
render()
});
mesh.material.map = texture
},
posClick: function(posObj) {
this.loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
this.num = 1;
this.posChoose.styleObj.background = null;
this.posChoose = posObj;
this.N = this.posChoose.jpgNameArr.length;
this.posChoose.styleObj.background = '#409EFF';
this.classPath = this.styleChoose.name + '/' + this.posChoose.name;
this.path = this.classPath + '/' + this.posChoose.jpgNameArr[this.num - 1];
var texture = textureLoader.load('./风格/' + this.path, function(obj) {
vm.loading.close();
render()
});
mesh.material.map = texture
},
update: function() {},
},
watch: {
num: function(value) {
this.loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
this.path = this.classPath + '/' + this.posChoose.jpgNameArr[this.num - 1];
console.log(this.path);
var texture = textureLoader.load('./风格/' + this.path, function(obj) {
vm.loading.close();
render()
});
mesh.material.map = texture;
render()
}
},
created() {
this.posArr = styleObjArr[0].children;
this.styleChoose = this.styleArr[0];
this.posChoose = styleObjArr[0].children[0];
this.loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
}
});
window.onresize = onresizeFun;
function onresizeFun() {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
vm.width = window.innerWidth;
vm.height = window.innerHeight;
};
function requestFullScreen() {
console.log('fdsfdf');
var de = document.documentElement;
if (de.requestFullscreen) {
de.requestFullscreen()
} else if (de.mozRequestFullScreen) {
de.mozRequestFullScreen()
} else if (de.webkitRequestFullScreen) {
de.webkitRequestFullScreen()
}
}
function exitFullscreen() {
var de = document;
if (de.exitFullscreen) {
de.exitFullscreen()
} else if (de.mozCancelFullScreen) {
de.mozCancelFullScreen()
} else if (de.webkitCancelFullScreen) {
de.webkitCancelFullScreen()
}
}
</script>
</body>
</html>