### Apply Visual Effect on 3D View
Source: https://docs.aspose.com/3d/python-net/apply-visual-effects-on-saving-3d-views
This code example demonstrates the initial setup for applying visual effects to a 3D view. It loads a scene, configures a camera, and sets up a light source. Further steps would involve using the `Renderer`'s post-processing capabilities.
```python
from aspose import pycore
from aspose.pydrawing import Color
from aspose.pydrawing.imaging import ImageFormat
from aspose.threed import Scene
from aspose.threed.entities import Camera, Light, LightType
from aspose.threed.render import ITexture2D, RenderParameters, Renderer
from aspose.threed.utilities import RelativeRectangle, Vector3
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Load an existing 3D scene
scene = Scene("data-dir" + "scene.obj")
# Create an instance of the camera
camera = Camera()
scene.root_node.create_child_node("camera", camera).transform.translation = Vector3(2, 44, 66)
# Set the target
camera.look_at = Vector3(50, 12, 0)
light = Light()
light.color = Vector3(Color.white)
light.light_type = LightType.POINT
# Create a light
scene.root_node.create_child_node("light", light).transform.translation = Vector3(26, 57, 43)
# The CreateRenderer will create a hardware OpenGL-backend renderer, more renderer will be added in the future
# And some internal initializations will be done.
```
--------------------------------
### Install Aspose.3D for Python via .NET
Source: https://docs.aspose.com/3d/python-net/installation
Use pip to install the Aspose.3D library. This is the recommended method for adding the library to your Python environment.
```bash
pip install aspose-3d
```
--------------------------------
### Convert Non-PBR to PBR Material and Save as GLTF
Source: https://docs.aspose.com/3d/python-net/customize-non-pbr-to-pbr-materials-conversion-before-saving-3d-scenes-to-gltf-2-0-format
This example demonstrates how to initialize a 3D scene, add a box with a Phong material, and then save the scene in GLTF 2.0 format with default material conversion.
```python
import aspose.threed as a3d
from aspose.threed.utilities import Vector3
from aspose.threed.formats import FileFormat
# initialize a new 3D scene
s = a3d.Scene()
box = a3d.Box()
mat = a3d.shading.PhongMaterial()
mat.diffuse_color = Vector3(1, 0, 1)
s.root_node.create_child_node("box1", box).material = mat
opt = a3d.formats.GLTFSaveOptions(FileFormat.GLTF2);
# save in GLTF 2.0 format
s.save("test.gltf", opt);
```
--------------------------------
### Create Scene with Primitive 3D Shapes
Source: https://docs.aspose.com/3d/python-net/create-scene-with-primitive-3d-shapes
Initializes a scene, adds a box and a cylinder as child nodes, and saves the scene to an FBX file. Ensure the Aspose.3D library is installed.
```python
from aspose.threed import FileFormat, Scene
from aspose.threed.entities import Box, Cylinder
# 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 object
scene = Scene()
# Create a Box model
scene.root_node.create_child_node("box", Box())
# Create a Cylinder model
scene.root_node.create_child_node("cylinder", Cylinder())
# Save drawing in the FBX format
output = "out" + "test.fbx"
scene.save(output, FileFormat.FBX7500ASCII)
```
--------------------------------
### Query objects by type or name
Source: https://docs.aspose.com/3d/python-net/work-with-xpath-like-object-queries
This example demonstrates selecting objects that are either of type 'Camera' or have the name 'light', irrespective of their position in the scene hierarchy. It utilizes boolean OR logic within the query.
```python
from aspose.threed import Scene
from aspose.threed.entities import Camera, Light
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Create a scene for testing
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"))
/*The hierarchy of the scene looks like:
- Root
- a
- a1
- a2
- b
- c
- c1
- cam
- c2
- light
*/
# select objects that has type Camera or name is 'light' whatever it's located.
objects = s.root_node.select_objects("//*[(Type = 'Camera') or (Name = 'light')]")
```
--------------------------------
### Basic Usage of Aspose.3D for Python
Source: https://docs.aspose.com/3d/python-net/installation
Import the Aspose.3D library and create a scene with a cylinder entity, then save it to an FBX file. Ensure the library is installed before running this code.
```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)
```
--------------------------------
### Cast and Receive Shadows on 3D Geometries
Source: https://docs.aspose.com/3d/python-net/cast-and-receive-shadows-on-3d-geometries
This code example demonstrates how to set up a scene with a light source, camera, and plane, and then configure objects to cast and receive shadows. It highlights how to control shadow behavior for individual geometries.
```python
from aspose.3d import Scene, Mesh, Material, Vector3, Color, Light, Camera, Plane, Box, Torus
from aspose.3d.shading import PhongMaterial
# Create a new scene
scene = Scene()
# Create a light source
light = Light()
light.set_direction(Vector3(0.5, -1, -0.5))
scene.add_child(light)
# Create a camera
camera = Camera()
camera.set_translation(Vector3(0, 5, 10))
camera.look_at(Vector3(0, 0, 0))
scene.add_child(camera)
# Create a plane to receive shadows
plane = Plane()
plane.width = 10
plane.height = 10
plane.material = PhongMaterial()
plane.material.diffuse = Color(0.5, 0.5, 0.5)
plane.receive_shadows = True
scene.add_child(plane)
# Create a red box that casts shadows but does not receive them
red_box = Box()
red_box.translation = Vector3(-2, 1, 0)
red_box.cast_shadows = True
red_box.receive_shadows = False
red_box.material = PhongMaterial()
red_box.material.diffuse = Color(1, 0, 0)
scene.add_child(red_box)
# Create a blue box that casts and receives shadows
blue_box = Box()
blue_box.translation = Vector3(0, 1, 0)
blue_box.cast_shadows = True
blue_box.receive_shadows = True
blue_box.material = PhongMaterial()
blue_box.material.diffuse = Color(0, 0, 1)
scene.add_child(blue_box)
# Create a torus that casts shadows but does not receive them
torus = Torus()
torus.translation = Vector3(2, 1, 0)
torus.cast_shadows = True
torus.receive_shadows = False
torus.material = PhongMaterial()
torus.material.diffuse = Color(0, 1, 0)
scene.add_child(torus)
# Save the scene to a file (e.g., glTF)
scene.save("shadows_example.gltf")
print("Scene with shadows created successfully.")
```
--------------------------------
### Create a Cube Node and Scene
Source: https://docs.aspose.com/3d/python-net/create-3d-mesh-and-scene
Use this code to create a 3D scene, add a cube mesh to it, and save the scene in FBX format. Ensure the Aspose.3D library is installed.
```python
from aspose.threed import FileFormat, Node, Scene
from aspose.threed.utilities import Common
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Initialize scene object
scene = Scene()
# Initialize Node class object
cubeNode = Node("cube")
# Call Common class create mesh using polygon builder method to set mesh instance
mesh = Common.CreateMeshUsingPolygonBuilder()
# Point node to the Mesh geometry
cubeNode.entity = mesh
# Add Node to a scene
scene.root_node.child_nodes.append(cubeNode)
# The path to the documents directory.
output = "out" + "CubeScene.fbx"
# Save 3D scene in the supported file formats
scene.save(output, FileFormat.FBX7400ASCII)
```
--------------------------------
### Serve HTML file using Python's http.server
Source: https://docs.aspose.com/3d/python-net/save-3d-scene-as-html
After exporting the 3D scene to HTML, you need to serve the file through a web server due to browser security restrictions. This command starts a simple HTTP server in the current directory.
```bash
python3 -m http.server
```
--------------------------------
### Create Vertex Element Normal
Source: https://docs.aspose.com/3d/python-net/aspose-3d-document-object-model
Manually create a vertex element and assign data for it. This example demonstrates creating a VertexElementNormal.
```python
from aspose import pycore
from aspose.threed.entities import MappingMode, ReferenceMode, VertexElementNormal, VertexElementType
from aspose.threed.utilities import Vector4
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
```
--------------------------------
### Apply PBR Material to a Box
Source: https://docs.aspose.com/3d/python-net/aspose-3d-document-object-model
Applies a PBR material with metallic and roughness factors to a box geometry and saves the scene to USDZ format. Ensure the Aspose.3D library is installed.
```python
from aspose.threed import Scene
from aspose.threed.entities import Box
from aspose.threed.shading import PbrMaterial
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# initialize a scene
scene = Scene()
# initialize PBR material object
mat = PbrMaterial()
# an almost metal material
mat.metallic_factor = 0.9
# material surface is very rough
mat.roughness_factor = 0.9
# create a box to which the material will be applied
boxNode = scene.root_node.create_child_node("box", Box())
boxNode.material = mat
# save 3d scene into USDZ format
scene.save("out" + "PBR_Material_Box_Out.usdz")
```
--------------------------------
### Load 3D File and Write Meshes in Custom Binary Format
Source: https://docs.aspose.com/3d/python-net/save-3d-meshes-in-custom-binary-format
Use the `accept` method of the `root_node` in the `Scene` class to visit sub-nodes. This snippet specifically converts meshes to a custom binary format. Ensure you have the necessary Aspose.3D library installed.
```python
from aspose.threed import Scene
from aspose.threed.entities import Box
from aspose.threed.utilities import Vector3
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Load a 3D file into Aspose.3D
scene = Scene.from_file("document.fbx")
box = scene.root_node.create_child_node("box", Box()).transform
box.scale = Vector3(12, 12, 12)
box.translation = Vector3(10, 0, 0)
# Serialize the node into binary file
with open("out" + "customData", "wb") as output:
scene.root_node.accept(output, "3d")
```
--------------------------------
### Specify FBX Save Options
Source: https://docs.aspose.com/3d/python-net/specify-3d-file-save-options
Set save options before saving a 3D file to FBX format. This example configures the export of legacy material properties.
```python
from aspose.threed import FileFormat
from aspose.threed.formats import FbxSaveOptions
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# The path to the documents directory.
dataDir = "data-dir"
# Initialize an object
saveOpts = FbxSaveOptions(FileFormat.FBX7500ASCII)
# Generates legacy material properties.
saveOpts.export_legacy_material_properties = True
```
--------------------------------
### Create and Save a 3D Cylinder to PLY
Source: https://docs.aspose.com/3d/python-net/convert-mesh-of-a-single-3d-object-in-ply-file
This code example demonstrates how to create a 3D Cylinder object and encode it directly into a PLY file using the default settings.
```python
from aspose.threed import FileFormat, FileContentType
from aspose.threed.entities import Cylinder
from aspose.threed.formats import PlySaveOptions
# Create a cylinder object and save it to ply file
FileFormat.PLY.encode_mesh(Cylinder(), "cylinder.ply")
```
--------------------------------
### Create PDF with 3D Scene - Cylinder, Shaded Illustration, CAD Lighting
Source: https://docs.aspose.com/3d/python-net/save-a-3d-scene-in-the-pdf
Use the Scene.save method to export a 3D scene to PDF. This example demonstrates creating a scene with a cylinder, applying a Phong material, and setting specific PDF save options for rendering mode and lighting.
```python
from aspose.pydrawing import Color
from aspose.threed import Scene
from aspose.threed.entities import Cylinder
from aspose.threed.formats import PdfLightingScheme, PdfRenderMode, PdfSaveOptions
from aspose.threed.shading import PhongMaterial
from aspose.threed.utilities import Vector3
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Create a new scene
scene = Scene()
material = PhongMaterial()
material.diffuse_color = Vector3(Color.dark_cyan)
# Create a cylinder child node
scene.root_node.create_child_node("cylinder", Cylinder()).material = material
# Set rendering mode and lighting scheme
opt = PdfSaveOptions()
opt.lighting_scheme = PdfLightingScheme.CAD
opt.render_mode = PdfRenderMode.SHADED_ILLUSTRATION
# Save in the PDF format
scene.save("out" + "output_out.pdf", opt)
```
--------------------------------
### Select a node by name, regardless of depth
Source: https://docs.aspose.com/3d/python-net/work-with-xpath-like-object-queries
This example shows how to select a node named 'a1' directly under the root node. If the node is not a direct child, this query will still find it due to the implicit global search.
```python
obj = s.root_node.select_single_object("a1")
```
--------------------------------
### Control Linear Extrusion Detail with 'slices'
Source: https://docs.aspose.com/3d/python-net/working-with-linear-extrusion
Demonstrates how to use the 'slices' property of the LinearExtrusion class to control the number of intermediate points along the extrusion path. Higher values result in smoother extrusions but increase complexity. This example shows two extrusions with different slice counts.
```python
from aspose.threed import FileFormat, Scene
from aspose.threed.entities import LinearExtrusion
from aspose.threed.profiles import RectangleShape
from aspose.threed.utilities import Vector3
shape = RectangleShape()
shape.rounding_radius = 0.3
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Initialize the base profile to be extruded
profile = shape
# Create a scene
scene = Scene()
# Create left node
left = scene.root_node.create_child_node()
# Create right node
right = scene.root_node.create_child_node()
left.transform.translation = Vector3(15, 0, 0)
extrusion = LinearExtrusion(profile, 2)
extrusion.slices = 2
# Slices parameter defines the number of intermediate points along the path of extrusion
# Perform linear extrusion on left node using slices property
left.create_child_node(extrusion)
extrusion2 = LinearExtrusion(profile, 2)
extrusion2.slices = 10
# Perform linear extrusion on right node using slices property
right.create_child_node(extrusion2)
# Save 3D scene
scene.save("out" + "SlicesInLinearExtrusion.obj", FileFormat.WAVEFRONT_OBJ)
```
--------------------------------
### Save a 3D Scene to a Stream
Source: https://docs.aspose.com/3d/python-net/save-a-3d-document
This code snippet demonstrates how to load a 3D document and save it to a byte stream in FBX7500ASCII format. Ensure you have the Aspose.3D library installed.
```python
import aspose.threed as a3d
import io
# For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
# Load a 3D document into Aspose.3D
scene = a3d.Scene.from_file("document.fbx")
# Save Scene to a stream
dstStream = io.BytesIO()
scene.save(dstStream, a3d.FileFormat.FBX7500ASCII);
```
--------------------------------
### Apply License from File in Aspose.3D for Python
Source: https://docs.aspose.com/3d/python-net/licensing
Use this method to set a license file by placing it in the same folder as the script and specifying only the file name.
```python
import aspose.threed as a3d
# Instantiate an instance of license and set the license file through its path
license = a3d.License()
license.set_license("Aspose.3D.lic")
```
--------------------------------
### Create and Save a 3D Scene Document
Source: https://docs.aspose.com/3d/python-net/create-and-read-an-existing-3d-scene
Use this snippet to create a new 3D scene from scratch and save it in the FBX7500ASCII format. Ensure the Aspose.3D library is imported.
```python
import aspose.threed as a3d
# For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
# The path to the documents directory.
# Create an object of the Scene class
scene = a3d.Scene()
# Save 3D scene document
scene.Save("document.fbx", a3d.FileFormat.FBX7500ASCII)
```
--------------------------------
### Create Renderer and Render Targets
Source: https://docs.aspose.com/3d/python-net/capture-the-viewports-of-3d-scene-and-render-to-a-texture-or-window
Initializes a renderer and creates a cube map render target with depth, and a 2D texture render target for image processing. A viewport is required on a render target.
```python
with Renderer.create_renderer() as renderer:
# Create a cube map render target with depth texture, depth is required when rendering a scene.
rt = renderer.render_factory.create_cube_render_texture(RenderParameters(False), 512, 512)
# create a 2D texture render target with no depth texture used for image processing
final = renderer.render_factory.create_render_texture(RenderParameters(False), 32, 0), 1024 * 3, 1024)
# a viewport is required on a render target
rt.create_viewport(cam, RelativeRectangle.from_scale(0, 0, 1, 1))
```
--------------------------------
### Extract All Raw 3D Contents from PDF
Source: https://docs.aspose.com/3d/python-net/import-3d-scenes-and-contents-from-a-pdf
Utilize the FileFormat.PDF.extract method to get all raw 3D data from a PDF. Iterate through the extracted content and save each piece into a separate file.
```python
from aspose.threed import FileFormat
# For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
# The path to the documents directory.
password = None
# Extract 3D contents
contents = FileFormat.PDF.extract("data-dir" + "House_Design.pdf", password)
i = 1
# Iterate through contents and save in separate 3D files
for content in contents:
fileName = "3d-" + str(i)
i = i + 1
with open(fileName, "wb") as f:
f.write(content)
```
--------------------------------
### Encode Sphere Mesh to Google Draco File
Source: https://docs.aspose.com/3d/python-net/encoding-3d-mesh-in-the-google-draco-file
This code retrieves a Sphere mesh and encodes it into a Google Draco file with an optimal compression level. Ensure the necessary Aspose.3D library is installed.
```python
from aspose.threed import FileFormat
from aspose.threed.entities import Sphere
from aspose.threed.formats import DracoCompressionLevel, DracoSaveOptions
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Create a sphere
sphere = Sphere()
options = DracoSaveOptions()
options.compression_level = DracoCompressionLevel.OPTIMAL
# Encode the sphere to Google Draco raw data using optimal compression level.
b = FileFormat.DRACO.encode(sphere.to_mesh(), options)
# Save the raw bytes to file
with open("out" + "SphereMeshtoDRC_Out.drc", "wb") as f:
f.write(b)
```
--------------------------------
### Apply Metered License in Aspose.3D for Python
Source: https://docs.aspose.com/3d/python-net/licensing
Apply a metered license using public and private keys. This mechanism requires an internet connection for usage tracking. It also demonstrates loading a scene and saving it, showing consumption before and after API calls.
```python
import aspose.threed as a3d
# Create an instance of CAD Metered class
metered = a3d.Metered()
# Access the set_metered_key property and pass public and private keys as parameters
metered.set_metered_key("*****", "*****")
# Get metered data amount before calling API
amountbefore = a3d.metered.get_consumption_quantity()
# Display information
print("Amount Consumed Before: " + str(amountbefore))
# Load the scene from disk.
scene = a3d.Scene.from_file("3D Model.fbx")
# Save as pdf
scene.save("out_pdf.pdf", a3d.FileFormat.PDF)
# Get metered data amount After calling API
amountafter = a3d.metered.get_consumption_quantity()
# Display information
print("Amount Consumed After: " + str(amountafter))
```
--------------------------------
### Apply License from Stream in Aspose.3D for Python
Source: https://docs.aspose.com/3d/python-net/licensing
Load a license directly from a stream. Ensure the stream contains valid license data.
```python
import aspose.threed as a3d
# Instantiate an instance of license and set the license file through its path
license = a3d.License()
license.set_license(stream)
```
--------------------------------
### Create Vertex Normals in Aspose.3D
Source: https://docs.aspose.com/3d/python-net/set-up-normals-or-uv-on-the-cube-and-add-material-to-3d-entities
This snippet demonstrates how to define and assign normal vectors to a mesh's control points using `VertexElementType.NORMAL` and `MappingMode.CONTROL_POINT`. Ensure the `Common.CreateMeshUsingPolygonBuilder()` method is available in your setup.
```python
from aspose import pycore
from aspose.threed.entities import MappingMode, ReferenceMode, VertexElementNormal, VertexElementType
from aspose.threed.utilities import Vector4
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Raw normal data
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)]
# Call Common class create mesh using polygon builder method to set mesh instance
mesh = Common.CreateMeshUsingPolygonBuilder()
normal = mesh.create_element(VertexElementType.NORMAL, MappingMode.CONTROL_POINT, ReferenceMode.DIRECT)
elementNormal = pycore.as_of(normal, VertexElementNormal) if pycore.is_assignable(normal, VertexElementNormal) else None
# Copy the data to the vertex element
elementNormal.data.extend(normals)
```
--------------------------------
### Using Twist Property in Linear Extrusion
Source: https://docs.aspose.com/3d/python-net/working-with-linear-extrusion
The `twist` property controls the degree of rotation during extrusion. This example creates two extrusions, one with 0.0 twist and another with 90.0 twist, both with 100 slices.
```python
from aspose.threed import FileFormat, Scene
from aspose.threed.entities import LinearExtrusion
from aspose.threed.profiles import RectangleShape
from aspose.threed.utilities import Vector3
shape = RectangleShape()
shape.rounding_radius = 0.3
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Initialize the base profile to be extruded
profile = shape
# Create a scene
scene = Scene()
# Create left node
left = scene.root_node.create_child_node()
# Create rifht node
right = scene.root_node.create_child_node()
left.transform.translation = Vector3(15, 0, 0)
extrusion = LinearExtrusion(profile, 10)
extrusion.twist = 0.0
extrusion.slices = 100
# Twist property defines the degree of rotation while extruding the profile
# Perform linear extrusion on left node using twist and slices property
left.create_child_node(extrusion)
extrusion2 = LinearExtrusion(profile, 10)
extrusion2.twist = 90.0
extrusion2.slices = 100
# Perform linear extrusion on right node using twist and slices property
right.create_child_node(extrusion2)
# Save 3D scene
scene.save("out" + "TwistInLinearExtrusion.obj", FileFormat.WAVEFRONT_OBJ)
```
--------------------------------
### Configure OBJ Save Options
Source: https://docs.aspose.com/3d/python-net/specify-3d-file-save-options
Set options for saving to OBJ format, including enabling materials, flipping the coordinate system, configuring lookup paths, serializing the W component, and enabling verbose output.
```python
from aspose.threed.formats import ObjSaveOptions
# The path to the documents directory.
dataDir = "data-dir"
# Initialize an object
saveObjOpts = ObjSaveOptions()
# Import materials from external material library file
saveObjOpts.enable_materials = True
# Flip to coordinate system.
saveObjOpts.flip_coordinate_system = True
# Configure lookup paths to allow importer to find external dependencies.
saveObjOpts.lookup_paths = [[dataDir]]
# Serialize W component in model's vertex position
saveObjOpts.serialize_w = True
# Generate comments for each section
saveObjOpts.verbose = True
```
--------------------------------
### Render 3D Scene with Post-Processing Effects
Source: https://docs.aspose.com/3d/python-net/apply-visual-effects-on-saving-3d-views
This snippet shows how to render a 3D scene to a texture and apply various post-processing effects sequentially. It demonstrates creating a renderer, setting up a render target, applying effects like pixelation, grayscale, edge detection, and blur, and saving the output. Ensure the 'camera' object is properly initialized before use.
```python
with Renderer.create_renderer() as renderer:
renderer.enable_shadows = False
with renderer.render_factory.create_render_texture(RenderParameters(), 1, 1024, 1024) as rt:
rectangle = RelativeRectangle()
rectangle.scale_width = 1.0
rectangle.scale_height = 1.0
vp = rt.create_viewport(camera, rectangle)
renderer.render(rt)
pycore.cast(ITexture2D, rt.targets[0]).save("out" + "Original_viewport_out.png", ImageFormat.png)
pixelation = renderer.get_post_processing("pixelation")
renderer.post_processings.append(pixelation)
renderer.render(rt)
pycore.cast(ITexture2D, rt.targets[0]).save("out" + "VisualEffect_pixelation_out.png", ImageFormat.png)
grayscale = renderer.get_post_processing("grayscale")
renderer.post_processings.clear()
renderer.post_processings.append(grayscale)
renderer.render(rt)
pycore.cast(ITexture2D, rt.targets[0]).save("out" + "VisualEffect_grayscale_out.png", ImageFormat.png)
renderer.post_processings.clear()
renderer.post_processings.append(grayscale)
renderer.post_processings.append(pixelation)
renderer.render(rt)
pycore.cast(ITexture2D, rt.targets[0]).save("out" + "VisualEffect_grayscale+pixelation_out.png", ImageFormat.png)
edgedetection = renderer.get_post_processing("edge-detection")
renderer.post_processings.clear()
renderer.post_processings.append(edgedetection)
renderer.render(rt)
pycore.cast(ITexture2D, rt.targets[0]).save("out" + "VisualEffect_edgedetection_out.png", ImageFormat.png)
blur = renderer.get_post_processing("blur")
renderer.post_processings.clear()
renderer.post_processings.append(blur)
renderer.render(rt)
pycore.cast(ITexture2D, rt.targets[0]).save("out" + "VisualEffect_blur_out.png", ImageFormat.png)
```
--------------------------------
### Create and Save Rectangular Torus in Python
Source: https://docs.aspose.com/3d/python-net/create-rectangular-torus-in-3d-scene
Use the RectangularTorus class to create a parameterized torus and add it to a scene. The scene can then be saved in various 3D formats like OBJ. Ensure Aspose.3D for Python is installed.
```python
import math
from aspose.threed.entities import RectangularTorus
rt = RectangularTorus()
rt.inner_radius = 17
rt.outer_radius = 22
rt.height = 30
rt.arc = math.pi * 0.5
scene = Scene()
scene.root_node.create_child_node(rt)
scene.save("rtorus.obj", FileFormat.WAVEFRONT_OBJ)
```
--------------------------------
### Create a Sphere Primitive
Source: https://docs.aspose.com/3d/python-net/aspose-3d-document-object-model
Creates a sphere with a specified radius and adds it to a scene. The scene is then saved as a Wavefront OBJ file.
```python
from aspose.threed import FileFormat, Scene
from aspose.threed.entities import Sphere
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Create a Scene
scene = Scene()
sphere = Sphere()
sphere.radius = 10.0
# Set Sphere Radius (Using Radius property you can get or set radius of Sphere)
scene.root_node.create_child_node(sphere)
# Save scene
scene.save("data-dir" + "sphere.obj", FileFormat.WAVEFRONT_OBJ)
```
--------------------------------
### Using TwistOffset Property in Linear Extrusion
Source: https://docs.aspose.com/3d/python-net/working-with-linear-extrusion
The `twist_offset` property allows for translation while rotating the extrusion. This example shows one extrusion with a 360-degree twist and another with the same twist but an additional offset of (3, 0, 0).
```python
from aspose.threed import FileFormat, Scene
from aspose.threed.entities import LinearExtrusion
from aspose.threed.profiles import RectangleShape
from aspose.threed.utilities import Vector3
shape = RectangleShape()
shape.rounding_radius = 0.3
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Initialize the base profile to be extruded
profile = shape
# Create a scene
scene = Scene()
# Create left node
left = scene.root_node.create_child_node()
# Create right node
right = scene.root_node.create_child_node()
left.transform.translation = Vector3(18, 0, 0)
extrusion = LinearExtrusion(profile, 10)
extrusion.twist = 360.0
extrusion.slices = 100
# TwistOffset property is the translate offset while rotating the extrusion.
# Perform linear extrusion on left node using twist and slices property
left.create_child_node(extrusion)
extrusion2 = LinearExtrusion(profile, 10)
extrusion2.twist = 360.0
extrusion2.slices = 100
extrusion2.twist_offset = Vector3(3, 0, 0)
# Perform linear extrusion on right node using twist, twist offset and slices property
right.create_child_node(extrusion2)
# Save 3D scene
scene.save("out" + "TwistOffsetInLinearExtrusion.obj", FileFormat.WAVEFRONT_OBJ)
```
--------------------------------
### Render 3D Model Image from Camera
Source: https://docs.aspose.com/3d/python-net/render-3d-view-in-image-format-from-camera
Create a camera in a 3D scene, set its target, and render an image with specified options. This is useful for capturing specific views of a 3D model.
```python
from aspose.pydrawing import Color, Size
from aspose.pydrawing.imaging import ImageFormat
from aspose.threed import ImageRenderOptions, Scene
from aspose.threed.entities import Camera
from aspose.threed.utilities import Vector3
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Load scene from file
scene = Scene("data-dir" + "camera.3ds")
# Create a camera at (10,10,10) and look at the origin point for rendering,
# It must be attached to the scene before render
camera = Camera()
scene.root_node.create_child_node("camera", camera)
camera.parent_node.transform.translation = Vector3(10, 10, 10)
camera.look_at = Vector3.ORIGIN
# Specify the image render option
opt = ImageRenderOptions()
# Set the background color
opt.background_color = Color.alice_blue
# Tells renderer where the it can find textures
opt.asset_directories.append("data-dir" + "textures")
# Turn on shadow
opt.enable_shadows = True
# Render the scene in given camera's perspective into specified png file with size 1024x1024
scene.render(camera, "out" + "Render3DModelImageFromCamera.png", Size(1024, 1024), ImageFormat.png, opt)
```
--------------------------------
### Initialize Renderer and Shader for Grid in GLSL
Source: https://docs.aspose.com/3d/python-net/hardware-based-rendering-of-3d-geometry
Initializes the renderer and shader for a grid using GLSL. This code is part of a larger demo project for hardware-based rendering.
```csharp
///
/// Initialize renderer and Shader for the grid.
///
public void InitializeShader()
{
// Initialize shader
var shader = new Shader("grid.vsh", "grid.fsh");
shader.Compile();
// Initialize shader variables
var shaderVariable = new ShaderVariable();
shaderVariable.Name = "WorldViewProjection";
shaderVariable.Type = "float4x4";
shaderVariable.Semantic = "WorldViewProjection";
shader.ShaderVariables.Add(shaderVariable);
shaderVariable = new ShaderVariable();
shaderVariable.Name = "WorldLight";
shaderVariable.Type = "float4";
shaderVariable.Semantic = "WorldLight";
shader.ShaderVariables.Add(shaderVariable);
shaderVariable = new ShaderVariable();
shaderVariable.Name = "Tiling";
shaderVariable.Type = "float";
shaderVariable.Semantic = "Tiling";
shader.ShaderVariables.Add(shaderVariable);
// Initialize renderer
var renderer = new Renderer(shader);
this.Renderer = renderer;
}
```
--------------------------------
### Initialize Buffer and Render State for Grid in C#
Source: https://docs.aspose.com/3d/python-net/hardware-based-rendering-of-3d-geometry
Initializes the buffer and render state for rendering a grid. This code is part of a larger demo project for hardware-based rendering.
```csharp
///
/// Initialize buffer and Render state for the grid.
///
public void InitializeBufferAndRenderState()
{
// Initialize buffer
var buffer = new Buffer();
buffer.PrimitiveType = PrimitiveType.TriangleList;
buffer.VertexFormat = VertexFormat.Position | VertexFormat.Normal | VertexFormat.TexCoord;
buffer.Indices = new int[] { 0, 1, 2, 0, 2, 3 };
buffer.Vertices = new float[]
{
-0.5f, 0.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.5f, 0.0f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
-0.5f, 0.0f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.5f, 0.0f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f
};
this.Buffer = buffer;
// Initialize render state
var renderState = new RenderState();
renderState.CullMode = CullMode.None;
renderState.DepthTestEnabled = true;
this.RenderState = renderState;
}
```
--------------------------------
### Define Metadata for a 3D Scene
Source: https://docs.aspose.com/3d/python-net/add-an-asset-information-and-flip-coordinate-system-in-3d-formats
Initialize a 3D scene and set asset information such as application name, vendor, measurement unit, and scale factor. Save the scene in a supported file format like FBX.
```python
from aspose.threed import FileFormat, Scene
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Initialize a 3D scene
scene = Scene()
# Set application/tool name
scene.asset_info.application_name = "Egypt"
# Set application/tool vendor name
scene.asset_info.application_vendor = "Manualdesk"
# We use ancient egyption measurement unit Pole
scene.asset_info.unit_name = "pole"
# One Pole equals to 60cm
scene.asset_info.unit_scale_factor = 0.6
# The saved file
output = "out" + "InformationToScene.fbx"
# Save scene to 3D supported file formats
scene.save(output, FileFormat.FBX7500ASCII)
```
--------------------------------
### Capture Viewport and Render Scene
Source: https://docs.aspose.com/3d/python-net/capture-the-viewports-of-3d-scene-and-render-to-a-texture-or-window
This code captures a viewport of a 3D scene and sets up the scene with a camera and lights for rendering. It loads a scene from a file and configures camera properties.
```python
from aspose import pycore
from aspose.pydrawing import Color, ImageFormat
from aspose.threed import Scene
from aspose.threed.entities import Camera, Light, LightType, ProjectionType, RotationMode
from aspose.threed.render import ITexture2D, RenderParameters, Renderer
from aspose.threed.utilities import RelativeRectangle, Vector3
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# The path to the documents directory.
# load a scene
scene = Scene("data-dir" + "VirtualCity.glb")
camera = Camera(ProjectionType.PERSPECTIVE)
camera.near_plane = 0.1
camera.far_plane = 200.0
camera.rotation_mode = RotationMode.FIXED_DIRECTION
# create a camera for capturing a cube map
cam = camera
cam.transform.translation = Vector3(5, 6, 0)
# create two lights to illuminate the scene
light = Light()
light.light_type = LightType.POINT
scene.root_node.create_child_node(light).transform.translation = Vector3(-10, 7, -10)
light2 = Light()
light2.color = Vector3(Color.cadet_blue)
scene.root_node.create_child_node(light2).transform.translation = Vector3(49, 0, 49)
```
--------------------------------
### Configure RVM Load Options and Save
Source: https://docs.aspose.com/3d/python-net/specify-3d-file-load-options
Set load options for RVM files, including segments for cylinders, dishes, and tori. The loaded RVM file is then saved in OBJ format.
```python
import aspose.threed as a3d
# set load options of RVM
scene = a3d.Scene()
opt = a3d.formats.RvmLoadOptions()
opt.cylinder_radial_segments = 32
opt.dish_latitude_segments = 16
opt.dish_longitude_segments = 24
opt.torus_tubular_segments = 40
# import RVM
scene.open("LAD-TOP.rvm", opt)
# save in the OBJ format
scene.save("LAD-TOP.obj", a3d.FileFormat.WAVEFRONT_OBJ)
```
--------------------------------
### Save Dependencies in Local Directory (OBJ)
Source: https://docs.aspose.com/3d/python-net/specify-3d-file-save-options
Employ LocalFileSystem with ObjSaveOptions to save all 3D scene dependencies, such as materials, to a specified local directory. This ensures external assets are stored alongside the main file.
```python
from aspose.threed import Scene
from aspose.threed.entities import Sphere
from aspose.threed.formats import ObjSaveOptions
from aspose.threed.shading import PhongMaterial
from aspose.threed.utilities import LocalFileSystem
# The code example uses the LocalFileSystem class to save dependencies to the local directory.
dataDir = "data-dir"
# Initialize Scene object
scene = Scene()
# Create a child node
scene.root_node.create_child_node("sphere", Sphere()).material = PhongMaterial()
# Set saving options
opt = ObjSaveOptions()
opt.file_system = LocalFileSystem(dataDir)
# Save 3D scene
scene.save("out" + "SavingDependenciesInLocalDirectory_out.obj", opt)
```
--------------------------------
### Configure U3D Save Options
Source: https://docs.aspose.com/3d/python-net/specify-3d-file-save-options
Set options for saving to U3D format, including flipping the coordinate system and configuring lookup paths.
```python
from aspose.threed.formats import U3dSaveOptions
dataDir = "data-dir"
saveU3DOpts = U3dSaveOptions()
# Flip to coordinate system.
saveU3DOpts.flip_coordinate_system = True
# Configure lookup paths to allow importer to find external dependencies.
saveU3DOpts.lookup_paths = [[dataDir]]
```
--------------------------------
### Open Scene from Password Protected PDF
Source: https://docs.aspose.com/3d/python-net/import-3d-scenes-and-contents-from-a-pdf
Use the Scene.open method with PdfLoadOptions to load a 3D scene from a password-protected PDF. Ensure the password is provided correctly.
```python
from aspose.threed import Scene
from aspose.threed.formats import PdfLoadOptions
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Create a new scene
scene = Scene()
options = PdfLoadOptions()
options.password = "password".encode("utf-8")
# Use loading options and apply password
opt = options
# Open scene
scene.open("data-dir" + "House_Design.pdf", opt)
```
--------------------------------
### Set OBJ Load Options
Source: https://docs.aspose.com/3d/python-net/specify-3d-file-load-options
Customize the loading of an OBJ file by setting specific options. This includes enabling material import from external files, flipping the coordinate system, and defining lookup paths for dependencies.
```python
from aspose.threed.formats import ObjLoadOptions
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# The path to the documents directory.
dataDir = "data-dir"
# Initialize an object
loadObjOpts = ObjLoadOptions()
# Import materials from external material library file
loadObjOpts.enable_materials = True
# Flip the coordinate system.
loadObjOpts.flip_coordinate_system = True
# Configure the look up paths to allow importer to find external dependencies.
loadObjOpts.lookup_paths.append(dataDir)
```
--------------------------------
### Build Tangent and Binormal Data for a Scene
Source: https://docs.aspose.com/3d/python-net/build-tangent-and-binormal-data-for-all-meshes-in-3d-model
Load a 3D scene, build tangent and binormal data for all its meshes, and save the modified scene. Ensure the necessary Aspose.3D library is imported.
```python
from aspose.threed import FileFormat, Scene
from aspose.threed.entities import PolygonModifier
# For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
# Load an existing 3D file
scene = Scene("data-dir" + "document.fbx")
# Triangulate a scene
PolygonModifier.build_tangent_binormal(scene)
# Save 3D scene
scene.save("out" + "BuildTangentAndBinormalData_out.fbx", FileFormat.FBX7400ASCII)
```
--------------------------------
### Configure glTF Save Options
Source: https://docs.aspose.com/3d/python-net/specify-3d-file-save-options
Set options for saving to glTF format, including embedding assets, using common materials, customizing buffer file names, and saving as ASCII or binary glTF.
```python
from aspose.threed import FileContentType, FileFormat, Scene
from aspose.threed.entities import Sphere
from aspose.threed.formats import GltfSaveOptions
# Initialize Scene object
scene = Scene()
# Create a child node
scene.root_node.create_child_node("sphere", Sphere())
# Set glTF saving options. The code example embeds all assets into the target file usually a glTF file comes with some dependencies, a bin file for model's vertex/indices, two .glsl files for vertex/fragment shaders
# Use opt.EmbedAssets to tells the Aspose.3D API to export scene and embed the dependencies inside the target file.
opt = GltfSaveOptions(FileContentType.ASCII)
opt.embed_assets = True
# Use KHR_materials_common extension to define the material, thus no GLSL files are generated.
opt.use_common_materials = True
# Customize the name of the buffer file which defines model
opt.buffer_file = "mybuf.bin"
# Save GlTF file
scene.save("out" + "glTFSaveOptions_out.gltf", opt)
# Save a binary glTF file using KHR_binary_glTF extension
scene.save("out" + "glTFSaveOptions_out.glb", FileFormat.GLTF_BINARY)
# Developers may use saving options to create a binary glTF file using KHR_binary_glTF extension
opts = GltfSaveOptions(FileContentType.BINARY)
scene.save("out" + "Test_out.glb", opts)
```