Skip to content

Commit

Permalink
Merge pull request #132 from xeokit/support-glb-json-independent-spli…
Browse files Browse the repository at this point in the history
…tting

Support glb json independent splitting
  • Loading branch information
xeolabs authored Feb 13, 2024
2 parents 3dab3f3 + ad50300 commit c55fa1f
Show file tree
Hide file tree
Showing 13 changed files with 12,254 additions and 11,761 deletions.
21 changes: 19 additions & 2 deletions convert2xkt.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,32 @@ 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,

// When converting .gltf source files that are accompanied by metadata JSON
// files, this will cause the metadata JSON files to not be embedded within the XKT output
// files, and instead be output separately. When converting split glTF / GLB models
// and outputting a manifest of split XKT files, the JSON files will be listed in the
// manifest alongside the XKT files.

"externalMetadata": true
},

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

// When converting GLB source files that are accompanied by metadata JSON
// files, this will cause the metadata JSON files to not be embedded within the XKT output
// files, and instead be output separately. When converting split glTF / GLB models
// and outputting a manifest of split XKT files, the JSON files will be listed in the
// manifest alongside the XKT files.

"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: 2 additions & 0 deletions dist/convert2xkt.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27457,6 +27457,8 @@ function convert2xkt({
reject(err);
return;
}
} else {
log(`Not embedding metadata in XKT`);
}

let metaModelJSON;
Expand Down
2 changes: 1 addition & 1 deletion dist/xeokit-convert.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/xeokit-convert.cjs.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit c55fa1f

Please sign in to comment.