TypeScript에서 3D 모델을 최적화하는 방법

TypeScript에서 3D 모델을 최적화하는 방법

Aspose.3D FOSS for TypeScript는 출력 파일 크기를 줄이고 처리 전환을 향상시키기위한 여러 전략을 제공합니다.이 가이드에는 형식 선택, 바이너리 삽입, 메모리 내 파이프라인 및 Node.js 수준의 최적화가 포함됩니다.

단계별 가이드

단계 1: 올바른 출력 형식을 선택합니다.

GLB (비나리 glTF)는 좋은 도구 지원을 가진 가장 컴팩트한 출력을 생산합니다.OBJ는 텍스트 기반이며 더 크습니다.STL은 지질학-직업 흐름만을 위한 컴파일입니다.

형식크기포함된 재료애니메이션 포함최고의 사용
GLB작은예 (이제 흥분된)예 예웹, 게임, 일반 교환
GSTF중간분리된 것 ( Separate )예 예개발, 검사
STL작은아니오아니오3D printing, geometry-only
OBJ분리 .mtl아니오유산 도구, 광범위한 호환성
FBX중간아니오*아니오*수입자/수출자는 존재하지만 자동 탐지에 연결되지 않습니다.
3MF작은예 예아니오현대 3D 인쇄

단계 2: 바이너리 GLB에 대한 수출

GLB에 저축 할 때, 설정 GltfSaveOptions.binaryMode = true 단일 자체 콘텐츠 바이너리 파일을 생성합니다.이를 방지하는 것은 분리 된 파일입니다. .bin 측면 및 많은 3D 시청자에게 필요합니다 :

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

const scene = new Scene();
scene.open('complex-model.obj', new ObjLoadOptions());

const opts = new GltfSaveOptions();
opts.binaryMode = true;

scene.save('optimized.glb', opts);
console.log('Saved compact binary GLB');

단계 3: In-Memory 파이프를 위한 Buffer I/O 사용

웹 서비스에서 파일을 처리할 때, 사용하기 openFromBuffer 그리고 saveToBuffer 파일 시스템에 글을 쓰지 않도록 하려면:

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

function convertInMemory(inputBuffer: Buffer): Buffer {
    const scene = new Scene();
    scene.openFromBuffer(inputBuffer, new ObjLoadOptions());
    return scene.saveToBuffer('glb');
}

단계 4: 노동자 위협을 가진 배치 프로세스 파일

대형 변환 작업을 위해, Node.js 노동자 스트레드를 통해 작업이 분배하여 여러 CPU 코어를 사용합니다 :

// worker.ts
import { workerData, parentPort } from 'worker_threads';
import { Scene } from '@aspose/3d';
import { ObjLoadOptions } from '@aspose/3d/formats/obj';

const { inputPath, outputPath } = workerData;

const scene = new Scene();
scene.open(inputPath, new ObjLoadOptions());
scene.save(outputPath);

parentPort?.postMessage({ done: true, output: outputPath });
// main.ts: dispatch files to workers
import { Worker } from 'worker_threads';
import * as fs from 'fs';
import * as path from 'path';

const files = fs.readdirSync('./input').filter(f => f.endsWith('.obj'));

for (const file of files) {
    const inputPath = path.join('./input', file);
    const outputPath = path.join('./output', file.replace('.obj', '.glb'));

    const worker = new Worker('./dist/worker.js', {
        workerData: { inputPath, outputPath }
    });

    worker.on('message', msg => console.log(`Converted: ${msg.output}`));
    worker.on('error', err => console.error(`Error: ${err}`));
}

5단계 : 큰 모델의 메모리 모니터링

50MB 이상의 파일에서는 메모리가 제한된 경우 헤프 사용을 모니터링하고 세속적으로 파일 처리합니다.:

function logMemory(label: string) {
    const used = process.memoryUsage();
    console.log(`[${label}] heapUsed: ${Math.round(used.heapUsed / 1024 / 1024)} MB`);
}

logMemory('before load');
const scene = new Scene();
scene.open('large-model.obj');
logMemory('after load');
scene.save('output.glb');
logMemory('after save');

매우 큰 모델에 대한 Node.js 을 증가시킵니다 :

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

자주 묻는 질문들

가장 컴팩트한 출력 형식은 무엇입니까?

GLB (비나리 glTF)는 내장된 자산으로 재료와 구조를 가진 장면에 가장 컴팩트한 단일 파일 출력을 생산합니다. STL은 지질만 콘텐츠에 더 컴파일입니다.

@aspose/3d는 메쉬 단순화 또는 LOD를 적용합니까?

No. 도서관은 메쉬 토폴리오를 수정하지 않고 출처 지질학을 읽고 쓰지 않습니다. 메시 단순화 (버텍스 감소, LOD 생성)는 지원되지 않습니다.

파일 크기를 줄이기 위해 재료를 스트립 할 수 있습니까?

세트 ObjSaveOptions.enableMaterials = false GLTF에 대한 모든 자료 데이터는 항상 포함되어 있습니다; STL을 사용하여 지질적 유일한 출력.


또한 보기

 한국어