Skip to content

Commit 71035e2

Browse files
authored
Merge pull request #616 from KhronosGroup/fix/cameraNodeSelection
Select camera via node index
2 parents 2badc4b + c8727a0 commit 71035e2

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

src/logic/uimodel.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,16 @@ class UIModel
292292
let cameraIndices = [{title: "User Camera", index: -1}];
293293
if (gltf.scenes[state.sceneIndex] !== undefined)
294294
{
295-
cameraIndices.push(...gltf.cameras.map( (camera, index) => {
296-
if(gltf.scenes[state.sceneIndex].includesNode(gltf, camera.node))
295+
cameraIndices.push(...gltf.nodes.map( (node, index) => {
296+
if(node.camera !== undefined && gltf.scenes[state.sceneIndex].includesNode(gltf, index))
297297
{
298-
let name = camera.name;
299-
if(name === "" || name === undefined)
298+
let name = node.name ?? "Node " + index;
299+
const camera = gltf.cameras[node.camera];
300+
if(camera.name !== undefined && camera.name !== "")
300301
{
301-
name = index;
302+
name += ": " + camera.name;
303+
} else {
304+
name += ": Camera " + node.camera;
302305
}
303306
return {title: name, index: index};
304307
}
@@ -311,7 +314,7 @@ class UIModel
311314
})
312315
);
313316
cameraIndices.subscribe(cameras => this.app.cameras = cameras);
314-
const loadedCameraIndex = sceneChangeObservable.pipe(map(state => state.cameraIndex));
317+
const loadedCameraIndex = sceneChangeObservable.pipe(map(state => state.cameraNodeIndex));
315318
loadedCameraIndex.subscribe(index => this.app.selectedCamera = index !== undefined ? index : -1 );
316319
}
317320

src/main.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export default async () => {
126126
state.gltf = gltf;
127127
const defaultScene = state.gltf.scene;
128128
state.sceneIndex = defaultScene === undefined ? 0 : defaultScene;
129-
state.cameraIndex = undefined;
129+
state.cameraNodeIndex = undefined;
130130

131131
if (state.gltf.scenes.length != 0) {
132132
if (state.sceneIndex > state.gltf.scenes.length - 1) {
@@ -171,7 +171,7 @@ export default async () => {
171171
.then((gltf) => {
172172
state.gltf = gltf;
173173
state.sceneIndex = 0;
174-
state.cameraIndex = undefined;
174+
state.cameraNodeIndex = undefined;
175175

176176
uiModel.exitLoadingState();
177177
redraw = true;
@@ -200,7 +200,7 @@ export default async () => {
200200
const sceneChangedObservable = uiModel.scene.pipe(
201201
map((sceneIndex) => {
202202
state.sceneIndex = sceneIndex;
203-
state.cameraIndex = undefined;
203+
state.cameraNodeIndex = undefined;
204204
const scene = state.gltf.scenes[state.sceneIndex];
205205
if (scene !== undefined) {
206206
scene.applyTransformHierarchy(state.gltf);
@@ -218,9 +218,9 @@ export default async () => {
218218
const cameraExportChangedObservable = uiModel.cameraValuesExport.pipe(
219219
map(() => {
220220
const camera =
221-
state.cameraIndex === undefined
221+
state.cameraNodeIndex === undefined
222222
? state.userCamera
223-
: state.gltf.cameras[state.cameraIndex];
223+
: state.gltf.cameras[state.cameraNodeIndex];
224224
return camera.getDescription(state.gltf);
225225
})
226226
);
@@ -257,7 +257,7 @@ export default async () => {
257257
listenForRedraw(uiModel.scene);
258258

259259
uiModel.camera.subscribe(
260-
(camera) => (state.cameraIndex = camera !== -1 ? camera : undefined)
260+
(camera) => (state.cameraNodeIndex = camera !== -1 ? camera : undefined)
261261
);
262262
listenForRedraw(uiModel.camera);
263263

@@ -447,21 +447,21 @@ export default async () => {
447447
uiModel.attachCameraChangeObservable(sceneChangedStateObservable);
448448

449449
uiModel.orbit.subscribe((orbit) => {
450-
if (state.cameraIndex === undefined) {
450+
if (state.cameraNodeIndex === undefined) {
451451
state.userCamera.orbit(orbit.deltaPhi, orbit.deltaTheta);
452452
}
453453
});
454454
listenForRedraw(uiModel.orbit);
455455

456456
uiModel.pan.subscribe((pan) => {
457-
if (state.cameraIndex === undefined) {
457+
if (state.cameraNodeIndex === undefined) {
458458
state.userCamera.pan(pan.deltaX, -pan.deltaY);
459459
}
460460
});
461461
listenForRedraw(uiModel.pan);
462462

463463
uiModel.zoom.subscribe((zoom) => {
464-
if (state.cameraIndex === undefined) {
464+
if (state.cameraNodeIndex === undefined) {
465465
state.userCamera.zoomBy(zoom.deltaZoom);
466466
}
467467
});

0 commit comments

Comments
 (0)