From fd39c54bb32e8c6b3cc260ea5d696b99cb016427 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Sun, 4 Oct 2020 11:13:38 +0200 Subject: [PATCH] Improve performance --- js/animations/animation.js | 2 +- js/io/formats/obj.js | 2 +- js/io/project.js | 3 +++ js/outliner/group.js | 1 + js/outliner/outliner.js | 3 +++ js/preview/canvas.js | 2 +- js/preview/preview.js | 2 +- js/texturing/textures.js | 4 ++-- js/texturing/uv.js | 4 ++-- js/undo.js | 8 ++++---- 10 files changed, 19 insertions(+), 12 deletions(-) diff --git a/js/animations/animation.js b/js/animations/animation.js index 2e55a47..69e0498 100644 --- a/js/animations/animation.js +++ b/js/animations/animation.js @@ -714,7 +714,7 @@ class BoneAnimator extends GeneralAnimator { return [...this.rotation, ...this.position, ...this.scale]; } getGroup() { - this.group = Group.all.findInArray('uuid', this.uuid) + this.group = OutlinerElement.uuids[this.uuid] if (!this.group) { if (this.animation && this.animation.animators[this.uuid] && this.animation.animators[this.uuid].type == 'bone') { delete this.animation.bones[this.uuid]; diff --git a/js/io/formats/obj.js b/js/io/formats/obj.js index 2aea24f..bba7eac 100644 --- a/js/io/formats/obj.js +++ b/js/io/formats/obj.js @@ -41,7 +41,7 @@ var codec = new Codec('obj', { var nbNormals = 0; var geometry = mesh.geometry; - var element = elements.findInArray('uuid', mesh.name) + var element = OutlinerElement.uuids[mesh.name]; if (!element) return; if (element.export === false) return; diff --git a/js/io/project.js b/js/io/project.js index 59858d9..478777f 100644 --- a/js/io/project.js +++ b/js/io/project.js @@ -43,6 +43,9 @@ class ModelProject { Screencam.stopTimelapse(); Format = 0; + for (var uuid in OutlinerElement.uuids) { + delete OutlinerElement.uuids[uuid]; + } Outliner.elements.empty(); Outliner.root.purge(); Canvas.materials; diff --git a/js/outliner/group.js b/js/outliner/group.js index cbb7778..68fd3f8 100644 --- a/js/outliner/group.js +++ b/js/outliner/group.js @@ -211,6 +211,7 @@ class Group extends OutlinerElement { }) TickUpdates.selection = true this.constructor.all.remove(this); + delete OutlinerElement.uuids[this.uuid]; if (undo) { cubes.length = 0 Undo.finishEdit('removed_group') diff --git a/js/outliner/outliner.js b/js/outliner/outliner.js index 308deff..1e9760b 100644 --- a/js/outliner/outliner.js +++ b/js/outliner/outliner.js @@ -84,6 +84,7 @@ var markerColors = [ class OutlinerElement { constructor(uuid) { this.uuid = uuid || guid() + OutlinerElement.uuids[this.uuid] = this; this.export = true; this.locked = false; } @@ -211,6 +212,7 @@ class OutlinerElement { } remove() { this.constructor.all.remove(this); + delete OutlinerElement.uuids[this.uuid]; this.removeFromParent() } rename() { @@ -336,6 +338,7 @@ class OutlinerElement { this.shade = !val; } } +OutlinerElement.uuids = {}; class NonGroup extends OutlinerElement { constructor(data, uuid) { super(uuid); diff --git a/js/preview/canvas.js b/js/preview/canvas.js index d073d4a..7dbfa36 100644 --- a/js/preview/canvas.js +++ b/js/preview/canvas.js @@ -266,7 +266,7 @@ const Canvas = { Canvas.adaptObjectPosition(obj) }) if (leave_selection !== true) { - updateSelection() + TickUpdates.selection = true; } }, updateSelectedFaces() { diff --git a/js/preview/preview.js b/js/preview/preview.js index d32da69..ca45ec3 100644 --- a/js/preview/preview.js +++ b/js/preview/preview.js @@ -320,7 +320,7 @@ class Preview { } if (intersect.isElement) { this.controls.hasMoved = true - var obj = elements.findInArray('uuid', intersects[0].object.name) + var obj = OutlinerElement.uuids[intersects[0].object.name] let face = Canvas.face_order[intersects[0].face.materialIndex]; return { diff --git a/js/texturing/textures.js b/js/texturing/textures.js index 03d756d..435e043 100644 --- a/js/texturing/textures.js +++ b/js/texturing/textures.js @@ -484,7 +484,7 @@ class Texture { } //Management select(event) { - textures.forEach(s => { + Texture.all.forEach(s => { if (s.selected) s.selected = false; }) if (event) { @@ -495,7 +495,7 @@ class Texture { this.scrollTo(); if (Project.layered_textures) { Canvas.updatePaintingGrid() - } else if (Format.single_texture) { + } else if (Format.single_texture && Texture.all.length > 1) { Canvas.updateAllFaces() TickUpdates.selection = true; } diff --git a/js/texturing/uv.js b/js/texturing/uv.js index efd49bc..b8a945c 100644 --- a/js/texturing/uv.js +++ b/js/texturing/uv.js @@ -918,10 +918,10 @@ class UVEditor { } } if (!tex || typeof tex !== 'object') { - if (!Format.single_texture) { + if (!Format.single_texture && Texture.selected) { unselectTextures() } - } else { + } else if (Texture.selected != tex) { tex.select() } this.setSize(this.size, true) diff --git a/js/undo.js b/js/undo.js index cd8f096..8164bd4 100644 --- a/js/undo.js +++ b/js/undo.js @@ -227,7 +227,7 @@ var Undo = { if (save.elements.hasOwnProperty(uuid)) { var element = save.elements[uuid] - var new_element = elements.findInArray('uuid', uuid) + var new_element = OutlinerElement.uuids[uuid] if (new_element) { for (var face in new_element.faces) { new_element.faces[face].reset() @@ -246,7 +246,7 @@ var Undo = { } for (var uuid in reference.elements) { if (reference.elements.hasOwnProperty(uuid) && !save.elements.hasOwnProperty(uuid)) { - var obj = elements.findInArray('uuid', uuid) + var obj = OutlinerElement.uuids[uuid] if (obj) { obj.remove() } @@ -277,7 +277,7 @@ var Undo = { if (save.selection_group && !is_session) { Group.selected = undefined - var sel_group = Group.all.findInArray('uuid', save.selection_group) + var sel_group = OutlinerElement.uuids[save.selection_group] if (sel_group) { sel_group.select() } @@ -293,7 +293,7 @@ var Undo = { } if (save.group) { - var group = Group.all.findInArray('uuid', save.group.uuid) + var group = OutlinerElement.uuids[save.group.uuid] if (group) { if (is_session) { delete save.group.isOpen;