### Install Aspose.3D for Python via .NET Source: https://github.com/aspose-3d/aspose.3d-for-python-via-.net/blob/main/README.md Install the library using pip. This command is used to add the Aspose.3D package to your Python environment. ```bash pip install aspose-3d ``` -------------------------------- ### Setup Camera with Target Node and Export Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Set up a camera attached to a node and aimed at a target node. Exports the scene to 3DS format. ```python from aspose.threed import Scene from aspose.threed.entities import Camera from aspose.threed.utilities import Vector3 scene = Scene() camera_node = scene.root_node.create_child_node("camera", Camera()) camera_node.transform.translation = Vector3(100, 20, 0) # Camera looks at a target node target_node = scene.root_node.create_child_node("target") camera_node.entity.cast(Camera).target = target_node scene.save("output/camera-test.3ds") ``` -------------------------------- ### Export to PDF with Lighting and Render Mode Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Export a 3D scene to a PDF file, customizing the lighting scheme and render mode for presentation. This example demonstrates creating a simple cylinder with a specific material and then saving it to PDF. ```python from aspose.threed import Scene from aspose.threed.entities import Cylinder from aspose.threed.shading import PhongMaterial from aspose.threed.formats import PdfSaveOptions, PdfLightingScheme, PdfRenderMode from aspose.threed.utilities import Vector3 scene = Scene() mat = PhongMaterial() mat.diffuse_color = Vector3(0, 0.3, 0.56) scene.root_node.create_child_node("cylinder", Cylinder()).material = mat opt = PdfSaveOptions() opt.lighting_scheme = PdfLightingScheme.CAD opt.render_mode = PdfRenderMode.SHADED_ILLUSTRATION scene.save("output/output_out.pdf", opt) ``` -------------------------------- ### Create and Save an Empty 3D Document Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Create an empty 3D scene using the Scene class and save it to an FBX file. This is useful for starting a new 3D project from scratch. ```python import aspose.threed as a3d # Create an empty 3D scene and save as FBX scene = a3d.Scene() scene.save("document.fbx") # Output: an empty .fbx file on disk ``` -------------------------------- ### Export to Compressed AMF Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Build a scene with multiple objects, including boxes with transformations, and save it as a compressed AMF file. This example showcases scene construction and saving to the AMF format. ```python from aspose.threed import Scene from aspose.threed.entities import Box from aspose.threed.utilities import Vector3 scene = Scene() box = Box() tr = scene.root_node.create_child_node(box).transform tr.scale = Vector3(12, 12, 12) tr.translation = Vector3(10, 0, 0) tr2 = scene.root_node.create_child_node(box).transform tr2.scale = Vector3(5, 5, 5) tr2.euler_angles = Vector3(50, 10, 0) scene.root_node.create_child_node().create_child_node(box) scene.save("output/Aspose.amf") ``` -------------------------------- ### Scene: Open an Existing 3D File Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Shows how to load an existing 3D file from disk into a Scene object using either the `open()` method or the `from_file()` factory method. ```APIDOC ## Scene: Open an Existing 3D File ### Description Loads an existing 3D file from disk. ### Method ```python import aspose.threed as a3d # Method 1: open into existing Scene instance scene = a3d.Scene() scene.open("input/document.fbx") # Method 2: factory method (reads RVM + companion ATT attributes) scene = a3d.Scene.from_file("input/att-test.rvm") a3d.FileFormat.RVM_BINARY.load_attributes(scene, "input/att-test.att", "rvm:") print("Scene loaded, ready for processing.") ``` ``` -------------------------------- ### Scene: Export to PDF with Lighting and Render Mode Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Demonstrates exporting a 3D scene directly to a PDF file, with options to configure lighting and render mode. ```APIDOC ## Scene: Export to PDF with Lighting and Render Mode ### Description Saves a 3D scene directly to an Adobe PDF file with configurable lighting and render mode. ### Method ```python from aspose.threed import Scene from aspose.threed.entities import Cylinder from aspose.threed.shading import PhongMaterial from aspose.threed.formats import PdfSaveOptions, PdfLightingScheme, PdfRenderMode from aspose.threed.utilities import Vector3 scene = Scene() mat = PhongMaterial() mat.diffuse_color = Vector3(0, 0.3, 0.56) scene.root_node.create_child_node("cylinder", Cylinder()).material = mat opt = PdfSaveOptions() opt.lighting_scheme = PdfLightingScheme.CAD opt.render_mode = PdfRenderMode.SHADED_ILLUSTRATION scene.save("output/output_out.pdf", opt) ``` ``` -------------------------------- ### Scene: Create and Save an Empty 3D Document Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Demonstrates how to create a new, empty 3D scene and save it to an FBX file. ```APIDOC ## Scene: Create and Save an Empty 3D Document ### Description Creates an empty 3D scene and saves it to a file. ### Method ```python import aspose.threed as a3d # Create an empty 3D scene and save as FBX scene = a3d.Scene() scene.save("document.fbx") # Output: an empty .fbx file on disk ``` ``` -------------------------------- ### Scene: Save to File or Stream with Format Options Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Illustrates saving a scene to a file path or a binary stream, with options to specify the file format and compression. ```APIDOC ## Scene: Save to File or Stream with Format Options ### Description Saves a scene to a file path or a binary stream, with options for format and compression. ### Method ```python import io import aspose.threed as a3d from aspose.threed.formats import FbxSaveOptions scene = a3d.Scene() scene.open("input/document.fbx") # Save to a BytesIO stream stream = io.BytesIO() scene.save(stream, a3d.FileFormat.FBX7500ASCII) # Save to file without compression opt = FbxSaveOptions(a3d.FileFormat.FBX7500ASCII) opt.enable_compression = False scene.save("output/UncompressedDocument.fbx", opt) ``` ``` -------------------------------- ### Apply Node Transformations using Euler Angles, Quaternion, or Matrix Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Demonstrates rotating and translating a node using three different transformation approaches: Euler angles, Quaternions, and Transformation matrices. Ensure the output directory exists before saving. ```python from aspose.threed import Scene, Node from aspose.threed.entities import Box from aspose.threed.utilities import Vector3, Quaternion, Matrix4 mesh = Box().to_mesh() scene = Scene() # 1. Euler angles node_euler = Node("euler") node_euler.entity = mesh node_euler.transform.euler_angles = Vector3(0.3, 0.1, -0.5) node_euler.transform.translation = Vector3(0, 0, 0) scene.root_node.child_nodes.append(node_euler) # 2. Quaternion node_quat = Node("quaternion") node_quat.entity = mesh node_quat.transform.rotation = Quaternion.from_rotation(Vector3(0, 1, 0), Vector3(0.3, 0.5, 0.1)) node_quat.transform.translation = Vector3(20, 0, 0) scene.root_node.child_nodes.append(node_quat) # 3. Transformation matrix node_mat = Node("matrix") node_mat.entity = mesh node_mat.transform.transform_matrix = Matrix4( 1, -0.3, 0, 0, 0.4, 1, 0.3, 0, 0, 0, 1, 0, 0, 20, 0, 1 ) scene.root_node.child_nodes.append(node_mat) scene.save("output/Transformations.fbx") ``` -------------------------------- ### Scene: Export to Compressed AMF Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Shows how to build a multi-object scene and save it as a compressed AMF file. ```APIDOC ## Scene: Export to Compressed AMF ### Description Builds a multi-object scene and saves it as a compressed AMF file. ### Method ```python from aspose.threed import Scene from aspose.threed.entities import Box from aspose.threed.utilities import Vector3 scene = Scene() box = Box() tr = scene.root_node.create_child_node(box).transform tr.scale = Vector3(12, 12, 12) tr.translation = Vector3(10, 0, 0) tr2 = scene.root_node.create_child_node(box).transform tr2.scale = Vector3(5, 5, 5) tr2.euler_angles = Vector3(50, 10, 0) scene.root_node.create_child_node().create_child_node(box) scene.save("output/Aspose.amf") ``` ``` -------------------------------- ### Open an Existing 3D File Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Load an existing 3D file into a Scene instance using either the open() method or the Scene.from_file() factory method. The from_file() method can also load companion attributes for specific formats like RVM. ```python import aspose.threed as a3d # Method 1: open into existing Scene instance scene = a3d.Scene() scene.open("input/document.fbx") # Method 2: factory method (reads RVM + companion ATT attributes) scene = a3d.Scene.from_file("input/att-test.rvm") a3d.FileFormat.RVM_BINARY.load_attributes(scene, "input/att-test.att", "rvm:") print("Scene loaded, ready for processing.") ``` -------------------------------- ### Apply PBR Material to a Mesh Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Uses PbrMaterial for physically-based rendering with metallic/roughness workflow. Ensure the output directory exists before saving. ```python from aspose.threed import Scene from aspose.threed.entities import Box from aspose.threed.shading import PbrMaterial scene = Scene() mat = PbrMaterial() mat.metallic_factor = 0.9 # near-metal surface mat.roughness_factor = 0.9 # very rough surface box_node = scene.root_node.create_child_node("box", Box()) box_node.material = mat scene.save("output/PBR_Material_Box_Out.stl") ``` -------------------------------- ### Set Up Vertex Normals on a Mesh Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Create a vertex normal element on a mesh and populate it with per-control-point normal vectors. Ensure the VertexElementType is NORMAL and MappingMode is CONTROL_POINT. ```python from aspose.threed import Scene from aspose.threed.entities import Box, VertexElementType, MappingMode, ReferenceMode, VertexElementNormal from aspose.threed.utilities import Vector4 normals = [ Vector4(-0.577350258, -0.577350258, 0.577350258, 1.0), Vector4( 0.577350258, -0.577350258, 0.577350258, 1.0), Vector4( 0.577350258, 0.577350258, 0.577350258, 1.0), Vector4(-0.577350258, 0.577350258, 0.577350258, 1.0), Vector4(-0.577350258, -0.577350258, -0.577350258, 1.0), Vector4( 0.577350258, -0.577350258, -0.577350258, 1.0), Vector4( 0.577350258, 0.577350258, -0.577350258, 1.0), Vector4(-0.577350258, 0.577350258, -0.577350258, 1.0), ] mesh = Box().to_mesh() element_normal = mesh.create_element( VertexElementType.NORMAL, MappingMode.CONTROL_POINT, ReferenceMode.DIRECT ).cast(VertexElementNormal) element_normal.data.add_range(normals) scene = Scene() scene.root_node.create_child_node(mesh) scene.save("output/NormalsOnCube.fbx") ``` -------------------------------- ### Create and Save a 3D Scene with a Cylinder Source: https://github.com/aspose-3d/aspose.3d-for-python-via-.net/blob/main/README.md This Python code snippet demonstrates how to initialize a 3D scene, add a cylinder entity to it, and save the scene to an FBX file. Ensure the aspose-3d library is imported. ```python import aspose.threed as a3d scene = a3d.Scene() scene.root_node.create_child_node(a3d.entities.Cylinder()) scene.save("Cylinder.fbx", a3d.FileFormat.FBX7400ASCII) ``` -------------------------------- ### Primitive Models: Box and Cylinder Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Demonstrates creating primitive 3D models like Box, Cylinder, and Sphere and adding them as named child nodes to a scene. ```APIDOC ## Primitive Models: Box and Cylinder ### Description Creates primitive 3D models (Box, Cylinder, Sphere, Torus) and adds them directly to a scene as named child nodes. ### Method ```python from aspose.threed import Scene from aspose.threed.entities import Box, Cylinder, Sphere scene = Scene() # Add primitive shapes as named nodes scene.root_node.create_child_node("box", Box()) scene.root_node.create_child_node("cylinder", Cylinder()) scene.root_node.create_child_node("sphere", Sphere()) scene.save("output/Primitives.fbx") print("Scene with Box, Cylinder, and Sphere saved.") ``` ``` -------------------------------- ### Apply Phong and Lambert Materials with Textures Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Attaches a PhongMaterial with an embedded texture and specular properties to a mesh node. Ensure the 'data/aspose-logo.jpg' file exists and the output directory is created. ```python from aspose.threed import Scene, Node from aspose.threed.entities import Box from aspose.threed.shading import PhongMaterial, Texture from aspose.threed.utilities import Vector3 scene = Scene() node = Node("cube") node.entity = Box().to_mesh() scene.root_node.child_nodes.append(node) mat = PhongMaterial() tex = Texture() # Load texture content from file and embed it in the FBX with open("data/aspose-logo.jpg", "rb") as f: tex.content = f.read() tex.file_name = "embedded-texture.png" mat.set_texture("DiffuseColor", tex) mat.specular_color = Vector3(1, 0, 0) mat.shininess = 100 node.material = mat scene.save("output/MaterialToCube.fbx") ``` -------------------------------- ### Scene: Set Asset Information Metadata Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Explains how to attach authoring metadata, such as application name, vendor, and measurement units, to a 3D scene. ```APIDOC ## Scene: Set Asset Information Metadata ### Description Attaches authoring metadata (application name, vendor, measurement units) to a 3D scene. ### Method ```python import aspose.threed as a3d scene = a3d.Scene() scene.asset_info.application_name = "MyApp" scene.asset_info.application_vendor = "MyCompany" scene.asset_info.unit_name = "meter" scene.asset_info.unit_scale_factor = 1.0 scene.save("output/InformationToScene.fbx") ``` ``` -------------------------------- ### Save to File or Stream with Format Options Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Save a 3D scene to a file path or a binary stream, with options to specify the file format and compression. This allows for fine-grained control over the output file. ```python import io import aspose.threed as a3d from aspose.threed.formats import FbxSaveOptions scene = a3d.Scene() scene.open("input/document.fbx") # Save to a BytesIO stream stream = io.BytesIO() scene.save(stream, a3d.FileFormat.FBX7500ASCII) # Save to file without compression opt = FbxSaveOptions(a3d.FileFormat.FBX7500ASCII) opt.enable_compression = False scene.save("output/UncompressedDocument.fbx", opt) ``` -------------------------------- ### Create Cylinder with Partial Arc (Fan Cylinder) Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Create a cylinder with a fan opening (partial arc) by setting `generate_fan_cylinder` and `theta_length`. Demonstrates both fan and non-fan cylinder creation. ```python from aspose.threed import Scene from aspose.threed.entities import Cylinder from aspose.threed.utilities import MathUtils, Vector3 scene = Scene() # Fan cylinder: 270-degree arc with fan cap fan = Cylinder(2, 2, 10, 20, 1, False) fan.generate_fan_cylinder = True fan.theta_length = MathUtils.to_radian(270) scene.root_node.create_child_node(fan).transform.translation = Vector3(10, 0, 0) # Non-fan cylinder: open arc without cap nonfan = Cylinder(2, 2, 10, 20, 1, False) nonfan.generate_fan_cylinder = False nonfan.theta_length = MathUtils.to_radian(270) scene.root_node.create_child_node(nonfan) scene.save("output/CreateFanCylinder.obj") ``` -------------------------------- ### Export Scene as Point Cloud Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Export a 3D scene as a point cloud by setting the `point_cloud` option to `True`. This strips the topological structure from the exported file. ```python from aspose.threed import Scene from aspose.threed.entities import Sphere from aspose.threed.formats import ObjSaveOptions scene = Scene(Sphere()) opt = ObjSaveOptions() opt.point_cloud = True scene.save("output/Export3DSceneAsPointCloud.obj", opt) ``` -------------------------------- ### Set Asset Information Metadata Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Attach authoring metadata, such as application name, vendor, and measurement units, to a 3D scene before saving. This is useful for tracking the origin and properties of 3D assets. ```python import aspose.threed as a3d scene = a3d.Scene() scene.asset_info.application_name = "MyApp" scene.asset_info.application_vendor = "MyCompany" scene.asset_info.unit_name = "meter" scene.asset_info.unit_scale_factor = 1.0 scene.save("output/InformationToScene.fbx") ``` -------------------------------- ### Create Primitive Models: Box, Cylinder, and Sphere Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Create and add primitive 3D shapes like Box, Cylinder, and Sphere as named child nodes to a scene. This is a fundamental step for building 3D models programmatically. ```python from aspose.threed import Scene from aspose.threed.entities import Box, Cylinder, Sphere scene = Scene() # Add primitive shapes as named nodes scene.root_node.create_child_node("box", Box()) scene.root_node.create_child_node("cylinder", Cylinder()) scene.root_node.create_child_node("sphere", Sphere()) scene.save("output/Primitives.fbx") print("Scene with Box, Cylinder, and Sphere saved.") ``` -------------------------------- ### Query Scene Objects with XPath-Style Expressions Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Select nodes and entities from a scene hierarchy using XPath-like query expressions. Supports selecting by type, name, or a combination of conditions. ```python from aspose.threed import Scene from aspose.threed.entities import Camera, Light s = Scene() a = s.root_node.create_child_node("a") a.create_child_node("a1") a.create_child_node("a2") s.root_node.create_child_node("b") c = s.root_node.create_child_node("c") c.create_child_node("c1").add_entity(Camera("cam")) c.create_child_node("c2").add_entity(Light("light")) # Select all Camera entities OR nodes named 'light' anywhere in the tree objects = s.root_node.select_objects("#*[(@Type = 'Camera') or (@Name = 'light')]") print(f"Found {len(objects)} matching objects.") # Select a single Camera under /c/*/ cam_node = s.root_node.select_single_object("/c/*/") # Select node named 'a1' anywhere under root (not necessarily a direct child) a1_node = s.root_node.select_single_object("a1") ``` -------------------------------- ### Inspect and Traverse Material Properties Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Enumerate all properties of a material, retrieve a specific property by name, and access its sub-properties. Requires loading a scene from a file. ```python from aspose.threed import Scene scene = Scene("data/EmbeddedTexture.fbx") material = scene.root_node.child_nodes[0].material # List all top-level properties for prop in material.properties: print(f"{prop.name} = {prop.value}") # Get a specific property and inspect its metadata diffuse = material.properties.find_property("Diffuse") print(f"Diffuse flags = {diffuse.get_property('flags')}") print(f"Diffuse label = {diffuse.get_property('label')}") # Traverse sub-properties of 'Diffuse' for sub in diffuse.properties: print(f"Diffuse.{sub.name} = {sub.value}") ``` -------------------------------- ### Convert Non-PBR to PBR on GLTF Export Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt When saving to GLTF 2.0, Aspose.3D automatically converts Phong/Lambert materials to PBR. Ensure the output directory exists before saving. ```python from aspose.threed import Scene, FileFormat from aspose.threed.entities import Box from aspose.threed.shading import PhongMaterial from aspose.threed.formats import GltfSaveOptions from aspose.threed.utilities import Vector3 scene = Scene() mat = PhongMaterial() mat.diffuse_color = Vector3(1, 0, 1) scene.root_node.create_child_node("box1", Box()).material = mat opt = GltfSaveOptions(FileFormat.GLTF2) scene.save("output/Non_PBRtoPBRMaterial_Out.gltf", opt) ``` -------------------------------- ### Embed Texture from PIL Image into Lambert Material Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Generates texture content in-memory using Pillow and embeds it in a Lambert-material FBX file. Ensure the output directory exists before saving. ```python import io import aspose.threed as a3d from aspose.threed.shading import Texture, LambertMaterial, Material from aspose.threed.entities import Torus from PIL import Image, ImageDraw # Generate PNG texture in memory image = Image.new("RGB", (256, 32), "grey") ImageDraw.Draw(image).text((10, 10), "Aspose.3D", fill="yellow") buf = io.BytesIO() image.save(buf, format="JPEG") # Attach embedded texture to material scene = a3d.Scene() tex = Texture() tex.content = buf.getvalue() tex.file_name = "label.jpg" mat = LambertMaterial("my-mat") mat.set_texture(Material.MAP_DIFFUSE, tex) mat.set_property("MyProp", 1.0) scene.root_node.create_child_node(Torus()).material = mat scene.save("output/EmbeddedTexture.fbx") ``` -------------------------------- ### Split a Mesh by Material Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Split a single mesh into sub-meshes based on per-polygon material indices. Use `SplitMeshPolicy.CLONE_DATA` to clone control-point data or `SplitMeshPolicy.COMPACT_DATA` for non-shared data. ```python from aspose.threed.entities import ( Box, VertexElementType, MappingMode, ReferenceMode, VertexElementMaterial, SplitMeshPolicy, PolygonModifier ) mesh = Box().to_mesh() mat_elem = mesh.create_element( VertexElementType.MATERIAL, MappingMode.POLYGON, ReferenceMode.INDEX ).cast(VertexElementMaterial) # Assign a different material index to each of the 6 planes mat_elem.indices.add_range([0, 1, 2, 3, 4, 5]) # Split into 6 sub-meshes (one per material), cloning control-point data planes_6 = PolygonModifier.split_mesh(mesh, SplitMeshPolicy.CLONE_DATA) mat_elem.indices.clear() mat_elem.indices.add_range([0, 0, 0, 1, 1, 1]) # Split into 2 sub-meshes with compact (non-shared) control-point data planes_2 = PolygonModifier.split_mesh(mesh, SplitMeshPolicy.COMPACT_DATA) print(f"Split into {len(planes_6)} and {len(planes_2)} sub-meshes.") ``` -------------------------------- ### Create Node Hierarchy with Shared Mesh Geometry Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Builds a parent-child node hierarchy where multiple nodes share the same mesh geometry instance, each with independent transforms and materials. Ensure the output directory exists before saving. ```python from aspose.threed import Scene from aspose.threed.entities import Box from aspose.threed.shading import LambertMaterial from aspose.threed.utilities import Vector3, Quaternion import math scene = Scene() # Shared mesh used by all child nodes mesh = Box().to_mesh() colors = [Vector3(1, 0, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)] top = scene.root_node.create_child_node() top.transform.rotation = Quaternion.from_euler_angle(math.pi, 4, 0) for i, color in enumerate(colors): node = top.create_child_node(f"cube{i}") node.entity = mesh # shared geometry mat = LambertMaterial() mat.diffuse_color = color node.material = mat node.transform.translation = Vector3(i * 20, 0, 0) scene.save("output/NodeHierarchy.fbx") ``` -------------------------------- ### Flip Coordinate System on Load/Save Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Load a 3DS file and re-save it as OBJ. The library automatically flips the coordinate system (Y-up to Z-up) during this process. A confirmation message is printed to the console. ```python from aspose.threed import Scene scene = Scene.from_file("data/camera.3ds") scene.save("output/FlipCoordinateSystem.obj") print("Coordinate system flipped and exported to OBJ.") ``` -------------------------------- ### FileFormat: Detect Format of a 3D File Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Provides a method to detect the file format of a 3D file without loading the entire scene. ```APIDOC ## FileFormat: Detect Format of a 3D File ### Description Detects the file format of a 3D file without loading the full scene. ### Method ```python from aspose.threed import FileFormat fmt = FileFormat.detect("input/document.fbx") print(f"File Format: {fmt}") # Output: File Format: FBX binary (FBX7400Binary or similar) ``` ``` -------------------------------- ### Detect Format of a 3D File Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Determine the file format of a 3D file using the FileFormat.detect() method without loading the entire scene. This is useful for validating file types or routing files to appropriate processors. ```python from aspose.threed import FileFormat fmt = FileFormat.detect("input/document.fbx") print(f"File Format: {fmt}") # Output: File Format: FBX binary (FBX7400Binary or similar) ``` -------------------------------- ### Add Keyframe Animation to a Node Property Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Animate a node's translation property on the X and Z axes using BindPoint and KeyframeSequence. Supports different interpolation types. ```python from aspose.threed import Scene from aspose.threed.animation import BindPoint, KeyframeSequence, Interpolation from aspose.threed.entities import Box scene = Scene() mesh = Box().to_mesh() cube1 = scene.root_node.create_child_node("cube1", mesh) # Bind animation to the Translation property translation = cube1.transform.find_property("Translation") bind_point = BindPoint(scene, translation) # Animate X: 10 → 20 → 30 over 5 seconds seq_x = KeyframeSequence() seq_x.add(0, 10.0, Interpolation.BEZIER) seq_x.add(3, 20.0, Interpolation.BEZIER) seq_x.add(5, 30.0, Interpolation.LINEAR) bind_point.bind_keyframe_sequence("X", seq_x) # Animate Z: 10 → -10 → 0 over 5 seconds seq_z = KeyframeSequence() seq_z.add(0, 10.0, Interpolation.BEZIER) seq_z.add(3, -10.0, Interpolation.BEZIER) seq_z.add(5, 0.0, Interpolation.LINEAR) bind_point.bind_keyframe_sequence("Z", seq_z) scene.save("output/PropertyToDocument.fbx") ``` -------------------------------- ### Linear Extrusion with Twist Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Extrude a 2D profile along the Z axis with twist rotation applied over the extrusion height. Shows extrusion with and without twist. ```python from aspose.threed import Scene from aspose.threed.profiles import RectangleShape from aspose.threed.entities import LinearExtrusion from aspose.threed.utilities import Vector3 scene = Scene() profile = RectangleShape() profile.rounding_radius = 0.3 left = scene.root_node.create_child_node() left.transform.translation = Vector3(15, 0, 0) # No twist extrusion_straight = LinearExtrusion(profile, 10) extrusion_straight.twist = 0 extrusion_straight.slices = 100 left.create_child_node(extrusion_straight) ``` -------------------------------- ### Encode Mesh to Google Draco Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Compress a mesh to Google Draco (`.drc`) binary format with configurable compression level. Use `DracoSaveOptions` to set the desired `compression_level`. ```python from aspose.threed import FileFormat from aspose.threed.entities import Sphere from aspose.threed.formats import DracoSaveOptions, DracoCompressionLevel sphere = Sphere() opt = DracoSaveOptions() opt.compression_level = DracoCompressionLevel.OPTIMAL raw_bytes = FileFormat.DRACO.encode(sphere.to_mesh(), opt) with open("output/SphereMeshtoDRC_Out.drc", "wb") as f: f.write(raw_bytes) ``` -------------------------------- ### Build Tangent and Binormal Data Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Generate tangent and binormal vectors for all meshes in a scene using `PolygonModifier.build_tangent_binormal()`. This data is essential for normal-mapped rendering. ```python from aspose.threed import Scene from aspose.threed.entities import PolygonModifier scene = Scene("input/document.fbx") PolygonModifier.build_tangent_binormal(scene) scene.save("output/BuildTangentAndBinormalData_out.fbx") ``` -------------------------------- ### Convert Primitive to Mesh Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Convert any primitive entity (Sphere, Cylinder, Box, etc.) to an explicit `Mesh` object using the `.to_mesh()` method. This allows for more detailed mesh manipulation. ```python from aspose.threed import Scene, Node from aspose.threed.entities import Sphere scene = Scene() node = Node("sphere") node.entity = Sphere().to_mesh() # convert Sphere primitive to explicit Mesh scene.root_node.child_nodes.append(node) scene.save("output/SphereToMeshScene.fbx") print("Sphere primitive converted to Mesh and saved.") ``` -------------------------------- ### Apply 90-degree twist to Linear Extrusion Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt This snippet demonstrates how to apply a 90-degree twist to a linear extrusion along its axis. Ensure the scene object is properly initialized before use. ```python right = scene.root_node.create_child_node() extrusion_twist = LinearExtrusion(profile, 10) extrusion_twist.twist = 90 extrusion_twist.slices = 100 right.create_child_node(extrusion_twist) scene.save("output/TwistInLinearExtrusion.obj") ``` -------------------------------- ### Triangulate a Scene Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Convert all polygonal faces in a scene to triangles using `PolygonModifier.triangulate()`. This is often a necessary step for compatibility with certain rendering engines or export formats. ```python from aspose.threed import Scene from aspose.threed.entities import PolygonModifier scene = Scene("input/document.fbx") PolygonModifier.triangulate(scene) scene.save("output/triangulated_out.fbx") ``` -------------------------------- ### Generate UV Coordinates for a Mesh Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Manually generate UV coordinates for a mesh that has no UV data using `PolygonModifier.generate_uv()`. This is useful for meshes that were created without UV mapping. ```python from aspose.threed import Scene from aspose.threed.entities import Box, VertexElementType, PolygonModifier scene = Scene() mesh = Box().to_mesh() # Remove the built-in UV element (simulate a mesh without UV data) mesh.vertex_elements.remove(mesh.get_element(VertexElementType.UV)) # Generate new UV and attach to mesh uv = PolygonModifier.generate_uv(mesh) mesh.add_element(uv) scene.root_node.create_child_node(mesh) scene.save("output/GeneratedUV.obj") ``` -------------------------------- ### Encode Mesh to Draco Point Cloud Source: https://context7.com/aspose-3d/aspose.3d-for-python-via-.net/llms.txt Encode a sphere mesh directly to a Draco point cloud file using the `FileFormat.DRACO.encode()` method. The third argument for scene options can be set to `None` if not needed. ```python from aspose.threed import FileFormat from aspose.threed.entities import Sphere FileFormat.DRACO.encode(Sphere(), "output/sphere.drc", None) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.