설치
이 가이드는 TypeScript용 Aspose.3D FOSS를 설치하고 첫 번째 3D 처리 스크립트를 작성하기 전에 올바르게 작동하는지 확인하는 데 필요한 모든 내용을 다룹니다.
전제 조건
다음이 설치되어 있고 귀하의 PATH 계속 진행하기 전에:
| 도구 | 최소 | 참고 사항 |
|---|---|---|
| Node.js | 18 LTS | 20 or 22 LTS recommended |
| npm | 7 | Node.js와 함께 번들됨 |
| TypeScript | 5.0 | 다음으로 설치 npm install -D typescript |
버전을 확인하려면:
node --version # v18.x.x or later
npm --version # 7.x or later
npx tsc --version # Version 5.x.x단계 1: 프로젝트 생성 (필요한 경우)
기존 TypeScript 프로젝트에 Aspose.3D를 추가하는 경우, 이 단계를 건너뛰고 바로 단계 2로 진행하십시오.
새 프로젝트의 경우:
mkdir my-3d-project && cd my-3d-project
npm init -y
npm install -D typescript ts-node @types/node단계 2: @aspose/3d 설치
npm install @aspose/3d이 명령은 패키지와 단일 전이 종속성을 설치합니다, xmldom, 자동으로 수행됩니다. 추가 시스템 패키지, 네이티브 애드온 또는 컴파일러가 필요하지 않습니다. 설치가 완료되는 시점은 @aspose/3d 귀하의 package.json 아래에 dependencies.
설치 확인:
ls node_modules/@aspose/3d패키지 디렉터리를 다음과 함께 확인할 수 있습니다 package.json, 타입 정의 파일 (.d.ts), 및 컴파일된 JavaScript.
단계 3: TypeScript 구성
추가 또는 업데이트 tsconfig.json 프로젝트 루트에 다음 설정을 적용하십시오. 이는 라이브러리의 타입 정의와 CommonJS 출력과 완전하게 호환되도록 필요합니다:
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist"]
}핵심 설정 및 중요 이유:
| 설정 | 값 | 왜 |
|---|---|---|
target | ES2020 | 내부에서 사용되는 옵셔널 체이닝, nullish 병합 및 기타 ES2020 기능을 활성화합니다 |
module | commonjs | 라이브러리는 CommonJS 출력으로 제공됩니다; 일치해야 합니다 |
moduleResolution | node | 올바른 해석을 위해 필요합니다 @aspose/3d 하위 경로 가져오기 |
esModuleInterop | true | 네임스페이스 우회 없이 CommonJS 모듈에서 기본 가져오기를 가능하게 합니다 |
strict | true | 이 라이브러리는 다음을 사용하여 작성되었습니다 noImplicitAny 및 strictNullChecks; 이 설정을 유지하십시오 |
단계 4: 설치 확인
생성 src/verify.ts 다음 최소 가져오기 테스트와 함께:
import { Scene } from '@aspose/3d';
const scene = new Scene();
console.log('Aspose.3D FOSS for TypeScript is installed correctly.');
console.log('rootNode name:', scene.rootNode.name);컴파일하고 실행하십시오:
npx tsc
node dist/verify.js예상 출력:
Aspose.3D FOSS for TypeScript is installed correctly.
rootNode name:루트 노드 이름은 기본적으로 빈 문자열입니다 — scene.rootNode 이름 인수 없이 생성됩니다.
개발 중에 컴파일 단계를 건너뛰고 싶다면, 다음을 사용하여 직접 실행하십시오 ts-node:
npx ts-node src/verify.ts단계 5: 빠른 시작: 씬을 로드하고 노드 정보를 출력하기
다음 스크립트는 3D 파일을 로드하고 씬에 있는 모든 노드의 이름과 엔터티 유형을 출력합니다. 지원되는 모든 포맷에서 작동합니다: OBJ, glTF, GLB, STL, 3MF, FBX, 또는 COLLADA.
import { Scene, Node } from '@aspose/3d';
function printNode(node: Node, depth: number = 0): void {
const indent = ' '.repeat(depth);
const entityType = node.entity ? node.entity.constructor.name : '(no entity)';
console.log(`${indent}${node.name} [${entityType}]`);
for (const child of node.childNodes) {
printNode(child, depth + 1);
}
}
const scene = new Scene();
// Replace 'model.obj' with any supported 3D file path.
// Format is detected automatically from binary magic numbers.
scene.open('model.obj');
console.log('Scene loaded. Node hierarchy:');
printNode(scene.rootNode);다음 이름으로 저장하십시오 src/quickstart.ts 그리고 실행하십시오:
npx ts-node src/quickstart.ts하나의 메쉬가 이름이 지정된 OBJ 파일의 경우 Cube, 출력은 다음과 같이 표시됩니다:
Scene loaded. Node hierarchy:
[(no entity)]
Cube [Mesh]루트 노드의 이름은 비어 있습니다(빈 접두사로 출력됨). 자식 노드들은 로드된 파일에서 이름을 상속받습니다.
의존성 참고사항
Aspose.3D FOSS for TypeScript는 정확히 하나의 런타임 의존성을 가지고 있습니다:
| 패키지 | 목적 | 자동으로 설치됨 |
|---|---|---|
xmldom | COLLADA (DAE) 및 3MF 형식 지원을 위한 XML 파싱 | 예, via npm install @aspose/3d |
설치할 필요가 없습니다 xmldom 수동으로. 귀하의 node_modules 주요 설치 명령 후에. 네이티브 애드온 (.node 파일) 및 시스템 라이브러리가 필요하지 않습니다.
다음 단계
이제 라이브러리가 설치되고 검증되었습니다: