Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/457fc4bdd1d59b3e421e29bd5a382f11 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/457fc4bdd1d59b3e421e29bd5a382f11 to your computer and use it in GitHub Desktop.
Create 3D Cylinder in Python
"""
basic_cylinder
=================
Demonstrates the simplest possible approach to Create 3D Cylinder in Python
using Aspose.3D. This covers the essential API pattern you will build upon.
"""
from aspose.threed import Scene
from aspose.threed.entities import Cylinder
# ─── Step 1: Create an empty 3D scene ─────────────────────────────────────
scene = Scene()
# ─── Step 2: Define cylinder geometry ─────────────────────────────────────
# Cylinder(radius_top, radius_bottom, height)
# All measurements are in scene units (typically meters or centimeters).
cylinder = Cylinder(
radius_top=0.5, # radius of top cap
radius_bottom=0.5, # radius of bottom cap (same → straight cylinder)
height=2.0 # total height of the cylinder
)
# ─── Step 3: Add geometry to the scene graph ──────────────────────────────
# create_child_node() adds a Node to the root and attaches the geometry.
cylinder_node = scene.root_node.create_child_node("MyCylinder", cylinder)
# ─── Step 4: Position the cylinder in world space ─────────────────────────
from aspose.threed.utilities import Vector3
cylinder_node.transform.translation = Vector3(0.0, 0.0, 0.0) # centered at origin
# ─── Step 5: Save to OBJ (Wavefront) ──────────────────────────────────────
output_path = "basic_cylinder.obj"
scene.save(output_path)
print(f"Cylinder saved to: {output_path}")
# ─── Optional: Inspect geometry stats ─────────────────────────────────────
print(f" Radius (top): {cylinder.radius_top}")
print(f" Radius (bottom): {cylinder.radius_bottom}")
print(f" Height: {cylinder.height}")
print(f" Radial segments: {cylinder.radial_segments}")
import os
from aspose.threed import Scene, FileFormat
from aspose.threed.entities import Cylinder
# Build scene
scene = Scene()
cylinder = Cylinder(
radius_top=0.5, # radius of top cap
radius_bottom=0.5, # radius of bottom cap (same → straight cylinder)
height=2.0 # total height of the cylinder
)
scene.root_node.create_child_node("MyCylinder", cylinder)
os.makedirs("output", exist_ok=True)
# OBJ — universal, no special format descriptor needed
scene.save("output/cylinder.obj")
print("OBJ exported")
# STL — standard for 3D printing workflows
scene.save("output/cylinder.stl")
print("STL exported")
# FBX ASCII — readable text format for debugging
scene.save("output/cylinder_ascii.fbx", FileFormat.FBX6100ASCII)
print("FBX ASCII exported")
# FBX Binary — compact format for production pipelines
scene.save("output/cylinder_binary.fbx", FileFormat.FBX6100_BINARY)
print("FBX Binary exported")
# glTF — modern format for web and AR/VR
scene.save("output/cylinder.gltf")
print("glTF exported")
# GLB — binary glTF, single self-contained file
scene.save("output/cylinder.glb")
print("GLB exported")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment