Skip to content

Commit

Permalink
FaceFilter: load LOD 0
Browse files Browse the repository at this point in the history
  • Loading branch information
marwie committed Sep 23, 2024
1 parent d1b4f63 commit dbbec3f
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions package/Runtime/Facefilter/FaceFilter~/src/Behaviours.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Animator, Behaviour, isDevEnvironment, serializable } from '@needle-tools/engine';
import { Animator, Behaviour, isDevEnvironment, NEEDLE_progressive, serializable } from '@needle-tools/engine';
import type { NeedleFilterTrackingManager } from './FaceFilter.js';
import { Matrix4, Mesh, Object3D, SkinnedMesh, Vector3 } from 'three';
import { BufferAttribute, Matrix4, Mesh, Object3D, SkinnedMesh, Vector3 } from 'three';
import { BlendshapeName, FacefilterUtils } from './utils.js';

declare type AvatarType = "Unknown" | "ReadyPlayerMe";
Expand All @@ -24,6 +24,7 @@ export class FaceFilterRoot extends Behaviour {
this._initialScale ??= this.gameObject?.scale.clone();
this._headMatrix = null;
this.setupHead();
this.loadProgressive();
}

private setupHead() {
Expand Down Expand Up @@ -142,6 +143,20 @@ export class FaceFilterRoot extends Behaviour {
}


private loadProgressive() {
this.gameObject.traverse(t => {
if (t instanceof Mesh) {
const vertices = t.geometry.getAttribute("position") as BufferAttribute;
if (!vertices?.array || vertices.array.length < 100_000) {
NEEDLE_progressive.assignMeshLOD(t, 0);
NEEDLE_progressive.assignTextureLOD(t, 0);
}
else {
console.debug(`Will not automatically load progressive mesh for ${t.name} because it has too many vertices (${vertices.array?.length})`);
}
}
})
}

private _filter: NeedleFilterTrackingManager | null = null;
private _behaviours: FilterBehaviour[] = [];
Expand Down

0 comments on commit dbbec3f

Please sign in to comment.