Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
0.8.3:models [2021/07/21 15:57] – [TGorillaVertexGroup] admin0.8.3:models [2022/04/25 11:26] – [Instancing by TModelDef] admin
Line 21: Line 21:
 | OBJ         | ✔             | ✔                 | ✘          | ✘      | ✘       | ✘      | ✘       | ✘      |           | only ascii format| | OBJ         | ✔             | ✔                 | ✘          | ✘      | ✘       | ✘      | ✘       | ✘      |           | only ascii format|
 | STL         | ✔             |✘                   | ✘          | ✘     | ✘        | ✘      | ✘       | ✔     | 1.0       | ascii and binary format, Standard + Solidworks-Format| | STL         | ✔             |✘                   | ✘          | ✘     | ✘        | ✘      | ✘       | ✔     | 1.0       | ascii and binary format, Standard + Solidworks-Format|
-| FBX         | ✔             | ✔                 ✘          | ✘      | ✘       | ✘      | ✘       | ✘      | 7.1 - 7.5 | only binary (v0.8.3.1931+). Animation import for 7.3-7.4 validated, 7.5 not working properly yet|+| FBX         | ✔             | ✔                 ✔          | ✘      | ✘       | ✘      | ✘       | ✘      | 7.1 - 7.5 | only binary (v0.8.3.1931+). Animation import for 7.3-7.4 validated, 7.5 not working properly yet|
 | X3D         | ✔             | ✔                 | ✔         | ✘      | ✘       | ✘      | ✘       | ✘      |           | deprecated | | X3D         | ✔             | ✔                 | ✔         | ✘      | ✘       | ✘      | ✘       | ✘      |           | deprecated |
 | glTF        | ✔             |✔                  | ✘          | ✘      | ✘       | ✘      | ✘       | ✘      | 2.0       | only glTF json format, not glb| | glTF        | ✔             |✔                  | ✘          | ✘      | ✘       | ✘      | ✘       | ✘      | 2.0       | only glTF json format, not glb|
Line 108: Line 108:
  
 A TGorillaGroup is just a simple transformable element used to group sub-meshes. A group itself is not renderable. A TGorillaGroup is just a simple transformable element used to group sub-meshes. A group itself is not renderable.
-===== Loading a new model from file at runtime =====+===== Loading a models at designtime ===== 
 + 
 +Since v0.8.3.2265 Gorilla3D is able to load model in designtime editor. 
 + 
 +We provide different ways to do it. 
 + 
 +==== Loading a model from an assets package ==== 
 + 
 +In case you have already set up an assets package with the assets manager in your form, you can link a TGorillaModal to that. 
 + 
 +  - Link the TGorillaAssetsManager component to the TGorillaModel.AssetsManager property 
 +  - Type in the name of your package (DisplayName) into the "PackageName" property 
 +  - Type in the model asset name in your package into the "Source" property 
 + 
 +The IDE will show up a loading window while it's setting up the model. 
 + 
 +The framework will generate TGorillaModel data from the linked package. It will repeat to load the model when starting the application. 
 +The data is not stored again in the formular *.fmx file, it only restores it from package information. 
 + 
 +**WARNING***: Your IDE memory is limited to 3GB, which can be exceeded very fast due to cached data by the IDE. 
 + 
 +==== Loading a model from binary storage ==== 
 + 
 +It is also possible to store and load complete model data (incl. textures) from binary storage inside of your formular *.fmx file. 
 + 
 +To do so, simply: 
 +  - Open the file dialog of the "Source" property in the object inspector 
 +  - Select your model file (Please check the supported file formats) 
 +  - All model data will be stored inside the *.fmx file of your form 
 + 
 +The IDE will show up a loading window while it's setting up the model. 
 +Because the data + textures are stored in the *.fmx of your form, it can become very large. 
 +This may slow down the performance of the IDE. 
 + 
 +**WARNING***: Your IDE memory is limited to 3GB, which can be exceeded very fast due to cached data by the IDE and model data with textures. 
 + 
 +===== Loading a model from at runtime ===== 
 + 
 +Besides the user-friendly loading at runtime, we of course support the model loading from file or stream. 
 + 
 +You can also take advantage of the designtime mechanisms at runtime. 
 + 
 + 
 +==== Loading a new model from file ====
  
 Creating a model instance at runtime is very easy and often very helpful for creating dynamically loaded scenes. Creating a model instance at runtime is very easy and often very helpful for creating dynamically loaded scenes.
Line 143: Line 186:
  
 You also can ignore the AssetPckg parameter currently. We will explain assets management in the [[assetsmanager|AssetsManager]] section. You also can ignore the AssetPckg parameter currently. We will explain assets management in the [[assetsmanager|AssetsManager]] section.
-===== Loading a model from file into an existing TGorillaModel instance =====+ 
 + 
 +==== Loading into an existing TGorillaModel instance ====
  
 In case you've dragged a TGorillaModel component onto your viewport, you can load the model by the following method. In case you've dragged a TGorillaModel component onto your viewport, you can load the model by the following method.
