Merge branch 'main' of github.com:sudhir9297/editor into feat/wall-room-creation
This commit is contained in:
@@ -38,6 +38,16 @@ export {
|
||||
wallTouchesOthers,
|
||||
} from './lib/space-detection'
|
||||
export { baseMaterial, glassMaterial } from './materials'
|
||||
export {
|
||||
getCatalogMaterialById,
|
||||
getLibraryMaterialIdFromRef,
|
||||
getMaterialPresetByRef,
|
||||
getMaterialsForTarget,
|
||||
LIBRARY_MATERIAL_REF_PREFIX,
|
||||
MATERIAL_CATALOG,
|
||||
type MaterialCatalogItem,
|
||||
toLibraryMaterialRef,
|
||||
} from './material-library'
|
||||
export * from './schema'
|
||||
export {
|
||||
type ControlValue,
|
||||
@@ -59,9 +69,24 @@ export {
|
||||
getWallPlanFootprint,
|
||||
getWallThickness,
|
||||
} from './systems/wall/wall-footprint'
|
||||
export {
|
||||
getClampedWallCurveOffset,
|
||||
getMaxWallCurveOffset,
|
||||
getWallChordFrame,
|
||||
getWallCurveFrameAt,
|
||||
getWallCurveLength,
|
||||
getWallMidpointHandlePoint,
|
||||
getWallStraightSnapOffset,
|
||||
getWallSurfacePolygon,
|
||||
isCurvedWall,
|
||||
normalizeWallCurveOffset,
|
||||
sampleWallCenterline,
|
||||
} from './systems/wall/wall-curve'
|
||||
export {
|
||||
calculateLevelMiters,
|
||||
getWallMiterBoundaryPoints,
|
||||
type Point2D,
|
||||
type WallMiterBoundaryPoints,
|
||||
pointToKey,
|
||||
type WallMiterData,
|
||||
} from './systems/wall/wall-mitering'
|
||||
|
||||
@@ -0,0 +1,627 @@
|
||||
import {
|
||||
type MaterialPresetPayload,
|
||||
type MaterialTarget,
|
||||
MaterialTarget as MaterialTargetSchema,
|
||||
} from './schema/material'
|
||||
|
||||
export type MaterialCatalogItem = {
|
||||
id: string
|
||||
label: string
|
||||
description?: string
|
||||
targets: MaterialTarget[]
|
||||
previewThumbnailUrl?: string
|
||||
previewColor?: string
|
||||
preset: MaterialPresetPayload
|
||||
}
|
||||
|
||||
const WALL_TARGETS: MaterialTarget[] = [
|
||||
MaterialTargetSchema.enum.wall,
|
||||
]
|
||||
|
||||
const SLAB_TARGETS: MaterialTarget[] = [
|
||||
MaterialTargetSchema.enum.slab,
|
||||
]
|
||||
|
||||
const WALL_AND_SLAB_TARGETS: MaterialTarget[] = [
|
||||
MaterialTargetSchema.enum.wall,
|
||||
MaterialTargetSchema.enum.slab,
|
||||
]
|
||||
|
||||
const STAIR_TARGETS: MaterialTarget[] = [
|
||||
MaterialTargetSchema.enum.stair,
|
||||
MaterialTargetSchema.enum['stair-segment'],
|
||||
]
|
||||
|
||||
const STAIR_AND_FENCE_TARGETS: MaterialTarget[] = [
|
||||
...STAIR_TARGETS,
|
||||
MaterialTargetSchema.enum.fence,
|
||||
]
|
||||
|
||||
const ROOF_TARGETS: MaterialTarget[] = [
|
||||
MaterialTargetSchema.enum.roof,
|
||||
MaterialTargetSchema.enum['roof-segment'],
|
||||
]
|
||||
|
||||
const CEILING_TARGETS: MaterialTarget[] = [
|
||||
MaterialTargetSchema.enum.ceiling,
|
||||
]
|
||||
|
||||
export const MATERIAL_CATALOG: MaterialCatalogItem[] = [
|
||||
{
|
||||
id: 'wall-wood1',
|
||||
label: 'Wood',
|
||||
description: 'Warm wood finish',
|
||||
targets: [...WALL_TARGETS, ...SLAB_TARGETS, ...STAIR_AND_FENCE_TARGETS],
|
||||
previewThumbnailUrl: '/material/wood1/wood1_thumbnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/wood1/albedoMap_basecolor.jpg',
|
||||
normalMap: '/material/wood1/normalMap_normal.jpg',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.575,
|
||||
metalness: 0,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'wall-wood2',
|
||||
label: 'Wood',
|
||||
description: 'Textured wood finish',
|
||||
targets: [...WALL_TARGETS, ...SLAB_TARGETS, ...STAIR_AND_FENCE_TARGETS],
|
||||
previewThumbnailUrl: '/material/wood2/wood2_thumbnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/wood2/albedoMap_Wood.jpg',
|
||||
normalMap: '/material/wood2/normalMap_Wood.jpg',
|
||||
aoMap: '/material/wood2/aoMap_Wood.jpg',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.467,
|
||||
metalness: 0,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 2,
|
||||
normalScaleY: 2,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 2,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'wall-wood3',
|
||||
label: 'Wood',
|
||||
description: 'Knotted timber finish',
|
||||
targets: [...WALL_TARGETS, ...SLAB_TARGETS, ...STAIR_AND_FENCE_TARGETS],
|
||||
previewThumbnailUrl: '/material/wood3/wood3_thumbnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/wood3/albedoMap_knotted-timber.jpg',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.489,
|
||||
metalness: 0,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 0.2,
|
||||
normalScaleY: 0.2,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 2,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'wall-wood4',
|
||||
label: 'Wood',
|
||||
description: 'Oak stretcher finish',
|
||||
targets: [...WALL_TARGETS, ...SLAB_TARGETS, ...STAIR_AND_FENCE_TARGETS],
|
||||
previewThumbnailUrl: '/material/wood4/wood4_thumbnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/wood4/albedoMap_oak-stretcher.jpg',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.378,
|
||||
metalness: 0,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'wall-wood5',
|
||||
label: 'Wood',
|
||||
description: 'Rich grain wood finish',
|
||||
targets: [...WALL_TARGETS, ...SLAB_TARGETS, ...STAIR_AND_FENCE_TARGETS],
|
||||
previewThumbnailUrl: '/material/wood5/wood5_thumnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/wood5/albedoMap_3_base_color.webp',
|
||||
normalMap: '/material/wood5/normalMap_3_normal.jpg',
|
||||
aoMap: '/material/wood5/aoMap_3_ao.jpg',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.6,
|
||||
metalness: 0,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 10,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'wall-granite1',
|
||||
label: 'Granite',
|
||||
description: 'Polished granite finish',
|
||||
targets: SLAB_TARGETS,
|
||||
previewThumbnailUrl: '/material/granite1/granite_thumbnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/granite1/albedoMap_Granite.jpg',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.189,
|
||||
metalness: 0,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'wall-marble1',
|
||||
label: 'Marble',
|
||||
description: 'Smooth marble finish',
|
||||
targets: [...SLAB_TARGETS, ...STAIR_AND_FENCE_TARGETS],
|
||||
previewThumbnailUrl: '/material/marble1/marble1_thumbnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/marble1/albedoMap_marble.jpg',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.133,
|
||||
metalness: 0,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'wall-marble2',
|
||||
label: 'Marble',
|
||||
description: 'Soft marble finish',
|
||||
targets: [...SLAB_TARGETS, ...STAIR_AND_FENCE_TARGETS],
|
||||
previewThumbnailUrl: '/material/marble2/marble2_thumbnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/marble2/albedoMap_marble.jpg',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.122,
|
||||
metalness: 0,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'wall-parquet1',
|
||||
label: 'Parquet',
|
||||
description: 'Parquet wood finish',
|
||||
targets: SLAB_TARGETS,
|
||||
previewThumbnailUrl: '/material/parquet1/parquet_thumnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/parquet1/albedoMap_parquet.jpg',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.644,
|
||||
metalness: 0.4,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'wall-parquet2',
|
||||
label: 'Parquet',
|
||||
description: 'Soft parquet finish',
|
||||
targets: SLAB_TARGETS,
|
||||
previewThumbnailUrl: '/material/parquet2/parquet2_thumbnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/parquet2/albedoMap_parquet.jpg',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.6,
|
||||
metalness: 0,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'wall-wallpaper1',
|
||||
label: 'Wallpaper',
|
||||
description: 'Soft wallpaper finish',
|
||||
targets: WALL_TARGETS,
|
||||
previewThumbnailUrl: '/material/wallpaper1/wallpaper1_thumbnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/wallpaper1/albedoMap_1.webp',
|
||||
normalMap: '/material/wallpaper1/normalMap_NormalMap.webp',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.911,
|
||||
metalness: 0,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'wall-wallpaper2',
|
||||
label: 'Wallpaper',
|
||||
description: 'Decorative wallpaper finish',
|
||||
targets: WALL_TARGETS,
|
||||
previewThumbnailUrl: '/material/wallpaper2/wallpaper2_thumnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/wallpaper2/albedoMap_5.webp',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.889,
|
||||
metalness: 0.255,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'wall-wallpaper3',
|
||||
label: 'Wallpaper',
|
||||
description: 'Patterned wallpaper finish',
|
||||
targets: WALL_TARGETS,
|
||||
previewThumbnailUrl: '/material/wallpaper3/wallpaper3_thumbnail.webp',
|
||||
preset: {
|
||||
maps: {
|
||||
albedoMap: '/material/wallpaper3/albedoMap_wallpaper3.avif',
|
||||
},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.887,
|
||||
metalness: 0.35,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'preset-white',
|
||||
label: 'White',
|
||||
description: 'Clean painted finish',
|
||||
targets: [
|
||||
...WALL_TARGETS,
|
||||
...SLAB_TARGETS,
|
||||
...ROOF_TARGETS,
|
||||
...STAIR_AND_FENCE_TARGETS,
|
||||
...CEILING_TARGETS,
|
||||
],
|
||||
previewColor: '#ffffff',
|
||||
preset: {
|
||||
maps: {},
|
||||
mapProperties: {
|
||||
color: '#ffffff',
|
||||
roughness: 0.9,
|
||||
metalness: 0,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: false,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'preset-metal',
|
||||
label: 'Metal',
|
||||
description: 'Brushed metal finish',
|
||||
targets: [...WALL_TARGETS, ...SLAB_TARGETS],
|
||||
previewColor: '#c0c0c0',
|
||||
preset: {
|
||||
maps: {},
|
||||
mapProperties: {
|
||||
color: '#c7ccd2',
|
||||
roughness: 0.26,
|
||||
metalness: 0.82,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: false,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 0,
|
||||
opacity: 1,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'preset-glass',
|
||||
label: 'Glass',
|
||||
description: 'Light glass finish',
|
||||
targets: [...WALL_TARGETS, ...SLAB_TARGETS],
|
||||
previewColor: '#87ceeb',
|
||||
preset: {
|
||||
maps: {},
|
||||
mapProperties: {
|
||||
color: '#87ceeb',
|
||||
roughness: 0.1,
|
||||
metalness: 0.1,
|
||||
repeatX: 1,
|
||||
repeatY: 1,
|
||||
rotation: 0,
|
||||
wrapS: 'Repeat',
|
||||
wrapT: 'Repeat',
|
||||
normalScaleX: 1,
|
||||
normalScaleY: 1,
|
||||
emissiveIntensity: 1,
|
||||
displacementScale: 0.02,
|
||||
transparent: true,
|
||||
flipY: true,
|
||||
bumpScale: 1,
|
||||
emissiveColor: '#000000',
|
||||
aoMapIntensity: 1,
|
||||
side: 2,
|
||||
opacity: 0.3,
|
||||
lightMapIntensity: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
export function getMaterialsForTarget(target: MaterialTarget): MaterialCatalogItem[] {
|
||||
return MATERIAL_CATALOG.filter((item) => item.targets.includes(target))
|
||||
}
|
||||
|
||||
export function getCatalogMaterialById(id?: string): MaterialCatalogItem | undefined {
|
||||
if (!id) return undefined
|
||||
return MATERIAL_CATALOG.find((item) => item.id === id)
|
||||
}
|
||||
|
||||
export const LIBRARY_MATERIAL_REF_PREFIX = 'library:'
|
||||
|
||||
export function toLibraryMaterialRef(id: string) {
|
||||
return `${LIBRARY_MATERIAL_REF_PREFIX}${id}`
|
||||
}
|
||||
|
||||
export function getLibraryMaterialIdFromRef(materialRef?: string | null) {
|
||||
if (!materialRef) return null
|
||||
if (!materialRef.startsWith(LIBRARY_MATERIAL_REF_PREFIX)) return null
|
||||
return materialRef.slice(LIBRARY_MATERIAL_REF_PREFIX.length)
|
||||
}
|
||||
|
||||
export function getMaterialPresetByRef(materialRef?: string | null): MaterialPresetPayload | null {
|
||||
const materialId = getLibraryMaterialIdFromRef(materialRef)
|
||||
if (!materialId) return null
|
||||
return getCatalogMaterialById(materialId)?.preset ?? null
|
||||
}
|
||||
@@ -7,11 +7,23 @@ export { type Collection, type CollectionId, generateCollectionId } from './coll
|
||||
// Material
|
||||
export {
|
||||
DEFAULT_MATERIALS,
|
||||
MaterialMapPropertiesSchema,
|
||||
MaterialMapsSchema,
|
||||
MaterialPreset,
|
||||
MaterialPresetPayloadSchema,
|
||||
MaterialProperties,
|
||||
MaterialSchema,
|
||||
MaterialTarget,
|
||||
TextureWrapMode,
|
||||
resolveMaterial,
|
||||
} from './material'
|
||||
export type {
|
||||
MaterialMapProperties,
|
||||
MaterialMaps,
|
||||
MaterialPresetPayload,
|
||||
MaterialTarget as MaterialTargetValue,
|
||||
TextureWrapMode as TextureWrapModeValue,
|
||||
} from './material'
|
||||
export { BuildingNode } from './nodes/building'
|
||||
export { CeilingNode } from './nodes/ceiling'
|
||||
export { DoorNode, DoorSegment } from './nodes/door'
|
||||
|
||||
@@ -25,6 +25,7 @@ export const MaterialProperties = z.object({
|
||||
export type MaterialProperties = z.infer<typeof MaterialProperties>
|
||||
|
||||
export const MaterialSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
preset: MaterialPreset.optional(),
|
||||
properties: MaterialProperties.optional(),
|
||||
texture: z
|
||||
@@ -37,6 +38,67 @@ export const MaterialSchema = z.object({
|
||||
})
|
||||
export type MaterialSchema = z.infer<typeof MaterialSchema>
|
||||
|
||||
export const MaterialTarget = z.enum([
|
||||
'wall',
|
||||
'roof',
|
||||
'roof-segment',
|
||||
'stair',
|
||||
'stair-segment',
|
||||
'fence',
|
||||
'slab',
|
||||
'ceiling',
|
||||
'door',
|
||||
'window',
|
||||
])
|
||||
export type MaterialTarget = z.infer<typeof MaterialTarget>
|
||||
|
||||
export const TextureWrapMode = z.enum(['Repeat', 'ClampToEdge', 'MirroredRepeat'])
|
||||
export type TextureWrapMode = z.infer<typeof TextureWrapMode>
|
||||
|
||||
export const MaterialMapsSchema = z.object({
|
||||
albedoMap: z.string().optional(),
|
||||
metalnessMap: z.string().optional(),
|
||||
roughnessMap: z.string().optional(),
|
||||
normalMap: z.string().optional(),
|
||||
displacementMap: z.string().optional(),
|
||||
aoMap: z.string().optional(),
|
||||
emissiveMap: z.string().optional(),
|
||||
bumpMap: z.string().optional(),
|
||||
alphaMap: z.string().optional(),
|
||||
lightMap: z.string().optional(),
|
||||
})
|
||||
export type MaterialMaps = z.infer<typeof MaterialMapsSchema>
|
||||
|
||||
export const MaterialMapPropertiesSchema = z.object({
|
||||
color: z.string().default('#ffffff'),
|
||||
roughness: z.number().min(0).max(1).default(0.5),
|
||||
metalness: z.number().min(0).max(1).default(0),
|
||||
repeatX: z.number().default(1),
|
||||
repeatY: z.number().default(1),
|
||||
rotation: z.number().default(0),
|
||||
wrapS: TextureWrapMode.default('Repeat'),
|
||||
wrapT: TextureWrapMode.default('Repeat'),
|
||||
normalScaleX: z.number().default(1),
|
||||
normalScaleY: z.number().default(1),
|
||||
emissiveIntensity: z.number().default(1),
|
||||
displacementScale: z.number().default(0.02),
|
||||
transparent: z.boolean().default(false),
|
||||
flipY: z.boolean().default(true),
|
||||
bumpScale: z.number().default(1),
|
||||
emissiveColor: z.string().default('#000000'),
|
||||
aoMapIntensity: z.number().default(1),
|
||||
side: z.number().default(0),
|
||||
opacity: z.number().min(0).max(1).default(1),
|
||||
lightMapIntensity: z.number().default(1),
|
||||
})
|
||||
export type MaterialMapProperties = z.infer<typeof MaterialMapPropertiesSchema>
|
||||
|
||||
export const MaterialPresetPayloadSchema = z.object({
|
||||
maps: MaterialMapsSchema,
|
||||
mapProperties: MaterialMapPropertiesSchema,
|
||||
})
|
||||
export type MaterialPresetPayload = z.infer<typeof MaterialPresetPayloadSchema>
|
||||
|
||||
export const DEFAULT_MATERIALS: Record<MaterialPreset, MaterialProperties> = {
|
||||
white: {
|
||||
color: '#ffffff',
|
||||
|
||||
@@ -9,6 +9,7 @@ export const CeilingNode = BaseNode.extend({
|
||||
type: nodeType('ceiling'),
|
||||
children: z.array(ItemNode.shape.id).default([]),
|
||||
material: MaterialSchema.optional(),
|
||||
materialPreset: z.string().optional(),
|
||||
polygon: z.array(z.tuple([z.number(), z.number()])),
|
||||
holes: z.array(z.array(z.tuple([z.number(), z.number()]))).default([]),
|
||||
height: z.number().default(2.5), // Height in meters
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import dedent from 'dedent'
|
||||
import { z } from 'zod'
|
||||
import { BaseNode, nodeType, objectId } from '../base'
|
||||
import { MaterialSchema } from '../material'
|
||||
|
||||
export const FenceStyle = z.enum(['slat', 'rail', 'privacy'])
|
||||
export const FenceBaseStyle = z.enum(['floating', 'grounded'])
|
||||
@@ -8,6 +9,8 @@ export const FenceBaseStyle = z.enum(['floating', 'grounded'])
|
||||
export const FenceNode = BaseNode.extend({
|
||||
id: objectId('fence'),
|
||||
type: nodeType('fence'),
|
||||
material: MaterialSchema.optional(),
|
||||
materialPreset: z.string().optional(),
|
||||
start: z.tuple([z.number(), z.number()]),
|
||||
end: z.tuple([z.number(), z.number()]),
|
||||
height: z.number().default(1.8),
|
||||
|
||||
@@ -11,6 +11,7 @@ export const RoofSegmentNode = BaseNode.extend({
|
||||
id: objectId('rseg'),
|
||||
type: nodeType('roof-segment'),
|
||||
material: MaterialSchema.optional(),
|
||||
materialPreset: z.string().optional(),
|
||||
position: z.tuple([z.number(), z.number(), z.number()]).default([0, 0, 0]),
|
||||
// Rotation around Y axis in radians
|
||||
rotation: z.number().default(0),
|
||||
|
||||
@@ -8,6 +8,7 @@ export const RoofNode = BaseNode.extend({
|
||||
id: objectId('roof'),
|
||||
type: nodeType('roof'),
|
||||
material: MaterialSchema.optional(),
|
||||
materialPreset: z.string().optional(),
|
||||
position: z.tuple([z.number(), z.number(), z.number()]).default([0, 0, 0]),
|
||||
// Rotation around Y axis in radians
|
||||
rotation: z.number().default(0),
|
||||
|
||||
@@ -7,6 +7,7 @@ export const SlabNode = BaseNode.extend({
|
||||
id: objectId('slab'),
|
||||
type: nodeType('slab'),
|
||||
material: MaterialSchema.optional(),
|
||||
materialPreset: z.string().optional(),
|
||||
polygon: z.array(z.tuple([z.number(), z.number()])),
|
||||
holes: z.array(z.array(z.tuple([z.number(), z.number()]))).default([]),
|
||||
elevation: z.number().default(0.05), // Elevation in meters
|
||||
|
||||
@@ -15,6 +15,7 @@ export const StairSegmentNode = BaseNode.extend({
|
||||
id: objectId('sseg'),
|
||||
type: nodeType('stair-segment'),
|
||||
material: MaterialSchema.optional(),
|
||||
materialPreset: z.string().optional(),
|
||||
position: z.tuple([z.number(), z.number(), z.number()]).default([0, 0, 0]),
|
||||
// Rotation around Y axis in radians
|
||||
rotation: z.number().default(0),
|
||||
|
||||
@@ -16,6 +16,7 @@ export const StairNode = BaseNode.extend({
|
||||
id: objectId('stair'),
|
||||
type: nodeType('stair'),
|
||||
material: MaterialSchema.optional(),
|
||||
materialPreset: z.string().optional(),
|
||||
position: z.tuple([z.number(), z.number(), z.number()]).default([0, 0, 0]),
|
||||
// Rotation around Y axis in radians
|
||||
rotation: z.number().default(0),
|
||||
|
||||
@@ -13,8 +13,10 @@ export const WallNode = BaseNode.extend({
|
||||
.array(z.union([ItemNode.shape.id, DoorNode.shape.id, WindowNode.shape.id]))
|
||||
.default([]),
|
||||
material: MaterialSchema.optional(),
|
||||
materialPreset: z.string().optional(),
|
||||
thickness: z.number().optional(),
|
||||
height: z.number().optional(),
|
||||
curveOffset: z.number().optional(),
|
||||
// e.g., start/end points for path
|
||||
start: z.tuple([z.number(), z.number()]),
|
||||
end: z.tuple([z.number(), z.number()]),
|
||||
@@ -26,6 +28,7 @@ export const WallNode = BaseNode.extend({
|
||||
Wall node - used to represent a wall in the building
|
||||
- thickness: thickness in meters
|
||||
- height: height in meters
|
||||
- curveOffset: midpoint sagitta offset used to bend the wall into an arc
|
||||
- start: start point of the wall in level coordinate system
|
||||
- end: end point of the wall in level coordinate system
|
||||
- size: size of the wall in grid units
|
||||
|
||||
@@ -4,6 +4,13 @@ import { sceneRegistry } from '../../hooks/scene-registry/scene-registry'
|
||||
import type { AnyNodeId, CeilingNode } from '../../schema'
|
||||
import useScene from '../../store/use-scene'
|
||||
|
||||
function ensureUv2Attribute(geometry: THREE.BufferGeometry) {
|
||||
const uv = geometry.getAttribute('uv')
|
||||
if (!uv) return
|
||||
|
||||
geometry.setAttribute('uv2', new THREE.Float32BufferAttribute(Array.from(uv.array), 2))
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// CEILING SYSTEM
|
||||
// ============================================================================
|
||||
@@ -100,6 +107,7 @@ export function generateCeilingGeometry(ceilingNode: CeilingNode): THREE.BufferG
|
||||
// Rotate so the shape lies flat in X-Z plane
|
||||
geometry.rotateX(-Math.PI / 2)
|
||||
geometry.computeVertexNormals()
|
||||
ensureUv2Attribute(geometry)
|
||||
|
||||
return geometry
|
||||
}
|
||||
|
||||
@@ -10,6 +10,66 @@ type FencePart = {
|
||||
scale: [number, number, number]
|
||||
}
|
||||
|
||||
function applyFenceUVs(geometry: THREE.BufferGeometry) {
|
||||
const position = geometry.getAttribute('position')
|
||||
const normal = geometry.getAttribute('normal')
|
||||
|
||||
if (!(position && normal)) return
|
||||
|
||||
const uvs = new Float32Array(position.count * 2)
|
||||
let minX = Number.POSITIVE_INFINITY
|
||||
let minY = Number.POSITIVE_INFINITY
|
||||
let minZ = Number.POSITIVE_INFINITY
|
||||
let maxX = Number.NEGATIVE_INFINITY
|
||||
let maxY = Number.NEGATIVE_INFINITY
|
||||
let maxZ = Number.NEGATIVE_INFINITY
|
||||
|
||||
for (let index = 0; index < position.count; index += 1) {
|
||||
const px = position.getX(index)
|
||||
const py = position.getY(index)
|
||||
const pz = position.getZ(index)
|
||||
minX = Math.min(minX, px)
|
||||
minY = Math.min(minY, py)
|
||||
minZ = Math.min(minZ, pz)
|
||||
maxX = Math.max(maxX, px)
|
||||
maxY = Math.max(maxY, py)
|
||||
maxZ = Math.max(maxZ, pz)
|
||||
}
|
||||
|
||||
const width = Math.max(maxX - minX, 0.001)
|
||||
const height = Math.max(maxY - minY, 0.001)
|
||||
const depth = Math.max(maxZ - minZ, 0.001)
|
||||
|
||||
for (let index = 0; index < position.count; index += 1) {
|
||||
const px = position.getX(index)
|
||||
const py = position.getY(index)
|
||||
const pz = position.getZ(index)
|
||||
const nx = Math.abs(normal.getX(index))
|
||||
const ny = Math.abs(normal.getY(index))
|
||||
const nz = Math.abs(normal.getZ(index))
|
||||
|
||||
let u = 0
|
||||
let v = 0
|
||||
|
||||
if (ny >= nx && ny >= nz) {
|
||||
u = (px - minX) / width
|
||||
v = (pz - minZ) / depth
|
||||
} else if (nx >= nz) {
|
||||
u = (pz - minZ) / depth
|
||||
v = (py - minY) / height
|
||||
} else {
|
||||
u = (px - minX) / width
|
||||
v = (py - minY) / height
|
||||
}
|
||||
|
||||
uvs[index * 2] = u
|
||||
uvs[index * 2 + 1] = v
|
||||
}
|
||||
|
||||
geometry.setAttribute('uv', new THREE.Float32BufferAttribute(uvs, 2))
|
||||
geometry.setAttribute('uv2', new THREE.Float32BufferAttribute(uvs.slice(), 2))
|
||||
}
|
||||
|
||||
function getStyleDefaults(style: FenceNode['style']) {
|
||||
if (style === 'privacy') {
|
||||
return { spacingFactor: 0.42, postFactor: 1.35, baseFactor: 1.2, topFactor: 1.2 }
|
||||
@@ -103,6 +163,7 @@ function generateFenceGeometry(fence: FenceNode) {
|
||||
|
||||
const merged = mergeGeometries(geometries, false) ?? new THREE.BufferGeometry()
|
||||
geometries.forEach((geometry) => geometry.dispose())
|
||||
applyFenceUVs(merged)
|
||||
merged.computeVertexNormals()
|
||||
return merged
|
||||
}
|
||||
|
||||
@@ -4,6 +4,13 @@ import { sceneRegistry } from '../../hooks/scene-registry/scene-registry'
|
||||
import type { AnyNodeId, SlabNode } from '../../schema'
|
||||
import useScene from '../../store/use-scene'
|
||||
|
||||
function ensureUv2Attribute(geometry: THREE.BufferGeometry) {
|
||||
const uv = geometry.getAttribute('uv')
|
||||
if (!uv) return
|
||||
|
||||
geometry.setAttribute('uv2', new THREE.Float32BufferAttribute(Array.from(uv.array), 2))
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// SLAB SYSTEM
|
||||
// ============================================================================
|
||||
@@ -39,6 +46,7 @@ export const SlabSystem = () => {
|
||||
*/
|
||||
function updateSlabGeometry(node: SlabNode, mesh: THREE.Mesh) {
|
||||
const newGeo = generateSlabGeometry(node)
|
||||
ensureUv2Attribute(newGeo)
|
||||
|
||||
mesh.geometry.dispose()
|
||||
mesh.geometry = newGeo
|
||||
@@ -157,16 +165,46 @@ function generatePoolGeometry(slabNode: SlabNode): THREE.BufferGeometry {
|
||||
if (polygon.length < 3) return new THREE.BufferGeometry()
|
||||
|
||||
const positions: number[] = []
|
||||
const uvs: number[] = []
|
||||
const indices: number[] = []
|
||||
const n = polygon.length
|
||||
const bounds = new THREE.Box2()
|
||||
|
||||
for (const [x, z] of polygon) {
|
||||
bounds.expandByPoint(new THREE.Vector2(x, z))
|
||||
}
|
||||
for (const hole of slabNode.holes ?? []) {
|
||||
for (const [x, z] of hole) {
|
||||
bounds.expandByPoint(new THREE.Vector2(x, z))
|
||||
}
|
||||
}
|
||||
|
||||
const floorWidth = Math.max(bounds.max.x - bounds.min.x, 0.001)
|
||||
const floorHeight = Math.max(bounds.max.y - bounds.min.y, 0.001)
|
||||
|
||||
const pushFloorVertex = (x: number, y: number, z: number) => {
|
||||
positions.push(x, y, z)
|
||||
uvs.push((x - bounds.min.x) / floorWidth, (z - bounds.min.y) / floorHeight)
|
||||
}
|
||||
|
||||
const pushWallVertex = (
|
||||
x: number,
|
||||
y: number,
|
||||
z: number,
|
||||
u: number,
|
||||
v: number,
|
||||
) => {
|
||||
positions.push(x, y, z)
|
||||
uvs.push(u, v)
|
||||
}
|
||||
|
||||
// --- Floor at Y=0 ---
|
||||
for (const [x, z] of polygon) positions.push(x!, 0, z!)
|
||||
for (const [x, z] of polygon) pushFloorVertex(x!, 0, z!)
|
||||
|
||||
const pts2d = polygon.map(([x, z]) => new THREE.Vector2(x!, z!))
|
||||
const holesPts2d = (slabNode.holes ?? []).map((h) => h.map(([x, z]) => new THREE.Vector2(x!, z!)))
|
||||
for (const hole of slabNode.holes ?? []) {
|
||||
for (const [x, z] of hole) positions.push(x!, 0, z!)
|
||||
for (const [x, z] of hole) pushFloorVertex(x!, 0, z!)
|
||||
}
|
||||
|
||||
const floorTris = THREE.ShapeUtils.triangulateShape(pts2d, holesPts2d)
|
||||
@@ -182,11 +220,12 @@ function generatePoolGeometry(slabNode: SlabNode): THREE.BufferGeometry {
|
||||
const [x0, z0] = polygon[i]!
|
||||
const [x1, z1] = polygon[j]!
|
||||
const vBase = positions.length / 3
|
||||
const segmentLength = Math.max(Math.hypot(x1 - x0, z1 - z0), 0.001)
|
||||
|
||||
positions.push(x0!, 0, z0!) // v0 — floor level
|
||||
positions.push(x1!, 0, z1!) // v1 — floor level
|
||||
positions.push(x1!, depth, z1!) // v2 — ground level
|
||||
positions.push(x0!, depth, z0!) // v3 — ground level
|
||||
pushWallVertex(x0!, 0, z0!, 0, 0) // v0 — floor level
|
||||
pushWallVertex(x1!, 0, z1!, segmentLength, 0) // v1 — floor level
|
||||
pushWallVertex(x1!, depth, z1!, segmentLength, depth) // v2 — ground level
|
||||
pushWallVertex(x0!, depth, z0!, 0, depth) // v3 — ground level
|
||||
|
||||
indices.push(vBase, vBase + 1, vBase + 2)
|
||||
indices.push(vBase, vBase + 2, vBase + 3)
|
||||
@@ -194,6 +233,7 @@ function generatePoolGeometry(slabNode: SlabNode): THREE.BufferGeometry {
|
||||
|
||||
const geo = new THREE.BufferGeometry()
|
||||
geo.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3))
|
||||
geo.setAttribute('uv', new THREE.Float32BufferAttribute(uvs, 2))
|
||||
geo.setIndex(indices)
|
||||
geo.computeVertexNormals()
|
||||
return geo
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
import type { Point2D } from './wall-mitering'
|
||||
import type { WallNode } from '../../schema'
|
||||
|
||||
const CURVE_EPSILON = 1e-6
|
||||
const DEFAULT_SAMPLE_SEGMENTS = 24
|
||||
|
||||
type WallCurveLike = Pick<WallNode, 'start' | 'end' | 'curveOffset'>
|
||||
|
||||
type CurveFrame = {
|
||||
point: Point2D
|
||||
tangent: Point2D
|
||||
normal: Point2D
|
||||
}
|
||||
|
||||
type WallSurfaceMiterOverrides = {
|
||||
startLeft?: Point2D
|
||||
startRight?: Point2D
|
||||
endLeft?: Point2D
|
||||
endRight?: Point2D
|
||||
}
|
||||
|
||||
function clamp01(value: number) {
|
||||
return Math.max(0, Math.min(1, value))
|
||||
}
|
||||
|
||||
function lerp(a: number, b: number, t: number) {
|
||||
return a + (b - a) * t
|
||||
}
|
||||
|
||||
function distance(a: Point2D, b: Point2D) {
|
||||
return Math.hypot(b.x - a.x, b.y - a.y)
|
||||
}
|
||||
|
||||
export function getWallStartPoint(wall: WallCurveLike): Point2D {
|
||||
return { x: wall.start[0], y: wall.start[1] }
|
||||
}
|
||||
|
||||
export function getWallEndPoint(wall: WallCurveLike): Point2D {
|
||||
return { x: wall.end[0], y: wall.end[1] }
|
||||
}
|
||||
|
||||
export function getWallChordLength(wall: WallCurveLike) {
|
||||
return distance(getWallStartPoint(wall), getWallEndPoint(wall))
|
||||
}
|
||||
|
||||
export function getMaxWallCurveOffset(wall: WallCurveLike) {
|
||||
return getWallChordLength(wall) / 2
|
||||
}
|
||||
|
||||
export function getWallStraightSnapOffset(wall: WallCurveLike) {
|
||||
return Math.min(0.03, Math.max(0.005, getWallChordLength(wall) * 0.005))
|
||||
}
|
||||
|
||||
function clampCurveOffset(wall: WallCurveLike, offset: number) {
|
||||
const maxOffset = getMaxWallCurveOffset(wall)
|
||||
if (!Number.isFinite(maxOffset) || maxOffset < CURVE_EPSILON) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return Math.max(-maxOffset, Math.min(maxOffset, offset))
|
||||
}
|
||||
|
||||
export function normalizeWallCurveOffset(wall: WallCurveLike, offset: number) {
|
||||
const clamped = clampCurveOffset(wall, offset)
|
||||
return Math.abs(clamped) <= getWallStraightSnapOffset(wall) ? 0 : clamped
|
||||
}
|
||||
|
||||
export function getClampedWallCurveOffset(wall: WallCurveLike) {
|
||||
const value = wall.curveOffset ?? 0
|
||||
const normalized = normalizeWallCurveOffset(wall, value)
|
||||
return Math.abs(normalized) > CURVE_EPSILON ? normalized : 0
|
||||
}
|
||||
|
||||
export function isCurvedWall(wall: WallCurveLike) {
|
||||
return Math.abs(getClampedWallCurveOffset(wall)) > CURVE_EPSILON
|
||||
}
|
||||
|
||||
export function getWallChordFrame(wall: WallCurveLike) {
|
||||
const start = getWallStartPoint(wall)
|
||||
const end = getWallEndPoint(wall)
|
||||
const dx = end.x - start.x
|
||||
const dy = end.y - start.y
|
||||
const length = Math.hypot(dx, dy)
|
||||
|
||||
if (length < CURVE_EPSILON) {
|
||||
return {
|
||||
start,
|
||||
end,
|
||||
midpoint: start,
|
||||
tangent: { x: 1, y: 0 },
|
||||
normal: { x: 0, y: 1 },
|
||||
length: 0,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
start,
|
||||
end,
|
||||
midpoint: {
|
||||
x: (start.x + end.x) / 2,
|
||||
y: (start.y + end.y) / 2,
|
||||
},
|
||||
tangent: { x: dx / length, y: dy / length },
|
||||
normal: { x: -dy / length, y: dx / length },
|
||||
length,
|
||||
}
|
||||
}
|
||||
|
||||
function getWallArcData(wall: WallCurveLike) {
|
||||
const chord = getWallChordFrame(wall)
|
||||
const sagitta = getClampedWallCurveOffset(wall)
|
||||
|
||||
if (Math.abs(sagitta) <= CURVE_EPSILON || chord.length < CURVE_EPSILON) {
|
||||
return null
|
||||
}
|
||||
|
||||
const absSagitta = Math.abs(sagitta)
|
||||
const radius = chord.length * chord.length / (8 * absSagitta) + absSagitta / 2
|
||||
const centerOffset = radius - absSagitta
|
||||
const direction = Math.sign(sagitta) || 1
|
||||
const center = {
|
||||
x: chord.midpoint.x + chord.normal.x * centerOffset * direction,
|
||||
y: chord.midpoint.y + chord.normal.y * centerOffset * direction,
|
||||
}
|
||||
const startAngle = Math.atan2(chord.start.y - center.y, chord.start.x - center.x)
|
||||
const endAngle = Math.atan2(chord.end.y - center.y, chord.end.x - center.x)
|
||||
|
||||
let delta = endAngle - startAngle
|
||||
if (direction > 0) {
|
||||
while (delta <= 0) delta += Math.PI * 2
|
||||
} else {
|
||||
while (delta >= 0) delta -= Math.PI * 2
|
||||
}
|
||||
|
||||
return { center, radius, startAngle, delta, direction }
|
||||
}
|
||||
|
||||
export function getWallCurveFrameAt(wall: WallCurveLike, t: number): CurveFrame {
|
||||
const chord = getWallChordFrame(wall)
|
||||
if (!isCurvedWall(wall) || chord.length < CURVE_EPSILON) {
|
||||
return {
|
||||
point: {
|
||||
x: lerp(chord.start.x, chord.end.x, clamp01(t)),
|
||||
y: lerp(chord.start.y, chord.end.y, clamp01(t)),
|
||||
},
|
||||
tangent: chord.tangent,
|
||||
normal: chord.normal,
|
||||
}
|
||||
}
|
||||
|
||||
const arc = getWallArcData(wall)
|
||||
if (!arc) {
|
||||
return {
|
||||
point: chord.midpoint,
|
||||
tangent: chord.tangent,
|
||||
normal: chord.normal,
|
||||
}
|
||||
}
|
||||
|
||||
const angle = arc.startAngle + arc.delta * clamp01(t)
|
||||
const point = {
|
||||
x: arc.center.x + Math.cos(angle) * arc.radius,
|
||||
y: arc.center.y + Math.sin(angle) * arc.radius,
|
||||
}
|
||||
const tangent =
|
||||
arc.direction > 0
|
||||
? { x: -Math.sin(angle), y: Math.cos(angle) }
|
||||
: { x: Math.sin(angle), y: -Math.cos(angle) }
|
||||
|
||||
return {
|
||||
point,
|
||||
tangent,
|
||||
normal: {
|
||||
x: -tangent.y,
|
||||
y: tangent.x,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function getWallMidpointHandlePoint(wall: WallCurveLike) {
|
||||
return getWallCurveFrameAt(wall, 0.5).point
|
||||
}
|
||||
|
||||
export function sampleWallCenterline(wall: WallCurveLike, segments = DEFAULT_SAMPLE_SEGMENTS) {
|
||||
const count = Math.max(1, segments)
|
||||
return Array.from({ length: count + 1 }, (_, index) => getWallCurveFrameAt(wall, index / count).point)
|
||||
}
|
||||
|
||||
export function getWallCurveLength(wall: WallCurveLike, segments = DEFAULT_SAMPLE_SEGMENTS) {
|
||||
const points = sampleWallCenterline(wall, segments)
|
||||
let totalLength = 0
|
||||
|
||||
for (let index = 1; index < points.length; index += 1) {
|
||||
totalLength += distance(points[index - 1]!, points[index]!)
|
||||
}
|
||||
|
||||
return totalLength
|
||||
}
|
||||
|
||||
export function getWallSurfacePolygon(
|
||||
wall: Pick<WallNode, 'start' | 'end' | 'curveOffset' | 'thickness'>,
|
||||
segments = DEFAULT_SAMPLE_SEGMENTS,
|
||||
miterOverrides?: WallSurfaceMiterOverrides,
|
||||
) {
|
||||
const halfThickness = (wall.thickness ?? 0.1) / 2
|
||||
const count = Math.max(1, segments)
|
||||
const left: Point2D[] = []
|
||||
const right: Point2D[] = []
|
||||
|
||||
for (let index = 0; index <= count; index += 1) {
|
||||
const frame = getWallCurveFrameAt(wall, index / count)
|
||||
left.push({
|
||||
x: frame.point.x + frame.normal.x * halfThickness,
|
||||
y: frame.point.y + frame.normal.y * halfThickness,
|
||||
})
|
||||
right.push({
|
||||
x: frame.point.x - frame.normal.x * halfThickness,
|
||||
y: frame.point.y - frame.normal.y * halfThickness,
|
||||
})
|
||||
}
|
||||
|
||||
if (left.length > 0 && right.length > 0) {
|
||||
left[0] = miterOverrides?.startLeft ?? left[0]!
|
||||
right[0] = miterOverrides?.startRight ?? right[0]!
|
||||
left[left.length - 1] = miterOverrides?.endLeft ?? left[left.length - 1]!
|
||||
right[right.length - 1] = miterOverrides?.endRight ?? right[right.length - 1]!
|
||||
}
|
||||
|
||||
return [...right, ...left.reverse()]
|
||||
}
|
||||
@@ -1,8 +1,15 @@
|
||||
import type { WallNode } from '../../schema'
|
||||
import { type Point2D, pointToKey, type WallMiterData } from './wall-mitering'
|
||||
import { getWallSurfacePolygon, isCurvedWall } from './wall-curve'
|
||||
import {
|
||||
getWallMiterBoundaryPoints,
|
||||
type Point2D,
|
||||
pointToKey,
|
||||
type WallMiterData,
|
||||
} from './wall-mitering'
|
||||
|
||||
export const DEFAULT_WALL_THICKNESS = 0.1
|
||||
export const DEFAULT_WALL_HEIGHT = 2.5
|
||||
const CURVED_WALL_SURFACE_SEGMENTS = 24
|
||||
|
||||
export function getWallThickness(wallNode: WallNode): number {
|
||||
return wallNode.thickness ?? DEFAULT_WALL_THICKNESS
|
||||
@@ -10,25 +17,38 @@ export function getWallThickness(wallNode: WallNode): number {
|
||||
|
||||
export function getWallPlanFootprint(wallNode: WallNode, miterData: WallMiterData): Point2D[] {
|
||||
const { junctionData } = miterData
|
||||
|
||||
const wallStart: Point2D = { x: wallNode.start[0], y: wallNode.start[1] }
|
||||
const wallEnd: Point2D = { x: wallNode.end[0], y: wallNode.end[1] }
|
||||
const thickness = getWallThickness(wallNode)
|
||||
const halfT = thickness / 2
|
||||
|
||||
const v = { x: wallEnd.x - wallStart.x, y: wallEnd.y - wallStart.y }
|
||||
const L = Math.sqrt(v.x * v.x + v.y * v.y)
|
||||
|
||||
if (L < 1e-9) {
|
||||
return []
|
||||
}
|
||||
const nUnit = { x: -v.y / L, y: v.x / L }
|
||||
|
||||
const keyStart = pointToKey(wallStart)
|
||||
const keyEnd = pointToKey(wallEnd)
|
||||
|
||||
const startJunction = junctionData.get(keyStart)?.get(wallNode.id)
|
||||
const endJunction = junctionData.get(keyEnd)?.get(wallNode.id)
|
||||
|
||||
if (isCurvedWall(wallNode)) {
|
||||
const boundaryPoints = getWallMiterBoundaryPoints(wallNode, miterData)
|
||||
if (!boundaryPoints) {
|
||||
return []
|
||||
}
|
||||
|
||||
const { startLeft, startRight, endLeft, endRight } = boundaryPoints
|
||||
|
||||
return getWallSurfacePolygon(wallNode, CURVED_WALL_SURFACE_SEGMENTS, {
|
||||
endLeft,
|
||||
endRight,
|
||||
startLeft,
|
||||
startRight,
|
||||
})
|
||||
}
|
||||
|
||||
const pStartLeft: Point2D = startJunction?.left || {
|
||||
x: wallStart.x + nUnit.x * halfT,
|
||||
y: wallStart.y + nUnit.y * halfT,
|
||||
@@ -37,8 +57,6 @@ export function getWallPlanFootprint(wallNode: WallNode, miterData: WallMiterDat
|
||||
x: wallStart.x - nUnit.x * halfT,
|
||||
y: wallStart.y - nUnit.y * halfT,
|
||||
}
|
||||
|
||||
// Junction offsets are stored relative to the outgoing direction.
|
||||
const pEndLeft: Point2D = endJunction?.right || {
|
||||
x: wallEnd.x + nUnit.x * halfT,
|
||||
y: wallEnd.y + nUnit.y * halfT,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { WallNode } from '../../schema'
|
||||
import { getWallCurveFrameAt, isCurvedWall } from './wall-curve'
|
||||
|
||||
// ============================================================================
|
||||
// TYPES
|
||||
@@ -9,6 +10,13 @@ export interface Point2D {
|
||||
y: number
|
||||
}
|
||||
|
||||
export interface WallMiterBoundaryPoints {
|
||||
startLeft: Point2D
|
||||
startRight: Point2D
|
||||
endLeft: Point2D
|
||||
endRight: Point2D
|
||||
}
|
||||
|
||||
interface LineEquation {
|
||||
a: number
|
||||
b: number
|
||||
@@ -127,6 +135,70 @@ function findJunctions(walls: WallNode[]): Map<string, Junction> {
|
||||
return actualJunctions
|
||||
}
|
||||
|
||||
function getWallDirectionFromJunction(
|
||||
wall: WallNode,
|
||||
endType: 'start' | 'end' | 'passthrough',
|
||||
) {
|
||||
if (endType === 'passthrough') {
|
||||
return {
|
||||
x: wall.end[0] - wall.start[0],
|
||||
y: wall.end[1] - wall.start[1],
|
||||
}
|
||||
}
|
||||
|
||||
if (isCurvedWall(wall)) {
|
||||
const frame = getWallCurveFrameAt(wall, endType === 'start' ? 0 : 1)
|
||||
return endType === 'start'
|
||||
? frame.tangent
|
||||
: { x: -frame.tangent.x, y: -frame.tangent.y }
|
||||
}
|
||||
|
||||
return endType === 'start'
|
||||
? { x: wall.end[0] - wall.start[0], y: wall.end[1] - wall.start[1] }
|
||||
: { x: wall.start[0] - wall.end[0], y: wall.start[1] - wall.end[1] }
|
||||
}
|
||||
|
||||
function getWallBoundaryFrame(
|
||||
wall: WallNode,
|
||||
endType: 'start' | 'end',
|
||||
) {
|
||||
if (isCurvedWall(wall)) {
|
||||
const frame = getWallCurveFrameAt(wall, endType === 'start' ? 0 : 1)
|
||||
return {
|
||||
point: frame.point,
|
||||
tangent:
|
||||
endType === 'start'
|
||||
? frame.tangent
|
||||
: { x: -frame.tangent.x, y: -frame.tangent.y },
|
||||
normal: frame.normal,
|
||||
}
|
||||
}
|
||||
|
||||
const point =
|
||||
endType === 'start'
|
||||
? { x: wall.start[0], y: wall.start[1] }
|
||||
: { x: wall.end[0], y: wall.end[1] }
|
||||
const vector =
|
||||
endType === 'start'
|
||||
? { x: wall.end[0] - wall.start[0], y: wall.end[1] - wall.start[1] }
|
||||
: { x: wall.start[0] - wall.end[0], y: wall.start[1] - wall.end[1] }
|
||||
const length = Math.hypot(vector.x, vector.y)
|
||||
|
||||
if (length < 1e-9) {
|
||||
return {
|
||||
point,
|
||||
tangent: { x: 1, y: 0 },
|
||||
normal: { x: 0, y: 1 },
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
point,
|
||||
tangent: { x: vector.x / length, y: vector.y / length },
|
||||
normal: { x: -vector.y / length, y: vector.x / length },
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// MITER CALCULATION (exactly like demo)
|
||||
// ============================================================================
|
||||
@@ -171,10 +243,7 @@ function calculateJunctionIntersections(
|
||||
}
|
||||
} else {
|
||||
// Normal wall endpoint (start or end)
|
||||
const v =
|
||||
endType === 'start'
|
||||
? { x: wall.end[0] - wall.start[0], y: wall.end[1] - wall.start[1] }
|
||||
: { x: wall.start[0] - wall.end[0], y: wall.start[1] - wall.end[1] }
|
||||
const v = getWallDirectionFromJunction(wall, endType)
|
||||
|
||||
const L = Math.sqrt(v.x * v.x + v.y * v.y)
|
||||
if (L < 1e-9) continue
|
||||
@@ -264,6 +333,37 @@ export function calculateLevelMiters(walls: WallNode[]): WallMiterData {
|
||||
return { junctionData, junctions }
|
||||
}
|
||||
|
||||
export function getWallMiterBoundaryPoints(
|
||||
wall: WallNode,
|
||||
miterData: WallMiterData,
|
||||
): WallMiterBoundaryPoints | null {
|
||||
const thickness = wall.thickness ?? 0.1
|
||||
const halfThickness = thickness / 2
|
||||
const startFrame = getWallBoundaryFrame(wall, 'start')
|
||||
const endFrame = getWallBoundaryFrame(wall, 'end')
|
||||
const startJunction = miterData.junctionData.get(pointToKey(startFrame.point))?.get(wall.id)
|
||||
const endJunction = miterData.junctionData.get(pointToKey(endFrame.point))?.get(wall.id)
|
||||
|
||||
return {
|
||||
startLeft: startJunction?.left ?? {
|
||||
x: startFrame.point.x + startFrame.normal.x * halfThickness,
|
||||
y: startFrame.point.y + startFrame.normal.y * halfThickness,
|
||||
},
|
||||
startRight: startJunction?.right ?? {
|
||||
x: startFrame.point.x - startFrame.normal.x * halfThickness,
|
||||
y: startFrame.point.y - startFrame.normal.y * halfThickness,
|
||||
},
|
||||
endLeft: endJunction?.right ?? {
|
||||
x: endFrame.point.x + endFrame.normal.x * halfThickness,
|
||||
y: endFrame.point.y + endFrame.normal.y * halfThickness,
|
||||
},
|
||||
endRight: endJunction?.left ?? {
|
||||
x: endFrame.point.x - endFrame.normal.x * halfThickness,
|
||||
y: endFrame.point.y - endFrame.normal.y * halfThickness,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets wall IDs that share junctions with the given walls
|
||||
*/
|
||||
|
||||
@@ -8,15 +8,75 @@ import { resolveLevelId } from '../../hooks/spatial-grid/spatial-grid-sync'
|
||||
import type { AnyNode, AnyNodeId, WallNode } from '../../schema'
|
||||
import useScene from '../../store/use-scene'
|
||||
import { DEFAULT_WALL_HEIGHT, getWallPlanFootprint, getWallThickness } from './wall-footprint'
|
||||
import { getWallCurveFrameAt, getWallSurfacePolygon, isCurvedWall } from './wall-curve'
|
||||
import {
|
||||
calculateLevelMiters,
|
||||
getAdjacentWallIds,
|
||||
getWallMiterBoundaryPoints,
|
||||
type Point2D,
|
||||
type WallMiterData,
|
||||
pointToKey,
|
||||
} from './wall-mitering'
|
||||
|
||||
// Reusable CSG evaluator for better performance
|
||||
const csgEvaluator = new Evaluator()
|
||||
const CURVED_WALL_3D_ENDPOINT_INSET = 0.0015
|
||||
|
||||
function ensureUv2Attribute(geometry: THREE.BufferGeometry) {
|
||||
const uv = geometry.getAttribute('uv')
|
||||
if (!uv) return
|
||||
|
||||
geometry.setAttribute('uv2', new THREE.Float32BufferAttribute(Array.from(uv.array), 2))
|
||||
}
|
||||
|
||||
function insetCurvedWallBoundaryPointsFor3D(
|
||||
wall: WallNode,
|
||||
boundaryPoints: ReturnType<typeof getWallMiterBoundaryPoints>,
|
||||
miterData: WallMiterData,
|
||||
) {
|
||||
if (!boundaryPoints || !isCurvedWall(wall)) {
|
||||
return boundaryPoints
|
||||
}
|
||||
|
||||
const insetDistance = Math.min(
|
||||
CURVED_WALL_3D_ENDPOINT_INSET,
|
||||
Math.max((wall.thickness ?? 0.1) * 0.01, 0.0005),
|
||||
)
|
||||
|
||||
if (insetDistance <= 0) {
|
||||
return boundaryPoints
|
||||
}
|
||||
|
||||
const next = { ...boundaryPoints }
|
||||
const startJunction = miterData.junctions.get(pointToKey({ x: wall.start[0], y: wall.start[1] }))
|
||||
const endJunction = miterData.junctions.get(pointToKey({ x: wall.end[0], y: wall.end[1] }))
|
||||
|
||||
if (startJunction && startJunction.connectedWalls.length > 1) {
|
||||
const frame = getWallCurveFrameAt(wall, 0)
|
||||
next.startLeft = {
|
||||
x: next.startLeft.x + frame.tangent.x * insetDistance,
|
||||
y: next.startLeft.y + frame.tangent.y * insetDistance,
|
||||
}
|
||||
next.startRight = {
|
||||
x: next.startRight.x + frame.tangent.x * insetDistance,
|
||||
y: next.startRight.y + frame.tangent.y * insetDistance,
|
||||
}
|
||||
}
|
||||
|
||||
if (endJunction && endJunction.connectedWalls.length > 1) {
|
||||
const frame = getWallCurveFrameAt(wall, 1)
|
||||
next.endLeft = {
|
||||
x: next.endLeft.x - frame.tangent.x * insetDistance,
|
||||
y: next.endLeft.y - frame.tangent.y * insetDistance,
|
||||
}
|
||||
next.endRight = {
|
||||
x: next.endRight.x - frame.tangent.x * insetDistance,
|
||||
y: next.endRight.y - frame.tangent.y * insetDistance,
|
||||
}
|
||||
}
|
||||
|
||||
return next
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// WALL SYSTEM
|
||||
@@ -163,7 +223,14 @@ export function generateExtrudedWall(
|
||||
if (L < 1e-9) {
|
||||
return new THREE.BufferGeometry()
|
||||
}
|
||||
const polyPoints = getWallPlanFootprint(wallNode, miterData)
|
||||
const boundaryPoints = getWallMiterBoundaryPoints(wallNode, miterData)
|
||||
const polyPoints = isCurvedWall(wallNode)
|
||||
? getWallSurfacePolygon(
|
||||
wallNode,
|
||||
24,
|
||||
insetCurvedWallBoundaryPointsFor3D(wallNode, boundaryPoints, miterData) ?? undefined,
|
||||
)
|
||||
: getWallPlanFootprint(wallNode, miterData)
|
||||
if (polyPoints.length < 3) {
|
||||
return new THREE.BufferGeometry()
|
||||
}
|
||||
@@ -205,6 +272,7 @@ export function generateExtrudedWall(
|
||||
// Rotate so extrusion direction (Z) becomes height direction (Y)
|
||||
geometry.rotateX(-Math.PI / 2)
|
||||
geometry.computeVertexNormals()
|
||||
ensureUv2Attribute(geometry)
|
||||
|
||||
// Apply CSG subtraction for cutouts (doors/windows)
|
||||
const cutoutBrushes = collectCutoutBrushes(wallNode, childrenNodes, thickness)
|
||||
@@ -239,6 +307,7 @@ export function generateExtrudedWall(
|
||||
|
||||
const resultGeometry = resultBrush.geometry
|
||||
resultGeometry.computeVertexNormals()
|
||||
ensureUv2Attribute(resultGeometry)
|
||||
|
||||
return resultGeometry
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user