forked from KhronosGroup/glTF
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from CesiumGS/feature-metadata
Feature metadata extension (EXT_feature_metadata)
- Loading branch information
Showing
68 changed files
with
4,592 additions
and
0 deletions.
There are no files selected for viewing
682 changes: 682 additions & 0 deletions
682
extensions/2.0/Vendor/EXT_feature_metadata/0.0.0/README.md
Large diffs are not rendered by default.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
extensions/2.0/Vendor/EXT_feature_metadata/0.0.0/examples/microcosm/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## Texture Metadata Example: Microcosm | ||
|
||
This glTF example is a mesh that represents a lot of different types of | ||
terrain in one small tile | ||
|
||
This example simulates using per-texel metadata for land cover | ||
classification as well as the Normalized Difference Vegetation Index (NDVI) | ||
values. | ||
|
||
The data here is hand-made until we can get more realistic data. | ||
|
||
### Script to generate metadata | ||
|
||
To generate the metadata buffer, run `node microcosm-metadata.js`. This | ||
will overwrite `microcosm.bin` and print out JSON to add to the bufferViews | ||
of the glTF. |
Binary file added
BIN
+16.1 KB
extensions/2.0/Vendor/EXT_feature_metadata/0.0.0/examples/microcosm/land-cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.27 KB
extensions/2.0/Vendor/EXT_feature_metadata/0.0.0/examples/microcosm/microcosm-metadata.bin
Binary file not shown.
149 changes: 149 additions & 0 deletions
149
extensions/2.0/Vendor/EXT_feature_metadata/0.0.0/examples/microcosm/microcosm-metadata.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
|
||
/** | ||
* Need to know these lengths: | ||
* - total buffer length | ||
* | ||
* - LULC Name bufferView length and offsets | ||
* - LULC Name offsets bufferView length and offsets | ||
* - LULC Color bufferView length and offsets | ||
*/ | ||
|
||
// This is how I mapped the color values in GIMP. Kinda haphazard admittedly. | ||
const landCoverValues = { | ||
0: { | ||
name: "Grassland", | ||
color: [118, 163, 11] | ||
}, | ||
32: { | ||
name: "Rocky Ground", | ||
color: [110, 110, 110] | ||
}, | ||
64: { | ||
name: "Desert", | ||
color: [212, 209, 182] | ||
}, | ||
128: { | ||
name: "River", | ||
color: [82, 173, 204] | ||
}, | ||
208: { | ||
name: "Forest", | ||
color: [50, 84, 51] | ||
}, | ||
255: { | ||
name: "Building", | ||
color: [194, 194, 194] | ||
} | ||
}; | ||
|
||
const unusedLandCover = { | ||
name: "Unused", | ||
color: [0, 0, 0] | ||
}; | ||
|
||
const numberOfLandCoverFeatures = 256; | ||
const sizeOfColor = 3; | ||
|
||
function makeLandCoverColors() { | ||
const bufferLength = numberOfLandCoverFeatures * sizeOfColor; | ||
const buffer = Buffer.alloc(bufferLength); | ||
for (let i = 0; i < numberOfLandCoverFeatures; i++) { | ||
const feature = landCoverValues[i]; | ||
if (feature !== undefined) { | ||
const [r, g, b] = feature.color; | ||
buffer[3 * i] = r; | ||
buffer[3 * i + 1] = g; | ||
buffer[3 * i + 2] = b; | ||
} | ||
|
||
// Otherwise the default color of 0, 0, 0 is used, | ||
// but the buffer is allocated with all 0s so no work is needed here. | ||
} | ||
return buffer; | ||
} | ||
|
||
function makeLandCoverNames() { | ||
const offsets = new Uint32Array(numberOfLandCoverFeatures + 1); | ||
let nameText = ''; | ||
let currentOffset = 0; | ||
for (let i = 0; i < numberOfLandCoverFeatures; i++) { | ||
let feature = landCoverValues[i]; | ||
if (feature === undefined) { | ||
feature = unusedLandCover; | ||
} | ||
|
||
const name = feature.name; | ||
const nameLength = Buffer.byteLength(name, 'utf8'); | ||
|
||
offsets[i] = currentOffset; | ||
currentOffset += nameLength; | ||
|
||
nameText += name; | ||
} | ||
offsets[numberOfLandCoverFeatures] = currentOffset; | ||
|
||
const namesBuffer = Buffer.from(nameText, 'utf8'); | ||
|
||
// Convert from Uint32Array -> Buffer (which is a Uint8Array) | ||
const offsetsBuffer = Buffer.from(offsets.buffer); | ||
return [namesBuffer, offsetsBuffer]; | ||
} | ||
|
||
function makeBufferViews() { | ||
const [landCoverNames, landCoverOffsets] = makeLandCoverNames(); | ||
const landCoverColor = makeLandCoverColors(); | ||
|
||
return [ | ||
{ | ||
name: "LULC Name", | ||
bufferView: landCoverNames | ||
}, | ||
{ | ||
name: "LULC Name Offsets", | ||
bufferView: landCoverOffsets, | ||
}, | ||
{ | ||
name: "LULC Color", | ||
bufferView: landCoverColor | ||
} | ||
] | ||
} | ||
|
||
function makeBinFile() { | ||
const bufferViewInfos = makeBufferViews(); | ||
const bufferViews = []; | ||
const stats = []; | ||
let offset = 0; | ||
for (const bufferViewInfo of bufferViewInfos) { | ||
if (offset % 8 != 0) { | ||
const paddingBytes = 8 - (offset % 8); | ||
console.log(`Offset not aligned, adding ${paddingBytes} of padding`); | ||
const padding = Buffer.alloc(paddingBytes); | ||
bufferViews.push(padding); | ||
offset += paddingBytes; | ||
} | ||
|
||
const bufferView = bufferViewInfo.bufferView; | ||
const byteLength = bufferView.byteLength; | ||
stats.push({ | ||
name: bufferViewInfo.name, | ||
buffer: 1, | ||
byteLength: byteLength, | ||
byteOffset: offset | ||
}); | ||
offset += byteLength; | ||
|
||
bufferViews.push(bufferView); | ||
} | ||
|
||
const buffer = Buffer.concat(bufferViews); | ||
fs.writeFileSync('microcosm-metadata.bin', buffer, 'utf8'); | ||
|
||
console.log(JSON.stringify(stats, undefined, 4)); | ||
console.log('totalLength:', buffer.byteLength); | ||
} | ||
|
||
makeBinFile(); |
Binary file added
BIN
+2.58 MB
extensions/2.0/Vendor/EXT_feature_metadata/0.0.0/examples/microcosm/microcosm.bin
Binary file not shown.
Oops, something went wrong.