Skip to content

Commit 81357fb

Browse files
committed
Add option: Track all changes.
1 parent 61008a6 commit 81357fb

17 files changed

+169
-90
lines changed

source/.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Metrics/AbcSize:
1818
Enabled: false
1919

2020
Metrics/MethodLength:
21-
Max: 20
21+
Max: 25
2222

2323
Metrics/ClassLength:
2424
Max: 200

source/pbr.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# PBR plugin namespace.
2727
module PBR
2828

29-
VERSION = '1.5.5'.freeze
29+
VERSION = '1.5.6'.freeze
3030

3131
# Load translation if it's available for current locale.
3232
TRANSLATE = LanguageHandler.new('pbr.strings')

source/pbr/Resources/fr/pbr.strings

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"HDR Image"="Image HDR";
3535
"Edit Materials..."="Modifier les matériaux...";
3636
"Add an Artificial Light"="Ajouter une lumière artificielle";
37-
"Reopen Viewport"="Rouvrir la fenêtre de visualisation";
37+
"Render scene in Viewport"="Rendre la scène dans la fenêtre de visu.";
38+
"Track all Changes"="Suivre tous les changements";
3839
"Export As 3D Object..."="Exporter en tant qu'objet 3D...";
3940
"Export As glTF"="Exporter en tant que fichier glTF";
4041
"Model well exported here:"="Modèle bien exporté ici :";
@@ -52,7 +53,7 @@
5253
"PBR"="RBP";
5354
"Define if a material is rough, is a metal, etc."="Définissez si un matériau est rugueux, est un métal, etc.";
5455
"Move it in space. Change its color."="Déplacez-la dans l'espace. Changez sa couleur.";
55-
"Render scene in real-time."="Rendez la scène en temps réel.";
56+
"This will reopen Viewport."="Ceci réouvrira la fenêtre de visualisation.";
5657
"Save 3D model as .gltf."="Enregistrez le modèle 3D en tant que .gltf.";
5758

5859
//
@@ -117,6 +118,7 @@
117118
//
118119

119120
"Untitled"="Sans titre";
121+
"Export geometry and textures to glTF format"="Export de la géométrie et des textures au format glTF";
120122
"PBR: Exporting geometry and textures... Please wait."="RBP : Export de la géométrie et des textures en cours... Veuillez patienter.";
121123

122124
//

source/pbr/Viewport App/assets/sketchup-locale.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

source/pbr/Viewport App/assets/sketchup-model.gltf

Lines changed: 0 additions & 1 deletion
This file was deleted.

source/pbr/Viewport App/viewport.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ PBR.Viewport.naturalLights = {};
100100
*/
101101
PBR.Viewport.artificialLights = [];
102102

