Hi,
I wrote this data binding library for object3D for a small project.
It adds these functions to object3D (exaplained on github repo):
- bindProperty(property: string, getCallback: () => any, bindAfterParentAdded?: boolean): this;
- bindCallback(key: string, callback: () => void, bindAfterParentAdded?: boolean): this;
- unbindByKey(key: string): this;
- detectChanges(): void;
Example:
const materialRed = new MeshBasicMaterial({ color: 0xff0000 }));
const materialYellow = new MeshBasicMaterial({ color: 0xffff00 }));
const mesh = new Mesh(new BufferGeometry());
mesh.bindProperty("material", () => mesh.isActive ? materialYellow : materialRed);
mesh.isActive = true; // this will change material after computeAutoBinding call
mesh.bindCallback("rotation", () => this.rotation.x += 0.1)); // triggered after every computeAutoBinding call
mesh.unbindByKey("material").unbindByKey("position");