Hi,
How can I create a class to draw a grid by TGLCylinder or pipe ? I want this grid is an object and it is not created by lines. I want this object to be specified in the scene with a name so that it is known by clicking on any part like the standard objects. Help me please.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you want can construct your own object with others glscene objects you must herited your object from TGLCustomSceneObject else your object will no be display.
forwhat you want to do and a more concrete sample take look at the code in units GLGizmo.pas and for a bit more complicated GLGizmoEX you'll see how each part a drawn from GLScene's object You can also take a look at this https://sourceforge.net/p/glscene/discussion/93606/thread/44c2c3b7/2f3b/attachment/glfreeformex.pas on how to make your own object from TGLFreeForm
Last edit: Jerome.D (BeanzMaster) 2018-01-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But there are some problems about rendering and initialization :
1-Is my code correct?
2- I do not know which function to use for rendering. This function exists in the GLscene.pas:
procedure Render(var ARci: TGLRenderContextInfo);
or
procedure Render(baseObject: TGLBaseSceneObject = nil); override;
Should I apply this function exactly? whitout any change?
3- and about Initialization too
Last edit: Mostafa 2018-01-20
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok first at first time remove RegisterClass(['TMyGrid']); not need, it's just form glscene editor in ide.
2nd you need create TGLZCylinder whatelse you 'll never show there
MyGrid_X[index] := TGLCylinder.Create
and don't forget to free all cylinder in a destructor Destruct
Take a look more deeply in GLGizmo Unit see how each part is construct and how the object can be rendered. All the answer are in
Last edit: Jerome.D (BeanzMaster) 2018-01-20
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thank you Jerome,
I did a simple job to better understanding, I derived a class from one of the GLscene classes, for example:
type
TMyGLPipe = class(TGLPipe)
end;
I used this class in my program and I plotted the pipe with TMyGLPipe class easily. I saved the scene. But when I try to reload the file by GLScene.LoadFromFile, I encounter the following error:
Class TMyGLPipe Not found,
Can you help me to find out what the solution to this problem is?
Last edit: Mostafa 2018-02-08
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Mostafa, it's normal it's a new object you need override some function. But
1st : Don't forget to register your new object in source\designtim\GLSceneRegister.Pas
Add your unit in uses
find where objects are registered and add
rebuild GLScene Package to take in charge your new object. Normally it will be work
If you have added your own properties, it will possible you'll must add "Store" keyword after property myvalue:integer read FMyValue write FMyValue Store IsMyValueStored
Last edit: Jerome.D (BeanzMaster) 2018-02-09
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
How can I create a class to draw a grid by TGLCylinder or pipe ? I want this grid is an object and it is not created by lines. I want this object to be specified in the scene with a name so that it is known by clicking on any part like the standard objects. Help me please.
Hi, from sratch :
Last edit: Jerome.D (BeanzMaster) 2018-01-10
Thank you Jerome.D,
Give me more explanation please ,
or
If there is an example here, please give me.
If you want can construct your own object with others glscene objects you must herited your object from TGLCustomSceneObject else your object will no be display.
forwhat you want to do and a more concrete sample take look at the code in units GLGizmo.pas and for a bit more complicated GLGizmoEX you'll see how each part a drawn from GLScene's object You can also take a look at this https://sourceforge.net/p/glscene/discussion/93606/thread/44c2c3b7/2f3b/attachment/glfreeformex.pas on how to make your own object from TGLFreeForm
Last edit: Jerome.D (BeanzMaster) 2018-01-18
Hi,
I tried to write the following code:
type
TMyGrid = Class(TGLCustomSceneObject)
private
TMyGrid : array of TGLCylinder;
FSizeX, FSizeY, FStepX, FStepY : single ;
x_pos,y_pos,z_pos : single;
protected
procedure SetPosition(X,Y,Z:single);
procedure SetDimension(X_Size,Y_Size:single);
procedure SetRowNum(R_Num:Integer);
procedure SetColNum(C_Num:Integer);
// procedure InitGrid;
procedure DrawMyGrid;
public
End;
var
Form1: TForm1;
implementation
{$R *.dfm}
{TMyGrid}
procedure TMyGrid.SetPosition(X,Y,Z:single);
begin
x_pos:=X;
y_pos:=Y;
z_pos:=z;
end;
procedure TMyGrid.SetDimension(X_Size: Single; Y_Size: Single);
begin
FSizeX:=X_Size;
FSizeY:=Y_Size;
end;
procedure TMyGrid.SetRowNum(R_Num: Integer);
begin
if R_Num<1 then
R_Num:=2;
FStepY:=FSizeY/R_Num;
if FStepY=0 then
FStepY:=2;
end;
procedure TMyGrid.SetColNum(C_Num: Integer);
begin
if C_Num<1 then
C_Num:=2;
FStepX:=FSizeX/C_Num;
if FStepX=0 then
FStepX:=2;
end;
procedure Tmygrid.DrawMyGrid;
begin
SetLength(MyGrid_X,1);
MyGrid_X[0].Position.x:=x_pos;
MyGrid_X[0].Position.y:=y_pos;
MyGrid_X[0].Position.z:=z_pos;
MyGrid_X[0].TopRadius:=0.5;
MyGrid_X[0].Bottomradius:=0.5;
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
But there are some problems about rendering and initialization :
1-Is my code correct?
2- I do not know which function to use for rendering. This function exists in the GLscene.pas:
procedure Render(var ARci: TGLRenderContextInfo);
or
procedure Render(baseObject: TGLBaseSceneObject = nil); override;
Should I apply this function exactly? whitout any change?
3- and about Initialization too
Last edit: Mostafa 2018-01-20
Ok first at first time remove RegisterClass(['TMyGrid']); not need, it's just form glscene editor in ide.
2nd you need create TGLZCylinder whatelse you 'll never show there
MyGrid_X[index] := TGLCylinder.Create
and don't forget to free all cylinder in a destructor Destruct
Take a look more deeply in GLGizmo Unit see how each part is construct and how the object can be rendered. All the answer are in
Last edit: Jerome.D (BeanzMaster) 2018-01-20
thank you Jerome,
I did a simple job to better understanding, I derived a class from one of the GLscene classes, for example:
type
TMyGLPipe = class(TGLPipe)
end;
I used this class in my program and I plotted the pipe with TMyGLPipe class easily. I saved the scene. But when I try to reload the file by GLScene.LoadFromFile, I encounter the following error:
Class TMyGLPipe Not found,
Can you help me to find out what the solution to this problem is?
Last edit: Mostafa 2018-02-08
Hi Mostafa, it's normal it's a new object you need override some function. But
1st : Don't forget to register your new object in source\designtim\GLSceneRegister.Pas
Add your unit in uses
find where objects are registered and add
rebuild GLScene Package to take in charge your new object. Normally it will be work
If you have added your own properties, it will possible you'll must add "Store" keyword after
property myvalue:integer read FMyValue write FMyValue Store IsMyValueStoredLast edit: Jerome.D (BeanzMaster) 2018-02-09
An another thing you must also override procedure assign and call the inherited in.