DGL
https://delphigl.com/forum/

class troubles again
https://delphigl.com/forum/viewtopic.php?f=19&t=7358
Seite 1 von 1

Autor:  noeska [ Do Mär 27, 2008 20:22 ]
Betreff des Beitrags:  class troubles again

Brushing up the new version of gl3ds i encounter some problems.

Basic setup is like this:
TBaseModel
and derived from that are
TGLModel
T3dsModel

TBaseMesh
and derived fromt that is
TGLMesh

TBaseModel contains an array of TBaseMesh

Now i get problems when rendering because TGLMesh is never used.

A model is created like this
var
mymodel: TBaseModel;

mymodel := TGLModel.Create();

mymodel.loadfromfile('name.3ds');

Here internally the needed class is used for loading (in this case T3dsModel) and the properties are copied to the on TGLModel based object.

So far so good.

Even mymodel.render can be called.

The problems arrise when the meshes are called. T3dsModel (and TBaseModel) has no knowledge of TGLMesh and thus create TBaseMesh objects. As an end result the mesh cannot be rendered. Not even by typecasting. As an hack the override on the render procedure can be removed in TGLMesh and things work again by using a typecast in TGLModel.render when rendering meshes.

What can i do so that when mymodel is created as an TGLModel the meshes are created as TGLMesh and not as TBaseMesh. The problem with that is that i do not want to put knowledge of TGLMesh in TBaseModel or T3dsModel.

E.g. can i pass a class of TGLMesh to an property of TBaseModel then i could use that for creating the proper object. But how do i store that as i do not want knowledge of TGLMesh in TBaseModel. Oh wait i may store that in an class of TBaseMesh. ... (typing a message sometimes make you get ideas on how to solve the problem)

Autor:  Lord Horazont [ Do Mär 27, 2008 20:29 ]
Betreff des Beitrags: 

Yes, I think to pass a class of TBaseMesh to the loading function would be the nicest way to solve this.
I use this technique at different places and it is a very well working solution if your class structure is well defined, so that there is no problem when calling the different methods from a instance of TGLMesh which is declared as TBaseMesh.

greetings Lord Horazont

Autor:  noeska [ Do Mär 27, 2008 20:57 ]
Betreff des Beitrags: 

yes it also works in reality. Now i can clean up some more. Also this now opens the possibility of using a TDXModel and TDXMesh or TGL20Model or TGL15Model.
For the moment i stored in a property. Your solution as to only pass it when needed is also apealing. But it can be a hassle passing it along different procedures involved in loading and parsing 3d formats.

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/