Vector2, Vector4 — Aspose.3D TypeScript API Reference
แพคเกจ: @aspose/3d (v24.12.0)
Vector2 และ Vector4 เป็นประเภทเวกเตอร์ความแม่นยำคู่ที่ส่งออกจาก @aspose/3d/utilities. Vector2 เป็นประเภทพิกัด 2 มิติมาตรฐานสำหรับข้อมูล UV. Vector4 เป็นประเภทโฮโมจีนีอัส 4 ส่วนประกอบที่ใช้สำหรับจุดควบคุมเมชและอาเรย์ข้อมูลองค์ประกอบเวอร์เท็กซ์.
import { Vector2, Vector4 } from '@aspose/3d';Properties
เวกเตอร์ความแม่นยำคู่สองส่วนประกอบที่มี x และ y ฟิลด์.
export class Vector2Properties
new Vector2(x: number = 0.0, y: number = 0.0)Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
x | number | อ่าน/เขียน | ส่วนประกอบแรก (แนวนอน). |
y | number | อ่าน/เขียน | ส่วนประกอบที่สอง (แนวตั้ง). |
length | number | อ่าน | ความยาวยูคลิด: sqrt(x² + y²). |
length2 | number | อ่าน | ความยาวกำลังสอง: x² + y². ถูกกว่า length เมื่อเปรียบเทียบระยะทาง. |
Properties
set(x, y)
ตั้งค่าทั้งสองส่วนประกอบในที่เดียว.
set(newX: number, newY: number): voidgetItem(key) / setItem(key, value)
การเข้าถึงแบบอิงดัชนี; key ต้องเป็น 0 หรือ 1.
equals(other)
การเปรียบเทียบความเท่ากันแบบส่วนประกอบ.
equals(other: Vector2): booleanVector2.parse(input) (static)
แยกวิเคราะห์สตริงที่คั่นด้วยช่องว่าง "x y" เป็น Vector2.
static parse(input: string): Vector2toString()
Properties "Vector2(x, y)".
Properties
import { Vector2 } from '@aspose/3d';
const uv = new Vector2(0.5, 0.25);
console.log(uv.x, uv.y); // 0.5 0.25
console.log(uv.length); // ~0.559
const uv2 = Vector2.parse('0.0 1.0');
console.log(uv2.equals(new Vector2(0.0, 1.0))); // true
uv.set(1.0, 0.0);
console.log(uv.toString()); // Vector2(1, 0)
Properties
เวกเตอร์ความแม่นยำคู่สี่ส่วนประกอบที่มี x, y, z, และ w ฟิลด์ ใช้เป็นประเภทขององค์ประกอบของ Mesh.controlPoints และอาร์เรย์ข้อมูลองค์ประกอบเวอร์เท็กซ์.
export class Vector4Properties
new Vector4()
new Vector4(x: number, y: number, z: number, w: number)
new Vector4(vec3: FVector3, w: number)
new Vector4(vec: FVector2, w: number)คอนสตรัคเตอร์เริ่มต้นให้ผลลัพธ์เป็น (0, 0, 0, 1). เมื่อสร้างจาก FVector3, ส่วน xyz ส่วนประกอบจะถูกดึงจากเวกเตอร์และ w จะถูกส่งเป็นอาร์กิวเมนต์ที่สอง.
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
x | number | อ่าน/เขียน | ส่วนประกอบแรก. |
y | number | อ่าน/เขียน | ส่วนประกอบที่สอง. |
z | number | อ่าน/เขียน | ส่วนที่สาม. |
w | number | อ่าน/เขียน | ส่วนประกอบที่สี่ (แบบเดียวกัน). สำหรับข้อมูลตำแหน่ง, w คือ 1.0. |
Properties
set(x, y, z, w?)
ตั้งค่าทุกส่วนประกอบให้เรียบร้อย. w ค่าเริ่มต้นเป็น 1.0.
set(newX: number, newY: number, newZ: number, newW: number = 1.0): voidgetItem(key) / setItem(key, value)
การเข้าถึงแบบดัชนี; key ต้องเป็น 0–3.
equals(other)
การเท่ากันตามส่วนประกอบ.
toString()
Properties "Vector4(x, y, z, w)".
Properties
import { Vector4 } from '@aspose/3d';
// Used as mesh control points
const v = new Vector4(1.0, 0.0, 0.0, 1.0);
console.log(v.w); // 1.0
// Index access
console.log(v.getItem(0)); // 1.0
v.setItem(1, 2.0);
console.log(v.y); // 2.0
เติมจุดควบคุมของเมช:
import { Scene, Mesh, Vector4 } from '@aspose/3d';
const mesh = new Mesh();
mesh.controlPoints.push(new Vector4(0.0, 0.0, 0.0, 1.0));
mesh.controlPoints.push(new Vector4(1.0, 0.0, 0.0, 1.0));
mesh.controlPoints.push(new Vector4(0.5, 1.0, 0.0, 1.0));
mesh.createPolygon(0, 1, 2);
const scene = new Scene();
scene.rootNode.createChildNode('triangle', mesh);
scene.save('triangle.glb');