Newer
Older
<head>
<style> body { margin: 0; } </style>
<title>MetaVoxel</title>
<script src="//unpkg.com/three"></script>
<script type="text/javascript" src="https://files.mcneel.com/rhino3dm/js/latest/rhino3dm.js"></script>
<script src="../lib/js-colormaps.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="//unpkg.com/3d-force-graph"></script>
<!-- <script src="../lib/3d-force-graph.js"></script> -->
<script src="//unpkg.com/three-spritetext"></script>
<script src="../visualization/geometry.js"></script>
<script src="../visualization/drawFrep.js"></script>
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
<script src="../visualization/utils.js"></script>
</head>
<body>
<div id="3d-graph"></div>
<script>
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 nodes=[];
var buildList=[];
var offset2=12;
var offset=offset2+8;
var buildSize=32;
var gridSize=buildSize+2*(offset);
var scale,setup;
var voxelIndexList=[
null,
{
size:1,
list:[
new THREE.Vector3(0,0,0),
]
},
{
size:2,
list:[
new THREE.Vector3(0,0,0),
new THREE.Vector3(0,1,0),
new THREE.Vector3(1,0,0),
new THREE.Vector3(1,1,0),
new THREE.Vector3(0,0,1),
new THREE.Vector3(0,1,1),
new THREE.Vector3(1,0,1),
new THREE.Vector3(1,1,1)
]
},
null,
{
size:4,
list:[
new THREE.Vector3(0,0,0),
new THREE.Vector3(0,1,0),
new THREE.Vector3(0,2,0),
new THREE.Vector3(0,3,0),
new THREE.Vector3(1,0,0),
new THREE.Vector3(1,1,0),
new THREE.Vector3(1,2,0),
new THREE.Vector3(1,3,0),
new THREE.Vector3(2,0,0),
new THREE.Vector3(2,1,0),
new THREE.Vector3(2,2,0),
new THREE.Vector3(2,3,0),
new THREE.Vector3(3,0,0),
new THREE.Vector3(3,1,0),
new THREE.Vector3(3,2,0),
new THREE.Vector3(3,3,0),
new THREE.Vector3(0,0,1),
new THREE.Vector3(0,1,1),
new THREE.Vector3(0,2,1),
new THREE.Vector3(0,3,1),
new THREE.Vector3(1,0,1),
// new THREE.Vector3(1,1,1),
// new THREE.Vector3(1,2,1),
new THREE.Vector3(1,3,1),
new THREE.Vector3(2,0,1),
// new THREE.Vector3(2,1,1),
// new THREE.Vector3(2,2,1),
new THREE.Vector3(2,3,1),
new THREE.Vector3(3,0,1),
new THREE.Vector3(3,1,1),
new THREE.Vector3(3,2,1),
new THREE.Vector3(3,3,1),
new THREE.Vector3(0,0,2),
new THREE.Vector3(0,1,2),
new THREE.Vector3(0,2,2),
new THREE.Vector3(0,3,2),
new THREE.Vector3(1,0,2),
// new THREE.Vector3(1,1,2),
// new THREE.Vector3(1,2,2),
new THREE.Vector3(1,3,2),
new THREE.Vector3(2,0,2),
// new THREE.Vector3(2,1,2),
// new THREE.Vector3(2,2,2),
new THREE.Vector3(2,3,2),
new THREE.Vector3(3,0,2),
new THREE.Vector3(3,1,2),
new THREE.Vector3(3,2,2),
new THREE.Vector3(3,3,2),
new THREE.Vector3(0,0,3),
new THREE.Vector3(0,1,3),
new THREE.Vector3(0,2,3),
new THREE.Vector3(0,3,3),
new THREE.Vector3(1,0,3),
new THREE.Vector3(1,1,3),
new THREE.Vector3(1,2,3),
new THREE.Vector3(1,3,3),
new THREE.Vector3(2,0,3),
new THREE.Vector3(2,1,3),
new THREE.Vector3(2,2,3),
new THREE.Vector3(2,3,3),
new THREE.Vector3(3,0,3),
new THREE.Vector3(3,1,3),
new THREE.Vector3(3,2,3),
new THREE.Vector3(3,3,3),
]
}
];
var opacity=0.9;
$.getJSON("../json/asdf/cubeCone4.json", function(json) {
console.log(json);
//todo move this to other document
scale=1/0.1875;
var shift=gridSize/2.0;
buildList={
currentZIndex:0,
maxZIndex:json.length,
listZ:[],
done:false,
availablePickup:[],
listToBuild:[]
};
setup={};
setup.nodes=[];
setup.edges=[];
setup.viz={};
setup.viz.colorMaps=[YlGnBu,coolwarm, winter ,jet];
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// todo multiply by 4 as smallest size in cubeCone is 0.25
// y is z and z is y
// shift z by 1 cause sacrificial layer is 0
// shift x and y to not have negative values
for(var i=0;i<json.length;i++){ //for each z layer bin
buildList.listZ.push({
layerZ:json[i][0][0][0].origin[1]*scale+1,
done:false,
currentSizeIndex:0,
maxSizeIndex:json[i].length,
listSize:[]
});
for(var j=0;j<json[i].length;j++){ //for each size bin
buildList.listZ[i].listSize.push({
size:json[i][j][0][0].widths[0]*scale,
layerZ:buildList.listZ[i].layerZ,
done:false,
currentSDFIndex:0,
maxSDFIndex:json[i][j].length,
listSDF:[]
});
for(var k=0;k<json[i][j].length;k++){ //for each sdf bin (signed distance field)
buildList.listZ[i].listSize[j].listSDF.push({
sdfRank:k,
layerZ:buildList.listZ[i].layerZ,
size:buildList.listZ[i].listSize[j].size,
done:false,
currentCubeIndex:0,
maxCubeIndex:json[i][j][k].length,
listCubes:[]
});
for(var l=0;l<json[i][j][k].length;l++){ //for each cube add location (todo check if int)
var stockBuilt=false;
if(buildList.listZ[i].listSize[j].size==1){
stockBuilt=true;
}
buildList.listZ[i].listSize[j].listSDF[k].listCubes.push({
layerZ:buildList.listZ[i].layerZ,
size:buildList.listZ[i].listSize[j].size,
sdfRank:buildList.listZ[i].listSize[j].listSDF[k].sdfRank,
done:false,
stockBuilt:stockBuilt,
stockAssigned:false,
stockPickedUp:false,
position:new THREE.Vector3(
json[i][j][k][l].origin[0]*scale+shift,
json[i][j][k][l].origin[2]*scale+shift,
json[i][j][k][l].origin[1]*scale+1)
});
var nomSize=buildList.listZ[i].listSize[j].size;
var x=json[i][j][k][l].origin[0]*scale;
var y=json[i][j][k][l].origin[1]*scale;
var z=json[i][j][k][l].origin[2]*scale;
// if(true){
if(json[i][j][k][l].origin[2]*scale+nomSize/2.0<0){
setup.nodes.push({
id:"["+nomSize+","+x+","+y+","+z+"]",
position:{
x:x+nomSize/2.0,
y:y+nomSize/2.0,
z:z+nomSize/2.0
},
displacement:{
x:0,
y:0,
z:0
},
nomSize:nomSize,
orgNomSize:nomSize,
viz:opacity
});
if(nomSize==2){
for(var ii=0;ii<voxelIndexList[2].list.length;ii++){
var nomSize1=1;
var x1=x+voxelIndexList[2].list[ii].x;
var y1=y+voxelIndexList[2].list[ii].y;
var z1=z+voxelIndexList[2].list[ii].z;
setup.nodes.push({
id:"["+nomSize1+","+x1+","+y1+","+z1+"]",
position:{
x:x1+nomSize1/2.0,
y:y1+nomSize1/2.0,
z:z1+nomSize1/2.0
},
displacement:{
x:0,
y:0,
z:0
},
nomSize:nomSize1,
orgNomSize:nomSize,
viz:0.0
});
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
}
}
if(nomSize==4){
for(var ii=0;ii<voxelIndexList[4].list.length;ii++){
var nomSize1=1;
var x1=x+voxelIndexList[4].list[ii].x;
var y1=y+voxelIndexList[4].list[ii].y;
var z1=z+voxelIndexList[4].list[ii].z;
setup.nodes.push({
id:"["+nomSize1+","+x1+","+y1+","+z1+"]",
position:{
x:x1+nomSize1/2.0,
y:y1+nomSize1/2.0,
z:z1+nomSize1/2.0
},
displacement:{
x:0,
y:0,
z:0
},
nomSize:nomSize1,
orgNomSize:nomSize,
viz:0.0
});
}
}
}
}
}
}
}
// console.log(buildList);
if(Y>0){
return -1;
}
return Math.min(((16)-Z),(Math.min((Z-(0)),(((10*(16-(Z-(0)))/16)*(10*(16-(Z-(0)))/16)-((X-(0))*(X-(0))+(Y-(0))*(Y-(0))))))));
}
// Graph=drawFromFrep(cone,new THREE.Vector3(0.0,0,0),true);
});
function drawGraph(setup,scale,hierarchical=true){
function getColor(stress){
// console.log(stress)
var val=map(stress,setup.viz.minStress,setup.viz.maxStress,1.0,0.0);
color=interpolateLinearly(val, setup.viz.colorMaps[setup.viz.colorMap]);
return new THREE.Color(color[0],color[1],color[2]).getHex();
}
const gData = {
nodes: setup.nodes.map(node => ({
id: node.id,
px:node.position.x*scale-scale*10,
py:node.position.y*scale-scale,
pz:node.position.z*scale-scale*10,
dx:node.displacement.x*scale,
dy:node.displacement.y*scale,
dz:node.displacement.z*scale,
viz:node.viz,
})),
links: setup.edges
.filter(edge => edge.id)
.map(edge => ({
color:getColor(edge.stress)
}))
};
Graph = ForceGraph3D({ controlType: 'orbit' }).backgroundColor(color2)
(document.getElementById('3d-graph'))
.d3Force('center', null)
.d3Force('charge', null)
.linkOpacity(1.0)
.nodeThreeObject(({ nomSize,viz }) => new THREE.Mesh(
new THREE.BoxGeometry(scale*nomSize*0.9, scale*nomSize*0.9, scale*nomSize*0.9),
new THREE.MeshLambertMaterial({
color: color3,
transparent: true,
})
)
)
.d3Force('box', () => {
gData.nodes.forEach(node => {
node.fx=node.px;
node.fy=node.py;
node.fz=node.pz;
});
})
.cooldownTime(Infinity)
.graphData(gData);
//
var helper = new THREE.GridHelper( scale*2, scale*2 );
helper.position.y = 0;
helper.material.opacity = 0.5;
helper.material.transparent = true;
helper.scale.x=2.0*scale
helper.scale.z=2.0*scale
Graph.scene().add(helper);
// Graph.camera().position.y+=15*scale;
Graph.camera().position.z-=10*scale;
return Graph;
function drawGraph1(setup,scale,hierarchical=true){
function getColor(stress){
// console.log(stress)
var val=map(stress,setup.viz.minStress,setup.viz.maxStress,1.0,0.0);
color=interpolateLinearly(val, setup.viz.colorMaps[setup.viz.colorMap]);
return new THREE.Color(color[0],color[1],color[2]).getHex();
}
const gData = {
nodes: setup.nodes.map(node => ({
id: node.id,
px:node.position.x*scale,
py:node.position.y*scale,
pz:node.position.z*scale,
dx:node.displacement.x*scale,
dy:node.displacement.y*scale,
dz:node.displacement.z*scale,
nomSize:hierarchical? node.nomSize:node.nomSize/3.0,
viz:node.viz,
})),
links: setup.edges
.filter(edge => edge.id)
.map(edge => ({
source: edge.source,
target: edge.target,
color:getColor(edge.stress)
}))
};
Graph = ForceGraph3D({ controlType: 'orbit' }).backgroundColor(color2)
(document.getElementById('3d-graph'))
.d3Force('center', null)
.d3Force('charge', null)
.linkWidth(1.0)
.linkOpacity(1.0)
.nodeThreeObject(({ nomSize,viz }) => new THREE.Mesh(
new THREE.BoxGeometry(scale*nomSize*0.9, scale*nomSize*0.9, scale*nomSize*0.9),
new THREE.MeshLambertMaterial({
color: color3,
transparent: true,
opacity: viz
})
)
)
.d3Force('box', () => {
gData.nodes.forEach(node => {
node.fx=node.px;
node.fy=node.py;
node.fz=node.pz;
});
})
.cooldownTime(Infinity)
.graphData(gData);
var helper = new THREE.GridHelper( scale*2, scale*2 );
helper.position.y = 0;
helper.material.opacity = 0.5;
helper.material.transparent = true;
helper.scale.x=2.0*scale
helper.scale.z=2.0*scale
Graph.scene().add(helper);
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
function drawConstraintBoundingBoxes(setup,scene,scale){
//grid helper
var helper = new THREE.GridHelper( 100, 100 );
helper.position.y = -5.0*scale;
helper.material.opacity = 0.5;
helper.material.transparent = true;
helper.scale.x=2.0*scale
helper.scale.z=2.0*scale
scene.add(helper);
let supports=setup.supports;
let loads=setup.loads;
let mat=setup.materials;
let disps=setup.fixedDisplacements;
if (supports ) {
for (var i=0;i< supports.length;i++) {
let s=supports[i][0];
drawBox(s.min,s.max,color4,scene,scale);
}
}
if (loads ) {
for (var i=0;i< loads.length;i++) {
let l=loads[i][0];
drawBox(l.min,l.max,color7,scene,scale);
}
}
if (disps ) {
for (var i=0;i< disps.length;i++) {
let l=disps[i][0];
drawBox(l.min,l.max,color7,scene,scale);
}
}
if (mat ) {
for (var i=0;i< mat.length;i++) {
let l=mat[i][0];
// console.log(l)
drawBox(l.min,l.max,color5,scene,scale);
}
}
};
function drawBox (min,max,color,scene,scale) {
var box = new THREE.Box3(new THREE.Vector3(min.x*scale,min.y*scale,min.z*scale),new THREE.Vector3(max.x*scale,max.y*scale,max.z*scale));
var helper = new THREE.Box3Helper( box, color );
scene.add( helper );
// todo add name??
};
function getColor(viz,stress){
// console.log(stress)
var val=map(stress,viz.minStress,viz.maxStress,1.0,0.0);
color=interpolateLinearly(val, viz.colorMaps[viz.colorMap]);
return new THREE.Color(color[0],color[1],color[2]).getHex();
}
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
var source="["+nomSize+","+x+","+y+","+z+"]";
for(var i=-1;i<2;i++){
for(var j=-1;j<2;j++){
for(var k=-1;k<2;k++){
if(((i==0&&j==0)||(i==0&&k==0)||(j==0&&k==0))){ //not same voxel and no diagonals
if(!(i==0&&j==0&&k==0)){
var x1=x+i*nomSize;
var y1=y+j*nomSize;
var z1=z+k*nomSize;
var target="["+nomSize+","+x1+","+y1+","+z1+"]";
var node=setup.nodes.find(v => v.id === target);
if(node!==undefined){
if(!(viz==0&&node.viz==0)){
setup.edges.push({ id: 'e'+setup.edges.length, source: source, target: target ,stress:0 });
}
if(orgNomSize!=node.orgNomSize){
setup.edges.push({ id: 'e'+setup.edges.length, source: source, target: target ,stress:0 });
}
}
}
}
}
}
}
}
</script>
</body>