Skip to content

Commit

Permalink
Merge pull request #22 from RyugaRyuzaki/develop
Browse files Browse the repository at this point in the history
add browser view
  • Loading branch information
RyugaRyuzaki committed Jun 9, 2024
2 parents 0d18c6a + 53946d5 commit bf4c84b
Show file tree
Hide file tree
Showing 44 changed files with 1,270 additions and 315 deletions.
10 changes: 5 additions & 5 deletions src/BimModel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export class BimModel {
/* =====WorkPlane===== */
const workPlane = this.components.tools.get(WorkPlane);
workPlane.enabled = true;

/* =====Snapper===== */
const snapper = this.components.tools.get(Snapper);
snapper.enabled = true;
/* =====DrawTool===== */
const drawTool = this.components.tools.get(DrawTool);
drawTool.enabled = true;
Expand All @@ -75,13 +77,11 @@ export class BimModel {
/* =====SelectionComponent===== */
const selectionComponent = this.components.tools.get(SelectionComponent);
selectionComponent.enabled = true;
/* =====Snapper===== */
const snapper = this.components.tools.get(Snapper);
snapper.enabled = true;
this.components.ifcModel.init().then(() => {
projectComponent.init(this.structure, this.property);
projectComponent.init(this.property);
projectComponent.initElement();
modelingComponent.init(this.modeling, this.option);
levelSystem.initView(this.structure);
});
this.components.gameLoop();
}
Expand Down
9 changes: 7 additions & 2 deletions src/BimModel/src/Components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
isModelingSignal,
isOrthoSignal,
keyboardSignal,
visibilityStateSignal,
selectViewSignal,
} from "../Signals";
import {RendererComponent} from "../RendererComponent";
import {SceneBuilder} from "./SceneBuilder";
Expand Down Expand Up @@ -50,7 +50,12 @@ export class Components implements Disposable {
const mouseButtons =
this.tools.get(RendererComponent)!.camera.cameraControls.mouseButtons;
if (!mouseButtons) return;
mouseButtons.left = visibilityStateSignal.value === "3D" && enabled ? 1 : 0;
mouseButtons.left =
selectViewSignal.value &&
selectViewSignal.value.viewType === "3D" &&
enabled
? 1
: 0;
}
set setupEvent(enabled: boolean) {
if (enabled) {
Expand Down
29 changes: 27 additions & 2 deletions src/BimModel/src/CubeMapComponent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {CubeMapMaterial, BoxCube} from "./src";
import {RendererComponent} from "../RendererComponent";
import {defaultBox, defaultSphere, switchPick} from "../utils";
import {IView} from "../LevelSystem/types";

const near = 1,
far = 10000;
Expand All @@ -30,8 +31,8 @@ export class CubeMapComponent
static readonly uuid = UUID.CubeMapComponent;
enabled = false;
private materials = new CubeMapMaterial();
private box: THREE.Box3 = defaultBox;
private sphere: THREE.Sphere = defaultSphere();
box: THREE.Box3 = defaultBox;
sphere: THREE.Sphere = defaultSphere();
private container!: HTMLDivElement;
private canvas!: HTMLCanvasElement;
set align(position: ICubeMapPosition) {
Expand Down Expand Up @@ -296,5 +297,29 @@ export class CubeMapComponent
controls.setLookAt(pos.x, pos.y, pos.z, center.x, center.y, center.z);
controls.fitToSphere(this.sphere, true);
}
onNavigationElevation(view: IView) {
if (view.viewType !== "Elevation" || !view.elevationType) return;
const controls =
this.components.tools.get(RendererComponent).camera.cameraControls;
const {center} = this.sphere;
const {max, min} = this.box;
const pos = center.clone();
switch (view.elevationType) {
case "South":
pos.set(0, center.y, max.z);
break;
case "West":
pos.set(min.x, center.y, 0);
break;
case "East":
pos.set(max.x, center.y, 0);
break;
case "North":
pos.set(0, center.y, min.z);
break;
}
controls.setLookAt(pos.x, pos.y, pos.z, center.x, center.y, center.z);
controls.fitToSphere(this.sphere, true);
}
}
ToolComponent.libraryUUIDs.add(CubeMapComponent.uuid);
1 change: 0 additions & 1 deletion src/BimModel/src/DrawTool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export class DrawTool extends Component<string> implements Disposable {
this.components.tools.add(DrawTool.uuid, this);
this.drawingDimension = new Dimension(components);
this.initDraws();

effect(() => {
for (const name in this.draws) {
const draw = this.draws[name];
Expand Down
9 changes: 9 additions & 0 deletions src/BimModel/src/DrawTool/src/BaseDraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,13 @@ export abstract class BaseDraw {
).normalize();
return start.clone().add(dir.multiplyScalar(distance));
}
disposeElement() {
this.Snapper.snapper = null;
if (!this.tempElement) return;
for (const mesh of this.tempElement.meshes) {
mesh.removeFromParent();
}
this.tempElement.type.deleteInstance(this.tempElement.attributes.expressID);
(this.tempElement as any) = null;
}
}
34 changes: 7 additions & 27 deletions src/BimModel/src/DrawTool/src/DrawLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class DrawLine extends BaseDraw {
} else {
this.start = this.foundPoint.clone();
}
if (this.Snapper.snap) this.start.copy(this.Snapper.snap);
this.points.push(this.start);
// if the first time user click
// if another time
Expand Down Expand Up @@ -65,7 +66,7 @@ export class DrawLine extends BaseDraw {
this.end = this.foundPoint.clone();
this.orthoDir = null;
}

if (this.Snapper.snap) this.end = this.Snapper.snap.clone();
// if measureControl.tempDim is null then create a dimensionLine
const start = this.points[this.points.length - 1];
if (!this.locationLine)
Expand Down Expand Up @@ -141,14 +142,10 @@ export class DrawLine extends BaseDraw {
case "Structure Beam":
element.addQsetBeamCommon();
break;
case "Wall":
case "Structure Wall":
element.addQsetWallCommon();
break;
case "Structure Column":
case "Structure Slab":
case "Structure Foundation":
case "ReinForcement":
break;
default:
break;
}
Expand All @@ -164,27 +161,22 @@ export class DrawLine extends BaseDraw {
case "Structure Beam":
if (!this.tempElement)
this.tempElement = selectType.addInstance(
this.MaterialComponent.BeamMaterial
this.MaterialComponent.materialCategories[type]!
) as SimpleBeam;
this.tempElement.attributes.Name = new IFC.IfcLabel(
`${type} ${this.CurrentElementIndex + 1}`
);
break;
case "Wall":
case "Structure Wall":
if (!this.tempElement)
this.tempElement = selectType.addInstance(
this.MaterialComponent.WallMaterial
this.MaterialComponent.materialCategories[type]!
) as SimpleWall;

this.tempElement.attributes.Name = new IFC.IfcLabel(
`${type} ${this.CurrentElementIndex + 1}`
);

break;
case "Structure Column":
case "Structure Slab":
case "Structure Foundation":
case "ReinForcement":
break;
default:
break;
Expand Down Expand Up @@ -212,6 +204,7 @@ export class DrawLine extends BaseDraw {
(this.tempElement as SimpleBeam).endPoint.z = end.y;
(this.tempElement as SimpleBeam).update(true);
break;
case "Wall":
case "Structure Wall":
(this.tempElement as SimpleWall).startPoint.x = start.x;
(this.tempElement as SimpleWall).startPoint.y = -start.z;
Expand All @@ -221,21 +214,8 @@ export class DrawLine extends BaseDraw {
(this.tempElement as SimpleWall).endPoint.z = end.y;
(this.tempElement as SimpleWall).update(true, true);
break;
case "Structure Column":
case "Structure Slab":
case "Structure Foundation":
case "ReinForcement":
break;
default:
break;
}
};
disposeElement() {
if (!this.tempElement) return;
for (const mesh of this.tempElement.meshes) {
mesh.removeFromParent();
}
this.tempElement.type.deleteInstance(this.tempElement.attributes.expressID);
(this.tempElement as any) = null;
}
}
128 changes: 123 additions & 5 deletions src/BimModel/src/DrawTool/src/DrawPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ import {Components} from "@BimModel/src/Components";
import {BaseDraw} from "./BaseDraw";
import {IDrawType} from "@ModelingComponent/types";
import {LocationArc, LocationLine, LocationPoint} from "@BimModel/src/system";
import {
modelingSignal,
modelStructureSignal,
tempElementSignal,
} from "@BimModel/src/Signals";
import {IFC4X3 as IFC} from "web-ifc";
import {SimpleColumn} from "clay";

export class DrawPoint extends BaseDraw {
drawType: IDrawType = "Point";

private locationPoint!: LocationPoint;
/**
*
*/
Expand All @@ -19,23 +26,134 @@ export class DrawPoint extends BaseDraw {
};
onMouseMove = (_e: MouseEvent) => {
this.findPoint = _e;
this.Snapper.find = _e;
if (!this.foundPoint || this.mousedown) return;
this.RaycasterComponent!.updateInfo(this.foundPoint);
const point = this.foundPoint.clone();
if (this.Snapper.snap) point.copy(this.Snapper.snap);
if (!this.locationPoint)
this.locationPoint = new LocationPoint(this.components);
this.locationPoint.update(point);
this.locationPoint.visible = true;
this.createElement();
this.updateElement(this.locationPoint);
};
onMousedown = (_e: MouseEvent) => {
if (_e.button === 0) this.mousedown = true;
};
onKeyDown = (_e: KeyboardEvent) => {};
onKeyDown = (_e: KeyboardEvent) => {
if (_e.key === " ") {
if (!tempElementSignal.value || !modelingSignal.value) return;
const {selectType} = tempElementSignal.value.bimElementTypes;
if (!selectType) return;
const {type} = modelingSignal.value;
if (!this.tempElement) return;
switch (type) {
case "Column":
case "Structure Column":
this.tempElement.rotation.z =
this.tempElement.rotation.z + Math.PI / 4;
this.tempElement.update(true);
break;
default:
break;
}
}
};

onFinished = () => {
this.drawingDimension.visible = false;
this.addElement();
};
onCallBack = (_value?: number) => {};
dispose = () => {
this.disposeElement();
this.drawingDimension.visible = false;
this.locationPoint?.dispose();
(this.locationPoint as any) = null;
};
addElement = () => {
if (
!this.tempElement ||
!tempElementSignal.value ||
!modelingSignal.value ||
!modelStructureSignal.value
)
return;
const {type} = modelingSignal.value;
const bimElementTypes = {...tempElementSignal.value.bimElementTypes};
const element = this.ProjectComponent.setElement(
type,
bimElementTypes,
this.tempElement,
this.locationPoint
);
element.groupParameter = {...tempElementSignal.value.groupParameter};
switch (type) {
case "Structure Beam":
case "Structure Wall":
case "Structure Slab":
case "Structure Foundation":
case "ReinForcement":
break;
case "Structure Column":
break;
default:
break;
}
(this.tempElement as any) = null;
(this.locationPoint as any) = null;
};
createElement = () => {
if (!tempElementSignal.value || !modelingSignal.value) return;
const {selectType} = tempElementSignal.value.bimElementTypes;
if (!selectType) return;
const {type} = modelingSignal.value;
switch (type) {
case "Structure Beam":
case "Structure Wall":
case "Structure Slab":
case "Structure Foundation":
case "ReinForcement":
break;
case "Structure Column":
if (!this.tempElement)
this.tempElement = selectType.addInstance(
this.MaterialComponent.materialCategories[type]!
) as SimpleColumn;
this.tempElement.attributes.Name = new IFC.IfcLabel(
`${type} ${this.CurrentElementIndex + 1}`
);
break;
default:
break;
}
this.components.modelScene.updateMatrixWorld(true);
if (this.tempElement)
this.components.modelScene.add(...this.tempElement.meshes);
};
updateElement = (_location: LocationPoint | LocationArc | LocationLine) => {
if (!tempElementSignal.value || !modelingSignal.value) return;
const {selectType} = tempElementSignal.value.bimElementTypes;
if (!selectType) return;
const {type} = modelingSignal.value;
if (!this.tempElement) return;
if (!this.locationPoint) return;
switch (type) {
case "Structure Beam":
case "Structure Wall":
case "Structure Slab":
case "Structure Foundation":
case "ReinForcement":
break;
case "Structure Column":
this.tempElement.position.x = this.locationPoint.location.point.x;
this.tempElement.position.y = -this.locationPoint.location.point.z;
this.tempElement.position.z = this.locationPoint.location.point.y;
this.tempElement.update(true);
break;
default:
break;
}
};
addElement = () => {};
createElement = () => {};
updateElement = (_location: LocationPoint | LocationArc | LocationLine) => {};
}
Loading

0 comments on commit bf4c84b

Please sign in to comment.