Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions main/opengeometry-three/src/primitives/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@ export class Line extends THREE.Line {
this.geometry = geometry;
this.material = new THREE.LineBasicMaterial({ color: this.options.color });
}

getDXF() {
const dxfData = this.line.get_dxf_serialized();
return dxfData;
}
}
4 changes: 3 additions & 1 deletion main/opengeometry-three/src/shapes/cuboid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ export class Cuboid extends THREE.Mesh {
setConfig(options: ICuboidOptions) {
this.validateOptions();

const { width, height, depth, center } = options;
const { width, height, depth, center, color } = options;
this.cuboid.set_config(
center.clone(),
width,
height,
depth
);

this.options.color = color;

this.generateGeometry();
}

Expand Down
4 changes: 3 additions & 1 deletion main/opengeometry-three/src/shapes/opening.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ export class Opening extends THREE.Mesh {
const material = new THREE.MeshStandardMaterial({
color: this.options.color,
transparent: true,
opacity: 0.6,
opacity: 0,
// Disable depth writing for transparent materials, so that we can see through openings and elements behind them
depthWrite: false,
});

geometry.computeVertexNormals();
Expand Down
46 changes: 30 additions & 16 deletions main/opengeometry-three/src/shapes/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import { OGPolygon, Vector3 } from "../../../opengeometry/pkg/opengeometry";
import { getUUID } from "../utils/randomizer";

interface IPolygonOptions {
ogid?: string;
vertices: Vector3[];
color: number;
}

export class Polygon extends THREE.Mesh {
ogid: string;
options: IPolygonOptions = { vertices: [] };
options: IPolygonOptions = { vertices: [], color: 0x00ff00 };
polygon: OGPolygon;
#outlineMesh: THREE.Line | null = null;

#color: number = 0x00ff00;

transformationMatrix: THREE.Matrix4 = new THREE.Matrix4();

set color(color: number) {
this.#color = color;
this.options.color = color;
if (this.material instanceof THREE.MeshStandardMaterial) {
this.material.color.set(color);
}
Expand All @@ -33,14 +33,13 @@ export class Polygon extends THREE.Mesh {
// constructor(vertices?: Vector3[]) // If no vertices are provided, it will be an empty polygon
constructor(options?: IPolygonOptions) {
super();
this.ogid = getUUID();
if (options) {
this.options = options;
}
this.ogid = options?.ogid ?? getUUID();
this.polygon = new OGPolygon(this.ogid);

this.options = { ...this.options, ...options };
this.options.ogid = this.ogid;

this.setConfig();
this.generateGeometry();
this.setConfig(this.options);

// TODO: THIS MIGHT HELP WITH SHARING THE POSITION with KERNEL when something is changed
// const originalSet = this.position.set.bind(this.position);
Expand All @@ -64,10 +63,15 @@ export class Polygon extends THREE.Mesh {
}
}

setConfig() {
setConfig(options: IPolygonOptions) {
this.validateOptions();
const { vertices } = this.options;

const { vertices, color } = options;
this.polygon.set_config(vertices);

this.options.color = color;

this.generateGeometry();
}

// /**
Expand Down Expand Up @@ -128,7 +132,17 @@ export class Polygon extends THREE.Mesh {
// return this._yaw;
// }

cleanGeometry() {
this.geometry.dispose();
if (Array.isArray(this.material)) {
this.material.forEach(mat => mat.dispose());
} else {
this.material.dispose();
}
}

generateGeometry() {
this.cleanGeometry();

// this.updateMatrix();
// this.transformationMatrix.copy(this.matrix);
Expand All @@ -155,10 +169,10 @@ export class Polygon extends THREE.Mesh {
new THREE.Float32BufferAttribute(bufferData, 3)
);

const material = new THREE.MeshStandardMaterial({
color: this.#color,
transparent: true,
opacity: 0.6,
const material = new THREE.MeshBasicMaterial({
color: this.options.color,
// transparent: true,
// opacity: 1,
// TODO: Enabling Double Side untill we have proper face normals from triangulation
side: THREE.DoubleSide,
});
Expand Down
4 changes: 3 additions & 1 deletion main/opengeometry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ serde_json = "1.0.127"
web-sys = { version = "0.3", features = ["console"] }
openmaths = "0.2.4"
uuid = { version = "1.17.0", features = ["v4", "serde", "js"] }
earcutr = "=0.3.0"
getrandom = { version = "0.2", features = ["js"] }
earcutr = "=0.3.0"
dxf = "0.6.0"
7 changes: 7 additions & 0 deletions main/opengeometry/src/primitives/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use wasm_bindgen::prelude::*;
use serde::{Serialize, Deserialize};
use openmaths::Vector3;
use uuid::Uuid;
use dxf::Drawing;
use dxf::entities::*;

#[wasm_bindgen]
#[derive(Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -104,4 +106,9 @@ impl OGLine {
let vertex_serialized = serde_json::to_string(&vertex_buffer).unwrap();
vertex_serialized
}

pub fn get_dxf_serialized(&self) -> String {
// TODO: Implement DXF serialization for line
String::new()
}
}