question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Manipulate SceneNodeGroupModel3D Successfully and but Export Incorrectly

See original GitHub issue

Hi there! I am stuck at this problem for a week and really eager for some help.

My purpose is 1) to generate multiple MeshGeometryModel3D models and manipulate them by using UITranslateManipulator3D/UIRotateManipulator3D. After manipulation, 2) I need to export the translated/rotated models to a .dae file.

For the first part, I can successfully generated the models and play around with the manipulators. Below is the code I have implemented. As an example, a new sphere model will be created at origin whenever a button is clicked calling the method AddSphere(). After, six manipulators are then created and bound to the sphere model. All the models are added to a SceneNodeGroupModel3D, GroupModel, to be displayed in the viewport (<hx:Element3DPresenter Content="{Binding GroupModel}"/> in XAML). Up to now, the models can be successfully generated and manipulated. The transformation of each model can also be verified with GroupModel.GroupNode.Items[index].ModelMatrix.

	private void AddSphere(object parameter)
    {
        MeshBuilder mbuilder = new MeshBuilder();
        mbuilder.AddSphere(new SharpDX.Vector3(0, 0, 0), 5);  
        MeshGeometryModel3D Model = new MeshGeometryModel3D()
        {
            Geometry = mbuilder.ToMeshGeometry3D(),
            Material = new PhongMaterial() { DiffuseColor = new SharpDX.Color4(1f, 0, 0, 0.2f) }
        };

        UITranslateManipulator3D TransX = new UITranslateManipulator3D() { ... }; // the trivials are neglected
        UITranslateManipulator3D TransY = new UITranslateManipulator3D() { ... };
        UITranslateManipulator3D TransZ = new UITranslateManipulator3D() { ... };
        TransX.Bind(Model);
        TransY.Bind(Model);
        TransZ.Bind(Model);

        UIRotateManipulator3D RotX = new UIRotateManipulator3D() { ... };
        UIRotateManipulator3D RotY = new UIRotateManipulator3D() { ... };
        UIRotateManipulator3D RotZ = new UIRotateManipulator3D() { ... };
        RotX.Bind(Model);
        RotY.Bind(Model);
        RotZ.Bind(Model);

        // GroupModel is an instance of class SceneNodeGroupModel3D
        GroupModel.AddNode(Model.SceneNode);
        GroupModel.AddNode(TransX.SceneNode);
        GroupModel.AddNode(TransY.SceneNode);
        GroupModel.AddNode(TransZ.SceneNode);
        GroupModel.AddNode(RotX.SceneNode);
        GroupModel.AddNode(RotY.SceneNode);
        GroupModel.AddNode(RotZ.SceneNode);
    }

However, all the transformed models cannot be exported correctly. They all return to origin. I am using HelixToolkitScene to contain the GroupNode. Below is the code for export.

    private void Export(object parameter)
    {
        // Add "GroupModel" to scene:            
        scene = new HelixToolkitScene(GroupModel.GroupNode);
        ...
        HelixToolkit.SharpDX.Core.Assimp.Exporter exporter = new HelixToolkit.SharpDX.Core.Assimp.Exporter(); 
        exporter.ExportToFile(path, scene, id);
        ...
    }

I realize that when instancing HelixToolkitScene with the GroupNode, all the SceneNodes can be added to scene.Root. Nevertheless, the transforms of each model are NOT. When I print out scene.Root.ModelMatrix, it shows “identity,” which I suspect the reason why all the models are sent back to origin. If I set the ModelMatrix to some other values, e.g., scene.Root.ModelMatrix = GroupModel.GroupNode.Items[0].ModelMatrix, all the exported models are transformed according to the given Matrix. But what I need is different spheres should be in different positions, as transformed by its own manipulators.

I am not sure if there is any step missing. Or am I even in the right track to fulfill this function? Any help or suggestion will be very much appreciated.

Manipulation of models in WPF image

All the exported models, including manipulators, are located at origin. There are 21 (3*7) nodes in the scene. image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
holancecommented, Mar 23, 2022

Already merged

0reactions
Yu-Rucommented, Mar 23, 2022

It works!!! Thank you so much, @holance. Just wondering, will the modification be merged in the future release?

Read more comments on GitHub >

github_iconTop Results From Across the Web

helix-toolkit/CHANGELOG.md at develop
Hot fix for v2.5.0. Fixed. Fixed wrong type cast while using custom ViewBox Texture in HelixToolkit.SharpDX and UWP. (WPF.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found