Skip to content

Commit

Permalink
Use camera fov when exporting html viewer (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck authored Dec 6, 2024
1 parent 7c65fa5 commit fae6578
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/splat-serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,16 +912,18 @@ const serializeViewer = async (splats: Splat[], write: WriteFunc) => {

// use camera clear color
const bgClr = events.invoke('bgClr');
const fov = events.invoke('camera.fov');
const pose = events.invoke('camera.poses')?.[0];
const p = pose && pose.position;
const t = pose && pose.target;

const html = ViewerHtmlTemplate
.replace('{{backgroundColor}}', `rgb(${bgClr.r * 255} ${bgClr.g * 255} ${bgClr.b * 255})`)
.replace('{{clearColor}}', `${bgClr.r} ${bgClr.g} ${bgClr.b}`)
.replace('{{plyModel}}', plyModel)
.replace('{{fov}}', `${fov.toFixed(2)}`)
.replace('{{resetPosition}}', pose ? `new Vec3(${p.x}, ${p.y}, ${p.z})` : 'null')
.replace('{{resetTarget}}', pose ? `new Vec3(${t.x}, ${t.y}, ${t.z})` : 'null');
.replace('{{resetTarget}}', pose ? `new Vec3(${t.x}, ${t.y}, ${t.z})` : 'null')
.replace('{{plyModel}}', plyModel);

await write(new TextEncoder().encode(html), true);
};
Expand Down
19 changes: 12 additions & 7 deletions src/templates/viewer-html-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const template = /* html */ `
<!-- Camera (with XR support) -->
<pc-entity name="camera root">
<pc-entity name="camera">
<pc-camera clear-color="{{clearColor}}"></pc-camera>
<pc-camera clear-color="{{clearColor}}" fov="{{fov}}"></pc-camera>
<pc-scripts>
<pc-script name="cameraControls"></pc-script>
</pc-scripts>
Expand Down Expand Up @@ -124,19 +124,19 @@ const template = /* html */ `
<h3>Controls</h3>
<div class="control-item">
<span class="control-action">Orbit</span>
<span class="control-key">Left mouse button</span>
<span class="control-key">Left Mouse Button</span>
</div>
<div class="control-item">
<span class="control-action">Pan</span>
<span class="control-key">Middle mouse button</span>
<span class="control-key">Middle Mouse Button</span>
</div>
<div class="control-item">
<span class="control-action">Look around</span>
<span class="control-key">Right mouse button</span>
<span class="control-key">Right Mouse Button</span>
</div>
<div class="control-item">
<span class="control-action">Zoom</span>
<span class="control-key">Mouse wheel</span>
<span class="control-key">Mouse Wheel</span>
</div>
<div class="control-item">
<span class="control-action">Fly</span>
Expand All @@ -151,11 +151,11 @@ const template = /* html */ `
<span class="control-key">Ctrl</span>
</div>
<div class="control-item">
<span class="control-action">Frame the scene</span>
<span class="control-action">Frame Scene</span>
<span class="control-key">F</span>
</div>
<div class="control-item">
<span class="control-action">Return to origin</span>
<span class="control-action">Reset Camera</span>
<span class="control-key">R</span>
</div>
</div>
Expand Down Expand Up @@ -198,6 +198,11 @@ const template = /* html */ `
const bbox = this.calcBound();
// configure camera
this.entity.camera.horizontalFov = true;
this.entity.camera.farClip = bbox.halfExtents.length() * 20;
this.entity.camera.nearClip = this.entity.camera.farClip * 0.001;
if (bbox.halfExtents.length() > 100 || resetPosition || resetTarget) {
this.resetCamera(bbox);
} else {
Expand Down

0 comments on commit fae6578

Please sign in to comment.