Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
1.0.0:models [2023/02/23 11:36] – [Sketchfab Plugin] admin | 1.0.0:models [2023/02/23 15:20] – [Using Packages] admin | ||
---|---|---|---|
Line 57: | Line 57: | ||
- All model data will be stored inside the *.fmx file of your form | - 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. | + | {{: |
+ | |||
+ | When the loading options dialog appears you can configure the import process. | ||
+ | But not all options are available for all formats. | ||
+ | |||
+ | * Ignore importing animations | ||
+ | * Animation caching settings | ||
+ | * Ignore importing lights or cameras | ||
+ | * Directly import additional animation files without an extra call | ||
+ | * Limit texture size, in case you have a memory-sensitive application | ||
+ | |||
+ | Afterwards the IDE will show up a loading window while importing. | ||
Because the data + textures are stored in the *.fmx of your form, it can become very large. | 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. | This may slow down the performance of the IDE. | ||
- | **WARNING***: | + | **WARNING***: |
==== Using Packages ==== | ==== Using Packages ==== | ||
Line 85: | Line 97: | ||
The data is not stored again in the formular *.fmx file, it only restores it from package information. | The data is not stored again in the formular *.fmx file, it only restores it from package information. | ||
- | **WARNING***: | + | **WARNING***: |
Line 258: | Line 270: | ||
+ | ==== The Better Loading ==== | ||
+ | |||
+ | Configured loading is the better way of loading model data into your application at runtime. | ||
+ | |||
+ | It gives you the opportunity to tell the loader how to import data. | ||
+ | |||
+ | For example: | ||
+ | * You can choose to ignore importing lights or cameras | ||
+ | * You can directly import additional animation files without an extra call | ||
+ | * You can limit texture size, in case you have a memory-sensitive application | ||
+ | * You can define a status callback function (" | ||
+ | * You can link to a specific model asset inside of package for fast model data reusage | ||
+ | |||
+ | Loading options can be submitted as argument to the LoadNewModelFromFile() or LoadFromFile() method. | ||
+ | |||
+ | In the following example we demonstrate the usage at runtime: | ||
+ | |||
+ | <file pascal> | ||
+ | uses | ||
+ | Gorilla.DefTypes, | ||
+ | Gorilla.Model, | ||
+ | Gorilla.FBX.Loader; | ||
+ | |||
+ | [...] | ||
+ | |||
+ | var LOpts : TGorillaLoadOptions; | ||
+ | LMdlPath := IncludeTrailingPathDelimiter(' | ||
+ | LOpts := TGorillaLoadOptions.Create(LMdlPath + ' | ||
+ | | ||
+ | // only allow this exact filename and no automated lookup | ||
+ | LOpts.FileInfo.StrictFilename := true; | ||
+ | | ||
+ | // link to a package and/or to a specific asset inside of a package | ||
+ | LOpts.Package := nil; | ||
+ | LOpts.Asset := nil; | ||
+ | | ||
+ | // limit to a max. size of textures (textures will be resized in aspect ratio) | ||
+ | LOpts.TextureLimits := Point(512, 512); | ||
+ | | ||
+ | // ignore lights and camera for import | ||
+ | LOpts.ImportLights := false; | ||
+ | LOpts.ImportCameras := false; | ||
+ | | ||
+ | // user defined animation import | ||
+ | LOpts.ImportAnimations := true; | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | LOpts.AddAnimation(LMdlPath + ' | ||
+ | |||
+ | FModel := TGorillaModel.LoadNewModelFromFile(GorillaViewport1, | ||
+ | FModel.Parent := GorillaViewport1; | ||
+ | </ | ||
==== Loading a model from package source ==== | ==== Loading a model from package source ==== | ||
To adopt the behaviour used in the IDE at design time, you can load model data from assets 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. | also at runtime by the following method. | ||
+ | |||
+ | __NOTICE:__ This will trigger design time dialogs on loading data. If you don't want that dialogs to appear, please use LoadNewModelFromFile() or LoadFromFile(). | ||
<file pascal Form1.pas> | <file pascal Form1.pas> | ||
Line 341: | Line 418: | ||
</ | </ | ||
+ | ==== Sketchfab Runtime Support ==== | ||
+ | Since 0.8.2.1675 we provide a Sketchfab plugin directly by using our loading mechanism. | ||
+ | Before implementation you'll need to ensure you've got a valid Sketchfab account with username and password. | ||
+ | |||
+ | https:// | ||
+ | |||
+ | **Remarks: | ||
+ | To request those credentials contact support at https:// | ||
+ | |||
+ | The usage of the plugin is simular to other file formats in Gorilla3D. But instead of using the simple method headers, | ||
+ | you'll have to use the extended method call with a TGorillaLoadOptions parameter. | ||
+ | |||
+ | <file pascal> | ||
+ | // setup loading options to connect to sketchfab | ||
+ | LOpts := TGorillaLoadOptions.Create(FUID, | ||
+ | LOpts.FileInfo.OpenFormat := TGorillaFileOpenFormat.fofDownload; | ||
+ | |||
+ | LOpts.FileInfo.URL := Gorilla.Sketchfab.Loader.GORILLA_SKETCHFAB_URL; | ||
+ | LOpts.FileInfo.ClientId := < | ||
+ | LOpts.FileInfo.ClientSecret := < | ||
+ | LOpts.FileInfo.Username := < | ||
+ | LOpts.FileInfo.Password := < | ||
+ | | ||
+ | // set an individual download folder, where data is written to | ||
+ | // leave empty to use system temporary folders | ||
+ | LOpts.ExtractDirectory := ''; | ||
+ | |||
+ | try | ||
+ | // try loading sketchfab model | ||
+ | FModel := TGorillaModel.LoadNewModelFromFile(GorillaViewport1, | ||
+ | if Assigned(FModel) then | ||
+ | FModel.Parent := GorillaViewport1; | ||
+ | except | ||
+ | on E:Exception do | ||
+ | ShowMessage(' | ||
+ | end; | ||
+ | </ | ||
+ | |||
+ | The plugin will automatically download a zip-archive with a glTF file to your preferred folder (" | ||
+ | and tries to load the contained model. | ||
+ | Before requesting Sketchfab, the loader checks the ExtractDirectory for an already existing download of UID. | ||
+ | If a zip and gltf file already exists it will directly load it, instead of downloading again. | ||
+ | |||
+ | You have to take care yourself in case a previous download is invalid or decprecated. | ||
===== Components ===== | ===== Components ===== | ||
Line 348: | Line 469: | ||
==== TGorillaModel ==== | ==== TGorillaModel ==== | ||
- | A TGorillaModel is the head component for loaded models from file/asset. Even it's inherited from TGorillaMesh, | + | A TGorillaModel is the "head" |
sub-meshes, animations and materials. So a TGorillaModel needs to contain at least one TGorillaMesh in it's Meshes list. | sub-meshes, animations and materials. So a TGorillaModel needs to contain at least one TGorillaMesh in it's Meshes list. | ||
Line 423: | Line 544: | ||
- | ===== Instancing / Model duplication | + | ===== Instancing / Cloning |
==== Instanced Rendering ==== | ==== Instanced Rendering ==== | ||
Line 431: | Line 552: | ||
Use this method to render for example grass or trees. It is not recommended to use it for animated charaters, | 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). | because they would be rendered the same (with the same animation frame). | ||
- | |||
- | You can simply setup instanced rendering in your TGorillaModel or TGorillaMesh object. | ||
{{youtube> | {{youtube> | ||
+ | |||
+ | |||
+ | |||
+ | === At DesignTime === | ||
+ | |||
+ | We offer a collection property called " | ||
+ | |||
+ | You can simply add instances at design time with their transformation information. | ||
+ | |||
+ | __NOTICE:__ The transformation information (position, rotation and scale) is absolute and not depending on the owner mesh. | ||
+ | |||
+ | |||
+ | === At Runtime === | ||
+ | |||
+ | For better usability TGorillaMesh/ | ||
+ | Internally it will be cached in buffer for fast GPU transmission. | ||
+ | |||
+ | This brings new opportunities, | ||
+ | |||
+ | In that case you want to ignore the collection and simply add those instances to the buffer. Therefore please use the AddInstance() method | ||
+ | |||
+ | <file pascal> | ||
+ | function AddInstance(const ATransform : TMatrix3D; const ACreateItem : Boolean; | ||
+ | AName : String = '' | ||
+ | </ | ||
<file pascal> | <file pascal> | ||
/// we create 4 instances in a row | /// we create 4 instances in a row | ||
- | GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(-10, | + | GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(-10, |
- | GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(-5, | + | GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(-5, |
- | GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(5, | + | GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(5, |
- | GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(10, | + | GorillaModel1.AddInstance(TMatrix3D.CreateTranslation(Point3D(10, |
/// afterwards we can modify a specific instance | /// afterwards we can modify a specific instance | ||
Line 452: | Line 596: | ||
</ | </ | ||
+ | __WARNING: | ||
+ | ==== Cloning ==== | ||
+ | |||
+ | Instancing can be done by GPU and providing different transformation matrices like above or by cloning the visual component with all of it's data. | ||
+ | Both ways have their advantages and disadvantages. | ||
- | ==== Instancing by template | + | * Use instancing if you want to re-render a mesh multiple times |
+ | * Use cloning if you need different visual feedback | ||
- | 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 (TModelDef), | We will load up a template (TModelDef), | ||
Line 529: | Line 678: | ||
end; | end; | ||
</ | </ | ||
- | ===== Plugins ===== | ||
- | |||