Skip to content

Commit 61e0055

Browse files
committed
fix: incorrect positioning of clip edges and fills in models loaded after the first
1 parent e348ac1 commit 61e0055

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

packages/front/src/core/ClipStyler/src/clip-edges.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class ClipEdges implements OBC.Disposable {
8080
});
8181
}
8282

83-
private getStyleMeshes(modelId: string, styleName: string) {
83+
private async getStyleMeshes(modelId: string, styleName: string) {
8484
const clipStyler = this._components.get(ClipStyler);
8585
const style = clipStyler.styles.get(styleName);
8686
if (!style) {
@@ -107,14 +107,18 @@ export class ClipEdges implements OBC.Disposable {
107107
if (linesMaterial) {
108108
edges = new LineSegments2(new LineSegmentsGeometry(), linesMaterial);
109109
edges.frustumCulled = false;
110-
if (model) edges.applyMatrix4(model.object.matrixWorld);
110+
if (model) {
111+
fragments.applyBaseCoordinateSystem(edges, await model.getCoordinationMatrix())
112+
}
111113
this.three.add(edges);
112114
}
113-
115+
114116
let fills: THREE.Mesh | undefined;
115117
if (fillsMaterial) {
116118
fills = new THREE.Mesh(new THREE.BufferGeometry(), fillsMaterial);
117-
if (model) fills.applyMatrix4(model.object.matrixWorld);
119+
if (model) {
120+
fragments.applyBaseCoordinateSystem(fills, await model.getCoordinationMatrix())
121+
}
118122
this.three.add(fills);
119123
}
120124

@@ -137,12 +141,19 @@ export class ClipEdges implements OBC.Disposable {
137141
const disposer = this._components.get(OBC.Disposer);
138142

139143
const plane = this.plane.clone();
140-
plane.constant -= 0.01;
144+
145+
const planeTransform = (await model.getCoordinationMatrix())
146+
.clone()
147+
.multiply(fragments.baseCoordinationMatrix.clone().invert());
148+
149+
plane.applyMatrix4(planeTransform)
150+
151+
plane.constant -= 0.01; // little offset to avoid z-fighting
141152

142153
const section = await model.getSection(plane, localIds);
143154
const { buffer, index, fillsIndices } = section;
144155

145-
const meshes = this.getStyleMeshes(modelId, styleName);
156+
const meshes = await this.getStyleMeshes(modelId, styleName);
146157
const { edges, fills } = meshes;
147158

148159
const posAttr = new THREE.BufferAttribute(buffer, 3, false);
@@ -157,7 +168,7 @@ export class ClipEdges implements OBC.Disposable {
157168
edges.geometry.fromLineSegments(temp);
158169
disposer.destroy(temp);
159170
}
160-
171+
161172
// Update fills
162173
if (fills) {
163174
fills.geometry.attributes.position = posAttr;

0 commit comments

Comments
 (0)