Line 190: Line 235:
 Only then the format loader is able to load the specific file.  Only then the format loader is able to load the specific file. 
  
 +
 +==== Loading a model from package ====
 +
 +To adopt the behaviour used in the IDE at design time, you can load model data from assets package
 +also at runtime by the following method.
 +
 +<file pascal Form1.pas>
 +uses
 +  Gorilla.DefTypes,
 +  Gorilla.G3D.Loader,
 +  Gorilla.DAE.Loader,
 +  Gorilla.OBJ.Loader,
 +  Gorilla.STL.Loader,
 +  Gorilla.FBX.Loader,
 +  Gorilla.GLTF.Loader,
 +  Gorilla.Babylon.Loader,
 +  Gorilla.PLY.Loader,
 +  Gorilla.SKP.Loader,
 +  Gorilla.AssetsManager,
 +  Gorilla.Model;
 +  
 +[...]
 +
 +var FAssetsManager : TGorillaAssetsManager;
 +    FPackage : TGorillaAssetsPackage;
 +    FModel : TGorillaModel;
 +
 +// in our form (TForm1) we added a field named "FModel"
 +procedure TForm1.FormCreate(Sender: TObject);
 +begin
 +  // setup the assets manager and load an existing package from file
 +  FAssetsManager := TGorillaAssetsManager.Create(Self);
 +  FPackage := FAssetsManager.LoadPackageFromFile('C:\Temp\mypackage.zip');
 +  FPackage.DisplayName := 'MyPackage';
 +  
 +  // prepare the model for loading from package
 +  FModel := TGorillaModel.Create(GorillaViewport1);
 +  FModel.Parent := GorillaViewport1;
 +  
 +  // start linking to assets manager like at designtime
 +  FModel.AssetsManager := FAssetsManager;
 +  FModel.PackageName := 'MyPackage';
 +  FModel.Source := 'myfile.dae';
 +end;
 +</file>
 +
 +==== Loading a model from source ====
 +
 +This is another way to load model data from file at runtime.
 +The difference to //LoadFromFile()// and //LoadNewModelFromFile()// is, that it will store model data in the BinaryData property too.
 +
 +<file pascal Form1.pas>
 +uses
 +  Gorilla.DefTypes,
 +  Gorilla.G3D.Loader,
 +  Gorilla.DAE.Loader,
 +  Gorilla.OBJ.Loader,
 +  Gorilla.STL.Loader,
 +  Gorilla.FBX.Loader,
 +  Gorilla.GLTF.Loader,
 +  Gorilla.Babylon.Loader,
 +  Gorilla.PLY.Loader,
 +  Gorilla.SKP.Loader,
 +  Gorilla.AssetsManager,
 +  Gorilla.Model;
 +  
 +[...]
 +
 +var FModel : TGorillaModel;
 +
 +// in our form (TForm1) we added a field named "FModel"
 +procedure TForm1.FormCreate(Sender: TObject);
 +begin  
 +  // prepare the model for loading from package
 +  FModel := TGorillaModel.Create(GorillaViewport1);
 +  FModel.Parent := GorillaViewport1;
 +  FModel.Source := 'c:\Temp\myfile.dae';
 +end;
 +</file>
  
 ===== Instancing / Model duplication ===== ===== Instancing / Model duplication =====
 +
 +==== Instanced Rendering ====
 +
 +Since 0.8.3.2265 instanced rendering of the same mesh for x-times was implemented.
 +
 +Use this method to render for example grass or trees. It is not recommended to use it for animated charaters,
 +because they would be rendered the same (with the same animation frame).
 +
 +You can simply setup instanced rendering in your TGorillaModel or TGorillaMesh object.
 +
 +<file pascal>
 +/// we create 4 instances in a row
 +GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(-10, 0, 0)));
 +GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(-5, 0, 0)));
 +GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(5, 0, 0)));
 +GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(10, 0, 0)));
 +
 +/// afterwards we can modify a specific instance
 +var LTransf : TMatrix3D;
 +LTransf := TMatrix3D.CreateScaling(Point3D(2, 2, 2));
 +LTransf := LTransf * TMatrix3D.CreateRotationY(DegToRad(90));
 +LTransf := LTransf * TMatrix3D.CreateScaling(Point3D(2, 2, 2));
 +
 +GorillaModel1.Instances[2] := LTransf;
 +</file>
 +
 +
 +==== Instancing by TModelDef ====
  
 Since 0.8.3.1966+ we've refactored the way to instanciate models. The previous method was incomplete in handling animated models. Since 0.8.3.1966+ we've refactored the way to instanciate models. The previous method was incomplete in handling animated models.
 In the following example we show how to load a complex animated model with multiple meshes and animations. In the following example we show how to load a complex animated model with multiple meshes and animations.
-We will load up a template, which will be used for duplication. The template itself will not be rendered in our example, but of course that's possible too.+We will load up a template (TModelDef), which will be used for duplication. The template (TModelDef) itself will not be rendered in our example, but of course that's possible too.
  
 Each duplicated model will run a different animation to show instanciating is still fast, but allows to handle models differently. Each duplicated model will run a different animation to show instanciating is still fast, but allows to handle models differently.