-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.xhtml
185 lines (160 loc) · 4.6 KB
/
index.xhtml
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
183
184
185
---
---
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>dom access for x_ite</title>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
<meta charset="utf-8"/>
<script type="text/javascript"
src="https://create3000.github.io/code/x_ite/latest/dist/x_ite.js">
</script>
<script type="text/javascript"
src="./src/x_ite_dom.js">
</script>
<link rel="stylesheet" type="text/css"
href="https://create3000.github.io/code/x_ite/latest/dist/x_ite.css"/>
<style >
html, body {
margin: 10px;
padding: 0px;
border: 0px;
width: 100%;
height: 100%;
_overflow: hidden;
}
body {
background: slategrey;
color: white;
}
X3DCanvas {
background: #414141;
width: 600px;
height: 400px;
}
.fallback {
display: block;
margin: 300px 0 0 0;
text-align: center;
}
a {
background: white;
padding: 5px;
}
a:hover {
background: #dcdc63;
}
button, li, a {
margin: 5px;
}
</style>
</head>
<body>
<h1> x_cite via the DOM </h1>
<X3DCanvas>
<X3D>
<Scene>
<Viewpoint description='default'></Viewpoint>
<Viewpoint description='fromBack' position='0 0 -10' orientation='0 1 0 3.1415'></Viewpoint>
<Transform translation='2 0 0'>
<TouchSensor DEF='ts1'></TouchSensor>
<Shape>
<!-- When attribute values are not specified, the default values from the X3D (or VRML) Specification are used. -->
<Appearance>
<Material></Material>
</Appearance>
<Box></Box>
</Shape>
</Transform>
<Transform id='shell'>
</Transform>
</Scene>
</X3D>
<p class="fallback">
Your browser may not support all features required by Cobweb! You can use Firefox, <br/>
because this is currently the choice of the choice. We will continuously keep you informed <br/>
on technical developments and as soon as Cobweb is running in other browser too.
</p>
</X3DCanvas>
<div>
<button onclick='random_color()'>new color</button>
<button onclick='add_box()'>new box</button>
<button onclick='remove_last_box()'>remove box</button>
<button onclick='remove_last_material()'>remove material</button>
<button onclick='toggle_Viewpoint()'>toggle view</button>
<button onclick='reset_Viewpoint()'>reset view</button>
</div>
<div> <h2> xhtml examples </h2>
<ol>
{% for example in site.static_files %}
{% if example.extname == '.xhtml' %}
{% if example.path contains 'tests/' %}
<li><a href="{{ site.github.url }}{{example.path}}"> {{example.name}} </a></li>
{% endif %}
{% endif %}
{% endfor %}
</ol>
</div>
<div> <h2> html5 examples </h2>
<ol>
{% for example in site.static_files %}
{% if example.extname == '.html' %}
{% if example.path contains 'tests/' %}
<li><a href="{{ site.github.url }}{{example.path}}"> {{example.name}} </a></li>
{% endif %}
{% endif %}
{% endfor %}
</ol>
</div>
</body>
<script>
console.log('START')
var box_counter = 0;
var radius = 4;
var perBoxAngle = 2*Math.PI/12;
var viewpointNodes=document.querySelectorAll("Viewpoint");
var v_i = 0;
function reset_Viewpoint () {
X3D.getBrowser("X3DCanvas").bindViewpoint(viewpointNodes[v_i%2].x3d);//direct browser interface
}
function toggle_Viewpoint () {
viewpointNodes[++v_i%2].setAttribute("set_bind","true");
}
function random_color() {
var m = document.querySelector("Material")
//will be transferred to scene graph node
m.setAttribute("diffuseColor", Math.random()+" "+Math.random()+" "+Math.random());
console.log(m);
}
function add_box() {
var transform = document.createElement('Transform');
transform.setAttribute('translation', radius * Math.cos(perBoxAngle * box_counter) + " " + radius * Math.sin(perBoxAngle * box_counter++) + " " + 0);
var shape = document.createElement('Shape');
var app = document.createElement('Appearance');
var mat = document.createElement('Material');
var box = document.createElement('Box');
var shell = document.querySelector('#shell');
app.appendChild(mat);
shape.appendChild(app);
shape.appendChild(box);
transform.appendChild(shape);
shell.appendChild(transform);
radius = radius + box_counter/100;
}
function remove_last_box() {
var trafos = document.querySelectorAll("Transform");
var last_trafo = trafos[trafos.length - 1];
last_trafo.remove();
box_counter--;
radius = radius - box_counter/100;
}
function remove_last_material() {
var mats = document.querySelectorAll("Material");
var last_mat = mats[mats.length - 1];
last_mat.remove();
}
</script>
</html>