Mega Code Archive

 
Categories / Delphi / Graphic
 

MNCadBuilder RapidCAD with Delphi (OpenGL)

Title: MNCadBuilder - RapidCAD with Delphi (OpenGL) Question: Delphi and 3D CAD development - the first steps of a solution Answer: 1. Install the MNCadBuilder --------------------------- Download the latest version (http://www.develocad.com/reg/download/mncadbuilder/mncb_lt.htm) Execute setup (e.g. D:\MNCB) When setup is finished please check "Start" - "All Programs" - "MNCadBuilder" - "Switch Libraries to" -- the Delphi version you are using. Now, the corresponding files (*.dcu; *.bpl for Win32 platforms and *.dcuil; *.dll for .NET platforms) are copied to the root folder of your MNCB installation. 2. Integrate MNCadBuilder in to Delphi (using Delphi 7) ------------------------------------------------------- Install package ("Component" - "Install packages") - Click "Add" Button, and select MNLib.bpl from the root of your MNCB folder. Now the "MNCadBuilder - 3D cad components collection" is installed. 3. First steps -------------- Create a new project. Please make sure, that the root path of your MNCB installation folder is in the search path. Start "Project" - "Options" - select folder "Directories/Conditionals" and add the MNCB folder to the "Search path" settings. Now we drag and drop a TMNOglCanvas component on to the form. TMNOglCanvas is the central component for drawing and render output. When assigning a Window control to the property WinControl, an "OpenGL render context" is created based on the Window Handle of the Window control. So, let us assign the Form (Form1) to the WinControl. We also change the BackgroundColor of the TMNOglCanvas to get a more friendly background color (maybe clCream). When we now want to draw an object in this render canvas, we can use some predefined ones. We drag and drop a TMNShape3D on to the form. Now we have to inform the MNOglCanvas that he shall draw this shape. We set the _Entity property to MNShape3D1. A click on the form (in design mode) and the MNOglCanvas is refreshing. When we set the MNOglCanvas property Navigate to TRUE, we can change the view of the MNOglCanvas at runtime (means changing the projection matrix of the canvas) . When start the project, we see the designed shape. Because of Navigate is TRUE, we can change the view by pressing the left mouse button and moving the mouse. When you additionally press the [Ctrl] key you can translate the view in X and Y. If you want a perspective view, you can change the MNOglCanvas property FieldOfView to a value 0 (e.g. 20 degree). After restarting the project you see the object in a perspective view. And now we can also translate the view in Z axis by pressing the [Shift] key, left mouse button down and moving the mouse in Y+/- direction. These were some of the first steps with the MNCadBuilder. Leopold Minikus DeveloCAD.com This is the source of the pas file: unit _Beginner1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, _MNDevice, _MNObjects3D, _MNPlatform, _MNOglCanvas; type TForm1 = class(TForm) MNOglCanvas1: TMNOglCanvas; MNShape3D1: TMNShape3D; private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} end. This is the source of the dfm file: object Form1: TForm1 Left = 350 Top = 352 Width = 736 Height = 447 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -13 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False PixelsPerInch = 120 TextHeight = 16 object MNOglCanvas1: TMNOglCanvas MNName = 'MNOglCanvas1' BackgroundColor = 15793151 Culling = True Cursor = CR_Cross DefaultLight = True DefaultPixelsPerUnit = 30.000000000000000000 FieldOfView = 20.000000000000000000 FontName = 'Modern' FontSize = 40 Lightning = True CanFocus = True WinControl = Owner ZoomFactor = 1.000000000000000000 DrawFocusRect = False Navigate = True EyeLight = True _Entity = MNShape3D1 _ProjectionBase.BaseX.x = 1.000000000000000000 _ProjectionBase.BaseY.y = 1.000000000000000000 _ProjectionBase.BaseZ.z = 1.000000000000000000 PixelsPerUnit = 30.000000000000000000 Left = 64 Top = 56 end object MNShape3D1: TMNShape3D MNName = 'MNShape3D1' CatchEnabled = True HitPriority = 0 MNBase.BaseX.x = 1.000000000000000000 MNBase.BaseY.y = 1.000000000000000000 MNBase.BaseZ.z = 1.000000000000000000 ParentAttributes = False SelectEnabled = True Visible = True _Attributes.MaterialKind = MKNone _Attributes.Material.Ambient = 4210752 _Attributes.Material.Diffuse = 6710886 _Attributes.Material.Specular = 13027014 _Attributes.Material.Emission = 0 _Attributes.Material.Shininess = 76.800000000000000000 _Attributes.Material.Translucent = 1.000000000000000000 _Attributes.PenWidth = 1 _Attributes.PenStyle = psSolid Shape = s3d_Box Length = 3.000000000000000000 Width = 3.000000000000000000 Height = 3.000000000000000000 Filled = True Left = 88 Top = 112 end end