object transform in editor
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import * as THREE from 'three';
|
||||
import { MobxReconcilerMap, type ReconcilerMap } from '../utils/reconciler';
|
||||
import type { ObjectTypeGeometryViewItem } from '../state/viewLayers';
|
||||
import type { ObjectGeometryViewItem, ObjectTypeGeometryViewItem } from '../state/viewLayers';
|
||||
|
||||
export class ObjectGeometryList {
|
||||
private items: ReconcilerMap<ObjectTypeGeometryViewItem>;
|
||||
|
||||
private readonly instancesByMesh = new Map<THREE.InstancedMesh, ObjectGeometryViewItem[]>();
|
||||
|
||||
private readonly matrixObj = new THREE.Object3D();
|
||||
private readonly _p = new THREE.Vector3();
|
||||
private readonly _e = new THREE.Euler();
|
||||
private readonly _q = new THREE.Quaternion();
|
||||
|
||||
private readonly _meshToObjectIds = new Map<THREE.InstancedMesh, string[]>();
|
||||
|
||||
constructor(scene: THREE.Scene, typeGeometries: Iterable<ObjectTypeGeometryViewItem>) {
|
||||
this.items = new MobxReconcilerMap<ObjectTypeGeometryViewItem>({
|
||||
reaction: () => typeGeometries,
|
||||
@@ -31,17 +31,16 @@ export class ObjectGeometryList {
|
||||
this.items?.dispose();
|
||||
}
|
||||
|
||||
getObjectIdByMesh(mesh: THREE.InstancedMesh, instanceId: number): string | undefined {
|
||||
return this._meshToObjectIds.get(mesh)?.[instanceId];
|
||||
getObjectGeometryByMesh(mesh: THREE.InstancedMesh, instanceId: number): ObjectGeometryViewItem | undefined {
|
||||
return this.instancesByMesh.get(mesh)?.[instanceId];
|
||||
}
|
||||
|
||||
tick(): void {
|
||||
this._meshToObjectIds.clear();
|
||||
this.instancesByMesh.clear();
|
||||
|
||||
this.items.values.forEach((typeGeometry) => {
|
||||
const instances = typeGeometry.instances;
|
||||
const meshes = typeGeometry.meshes ?? [];
|
||||
const objectIds: string[] = [];
|
||||
|
||||
instances.forEach((item, instanceIdx) => {
|
||||
const obj = item.object;
|
||||
@@ -54,14 +53,12 @@ export class ObjectGeometryList {
|
||||
this.matrixObj.scale.set(...obj.scale);
|
||||
this.matrixObj.updateMatrix();
|
||||
|
||||
objectIds[instanceIdx] = obj.id;
|
||||
|
||||
for (const mesh of meshes)
|
||||
mesh.setMatrixAt(instanceIdx, this.matrixObj.matrix);
|
||||
});
|
||||
|
||||
for (const mesh of meshes) {
|
||||
this._meshToObjectIds.set(mesh, objectIds);
|
||||
this.instancesByMesh.set(mesh, typeGeometry.instances);
|
||||
mesh.count = instances.length;
|
||||
mesh.instanceMatrix.needsUpdate = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user