forked from xeolabs/scenejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
effects_zspace_geometries.html
162 lines (132 loc) · 4.57 KB
/
effects_zspace_geometries.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
<!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,
nodes: [
{
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: [
{
type: "camera",
id: "theCamera",
optics: {
type: "frustumAngles",
left:20,
down:20,
near:0.1,
right:20,
up:20,
far:10000
},
nodes: [
{
type: "rotate",
id: "theRotate",
x: 0, y: -1, z: 0, // Axis of rotation
angle: 90.0,
nodes: [
// Randomly scattered boxes, implemented by plugin at
// http://scenejs.org/api/latest/plugins/node/geometry/randomObjects.js
{
type: "geometry/randomObjects",
numObjects: 500
}
]
}
]
}
]
}
]
});
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);
var stylusButtons = zspace.getStylusButtons();
if (stylusButtons[0]) {
}
});
</script>
</body>
</html>