Fehlerbehebungsleitfäden

Fehlerbehebungsleitfäden

Diese Seite behandelt die häufigsten Fehler, die bei der Verwendung von @aspose/3d in TypeScript‑ und Node.js‑Projekten auftreten, mit Ursachen‑Erklärungen und geprüften Lösungen.


Modulauflösungsfehler

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

Ursache: Die Modulauflösungsstrategie von TypeScript unterstützt Node.js‑ähnliche Sub‑Pfad‑Exporte (exports in package.json) nicht, es sei denn, moduleResolution ist auf node oder node16 gesetzt.

Korrektur: Setze moduleResolution auf "node" in deinem tsconfig.json:

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

Wenn Sie TypeScript 5.x mit "module": "node16" oder "module": "nodenext" verwenden, nutzen Sie "moduleResolution": "node16" zum Abgleichen.


SyntaxError: Cannot use import statement in a module

Ursache: Der kompilierte JavaScript‑Code wird mit require()‑Semantik ausgeführt, aber die Ausgabe enthält ES‑Modul‑import‑Syntax; das passiert, wenn module auf es2020 oder esnext gesetzt ist, aber die Node.js‑Laufzeit CommonJS erwartet.

Korrektur: Verwenden Sie "module": "commonjs" in tsconfig.json und führen Sie die kompilierten .js-Dateien mit node direkt aus:

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

Dann kompilieren und ausführen:

npx tsc
node dist/main.js

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

Ursache: Das Paket ist nicht installiert, oder node_modules ist veraltet.

Behebung:

npm install @aspose/3d

Installation überprüfen:

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

Leere Szene nach dem Laden

Szene lädt, aber rootNode.childNodes ist leer

Ursache (1): Das Dateiformat legt alle Geometrie direkt auf rootNode.entity ab, anstatt als Kindknoten. Dies ist bei STL-Dateien mit einem einzelnen Mesh üblich.

Diagnose:

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}`);

Korrektur: Durchlaufen Sie beginnend mit scene.rootNode selbst, nicht nur dessen Kinder:

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);

Ursache (2): Der Dateipfad ist falsch oder die Datei hat Null‑Bytes. Stellen Sie sicher, dass die Datei existiert und nicht leer ist, bevor Sie open() aufrufen.

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}`);

Materialliste ist nach OBJ‑Laden leer

Ursache: Das Laden von Materialien ist standardmäßig in ObjLoadOptions deaktiviert. Die Bibliothek lädt die Geometrie, ohne die .mtl Sidecar-Datei zu lesen.

Fix: Setze 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);

Stellen Sie außerdem sicher, dass die .mtl‑Datei im selben Verzeichnis wie die .obj‑Datei liegt, da die Bibliothek sie relativ zum Pfad .obj auflöst.


Format- und I/O-Fehler

openFromBuffer wirft einen nicht erkannten Formatfehler

Ursache: Der Pufferinhalt ist kein erkennbares Binärformat oder der Puffer ist beschädigt (abgeschnitten, falsche Kodierung oder Base64 anstelle von Rohbytes).

Diagnose:

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

Behebung: Für textbasierte Formate (OBJ, COLLADA) übergeben Sie die entsprechende Optionsklasse, um das Format anzugeben:

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

Ausgabe-GLB wird in 3D-Viewern als JSON geöffnet

Ursache: GltfSaveOptions.binaryMode ist standardmäßig false, erzeugt .gltf JSON‑Ausgabe, selbst wenn der Ausgabedateiname .glb ist.

Korrektur: Explizit binaryMode = true setzen:

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

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

STL-Ausgabe enthält keine Farb- oder Materialdaten im Slicer

Ursache: Das STL-Format unterstützt in seiner Standardspezifikation keine Materialien oder Farben. Farbunterstützende Slicer verwenden proprietäre Erweiterungen, die von @aspose/3d nicht unterstützt werden.

Fix: Exportieren Sie stattdessen in 3MF, das Farb‑ und Materialmetadaten unterstützt:

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

TypeScript-Kompilierungsfehler

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

Ursache: Entity ist die Basisklasse; Mesh ist der konkrete Typ mit Geometrieeigenschaften. Sie benötigen eine instanceof‑Abfrage, bevor Sie auf mesh‑spezifische Mitglieder zugreifen.

Behebung:

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'

Ursache: getChildNode() gibt Node | null zurück. TypeScript strict mode erfordert, dass Sie den Nullfall behandeln.

Behebung:

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

Cannot find name 'GltfSaveOptions'

Ursache: GltfSaveOptions befindet sich im Unterpfadmodul @aspose/3d/formats/gltf, nicht im Paketstamm.

Fix: Import aus dem Unterpfad:

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

Speicher- und Leistungsprobleme

Prozess läuft bei großen FBX-Dateien wegen Speichermangels aus

Ursache: Sehr große FBX-Dateien (>200 MB) belegen einen erheblichen Heap. Der Standard‑Heap von Node.js beträgt auf 64‑Bit‑Systemen etwa 1,5 GB, könnte jedoch für Multi‑Scene‑Dateien nicht ausreichen.

Fix: Erhöhen Sie die Node.js-Heap-Größe:

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

Verarbeiten Sie Dateien auch sequentiell statt parallel, wenn der Speicher begrenzt ist:

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
}

Siehe auch

 Deutsch