Skip to content

Commit 067f852

Browse files
committed
add basic merge 3d layer (#14)
1 parent c3d658e commit 067f852

20 files changed

+1184
-27
lines changed

examples/acgan/acganGen.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127

128128
model.init(function() {
129129

130+
130131
$("#loadingPad").hide();
131132

132133
});

src/assets/image/Plus.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/assets/image/plus.png

2.01 KB
Loading

src/elements/CloseButton.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MinAlpha } from "../utils/Constant";
2-
import { CloseData } from "../assets/image/CloseData";
2+
import { TextureProvider } from "../utils/TextureProvider";
33

44
function CloseButton(size, unitLength, position, color) {
55

@@ -25,7 +25,7 @@ CloseButton.prototype = {
2525

2626
init: function() {
2727

28-
let texture = new THREE.TextureLoader().load( CloseData );
28+
let texture = new THREE.TextureLoader().load( TextureProvider.getTexture("close") );
2929

3030
let materialSide = new THREE.MeshBasicMaterial( { color: this.color, opacity: MinAlpha, transparent: true } );
3131
let materialTop = new THREE.MeshBasicMaterial( { color: this.color, alphaMap: texture, transparent: true } );

src/elements/MergedAggregation.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import { MinAlpha } from "../utils/Constant";
2+
import { FrameColor } from "../utils/Constant";
3+
import { colorUtils } from "../utils/ColorUtils";
4+
import { RenderPreprocessor } from "../utils/RenderPreprocessor";
5+
import { TextureProvider } from "../utils/TextureProvider";
6+
7+
function MergedAggregation(operator, width, height, actualWidth, actualHeight, depth, color) {
8+
9+
this.operator = operator;
10+
this.width = width;
11+
this.height = height;
12+
this.actualWidth = actualWidth;
13+
this.actualHeight = actualHeight;
14+
this.depth = depth;
15+
16+
this.color = color;
17+
18+
this.cube = undefined;
19+
this.aggregationElement = undefined;
20+
21+
this.dataArray = undefined;
22+
this.dataTexture = undefined;
23+
24+
this.dataMaterial = undefined;
25+
this.clearMaterial = undefined;
26+
27+
this.init();
28+
29+
}
30+
31+
MergedAggregation.prototype = {
32+
33+
init: function() {
34+
35+
let amount = this.width * this.height;
36+
let data = new Uint8Array(amount);
37+
this.dataArray = data;
38+
let dataTex = new THREE.DataTexture(data, this.width, this.height, THREE.LuminanceFormat, THREE.UnsignedByteType);
39+
this.dataTexture = dataTex;
40+
41+
dataTex.magFilter = THREE.NearestFilter;
42+
dataTex.needsUpdate = true;
43+
44+
let material = new THREE.MeshBasicMaterial({ color: this.color, alphaMap: dataTex, transparent: true });
45+
46+
let geometry = new THREE.BoxBufferGeometry(this.actualWidth, this.depth, this.actualHeight);
47+
48+
let basicMaterial = new THREE.MeshBasicMaterial({
49+
color: this.color, opacity: MinAlpha, transparent: true
50+
});
51+
52+
let materials = [
53+
basicMaterial,
54+
basicMaterial,
55+
material,
56+
material,
57+
basicMaterial,
58+
basicMaterial
59+
];
60+
61+
this.dataMaterial = materials;
62+
63+
let operatorTexture = new THREE.TextureLoader().load( TextureProvider.getTexture(this.operator) );
64+
let operatorMaterial = new THREE.MeshBasicMaterial( { color: this.color, alphaMap: operatorTexture, transparent: true} );
65+
66+
let clearMaterial = [
67+
basicMaterial,
68+
basicMaterial,
69+
operatorMaterial,
70+
operatorMaterial,
71+
basicMaterial,
72+
basicMaterial
73+
];
74+
75+
this.clearMaterial = clearMaterial;
76+
77+
let cube = new THREE.Mesh(geometry, materials);
78+
79+
cube.position.set(0, 0, 0);
80+
cube.elementType = "aggregationElement";
81+
cube.clickable = true;
82+
cube.hoverable = true;
83+
84+
this.cube = cube;
85+
86+
let edgesGeometry = new THREE.EdgesGeometry(geometry);
87+
let edgesLine = new THREE.LineSegments(edgesGeometry, new THREE.LineBasicMaterial({
88+
color: FrameColor
89+
}));
90+
91+
let aggregationGroup = new THREE.Object3D();
92+
aggregationGroup.add(cube);
93+
aggregationGroup.add(edgesLine);
94+
95+
this.aggregationElement = aggregationGroup;
96+
97+
this.clear();
98+
},
99+
100+
getElement: function() {
101+
return this.aggregationElement;
102+
},
103+
104+
setLayerIndex: function(layerIndex) {
105+
this.cube.layerIndex = layerIndex;
106+
},
107+
108+
clear: function() {
109+
110+
let zeroValue = new Int8Array(this.width * this.height);
111+
let colors = colorUtils.getAdjustValues(zeroValue);
112+
113+
this.updateVis(colors);
114+
this.cube.material = this.clearMaterial;
115+
116+
},
117+
118+
updateVis: function(colors) {
119+
120+
let renderColor = RenderPreprocessor.preProcessFmColor(colors, this.width, this.height);
121+
122+
for (let i = 0; i < renderColor.length; i++) {
123+
this.dataArray[i] = renderColor[i] * 255;
124+
}
125+
126+
this.dataTexture.needsUpdate = true;
127+
this.cube.material = this.dataMaterial;
128+
129+
}
130+
131+
};
132+
133+
export { MergedAggregation };

0 commit comments

Comments
 (0)