forked from MyYosun/mxreality.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pano_object_scenne.html
127 lines (99 loc) · 3.87 KB
/
pano_object_scenne.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
<!DOCTYPE html>
<html>
<head>
<title>vr obj scene</title>
<script src="../build/three.js"></script>
<script src="./js/controls/OrbitControls.js"></script>
<script src="../build/mxreality.js"></script>
<script src="js/loaders/collada/AnimationHandler.js"></script>
<meta charset="utf-8">
<style>
body {
/* set margin to 0 and overflow to hidden, to go fullscreen */
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<!-- 用来保存输出结果 -->
<div id="WebGL-output">
</div>
<script type="text/javascript">
// 当页面加载完成时运行初始化函数, 完成绘制
function init() {
var scene = new THREE.Scene();
var renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setClearColor(0x000000)
var container =document.getElementById("WebGL-output");
var mesh1,distance=40;
var vr=new VR(scene,renderer,container);
vr.init(function () {
});
// 创建一个平面层
var planeGeometry = new THREE.PlaneGeometry(60, 60);
var texture=new THREE.TextureLoader().load("textures/lavatile.jpg");//加载纹理图片
var planeMaterial = new THREE.MeshLambertMaterial({map:texture});
var plane = new THREE.Mesh(planeGeometry, planeMaterial);
// 旋转并设置平面层位置
plane.rotation.x = -0.5 * Math.PI;
plane.receiveShadow = true;
// 将平面层加入到场景
scene.add(plane);
//添加环境光
var envLight=new THREE.AmbientLight(0xffffff,0.7);
scene.add(envLight);
// 添加聚光灯
var spotLight = new THREE.SpotLight(0xffffff, 1,300,2);
//var spotLight=new THREE.DirectionalLight(0xffffff,1)
spotLight.position.set(0, 20, 20);
spotLight.castShadow = true;
spotLight.shadow.camera.zoom=1;
mixer = new THREE.AnimationMixer( scene );
var loader = new THREE.JSONLoader();
loader.load( 'models/animated/monster/monster.js', function ( geometry, materials ) {
// adjust color a bit
var material = materials[ 0 ];
material.morphTargets = true;
material.color.setHex( 0xffaaaa );
var faceMaterial = new THREE.MultiMaterial( materials );
// random placement in a grid
mesh1 = new THREE.Mesh( geometry, faceMaterial );
mesh1.scale.set( 0.01, 0.01, 0.01 );
mesh1.position.set( distance, -4, 0 );
//mesh.rotation.y = THREE.Math.randFloat( -0.25, 0.25 );
mesh1.rotation.y =Math.PI;
mesh1.matrixAutoUpdate = true;
mesh1.updateMatrix();
mesh1.castShadow=true;
scene.add( mesh1 );
mixer.clipAction( geometry.animations[0], mesh1 )
.setDuration( 1 ) // one second
.startAt(0) // random phase (already running)
.play(); // let's go
} );
// 创建一个渲染器
//renderer.setClearColorHex();
renderer.setClearColor(new THREE.Color(0xEEEEEE));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled=true;
// 添加图形到div层
document.getElementById("WebGL-output").appendChild(renderer.domElement);
var clock=new THREE.Clock();
//var mixer = new THREE.AnimationMixer( scene );
function render() {
requestAnimationFrame(render);
var delta = clock.getDelta();
// animate Collada model
THREE.AnimationHandler.update( delta );
mixer.update( delta );
mesh1.position.x=distance;
distance -=0.01;
if(distance<=20) distance=40;
}
render();
}
window.onload = init;
</script>
</body>
</html>