scans and ref image
This commit is contained in:
@@ -15,6 +15,8 @@ export const sceneRegistry = {
|
||||
item: new Set<string>(),
|
||||
slab: new Set<string>(),
|
||||
zone: new Set<string>(),
|
||||
scan: new Set<string>(),
|
||||
guide: new Set<string>(),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -34,3 +34,5 @@ export { SlabSystem } from './systems/slab/slab-system'
|
||||
export { WallSystem } from './systems/wall/wall-system'
|
||||
|
||||
export { isObject } from './utils/types'
|
||||
// Asset storage
|
||||
export { saveAsset, loadAssetUrl } from './lib/asset-storage'
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { get, set } from 'idb-keyval'
|
||||
|
||||
export const ASSET_PREFIX = 'asset_data:'
|
||||
|
||||
// Cache for active object URLs to prevent leaks and flickering
|
||||
const urlCache = new Map<string, string>()
|
||||
|
||||
/**
|
||||
* Save a file to IndexedDB and return a custom protocol URL
|
||||
*/
|
||||
export async function saveAsset(file: File): Promise<string> {
|
||||
const id = crypto.randomUUID()
|
||||
await set(`${ASSET_PREFIX}${id}`, file)
|
||||
return `asset://${id}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a file from IndexedDB and return an object URL
|
||||
* If the URL is not a custom protocol URL, return it as is
|
||||
*/
|
||||
export async function loadAssetUrl(url: string): Promise<string | null> {
|
||||
if (!url) return null
|
||||
|
||||
// If it's already a blob or http URL, return as is
|
||||
if (url.startsWith('blob:') || url.startsWith('http')) {
|
||||
return url
|
||||
}
|
||||
|
||||
// Handle our custom asset protocol
|
||||
if (url.startsWith('asset://')) {
|
||||
const id = url.replace('asset://', '')
|
||||
|
||||
// Check cache first
|
||||
if (urlCache.has(id)) {
|
||||
return urlCache.get(id)!
|
||||
}
|
||||
|
||||
try {
|
||||
const file = await get<File | Blob>(`${ASSET_PREFIX}${id}`)
|
||||
if (!file) {
|
||||
console.warn(`Asset not found: ${id}`)
|
||||
return null
|
||||
}
|
||||
const objectUrl = URL.createObjectURL(file)
|
||||
urlCache.set(id, objectUrl)
|
||||
return objectUrl
|
||||
} catch (error) {
|
||||
console.error('Failed to load asset:', error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy data URLs are returned as is
|
||||
return url
|
||||
}
|
||||
@@ -13,6 +13,8 @@ export { BuildingNode } from './nodes/building'
|
||||
export { CeilingNode } from './nodes/ceiling'
|
||||
|
||||
export { ZoneNode } from './nodes/zone'
|
||||
export { ScanNode } from './nodes/scan'
|
||||
export { GuideNode } from './nodes/guide'
|
||||
export type { AnyNodeId, AnyNodeType } from './types'
|
||||
// Union types
|
||||
export { AnyNode } from './types'
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { z } from 'zod'
|
||||
import { BaseNode, nodeType, objectId } from '../base'
|
||||
|
||||
export const GuideNode = BaseNode.extend({
|
||||
id: objectId('guide'),
|
||||
type: nodeType('guide'),
|
||||
url: z.string(),
|
||||
position: z.tuple([z.number(), z.number(), z.number()]).default([0, 0, 0]),
|
||||
rotation: z.tuple([z.number(), z.number(), z.number()]).default([0, 0, 0]),
|
||||
scale: z.number().default(1),
|
||||
opacity: z.number().min(0).max(100).default(50),
|
||||
})
|
||||
|
||||
export type GuideNode = z.infer<typeof GuideNode>
|
||||
@@ -2,6 +2,8 @@ import dedent from 'dedent'
|
||||
import { z } from 'zod'
|
||||
import { BaseNode, nodeType, objectId } from '../base'
|
||||
import { CeilingNode } from './ceiling'
|
||||
import { GuideNode } from './guide'
|
||||
import { ScanNode } from './scan'
|
||||
import { SlabNode } from './slab'
|
||||
import { WallNode } from './wall'
|
||||
import { ZoneNode } from './zone'
|
||||
@@ -9,7 +11,7 @@ import { ZoneNode } from './zone'
|
||||
export const LevelNode = BaseNode.extend({
|
||||
id: objectId('level'),
|
||||
type: nodeType('level'),
|
||||
children: z.array(z.union([WallNode.shape.id, ZoneNode.shape.id, SlabNode.shape.id, CeilingNode.shape.id])).default([]),
|
||||
children: z.array(z.union([WallNode.shape.id, ZoneNode.shape.id, SlabNode.shape.id, CeilingNode.shape.id, ScanNode.shape.id, GuideNode.shape.id])).default([]),
|
||||
// Specific props
|
||||
level: z.number().default(0),
|
||||
}).describe(
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { z } from 'zod'
|
||||
import { BaseNode, nodeType, objectId } from '../base'
|
||||
|
||||
export const ScanNode = BaseNode.extend({
|
||||
id: objectId('scan'),
|
||||
type: nodeType('scan'),
|
||||
url: z.string(),
|
||||
position: z.tuple([z.number(), z.number(), z.number()]).default([0, 0, 0]),
|
||||
rotation: z.tuple([z.number(), z.number(), z.number()]).default([0, 0, 0]),
|
||||
scale: z.number().default(1),
|
||||
opacity: z.number().min(0).max(100).default(100),
|
||||
})
|
||||
|
||||
export type ScanNode = z.infer<typeof ScanNode>
|
||||
@@ -1,8 +1,10 @@
|
||||
import z from 'zod'
|
||||
import { BuildingNode } from './nodes/building'
|
||||
import { CeilingNode } from './nodes/ceiling'
|
||||
import { GuideNode } from './nodes/guide'
|
||||
import { ItemNode } from './nodes/item'
|
||||
import { LevelNode } from './nodes/level'
|
||||
import { ScanNode } from './nodes/scan'
|
||||
import { SiteNode } from './nodes/site'
|
||||
import { SlabNode } from './nodes/slab'
|
||||
import { WallNode } from './nodes/wall'
|
||||
@@ -17,6 +19,8 @@ export const AnyNode = z.discriminatedUnion('type', [
|
||||
ZoneNode,
|
||||
SlabNode,
|
||||
CeilingNode,
|
||||
ScanNode,
|
||||
GuideNode,
|
||||
])
|
||||
|
||||
export type AnyNode = z.infer<typeof AnyNode>
|
||||
|
||||
Reference in New Issue
Block a user