I’m working on something like a threejs editor, and when I add objects (no matter how simple the objects are), when I drag the transformControls, the 60fps drops to 44fps, but if I don’t add any operations, there won’t be much fluctuation when operating the objects in the original scene. I don’t quite understand why
Here is the code:
transformControls.addEventListener('objectChange', () => {
this.signals.objectChanged.emit('', transformControls.object);
});
transformControls.addEventListener('mouseDown', () => {
const object = transformControls.object;
objectPositionOnDown = object.position.clone();
objectRotationOnDown = object.rotation.clone();
objectScaleOnDown = object.scale.clone();
this.controls.enabled = false;
});
// 当鼠标抬起去发送请求
transformControls.addEventListener('mouseUp', () => {
const {conf} = storeToRefs(useBusinessData());
const object = transformControls.object;
const keys = object.allPathKey.split('.');
const lastKey = keys.pop();
const lastObj = keys.reduce((acc: any, key: any) => acc?.[key], conf.value);
if (object !== undefined) {
switch (transformControls.getMode()) {
case 'translate':
if (!objectPositionOnDown.equals(object.position)) {
this.editor.execute(new SetPositionCommand(this.editor, object, object.position, objectPositionOnDown));
if (lastObj && lastKey) {
// 需要修改的响应值
const reflectObj = lastObj[lastKey];
this.editor.wsSend(
'change',
[{
value: {
...reflectObj,
},
key: object.allPathKey,
}]
);
}
}
break;
case 'rotate':
if (!objectRotationOnDown.equals(object.rotation)) {
this.editor.execute(new SetRotationCommand(this.editor, object, object.rotation, objectPositionOnDown));
if (lastObj && lastKey) {
const reflectObj = lastObj[lastKey];
this.editor.wsSend(
'change',
[{
value: {
...reflectObj,
},
key: object.allPathKey,
}]
);
}
}
break;
case 'scale':
if (!objectScaleOnDown.equals(object.scale)) {
this.editor.execute(new SetScaleCommand(this.editor, object, object.scale, objectPositionOnDown));
if (lastObj && lastKey) {
const reflectObj = lastObj[lastKey];
this.editor.wsSend(
'change',
[{
value: {
...reflectObj,
},
key: object.allPathKey,
}]
);
}
}
break;
}
// 恢复相机控制移动
this.controls.enabled = true;
}
});
And I did a performance analysis ,here are the pictures
It confuses me.