Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
models [2020/11/04 14:47] – [Supported file formats] admin | models [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Loading models ====== | ||
- | You can find the model component in the toolbar under Gorilla3D > TGorillaModel | ||
- | |||
- | A TGorillaModel component automatically manages sub-meshes, materials and animations for you. So this is the best component for loading complex mesh data. | ||
- | |||
- | Every model contains a number of TGorillaMesh instances which holds the vertex data of a specific child mesh. At least one mesh will be available in a valid model. | ||
- | |||
- | When loading models from file / stream, all materials and animations, defined in the source file / stream, are loaded too. | ||
- | In case you are using explicit animation files (only for Collada DAE format), you need to load them afterwards by AddAnimationFromFile(). | ||
- | |||
- | A TGorillaModel instance needs to be a child / sub-child of a TGorillaViewport instance, otherwise it will not be displayed. | ||
- | |||
- | ===== Supported file formats ===== | ||
- | |||
- | Currently it is allowed to use the following file-formats: | ||
- | |||
- | ^ Format | ||
- | | G3D | ✔ | ✔ | ✔ | ✔ | | ||
- | | DAE | ✔ | ✔ | ✔ | ✘ | | ||
- | | OBJ | ✔ | ✔ | ✘ | ✘ | | ||
- | | STL | ✔ |✘ | ✘ | ✔ | | ||
- | | FBX | ✔ | ✔ | ✘ | ✘ | | ||
- | | X3D | ✔ | ✔ | ✔ | ✘ | | ||
- | | glTF | ||
- | | Babylon | ||
- | | Sketchfab | ||
- | ===== Loading a new model from file at runtime ===== | ||
- | |||
- | Creating a model instance at runtime is very easy and often very helpful for creating dynamically loaded scenes. | ||
- | |||
- | <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.Model; | ||
- | |||
- | // in our form (TForm1) we added a field named " | ||
- | procedure TForm1.FormCreate(Sender: | ||
- | var LPath : String; | ||
- | LAssetPckg : TGorillaAssetPackage; | ||
- | begin | ||
- | LPath := ' | ||
- | LAssetPckg := nil; | ||
- | FModel := TGorillaModel.LoadNewModelFromFile(FGorilla, | ||
- | OpenDialog1.FileName, | ||
- | FModel.Parent := FGorilla; | ||
- | end; | ||
- | </ | ||
- | | ||
- | For the moment you can ignore the last parameter " | ||
- | We will explain this in the [[animations|Animations]] 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 ===== | ||
- | |||
- | In case you've dragged a TGorillaModel component onto your viewport, you can load the model by the following method. | ||
- | |||
- | <file pascal Form1.pas> | ||
- | uses | ||
- | Gorilla.G3D.Loader, | ||
- | Gorilla.DAE.Loader, | ||
- | Gorilla.OBJ.Loader, | ||
- | Gorilla.STL.Loader, | ||
- | Gorilla.FBX.Loader, | ||
- | Gorilla.GLTF.Loader, | ||
- | Gorilla.Model; | ||
- | |||
- | // in our form (TForm1) we added a field named " | ||
- | procedure TForm1.FormCreate(Sender: | ||
- | var LPath : String; | ||
- | LAssetPckg : TGorillaAssetPackage; | ||
- | begin | ||
- | LPath := ' | ||
- | LAssetPckg := nil; | ||
- | GorillaModel1.LoadFromFile(LAssetPckg, | ||
- | OpenDialog1.FileName, | ||
- | end; | ||
- | </ | ||
- | |||
- | | ||
- | To load a specific file format you need to include the format unit: | ||
- | * Gorilla.G3D.Loader | ||
- | * Gorilla.DAE.Loader | ||
- | * Gorilla.OBJ.Loader | ||
- | * Gorilla.STL.Loader | ||
- | * Gorilla.FBX.Loader | ||
- | * Gorilla.GLTF.Loader | ||
- | * Gorilla.X3D.Loader | ||
- | * Gorilla.X3DZ.Loader | ||
- | * Gorilla.X3DVZ.Loader | ||
- | |||
- | Only then the format loader is able to load the specific file. | ||
- | |||
- | ===== Plugins ===== | ||
- | |||
- | ==== Sketchfab Plugin ==== | ||
- | |||
- | 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. | ||
- | |||
- | ===== Exporting a model ===== | ||
- | |||
- | We provide 2 export formats at the moment: G3D and STL, which are easy to use. | ||
- | |||
- | ==== G3D Export ==== | ||
- | <file pascal> | ||
- | |||
- | uses | ||
- | Gorilla.G3D.Exporter; | ||
- | | ||
- | procedure TForm1.MenuItem1Click(Sender: | ||
- | var LG3DExp : TGorillaG3DExporter; | ||
- | LToBinary : Boolean; | ||
- | LZipped : Boolean; | ||
- | LBeautified : Boolean; | ||
- | begin | ||
- | LToBinary := true; | ||
- | LZipped := true; | ||
- | LBeautified := true; | ||
- | | ||
- | if Assigned(fModel) then | ||
- | begin | ||
- | if SaveDialog1.Execute() then | ||
- | begin | ||
- | LG3DExp := TGorillaG3DExporter.Create(); | ||
- | try | ||
- | if LToBinary then | ||
- | LG3DExp.Format := TGorillaG3DFormat.BSONFormat | ||
- | else | ||
- | LG3DExp.Format := TGorillaG3DFormat.JSONFormat; | ||
- | |||
- | LG3DExp.Zipped | ||
- | LG3DExp.Beautified := LBeautified; | ||
- | |||
- | LG3DExp.SaveToFile(fModel.Def as TModelDef, SaveDialog1.FileName); | ||
- | finally | ||
- | FreeAndNil(LG3DExp); | ||
- | end; | ||
- | |||
- | ShowMessage(' | ||
- | SaveDialog1.FileName); | ||
- | end; | ||
- | end; | ||
- | end; | ||
- | </ | ||
- | |||
- | |||
- | ==== STL Export ==== | ||
- | |||
- | <file pascal> | ||
- | <file pascal> | ||
- | |||
- | uses | ||
- | Gorilla.STL.Exporter; | ||
- | | ||
- | procedure TForm1.MenuItem1Click(Sender: | ||
- | var LSTLExp : TGorillaSTLExporter; | ||
- | LToBinary : Boolean; | ||
- | LAllowMultipleMeshes : Boolean; | ||
- | LUseMultipleFiles : Boolean; | ||
- | begin | ||
- | // ascii and binary format supported | ||
- | LToBinary := true; | ||
- | | ||
- | // because STL supports only single meshes per file (per default), | ||
- | // we can split up a model with multiple meshes into multiple files | ||
- | LAllowMultipleMeshes := true; | ||
- | // but this exporter also allows to export multiple meshes to a single file | ||
- | // just set UseMultipleFiles to false | ||
- | LUseMultipleFiles := true; | ||
- | | ||
- | if Assigned(FModel) then | ||
- | begin | ||
- | if SaveDialog1.Execute() then | ||
- | begin | ||
- | LSTLExp := TGorillaSTLExporter.Create(); | ||
- | try | ||
- | LSTLExp.Binary := LToBinary; | ||
- | LSTLExp.AllowMultipleMeshes := LAllowMultipleMeshes; | ||
- | LSTLExp.UseMultipleFiles := LUseMultipleFiles; | ||
- | LSTLExp.SaveToFile(FModel.Def as TModelDef, SaveDialog1.FileName); | ||
- | finally | ||
- | FreeAndNil(LSTLExp); | ||
- | end; | ||
- | |||
- | ShowMessage(' | ||
- | SaveDialog1.FileName); | ||
- | end; | ||
- | end; | ||
- | end; | ||
- | </ | ||
- | |||
- | Next step: [[animations|Animations]] |