Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
0.8.3:models [2022/04/08 13:33] – [Loading a model from at runtime] admin | 0.8.3:models [2022/04/25 11:26] (current) – [Instancing by TModelDef] admin | ||
---|---|---|---|
Line 21: | Line 21: | ||
| OBJ | ✔ | ✔ | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ | | only ascii format| | | OBJ | ✔ | ✔ | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ | | only ascii format| | ||
| STL | ✔ | | STL | ✔ | ||
- | | FBX | ✔ | ✔ | + | | FBX | ✔ | ✔ |
| X3D | ✔ | ✔ | ✔ | ✘ | ✘ | ✘ | ✘ | ✘ | | deprecated | | | X3D | ✔ | ✔ | ✔ | ✘ | ✘ | ✘ | ✘ | ✘ | | deprecated | | ||
| glTF | ✔ | | glTF | ✔ | ||
Line 149: | Line 149: | ||
You can also take advantage of the designtime mechanisms at runtime. | You can also take advantage of the designtime mechanisms at runtime. | ||
+ | |||
+ | |||
==== Loading a new model from file ==== | ==== Loading a new model from file ==== | ||
Line 186: | Line 188: | ||
- | ==== Loading | + | ==== 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 233: | 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 " | ||
+ | procedure TForm1.FormCreate(Sender: | ||
+ | begin | ||
+ | // setup the assets manager and load an existing package from file | ||
+ | FAssetsManager := TGorillaAssetsManager.Create(Self); | ||
+ | FPackage := FAssetsManager.LoadPackageFromFile(' | ||
+ | FPackage.DisplayName := ' | ||
+ | | ||
+ | // 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 := ' | ||
+ | FModel.Source := ' | ||
+ | end; | ||
+ | </ | ||
+ | |||
+ | ==== Loading a model from source ==== | ||
+ | |||
+ | This is another way to load model data from file at runtime. | ||
+ | The difference to // | ||
+ | |||
+ | <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 " | ||
+ | procedure TForm1.FormCreate(Sender: | ||
+ | begin | ||
+ | // prepare the model for loading from package | ||
+ | FModel := TGorillaModel.Create(GorillaViewport1); | ||
+ | FModel.Parent := GorillaViewport1; | ||
+ | FModel.Source := ' | ||
+ | end; | ||
+ | </ | ||
===== 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, | ||
+ | GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(-5, | ||
+ | GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(5, | ||
+ | GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(10, | ||
+ | |||
+ | /// afterwards we can modify a specific instance | ||
+ | var LTransf : TMatrix3D; | ||
+ | LTransf := TMatrix3D.CreateScaling(Point3D(2, | ||
+ | LTransf := LTransf * TMatrix3D.CreateRotationY(DegToRad(90)); | ||
+ | LTransf := LTransf * TMatrix3D.CreateScaling(Point3D(2, | ||
+ | |||
+ | GorillaModel1.Instances[2] := LTransf; | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Instancing by template (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 |
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. |