I understand how create a sphere or a box, but is not my question.
I have a STL file with many meshes inside and i have to manipulate (rotate, move, change material) them, not create a new mesh.
I don't find any examples on existing mesh manipulation
Is it possible?
I can't attach my stl file because it's too big... (7000kb)
There is no such sample yet. But you can get some pieces from multiple samples.
First you need to read the stl in code so you will get better access to the hierarchy of objects - using Model3DGroup (see link that I posted last time to get known with the WPF 3D objects).
Then show the 3D model (create a ModelVisual3D object, add your Model3DGroup to its Content and then add ModelVisual3D to Viewport3D.Children).
Because user can select any individual part of the 3D object, it is not good to use EventManager3D. Instead subscribe to MouseDown (or LeftMouseDown) and MouseUp events on Viewport3D (or event better on parent Border - see samples where usually Viewport3D is a child of a Border). In MouseDown handler use standard WPF hit testing:
var hitTestResult = VisualTreeHelper.HitTest(MainViewport, mousePosition) as RayMeshGeometry3DHitTestResult;
(if you want to skip some hit results, you can also use the HitTest method that takes hitTestCallback). Search the samples for ".HitTest" to get some sample code.
In the hitTestResult check which GeomeryModel3D is hit.
Now you can decide what to do:
- there are many options on how to select this part (change material, show WireBoxVisual3D, ... - see samples for options).
- if you want to move this part around, see ModelMover samples in the Utilities section.
To correctly position selection box or ModelMover, you will need to get the correct transformation of the selected object - in case when the selected object is deep in the objects hierarchy, you can get the total transformation with using Ab3d.Utilities.TransformationsHelper.GetModelTotalTransform method.
This should be your basic plan.
the problem is that I have an STL file with inside a cube and a sphere.
I read STL file and I add it to a viewport here is the code:
Dim readmodel3d As New Model3DGroup
Dim assimpWpfImporter As New AssimpWpfImporter
Dim modelarray = New ModelVisual3D
modelarray.Content = readmodel3d
I added an handler but when i click on the sphere and apply a trasformation the transformation is applied on shere and on cube.
So i can hint the single object.
Where I,m wrong?
DumpHierarchy is defined as an extension method for Model3D (in Ab3d namespace).
So to use it, the code that is executing should have "using Ab3d" or and other namespace under Ab3d defined.
You can also use the longer way to get the dump string (in c#):
string infoText = Ab3d.Utilities.Dumper.GetObjectHierarchyString(model3D);