Skip to content
Merged
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
17 changes: 15 additions & 2 deletions packages/core/src/contracts/reference-inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,13 @@ export const METADATA_REFERENCES: readonly ExistingReference[] = [
),
meta('floorPlanUrl', { ...policy('asset', 'content', 'freeze', 'keep') }),
...(
['expressID', 'globalId', 'hostWallExpressID', 'ifcSimplification.mergedExpressIDs[]'] as const
[
'expressID',
'globalId',
'hostWallExpressID',
'ifcHostExpressID',
'ifcSimplification.mergedExpressIDs[]',
] as const
).map((key) =>
meta(key, {
...policy('source', 'content', 'freeze', 'keep'),
Expand All @@ -852,6 +858,10 @@ export const METADATA_REFERENCES: readonly ExistingReference[] = [
targetKinds: ['slab'],
note: 'The plate whose manual hole a floor opening was converted from.',
}),
meta('pascalNodeId', {
...policy('source', 'content', 'freeze', 'strip'),
note: 'Import provenance: the Pascal node id an IFC element carried in its Pascal property set, so a re-import keeps identity.',
}),
meta('sourceIds[]', {
...policy('source', 'content', 'freeze', 'strip'),
note: 'Import provenance: the source element ids an importer recorded (the /next converter writes them); find_nodes filters on them.',
Expand Down Expand Up @@ -879,6 +889,8 @@ export const METADATA_NON_REFERENCES: readonly { path: string; reason: string }[
'floorReassignmentHeight',
'footprintApproximated',
'generatedBy',
'ifcDerived',
'ifcSplit',
'isFloorplanPreview',
'isNew',
'isTransient',
Expand Down Expand Up @@ -927,8 +939,9 @@ export const METADATA_NON_REFERENCES: readonly { path: string; reason: string }[
...described('IFC attribute copy: a value or IFC label, not an id.', [
'elevation',
'height',
'thickness',
'sillHeight',
'sourceColor',
'typeName',
'polygon',
'material',
'materialLayers',
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/store/derived-writer-allowlist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const ALLOWLIST = new Set([
// Load migrations mint the same construction for scenes saved before it.
'packages/core/src/utils/room-zone-migration.ts',
'packages/core/src/utils/floor-plate-migration.ts',
// The IFC importer hands the loader plates and ceilings already linked to
// their rooms; the load migrations and the kernel then re-derive them.
'packages/ifc-converter/src/room-first.ts',
])

const MARKERS = [/\bboundary:\s*'auto'/, /\bautoFromWalls:\s*true/]
Expand Down
1 change: 1 addition & 0 deletions packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@dnd-kit/utilities": "^3.2.2",
"@iconify/react": "^6.0.2",
"@number-flow/react": "^0.6.0",
"@pascal-app/ifc-converter": "^1.0.3",
"@pascal-app/lingo": "^0.2.0",
"@radix-ui/react-alert-dialog": "^1.1.15",
"@radix-ui/react-context-menu": "^2.2.16",
Expand Down
32 changes: 28 additions & 4 deletions packages/editor/src/components/editor/export-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { useEffect } from 'react'
import * as THREE from 'three'
import { OBJExporter } from 'three/examples/jsm/exporters/OBJExporter.js'
import { STLExporter } from 'three/examples/jsm/exporters/STLExporter.js'
import { exportSceneToGlb, nextFrames, prepareSceneForExport } from '../../lib/glb-export'
import {
exportSceneToGlb,
prepareSceneForExport,
waitForExportGeometry,
} from '../../lib/glb-export'
import { exportPreparedSceneToIfc, ifcFileName } from '../../lib/ifc-export'
import { exportSceneLevelsForPrint } from '../../lib/level-print-export'
import type { ModelExport, ModelExportArtifact } from '../../lib/model-export'
import {
Expand Down Expand Up @@ -51,7 +56,10 @@ export function ExportManager() {
const setModelExport = useEditor((state) => state.setModelExport)

useEffect(() => {
const exportFn: ModelExport = async (format = 'glb', options = {}) => {
const exportFn: ModelExport = async (format = 'glb', requested = {}) => {
// Resolve once: scene preparation prunes hidden nodes by default, and the
// IFC writer must drop the same nodes it rebuilds parametrically.
const options = { ...requested, onlyVisible: requested.onlyVisible ?? true }
// Find the scene renderer group by name
const sceneGroup = scene.getObjectByName('scene-renderer')
if (!sceneGroup) {
Expand All @@ -67,7 +75,7 @@ export function ExportManager() {
// without it every plant exports as its raycast collider, a white box).
useViewer.getState().setExporting(true)
try {
await nextFrames()
await waitForExportGeometry(useScene.getState().nodes, options)

if (format === 'glb') {
const warnings: string[] = []
Expand Down Expand Up @@ -100,7 +108,7 @@ export function ExportManager() {
try {
prepared = prepareSceneForExport(sceneGroup, nodes, {
...options,
requireSynchronousBake: format === 'stl' || format === 'obj',
requireSynchronousBake: format === 'stl' || format === 'obj' || format === 'ifc',
})
} finally {
restoreLevels()
Expand Down Expand Up @@ -206,6 +214,22 @@ export function ExportManager() {
return finishArtifact(blob, `model_${date}.stl`, options.download)
}

if (format === 'ifc') {
const { data, warnings } = exportPreparedSceneToIfc(exportScene, nodes, {
projectName: options.projectName,
onlyVisible: options.onlyVisible,
excludedNodeTypes: options.excludedNodeTypes,
})
const blob = new Blob([data], { type: 'application/x-step' })
return finishArtifact(
blob,
ifcFileName(options.projectName, `model_${date}`),
options.download,
undefined,
warnings,
)
}

if (format === 'obj') {
const exporter = new OBJExporter()
const result = exporter.parse(exportScene)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const MODEL_EXPORT_FORMATS = [
{ format: 'usdz', label: 'USDZ' },
{ format: 'stl', label: 'STL' },
{ format: 'obj', label: 'OBJ' },
{ format: 'ifc', label: 'IFC' },
] as const

type ModelExportFormat = (typeof MODEL_EXPORT_FORMATS)[number]['format']
Expand Down Expand Up @@ -688,6 +689,7 @@ export function SettingsPanel({
setModelExportWarning(null)
try {
const artifact = await modelExport(format, {
projectName,
onlyVisible: exportOnlyVisible,
excludedNodeTypes,
includedPresentationIds:
Expand Down Expand Up @@ -903,7 +905,7 @@ export function SettingsPanel({
<legend className="px-1 font-medium text-sm">Include in file</legend>
<p className="text-muted-foreground text-xs">
Choose which procedural content is baked into model files. GLB and USDZ use the
textured portable path; STL and OBJ remain geometry-only.
textured portable path; STL, OBJ and IFC remain geometry-only.
</p>
{exportableNodeTypes.length > 0 ? (
<div className="space-y-2 pt-1">
Expand Down
90 changes: 90 additions & 0 deletions packages/editor/src/lib/export-geometry-wait.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
import {
type AnyNode,
type AnyNodeDefinition,
DoorNode,
nodeRegistry,
registerNode,
sceneRegistry,
} from '@pascal-app/core'
import * as THREE from 'three'
import { nodesAwaitingExportGeometry, waitForExportGeometry } from './glb-export'

const node = (id: string, type: string, fields: Record<string, unknown> = {}) =>
({
object: 'node',
id,
type,
parentId: 'level_a',
visible: true,
metadata: {},
...fields,
}) as unknown as AnyNode

const definition = (kind: string, extra: Record<string, unknown> = {}) =>
({
kind,
schemaVersion: 1,
schema: DoorNode,
category: 'utility',
defaults: () => ({}) as never,
capabilities: {},
bake: 'replace',
...extra,
}) as AnyNodeDefinition

let restoreRegistry: () => void

beforeEach(() => {
restoreRegistry = nodeRegistry._snapshot()
registerNode(definition('test:plant'))
registerNode(definition('test:baked', { bakeGeometry: () => new THREE.Group() }))
})

afterEach(() => {
restoreRegistry()
sceneRegistry.clear()
})

// Live objects as the editor registers them: still empty, i.e. the export
// geometry has not mounted.
function mount(ids: string[]) {
for (const id of ids) sceneRegistry.nodes.set(id, new THREE.Group())
}

describe('waitForExportGeometry', () => {
const nodes: Record<string, AnyNode> = {
level_a: node('level_a', 'level', { parentId: null }),
plant_a: node('plant_a', 'test:plant'),
plant_hidden: node('plant_hidden', 'test:plant', { visible: false }),
baked_a: node('baked_a', 'test:baked'),
}

test('waits only for included collective kinds that mount their own geometry', () => {
mount(['plant_a', 'plant_hidden', 'baked_a'])
expect(nodesAwaitingExportGeometry(nodes)).toEqual(['plant_a'])
expect(nodesAwaitingExportGeometry(nodes, { onlyVisible: false })).toEqual([
'plant_a',
'plant_hidden',
])
expect(nodesAwaitingExportGeometry(nodes, { excludedNodeTypes: ['test:plant'] })).toEqual([])
sceneRegistry.nodes.get('plant_a')!.add(new THREE.Mesh())
expect(nodesAwaitingExportGeometry(nodes)).toEqual([])
})

test('times out on its own timer when geometry never mounts and frames never run', async () => {
mount(['plant_a'])
const started = Date.now()
await waitForExportGeometry(nodes, {}, 300)
const elapsed = Date.now() - started
expect(elapsed).toBeGreaterThanOrEqual(280)
expect(elapsed).toBeLessThan(1500)
})

test('returns as soon as nothing is pending', async () => {
mount(['plant_a', 'baked_a'])
const started = Date.now()
await waitForExportGeometry(nodes, { excludedNodeTypes: ['test:plant'] }, 5_000)
expect(Date.now() - started).toBeLessThan(1_000)
})
})
Loading
Loading