Cylinder object in the current version of Ab3d.PowerToys is always pointing up.
But you can use TubeVisual3D that allows you to specify the "height direction".
Usually TubeVisual3D also renders the inner tube. But you can set the InnerRadius to 0 and this will remove the inner tube and produce a cylinder.
For example:
Code:
var startPosition = new Point3D(1, -3, 2);
var endPosition = new Point3D(3, 7, 5);
Vector3D tubeDirection = endPosition - startPosition;
var tubeVisual3D = new TubeVisual3D()
{
BottomCenterPosition = startPosition,
HeightDirection = tubeDirection,
Height = tubeDirection.Length,
InnerRadius = 0,
OuterRadius = 4,
Material = new DiffuseMaterial(Brushes.Green)
};
MainViewport.Children.Add(tubeVisual3D);
If you need to get MeshGeometry or GeometryModel3D (instead of Visual3D), you can use Ab3d.Meshes.TubeMesh3D.
When checking the code for Tube I have seen that even when the InnerRadius is set to 0, the positions and triangles for the inner tube are still generated. In most cases this should not be a problem. But anyway, I will improve the code so that in case when InnerRadius is set to 0 a simple cylinder will be generated without the inner tube.
EDIT:
Another option that creates more optimal cylinder (without inner tube positions and triangles) is to use LatheMesh3D. LatheMesh3D is used to create lathe objects that are created with rotating the specified segments around an axis - each segment specifies a radius and an offset. A typical lathe mesh is a vase - different offsets from bottom have different radius.
A cylinder is a very simple lathe object with only two segments and where both segments have the same radius.
The following code can be used to create cylinder with LatheMesh3D:
Code:
var startPosition = new Point3D(1, -3, 2);
var endPosition = new Point3D(3, 7, 5);
double radius = 4;
var sections = new Ab3d.Meshes.LatheSection[2];
sections[0] = new Ab3d.Meshes.LatheSection(0, radius, true);
sections[1] = new Ab3d.Meshes.LatheSection(1, radius, true);
var latheMesh3D = new Ab3d.Meshes.LatheMesh3D(startPosition, endPosition, sections,
segments: 30, // this can be adjusted to create lower or higher detailed cylinder
isStartPositionClosed: true,
isEndPositionClosed: true,
generateTextureCoordinates: true);
var cylinderGeometry = latheMesh3D.Geometry;
var material = new DiffuseMaterial(Brushes.Green);
var model3D = new GeometryModel3D(cylinderGeometry, material);
var visual3D = new ModelVisual3D()
{
Content = model3D
};
MainViewport.Children.Add(visual3D);