Skip to content

Commit

Permalink
Add option: Track all changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelTallet committed Nov 28, 2019
1 parent 61008a6 commit 81357fb
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 90 deletions.
2 changes: 1 addition & 1 deletion source/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Metrics/AbcSize:
Enabled: false

Metrics/MethodLength:
Max: 20
Max: 25

Metrics/ClassLength:
Max: 200
2 changes: 1 addition & 1 deletion source/pbr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# PBR plugin namespace.
module PBR

VERSION = '1.5.5'.freeze
VERSION = '1.5.6'.freeze

# Load translation if it's available for current locale.
TRANSLATE = LanguageHandler.new('pbr.strings')
Expand Down
6 changes: 4 additions & 2 deletions source/pbr/Resources/fr/pbr.strings
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"HDR Image"="Image HDR";
"Edit Materials..."="Modifier les matériaux...";
"Add an Artificial Light"="Ajouter une lumière artificielle";
"Reopen Viewport"="Rouvrir la fenêtre de visualisation";
"Render scene in Viewport"="Rendre la scène dans la fenêtre de visu.";
"Track all Changes"="Suivre tous les changements";
"Export As 3D Object..."="Exporter en tant qu'objet 3D...";
"Export As glTF"="Exporter en tant que fichier glTF";
"Model well exported here:"="Modèle bien exporté ici :";
Expand All @@ -52,7 +53,7 @@
"PBR"="RBP";
"Define if a material is rough, is a metal, etc."="Définissez si un matériau est rugueux, est un métal, etc.";
"Move it in space. Change its color."="Déplacez-la dans l'espace. Changez sa couleur.";
"Render scene in real-time."="Rendez la scène en temps réel.";
"This will reopen Viewport."="Ceci réouvrira la fenêtre de visualisation.";
"Save 3D model as .gltf."="Enregistrez le modèle 3D en tant que .gltf.";

//
Expand Down Expand Up @@ -117,6 +118,7 @@
//

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

//
Expand Down
1 change: 0 additions & 1 deletion source/pbr/Viewport App/assets/sketchup-locale.json

This file was deleted.

1 change: 0 additions & 1 deletion source/pbr/Viewport App/assets/sketchup-model.gltf

This file was deleted.

66 changes: 66 additions & 0 deletions source/pbr/Viewport App/viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ PBR.Viewport.naturalLights = {};
*/
PBR.Viewport.artificialLights = [];

/**
* Viewport glTF model version.
*
* @type {number}
*/
PBR.Viewport.modelVersion = 0;

/**
* Helper function to convert HTML colors.
*
Expand Down Expand Up @@ -375,9 +382,66 @@ PBR.Viewport.listenToCameraReset = function() {

};

/**
* Set model version from URL parameter?
*/
PBR.Viewport.setModelVersion = function() {

PBR.Viewport.modelVersion = parseInt(document.location.search.replace(/\D/g, ''));

if ( isNaN(PBR.Viewport.modelVersion) ) {

PBR.Viewport.modelVersion = parseInt(Date.now() / 1000);

}

};

/**
* Refresh Viewport if a newer version of model is available.
*/
PBR.Viewport.checkForModelUpdates = function() {

var request = new XMLHttpRequest();

var lastModelVersion = 0;

request.addEventListener('load', function(event) {

lastModelVersion = parseInt(event.target.response);

if ( PBR.Viewport.modelVersion < lastModelVersion ) {

// Refresh Viewport.
document.location.search = 'model_ver=' + lastModelVersion;

}

});

request.open('GET', 'assets/sketchup-model.ver');

request.send();

};

/**
* Set Viewport "Check Model Updates" interval.
*/
PBR.Viewport.setCmuInterval = function() {

window.setInterval(
PBR.Viewport.checkForModelUpdates,
1000
);

};

