-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathx-ray-02.html
165 lines (135 loc) · 4.31 KB
/
x-ray-02.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
<!DOCTYPE html>
<html>
<head>
<title>X-ray</title>
<script src="js/three.min.js"></script>
<script src="js/three/js/loaders/OBJLoader.js"></script>
<script src="js/three/js/loaders/ColladaLoader.js"></script>
<script id="vertexShader" type="x-shader/x-vertex">
uniform float p;
varying float intensity;
void main()
{
vec3 vNormal = normalize( normalMatrix * normal );
intensity = pow(1.0 - abs(dot(vNormal, vec3(0, 0, 1))), p);
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
</script>
<!-- fragment shader a.k.a. pixel shader -->
<script id="fragmentShader" type="x-shader/x-vertex">
uniform vec3 glowColor;
varying float intensity;
void main()
{
vec3 glow = glowColor * intensity;
gl_FragColor = vec4( glow, 1.0 );
}
</script>
<style>
html, body {
height: 100%;
margin: 0;
overflow: hidden;
}
canvas {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<script>
"use strict";
window.addEventListener('load', function () {
var mouseX = 0, mouseY = 0;
var human;
var camstep = 0;
var dae;
var $ = document.querySelector.bind(document);
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, 1, 0.1, 1000);
var renderer = new THREE.WebGLRenderer({antialias: true, alpha: true});
renderer.setClearColor(0x000000, 1.0);
var lookAt = scene.position;
lookAt.y = 15;
camera.lookAt(lookAt);
var light = new THREE.HemisphereLight( 0xffbbbb, 0x444488 );
light.position.set( - 0.5, 0.8, 1 );
scene.add( light );
document.body.appendChild(renderer.domElement);
var plainMaterial = new THREE.MeshPhongMaterial({
ambient: 0x808080,
color: 0xFFFFFF,
specular: 0xFFFFFF,
shininess: 3,
shading: THREE.SmoothShading,
});
var customMaterial = new THREE.ShaderMaterial(
{
uniforms: {
p: { type: "f", value: 3 },
glowColor: { type: "c", value: new THREE.Color(0x84ccff) },
},
vertexShader: document.getElementById('vertexShader').textContent,
fragmentShader: document.getElementById('fragmentShader').textContent,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending,
transparent: true,
depthWrite: false
});
var loader = new THREE.ColladaLoader();
loader.options.convertUpAxis = true;
loader.load('assets/woman.dae', function (collada) {
dae = collada.scene;
dae.traverse( function ( child ) {
if (child instanceof THREE.Mesh) {
child.material = customMaterial;
}
} );
dae.scale.x = dae.scale.y = dae.scale.z = 0.002;
dae.updateMatrix();
dae.position.y = 0;
dae.scale.x = 0.2;
dae.scale.y = 0.2;
dae.scale.z = 0.2;
human = dae;
scene.add( human );
});
loader.load('assets/skeleton.dae', function( collada ) {
var inner = collada.scene;
inner.traverse( function( child ) {
if (child instanceof THREE.Mesh) {
console.log(child);
child.material = plainMaterial;
}
});
inner.scale.x = 0.7;
inner.scale.y = 0.7;
inner.scale.z = 0.7;
scene.add( inner );
});
function resize() {
var canvas = renderer.domElement;
var width = canvas.clientWidth;
var height = canvas.clientHeight;
if (canvas.width !== width || canvas.height !== height) {
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
}
function render(time) {
time *= 0.001;
resize();
camera.position.x = -20 * (Math.cos(time));
camera.position.z = (20 * (Math.sin(time)));
camera.position.y = 20;
camera.lookAt(lookAt);
renderer.render(scene, camera);
requestAnimationFrame(render);
}
requestAnimationFrame(render);
});
</script>
</body>
</html>