Skip to content

Commit 0cf0473

Browse files
committed
Export sun intensity.
1 parent a208870 commit 0cf0473

File tree

5 files changed

+48
-24
lines changed

5 files changed

+48
-24
lines changed

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.7'.freeze
29+
VERSION = '1.5.8'.freeze
3030

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

source/pbr/Viewport App/viewport.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<script src="lib/claygl.modded.js"></script>
1414
<script src="lib/claygl-advanced-renderer.min.js"></script>
1515

16-
<script src="assets/sketchup-sun-dir.json"></script>
16+
<script src="assets/sketchup-sunlight.json"></script>
1717
<script src="assets/sketchup-locale.json"></script>
1818

1919
<link rel="stylesheet" href="viewport.css"></link>

source/pbr/Viewport App/viewport.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ localforage.getItem('cameraPosition').then(function(cameraPosition) {
157157

158158
// Instantiate an adv. renderer.
159159
this._advancedRenderer = new ClayAdvancedRenderer(
160-
app.renderer, app.scene, app.timeline, PBR.Viewport.cfg.advancedGraphics
160+
app.renderer, app.scene, app.timeline,
161+
PBR.Viewport.cfg.advancedGraphics
161162
);
162163

163164
// Create a perspective camera.
@@ -191,8 +192,13 @@ localforage.getItem('cameraPosition').then(function(cameraPosition) {
191192

192193
// Create an cubemap ambient light and an spherical harmonic ambient
193194
// light for specular and diffuse lighting in PBR rendering.
194-
return app.createAmbientCubemapLight('assets/equirectangular.hdr', 0.8, 0.8)
195-
.then(function (ambientLight){
195+
return app.createAmbientCubemapLight(
196+
197+
'assets/equirectangular.hdr',
198+
sketchUpSunlight.intensity,
199+
sketchUpSunlight.intensity
200+
201+
).then(function(ambientLight) {
196202

197203
PBR.Viewport.naturalLights.diffuse = ambientLight.diffuse;
198204
PBR.Viewport.naturalLights.specular = ambientLight.specular;
@@ -201,25 +207,31 @@ localforage.getItem('cameraPosition').then(function(cameraPosition) {
201207
PBR.Viewport.naturalLights.direct = app.createDirectionalLight(
202208
[
203209
// XXX XYZ to -X-ZY
204-
sketchUpSunDir.x * -1,
205-
sketchUpSunDir.z * -1,
206-
sketchUpSunDir.y,
210+
sketchUpSunlight.direction.x * -1,
211+
sketchUpSunlight.direction.z * -1,
212+
sketchUpSunlight.direction.y,
207213
],
208-
'#fff',
209-
0.8
214+
'#fff',
215+
sketchUpSunlight.intensity
210216
);
211217

218+
document.querySelector('#sunlightIntensity .slider').value = sketchUpSunlight.intensity;
219+
212220
PBR.Viewport.naturalLights.direct.shadowResolution = 4096;
213221

214222
// Set HDR background image.
215223
new clay.plugin.Skybox({
224+
216225
scene: app.scene,
217226
environmentMap: ambientLight.environmentMap
227+
218228
});
219229

220230
// Load a glTF format model.
221231
app.loadModel('assets/sketchup-model.gltf', {
232+
222233
textureConvertToPOT: true
234+
223235
}).then(function (model) {
224236

225237
if ( model.json.extras && model.json.extras.lights ) {
@@ -262,14 +274,18 @@ localforage.getItem('cameraPosition').then(function(cameraPosition) {
262274
if ( glTFMaterial.extras && glTFMaterial.extras.parallaxOcclusionTextureURI ) {
263275

264276
app.loadTexture(glTFMaterial.extras.parallaxOcclusionTextureURI, {
277+
265278
convertToPOT: true,
266279
anisotropic: 16,
267280
flipY: false
268-
}).then(function (parallaxOcclusionTexture) {
281+
282+
}).then(function(parallaxOcclusionTexture) {
283+
269284
clayMaterial.set('parallaxOcclusionMap', parallaxOcclusionTexture);
270285
clayMaterial.set('parallaxOcclusionScale', 0.05);
271286
clayMaterial.set('parallaxMinLayers', 50);
272287
clayMaterial.set('parallaxMaxLayers', 50);
288+
273289
});
274290

275291
}

source/pbr/sun_observer.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ class SunObserver < Sketchup::ShadowInfoObserver
3434
# When user changes shadow settings:
3535
def onShadowInfoChanged(_shadow_info, type)
3636

37-
# Escape if it's not about "Time/Date sliders".
38-
return unless type.zero?
37+
# Escape if it's not about "Time/Date/Light/Dark sliders".
38+
return unless type == 0 || type == 2
3939

4040
if SESSION[:track_all_changes?]
4141

42-
Viewport.update_sun_direction
42+
Viewport.update_sunlight
4343

4444
Viewport.update_data_version
4545

source/pbr/viewport.rb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,32 @@ def self.update_translation
9696

9797
end
9898

99-
# Updates Viewport sun direction.
99+
# Updates Viewport sunlight.
100100
#
101101
# @return [nil]
102-
def self.update_sun_direction
102+
def self.update_sunlight
103103

104-
sun_vec = Sketchup.active_model.shadow_info['SunDirection']
104+
sun_direction = Sketchup.active_model.shadow_info['SunDirection']
105105

106-
sun_dir = {
106+
sun_intensity = Sketchup.active_model.shadow_info['Light'].to_f / 100
107107

108-
x: sun_vec.x,
109-
y: sun_vec.y,
110-
z: sun_vec.z
108+
sunlight = {
109+
110+
direction: {
111+
112+
x: sun_direction.x,
113+
y: sun_direction.y,
114+
z: sun_direction.z
115+
116+
},
117+
118+
intensity: sun_intensity
111119

112120
}
113121

114-
sun_dir_path = File.join(ASSETS_DIR, 'sketchup-sun-dir.json')
122+
sunlight_path = File.join(ASSETS_DIR, 'sketchup-sunlight.json')
115123

116-
File.write(sun_dir_path, 'sketchUpSunDir = ' + sun_dir.to_json + ';')
124+
File.write(sunlight_path, 'sketchUpSunlight = ' + sunlight.to_json + ';')
117125

118126
nil
119127

@@ -132,7 +140,7 @@ def self.update
132140

133141
File.write(gltf_path, gltf.json) if gltf.valid?
134142

135-
update_sun_direction
143+
update_sunlight
136144

137145
update_translation
138146

0 commit comments

Comments
 (0)