Skip to content

Commit

Permalink
Viewer: add SpotLightHelper to view spotlight's cone
Browse files Browse the repository at this point in the history
+ add function set_folder_callback
  • Loading branch information
ManifoldFR committed Feb 3, 2024
1 parent 5ec49ff commit c91bc26
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/main.min.js

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1143,12 +1143,24 @@ class Viewer {
return spot_light;
}

set_folder_callback(path, callback) {
this.scene_tree.find(path).on_update = callback;
}

add_default_scene_elements() {
var spot_light = this.create_default_spot_light();
this.set_object(["Lights", "SpotLight"], spot_light);
// By default, the spot light is turned off, since
// it's primarily used for casting detailed shadows
this.set_property(["Lights", "SpotLight"], "visible", false);
const spotlight_helper = new THREE.SpotLightHelper(spot_light, 0xf5a716);
spotlight_helper.matrix = spot_light.matrix;
this.set_folder_callback(["Lights", "SpotLight"], () => {
spotlight_helper.update();
this.set_dirty();
});
this.set_object(["Lights", "SpotLightHelper"], spotlight_helper);
this.set_property(["Lights", "SpotLightHelper"], "visible", false);

var point_light_px = new THREE.PointLight(0xffffff,
this.upgrade_intensity(0.4));
Expand Down Expand Up @@ -1226,9 +1238,9 @@ class Viewer {
bg_folder.on_update = () => {
this.update_background();
};
this.scene_tree.find(["Background", "<object>"]).on_update = () => {
this.set_folder_callback(["Background", "<object>"], () => {
this.update_background();
}
})
this.update_background();
}

Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1111,13 +1111,20 @@ __metadata:
languageName: node
linkType: hard

"three@npm:^0.160.1, three@npm:~0.160.0":
"three@npm:^0.160.1":
version: 0.160.1
resolution: "three@npm:0.160.1"
checksum: b14b54a8b0799bc337ea2a841a1f01322dc50198d8a438ff4fbdf83ad95a15bd405ba43bd398c05b1ffc2e40a7685b73481a048c288389acb949cea5510269ea
languageName: node
linkType: hard

"three@npm:~0.160.0":
version: 0.160.0
resolution: "three@npm:0.160.0"
checksum: d78e9605de6f8072e7fbebe36db7741c13f2ae89be15b4421d2fc7d549e216f53cb3e136d98e9424648f19a42345f47f8186478e038f0046655475166c156b0b
languageName: node
linkType: hard

"update-browserslist-db@npm:^1.0.13":
version: 1.0.13
resolution: "update-browserslist-db@npm:1.0.13"
Expand Down

0 comments on commit c91bc26

Please sign in to comment.