-
Notifications
You must be signed in to change notification settings - Fork 103
/
materials.html
178 lines (147 loc) · 6.99 KB
/
materials.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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>
CubicVR.js: Basic Primitives /w Scene, MouseViewController and Advanced Materials
</title>
<script src="../../CubicVR.js" type="text/javascript">
</script>
<script type='text/javascript'>
function webGLStart() {
var canvas = document.getElementById("cubicvr-canvas");
var gl = CubicVR.GLCore.init(canvas, "../../CubicVR_Core.vs", "../../CubicVR_Core.fs");
if (!gl) {
alert("Sorry, no WebGL support.");
return;
};
// New scene with our canvas dimensions and default camera with FOV 80
var scene = new CubicVR.Scene(canvas.width, canvas.height, 80);
var light = new CubicVR.Light({
type: CubicVR.enums.light.type.POINT,
method: CubicVR.enums.light.method.DYNAMIC,
diffuse:[1,1,1],
specular:[1,1,1],
position:[0,5,-2],
distance:20
});
scene.bindLight(light);
var envTex = new CubicVR.Texture("../images/fract_reflections.jpg");
// Create a material for the mesh
var material1 = new CubicVR.Material({
color: [80/255, 200/255, 120/255],
specular:[1,1,1],
shininess: 0.9,
env_amount: 1.0,
textures: {
color: new CubicVR.Texture("../images/2576-diffuse.jpg"),
normal: new CubicVR.Texture("../images/2576-normal.jpg"),
bump: new CubicVR.Texture("../images/2576-bump.jpg"),
envsphere: envTex
}
});
var material2 = new CubicVR.Material({
specular:[1,1,1],
color: [224/255, 17/255, 95/255],
shininess: 0.9,
env_amount: 1.0,
textures: {
color: new CubicVR.Texture("../images/2282-diffuse.jpg"),
normal: new CubicVR.Texture("../images/2282-normal.jpg"),
bump: new CubicVR.Texture("../images/2282-bump.jpg"),
envsphere: envTex
}
});
var material3 = new CubicVR.Material({
specular:[1,1,1],
color: [197/255, 179/255, 88/255],
shininess: 0.9,
env_amount: 1.0,
textures: {
color: new CubicVR.Texture("../images/6583-diffuse.jpg"),
normal: new CubicVR.Texture("../images/6583-normal.jpg"),
bump: new CubicVR.Texture("../images/6583-bump.jpg"),
envsphere: envTex
}
});
var uvplanar = {
projectionMode: CubicVR.enums.uv.projection.PLANAR,
projectionAxis: CubicVR.enums.uv.axis.Y,
scale: [0.5, 0.5, 0.5]
};
var uvplane = {
projectionMode: CubicVR.enums.uv.projection.PLANAR,
projectionAxis: CubicVR.enums.uv.axis.Z,
scale: [0.5, 0.5, 0.5]
};
var uvcubic = {
projectionMode: CubicVR.enums.uv.projection.CUBIC,
scale: [0.5, 0.5, 0.5]
};
var torusMesh = CubicVR.primitives.torus({
innerRadius: 0.5,
outerRadius: 0.75,
lat: 24,
lon: 24,
material: material2,
uvmapper: uvplanar
}).triangulateQuads().compile().clean();
var planeMesh = CubicVR.primitives.plane({
size: 1.0,
material: material1,
uvmapper: uvplane
}).triangulateQuads().compile().clean();
var boxMesh = CubicVR.primitives.box({
size: 1.0,
material: material3,
uvmapper: uvcubic
}).triangulateQuads().compile().clean();
var sphereMesh = CubicVR.primitives.sphere({
radius: 0.5,
lat: 24,
lon: 24,
material: material1,
uvmapper: uvcubic
}).triangulateQuads().compile().clean();
var coneMesh = CubicVR.primitives.cone({
base: 1.0,
material: material2,
uvmapper: uvcubic
}).triangulateQuads().compile().clean();
var cylinderMesh = CubicVR.primitives.cylinder({
radius: 0.5,
height: 1.0,
lon: 24,
material: material3,
uvmapper: uvcubic
}).triangulateQuads().compile().clean();
// Add SceneObjects
scene.bindSceneObject(new CubicVR.SceneObject({mesh:torusMesh, position:[-1.5,0,-1]}),true);
scene.bindSceneObject(new CubicVR.SceneObject({mesh:planeMesh, position:[0,0,-1]}),true);
scene.bindSceneObject(new CubicVR.SceneObject({mesh:boxMesh, position:[1.5,0,-1]}),true);
scene.bindSceneObject(new CubicVR.SceneObject({mesh:sphereMesh, position:[-1.5,0,1]}),true);
scene.bindSceneObject(new CubicVR.SceneObject({mesh:coneMesh, position:[0,0,1]}),true);
scene.bindSceneObject(new CubicVR.SceneObject({mesh:cylinderMesh, position:[1.5,0,1]}),true);
// set initial camera position and target
scene.camera.position = [0, 2, 2];
scene.camera.target = [0, 0, 0];
// initialize a mouse view controller
mvc = new CubicVR.MouseViewController(canvas, scene.camera);
// Start our main drawing loop, it provides a timer and the gl context as parameters
CubicVR.MainLoop(function(timer, gl) {
var lus = timer.getLastUpdateSeconds();
for (var i = 0; i < scene.sceneObjects.length; i++) {
scene.sceneObjects[i].rotation[0] += lus*2.0+0.1*(i+1);
scene.sceneObjects[i].rotation[2] += lus*2.5+0.2*(i+1);
}
scene.render();
});
}
</script>
</head>
<body onLoad="webGLStart();">
<div>
<canvas id="cubicvr-canvas" style="border: none;" width="1280" height="720">
</canvas>
</div>
</body>
</html>