Store field of view in engine's camera.
This commit is contained in:
parent
05c08b7cfe
commit
73417f2a90
@ -29,7 +29,8 @@
|
||||
camera : new OV.Camera (
|
||||
new OV.Coord3D (-1.5, 2.0, 3.0),
|
||||
new OV.Coord3D (0.0, 0.0, 0.0),
|
||||
new OV.Coord3D (0.0, 1.0, 0.0)
|
||||
new OV.Coord3D (0.0, 1.0, 0.0),
|
||||
45.0
|
||||
),
|
||||
backgroundColor : new OV.RGBAColor (255, 255, 255, 255),
|
||||
defaultColor : new OV.RGBColor (200, 200, 200),
|
||||
|
||||
@ -49,7 +49,8 @@ export let ParameterConverter =
|
||||
let cameraParameters = [
|
||||
this.NumberToString (camera.eye.x), this.NumberToString (camera.eye.y), this.NumberToString (camera.eye.z),
|
||||
this.NumberToString (camera.center.x), this.NumberToString (camera.center.y), this.NumberToString (camera.center.z),
|
||||
this.NumberToString (camera.up.x), this.NumberToString (camera.up.y), this.NumberToString (camera.up.z)
|
||||
this.NumberToString (camera.up.x), this.NumberToString (camera.up.y), this.NumberToString (camera.up.z),
|
||||
this.NumberToString (camera.fov)
|
||||
].join (',');
|
||||
return cameraParameters;
|
||||
},
|
||||
@ -60,13 +61,20 @@ export let ParameterConverter =
|
||||
return null;
|
||||
}
|
||||
let paramParts = str.split (',');
|
||||
if (paramParts.length !== 9) {
|
||||
if (paramParts.length < 9) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let fieldOfView = 45.0;
|
||||
if (paramParts.length >= 10) {
|
||||
fieldOfView = this.StringToNumber (paramParts[9]);
|
||||
}
|
||||
|
||||
let camera = new Camera (
|
||||
new Coord3D (this.StringToNumber (paramParts[0]), this.StringToNumber (paramParts[1]), this.StringToNumber (paramParts[2])),
|
||||
new Coord3D (this.StringToNumber (paramParts[3]), this.StringToNumber (paramParts[4]), this.StringToNumber (paramParts[5])),
|
||||
new Coord3D (this.StringToNumber (paramParts[6]), this.StringToNumber (paramParts[7]), this.StringToNumber (paramParts[8]))
|
||||
new Coord3D (this.StringToNumber (paramParts[6]), this.StringToNumber (paramParts[7]), this.StringToNumber (paramParts[8])),
|
||||
fieldOfView
|
||||
);
|
||||
return camera;
|
||||
},
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
import { CoordIsEqual3D } from '../geometry/coord3d.js';
|
||||
import { IsEqual } from '../geometry/geometry.js';
|
||||
|
||||
export class Camera
|
||||
{
|
||||
constructor (eye, center, up)
|
||||
constructor (eye, center, up, fov)
|
||||
{
|
||||
this.eye = eye;
|
||||
this.center = center;
|
||||
this.up = up;
|
||||
this.fov = fov;
|
||||
}
|
||||
|
||||
Clone ()
|
||||
@ -14,12 +16,13 @@ export class Camera
|
||||
return new Camera (
|
||||
this.eye.Clone (),
|
||||
this.center.Clone (),
|
||||
this.up.Clone ()
|
||||
this.up.Clone (),
|
||||
this.fov
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function CameraIsEqual3D (a, b)
|
||||
{
|
||||
return CoordIsEqual3D (a.eye, b.eye) && CoordIsEqual3D (a.center, b.center) && CoordIsEqual3D (a.up, b.up);
|
||||
return CoordIsEqual3D (a.eye, b.eye) && CoordIsEqual3D (a.center, b.center) && CoordIsEqual3D (a.up, b.up) && IsEqual (a.fov, b.fov);
|
||||
}
|
||||
|
||||
@ -339,7 +339,7 @@ export class Navigation
|
||||
this.Update ();
|
||||
}
|
||||
|
||||
GetFitToSphereCamera (center, radius, fov)
|
||||
GetFitToSphereCamera (center, radius)
|
||||
{
|
||||
if (IsZero (radius)) {
|
||||
return null;
|
||||
@ -352,7 +352,7 @@ export class Navigation
|
||||
fitCamera.center = center.Clone ();
|
||||
|
||||
let centerEyeDirection = SubCoord3D (fitCamera.eye, fitCamera.center).Normalize ();
|
||||
let fieldOfView = fov / 2.0;
|
||||
let fieldOfView = this.camera.fov / 2.0;
|
||||
if (this.canvas.width < this.canvas.height) {
|
||||
fieldOfView = fieldOfView * this.canvas.width / this.canvas.height;
|
||||
}
|
||||
|
||||
@ -11,23 +11,27 @@ import * as THREE from 'three';
|
||||
|
||||
export function GetDefaultCamera (direction)
|
||||
{
|
||||
let fieldOfView = 45.0;
|
||||
if (direction === Direction.X) {
|
||||
return new Camera (
|
||||
new Coord3D (2.0, -3.0, 1.5),
|
||||
new Coord3D (0.0, 0.0, 0.0),
|
||||
new Coord3D (1.0, 0.0, 0.0)
|
||||
new Coord3D (1.0, 0.0, 0.0),
|
||||
fieldOfView
|
||||
);
|
||||
} else if (direction === Direction.Y) {
|
||||
return new Camera (
|
||||
new Coord3D (-1.5, 2.0, 3.0),
|
||||
new Coord3D (0.0, 0.0, 0.0),
|
||||
new Coord3D (0.0, 1.0, 0.0)
|
||||
new Coord3D (0.0, 1.0, 0.0),
|
||||
fieldOfView
|
||||
);
|
||||
} else if (direction === Direction.Z) {
|
||||
return new Camera (
|
||||
new Coord3D (-1.5, -3.0, 2.0),
|
||||
new Coord3D (0.0, 0.0, 0.0),
|
||||
new Coord3D (0.0, 0.0, 1.0)
|
||||
new Coord3D (0.0, 0.0, 1.0),
|
||||
fieldOfView
|
||||
);
|
||||
}
|
||||
return null;
|
||||
@ -322,9 +326,8 @@ export class Viewer
|
||||
}
|
||||
let center = new Coord3D (boundingSphere.center.x, boundingSphere.center.y, boundingSphere.center.z);
|
||||
let radius = boundingSphere.radius;
|
||||
let fov = this.camera.fov;
|
||||
|
||||
let newCamera = this.navigation.GetFitToSphereCamera (center, radius, fov);
|
||||
let newCamera = this.navigation.GetFitToSphereCamera (center, radius);
|
||||
this.navigation.MoveCamera (newCamera, animation ? this.settings.animationSteps : 0);
|
||||
}
|
||||
|
||||
@ -513,12 +516,11 @@ export class Viewer
|
||||
|
||||
InitNavigation ()
|
||||
{
|
||||
this.camera = new THREE.PerspectiveCamera (45.0, this.canvas.width / this.canvas.height, 0.1, 1000.0);
|
||||
let camera = GetDefaultCamera (Direction.Z);
|
||||
this.camera = new THREE.PerspectiveCamera (camera.fov, this.canvas.width / this.canvas.height, 0.1, 1000.0);
|
||||
this.scene.add (this.camera);
|
||||
|
||||
let canvasElem = this.renderer.domElement;
|
||||
let camera = GetDefaultCamera (Direction.Z);
|
||||
|
||||
this.navigation = new Navigation (canvasElem, camera, {
|
||||
onUpdate : () => {
|
||||
this.Render ();
|
||||
|
||||
@ -10,7 +10,8 @@ describe ('Parameter List', function () {
|
||||
let camera = new OV.Camera (
|
||||
new OV.Coord3D (1.0, 1.0, 1.0),
|
||||
new OV.Coord3D (0.0, 0.0, 0.0),
|
||||
new OV.Coord3D (0.0, 0.0, 1.0)
|
||||
new OV.Coord3D (0.0, 0.0, 1.0),
|
||||
45.0
|
||||
);
|
||||
let background = new OV.RGBAColor (4, 5, 6, 7);
|
||||
let color = new OV.RGBColor (1, 2, 3);
|
||||
@ -25,10 +26,10 @@ describe ('Parameter List', function () {
|
||||
edgeThreshold : 15
|
||||
}).GetParameterList ();
|
||||
assert.strictEqual (urlParams1, 'model=a.txt,b.txt');
|
||||
assert.strictEqual (urlParams2, 'camera=1.00000,1.00000,1.00000,0.00000,0.00000,0.00000,0.00000,0.00000,1.00000');
|
||||
assert.strictEqual (urlParams3, 'model=a.txt,b.txt$camera=1.00000,1.00000,1.00000,0.00000,0.00000,0.00000,0.00000,0.00000,1.00000');
|
||||
assert.strictEqual (urlParams4, 'model=a.txt,b.txt$camera=1.00000,1.00000,1.00000,0.00000,0.00000,0.00000,0.00000,0.00000,1.00000$defaultcolor=1,2,3');
|
||||
assert.strictEqual (urlParams5, 'model=a.txt,b.txt$camera=1.00000,1.00000,1.00000,0.00000,0.00000,0.00000,0.00000,0.00000,1.00000$backgroundcolor=4,5,6,7$defaultcolor=1,2,3');
|
||||
assert.strictEqual (urlParams2, 'camera=1.00000,1.00000,1.00000,0.00000,0.00000,0.00000,0.00000,0.00000,1.00000,45.00000');
|
||||
assert.strictEqual (urlParams3, 'model=a.txt,b.txt$camera=1.00000,1.00000,1.00000,0.00000,0.00000,0.00000,0.00000,0.00000,1.00000,45.00000');
|
||||
assert.strictEqual (urlParams4, 'model=a.txt,b.txt$camera=1.00000,1.00000,1.00000,0.00000,0.00000,0.00000,0.00000,0.00000,1.00000,45.00000$defaultcolor=1,2,3');
|
||||
assert.strictEqual (urlParams5, 'model=a.txt,b.txt$camera=1.00000,1.00000,1.00000,0.00000,0.00000,0.00000,0.00000,0.00000,1.00000,45.00000$backgroundcolor=4,5,6,7$defaultcolor=1,2,3');
|
||||
assert.strictEqual (urlParams6, 'edgesettings=on,1,2,3,15');
|
||||
});
|
||||
|
||||
@ -37,13 +38,15 @@ describe ('Parameter List', function () {
|
||||
let camera = new OV.Camera (
|
||||
new OV.Coord3D (1.0, 1.0, 1.0),
|
||||
new OV.Coord3D (0.0, 0.0, 0.0),
|
||||
new OV.Coord3D (0.0, 0.0, 1.0)
|
||||
new OV.Coord3D (0.0, 0.0, 1.0),
|
||||
45.0
|
||||
);
|
||||
let background = new OV.RGBAColor (4, 5, 6, 7);
|
||||
let color = new OV.RGBColor (1, 2, 3);
|
||||
let urlParamsLegacy = 'a.txt,b.txt';
|
||||
let urlParams1 = 'model=a.txt,b.txt';
|
||||
let urlParams2 = 'camera=1.0000,1.0000,1.0000,0.0000,0.0000,0.0000,0.0000,0.0000,1.0000';
|
||||
let urlParams2b = 'camera=1.0000,1.0000,1.0000,0.0000,0.0000,0.0000,0.0000,0.0000,1.0000,60.0000';
|
||||
let urlParams3 = 'model=a.txt,b.txt$camera=1.0000,1.0000,1.0000,0.0000,0.0000,0.0000,0.0000,0.0000,1.0000';
|
||||
let urlParams4 = 'model=a.txt,b.txt$camera=1.0000,1.0000,1.0000,0.0000,0.0000,0.0000,0.0000,0.0000,1.0000$defaultcolor=1,2,3';
|
||||
let urlParams5 = 'model=a.txt,b.txt$camera=1.0000,1.0000,1.0000,0.0000,0.0000,0.0000,0.0000,0.0000,1.0000$backgroundcolor=4,5,6,7$defaultcolor=1,2,3';
|
||||
@ -59,6 +62,10 @@ describe ('Parameter List', function () {
|
||||
assert.deepStrictEqual (parser2.GetModelUrls (), null);
|
||||
assert.deepStrictEqual (parser2.GetCamera (), camera);
|
||||
assert.deepStrictEqual (parser2.GetDefaultColor (), null);
|
||||
let parser2b = OV.CreateUrlParser (urlParams2b);
|
||||
assert.deepStrictEqual (parser2b.GetModelUrls (), null);
|
||||
assert.deepStrictEqual (parser2b.GetCamera (), new OV.Camera (new OV.Coord3D (1.0, 1.0, 1.0), new OV.Coord3D (0.0, 0.0, 0.0), new OV.Coord3D (0.0, 0.0, 1.0), 60.0));
|
||||
assert.deepStrictEqual (parser2b.GetDefaultColor (), null);
|
||||
let parser3 = OV.CreateUrlParser (urlParams3);
|
||||
assert.deepStrictEqual (parser3.GetModelUrls (), modelUrls);
|
||||
assert.deepStrictEqual (parser3.GetCamera (), camera);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user