Skip to content

Commit

Permalink
[FEATURE] Add externalMetadata option for glTF and GLB #130
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Feb 9, 2024
1 parent 3dab3f3 commit 50c11ed
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
8 changes: 6 additions & 2 deletions convert2xkt.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,19 @@ module.exports = {
// (i.e. more draw calls). We recommend using the default value unless you get
// precision problems when rendering (i.e. jittering, or misalignment of objects).

"minTileSize": 200
"minTileSize": 200,

"externalMetadata": true
},
"glb": {
"reuseGeometries": true,
"includeTextures": true,
"includeNormals": false,
// "includeTypes":[],
"excludeTypes": [],
"minTileSize": 200
"minTileSize": 200,

"externalMetadata": true
},

//----------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions convert2xkt.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@
"includeTextures": true,
"includeNormals": false,
"excludeTypes": [],
"minTileSize": 200
"minTileSize": 200,
"externalMetadata": true
},
"glb": {
"reuseGeometries": true,
"includeTextures": true,
"includeNormals": false,
"excludeTypes": [],
"minTileSize": 200
"minTileSize": 200,
"externalMetadata": true
},
"json": {
"center": false,
Expand Down
27 changes: 15 additions & 12 deletions convert2xkt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const defaultConfigs = require(`./convert2xkt.conf.js`);

const WebIFC = require("web-ifc/web-ifc-api-node.js");
const path = require("path");
const { createValidator } = require("@typeonly/validator");
const {createValidator} = require("@typeonly/validator");

// const validator = createValidator({
// bundle: require("./types.to.json")
Expand Down Expand Up @@ -44,8 +44,6 @@ const options = program.opts();

let configs = defaultConfigs;



if (options.source === undefined && options.sourcemanifest === undefined) {
console.error('[convert2xkt] [ERROR]: Please specify path to source file or manifest.');
program.help();
Expand Down Expand Up @@ -107,11 +105,6 @@ async function main() {
process.exit(1);
}

if (manifest.metadataOutFiles && numInputFiles !== manifest.metadataOutFiles.length) {
console.error(`[convert2xkt] [ERROR]: Input manifest invalid - length of gltfOutFiles and metadataOutFiles don't match`);
process.exit(1);
}

const outputDir = getBasePath(options.output).trim();
if (outputDir !== "" && !fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, {recursive: true});
Expand All @@ -132,26 +125,36 @@ async function main() {
converterApplication: "convert2xkt",
converterApplicationVersion: `v${npmPackage.version}`,
conversionDate: formatDate(new Date()),
outputDir: outputDir,
outputDir,
xktFiles: []
};

const sourceConfigs = configs.sourceConfigs || {};
const formatConfig = sourceConfigs["gltf"] || configs["glb"] || {};
const externalMetadata = (!!formatConfig.externalMetadata);
if (externalMetadata) {
xktManifest.metaModelFiles = [];
for (let i = 0, len = manifest.metadataOutFiles.length; i < len; i++) {
const metadataSource = manifest.metadataOutFiles[i];
xktManifest.metaModelFiles.push(metadataSource.substring(metadataSource.lastIndexOf('/') + 1));
}
}

let i = 0;

const convertNextFile = () => {

const source = manifest.gltfOutFiles[i];
const metaModelSource = manifest.metadataOutFiles ? manifest.metadataOutFiles[i] : null;
const metaModelSource = (i < manifest.metadataOutFiles.length) ? manifest.metadataOutFiles[i] : null;
const outputFileName = getFileNameWithoutExtension(source);

const outputFileNameXKT = `${outputFileName}.xkt`;

convert2xkt({
WebIFC,
configs,
source,
format: "gltf",
metaModelSource,
metaModelSource: (!externalMetadata) ? metaModelSource : null,
output: path.join(outputDir, outputFileNameXKT),
includeTypes: options.include ? options.include.slice(",") : null,
excludeTypes: options.exclude ? options.exclude.slice(",") : null,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xeokit/xeokit-convert",
"version": "1.1.15-beta-1",
"version": "1.1.15-beta-2",
"description": "JavaScript utilities to create .XKT files",
"main": "index.js",
"bin": "/convert2xkt.js",
Expand Down
2 changes: 2 additions & 0 deletions src/convert2xkt.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ function convert2xkt({
reject(err);
return;
}
} else {
log(`Not embedding metadata in XKT`);
}

let metaModelJSON;
Expand Down

0 comments on commit 50c11ed

Please sign in to comment.