-
Notifications
You must be signed in to change notification settings - Fork 0
/
paramUI.js
128 lines (102 loc) · 3.5 KB
/
paramUI.js
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
//should be global
var lrScaleUIAdded = false, topScaleUIAdded = false, modelLoaded = false;
var leftBoxUI, rightBoxUI, topBoxUI;
var settings = {
model: {
'x': 1.0,
'y': 1.0,
'z': 1.0
},
modelScale: 1.0,
leftBbox: {
'x': 1.0,
'y': 1.0,
'z': 1.0
},
rightBbox: {
'x': 1.0,
'y': 1.0,
'z': 1.0
},
topBbox: {
'x': 1.0,
'y': 1.0,
'z': 1.0
}
}
var panel = new dat.GUI();
var params = {
loadFile: function(){
document.getElementById("myInput").click();
var stlMesh = loadSTLModel('./models/android.stl', 'ascii');
// modelUI.add( settings.model, 'x', 0, 360, 1).listen();//.onFinishCahnge(()=>{}); //then update model scale
// modelUI.add( settings.model, 'y', 0, 360, 1).listen();
// modelUI.add( settings.model, 'z', 0, 360, 1).listen();
if( stlMesh ){
scene.add( stlMesh );
objects.push( stlMesh ); //objects from editor
panel.add(settings, 'modelScale', -10, 10, 0.1).onChange(function(){
console.log("stl Mesh: ", stlMesh)
stlMesh.scale.set(settings.modelScale, settings.modelScale, settings.modelScale);
});
}
},
Kinemake:function() {
loadSTLModel('./models/android-body.stl', 'chunk');
},
export: function(){
console.log("export stl")
}
}
// var modelUI = panel.addFolder( 'Model Scale' );
function createPanel(){
//file upload
panel.add(params, 'loadFile').name('Load 3D Model');
panel.add(params, 'Kinemake');
panel.add(params, 'export').name('Export to STL');
// modelUI.open();
}
function addLRScalePanel(gearType){
if( !lrScaleUIAdded ){
leftBoxUI = panel.addFolder( 'Scale Left BoudingBox' );
rightBoxUI = panel.addFolder( 'Scale Right BoudingBox' );
leftBoxUI.add( settings.leftBbox, 'x', 0, 5).name('Width').listen(); //then update model scale
leftBoxUI.add( settings.leftBbox, 'y', 0, 5).name('Height').listen();
leftBoxUI.add( settings.leftBbox, 'z', 0, 5).name('Length').listen();
rightBoxUI.add( settings.rightBbox, 'x', 0, 5).name('Width').listen(); //then update model scale
rightBoxUI.add( settings.rightBbox, 'y', 0, 5).name('Height').listen();
rightBoxUI.add( settings.rightBbox, 'z', 0, 5).name('Length').listen();
leftBoxUI.open();
rightBoxUI.open();
lrScaleUIAdded = true;
}
}
function addTopScalePanel(gearType){
if( !topScaleUIAdded ){
topBoxUI = panel.addFolder( 'Scale Top BoundingBox' );
topBoxUI.add( settings.topBbox, 'x', 0, 5).name('Width').onChange(()=>{
console.log("gears.top: ", gears[0].top);
console.log("x scale: ", settings.topBbox.x);
gears[0].top.scale.set(settings.topBbox.x, settings.topBbox.y, settings.topBbox.z);
}); //then update model scale
topBoxUI.add( settings.topBbox, 'y', 0, 5).name('Height').onChange(()=>{
console.log("y scale: ", settings.topBbox.y);
gears[0].top.scale.set(settings.topBbox.x, settings.topBbox.y, settings.topBbox.z);
});
topBoxUI.add( settings.topBbox, 'z', 0, 5).name('Length').onChange(()=>{
console.log("z scale: ", settings.topBbox.z);
gears[0].top.scale.set(settings.topBbox.x, settings.topBbox.y, settings.topBbox.z);
});
topBoxUI.open();
topScaleUIAdded = true;
}
}
function removePanel(gearType){
topBoxUI.close();
delete topBoxUI;
}
function showDiv() {
document.getElementById('bbox_shape').style.display = "block";
// document.getElementById('loadSTL').style.display = "block";
// document.getElementById('model_rotation').style.display = "block";
}