Skip to content

Commit

Permalink
fix(single_mesh): fix single_mesh data sources
Browse files Browse the repository at this point in the history
Fixes #702.
  • Loading branch information
jbms committed Jan 23, 2025
1 parent f343058 commit 18da7fc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 135 deletions.
1 change: 1 addition & 0 deletions src/datasource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ export class DataSourceRegistry extends RefCounted {
): Promise<DataSourceWithRedirectInfo> {
const redirectLog = new Set<string>();
let url: string = options.url;
url = url.trim();
// Trim any trailing "|" characters.
url = url.replace(/\|+$/, "");
let originalCanonicalUrl: string | undefined;
Expand Down
66 changes: 0 additions & 66 deletions src/datasource/obj/frontend.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/datasource/obj/register_default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
registerProvider,
} from "#src/datasource/default_provider.js";
import { KvStoreBasedDataSourceLegacyUrlAdapter } from "#src/datasource/index.js";
import { ObjDataSource } from "#src/datasource/obj/frontend.js";
import { SingleMeshDataSource } from "#src/single_mesh/frontend.js";

const provider = new ObjDataSource();
const provider = new SingleMeshDataSource("obj", "Wavefront OBJ mesh");
registerKvStoreBasedDataProvider(provider);
registerProvider(new KvStoreBasedDataSourceLegacyUrlAdapter(provider));
65 changes: 0 additions & 65 deletions src/datasource/vtk/frontend.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/datasource/vtk/register_default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
registerProvider,
} from "#src/datasource/default_provider.js";
import { KvStoreBasedDataSourceLegacyUrlAdapter } from "#src/datasource/index.js";
import { VtkDataSource } from "#src/datasource/vtk/frontend.js";
import { SingleMeshDataSource } from "#src/single_mesh/frontend.js";

const provider = new VtkDataSource();
const provider = new SingleMeshDataSource("vtk", "VTK mesh");
registerKvStoreBasedDataProvider(provider);
registerProvider(new KvStoreBasedDataSourceLegacyUrlAdapter(provider));
48 changes: 48 additions & 0 deletions src/single_mesh/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ import {
TextureFormat,
} from "#src/webgl/texture_access.js";
import { SharedObject } from "#src/worker_rpc.js";
import type {
DataSource,
GetKvStoreBasedDataSourceOptions,
KvStoreBasedDataSourceProvider,
} from "#src/datasource/index.js";
import { ensureEmptyUrlSuffix } from "#src/kvstore/url.js";
import {
makeCoordinateSpace,
makeIdentityTransform,
} from "#src/coordinate_transform.js";

const DEFAULT_FRAGMENT_MAIN = `void main() {
emitGray();
Expand Down Expand Up @@ -681,3 +691,41 @@ export async function getSingleMeshSource(
parameters: { meshSourceUrl: url, info },
});
}

export class SingleMeshDataSource implements KvStoreBasedDataSourceProvider {
constructor(
public scheme: string,
public description: string,
) {}

get singleFile() {
return true;
}

async get(options: GetKvStoreBasedDataSourceOptions): Promise<DataSource> {
ensureEmptyUrlSuffix(options.url);
const meshSource = await getSingleMeshSource(
options.registry.sharedKvStoreContext,
`${options.url.scheme}://${options.kvStoreUrl}`,
options,
);
const modelSpace = makeCoordinateSpace({
rank: 3,
names: ["x", "y", "z"],
units: ["m", "m", "m"],
scales: Float64Array.of(1e-9, 1e-9, 1e-9),
});
const dataSource: DataSource = {
canonicalUrl: `${options.kvStoreUrl}|${options.url.scheme}:`,
modelTransform: makeIdentityTransform(modelSpace),
subsources: [
{
id: "default",
default: true,
subsource: { singleMesh: meshSource },
},
],
};
return dataSource;
}
}

0 comments on commit 18da7fc

Please sign in to comment.