Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gizmo rendering problem #58

Merged
merged 5 commits into from
Dec 20, 2023
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
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
Loading