Skip to content

Commit a32ee68

Browse files
committed
SceneLoader: setting visibility of implicitly created children to explicitly specified visibility in JSON.
This is for toggling visibility in hierarchy models loaded from OBJ, UTF8, etc. where in JSON there is just a root node.
1 parent 23da729 commit a32ee68

3 files changed

Lines changed: 42 additions & 14 deletions

File tree

build/three.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10378,6 +10378,9 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
1037810378

1037910379
node.scale.set( s[0], s[1], s[2] );
1038010380

10381+
// override children materials
10382+
// if object material was specified in JSON explicitly
10383+
1038110384
if ( material ) {
1038210385

1038310386
node.traverse( function ( child ) {
@@ -10388,6 +10391,17 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
1038810391

1038910392
}
1039010393

10394+
// override children visibility
10395+
// with root node visibility as specified in JSON
10396+
10397+
var visible = ( obj.visible !== undefined ) ? obj.visible : true;
10398+
10399+
node.traverse( function ( child ) {
10400+
10401+
child.visible = visible;
10402+
10403+
} );
10404+
1039110405
parent.add( node );
1039210406

1039310407
node.name = id;

build/three.min.js

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/loaders/SceneLoader.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
534534

535535
node.scale.set( s[0], s[1], s[2] );
536536

537+
// override children materials
538+
// if object material was specified in JSON explicitly
539+
537540
if ( material ) {
538541

539542
node.traverse( function ( child ) {
@@ -544,6 +547,17 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
544547

545548
}
546549

550+
// override children visibility
551+
// with root node visibility as specified in JSON
552+
553+
var visible = ( obj.visible !== undefined ) ? obj.visible : true;
554+
555+
node.traverse( function ( child ) {
556+
557+
child.visible = visible;
558+
559+
} );
560+
547561
parent.add( node );
548562

549563
node.name = id;

0 commit comments

Comments
 (0)