Class Camera
แพคเกจ: @aspose/3d (v24.12.0)
Camera เป็น Entity ที่สามารถแนบไปยัง Node เพื่อกำหนดมุมมองในฉาก มันรองรับการฉายภาพแบบ perspective และ orthographic ทั้งสองแบบ โดยควบคุมด้วย projectionType property. พารามิเตอร์ของกล้องจะถูกบันทึกในไฟล์ 3D เมื่อฉากถูกบันทึกเป็นรูปแบบที่รองรับกล้อง (FBX, COLLADA, glTF).
export class Camera extends EntityProperties
A3DObject ← SceneObject ← Entity ← Camera
Properties
เพิ่มกล้องแบบ perspective ลงในฉากและกำหนด frustum ของมัน.
import { Scene, Node, Camera, ProjectionType } from '@aspose/3d';
const scene = new Scene();
const camNode = scene.rootNode.createChildNode('mainCamera');
const camera = new Camera('mainCamera', ProjectionType.PERSPECTIVE);
camNode.entity = camera;
camera.nearPlane = 0.1;
camera.farPlane = 500;
camera.fieldOfView = 60;
camera.aspect = 16 / 9;
scene.save('output.gltf');
console.log(`Camera projection: ${camera.projectionType}`);
// Camera projection: PERSPECTIVE
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
name | string | '' | ชื่อของกล้องนี้ ใช้เพื่อระบุในกราฟของฉาก. |
projectionType | `ProjectionType | string` | ProjectionType.PERSPECTIVE |
nearPlane | number | 0.1 | ระยะห่างจากกล้องถึงระนาบตัดเก็บใกล้. วัตถุที่อยู่ใกล้กว่าค่านี้จะไม่ถูกเรนเดอร์. |
farPlane | number | 1000.0 | ระยะห่างจากกล้องถึงระนาบตัดเก็บไกล. วัตถุที่อยู่ไกลกว่าค่านี้จะไม่ถูกเรนเดอร์. |
aspect | number | 1.0 | อัตราส่วนความกว้างต่อความสูงของ viewport ของกล้อง. |
fieldOfView | number | 0.0 | มุมมองแนวทแยงเป็นองศา (การฉายภาพแบบ perspective). |
fieldOfViewX | number | 0.0 | มุมมองแนวนอนเป็นองศา. |
fieldOfViewY | number | 0.0 | มุมมองแนวตั้งเป็นองศา. |
orthoHeight | number | 100.0 | ความสูงของปริมาณการฉายภาพออร์โธกราฟิก มีความสำคัญเฉพาะเมื่อ projectionType เป็น 'ORTHOGRAPHIC'. |
width | number | 0.0 | ความกว้างของเซนเซอร์หรือวิวพอร์ต, ใช้เมื่อ apertureMode ควบคุมการสรุปค่า FOV. |
height | number | 0.0 | ความสูงของเซนเซอร์หรือวิวพอร์ต. |
aspectRatio | number | 1.0 | นามแฝงสำหรับอัตราส่วนภาพ, มีไว้เพื่อความเข้ากันได้กับฉากบางส่วนที่มาจาก FBX. |
Properties
moveForward(distance)
ย้ายกล้องไปข้างหน้าตามทิศทางการมองของมันโดยระยะที่กำหนด.
moveForward(distance: number): voidProperties
distance number
ระยะทางที่จะย้ายไปข้างหน้า ค่าเป็นลบจะทำให้กล้องเคลื่อนถอยหลัง.
Properties
void
Properties
import { Scene, Camera, ProjectionType } from '@aspose/3d';
const scene = new Scene();
const camNode = scene.rootNode.createChildNode('cam');
const camera = new Camera('cam', ProjectionType.PERSPECTIVE);
camNode.entity = camera;
camera.moveForward(10);
console.log('Camera moved forward by 10 units.');Properties
- ในซอร์ส,
CameraสืบทอดจากEntity.LightยังขยายจากCamera, ซึ่งหมายความว่าLightวัตถุมีคุณสมบัติของกล้องทั้งหมดในลำดับชั้นประเภท; สิ่งนี้สะท้อนโมเดลข้อมูล FBX ที่ไฟแสงและกล้องใช้โหนดฐานร่วมกัน. - ใช้
ProjectionTypeค่าคงที่ของคลาส (ProjectionType.PERSPECTIVE,ProjectionType.ORTHOGRAPHIC) แทนการใช้สตริงลิเทอรัลดิบเพื่อความปลอดภัยของประเภท.