Aspose.3D FOSS for .NET은 일곱 가지 3D 파일 형식을 지원합니다: OBJ, STL, glTF, GLB, FBX, Collada, 및 3MF. 이 게시물은 각 형식을 로드하고 저장하는 방법, 사용 가능한 옵션, 그리고 형식 간 변환 방법을 보여주는 실용적인 형식별 가이드입니다.

모든 예제는 Aspose.ThreeD 네임스페이스를 사용합니다:

using Aspose.ThreeD;
using Aspose.ThreeD.Formats;

NuGet 패키지:

dotnet add package Aspose.3D --version 26.1.0

OBJ (Wavefront)

OBJ는 메쉬 기하학을 위한 널리 지원되는 텍스트 기반 형식입니다. Aspose.3D FOSS는 OBJ 파일을 해당 companion .mtl 재질 파일과 함께 로드합니다.

OBJ 로드

var scene = new Scene();
scene.Open("model.obj");

Console.WriteLine("Nodes: " + scene.RootNode.ChildNodes.Count);

옵션을 사용한 로드

var opts = new ObjLoadOptions();
// Configure loading behavior as needed
var scene = new Scene();
scene.Open("model.obj", opts);

OBJ로 저장

var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);

scene.Save("output.obj");

OBJ 저장 옵션과 함께

var opts = new ObjSaveOptions();
scene.Save("output.obj", opts);

STL (스테레오리소그래피)

STL은 3D 프린팅을 위한 표준 형식입니다. 재료나 계층 구조 없이 원시 삼각형 기하학을 저장합니다. Aspose.3D FOSS는 바이너리와 ASCII STL을 모두 지원합니다.

STL 로드

var scene = new Scene();
scene.Open("part.stl");

Console.WriteLine("Nodes: " + scene.RootNode.ChildNodes.Count);

STL로 저장

var scene = new Scene();
var sphere = new Entities.Sphere(1);
scene.RootNode.CreateChildNode("SphereNode", sphere);

scene.Save("output.stl");

저장 옵션이 있는 STL

var opts = new StlSaveOptions();
// Control binary mode, scale, and coordinate flipping
scene.Save("output.stl", opts);

STL 라운드 트립

// Load an STL file and re-save it -- geometry is preserved
var scene = new Scene();
scene.Open("original.stl");
scene.Save("copy.stl");

glTF 2.0 및 GLB

glTF는 웹 및 실시간 3D를 위한 최신 표준입니다. PBR 재질, 전체 씬 계층 구조, 그리고 효율적인 바이너리 패킹(GLB)을 지원합니다.

glTF 로드

var scene = new Scene();
scene.Open("model.gltf");

옵션을 사용한 로드

var opts = new GltfLoadOptions();
var scene = new Scene();
scene.Open("model.gltf", opts);

glTF로 저장

var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);

scene.Save("output.gltf");

GLB (Binary glTF) 형식으로 저장

자체 포함된 바이너리 .glb 파일을 만들려면 .glb 확장자를 사용하여 저장하십시오. 라이브러리는 확장자를 기반으로 바이너리 glTF 형식을 추론합니다:

scene.Save("output.glb");

FBX (Filmbox)

FBX는 게임 개발 및 디지털 콘텐츠 제작에 널리 사용됩니다. Aspose.3D FOSS for .NET은 FBX 가져오기 및 내보내기를 지원합니다. Export는 바이너리 FBX를 생성합니다; ASCII FBX export 코드는 소스에 존재하지만 이 버전의 export 경로에서는 호출되지 않습니다. FbxSaveOptions 클래스는 기본 설정을 제공합니다.

FBX 로드

var scene = new Scene();
scene.Open("model.fbx");

옵션을 사용한 로드

var opts = new FbxLoadOptions();
var scene = new Scene();
scene.Open("model.fbx", opts);

FBX로 저장

var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);

// FBX export always produces binary FBX output
scene.Save("output.fbx");

옵션을 사용한 저장

// Use FbxSaveOptions for format-specific defaults
var opts = new FbxSaveOptions();
scene.Save("output.fbx", opts);

3MF (3D 제조 형식)

3MF는 3MF Consortium에서 개발한 최신 3D 프린팅 형식입니다. 단일 ZIP 기반 패키지에서 풍부한 메타데이터, 재료 및 다중 객체 장면을 지원합니다.

3MF 로드

var scene = new Scene();
scene.Open("model.3mf");

옵션을 사용한 로드

var opts = new TmfLoadOptions();
var scene = new Scene();
scene.Open("model.3mf", opts);

3MF로 저장

var scene = new Scene();
var box = new Entities.Box(2, 2, 2);
scene.RootNode.CreateChildNode("BoxNode", box);

scene.Save("output.3mf");

옵션을 사용한 저장

var opts = new TmfSaveOptions();
scene.Save("output.3mf", opts);

스트림 기반 I/O

모든 형식은 스트림에서 로드하고 스트림에 저장하는 것을 지원하며, 이는 웹 서비스 및 클라우드 처리에 유용합니다:

using var stream = File.OpenRead("model.obj");
var scene = new Scene();
var opts = new ObjLoadOptions();
scene.Open(stream, opts);

// Save to a memory stream
using var output = new MemoryStream();
var saveOpts = new GltfSaveOptions();
scene.Save(output, saveOpts);

형식 감지

라이브러리는 파일 확장자 또는 스트림 콘텐츠를 통해 형식을 자동 감지할 수 있습니다:

// Auto-detect from extension
var scene = new Scene();
scene.Open("model.obj");  // Detects OBJ from .obj extension

// Auto-detect from stream content
using var stream = File.OpenRead("model.obj");
scene.Open(stream);  // Inspects stream content to determine format

배치 변환

여러 파일을 변환하려면 디렉터리를 순회하며 각각을 변환합니다:

using Aspose.ThreeD;
using Aspose.ThreeD.Formats;

var inputDir = "assets/";
var outputDir = "converted/";

foreach (var file in Directory.GetFiles(inputDir, "*.fbx"))
{
    var scene = new Scene();
    scene.Open(file);

    var outputPath = Path.Combine(outputDir,
        Path.GetFileNameWithoutExtension(file) + ".glb");

    scene.Save(outputPath);
    Console.WriteLine("Converted: " + file);
}

형식 비교

기능OBJSTLglTFFBX3MF
재료MTL아니오PBR
장면 계층 구조아니오아니오
애니메이션 스텁아니오아니오아니오
바이너리 모드아니오GLBZIP
3D 프린팅 준비제한됨아니오아니오
웹 전달아니오아니오아니오아니오

요약

Aspose.3D FOSS for .NET은 모든 주요 3D 파일 형식을 다루는 단일하고 일관된 API를 제공합니다. 패턴은 항상 동일합니다: Scene을 생성하고, Open()을 호출하여 로드하고, 선택적으로 형식별 옵션을 구성한 다음, Save()을 호출하여 내보냅니다. 형식 감지, 스트림 기반 I/O 및 배치 변환을 통해 .NET 파이프라인에 쉽게 통합할 수 있습니다.

자세한 내용은: