stride3d / stride

Stride (formerly Xenko), a free and open-source cross-platform C# game engine.
https://stride3d.net
MIT License
6.62k stars 958 forks source link

GameStudio to discover IProceduralModel classes from project files. #1583

Open tagcode opened 1 year ago

tagcode commented 1 year ago

Game Studio cannot discover exported IProceduralModel classes from project, only the built-in ones.

gamestudio

Could the Game Studio be updated so that it scans for the exported IProceduralModel classes from the managed .dll files, and adds them to the Asset menu. The scanning part is should be easy to do with Mono.Cecil which can enumerate anything inside managed .dll without loading into appdomain.

tagcode commented 1 year ago

I just noticed that this dropdown menu does discover all the procedural model classes. So it's only that asset menu that doesn't.

stride

As workaround trick, I can create a model from a built-in procedure, e.g. Plane, and then change it from this dropdown menu.

mattiascibien commented 1 year ago

As far as I saw by studying the code there are some different approaches with the Asset Window and the Property Grid. The property grid looks for the Types in every assembly or DLL while the Asset Window uses YAML templates like this in order to be discovered:

# FILE: Stride.Assets.Presentation\Templates\Assets\Models\ProceduralCube.sdtpl
!TemplateAssetFactory
Id: 8267F08C-3DC8-48F4-81EA-4888A1CEF9CE
AssetTypeName: ProceduralModelAsset
Name: Cube
Scope: Asset
Description: A procedurally-generated cube
Group: Model
Order: 20
Icon: ..\.sdtpl\ProceduralCube.png
DefaultOutputName: Cube
FactoryTypeName: ProceduralModelCubeFactory

I guess that if you add a template file like this one to your proect and implement the factory by implementing AssetFactory<ProceduralModelAsset> and specifying it in the FactoryTypeName of your template you can make your procedural model appear in the new Asset Window.

You also need to edit your game .sdpkg file to include your template:

!Package
SerializedVersion: {Assets: 3.1.0.0}
Meta:
    Name: StrideGameMenu.Game
    Version: 1.0.0
    Authors: []
    Owners: []
    Dependencies: null
AssetFolders:
    -   Path: !dir ../Assets/Shared
    -   Path: !dir Effects
ResourceFolders: []
OutputGroupDirectories: {}
ExplicitFolders: []
Bundles: []
TemplateFolders:
    - Path: !dir Templates/Assets
      Group: Assets
      Files:
        - !file Templates/MyCube.sdtpl
RootAssets:
    - 1b4052b1-fc6a-4d8b-8b3e-2674f6a73895:MainScene

As you can see I can see myCube inside my project: image

tagcode commented 1 year ago

Thanks, It worked. To an extent.

In order to write AssetFactory<ProceduralModelAsset> implementation, I had to take PackageReference to "Stride.Core.Assets" and "Stride.Assets.Model", and those required that the dependee library has to have TargetFramework of "net6.0-windows7.0". I can't have non-windows target framework.

mattiascibien commented 1 year ago

I guess that since AssetFactory is an editor class it should be Windows only as stride editor is Windows Only at the moment. I suggest to add these in yout .Windows project instead of your game one.

tagcode commented 1 year ago

Yeah, AssetFactory to its own library.

mattiascibien commented 1 year ago

Let me know if it works. I have just began to wonder inside the engine internals :)

tagcode commented 1 year ago

Procedural

It works very nicely! I separated into xxx.Asset and xxx.Asset.Editor class libraries.

tagcode commented 1 year ago

This issue could be closed if this document page was extended with procedural model template section, that contains @tebjan's instructions and @mattiascibien 's example.