Leitfaden zur Fehlerbehebung

Leitfaden zur Fehlerbehebung

Diese Seite behandelt die häufigsten Fehler bei der Verwendung von @aspose/3d in TypeScript- und Node.js-Projekten, mit Ursachenerklärungen und verifizierten Korrekturen.


Modul-Auflösungsfehler

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

Ursache: Die Modul-Auflösungsstrategie von TypeScript unterstützt keine Subpath-Exporte im Node.js-Stil (exports in der package.json) außer in den Fällen, in denen die moduleResolution ist auf: node oder node16.

Behebung:Set: Einheitliche Anordnung der moduleResolution zu . "node" in Ihrem tsconfig.json:

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

Wenn Sie TypeScript 5.x mit "module": "node16" oder "module": "nodenext", Verwendung "moduleResolution": "node16" - Das ist nicht wahr.


SyntaxError: Cannot use import statement in a module

Ursache:Das kompilierte JavaScript wird mit: require() Semantik, aber die Ausgabe enthält ES-Modul import Syntax; dies geschieht, wenn module ist auf: es2020 oder esnext Aber die Node.js-Laufzeit erwartet CommonJS.

Behebung:Verwendung: "module": "commonjs" in der tsconfig.json und die kompilierte .js Dateien mit node direkt:

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

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:

asposefoss/3d is not yet published — build from source until it ships. See the project README for build instructions.

Die Installation überprüfen:

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

Leere Szene nach dem Laden

Die Szene ist voll, aber… rootNode.childNodes ist leer.

Ursache (1):Das Dateifort wird alle Geometrie direkt auf die rootNode.entity Dies ist bei Single-Mesh STL Dateien ü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}`);

Behebung: Durchlauf ab: scene.rootNode sich selbst, nicht nur ihre 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 Pfad der Datei ist falsch oder die Datenbestandstärke beträgt null Bytes. Überprüfen Sie, ob die Datenbestandsbestände vor dem Aufruf nicht leer sind 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}`);

Die Liste der Materialien ist nach OBJ-Ladezeit leer.

Ursache: Die Materialladung ist standardmäßig in der ObjLoadOptions.Die Bibliothek lädt die Geometrie ohne das Lesen der .mtl Die Seite-File.

Behebung:Set: Einheitliche Anordnung der 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);

Die Kommission hat die .mtl Die Datei befindet sich im gleichen Verzeichnis wie die .obj Die Bibliothek ist in der Lage, die Daten zu verarbeiten. .obj Weg.


Format- und E/A-Fehler

openFromBuffer Wirft einen nicht erkannten Formatfehler ab

Ursache: Der Pufferinhalt ist kein erkennbares binäres Format oder der Pufer ist beschädigt (abgeschnitten, falsche Codierung oder base64 statt Rohbyte).

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: Bei Textformaten (OBJ, COLLADA) wird die entsprechende Optionsklasse übergeben, um das Format anzuzeigen:

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

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

Ursache: GltfSaveOptions.binaryMode Ausfall der false, produziert .gltf JSON-Ausgabe auch wenn der Ausgangsdateiname ist: .glb.

Behebung: explizit festgelegt binaryMode = true:

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

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

STL-Ausgabe hat keine Farb- oder Materialdaten im Slicer.

Ursache:Das STL-Format unterstützt weder Materialien noch Farben in seiner Standardspezifikation. @aspose/3d.

Behebung: Exportieren Sie stattdessen auf 3MF, das Farb- und Materialmetadaten unterstützt:

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

Fehler bei der TypScript-Kompilierung

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

Ursache: Entity ist die Basisklasse; Mesh ist der Betontyp mit geometrischen Eigenschaften. Sie brauchen eine instanceof Schutz vor dem Zugriff auf maschenspezifische Teile.

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() Rückgabe Node | null. TypScript-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 ist im Sub-Path Modul, @aspose/3d/formats/gltf, nicht die Wurzel des Pakets.

Behebung: Import aus dem Teilweg:

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

Probleme mit dem Gedächtnis und der Leistungsfähigkeit

Prozess läuft ohne Speicher mit großen FBX-Dateien

Ursache: Sehr große FBX-Dateien (> 200 MB) weisen einen erheblichen Heap auf. Node.js Standardheap beträgt bei 64-Bit Systemen ~1,5 GB, reicht aber für Multi-Szenendateier möglicherweise nicht aus.

Behebung:Erhöhen Sie die Node.js-Heapgröße:

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

Auch Dateien sequenziell und nicht parallel verarbeiten, wenn der Speicher eingeschränkt 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