-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexperiment8.html
More file actions
160 lines (141 loc) · 4.37 KB
/
experiment8.html
File metadata and controls
160 lines (141 loc) · 4.37 KB
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
<html>
<head>
<title>My first three.js app</title>
<style>
body {
margin: 0;
}
canvas {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<script src="js/three.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="js/GLTFLoader.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
2000
);
var renderer = new THREE.WebGLRenderer();
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.BasicShadowMap;
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var animate = function() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
};
animate();
// adding controls
controls = new THREE.OrbitControls(camera, renderer.domElement);
// adding a simple cube
var geometry = new THREE.BoxGeometry(500, 200, 500);
var texture = new THREE.TextureLoader().load("img/black_tile.jpg");
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(4, 3);
// adding a list of materials for cube faces
var cubeMaterials = [
new THREE.MeshStandardMaterial({
color: 0xffffff,
wireframe: false,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0x00ffff,
wireframe: false,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0xff00ff,
wireframe: false,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
map: texture,
wireframe: false,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0x00ff00,
wireframe: false,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0xff0000,
wireframe: false,
side: THREE.DoubleSide
})
];
var cube = new THREE.Mesh(geometry, cubeMaterials);
cube.receiveShadow = true;
scene.add(cube);
// move back camera
camera.position.z = 50;
var lightX = 50;
var lightY = 50;
var lightZ = 50;
var light = new THREE.PointLight(0xfffffff, 5, 500);
light.position.set(lightX, lightY, lightZ);
light.castShadow = true;
light.shadow.camera.near = 0.1;
light.shadow.camera.far = 500;
scene.add(light);
// adding a simple cube
var geometry = new THREE.BoxGeometry(10, 10, 10);
var material = new THREE.MeshBasicMaterial({
color: 0xffffff,
wireframe: false
});
var cube = new THREE.Mesh(geometry, material);
cube.position.x = lightX;
cube.position.y = lightY;
cube.position.z = lightZ;
scene.add(cube);
// Create a helper for the shadow camera (optional)
var helper = new THREE.CameraHelper(light.shadow.camera);
scene.add(helper);
// Instantiate a loader
var loader = new THREE.GLTFLoader();
// Load a glTF resource
loader.load(
// resource URL
"./models/bed/scene.gltf",
// called when the resource is loaded
function(gltf) {
console.log(gltf);
gltf.scene.position.y = -110;
gltf.scene.position.x = 0;
gltf.scene.castShadow = true; //default is false
gltf.scene.receiveShadow = true; //default is false
gltf.scene.traverse(function(node) {
if (node instanceof THREE.Mesh) {
node.castShadow = true;
}
});
scene.add(gltf.scene);
gltf.animations; // Array<THREE.AnimationClip>
gltf.scene; // THREE.Scene
gltf.scenes; // Array<THREE.Scene>
gltf.cameras; // Array<THREE.Camera>
gltf.asset; // Object
},
// called while loading is progressing
function(xhr) {
console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
},
// called when loading has errors
function(error) {
console.log("An error happened");
}
);
</script>
</body>
</html>