Skapa och läsa en existerande 3D Scene

Översikt

The article explains the following topics using C# 3D file formats manipulation library.

  • Skapa en tom 3D Scene i C# från början.
  • Läs eller ladda existerande 3D Scene i C#
  • Spara 3D i format som stöds med 3D med C#
  • Arbeta med 3D Scenegenskaper i C#

Skapa ett tomt 3D och spara i stödda 3D filformat

Aspose.3D API stöder skapandet av nya 3D scener från skrängen och sparas sedan i något filformat som stöds. Utvecklare kan också ladda en befintlig 3D scen för ändring, tillägg eller bearbetning.

Skapa ett dokument i 3D @ info: whatsthis

Följ dessa steg i C# för att skapa ett 3D-dokument med Aspose. 3D API:

  1. Skapa en instans av klassen Scene som representerar ett 3D scenedokument.
  2. Skapa ett 3D Scene-dokument genom att ringa Save-metoden för Scene-objektet.
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET

// Create an object of the Scene class
Scene scene = new Scene();
// Save 3D scene document
scene.Save("document.fbx");

Läs en 3D Scene

Using Aspose.3D API, developers can load all the supported 3D documents. The available constructors of the Scene class allow to do so and they accept a valid file path string. The supported readable file formats are as follows:

  1. FBX 7.5 (ASCII, Binära)
  2. FBX 7.4 (ASCII, Binära)
  3. FBX 7.3 (ASCII, Binära)
  4. FBX 7.2 (ASCII, Binära)
  5. FBX 6.1 (ASCII, binär)
  6. STL (ASCII, binär)
  7. WavefrontOBJ
  8. Discreet3DS
  9. Universal3D
  10. Collada
  11. glTF (ASCII, binär)
  12. Maya (ASCII, binära)
  13. OpenUSD (USD, USDZ)
  14. BlenderName
  15. DXF
  16. PLY (ASCII, binär)
  17. X (ASCII, binära)
  18. Draco
  19. 3MF
  20. RVM (Text, binärt)
  21. ASE

Constructors of the Scene class detect 3D document format internally.

// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
// The path to the documents directory.

// Initialize a Scene class object
Scene scene = new Scene();
// Load an existing 3D document
scene.Open("document.fbx");

Arbetar med 3D Scenegenskaper

Aspose.3D API låter dig läsa 3D Scenegenskaper med hjälp av scenens barnnoder. Följande C# kodprov visar hur denna funktion används.

// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
Scene scene = Scene.FromFile("EmbeddedTexture.fbx");
Material material = scene.RootNode.ChildNodes[0].Material;
PropertyCollection props = material.Properties;
//List all properties using foreach
foreach (var prop in props)
{
    Console.WriteLine("{0} = {1}", prop.Name, prop.Value);
}
//or using ordinal for loop
for (int i = 0; i < props.Count; i++)
{
    var prop = props[i];
    Console.WriteLine("{0} = {1}", prop.Name, prop.Value);
}
//Get property value by name
var diffuse = props["Diffuse"];
Console.WriteLine(diffuse);
//modify property value by name
props["Diffuse"] = new Vector3(1, 0, 1);
//Get property instance by name
Property pdiffuse = props.FindProperty("Diffuse");
Console.WriteLine(pdiffuse);
//Since Property is also inherited from A3DObject
//It's possible to get the property of the property
Console.WriteLine("Property flags = {0}", pdiffuse.GetProperty("flags"));
//and some properties that only defined in FBX file:
Console.WriteLine("Label = {0}", pdiffuse.GetProperty("label"));
Console.WriteLine("Type Name = {0}", pdiffuse.GetProperty("typeName"));
//so traversal on property's property is possible
foreach (var pp in pdiffuse.Properties)
{
    Console.WriteLine("Diffuse.{0} = {1}", pp.Name, pp.Value);
}