-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
200 lines (161 loc) · 5.65 KB
/
index.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>@0b5vr/tweakpane-plugin-rotation</title>
<style>
@import url('https://fonts.googleapis.com/css?family=Roboto+Mono:400,500,700');
body {
background: #000;
font-family: 'Roboto Mono', sans-serif;
color: #ffffff;
}
#canvas {
position: fixed;
left: 0;
top: 0;
}
main {
position: relative;
max-width: 800px;
margin: 64px auto 64px;
}
a {
color: #88a3dd;
}
#title-wrap {
display: inline-block;
perspective: 24em;
}
#title {
display: flex;
flex-direction: column;
transform-origin: center;
perspective-origin: center;
}
#namespace {
font-size: 0.7em;
}
#code-example {
display: none;
}
.CodeMirror {
height: 38em !important;
font-family: 'Roboto Mono', monospace !important;
font-size: 12px;
}
</style>
<link rel="stylesheet" href="https://www.unpkg.com/codemirror@5.62.3/lib/codemirror.css" />
<link rel="stylesheet" href="https://www.unpkg.com/codemirror@5.62.3/theme/material-darker.css" />
</head>
<body>
<canvas id="canvas"></canvas>
<main>
<span id="title-wrap">
<h1 id="title"><span id="namespace">@0b5vr/</span>tweakpane-plugin-rotation</h1>
</span>
<p>
Rotation input plugin for Tweakpane
</p>
<p>
<a href="https://www.npmjs.com/package/@0b5vr/tweakpane-plugin-rotation" target="_blank" rel="noreferrer">
<img alt="npm" src="https://img.shields.io/npm/v/@0b5vr/tweakpane-plugin-rotation?logo=npm&style=flat-square" />
</a>
</p>
<textarea id="code-example">pane.registerPlugin(TweakpaneRotationInputPlugin);
const params = {
euler: { x: 0.0, y: 0.0, z: 0.0 },
quat: { x: 0.0, y: 0.0, z: 0.0, w: 1.0 },
}
// euler
const guiEuler = pane.addBinding(params, 'euler', {
view: 'rotation',
rotationMode: 'euler',
order: 'XYZ', // Extrinsic rotation order. optional, 'XYZ' by default
unit: 'deg', // or 'rad' or 'turn'. optional, 'rad' by default
});
// quaternion
const guiQuat = pane.addBinding(params, 'quat', {
view: 'rotation',
rotationMode: 'quaternion', // optional, 'quaternion' by default
picker: 'inline', // or 'popup'. optional, 'popup' by default
expanded: true, // optional, false by default
});
guiEuler.on('change', ({ value }) => {
console.log(value); // do something
});
</textarea>
<p>
<a href="https://github.com/0b5vr/tweakpane-plugin-rotation" target="_blank" rel="noreferrer">GitHub</a>
</p>
</main>
<script src="https://unpkg.com/three@0.137.0"></script>
<script src="https://www.unpkg.com/codemirror@5.62.3/lib/codemirror.js"></script>
<script src="https://www.unpkg.com/codemirror@5.62.3/mode/javascript/javascript.js"></script>
<script type="module">
import * as Tweakpane from 'https://unpkg.com/tweakpane@4.0.1/dist/tweakpane.js';
import * as TweakpaneRotationInputPlugin from './dist/tweakpane-plugin-rotation.js';
const pane = new Tweakpane.Pane();
pane.registerPlugin( TweakpaneRotationInputPlugin );
const params = {
title: { x: 0.0, y: 0.0, z: 0.0 },
sphere: { x: 0.24, y: 0.13, z: -0.23, w: 0.93 },
};
const guiTitle = pane.addBinding( params, 'title', {
view: 'rotation',
rotationMode: 'euler',
unit: 'deg',
} );
const guiSphere = pane.addBinding( params, 'sphere', {
view: 'rotation',
picker: 'inline',
expanded: true,
} );
// -- css ------------------------------------------------------------------------------------
const title = document.getElementById( 'title' );
guiTitle.on( 'change', ( { value } ) => {
title.style.transform = `rotateZ(${ -value.z }deg) rotateY(${ value.y }deg) rotateX(${ -value.x }deg)`;
} );
// -- three ----------------------------------------------------------------------------------
let width = window.innerWidth;
let height = window.innerHeight;
const canvas = document.getElementById( 'canvas' );
canvas.width = width;
canvas.height = height;
const renderer = new THREE.WebGLRenderer( { canvas, antialias: true } );
const camera = new THREE.PerspectiveCamera( 60.0, width / height, 0.01, 20.0 );
camera.position.z = 9.0;
const scene = new THREE.Scene();
const sphere = new THREE.Mesh(
new THREE.IcosahedronGeometry( 10.0, 5 ),
new THREE.MeshBasicMaterial( {
color: 0x222222,
transparent: true,
wireframe: true,
side: THREE.BackSide,
} ),
);
sphere.quaternion.set( 0.24, 0.13, -0.23, 0.93 );
scene.add( sphere );
renderer.render( scene, camera );
guiSphere.on( 'change', ( { value } ) => {
sphere.quaternion.set( value.x, value.y, value.z, value.w );
renderer.render( scene, camera );
} );
window.addEventListener( 'resize', () => {
width = window.innerWidth;
height = window.innerHeight;
renderer.setSize( width, height );
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.render( scene, camera );
} );
// -- code-example ---------------------------------------------------------------------------
const codeExample = document.getElementById( 'code-example' );
CodeMirror.fromTextArea( codeExample, {
readOnly: true,
theme: 'material-darker',
} );
</script>
</body>
</html>