Skip to content

Commit 46ee63e

Browse files
committed
feat(core): add section mesh generation component
1 parent f9ea2c4 commit 46ee63e

File tree

6 files changed

+518
-6
lines changed

6 files changed

+518
-6
lines changed

packages/core/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thatopen/components",
33
"description": "Collection of core functionalities to author BIM apps.",
4-
"version": "2.4.2",
4+
"version": "2.4.3",
55
"author": "That Open Company",
66
"contributors": [
77
"Antonio Gonzalez Viegas (https://github.com/agviegas)",
@@ -39,13 +39,15 @@
3939
"devDependencies": {
4040
"@thatopen/fragments": "~2.4.0",
4141
"@thatopen/ui": "~2.4.0",
42+
"@types/earcut": "2.1.4",
4243
"@types/three": "0.160.0",
4344
"stats.js": "^0.17.0",
4445
"three": "^0.160.1",
4546
"web-ifc": "0.0.66"
4647
},
4748
"dependencies": {
4849
"camera-controls": "2.7.3",
50+
"earcut": "2.2.4",
4951
"fast-xml-parser": "4.4.1",
5052
"jszip": "3.10.1",
5153
"three-mesh-bvh": "0.7.0"

packages/core/src/core/Components/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class Components implements Disposable {
1414
/**
1515
* The version of the @thatopen/components library.
1616
*/
17-
static readonly release = "2.4.2";
17+
static readonly release = "2.4.3";
1818

1919
/** {@link Disposable.onDisposed} */
2020
readonly onDisposed = new Event<void>();

packages/core/src/core/Worlds/example.ts

+42-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ In this tutorial, we will import:
2323
import * as THREE from "three";
2424
import * as BUI from "@thatopen/ui";
2525
import Stats from "stats.js";
26-
import * as OBC from "@thatopen/components";
26+
import * as OBC from "../..";
2727

2828
/* MD
2929
### 🖼️ Getting the container
@@ -106,11 +106,51 @@ world.scene.three.background = null;
106106
107107
*/
108108

109-
const material = new THREE.MeshLambertMaterial({ color: "#6528D7" });
109+
const material = new THREE.MeshLambertMaterial({
110+
color: "#6528D7",
111+
transparent: true,
112+
opacity: 0.2,
113+
});
110114
const geometry = new THREE.BoxGeometry();
111115
const cube = new THREE.Mesh(geometry, material);
112116
world.scene.three.add(cube);
113117

118+
cube.rotation.x += Math.PI / 4.2;
119+
cube.rotation.y += Math.PI / 4.2;
120+
cube.rotation.z += Math.PI / 4.2;
121+
cube.updateMatrixWorld();
122+
123+
const buffer = new Float32Array(300000);
124+
const posAttr = new THREE.BufferAttribute(buffer, 3, false);
125+
posAttr.setUsage(THREE.DynamicDrawUsage);
126+
127+
const edgesGeometry = new THREE.BufferGeometry();
128+
edgesGeometry.setAttribute("position", posAttr);
129+
130+
const edges = new THREE.LineSegments(
131+
edgesGeometry,
132+
new THREE.LineBasicMaterial({ color: "red", linewidth: 0.001 }),
133+
);
134+
135+
edges.frustumCulled = false;
136+
137+
world.scene.three.add(edges);
138+
139+
const plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
140+
const edgeGenerator = components.get(OBC.EdgeGenerator);
141+
edgeGenerator.plane = plane;
142+
143+
const { index } = edgeGenerator.generate({
144+
meshes: [cube],
145+
posAttr,
146+
});
147+
148+
edges.geometry.setDrawRange(0, index);
149+
posAttr.needsUpdate = true;
150+
console.log(edges);
151+
152+
153+
114154
/* MD
115155
Finally, we will make the camera look at the cube:
116156
*/

packages/core/src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from "./geometry";
33
export * from "./materials";
44
export * from "./uuid";
55
export * from "./vertex-picker";
6+
export * from "./section-generator";

0 commit comments

Comments
 (0)