Skip to content
This repository was archived by the owner on Jun 14, 2023. It is now read-only.

Commit df3a841

Browse files
authored
Merge pull request #18 from MetacityTools/dev
Removed skipping, bugfix styling
2 parents 8268371 + 67e2c32 commit df3a841

File tree

8 files changed

+59
-71
lines changed

8 files changed

+59
-71
lines changed

example/App.tsx

Lines changed: 36 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,45 @@
11
import React from 'react'
22
import './App.css'
3-
import { MetacityGL, Extensions } from '../metacitygl/metacitygl';
3+
import { MetacityGL, Utils, Extensions } from '../metacitygl/metacitygl';
44

55
function App() {
66
return (
77
<MetacityGL
8-
//background={0x151d29}
9-
background={0x151515}
10-
target={[-742921, -1043242, 0]}
11-
antialias
12-
bloom
13-
bloomRadius={0.1}
14-
bloomStrength={1}>
15-
<Extensions.MetacityTreeLayer
16-
api="https://data.metacity.cc/pragueLampsDetailTree"
17-
instance="/lamp.glb"
18-
size={2}
19-
pickable
20-
swapDistance={4000}
21-
color={[1.5, 1.0, 0.8]}
22-
tree={{
23-
zOffset: 10,
24-
visualizeTree: false
25-
}}
26-
/>
27-
<Extensions.MetacityTreeLayer
28-
api="https://data.metacity.cc/pragueBuildingTree"
29-
pickable
30-
color={0x444444}
31-
tree={{
32-
//visualizeTree: false
33-
}}
34-
/>
35-
<Extensions.MetacityTreeLayer
36-
api="https://data.metacity.cc/pragueTreesTree"
37-
instance="/tree.glb"
38-
size={1}
39-
swapDistance={4000}
40-
color={0x333333}
41-
tree={{
42-
visualizeTree: false
43-
}}
44-
/>
45-
<Extensions.MetacityTreeLayer
46-
api="https://data.metacity.cc/pragueTerrainTree"
47-
color={0x222222}
48-
tree={{
49-
zOffset: -1
50-
}}
51-
/>
52-
<Extensions.MetacityTreeLayer
53-
api="https://data.metacity.cc/pragueBridgesTree"
54-
color={0x333333}
55-
tree={{
56-
//zOffset: -1
57-
visualizeTree: false
58-
}}
59-
/>
60-
</MetacityGL>
8+
//background={0x151d29}
9+
background={0x151515}
10+
target={[-742921, -1043242, 0]}
11+
antialias>
12+
<Extensions.MetacityTreeLayer
13+
api="https://data.metacity.cc/pragueBuildingTree"
14+
pickable
15+
enableUI
16+
colorPlaceholder={0x202c3d}
17+
styles={[
18+
new Utils.Styles.Style().add(
19+
new Utils.Styles.StyleAttributeRangeExt({
20+
attribute: 'height',
21+
min: 20,
22+
max: 50
23+
})
24+
).useColor([0x04d3ff, 0xFF00ea])
25+
]}
26+
tree={{
27+
zOffset: 5,
28+
visualizeTree: false
29+
}}
30+
>
31+
<div id="legend">
32+
<h2>Prague: Building Heights</h2>
33+
<div id="map">
34+
<div id="colormap"></div>
35+
<div id="labels">
36+
<div>20 m and below</div>
37+
<div>50 m and up</div>
38+
</div>
39+
</div>
40+
</div>
41+
</Extensions.MetacityTreeLayer>
42+
</MetacityGL>
6143
)
6244
}
6345

metacitygl/extensions/metacity/loader/style.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ function computeColorBuffer(ids: Uint8Array, colorBuffer: Uint8Array, colorTable
2828
for (let offset = 0; offset < ids.length; offset += 3) {
2929
id = idToNumber(offset);
3030
color = colorTable.get(id);
31+
3132
if (color) {
32-
colorBuffer[offset] = color[0];
33-
colorBuffer[offset + 1] = color[1];
34-
colorBuffer[offset + 2] = color[2];
33+
colorBuffer[offset] = color[0] * 255;
34+
colorBuffer[offset + 1] = color[1] * 255;
35+
colorBuffer[offset + 2] = color[2] * 255;
3536
}
3637
}
3738
return colorBuffer;

metacitygl/extensions/metacity/loader/worker.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ async function loadModel(message: any) {
2222
const useMetadata = styles !== undefined && styles.length > 0;
2323
const meshASM = new Utils.Assemblers.MeshAssembler(idOffset, useMetadata);
2424

25-
let layerID = 0;
2625
for (let i = 0; i < groups.meshes.length; i++) {
2726
const mesh = groups.meshes[i];
2827
if (!mesh.meta)
2928
mesh.meta = {};
3029
mesh.meta["url"] = url;
31-
mesh.meta["layerID"] = layerID++;
32-
33-
if (!skipObjects.includes(mesh.meta["layerID"]))
30+
//TODO resolve skipping based on metadata
31+
//mesh.meta["layerID"] = layerID++;
32+
//if (!skipObjects.includes(mesh.meta["layerID"]))
3433
meshASM.addMesh(mesh.positions, color, mesh.meta);
3534
}
3635

@@ -40,9 +39,8 @@ async function loadModel(message: any) {
4039
if (!points.meta)
4140
points.meta = {};
4241
points.meta["url"] = url;
43-
points.meta["layerID"] = layerID++;
44-
45-
if (!skipObjects.includes(points.meta["layerID"]))
42+
//points.meta["layerID"] = layerID++;
43+
//if (!skipObjects.includes(points.meta["layerID"]))
4644
pointsASM.addPoints(points.positions, points.meta);
4745
}
4846

metacitygl/utils/assemblers/line.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { vec3 } from "../types";
2-
import { colorHexToArr } from "../utils/color";
2+
import { colorHexToArr255 } from "../utils/color";
33

44

55
//can be used to construst both lines and double-lines
@@ -18,7 +18,7 @@ export class LineAssembler {
1818
//TODO does it have to be byte?
1919
this.colors.push(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255);
2020
if (this.useMetadata) {
21-
const idcolor = colorHexToArr(this.id);
21+
const idcolor = colorHexToArr255(this.id);
2222
this.ids.push(idcolor[0], idcolor[1], idcolor[2]);
2323
this.metadata[this.id++] = metadata;
2424
}

metacitygl/utils/assemblers/mesh.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computeBBox } from "../utils/bbox";
2-
import { colorHexToArr } from "../utils/color";
2+
import { colorHexToArr255 } from "../utils/color";
33
import { computeDots } from "../utils/normals";
44

55

@@ -26,7 +26,7 @@ export class MeshAssembler {
2626
}
2727

2828
if (this.useMetadata) {
29-
const idcolor = colorHexToArr(this.id);
29+
const idcolor = colorHexToArr255(this.id);
3030
for (let i = 0; i < vertexCount; i++) {
3131
this.ids.push(idcolor[0], idcolor[1], idcolor[2]);
3232
}

metacitygl/utils/assemblers/points.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computeBBox } from "../utils/bbox";
2-
import { colorHexToArr } from "../utils/color";
2+
import { colorHexToArr255 } from "../utils/color";
33

44

55
export class PointsAssembler {
@@ -22,7 +22,7 @@ export class PointsAssembler {
2222

2323
if (this.useMetadata) {
2424
const vertexCount = vertices.length / 3;
25-
const idcolor = colorHexToArr(this.id);
25+
const idcolor = colorHexToArr255(this.id);
2626
for (let i = 0; i < vertexCount; i++) {
2727
this.ids.push(idcolor[0], idcolor[1], idcolor[2]);
2828
}

metacitygl/utils/utils/color.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ export function sampleColor(color: Types.Color | Types.Color[], indicator: numbe
2727
return color as Types.Color;
2828
}
2929

30+
export function colorHexToArr255(hex: number): [number, number, number] {
31+
const r = ( hex >> 16 & 255 );
32+
const g = ( hex >> 8 & 255 );
33+
const b = ( hex & 255 );
34+
return [r, g, b];
35+
}
36+
3037
export function colorHexToArr(hex: number): [number, number, number] {
3138
const r = ( hex >> 16 & 255 ) / 255;
3239
const g = ( hex >> 8 & 255 ) / 255;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "metacitygl",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"type": "module",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)