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

Toggle Plan View #364

Merged
merged 29 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
58a3f4b
add methods for the cut plane
OlegMoshkovich Aug 13, 2022
cf19f8d
connect cut plane functionality to the button
OlegMoshkovich Aug 15, 2022
7c636dc
create a cutplane
OlegMoshkovich Aug 15, 2022
dfcca3e
push plane hash into url
OlegMoshkovich Aug 15, 2022
eaf8341
fix render hook trouble with the import
OlegMoshkovich Aug 23, 2022
07e161a
ExtractLevels Demo
mkeshavarzi Aug 26, 2022
bffa130
Add Plan View
mkeshavarzi Aug 30, 2022
fb0cd1b
Extract Height in script
mkeshavarzi Sep 14, 2022
b848856
Link extracted heights to menu [NEED FIX}
mkeshavarzi Sep 14, 2022
2381887
Return floorplan menu
mkeshavarzi Sep 14, 2022
bf61956
Lint clean
mkeshavarzi Sep 14, 2022
f8783e4
Merge remote-tracking branch 'upstream/main' into ExtractLevelsMenu
mkeshavarzi Sep 14, 2022
1eb00ef
Continue attempt to generate submenu
Sep 15, 2022
c656f55
Lint and Tests
Sep 15, 2022
55a738e
Revert "Add Plan View"
mkeshavarzi Sep 16, 2022
f6e1a6f
Revert "Revert "Add Plan View""
mkeshavarzi Sep 16, 2022
446c084
Reset to Manual model
mkeshavarzi Sep 16, 2022
79a0a06
Lint and tests
mkeshavarzi Sep 16, 2022
0f2d250
Level extraction directly from model.
mkeshavarzi Sep 16, 2022
bbeb43f
Another try
mkeshavarzi Sep 17, 2022
07e53cf
Utilize useState
mkeshavarzi Sep 21, 2022
0e78f60
Fix Duplication Bug
mkeshavarzi Sep 21, 2022
d55336e
Fix farInt issue
mkeshavarzi Sep 21, 2022
bfc99c2
Clean code + lint
mkeshavarzi Sep 21, 2022
a513e4e
Fixed duplication bug from another file
mkeshavarzi Sep 22, 2022
48f2378
Toggle to Center
mkeshavarzi Aug 31, 2022
4eb6398
Toggle back to non-top perspective view.
mkeshavarzi Aug 31, 2022
cfafd7e
Added icon for Toggle Plan View
mkeshavarzi Aug 31, 2022
8b8736d
Rebased to AutoLevelExtraction
mkeshavarzi Sep 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bldrs",
"version": "1.0.0-r403",
"version": "1.0.0-r443",
"main": "src/index.jsx",
"homepage": "https://github.com/bldrs-ai/Share",
"bugs": {
Expand Down
180 changes: 180 additions & 0 deletions src/Components/ExtractLevelsMenu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@

import React, {useState, useEffect} from 'react'
import Menu from '@mui/material/Menu'
import MenuItem from '@mui/material/MenuItem'
import {makeStyles} from '@mui/styles'
import {TooltipIconButton} from './Buttons'
import useStore from '../store/useStore'
import {getModelCenter} from '../utils/cutPlane'
import {addHashParams, getHashParams} from '../utils/location'
import {Vector3} from 'three'
import {useLocation} from 'react-router-dom'
import {removePlanes} from '../utils/cutPlane'
import LevelsIcon from '../assets/2D_Icons/Levels.svg'
import PlanViewIcon from '../assets/2D_Icons/PlanView.svg'
import {extractHeight} from '../utils/extractHeight'

/**
* BasicMenu used when there are several option behind UI button
* show/hide from the right of the screen.
*
* @param {Array} listOfOptions Title for the drawer
* @return {object} ItemPropertiesDrawer react component
*/
export default function ExtractLevelsMenu({listOfOptions, icon, title}) {
const [anchorEl, setAnchorEl] = useState(null)
const classes = useStyles()
const open = Boolean(anchorEl)

const model = useStore((state) => state.modelStore)
let [floorplanMenuItems, showExtractMenu] = useState([])


const PLANE_PREFIX = 'p'
const handleClick = (event) => {
setAnchorEl(event.currentTarget)
}
const handleClose = () => {
setAnchorEl(null)
}
const viewer = useStore((state) => state.viewerStore)
const location = useLocation()
const createFloorplanPlane = (h1, h2) => {
console.log('Got here')
removePlanes(viewer)
const modelCenter1 = new Vector3(0, h1, 0)
const modelCenter2 = new Vector3(0, h2, 0)
const normal1 = new Vector3(0, 1, 0)
const normal2 = new Vector3(0, -1, 0)
viewer.clipper.createFromNormalAndCoplanarPoint(normal1, modelCenter1)
viewer.clipper.createFromNormalAndCoplanarPoint(normal2, modelCenter2)
}
const planView = () => {
viewer.context.ifcCamera.toggleProjection()
viewer.plans.moveCameraTo2DPlanPosition(true)
const yConst = 100 // value used in moveCameraTo2DPlanPosition in web-ifc
const modelCenterX = getModelCenter(model).x
const modelCenterY = getModelCenter(model).y
const modelCenterZ = getModelCenter(model).z
viewer.context.ifcCamera.cameraControls.setLookAt(modelCenterX, yConst, modelCenterZ, modelCenterX, 0, modelCenterZ, true)
const currentProjection = viewer.context.ifcCamera.projectionManager.currentProjection
const camFac = 5
if (currentProjection === 0) {
viewer.context.ifcCamera.cameraControls.setLookAt(
modelCenterX * camFac, modelCenterY * camFac, -modelCenterZ * camFac, modelCenterX, modelCenterY, modelCenterZ, true)
}
}
const createPlane = (normalDirection) => {
const modelCenter = getModelCenter(model)
const planeHash = getHashParams(location, 'p')
console.log('in the function modelCenter', modelCenter)
let normal
switch (normalDirection) {
case 'x':
normal = new Vector3(1, 0, 0)
break
case 'y':
normal = new Vector3(0, 1, 0)
break
case 'z':
normal = new Vector3(0, 0, 1)
break
default:
normal = new Vector3(0, 1, 0)
break
}
console.log('in the function normal', normal)
if (!planeHash || planeHash !== normalDirection ) {
addHashParams(window.location, PLANE_PREFIX, {planeAxis: normalDirection})
}
return viewer.clipper.createFromNormalAndCoplanarPoint(normal, modelCenter)
}
useEffect(() => {
const planeHash = getHashParams(location, 'p')
if (planeHash && model && viewer) {
const modelCenter = getModelCenter(model)
const planeDirection = planeHash.split(':')[1]
let normal
switch (planeDirection) {
case 'x':
normal = new Vector3(1, 0, 0)
break
case 'y':
normal = new Vector3(0, 1, 0)
break
case 'z':
normal = new Vector3(0, 0, 1)
break
default:
normal = new Vector3(0, 1, 0)
break
}
console.log(' ------------------------- ')
console.log('the modelCenter from the useEffect', modelCenter)
console.log('plane direction', planeDirection)
console.log('normal', normal)
console.log(' ------------------------- ')
createPlane(planeDirection)
// viewer.clipper.createFromNormalAndCoplanarPoint(normal, modelCenter)
}
}, [model])

showExtractMenu = async () => {
const allStor = await extractHeight(model)
if (floorplanMenuItems.length + 1 <= allStor.length) {
const planeoffset = 0.5
for (let i = 0; i < allStor.length; i++) {
floorplanMenuItems[i] = (
<MenuItem onClick={() =>
createFloorplanPlane(allStor[i], allStor[i + 1] - planeoffset)}
> L{i} </MenuItem>)
}
}
}

showExtractMenu()

return (
<div>
<TooltipIconButton
title={'Extract Levels'}
icon={<LevelsIcon/>}
onClick={handleClick}
/>
<Menu
elevation={1}
id='basic-menu'
anchorEl={anchorEl}
open={open}
onClose={handleClose}
anchorOrigin={{vertical: 'top', horizontal: 'center'}}
transformOrigin={{vertical: 'top', horizontal: 'center'}}
className={classes.root}
PaperProps={{
style: {
left: '300px',
transform: 'translateX(-40px) translateY(-40px)',
},
}}
>
<TooltipIconButton
title={'Toggle Plan View'}
icon={<PlanViewIcon/>}
onClick={planView}
/>
{floorplanMenuItems}
</Menu>
</div>
)
}

const useStyles = makeStyles({
root: {
'& .MuiMenu-root': {
position: 'absolute',
left: '-200px',
top: '200px',
},
},
},
)
2 changes: 2 additions & 0 deletions src/Components/OperationsGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {makeStyles} from '@mui/styles'
import useStore from '../store/useStore'
import CameraControl from './CameraControl'
import CutPlaneMenu from './CutPlaneMenu'
import ExtractLevelsMenu from './ExtractLevelsMenu'
import ShareControl from './ShareControl'
import ShortcutsControl from './ShortcutsControl'
import {TooltipIconButton} from './Buttons'
Expand Down Expand Up @@ -60,6 +61,7 @@ export default function OperationsGroup({unSelectItem}) {
null
}
<CutPlaneMenu/>
<ExtractLevelsMenu/>
<TooltipIconButton title="Clear selection" onClick={unSelectItem} icon={<ClearIcon/>}/>
<ShortcutsControl/>
</div>
Expand Down