From 1498b37f671aa5f44ff9b9f5bade79d304737302 Mon Sep 17 00:00:00 2001 From: Daan Vanden Bosch Date: Sat, 28 Sep 2019 21:31:04 +0200 Subject: [PATCH] Reduced GC pressure while rotating entities. --- src/quest_editor/model/QuestEntityModel.ts | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/quest_editor/model/QuestEntityModel.ts b/src/quest_editor/model/QuestEntityModel.ts index 7f71fe96..a55d7175 100644 --- a/src/quest_editor/model/QuestEntityModel.ts +++ b/src/quest_editor/model/QuestEntityModel.ts @@ -5,6 +5,9 @@ import { WritableProperty } from "../../core/observable/property/WritablePropert import { SectionModel } from "./SectionModel"; import { Euler, Quaternion, Vector3 } from "three"; +const q1 = new Quaternion(); +const q2 = new Quaternion(); + export abstract class QuestEntityModel { readonly type: Type; @@ -122,15 +125,13 @@ export abstract class QuestEntityModel { const section = this.section.val; if (section) { - this._world_rotation.val = new Euler().setFromQuaternion( - new Quaternion() - .setFromEuler(section.rotation) - .multiply(new Quaternion().setFromEuler(rot)), - "ZXY", - ); + q1.setFromEuler(rot); + q2.setFromEuler(section.rotation); + this._world_rotation.val = new Euler().setFromQuaternion(q1.multiply(q2), "ZXY"); } else { this._world_rotation.val = rot; } + return this; } @@ -140,12 +141,10 @@ export abstract class QuestEntityModel { const section = this.section.val; if (section) { - this._rotation.val = new Euler().setFromQuaternion( - new Quaternion() - .setFromEuler(rot) - .multiply(new Quaternion().setFromEuler(section.rotation).inverse()), - "ZXY", - ); + q1.setFromEuler(rot); + q2.setFromEuler(section.rotation); + q2.inverse(); + this._rotation.val = new Euler().setFromQuaternion(q1.multiply(q2), "ZXY"); } else { this._rotation.val = rot; }