AB4D Forum
Creating an Extrusion Programatically - Printable Version

+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: Ab3d.PowerToys (https://forum.ab4d.com/forumdisplay.php?fid=9)
+--- Thread: Creating an Extrusion Programatically (/showthread.php?tid=4197)



Creating an Extrusion Programatically - Madaxe - 05-18-2020

I want to create an extrusion 120mm x 40mm x 2345.56mm

i was able to build a simple cube but i cant control the length of the extrusion, extrusion vector acts oddly i can step it up 1 unit at a time but if i do big changes i see the length changing in odd lengths

private void CreateExtrudedModel()
        {
            Vector3D extrudeVector=new Vector3D(0,1, 0); // Length and Direction Of Extrusion
            Vector3D shapeYVector3D= new Vector3D(1, 0, 0); //Extrusion Vector
            Vector3D modelOffset = new Vector3D(0, 0, 0); //Offset in Coordinate Space X , Y Z

            Point Point1 = new Point(0,0);
            Point Point2 = new Point(0,10);
            Point Point3 = new Point(10,10);
            Point Point4 = new Point(10,0);

            List<Point> centeredShapePositions = new List<Point>() { Point1, Point2, Point3, Point4 };
            try
            {
                
                MeshGeometry3D extrudedMesh = Mesh3DFactory.CreateExtrudedMeshGeometry(centeredShapePositions,
                                                                                       true,
                                                                                       modelOffset,
                                                                                       extrudeVector,
                                                                                       shapeYVector3D,
                                                                                       ExtrudeTextureCoordinatesGenerationType.Cylindrical);
                
                CreateGeometryModel(extrudedMesh);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error extruding shape:\r\n" + ex.Message);
            }
        }

        private void CreateGeometryModel(MeshGeometry3D meshGeometry3D)
        {
            GeometryModel3D ShownMode = new GeometryModel3D();
            ShownMode.Material = this._standardMaterial;
            ShownMode.Geometry = meshGeometry3D;
            ObjectsGroup.Children.Clear();
            ObjectsGroup.Children.Add(ShownMode);
        }


RE: Creating an Extrusion Programatically - Madaxe - 05-18-2020

so i found this methd, but some of our stuff is non orthagonal how do i create a box from a given point along a vector 

Point3D CenterPosition = new Point3D(0,20,0);
                Size3D CubeSize = new Size3D(140, 40, 5000); //width x heigth x length
                BoxMesh3D BoxMesh3D = new BoxMesh3D(CenterPosition, CubeSize, 5, 5, 5);


RE: Creating an Extrusion Programatically - abenedik - 05-19-2020

Hm, what do you mean by "extrusion vector acts oddly i can step it up 1 unit at a time but if i do big changes i see the length changing in odd lengths"?

If you set the extrudeVector to new Vector3D(0,123.456, 0), then the created mesh will have SizeX: 10.00, SizeY: 123.456, SizeZ: 10.00. This is correct.

Note that if you rotate the extrudeVector, then you also need to rotate the shapeYVector3D. Those two vectors define 2 axes for the extruded mesh (the third axis can be calculated with doing a vector cross product between those two vectors).


The BoxMesh3D and BoxVisual3D will always create an axis-aligned box. You can apply a transformation to them to rotate them.

If you want to create a box from a start 3D position to an end 3D position, you can also use the TubeLineMesh3D and TubeLineVisual3D - by default this will create a cylinder but you can set the Segments to 4 and this will create a 4 sided cylinder - a box.


RE: Creating an Extrusion Programatically - Madaxe - 05-19-2020

Thanks for the reply, how do a do an axis to axis transformation or apply a transformation matrix


RE: Creating an Extrusion Programatically - abenedik - 05-20-2020

To apply a transformation you need to set the Transform property. You can set it to a TranslateTransform3D, ScaleTransform3D, RotateTransform3D, MatrixTransform3D or Transform3DGroup.

Search the internet for more information or check the "Basic WPF 3D objects tutorial" sample that comes with the Ab3d.PowerToys samples project.