-
Notifications
You must be signed in to change notification settings - Fork 272
/
x3dom_htmlIntegration.html
162 lines (136 loc) · 5.49 KB
/
x3dom_htmlIntegration.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 xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Simple WebGL example</title>
<style>
label { width: 100px; float: left; clear: both; }
#ctrlContainer { border: 1px solid #000; padding: 20px; float: left; width: 280px; margin-left: 20px; }
#sliderContainer div { float:left; width: 200px; }
#sliderContainer li { height: 25px; }
#sliderContainer ul { clear: both; list-style-type: none; margin: 20px 0 10px 0; padding: 0; }
</style>
<link rel="stylesheet" type="text/css" href="x3dom.css" />
<style type="text/css">
.trans {
-webkit-animation: spin 8s infinite linear;
}
@-webkit-keyframes spin {
from { -webkit-transform: rotateY(0); }
to { -webkit-transform: rotateY(-360deg); }
}
</style>
</head>
<body style='font-size: 14pt;'>
<h1>Simple HTML/DOM/CSS/Event integration example</h1>
<p>
<ul>
<li>add/remove node: using simple <b>element.appendChild()/element.removeChild()</b> functions</li>
<li>node attribute updates: using <b>jQuery</b> per tag-type manipulator</li>
<li><a href='http://www.w3.org/TR/css3-3d-transforms'>CSS 3D Transform:</a> using CSS <b>-webkit-transform: property</b> </li>
<li><a href='http://www.w3.org/TR/css3-animations/'>CSS Animation:</a> using CSS <b>-webkit-transform: property</b> </li>
<li>HTML-Event: using <b>onclick()</b> to pick an 3D-object; returns 3d position</li>
</ul>
</p>
<p class="case">
<x3d id="boxes" showStat="true" x="0px" y="0px" width="600px" height="400px">
<scene>
<viewpoint position='9.6 8.12 14.8' orientation='-0.69017 0.723467 -0.0161809 0.735134' ></viewpoint>
<directionalLight direction='-0.8 -0.9 0.3' shadowIntensity='0.7' intensity='0.5'></directionalLight>
<background DEF='bgnd' transparency='0' skyColor='0.4 0.4 0.5' ></background>
<navigationinfo headlight='true'></navigationinfo>
<transform id="root" translation="0 0 0">
<shape>
<box ></box>
</shape>
</transform>
</scene>
</x3d>
</p>
<script type="text/javascript">
var count = 0;
var obj = null;
function addNode()
{
x = Math.random() * 6 - 3;
y = Math.random() * 6 - 3;
z = Math.random() * 6 - 3;
s0 = Math.random() + 0.5;
s1 = Math.random() + 0.5;
s2 = Math.random() + 0.5;
var t = document.createElement('Transform');
t.setAttribute("translation", x + " " + y + " " + z );
t.setAttribute("scale", s0 + " " + s1 + " " + s2 );
var t2 = document.createElement('Transform');
t2.setAttribute('class','trans');
t.appendChild(t2);
var s = document.createElement('Shape');
t2.appendChild(s);
var a = document.createElement('Appearance');
s.appendChild(a);
var m = document.createElement('Material');
m.setAttribute('diffuseColor','1 0 0');
m.setAttribute('specularColor','0.7 0.7 0.7');
m.setAttribute('shininess','0.5')
a.appendChild(m);
var b = document.createElement('Torus');
b.setAttribute ('innerRadius','0.5');
b.setAttribute ('outerRadius','1.1')
if (obj) {
b.setAttribute('USE', 'OBJ')
}
else {
obj = b;
b.setAttribute('DEF', 'OBJ')
}
s.appendChild(b);
b.setAttribute('onclick',"alert('Hit obj at '+event.hitPnt);");
var ot = document.getElementById('root');
ot.appendChild(t);
return false;
};
function removeNode()
{
var ot = document.getElementById('root');
for (var i = 0; i < ot.childNodes.length; i++) {
// check if we have a real X3DOM Node; not just e.g. a Text-tag
if (ot.childNodes[i].nodeType === Node.ELEMENT_NODE) {
ot.removeChild(ot.childNodes[i]);
break;
}
}
return false;
};
</script>
<p class="case">
<input type="button" value="Add Child" onclick="window.addNode();" />
<input type="button" value="Remove Child" onclick="window.removeNode();" />
</p>
<div id="ctrlContainer">
<p>Change the color with jQuery.</p>
<div id="sliderContainer">
<ul>
<li><label>Red</label><div id="redSlider" class="slider"></div></li>
<li><label>Green</label><div id="greenSlider" class="slider"></div></li>
<li><label>Blue</label><div id="blueSlider" class="slider"></div></li>
</ul>
</div>
</div>
<script type="text/javascript" src="x3dom.js"></script>
<script type="text/javascript" src="media/js/jquery.min.js"></script>
<link type="text/css" href="media/js/jquery-ui.css" rel="stylesheet" />
<script type="text/javascript" src="media/js/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// Create the sliders
$(".slider").slider({min: 0, max: 1, step: 0.01, slide: function(e, ui) {
var newCol = $("#redSlider").slider('option', 'value') + " "
+ $("#greenSlider").slider('option', 'value') + " "
+ $("#blueSlider").slider('option', 'value');
$("Material").attr("diffuseColor", newCol);
}});
});
</script>
</body>
</html>