forked from xeolabs/scenejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
effects_zspace_cube.html
182 lines (147 loc) · 5.46 KB
/
effects_zspace_cube.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>SceneJS Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<script src="libs/gl-matrix-min.js"></script>
<!-- Include this BEFORE SceneJS to avoid requireJS confusion -->
<script src="../api/latest/scenejs.js"></script>
<script src="js/zspace/zSpace.js"></script>
<script src="js/zspace/zSpaceEffect.js"></script>
<link href="css/styles.css" rel="stylesheet"/>
</head>
<body>
<div id="infoDark">
<a href="http://scenejs.org">SceneJS</a> - zSpace integration example
</div>
<script>
//-----------------------------------------------------------------------------------------------------------------
// Rendering a scene with zSpace
//-----------------------------------------------------------------------------------------------------------------
// Point SceneJS to the bundled plugins
SceneJS.setConfigs({
pluginPath: "../api/latest/plugins"
});
// Create scene
var scene = SceneJS.createScene({
webgl2: true, // Need WebGL2 for zSpace
nodes: [
// Viewing transform
{
type: "lookAt",
id: "theLookat",
eye: {x: 0, y: 0, z: 10},
look: {x: 0, y: 0, z: 0},
up: {x: 0, y: 1, z: 0},
nodes: [
// Projection transform
{
type: "camera",
id: "theCamera",
optics: {
type: "frustumAngles",
left: 20,
down: 20,
near: 0.1,
right: 20,
up: 20,
far: 10000
},
nodes: [
// Spin the cube
{
type: "rotate",
id: "theRotate",
x: 0, y: -1, z: 0, // Axis of rotation
angle: 90.0,
nodes: [
// Texture the cube
{
type: "texture",
src: "textures/superman.jpg",
applyTo: "color", // Apply to material "color" property (default)
nodes: [
// Scale the cube
{
type: "scale",
x: 0.2, y: 0.2, z: 0.2,
nodes: [
// Box primitive, implemented by plugin at
// http://scenejs.org/api/latest/plugins/node/geometry/box.js
{
type: "geometry/box"
}
]
}
]
}
]
}
]
}
]
}
]
});
var lookat = scene.getNode("theLookat");
var camera = scene.getNode("theCamera");
var rotate = scene.getNode("theRotate");
// Shows a ray as an object within the scene
var rayHelper = new (function () {
var material = camera.addNode({
type: "material",
color: {r: 1, g: 0.3, b: 0.3}
});
var flags = material.addNode({
type: "flags",
flags: {
enabled: true,
picking: false
}
});
var style = flags.addNode({
type: "style",
lineWidth: 3
});
var geometry = style.addNode({
type: "geometry",
primitive: "lines",
positions: [0, 0, 0, 0, 0, 0],
indices: [0, 1]
});
this.setRay = function (origin, direction) {
geometry.setPositions({
positions: [
// Origin
origin[0],
origin[1],
origin[2],
// Direction
origin[0] + direction[0],
origin[1] + direction[1],
origin[2] + direction[2]
]
});
};
})();
scene.on("tick", function () {
rotate.setAngle(rotate.getAngle() + 0.2);
});
var zspace = new SceneJS.ZSpaceEffect({
scene: scene,
lookat: lookat,
camera: camera,
farClip: 10000,
viewerScale: 10
});
scene.on("tick", function () {
var stylusWorldPos = zspace.getStylusWorldPos();
var stylusWorldDir = zspace.getStylusWorldDir();
console.log(stylusWorldPos);
console.log(stylusWorldDir);
rayHelper.setRay(stylusWorldPos, stylusWorldDir);
});
</script>
</body>
</html>