Skip to content

Commit f90241f

Browse files
committed
Fix missing asset data in generated graph JSON
1 parent f96841b commit f90241f

File tree

5 files changed

+150
-45
lines changed

5 files changed

+150
-45
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "metafold",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"description": "Metafold SDK for Node.js",
55
"main": "lib/metafold.js",
66
"type": "module",

src/func-types.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export type LineNetworkBvhAsset = Asset
7171
export type Graph = {
7272
operators: {
7373
type: string
74-
parameters?: object
74+
parameters?: {
75+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
76+
[key: string]: any
77+
}
7578
}[]
7679
edges?: {
7780
source: number
@@ -89,8 +92,10 @@ export class Func {
8992
constructor(
9093
readonly type: string,
9194
readonly inputs?: { [key: string]: Func },
92-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
95+
/* eslint-disable @typescript-eslint/no-explicit-any */
96+
readonly assets?: { [key: string]: any },
9397
readonly parameters?: { [key: string]: any },
98+
/* eslint-enable @typescript-eslint/no-explicit-any */
9499
) {}
95100

96101
/**
@@ -159,6 +164,9 @@ export class Func {
159164
})
160165
)
161166
}
167+
if (func.assets) {
168+
operator.parameters = Object.assign(operator.parameters ?? {}, func.assets)
169+
}
162170
const index = g.operators.push(operator) - 1
163171
indices.set(func, index)
164172
}
@@ -183,8 +191,10 @@ export class TypedFunc<T> extends Func {
183191
constructor(
184192
type: string,
185193
inputs?: { [key: string]: Func },
186-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
187-
parameters?: { [key: string]: any },
194+
/* eslint-disable @typescript-eslint/no-explicit-any */
195+
readonly assets?: { [key: string]: any },
196+
readonly parameters?: { [key: string]: any },
197+
/* eslint-enable @typescript-eslint/no-explicit-any */
188198
// Generic parameters are erased unless they are used in the type
189199
private returnType?: T,
190200
) {

src/func.spec.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import type {
77
import {
88
CSGIntersect,
99
GenerateSamplePoints,
10+
LoadVolume,
1011
Redistance,
1112
SampleBox,
1213
SampleSurfaceLattice,
14+
SampleVolume,
1315
Threshold,
1416
} from "./func.js"
15-
import type { Graph } from "./func-types.js"
17+
import type { Graph, VolumeAsset } from "./func-types.js"
1618
import { POINT_SOURCE } from "./func-types.js"
1719

1820

@@ -101,5 +103,54 @@ describe("Func", function() {
101103
)
102104
assert.deepEqual(f.json(source), want)
103105
})
106+
107+
it("should generate a valid shape graph with assets", function() {
108+
const volumeAsset: VolumeAsset = {
109+
file_type: "Raw",
110+
path: "foo.bin",
111+
}
112+
const volume = LoadVolume(volumeAsset, { resolution: [64, 64, 64] })
113+
const f = Threshold(
114+
Redistance(
115+
SampleVolume(source, volume, {
116+
volume_size: [2, 2, 2],
117+
volume_offset: [-1, -1, -1],
118+
}),
119+
),
120+
)
121+
assert.deepEqual(f.json(), {
122+
operators: [
123+
{ type: "Threshold" },
124+
{ type: "Redistance" },
125+
{
126+
type: "SampleVolume",
127+
parameters: {
128+
volume_size: [2, 2, 2],
129+
volume_offset: [-1, -1, -1],
130+
},
131+
},
132+
{
133+
type: "LoadVolume",
134+
parameters: {
135+
volume_data: volumeAsset,
136+
resolution: [64, 64, 64],
137+
},
138+
},
139+
{
140+
type: "GenerateSamplePoints",
141+
parameters: {
142+
size: [2, 2, 2],
143+
resolution: [64, 64, 64],
144+
},
145+
},
146+
],
147+
edges: [
148+
{ source: 1, target: [0, "Samples"] }, // Redistance -> Threshold
149+
{ source: 2, target: [1, "Samples"] }, // SampleVolume -> Redistance
150+
{ source: 4, target: [2, "Points"] }, // GenerateSamplePoints -> SampleVolume
151+
{ source: 3, target: [2, "Volume"] }, // LoadVolume -> SampleVolume
152+
],
153+
})
154+
})
104155
})
105156
})

0 commit comments

Comments
 (0)