Skip to content

Commit

Permalink
Merge pull request #58 from galacean/fix/gizmo-wireframe
Browse files Browse the repository at this point in the history
fix: gizmo rendering problem
  • Loading branch information
liuxi150 authored Dec 20, 2023
2 parents 145168f + 9e72d5c commit d3b75b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
18 changes: 14 additions & 4 deletions plugin-packages/editor-gizmo/src/gizmo-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,21 @@ export class EditorGizmoPlugin extends AbstractPlugin {
}
}
}
const wireframeMesh = gizmoVFXItem.wireframeMesh;

if (wireframeMesh && !wireframeMesh.isDestroyed) {
destroyWireframeMesh(wireframeMesh);
this.getEditorRenderPass(composition.renderFrame).removeMesh(wireframeMesh);
if (gizmoVFXItem.wireframeMeshes.length > 0) {
gizmoVFXItem.wireframeMeshes.forEach(mesh => {
if (!mesh.isDestroyed) {
destroyWireframeMesh(mesh);
this.getEditorRenderPass(composition.renderFrame).removeMesh(mesh);
}
});
} else {
const wireframeMesh = gizmoVFXItem.wireframeMesh;

if (wireframeMesh && !wireframeMesh.isDestroyed) {
destroyWireframeMesh(wireframeMesh);
this.getEditorRenderPass(composition.renderFrame).removeMesh(wireframeMesh);
}
}

const arr: GizmoVFXItem[] = composition.loaderData.gizmoItems;
Expand Down
10 changes: 8 additions & 2 deletions plugin-packages/editor-gizmo/src/gizmo-vfx-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class GizmoVFXItem extends VFXItem<Mesh | undefined> {
hitBounding?: { key: string, position: Vector3 };
mat = Matrix4.fromIdentity();
wireframeMesh?: Mesh;
wireframeMeshes: Mesh[] = [];
spriteMesh?: SpriteMesh;

private engine: Engine;
Expand Down Expand Up @@ -197,9 +198,12 @@ export class GizmoVFXItem extends VFXItem<Mesh | undefined> {

if (ms) {
this.targetItem = item;
this.wireframeMeshes = [];
ms.forEach(m => {
const mesh = this.wireframeMesh = createModeWireframe(engine, m, this.color);

this.wireframeMeshes.push(mesh);

meshesToAdd.push(mesh);
});
}
Expand Down Expand Up @@ -326,10 +330,12 @@ export class GizmoVFXItem extends VFXItem<Mesh | undefined> {
} else if (this.subType === GizmoSubType.modelWireframe) { // 模型线框
if (this.wireframeMesh && this.targetItem) {
const meshes = this.targetItem.content.mriMeshs as Mesh[];
const wireframeMesh = this.wireframeMesh;
const wireframeMeshes = this.wireframeMeshes;

if (meshes?.length > 0) {
meshes.forEach(mesh => updateWireframeMesh(mesh, wireframeMesh, WireframeGeometryType.triangle));
for (let i = 0;i < meshes.length;i++) {
updateWireframeMesh(meshes[i], wireframeMeshes[i], WireframeGeometryType.triangle);
}
}
}
} else { // 几何体模型
Expand Down
9 changes: 7 additions & 2 deletions plugin-packages/editor-gizmo/src/wireframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export enum WireframeGeometryType {
}

export function destroyWireframeMesh (mesh: Mesh) {
//mesh.geometry?.destroy();
mesh.geometry?.dispose();
mesh.dispose({ material: { textures: DestroyOptions.keep }, geometries: DestroyOptions.keep });
}

Expand Down Expand Up @@ -244,8 +244,13 @@ export class SharedGeometry extends GLGeometry {
super.flush();
}

destroy () {
override dispose () {
// from source geometry
this.buffers = {};
this.bufferProps = {};
super.dispose();
// @ts-expect-error
this.source = null;
}
}

Expand Down

0 comments on commit d3b75b4

Please sign in to comment.