EvergineTeam / Feedback

Feedback, feature requests, and bug reports for Evergine.
https://evergine.com
14 stars 1 forks source link

Cannot get "My first application" recipe to run with "CreateScene" code #45

Closed moses70 closed 3 years ago

moses70 commented 3 years ago

Hi,

I am interested in using the wave engine for a factory simulation project. For that, I intend to create most of the scene programmatically. In order to learn, I tested the "My first application" recipe (http://doc.waveengine.net/recipes/GettingStarted/My-First-Application.html) in the new 3.1 preview.

There were a few differences in the API but it seemed straight forward. But in the end, the cube is never showing up in the Viewer.

All enties from the editor are working fine.

It would be great to have a pointer here. I would offer to write a new tutorial afterwards.

moses70 commented 3 years ago

Update: I got the rotating cube working. The missing part was:

 // load some material
 var material = this.Managers.AssetSceneManager.Load<Material>(WaveContent.Materials.DefaultMaterial);
 // assign to MaterialComponent:
 .AddComponent(new MaterialComponent() { Material = material })

Now I am searching for the right place the update the scene. May I keep the issue open for a few days? It seems that there is some need for examples.

vicfergar commented 3 years ago

Hi @moses70,

The right place to include logic that has to be executed every update is creating a behavior. For this just create a class that extends from WaveEngine.Framework.Behavior as follows:

public class MyBehavior : Behavior
{
    protected override void Update(TimeSpan gameTime)
    {
        // My update logic goes here
    }
}

If you need it, you can declare dependencies with other components inside the class body as follows:

public class MyBehavior : Behavior
{
    [BindComponent]
    protected Transform3D transform;

    [...]
}

You are right, we have to improve in the documentation side and update existing recipies to the latests version. Hope it was useful for you!

moses70 commented 3 years ago

Hi Victor, thank you very much for this tips! There is some progress!

Currently, I am struggling a bit with materials: How can I create a simple colored material? Currently, I can only load it from assets. Can I modify it programmatically afterwards? Or better from scratch? (I saw the WaveEngine.Materials package. But this seems to be not available for v3.1)

Quite the same question would be for the MeshComponent: I have triangle meshes which I would like to convert into a MeshComponent. Should be trivial, but I cannot find how to do it.

Another question would be about the camera movement. The default camera seems to be suitable for a game, but not so much for a simulation system. I would prefer a control scheme like in an CAD software. Could you give me a hint how to find a suitable component?

I would love to contribute somehow, especially for industry use cases of wave engine. Maybe I am able to, after a while.

vicfergar commented 3 years ago

Hi again @moses70,

Materials According to your materials question: Yes you can, first you have lo load the effect asset. That is: var standardEffect = this.Managers.AssetSceneManager.Load<Effect>(WaveContent.Effects.StandardEffect);

Then create a material using this effect, and use a Decorator for easy property setup:

var standardMaterial = new Material(standardEffect); // Material instance
var standardDecorator = new StandardMaterial(standardMaterial); // Material decorator

If you load a material asset, use a material decorator to modidy its properties the same way as before.

Meshes As I can understand, you have meshes data (Index and Verttext buffers) that you whant to represent using MeshComponent and MeshRenderer. For this you have to create a Model and asign it to the MeshRenderer component. Let me share with you a Helper class that can be useful for you this task: ModelExtensions.zip

Camera As you probably notice the camera movement is fully personalizable. Maybe you want something more similar to the camera used in the Wave GLTF Viewer. Let me share with you the camera components that can be useful as reference: Camera.zip

moses70 commented 3 years ago

Hi Victor,

thank you so much for all the help! I got most of it working.

Only the camera behavior seems to be not working out of the box. This code here is not able to find the relevant transforms:

      protected override bool OnAttached()
      {
         if (!base.OnAttached())
         {
            return false;
         }

         var child = this.Owner.ChildEntities.FirstOrDefault();
         this.targetTransform = child?.FindComponent<Transform3D>();
         var grandChild = child?.ChildEntities.FirstOrDefault();
         this.cameraTransform = grandChild?.FindComponent<Transform3D>();

In my scene, the camera does not have any children. And the activation does not work either because the mouseDispatcher is not yet available at this point.

Seems that the code has to be adapted for the new WaveEngine version? It would be great if you could help with some sample code also here. Is the code of the "FreeCamera" behavior available somewhere?

vicfergar commented 3 years ago

Hi @moses70,

Looks like I missed that part. The entity hierarchy that should be used with these behaviors is as the following:

As you will notice the camera entity will rotate and zoom around the anchor entity

I will share with you also the current code from the FreeCamera3D behavior. This one is much simpler and probably a good starting point for reference. FreeCamera3D.zip

moses70 commented 3 years ago

Now it works, thank you! This is exactly what I was looking for. I only adjusted the deltas a bit.

vicfergar commented 3 years ago

I'm glad to have been of help.

By the way: Merry Christmas!