문제 해결 가이드

이 페이지는 사용 중 가장 일반적인 오류를 다루고 있습니다. @aspose/3d TypeScript 및 Node.js 프로젝트, 뿌리 원인 설명과 검증 된 수정으로.


모듈 해결 오류

Error: Cannot find module '@aspose/3d/formats/obj'

뿌리 원인: TypeScript의 모듈 해상도 전략은 Node.js 스타일의 하위 경로 수출을 지원하지 않습니다 (exports 안에 있는 package.json(만약 없으면 moduleResolution 설정되어 있는 것에 대하여 node 또는 node16.

고정: 세트 moduleResolution 를 위해서 "node" 당신의 안에서 tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "strict": true
  }
}

TypeScript 5.x를 사용하는 경우 "module": "node16" 또는 "module": "nodenext",사용하기 "moduleResolution": "node16" 경기할 수 있는 것.


SyntaxError: Cannot use import statement in a module

뿌리 원인: 작성된 JavaScript가 실행되고 있습니다. require() 세만틱하지만 출력에는 ES 모듈이 포함되어 있습니다. import 싱글 : 이것이 일어날 때 module 설정되어 있는 것에 대하여 es2020 또는 esnext 그러나 Node.js 실행 시간은 CommonJS를 기대합니다.

고정:사용하기 : 사용 "module": "commonjs" 안에 있는 tsconfig.json 그리고 그들이 작성한 것을 실행한다. .js 파일과 함께 node 직접적으로 :

{
  "compilerOptions": {
    "module": "commonjs",
    "outDir": "./dist"
  }
}

그 후에, 그것을 작성하고 실행 :

npx tsc
node dist/main.js

Error: Cannot find module '@aspose/3d'

뿌리 원인: 패키지가 설치되지 않거나, 또는 node_modules 스테일이 됐어요.

고정:

npm install @aspose/3d

설치를 확인하십시오 :

node -e "const { Scene } = require('@aspose/3d'); console.log('OK', new Scene().constructor.name);"

빈 장면 충전 후

장면이 흔들리지만 rootNode.childNodes 텅 비어있다

원인 뿌리 (1): 파일 형식은 모든 지질을 직접 설정합니다. rootNode.entity 아이 노드 대신.이것은 단일 메시 STL 파일과 일반적입니다.

진단:

import { Scene, Mesh } from '@aspose/3d';

const scene = new Scene();
scene.open('model.stl');

// Check rootNode directly
if (scene.rootNode.entity) {
    console.log(`Root entity: ${scene.rootNode.entity.constructor.name}`);
}
console.log(`Child count: ${scene.rootNode.childNodes.length}`);

고정: 시작부터 통과하는 scene.rootNode 자기 자신뿐만 아니라 자녀들:

function visit(node: any): void {
    if (node.entity instanceof Mesh) {
        const m = node.entity as Mesh;
        console.log(`Mesh: ${m.controlPoints.length} vertices`);
    }
    for (const child of node.childNodes) {
        visit(child);
    }
}
visit(scene.rootNode);

뿌리 원인 (2): 파일 경로는 잘못되거나 파일은 0 바이트입니다.이 파일이 존재하고 전화를 걸기 전에 비공개인지 확인합니다. open().

import * as fs from 'fs';

const path = 'model.obj';
if (!fs.existsSync(path)) throw new Error(`File not found: ${path}`);
const stat = fs.statSync(path);
if (stat.size === 0) throw new Error(`File is empty: ${path}`);

OBJ 로드 후 재료 목록이 텅 비어 있습니다.

뿌리 원인: 재료 충전은 기본적으로 켜지지 않습니다. ObjLoadOptions.도서관은 기하학을 읽지 않고도 충전한다. .mtl 옆 파일을 보세요.

고정: 세트 enableMaterials = true:

import { Scene } from '@aspose/3d';
import { ObjLoadOptions } from '@aspose/3d/formats/obj';

const scene = new Scene();
const opts = new ObjLoadOptions();
opts.enableMaterials = true;
scene.open('model.obj', opts);

또한 보장하기 위해서 .mtl 파일은 같은 디렉토리에 있습니다. .obj 도서관이 해결하는 것과 관련하여, 도서를 처리하는 것은 .obj 길을 가다.


I/O 오류 및 형식

openFromBuffer - 인식되지 않은 형식 오류를 던져 버립니다.

뿌리 원인: 버퍼 콘텐츠는 인식 가능한 바이너리 형식이 아니거나 버버가 부패합니다 (부러진, 잘못된 암호화 또는 원료 비트 대신 base64).

진단:

const buffer = fs.readFileSync('model.glb');
console.log('Buffer size:', buffer.length, 'bytes');
console.log('First 4 bytes (hex):', buffer.slice(0, 4).toString('hex'));
// GLB magic: 676c5446 ("glTF")
// STL binary starts with 80 bytes of header; no fixed magic
// OBJ is text: openFromBuffer may not detect format

고정: 텍스트 기반 형식 (OBJ, COLLADA)의 경우 적절한 옵션 클래스를 입력하여 형식을 표시합니다.:

import { ObjLoadOptions } from '@aspose/3d/formats/obj';
scene.openFromBuffer(buffer, new ObjLoadOptions());

출력 GLB는 3D 시청자에서 JSON로 열립니다.

뿌리 원인: GltfSaveOptions.binaryMode 망설임을 위한 false,생산하는 것 .gltf JSON 출력은 출력을 파일 이름이 있는 경우에도 .glb.

고정: 명확하게 설정된 binaryMode = true:

import { GltfSaveOptions } from '@aspose/3d/formats/gltf';

const opts = new GltfSaveOptions();
opts.binaryMode = true;
scene.save('output.glb', opts);

STL 출력에는 슬라이더에 색상 또는 물질 데이터가 없습니다.

뿌리 원인: STL 형식은 표준 사양에서 재료 또는 색상을 지원하지 않습니다. 색상 용도 슬라이더는 지원되지 않은 특권 확장 기능을 사용합니다. @aspose/3d.

고정: 대신 3MF로 수출, 색상 및 재료 메타 데이터를 지원합니다.:

scene.save('output.3mf');

TypeScript 복합 오류

Property 'controlPoints' does not exist on type 'Entity'

뿌리 원인: Entity 기본 클래스가 될 수 있습니다; Mesh 지질적 특성을 가진 구체적인 유형입니다.당신은 필요합니다 instanceof 경비원들이 메시지 특정 회원들에게 접근하기 전에.

고정:

import { Mesh } from '@aspose/3d';

if (node.entity instanceof Mesh) {
    const mesh = node.entity as Mesh;
    console.log(mesh.controlPoints.length);
}

Type 'null' is not assignable to type 'Node'

뿌리 원인: getChildNode() 돌아오는 Node | null.TypeScript 엄격한 모드는 null 사례를 처리해야합니다.

고정:

const child = node.getChildNode('wheel');
if (!child) throw new Error('Node "wheel" not found');
// child is now Node, not null

Cannot find name 'GltfSaveOptions'

뿌리 원인: GltfSaveOptions - 모듈의 하위 도로에 있는 @aspose/3d/formats/gltf,뿌리 패키지가 아닙니다.

고정: 수입 하위 경로에서:

import { GltfSaveOptions } from '@aspose/3d/formats/gltf';

기억과 성능 문제

프로세스는 큰 FBX 파일로 메모리에서 실행됩니다.

뿌리 원인: 매우 큰 FBX 파일 (>200 MB)은 상당한 히프를 할당합니다.Node.js 기본 힐은 64 비트 시스템에서 ~1.5 GB이지만 멀티 스크린 파일에 충분하지 않을 수 있습니다.

고정:Node.js 히프 크기를 늘리십시오 :

node --max-old-space-size=8192 dist/convert.js

또한 메모리가 제한되면 동시에 대신 연속적으로 파일을 처리합니다 :

for (const file of files) {
    const scene = new Scene();
    scene.open(file);
    scene.save(file.replace('.fbx', '.glb'));
    // scene goes out of scope; GC can reclaim
}

또한 보기

 한국어