Views
Below we will consider camera parameters to manage a graphics view.
To manage view orientation with changing current camera parameters, you can run the CameraOrientationCommand command. There’s also an ability to set camera animation duration using the duration field.
New in version 1.7.0: Added the CameraCaptureCommand.
Standard Views
To set one of the standard views, you should run the CameraOrientationCommand command with the StandardCameraOrientation type in the field ‘params’.
CameraOrientationCommand command:
export type CameraOrientationCommand = {
name:"CameraOrientationCommand" // name of command
params:StandardCameraOrientation|CustomCameraOrientation // field to set parameters of a camera
duration?:number // field to set camera animation duration
}
StandardCameraOrientation type:
export type StandardCameraOrientation = {
type:"standard", // name of type
value:StdCameraOrientationsList
}
Example (TypeScript):
// run CameraOrientationCommand to set front camera orientation
view.runCommand({
name:"CameraOrientationCommand", // name of command
// next arguments
params:{
type:"standard", // name of params
value: c3dvision.StdCameraOrientationsList.Front
},
duration:200, // camera animation duration (ms)
})
Setting up Custom View
You can change the camera orientation by running the CameraOrientationCommand command with the CustomCameraOrientation params type and setting camera position values (eyeVector, upVector). Also you can add the target field to move a camera.
CustomCameraOrientation type:
export type CustomCameraOrientation = {
type:"custom",
// The eye vector on target
eyeVector: {
x:number,
y:number,
z:number,
},
// The up vector of the camera
upVector: {
x:number,
y:number,
z:number,
},
// Target position of the camera
target?: {
x:number,
y:number,
z:number,
},
// The distance from the target to the eye position
distance?:number,
}
Example (TypeScript):
// run CameraOrientationCommand to set front camera orientation
view.runCommand({
name:"CameraOrientationCommand", // name of command
// next arguments
params:{
type:"custom", // name of params
eyeVector:{
x:0,
y:0,
z:-1,
},
upVector:{
x:0,
y:1,
z:0,
}
},
duration:200, // camera animation duration(ms)
})
Saving Current View
You can save current camera parameters to reuse them later. To get camera parameters, you should run the GetParametersCommand command with the Camera type.
Example (TypeScript):
// run GetParametersCommand to get current camera orientation
let result = view.runCommand({
name:"GetParametersCommand", // name of command
// next arguments:
type:"Camera"
})
if( result.name == "GetParametersResult" )
{
// save parameters
switch(result.params.name)
{
case "Camera":
savedOrientation = result.params.orientation
break
}
}
Then, run the CameraOrientationCommand command with saved parameters to restore a camera orientation.
Example (TypeScript):
// run CameraOrientationCommand to load saved camera orientation
view.runCommand({
name:"CameraOrientationCommand", // name of command
// next arguments
params: savedOrientation,
duration:200, // camera animation duration(ms)
})
Capturing Camera
The CameraCaptureCommand command allows you to handle the event when the camera changes its parameters (position, projection, etc.). When the parameters change, it fires the specified user’s callback.
Important
The callback is fired only once, as it’s removed right after firing. If you run a new command before a previous one fires its callback, the latter is never fired as it’s already rewritten.
CameraCaptureCommand type (TypeScript):
export type CameraCaptureCommand = {
name: "CameraCaptureCommand"
onChange: () => void
}
Example (TypeScript):
// run command "zoom to fit"
view.runCommand({
name: "CameraCaptureCommand", // name of command
// next arguments
onChange: () => {...}
})
Zoom to Fit
The ZoomFitCommand command allows you to scale an object or a scene to fit them in a camera. The uuid field is an identifier of node to fit in a camera.
Example (TypeScript):
// run command "zoom to fit"
view.runCommand({
name: "ZoomFitCommand", // name of command
// next arguments
uuid: node.id, // node`s id to fit in camera
duration: 200 // camera animation duration (ms)
})
Making Image of View
Example (TypeScript):
// run command "make image"
_view.runCommand({
name: "MakeImageCommand", // name of command
// next arguments
htmlParent: "body" //html element to contain img element
})