// When document is ready:
document.addEventListener('DOMContentLoaded', function() {

PBR.Viewport.setModelVersion();

PBR.Viewport.translateStrings();

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

PBR.Viewport.listenToCameraReset();

PBR.Viewport.setCmuInterval();

});

// When window is resized:
Expand Down
17 changes: 13 additions & 4 deletions source/pbr/app_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

require 'sketchup'
require 'pbr/viewport'
require 'pbr/model_observer'

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

# When SketchUp user creates a new, empty model.
def onNewModel(_model)
def onNewModel(model)

Viewport.reopen if Viewport.update_model
Viewport.close

SESSION[:track_all_changes?] = false

model.add_observer(ModelObserver.new)

end

# When SketchUp user opens an existing model:
def onOpenModel(_model)
def onOpenModel(model)

Viewport.close

SESSION[:track_all_changes?] = false

Viewport.reopen if Viewport.update_model
model.add_observer(ModelObserver.new)

end

Expand Down
52 changes: 0 additions & 52 deletions source/pbr/entity_observer.rb

This file was deleted.

15 changes: 15 additions & 0 deletions source/pbr/gltf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ def initialize

begin

SESSION[:export_in_progress?] = true

Sketchup.active_model.start_operation(
TRANSLATE['Export geometry and textures to glTF format'],
true # disable_ui
)

Sketchup.status_text = TRANSLATE[
'PBR: Exporting geometry and textures... Please wait.'
]
Expand All @@ -101,12 +108,20 @@ def initialize

complete

Sketchup.active_model.commit_operation

SESSION[:export_in_progress?] = false

Sketchup.status_text = nil

rescue StandardError => _exception

@valid = false

Sketchup.active_model.abort_operation

SESSION[:export_in_progress?] = false

Sketchup.status_text = nil

end
Expand Down
5 changes: 0 additions & 5 deletions source/pbr/light.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

require 'sketchup'
require 'pbr/shapes'
require 'pbr/entity_observer'

# PBR plugin namespace.
module PBR
Expand All @@ -42,10 +41,6 @@ def initialize

@light.name = 'PBR Light'

SESSION[:lights_objects_ids].push(@light.object_id.to_i)

@light.add_observer(EntityObserver.new)

end

end
Expand Down
18 changes: 11 additions & 7 deletions source/pbr/load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,27 @@ module PBR
Sketchup.active_model.add_observer(ModelObserver.new)

# Material Editor is not open yet.
SESSION[:mat_editor_open?] = false
SESSION[:material_editor_open?] = false

# Storage for Chromium process ID.
SESSION[:viewport_pid] = 0
SESSION[:viewport_process_id] = 0

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

# Plug PBR menu into SketchUp UI.
# Indicates if exporting to glTF...
SESSION[:export_in_progress?] = false

# Memory of last Viewport update.
SESSION[:last_viewport_update] = 0

# Plugs PBR menu into SketchUp UI.
Menu.new(
UI.menu('Plugins') # parent_menu
)

Toolbar.new.prepare.show

Viewport.open if Viewport.translate

# Load complete.

end
8 changes: 4 additions & 4 deletions source/pbr/material_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def self.safe_to_open?
return false
end

if SESSION[:mat_editor_open?]
if SESSION[:material_editor_open?]
UI.messagebox(TRANSLATE['PBR Material Editor is already open.'])
return false
end
Expand Down Expand Up @@ -83,7 +83,7 @@ def show
@dialog.show

# Material Editor is open.
SESSION[:mat_editor_open?] = true
SESSION[:material_editor_open?] = true

end

Expand Down Expand Up @@ -160,11 +160,11 @@ def show

@dialog.close

Viewport.update_model_and_reopen
Viewport.update_model

end

@dialog.set_on_closed { SESSION[:mat_editor_open?] = false }
@dialog.set_on_closed { SESSION[:material_editor_open?] = false }

@dialog.center

Expand Down
Loading

0 comments on commit 81357fb

Please sign in to comment.