Newer
Older
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
var color1= 0xffffff; /*white*/
var color2= '#020227'; /*kohly*/
var color3= 0x1c5c61; /*teal*/
var color4= "#fa6e70"; //red/orange
var color5="#380152"; //purple
var color6="#696767"; //grey
var color7="#03dbfc"; //blue
var fileName="setupScaling";
var setup,Graph,gData,scene,camera,renderer,orbit,gui,guiSupport,guiLoad;
var scale=10.0;
var supportCount=0;
var supportBoxes=[];
var supportControls=[];
var guiSupports=[];
var loadCount=0;
var loadBoxes=[];
var loadControls=[];
var guiLoads=[];
//////////////init///////////////////////
$.getJSON("../json/"+fileName+".json", function(json) {
setup=json.setup;
[scene,camera,renderer,orbit]=loadGraph(setup,scale);
setup.supports=[];
setup.loads=[];
gui = new dat.GUI();
guiCreate (setup);
});
////////////////////////////////////////////////////////////////////////
function getNodeColor(restrained,loaded){
if (restrained){
return 0xfa6e70;
}else if(loaded){
return 0x03dbfc;
}else{
return color3;
}
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
var f1 = gui.addFolder('Displacement Animation');
f1.add(setup.animation, 'showDisplacement');
f1.add(setup.animation, 'exaggeration', 0, 1000);
f1.add(setup.animation, 'speed', 0, 10);
var f2 = gui.addFolder('Stresses Visualization');
f2.add(setup.viz, 'minStress', -1000, 0).listen();
f2.add(setup.viz, 'maxStress', 0, 1000).listen();
f2.add(setup.viz, 'colorMap', {coolwarm:0, YlGnBu:1, winter:2,jet:3});
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
// gui.add(setup, 'solve');
// for (j in f2.__controllers) f2.__controllers[j].onChange (updateColors.bind(this)); //todo check three
// for (j in f1.__controllers) f1.__controllers[j].onChange (renderLast.bind(this)); //todo check three
}
function updateNodeColors(){
for(var j=0;j<supportCount;j++){
var box = new THREE.Box3();
supportBoxes[j].geometry.computeBoundingBox();
box.copy( supportBoxes[j].geometry.boundingBox ).applyMatrix4( supportBoxes[j].matrixWorld );
Graph.d3Force('box', () => {
gData.nodes.forEach(node => {
node.restrained=box.containsPoint(new THREE.Vector3(node.px,node.py,node.pz));
});
});
}
for(var j=0;j<loadCount;j++){
var box1 = new THREE.Box3();
loadBoxes[j].geometry.computeBoundingBox();
box1.copy( loadBoxes[j].geometry.boundingBox ).applyMatrix4( loadBoxes[j].matrixWorld );
Graph.d3Force('box', () => {
gData.nodes.forEach(node => {
node.loaded=box1.containsPoint(new THREE.Vector3(node.px,node.py,node.pz));
});
});
}
Graph.nodeThreeObject(({ restrained,loaded }) => new THREE.Mesh(
new THREE.BoxGeometry(scale, scale, scale),
new THREE.MeshLambertMaterial({
color: getNodeColor(restrained,loaded),
transparent: true,
opacity: 0.8
})
))
}