Manipulate SceneNodeGroupModel3D Successfully and but Export Incorrectly
See original GitHub issueHi 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
All the exported models, including manipulators, are located at origin. There are 21 (3*7) nodes in the scene.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Already merged
It works!!! Thank you so much, @holance. Just wondering, will the modification be merged in the future release?