103+
/**
104+
* Viewport glTF model version.
105+
*
106+
* @type {number}
107+
*/
108+
PBR.Viewport.modelVersion = 0;
109+
103110
/**
104111
* Helper function to convert HTML colors.
105112
*
@@ -375,9 +382,66 @@ PBR.Viewport.listenToCameraReset = function() {
375382

376383
};
377384

385+
/**
386+
* Set model version from URL parameter?
387+
*/
388+
PBR.Viewport.setModelVersion = function() {
389+
390+
PBR.Viewport.modelVersion = parseInt(document.location.search.replace(/\D/g, ''));
391+
392+
if ( isNaN(PBR.Viewport.modelVersion) ) {
393+
394+
PBR.Viewport.modelVersion = parseInt(Date.now() / 1000);
395+
396+
}
397+
398+
};
399+
400+
/**
401+
* Refresh Viewport if a newer version of model is available.
402+
*/
403+
PBR.Viewport.checkForModelUpdates = function() {
404+
405+
var request = new XMLHttpRequest();
406+
407+
var lastModelVersion = 0;
408+
409+
request.addEventListener('load', function(event) {
410+
411+
lastModelVersion = parseInt(event.target.response);
412+
413+
if ( PBR.Viewport.modelVersion < lastModelVersion ) {
414+
415+
// Refresh Viewport.
416+
document.location.search = 'model_ver=' + lastModelVersion;
417+
418+
}
419+
420+
});
421+
422+
request.open('GET', 'assets/sketchup-model.ver');
423+
424+
request.send();
425+
426+
};
427+
428+
/**
429+
* Set Viewport "Check Model Updates" interval.
430+
*/
431+
PBR.Viewport.setCmuInterval = function() {
432+
433+
window.setInterval(
434+
PBR.Viewport.checkForModelUpdates,
435+
1000
436+
);
437+
438+
};
439+
378440
// When document is ready:
379441
document.addEventListener('DOMContentLoaded', function() {
380442

443+
PBR.Viewport.setModelVersion();
444+
381445
PBR.Viewport.translateStrings();
382446

383447
PBR.Viewport.listenToSunlightChange();
@@ -386,6 +450,8 @@ document.addEventListener('DOMContentLoaded', function() {
386450

387451
PBR.Viewport.listenToCameraReset();
388452

453+
PBR.Viewport.setCmuInterval();
454+
389455
});
390456

391457
// When window is resized:

source/pbr/app_observer.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
require 'sketchup'
2424
require 'pbr/viewport'
25+
require 'pbr/model_observer'
2526

2627
# PBR plugin namespace.
2728
module PBR
@@ -32,16 +33,24 @@ class AppObserver < Sketchup::AppObserver
3233
# rubocop: disable Naming/MethodName
3334

3435
# When SketchUp user creates a new, empty model.
35-
def onNewModel(_model)
36+
def onNewModel(model)
3637

37-
Viewport.reopen if Viewport.update_model
38+
Viewport.close
39+
40+
SESSION[:track_all_changes?] = false
41+
42+
model.add_observer(ModelObserver.new)
3843

3944
end
4045

4146
# When SketchUp user opens an existing model:
42-
def onOpenModel(_model)
47+
def onOpenModel(model)
48+
49+
Viewport.close
50+
51+
SESSION[:track_all_changes?] = false
4352

44-
Viewport.reopen if Viewport.update_model
53+
model.add_observer(ModelObserver.new)
4554

4655
end
4756

source/pbr/entity_observer.rb

Lines changed: 0 additions & 52 deletions
This file was deleted.

source/pbr/gltf.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ def initialize
9393

9494
begin
9595

96+
SESSION[:export_in_progress?] = true
97+
98+
Sketchup.active_model.start_operation(
99+
TRANSLATE['Export geometry and textures to glTF format'],
100+
true # disable_ui
101+
)
102+
96103
Sketchup.status_text = TRANSLATE[
97104
'PBR: Exporting geometry and textures... Please wait.'
98105
]
@@ -101,12 +108,20 @@ def initialize
101108

102109
complete
103110

111+
Sketchup.active_model.commit_operation
112+
113+
SESSION[:export_in_progress?] = false
114+
104115
Sketchup.status_text = nil
105116

106117
rescue StandardError => _exception
107118

108119
@valid = false
109120

121+
Sketchup.active_model.abort_operation
122+
123+
SESSION[:export_in_progress?] = false
124+
110125
Sketchup.status_text = nil
111126

112127
end

source/pbr/light.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
require 'sketchup'
2424
require 'pbr/shapes'
25-
require 'pbr/entity_observer'
2625

2726
# PBR plugin namespace.
2827
module PBR
@@ -42,10 +41,6 @@ def initialize
4241

4342
@light.name = 'PBR Light'
4443

45-
SESSION[:lights_objects_ids].push(@light.object_id.to_i)
46-
47-
@light.add_observer(EntityObserver.new)
48-
4944
end
5045

5146
end

source/pbr/load.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,27 @@ module PBR
3737
Sketchup.active_model.add_observer(ModelObserver.new)
3838

3939
# Material Editor is not open yet.
40-
SESSION[:mat_editor_open?] = false
40+
SESSION[:material_editor_open?] = false
4141

4242
# Storage for Chromium process ID.
43-
SESSION[:viewport_pid] = 0
43+
SESSION[:viewport_process_id] = 0
4444

45-
# Memory of artificial lights IDs.
46-
SESSION[:lights_objects_ids] = []
45+
# Changes are not tracked by default.
46+
SESSION[:track_all_changes?] = false
4747

48-
# Plug PBR menu into SketchUp UI.
48+
# Indicates if exporting to glTF...
49+
SESSION[:export_in_progress?] = false
50+
51+
# Memory of last Viewport update.
52+
SESSION[:last_viewport_update] = 0
53+
54+
# Plugs PBR menu into SketchUp UI.
4955
Menu.new(
5056
UI.menu('Plugins') # parent_menu
5157
)
5258

5359
Toolbar.new.prepare.show
5460

55-
Viewport.open if Viewport.translate
56-
5761
# Load complete.
5862

5963
end

source/pbr/material_editor.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def self.safe_to_open?
4040
return false
4141
end
4242

43-
if SESSION[:mat_editor_open?]
43+
if SESSION[:material_editor_open?]
4444
UI.messagebox(TRANSLATE['PBR Material Editor is already open.'])
4545
return false
4646
end
@@ -83,7 +83,7 @@ def show
8383
@dialog.show
8484

8585
# Material Editor is open.
86-
SESSION[:mat_editor_open?] = true
86+
SESSION[:material_editor_open?] = true
8787

8888
end
8989

@@ -160,11 +160,11 @@ def show
160160

161161
@dialog.close
162162

163-
Viewport.update_model_and_reopen
163+
Viewport.update_model
164164

165165
end
166166

167-
@dialog.set_on_closed { SESSION[:mat_editor_open?] = false }
167+
@dialog.set_on_closed { SESSION[:material_editor_open?] = false }
168168

169169
@dialog.center
170170

0 commit comments

Comments
 (0)