virtual-cast / babylon-vrm-loader

glTF VRM extension Loader for babylon.js
https://virtual-cast.github.io/babylon-vrm-loader/
MIT License
124 stars 23 forks source link

define VRMFinder in scene #75

Open yamayuski opened 2 years ago

yamayuski commented 2 years ago
/**
 * @link https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Rendering/outlineRenderer.ts
 */

declare module "@babylonjs/core/scene" {
    export interface Scene {
        _vrmFinder: VRMFinder;
        getVRMFinder(): VRMFinder;
    }
}

Scene.prototype.getVRMFinder = function (): VRMFinder {
    if (!this._vrmFinder) {
        this._vrmFinder = new VRMFinder(this);
    }
    return this._vrmFinder;
};

export class VRMFinder implements ISceneComponent {
    public name = 'VRMFinder';

    public constructor(public readonly scene: Scene) {
        this.scene._addComponent(this);
    }

    public getByTitle(title: string): Nullable<VRMManager> {
        // ...
    }

    public getAll(): VRMManager[] {
        // ...
    }

    // ...
}

恐らくこんな感じのインターフェースを想定。

// use case
const vrm = this.scene.getByTitle('Alicia Solid') ?? throw new Error(`VRM not found`);
vrm.morphing('a', 1.0);
yamayuski commented 2 years ago