Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: init model load #53

Open
wants to merge 132 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
c6c05e0
wip getting blocks in a worker
Jun 21, 2023
7d2cb4d
wip
Jun 22, 2023
50bb7b7
wip init modules with time comparison
Jun 22, 2023
0268426
wip models in idb
Jun 22, 2023
118ac07
wip new useSpeckleObject
Jun 22, 2023
b312018
wip propped tree start
Jun 25, 2023
3d769d4
wip getting messy
Jun 25, 2023
745cffe
wip layout computer
Jun 25, 2023
4e881a6
wip minor
Jun 25, 2023
628c2a0
wip fix double import
Jun 26, 2023
d91ac00
wip quieten speckle ObjectLoader
Jun 27, 2023
921fdfc
wip delete rogue file
Jun 27, 2023
cd1eb71
wip global singleton systems worker
Jun 27, 2023
b3e65fe
wip idb houses
Jun 27, 2023
c21c84e
wip
Jun 27, 2023
2834e83
wip restructure
Jun 27, 2023
6e5216c
wip idb caching layouts
Jun 28, 2023
f21416e
wip fix-up fetcher code
Jun 28, 2023
e059be5
wip using cached layout
Jun 28, 2023
0bf79ca
big wip
Jun 28, 2023
98cb5ed
wip
Jun 29, 2023
e6dfd54
wip circular deps
Jul 2, 2023
a40db8d
wip transform matrices
Jul 3, 2023
1a6b589
wip perfect move
Jul 4, 2023
138b8df
wip fix collisions for move
Jul 4, 2023
2dc0a43
wip builds
Jul 5, 2023
33e1ec9
wip put vanilla columns in db
Jul 5, 2023
391a845
wip refactor stretch length 1
Jul 6, 2023
91cca4d
wip intent stretch working
Jul 6, 2023
44c4f5a
wip messy
Jul 6, 2023
edf1e4d
wip messier but builds
Jul 9, 2023
53379a2
wip pre compound layouts index
Jul 9, 2023
21ec01f
wip
Jul 10, 2023
63f2a69
wip key test
Jul 10, 2023
55840fb
wip rendering vanilla geoms
Jul 10, 2023
d7ecd18
wip house layout first pass
Jul 11, 2023
3384f3d
wip house render
Jul 11, 2023
7b50b1e
wip pre houseLayouts updates
Jul 11, 2023
7dcef52
wippy wip
Jul 12, 2023
337f774
wip adding house
Jul 12, 2023
ad39926
wip put houses in the db
Jul 12, 2023
43c6931
wip updating start/end cols
Jul 12, 2023
6576a36
wip nice key stretch
Jul 13, 2023
cd63f65
wip partition
Jul 13, 2023
2d933aa
wip subtractors
Jul 13, 2023
2ddaef1
wip update house dimensions
Jul 13, 2023
84df444
wip somewhere
Jul 14, 2023
59465bc
wip amess
Jul 17, 2023
b447962
wip translate/rotate with obb
Jul 17, 2023
0b89b0f
wip move/rotate/stretch obb consistency
Jul 17, 2023
5bdec1f
wip minor
Jul 20, 2023
61266eb
wip pre stencil
Jul 20, 2023
ea9abb5
wip delete clippingPlanes file
Jul 20, 2023
e63ce52
wip; layout algo type checking
Jul 26, 2023
85fff6e
wip
Jul 26, 2023
9b9088f
wip pre sub altSectionTypeLayouts
Jul 26, 2023
f3bfe2e
wip
Jul 27, 2023
a23fb61
wip yooo first pass
Jul 27, 2023
a016d19
wip going nicely
Jul 27, 2023
fed6428
wip bingo w/ keyboard at least
Jul 27, 2023
601d327
wip
Jul 28, 2023
dde9e68
wip start of week
Jul 31, 2023
54aa646
wip pre re scope
Jul 31, 2023
4c7e3fa
wip wip
Jul 31, 2023
6c110a1
wip handles moving
Jul 31, 2023
df6e714
wip
Aug 1, 2023
1a6bc08
wip w/ rotation
Aug 1, 2023
426f720
wip mess
Aug 2, 2023
c714978
wip z additive up working
Aug 2, 2023
b2a8d7f
wip
Aug 2, 2023
637236e
wip
Aug 2, 2023
c572d1f
wip pass 1
Aug 2, 2023
24b5569
wip
Aug 3, 2023
edaf119
wip z-stretch+ re-recovered
Aug 3, 2023
a305ae3
wip
Aug 3, 2023
3b93cd0
wip scope stuff
Aug 3, 2023
919bd92
wip level planes
Aug 3, 2023
5cca471
wip debug stretch type
Aug 3, 2023
593f080
wip de-pointer debug pane
Aug 3, 2023
b9fe239
wip comment breadcrumbs
Aug 3, 2023
b8e69a9
wip deleted edit mode
Aug 5, 2023
bd1265c
wip pre perf
Aug 8, 2023
0f78a32
wip move working
Aug 8, 2023
1c6d7e4
wip rotate mostly working
Aug 9, 2023
f665cce
wip rotate move very nice
Aug 9, 2023
46044c5
wip type updates
Aug 9, 2023
2dff242
wip handles show/hide improvement
Aug 10, 2023
a92195d
wip level plane off
Aug 10, 2023
a84d4b1
wip fixed material sharing
Aug 10, 2023
be099bc
wip cleanup
Aug 10, 2023
9358eba
wip z stretch down
Aug 10, 2023
b6c0200
wip
Aug 11, 2023
65f1af3
wip
Aug 11, 2023
eacd072
wip
Aug 14, 2023
1c751a9
wip nicen
Aug 14, 2023
0d34891
wip builds
Aug 14, 2023
77ef51b
wip
Aug 14, 2023
762e033
wip fixed positioning gnarl
Aug 15, 2023
d358c3b
wip progress
Aug 15, 2023
4ef0e63
wip additive/subtractive on front/back sides nicely in mid
Aug 15, 2023
9fb2316
wip reconcile stretch z drop
Aug 15, 2023
dffa5bf
wip needs clamp
Aug 15, 2023
b9caef9
wip van col len bug solved
Aug 16, 2023
1538fae
wip rounded handles
Aug 17, 2023
816c17c
wip pre vanilla indexing bug
Aug 17, 2023
e206b58
wip pre front mid fences
Aug 17, 2023
3a1cb8f
wip yippy
Aug 17, 2023
867b659
wip solved obb update
Aug 17, 2023
4da9854
wip we're so back
Aug 20, 2023
813645e
wip checkpoint
Aug 20, 2023
2afe5ce
wip
Aug 21, 2023
745ec56
wip
Aug 21, 2023
31f33ca
wip pre x handles to transforms group
Aug 21, 2023
66d72b0
wip separate layout helpers
Aug 22, 2023
b8dccc8
wip checkpoint
Aug 22, 2023
042bae2
wip
Aug 22, 2023
8798276
wip
Aug 22, 2023
6d8b1b4
wip pre sync st alts
Aug 22, 2023
97e2f0a
wip separate stretch handlers
Aug 22, 2023
961d222
wip
Aug 22, 2023
3105e57
wip
Aug 22, 2023
d0c75f9
wip
Aug 22, 2023
6759419
wip breadth vs depth guarding
Aug 22, 2023
59d9234
wip
Aug 22, 2023
d8c1e7b
wip half fixed
Aug 22, 2023
15c6bd2
wip
Aug 23, 2023
34aefb7
wip width then length working
Aug 23, 2023
9ba35c6
wip when it started working
Aug 23, 2023
c1517e5
wip maybe x clamp working
Aug 23, 2023
80ccab2
yay
Aug 23, 2023
78bd397
wip
Aug 24, 2023
91846d1
wip
Aug 24, 2023
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
2 changes: 1 addition & 1 deletion app/analyse/state/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import { type WindowType } from "@/server/data/windowTypes"
import { useSelectedHouseIds } from "../ui/HousesPillsSelector"
import { useElements } from "../../data/elements"
import { useEnergyInfos } from "../../data/energyInfos"
import { type House } from "../../data/houses"
import { useMaterials } from "../../data/materials"
import { useSpaceTypes } from "../../data/spaceTypes"
import { useWindowTypes } from "../../data/windowTypes"
import { useGetHouseModules, useHouses } from "../../design/state/houses"
import { type House } from "../../db/user"

export type SystemsData = {
houseTypes: Array<HouseType>
Expand Down
2 changes: 1 addition & 1 deletion app/analyse/ui/FloorAreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const FloorAreaChart = () => {
pipe(
selectedHouses,
A.filterMap((selectedHouse) =>
selectedHouse.id === houseId
selectedHouse.houseId === houseId
? O.some({
houseId,
floorArea,
Expand Down
3 changes: 0 additions & 3 deletions app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { initTRPC } from "@trpc/server"
import { fetchRequestHandler } from "@trpc/server/adapters/fetch"
import { appRouter } from "@/server/trpc/router"

const t = initTRPC.create()

export type AppRouter = typeof appRouter

const handler = async (request: Request) => {
Expand Down
8 changes: 5 additions & 3 deletions app/build/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client"
import dynamic from "next/dynamic"
import { PropsWithChildren } from "react"
import Footer from "../ui/Footer"
import { TrpcProvider } from "../ui/TrpcProvider"
import { PreloadSpeckleObjects } from "../utils/speckle/useSpeckleObject"
import { getLayoutsWorker, getSystemsWorker } from "../workers"
import BuildNav from "./common/BuildNav"

const HousesPillsSelector = dynamic(
Expand All @@ -13,6 +13,9 @@ const HousesPillsSelector = dynamic(
)

const BuildLayout = ({ children }: PropsWithChildren<{}>) => {
getSystemsWorker()
getLayoutsWorker()

return (
<TrpcProvider>
<div className="flex-auto overflow-y-auto flex flex-col">
Expand All @@ -26,7 +29,6 @@ const BuildLayout = ({ children }: PropsWithChildren<{}>) => {
<div className="flex-auto border-l border-grey-20">{children}</div>
</div>
</div>
<PreloadSpeckleObjects />
</TrpcProvider>
)
}
Expand Down
6 changes: 5 additions & 1 deletion app/build/materials/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use client"
import { Download } from "@carbon/icons-react"
import dynamic from "next/dynamic"
import { useState } from "react"
import MaterialsListTable from "./MaterialsListTable"

const MaterialsListTable = dynamic(() => import("./MaterialsListTable"), {
ssr: false,
})

const MaterialsListIndexPage = () => {
const [csvDownloadUrl, setCsvDownloadUrl] = useState<string | null>(null)
Expand Down
2 changes: 1 addition & 1 deletion app/build/materials/useMaterialsListRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const useMaterialsListRows = () => {
embodiedCarbonPerUnit,
linkUrl,
unit,
} = getElementMaterial(house.id, item)
} = getElementMaterial(house.houseId, item)

const quantity = pipe(houseModules, A.reduce(0, reducer))

Expand Down
2 changes: 1 addition & 1 deletion app/build/order/useOrderListData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const useOrderListData = () => {

return pipe(
selectedHouses,
A.chain(({ id: houseId, dnas: dnas, ...house }) =>
A.chain(({ houseId: houseId, dnas: dnas, ...house }) =>
pipe(
dnas,
A.map((dna) => ({
Expand Down
7 changes: 1 addition & 6 deletions app/build/overview/HousesView.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
"use client"
import DataInit from "~/data/DataInit"
import GroupedApp from "~/design/ui-3d/grouped/GroupedApp"
import React from "react"
import dynamic from "next/dynamic"

const AppInit = dynamic(() => import("~/design/ui-3d/init/AppInit"), {
ssr: false,
})
import AppInit from "../../design/ui-3d/init/AppInit"

const HousesView = () => {
return (
Expand Down
4 changes: 3 additions & 1 deletion app/build/overview/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"use client"
import { ArrowDown } from "@carbon/icons-react"
import { pipe } from "fp-ts/lib/function"
import dynamic from "next/dynamic"
import { Fragment } from "react"
import { A } from "~/utils/functions"
import { useAnalyseData } from "../../analyse/state/data"
import { useSiteCurrency } from "../../design/state/siteCtx"
import HousesView from "./HousesView"
import css from "./page.module.css"

const HousesView = dynamic(() => import("./HousesView"), { ssr: false })

const OverviewIndex = () => {
const { formatWithSymbol } = useSiteCurrency()

Expand Down
98 changes: 72 additions & 26 deletions app/data/elements.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { trpc } from "@/client/trpc"
import { liveQuery } from "dexie"
import { pipe } from "fp-ts/lib/function"
import { useMemo } from "react"
import { BufferGeometry } from "three"
import { BufferGeometry, BufferGeometryLoader } from "three"
import { proxy, ref, useSnapshot } from "valtio"
import { O, R, RA, S } from "~/utils/functions"
import { Element } from "../../server/data/elements"
import { Module } from "../../server/data/modules"
import useSpeckleObject from "../utils/speckle/useSpeckleObject"
import layoutsDB from "../db/layouts"
import systemsDB from "../db/systems"
import { isSSR } from "../utils/next"

export const useElements = (): Element[] => {
const { data = [] } = trpc.elements.useQuery()
Expand All @@ -20,6 +22,34 @@ export const useSystemElements = ({
return useElements().filter((x) => x.systemId === systemId)
}

export const ifcTagToElement = ({
systemId,
elements,
ifcTag,
}: {
elements: Element[]
ifcTag: string
systemId: string
}) => {
const result = pipe(
elements,
RA.findFirst((el) => {
return (
el.ifc4Variable.toUpperCase() === ifcTag && el.systemId === systemId
)
}),
O.toUndefined
)

if (result === undefined) {
console.log({
unmatchedIfcTag: { ifcTag },
})
}

return result
}

export const useIfcTagToElement = (systemId: string) => {
const elements = useSystemElements({ systemId })

Expand Down Expand Up @@ -55,27 +85,43 @@ export const invertModuleElementGeometriesKey = (input: string) => {
return { systemId, dna }
}

export const useModuleElements = ({
systemId,
speckleBranchUrl,
}: Module): Record<string, BufferGeometry> => {
const ifcTagToElement = useIfcTagToElement(systemId)
const speckleObject = useSpeckleObject(speckleBranchUrl)
const models = proxy<Record<string, Record<string, BufferGeometry>>>({})

return useMemo(
() =>
pipe(
speckleObject,
R.reduceWithIndex(S.Ord)({}, (ifcTag, acc, geometry) => {
const el = ifcTagToElement(ifcTag)
if (!el) return acc
return {
...acc,
[el.name]: geometry,
}
})
),
// eslint-disable-next-line react-hooks/exhaustive-deps
[speckleBranchUrl]
)
const loader = new BufferGeometryLoader()

if (!isSSR()) {
liveQuery(async () => {
const models = await layoutsDB.models.toArray()
const elements = await systemsDB.elements.toArray()
return { models, elements }
}).subscribe(({ models: dbModels, elements: dbElements }) => {
for (let { speckleBranchUrl, geometries, systemId } of dbModels) {
if (!(speckleBranchUrl in models)) {
const loadedModels: Record<string, BufferGeometry> = pipe(
geometries,
R.map((x) => loader.parse(x) as BufferGeometry),
R.reduceWithIndex(S.Ord)({}, (ifcTag, acc, geometry) => {
const el = ifcTagToElement({
systemId,
elements: dbElements,
ifcTag,
})
if (!el) return acc
return {
...acc,
[el.name]: geometry,
}
})
)
models[speckleBranchUrl] = ref(loadedModels)
}
}
})
}

export const useSpeckleObject = (
speckleBranchUrl: string
): O.Option<Record<string, BufferGeometry>> => {
const snap = useSnapshot(models) as typeof models
return R.lookup(speckleBranchUrl)(snap)
}
40 changes: 0 additions & 40 deletions app/data/houses.ts

This file was deleted.

16 changes: 9 additions & 7 deletions app/data/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ export const filterCompatibleModules =
"gridType",
]
) =>
(module: Module) =>
A.filter((m: Module) =>
ks.reduce(
(acc: boolean, k) =>
acc && m.structuredDna[k] === module.structuredDna[k],
true
)
(moduleA: Module) =>
A.filter(
(moduleB: Module) =>
moduleB.systemId === moduleA.systemId &&
ks.reduce(
(acc: boolean, k) =>
acc && moduleB.structuredDna[k] === moduleA.structuredDna[k],
true
)
)

export const keysFilter =
Expand Down
Loading