Skip to content

Commit

Permalink
Merge pull request #93 from ux3d/fix/multicastsForSceneChange
Browse files Browse the repository at this point in the history
turned scene change into multicasts (GSVN-211)
  • Loading branch information
UX3D-becher authored Jan 25, 2021
2 parents 6431a18 + c859938 commit c9441e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions app_web/src/logic/uimodel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { bindCallback, fromEvent, merge } from 'rxjs';
import { fromEvent, merge } from 'rxjs';
import { map, filter, startWith, pluck } from 'rxjs/operators';
import { glTF, ToneMaps, DebugOutput } from 'gltf-sample-viewer';
import { gltfInput } from '../input.js';

import { getIsGltf, getIsGlb, getIsHdr } from 'gltf-sample-viewer';

Expand Down
10 changes: 6 additions & 4 deletions app_web/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function main()

// whenever a new model is selected, load it and when complete pass the loaded gltf
// into a stream back into the UI
const subject = new Subject();
const gltfLoadedSubject = new Subject();
const gltfLoadedMulticast = uiModel.model.pipe(
mergeMap( (model) =>
{
Expand All @@ -50,18 +50,20 @@ async function main()
);
}),
// transform gltf loaded observable to multicast observable to avoid multiple execution with multiple subscriptions
multicast(subject)
multicast(gltfLoadedSubject)
);


const sceneChangedSubject = new Subject();
const sceneChangedObservable = uiModel.scene.pipe(map( newSceneIndex => {
state.sceneIndex = newSceneIndex;
state.cameraIndex = undefined;
const scene = state.gltf.scenes[state.sceneIndex];
scene.applyTransformHierarchy(state.gltf);
computePrimitiveCentroids(state.gltf);
state.userCamera.fitViewToScene(state.gltf, state.sceneIndex);
}));
}),
multicast(sceneChangedSubject)
);

const statisticsUpdateObservableTemp = merge(
gltfLoadedMulticast,
Expand Down

0 comments on commit c9441e2

Please sign in to comment.