Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing fbx animation question #2215

Open
seghier opened this issue May 11, 2024 · 12 comments
Open

Importing fbx animation question #2215

seghier opened this issue May 11, 2024 · 12 comments

Comments

@seghier
Copy link

seghier commented May 11, 2024

Hello, i need help with assimp to import fbx file and other files supported
I use ElementHost and HelixViewport3D inside Rhino3d form.
HelixToolkit.Wpf.SharpDX.Viewport3DX make a problem and block the entire window.
What is the best way to open and view fbx file with animation?

@holance
Copy link
Member

holance commented May 11, 2024

Not sure what you mean by blocking the entire window.

@seghier
Copy link
Author

seghier commented May 12, 2024

Hi , sorry if my question is not clear.
I use a panel form in Rhino3d software.
This is the code i used but the viewport always black and if i click on it the entire window of Rhino freeze.

............
private System.Windows.Controls.Viewbox viewbox;
private HelixToolkit.Wpf.SharpDX.Viewport3DX viewport3d;

this.elementHost2 = new System.Windows.Forms.Integration.ElementHost();
this.viewbox = new System.Windows.Controls.Viewbox();
.....
this.elementHost2.Child = this.viewbox;
..............
 public RHViewerUserControl()
 {
     InitializeComponent();
     this.Load += MainForm_Load;

     AmbientLight3D ambientLight = new AmbientLight3D();
     viewport3d = new Viewport3DX();
     viewport3d.Name = "view";
     viewport3d.Width = 400;
     viewport3d.Height = 400;
     viewport3d.ZoomExtentsWhenLoaded = true;
     viewport3d.BackgroundColor = System.Windows.Media.Color.FromRgb(200, 200, 200);
     viewport3d.ShowViewCube = true;
     viewport3d.Orthographic = false;
     /*/
     viewport3d.Camera = new HelixToolkit.Wpf.SharpDX.PerspectiveCamera
     {
         Position = new Point3D(0.0, 0.0, 5.0),
         LookDirection = new System.Windows.Media.Media3D.Vector3D(0.0, 0.0, -5.0),
         UpDirection = new System.Windows.Media.Media3D.Vector3D(0.0, 1.0, 0.0),
         NearPlaneDistance = 0.5,
         FarPlaneDistance = 150.0
     };
     /*/
     viewport3d.Visibility = Visibility.Visible;
     viewbox.Child = viewport3d;
     ......
     }
private string OpenFileFilter = $"{HelixToolkit.Wpf.SharpDX.Assimp.Importer.SupportedFormatsString}";
SceneNodeGroupModel3D groupModel = new SceneNodeGroupModel3D();
private void button4_Click(object sender, EventArgs e)
{
    string filePath = OpenFileDialog(OpenFileFilter);
    var loader = new HelixToolkit.Wpf.SharpDX.Assimp.Importer();
    var scene = loader.Load(filePath);
    groupModel.Clear();
    /*/
    foreach (var node in scene.Root.Traverse().ToList())
    {
        node.RemoveSelf(); // remove from scene to be able to add to group
        groupModel.AddNode(node);
    }
    /*/
    scene.Root.Attach(viewport3d.EffectsManager); // Pre attach scene graph
    scene.Root.UpdateAllTransformMatrix();

    groupModel.AddNode(scene.Root);
}

private string OpenFileDialog(string filter)
{
    var d = new Microsoft.Win32.OpenFileDialog();
    d.CustomPlaces.Clear();

    d.Filter = filter;

    if (!d.ShowDialog().Value)
    {
        return null;
    }

    return d.FileName;
}

image

@holance
Copy link
Member

holance commented May 12, 2024

Are you able to upload a sample project? I am not familiar with the rhino3D.

@seghier
Copy link
Author

seghier commented May 12, 2024

It's just windows form with c# code, i want know how it work in c# and windows form.
The example available use wpf and i try to implant the code in my form without success, or if there is an example using windows form this will be very helpful

@seghier
Copy link
Author

seghier commented May 12, 2024

HelixViewport3D works fine , but i prefer SharpDX.Viewport3DX to load more object with assimp

Recording.2024-05-11.171017.mp4

@seghier
Copy link
Author

seghier commented May 12, 2024

I add this to solve the problem of black background
assimpviewport3d.EffectsManager = new DefaultEffectsManager();
image
But i still to find a way how to import objects with assimp

private string OpenFileFilter = $"{HelixToolkit.Wpf.SharpDX.Assimp.Importer.SupportedFormatsString}";
SceneNodeGroupModel3D groupModel = new SceneNodeGroupModel3D();

private string OpenFileDialog(string filter)
{
    var d = new Microsoft.Win32.OpenFileDialog();
    d.CustomPlaces.Clear();

    d.Filter = filter;

    if (!d.ShowDialog().Value)
    {
        return null;
    }

    return d.FileName;
}

private void assimpLoadButton_Click(object sender, EventArgs e)
{
    string filePath = OpenFileDialog(OpenFileFilter);
    var loader = new HelixToolkit.Wpf.SharpDX.Assimp.Importer();
    var scene = loader.Load(filePath);
    groupModel.Clear();

    foreach (var node in scene.Root.Traverse().ToList())
    {
        node.RemoveSelf(); // remove from scene to be able to add to group
        groupModel.AddNode(node);
    }

    scene.Root.Attach(assimpviewport3d.EffectsManager); // Pre attach scene graph
    scene.Root.UpdateAllTransformMatrix();

    groupModel.AddNode(scene.Root);
}

@holance
Copy link
Member

holance commented May 13, 2024

Did you bind your groupModel in the viewport?

@seghier
Copy link
Author

seghier commented May 14, 2024

That's the problem
i don't know how to add the model to the viewport, i search a lot and don't find any example in c#

@holance
Copy link
Member

holance commented May 14, 2024

https://github.com/helix-toolkit/helix-toolkit/tree/develop/Source/Examples/WPF.SharpDX/FileLoadDemo. If you don't use wpf binding, you can just do Viewport3DX.Items.Add(groupModel).

@seghier
Copy link
Author

seghier commented May 14, 2024

Thank you Finally it work
Is fbx animation loaded automatically or it need complex steps?

@holance
Copy link
Member

holance commented May 15, 2024

It loads automatically.

@seghier
Copy link
Author

seghier commented May 15, 2024

Nice
Thank you i will try how to make it work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants