-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path007_points_gizmo.html
65 lines (55 loc) · 2.05 KB
/
007_points_gizmo.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
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title></title></head>
<style>canvas{ display:block; } body, html { padding:0px; margin:0px; width:100%; height:100%; }</style>
<body><script type="module">
//#region IMPORTS
import useThreeWebGL2, { THREE, useDarkScene, useVisualDebug } from './_lib/useThreeWebGL2.js';
import {
Gizmos,
PointsGizmo,
TranslateGizmo
} from '../src/index.ts';
//#endregion
//#region MAIN
let App = useDarkScene( useThreeWebGL2() );
let Ref = {};
let Debug;
window.addEventListener( 'load', async _=>{
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Setup
App.sphericalLook( 0, 20, 6 );
Debug = await useVisualDebug( App );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ref.gizmos = new Gizmos( App.renderer, App.camera, App.scene );
Ref.gizmos.events.on( 'dragStart', ()=>{ App.camCtrl.enabled = false; });
Ref.gizmos.events.on( 'dragStop', ()=>{ App.camCtrl.enabled = true; });
// --------------------------------------
Ref.pnt = new PointsGizmo();
Ref.pnt.addPoint( [0,0.5,0] );
Ref.pnt.addPoint( [-1,1.0,0] );
Ref.pnt.addPoint( [1,0.0,0] );
Ref.pnt.update();
Ref.gizmos.add( Ref.pnt );
Ref.gizmos.events.on( 'pointSelected', e=>{
// console.log( e.detail );
if( e.detail.index !== -1 ){
Ref.tran.visible = true;
Ref.tran.state.position = e.detail.point.pos.slice();
}else{
Ref.tran.visible = false;
}
});
// --------------------------------------
Ref.tran = new TranslateGizmo();
Ref.tran.visible = false;
Ref.gizmos.add( Ref.tran );
Ref.gizmos.events.on( 'translate', e=>{
if( e.detail.isDone ){
const i = Ref.pnt.selectedIndex;
if( i !== -1 ) Ref.pnt.setPosition( i, e.detail.position, true );
}
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
App.renderLoop();
});
// #endregion
</script></body></html>