Skip to content

Commit

Permalink
Merge pull request #18 from RyugaRyuzaki/develop
Browse files Browse the repository at this point in the history
refactoring
  • Loading branch information
RyugaRyuzaki authored May 31, 2024
2 parents d8c58f2 + 61713ca commit 83244ef
Show file tree
Hide file tree
Showing 108 changed files with 3,270 additions and 773 deletions.
987 changes: 983 additions & 4 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"eslint-plugin-react-refresh": "^0.3.4",
"postcss": "^8.4.35",
"tailwindcss": "^3.4.1",
"tsup": "^8.0.2",
"typescript": "^5.0.2",
"vite": "^4.3.9",
"vite-plugin-glsl": "^1.3.0",
Expand Down
35 changes: 21 additions & 14 deletions src/BimModel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import {
CubeMapComponent,
MaterialComponent,
ModelingComponent,
PropertyComponent,
RendererComponent,
RaycasterComponent,
StructureComponent,
ProjectComponent,
SystemComponent,
WorkPlane,
Snapper,
DrawTool,
LevelSystem,
} from "./src";

export class BimModel {
Expand Down Expand Up @@ -42,7 +43,7 @@ export class BimModel {
/* =====ProjectComponent===== */
const projectComponent = this.components.tools.get(ProjectComponent);
projectComponent.enabled = true;

projectComponent.init(this.structure);
/* =====RendererComponent===== */
const renderer = this.components.tools.get(RendererComponent);
renderer.enabled = true;
Expand All @@ -54,22 +55,28 @@ export class BimModel {
/* =====CubeMapComponent===== */
const cubeMapComponent = this.components.tools.get(CubeMapComponent);
cubeMapComponent.enabled = true;
/* =====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;

/* =====LevelSystem===== */
const levelSystem = this.components.tools.get(LevelSystem);
levelSystem.enabled = true;

/* =====ModelingComponent===== */
const modelingComponent = this.components.tools.get(ModelingComponent);
modelingComponent.enabled = true;
modelingComponent.init(this.modeling, this.option);

/* =====PropertyComponent===== */
const propertyComponent = this.components.tools.get(PropertyComponent);
propertyComponent.enabled = true;

/* =====StructureComponent===== */
const structureComponent = this.components.tools.get(StructureComponent);
structureComponent.enabled = true;
structureComponent.init(this.structure);

new SystemComponent(this.components);
this.components.gameLoop();
}
}
//
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/**
* @module DrawToolSystem
* @module DrawTool
*/

import * as THREE from "three";
import {Components, RaycasterComponent} from "@BimModel/src";
import {Components, Dimension, RaycasterComponent} from "@BimModel/src";
import {ToolComponent} from "@BimModel/src/Tool";
import {Component, Disposable} from "@BimModel/src/types";
import {systemGUID} from "../constants";
import {Component, Disposable, UUID} from "@BimModel/src/types";
import {
BaseDraw,
DrawArc,
Expand All @@ -19,17 +18,19 @@ import {
} from "./src";
import {effect} from "@preact/signals-react";
import {drawingTypeSignal} from "@BimModel/src/Signals";
export class DrawToolSystem extends Component<string> implements Disposable {
static readonly uuid = systemGUID.drawTool;
export class DrawTool extends Component<string> implements Disposable {
static readonly uuid = UUID.DrawTool;
enabled = false;
drawingDimension!: Dimension;
private draws: {[name: string]: BaseDraw} = {};

/**
*
*/
constructor(components: Components) {
super(components);
this.components.tools.add(DrawToolSystem.uuid, this);
this.components.tools.add(DrawTool.uuid, this);
this.drawingDimension = new Dimension(components);
this.initDraws();
effect(() => {
for (const name in this.draws) {
Expand All @@ -46,14 +47,15 @@ export class DrawToolSystem extends Component<string> implements Disposable {
});
}
async dispose() {
this.drawingDimension?.dispose();
for (const name in this.draws) {
this.draws[name]?.dispose();
}
this.draws = {};
}

get() {
return DrawToolSystem.uuid;
return DrawTool.uuid;
}
private initDraws() {
this.draws["Line"] = new DrawLine(this.components);
Expand All @@ -65,4 +67,4 @@ export class DrawToolSystem extends Component<string> implements Disposable {
this.draws["Circle"] = new DrawCircle(this.components);
}
}
ToolComponent.libraryUUIDs.add(DrawToolSystem.uuid);
ToolComponent.libraryUUIDs.add(DrawTool.uuid);
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
MaterialComponent,
lengthUnitSignal,
Dimension,
GeometrySystem,
DrawTool,
} from "@BimModel/src";
import {LineMaterial} from "three/examples/jsm/lines/LineMaterial";
import {ILevel} from "@system/08-level/types";
import {getLocalVectorOnFace} from "@BimModel/src/utils";
import {ILevel} from "@BimModel/src/LevelSystem/types";
const upDirection = new THREE.Vector3(0, 1, 0);

export abstract class BaseDraw {
Expand All @@ -29,7 +29,7 @@ export abstract class BaseDraw {
?.LocationMaterial as LineMaterial;
}
get drawingDimension(): Dimension {
return this.components.tools.get(GeometrySystem)?.drawingDimension;
return this.components.tools.get(DrawTool)?.drawingDimension;
}
get RaycasterComponent() {
return this.components.tools.get(RaycasterComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import * as THREE from "three";
import {Components} from "@BimModel/src/Components";
import {BaseDraw} from "./BaseDraw";
import {LocationArc} from "@system/01-geometry";
import {LocationArc} from "@system/geometry";
import {getDirection} from "@BimModel/src/utils";

export class DrawArc extends BaseDraw {
private tempLocation!: LocationArc;
Expand Down Expand Up @@ -55,11 +56,12 @@ export class DrawArc extends BaseDraw {
this.end,
this.movingPoint
);
this.drawingDimension.updateRadius(
this.start,
this.movingPoint,
this.workPlane
);
if (this.tempLocation.location) {
const {center, radius} = this.tempLocation.location;
const dir = getDirection(center, this.movingPoint);
const newMoving = center.clone().add(dir.multiplyScalar(radius));
this.drawingDimension.updateRadius(center, newMoving, this.workPlane);
}
}
this.tempLocation.visible = true;
this.drawingDimension.visible = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import * as THREE from "three";
import {Components} from "@BimModel/src/Components";
import {BaseDraw} from "./BaseDraw";
import {LocationArc} from "@system/01-geometry";
import {LocationArc} from "@system/geometry";
import {getDirection} from "@BimModel/src/utils";

export class DrawCircle extends BaseDraw {
private tempLocation!: LocationArc;
private tempLeftLocation!: LocationArc;
private tempRightLocation!: LocationArc;
private count = 0;
private start: THREE.Vector3 = new THREE.Vector3();
private end: THREE.Vector3 = new THREE.Vector3();
Expand All @@ -17,6 +19,12 @@ export class DrawCircle extends BaseDraw {
constructor(components: Components) {
super(components);
}
private getMirror() {
const dir = getDirection(this.start, this.end);
const dis = this.start.distanceTo(this.end);
return this.start.clone().add(dir.multiplyScalar(-dis));
}

onClick = (_e: MouseEvent) => {
if (!this.foundPoint || this.mousedown) return;
this.inputKey = "";
Expand All @@ -33,12 +41,17 @@ export class DrawCircle extends BaseDraw {
this.RaycasterComponent!.updateInfo(this.foundPoint);
if (this.count === 0) return;
this.end = this.foundPoint.clone();
// if measureControl.tempDim is null then create a dimensionLine
if (!this.tempLocation)
this.tempLocation = new LocationArc(this.components, this.workPlane);
// toggle visibility to true
this.tempLocation.updateCircle(this.start, this.end);
this.tempLocation.visible = true;
// update tempLeftLocation
if (!this.tempLeftLocation)
this.tempLeftLocation = new LocationArc(this.components, this.workPlane);
this.tempLeftLocation.updateCircle(this.start, this.end);
this.tempLeftLocation.visible = true;
//update tempRightLocation
if (!this.tempRightLocation)
this.tempRightLocation = new LocationArc(this.components, this.workPlane);
this.tempRightLocation.updateCircle(this.start, this.getMirror());
this.tempRightLocation.visible = true;
//update drawingDimension
this.drawingDimension.updateRadius(this.start, this.end, this.workPlane);
this.drawingDimension.visible = true;
};
Expand All @@ -58,9 +71,10 @@ export class DrawCircle extends BaseDraw {
this.inputKey = "";
return;
}
if (this.tempLocation) {
if (this.tempLeftLocation && this.tempRightLocation) {
this.end = this.getDistance(this.start, this.end, distance);
this.tempLocation.updateCircle(this.start, this.end);
this.tempLeftLocation.updateCircle(this.start, this.end);
this.tempRightLocation.updateCircle(this.start, this.getMirror());
this.onFinished();
this.inputKey = "";
this.count = 0;
Expand All @@ -71,19 +85,25 @@ export class DrawCircle extends BaseDraw {
}
};
onFinished = () => {
if (this.tempLocation) {
this.tempLocation.visible = false;
this.drawingDimension.visible = false;
(this.tempLocation as any) = null;
this.drawingDimension.visible = false;
if (this.tempLeftLocation) {
this.tempLeftLocation.visible = false;
(this.tempLeftLocation as any) = null;
}
if (this.tempRightLocation) {
this.tempRightLocation.visible = false;
(this.tempRightLocation as any) = null;
}
this.inputKey = "";
this.count = 0;
};
onCallBack = (_value?: number) => {};
dispose = () => {
this.drawingDimension.visible = false;
this.tempLocation?.dispose();
(this.tempLocation as any) = null;
this.tempLeftLocation?.dispose();
(this.tempLeftLocation as any) = null;
this.tempRightLocation?.dispose();
(this.tempRightLocation as any) = null;
this.count = 0;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as THREE from "three";
import {Components, isOrthoSignal} from "@BimModel/src";
import {BaseDraw} from "./BaseDraw";
import {LocationLine} from "@system/01-geometry";
import {LocationLine} from "@system/geometry";
export class DrawLine extends BaseDraw {
private tempLocation!: LocationLine;
private count = 0;
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/BimModel/src/ElementId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class ElementId {
static currentId = 0;
static undoIds: Set<number> = new Set();
static redoIds: Set<number> = new Set();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
import * as THREE from "three";
import {Components} from "@BimModel/src/Components";
import {ToolComponent} from "@BimModel/src/Tool";
import {Component, Disposable} from "@BimModel/src/types";
import {systemGUID} from "../constants";
import {Component, Disposable, UUID} from "@BimModel/src/types";
import {ILevel} from "./types";
import {
clippingPlanesSignal,
currentLevelSignal,
listLevelSignal,
} from "@BimModel/src/Signals";
import {RendererComponent} from "@BimModel/src/RendererComponent";
import {WorkPlaneSystem} from "../12-work-plane";
import {WorkPlane} from "../WorkPlane";

const defaultLevels: ILevel[] = [
{
Expand All @@ -36,13 +35,13 @@ const upPlane = new THREE.Plane();
const downPlane = new THREE.Plane();

export class LevelSystem extends Component<string> implements Disposable {
static readonly uuid = systemGUID.level;
static readonly uuid = UUID.LevelSystem;
enabled = false;
get renderer() {
return this.components.tools.get(RendererComponent);
}
get workPlane() {
return this.components.tools.get(WorkPlaneSystem);
return this.components.tools.get(WorkPlane);
}
get camera() {
return this.renderer?.camera;
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/BimModel/src/ModelingComponent/src/InitComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import NewProject from "./Project/NewProject";
import VisibilityOption from "./VisibilityOption/VisibilityOption";
import LineOption from "./LineOption/LineOption";
import WorkPlaneOption from "./WorkPlaneOption/WorkPlaneOption";
import ElementType from "./ModelingOption/ElementType/ElementType";

export function createModelingContainer(modeling: ModelingComponent) {
const div = document.createElement("div");
Expand All @@ -18,6 +19,7 @@ export function createModelingContainer(modeling: ModelingComponent) {
<ModelingTabs></ModelingTabs>
<ProjectInfo modeling={modeling}></ProjectInfo>
<NewProject modeling={modeling}></NewProject>
<ElementType></ElementType>
</>
);
return div;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from "react";
import {Button} from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import {Input} from "@/components/ui/input";
import {Label} from "@/components/ui/label";
import {openElementTypeSignal} from "@BimModel/src/Signals";
const ElementType = () => {
const handleOK = () => {
openElementTypeSignal.value = false;
};
return (
<Dialog open={openElementTypeSignal.value}>
<DialogContent className="xl:max-w-[50%]">
<DialogHeader>
<DialogTitle>Edit profile</DialogTitle>
</DialogHeader>
<div className="flex justify-between gap-4 py-4 h-[600px]">
<p>asdasd</p>
<p>asdasd</p>
</div>
<DialogFooter className="flex justify-between">
<Button type="submit" onClick={handleOK}>
OK
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
};

export default ElementType;
Loading

0 comments on commit 83244ef

Please sign in to comment.