Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended package server demo #86

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions demos/data/packageServer/3tzContent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

This example is the same as `./specs/data/combineTilesets/nestedExternal`,
but with the tilesets in `sub0` and `sub1` directories being converted
into 3TZ archives.
31 changes: 31 additions & 0 deletions demos/data/packageServer/3tzContent/externalA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"asset" : {
"version" : "1.1"
},
"geometricError" : 4.0,
"root" : {
"boundingVolume" : {
"box" : [ 0.5, -0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5 ]
},
"geometricError" : 2.0,
"children": [
{
"boundingVolume" : {
"box" : [ 0.5, -0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5 ]
},
"geometricError" : 1.0,
"content": {
"uri": "tileB.glb"
}
}, {
"boundingVolume" : {
"box" : [ 0.5, -0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5 ]
},
"geometricError" : 1.0,
"content": {
"uri": "sub1/externalC.3tz"
}
}
]
}
}
Binary file not shown.
Binary file not shown.
Binary file added demos/data/packageServer/3tzContent/tileA.glb
Binary file not shown.
Binary file added demos/data/packageServer/3tzContent/tileB.glb
Binary file not shown.
39 changes: 39 additions & 0 deletions demos/data/packageServer/3tzContent/tileset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"asset" : {
"version" : "1.1"
},
"geometricError" : 4.0,
"root" : {
"boundingVolume" : {
"box" : [ 0.5, -0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5 ]
},
"geometricError" : 2.0,
"children": [
{
"boundingVolume" : {
"box" : [ 0.5, -0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5 ]
},
"geometricError" : 1.0,
"content": {
"uri": "tileA.glb"
}
}, {
"boundingVolume" : {
"box" : [ 0.5, -0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5 ]
},
"geometricError" : 1.0,
"content": {
"uri": "externalA.json"
}
}, {
"boundingVolume" : {
"box" : [ 0.5, -0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5 ]
},
"geometricError" : 1.0,
"content": {
"uri": "sub0/externalB.3tz"
}
}
]
}
}
111 changes: 111 additions & 0 deletions demos/packageServer/ContentDataTypeUtilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { ContentDataTypes } from "../../src/contentTypes/ContentDataTypes";

/**
* Utility methods for determining default file extensions and MIME
* types for a `ContentDataType`.
*
* These are only used in the package server demo. The functionality
* could later become part of the `contentTypes` package, maybe as
* part of the `ContentDataTypeRegistry`.
*
* @internal
*/
export class ContentDataTypeUtilities {
/**
* A mapping from `ContentDataType` strings to "default" file
* extensions (without the `.` dot)
*/
private static extensions: { [key: string]: string };

/**
* A mapping from `ContentDataType` strings to MIME types
*/
private static mimeTypes: { [key: string]: string };

/**
* Initialize the `extensions` dictionary if it was not
* initialized yet.
*/
private static initializeExtensions() {
if (ContentDataTypeUtilities.extensions !== undefined) {
return;
}
const d: { [key: string]: string } = {};
d[ContentDataTypes.CONTENT_TYPE_GLB] = "glb";
d[ContentDataTypes.CONTENT_TYPE_B3DM] = "b3dm";
d[ContentDataTypes.CONTENT_TYPE_I3DM] = "i3dm";
d[ContentDataTypes.CONTENT_TYPE_CMPT] = "cmpt";
d[ContentDataTypes.CONTENT_TYPE_PNTS] = "pnts";
d[ContentDataTypes.CONTENT_TYPE_GEOM] = "geom";
d[ContentDataTypes.CONTENT_TYPE_VCTR] = "vctr";
d[ContentDataTypes.CONTENT_TYPE_SUBT] = "subtree";
d[ContentDataTypes.CONTENT_TYPE_PNG] = "png";
d[ContentDataTypes.CONTENT_TYPE_JPEG] = "jpg";
d[ContentDataTypes.CONTENT_TYPE_GIF] = "gif";
d[ContentDataTypes.CONTENT_TYPE_GEOJSON] = "geojson";
d[ContentDataTypes.CONTENT_TYPE_3TZ] = "3tz";
d[ContentDataTypes.CONTENT_TYPE_GLTF] = "gltf";
d[ContentDataTypes.CONTENT_TYPE_TILESET] = "json";
ContentDataTypeUtilities.extensions = d;
}

/**
* Initialize the `mimeTypes` dictionary if it was not
* initialized yet.
*/
private static initializeMimeTypes() {
if (ContentDataTypeUtilities.mimeTypes !== undefined) {
return;
}
const d: { [key: string]: string } = {};
d[ContentDataTypes.CONTENT_TYPE_GLB] = "model/gltf-binary";
d[ContentDataTypes.CONTENT_TYPE_B3DM] = "application/octet-stream";
d[ContentDataTypes.CONTENT_TYPE_I3DM] = "application/octet-stream";
d[ContentDataTypes.CONTENT_TYPE_CMPT] = "application/octet-stream";
d[ContentDataTypes.CONTENT_TYPE_PNTS] = "application/octet-stream";
d[ContentDataTypes.CONTENT_TYPE_GEOM] = "text/plain"; // ???
d[ContentDataTypes.CONTENT_TYPE_VCTR] = "application/json"; // ???
d[ContentDataTypes.CONTENT_TYPE_SUBT] = "application/octet-stream";
d[ContentDataTypes.CONTENT_TYPE_PNG] = "image/png";
d[ContentDataTypes.CONTENT_TYPE_JPEG] = "image/jpeg";
d[ContentDataTypes.CONTENT_TYPE_GIF] = "image/gif";
d[ContentDataTypes.CONTENT_TYPE_GEOJSON] = "application/json"; // ???
d[ContentDataTypes.CONTENT_TYPE_3TZ] = "application/octet-stream"; // ???
d[ContentDataTypes.CONTENT_TYPE_GLTF] = "model/gltf+json";
d[ContentDataTypes.CONTENT_TYPE_TILESET] = "application/json";
ContentDataTypeUtilities.mimeTypes = d;
}

/**
* Returns the "default" file extension (without `.` dot) for the
* given content data type, or `undefined` if the given type is
* `undefined` or not known.
*
* @param contentDataType The `ContentDataType` string
* @returns The file extension, without `.` dot
*/
static getFileExtension(
contentDataType: string | undefined
): string | undefined {
if (contentDataType === undefined) {
return undefined;
}
ContentDataTypeUtilities.initializeExtensions();
return ContentDataTypeUtilities.extensions[contentDataType];
}

/**
* Returns the MIME type for the given content data type, or
* `undefined` if the given type is `undefined` or not known.
*
* @param contentDataType The `ContentDataType` string
* @returns The file extension, without `.` dot
*/
static getMimeType(contentDataType: string | undefined): string | undefined {
if (contentDataType === undefined) {
return undefined;
}
ContentDataTypeUtilities.initializeMimeTypes();
return ContentDataTypeUtilities.mimeTypes[contentDataType];
}
}
Loading
Loading