Problem with selecting objects in ViewPort3D - Printable Version
+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: Ab3d.PowerToys (https://forum.ab4d.com/forumdisplay.php?fid=9)
+--- Thread: Problem with selecting objects in ViewPort3D (/showthread.php?tid=3952)
Problem with selecting objects in ViewPort3D - NPVoljers - 10-05-2015
[Hello! We are evaluating trial version of Ab3d.Powertoys and came across interesting problem. If we create our own custom GeometryModel3D object, and, lets say, 5 instances of the same object are added to ViewPort in different locations, and one of them is selected, all of them get highligted. On the other hand if create predifined GeometryModel3D object with Model3DFactory, add as many instances to the viewport as needed, and then select one of them, only selected object gets highlighted. Could anybody explain why is that so? Here is sample code:]
MeshGeometry3D extrudedMesh2 = Ab3d.Meshes.Mesh3DFactory.CreateExtrudedMeshGeometry(_pointList, isSmooth, modelOffset, extrudeVector);
int posX = 100;
int posY = 100;
for (int i = 0; i < 5; i++)
CreateGeometryModel(extrudedMesh, posX, posY);
posX += 100;
private void CreateGeometryModel(MeshGeometry3D meshGeometry3D, int X, int Z)
GeometryModel3D customModel = new GeometryModel3D(meshGeometry3D, new DiffuseMaterial(Brushes.Green));
ScaleTransform3D _scaleTransform = new ScaleTransform3D(0.2, 0.2, 0.2);
RotateTransform3D _rotateTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 0), 0), new Point3D(0, 0, 0));
TranslateTransform3D _translateTransform = new TranslateTransform3D(new Vector3D(X, 0, Z));
var transformGroup = new Transform3DGroup();
customModel.Transform = transformGroup;
GeometryModel3D predefinedModel = Ab3d.Models.Model3DFactory.CreateBox(new Point3D(0, 0, 0), new Size3D(40, 40, 40), _normalMaterial);
predefinedModel.Transform = transformGroup;
_eventManager3D = new Ab3d.Utilities.EventManager3D(MainViewport3D);
var modelEventSource3D = new Ab3d.Utilities.ModelEventSource3D(customModel);
modelEventSource3D.MouseEnter += BoxOnMouseEnter;
modelEventSource3D.MouseLeave += BoxOnMouseLeave;
modelEventSource3D.MouseClick += BoxOnMouseClick;
var modelEventSource3D2 = new Ab3d.Utilities.ModelEventSource3D(predefinedModel);
modelEventSource3D2.MouseEnter += BoxOnMouseEnter;
modelEventSource3D2.MouseLeave += BoxOnMouseLeave;
modelEventSource3D2.MouseClick += BoxOnMouseClick;
RE: Problem with selecting objects in ViewPort3D - abenedik - 10-06-2015
Thank you for posting your question and providing the sample source code.
I have checked your code and found a problem in EventManager3D.
The problem could occur when multiple GeometryModel3D objects were using the same MeshGeometry3D. In this case the events can be raised on the wrong ModelEventSource3D (usually on the first registered).
I have fixed the problem.
Because the problem was quite severe I have also released a new version of Ab3d.PowerToys v7.2. The new version also has some other features and fixes - see the Ab3d.PowerToys web page for more info.
Regarding your sample code I have one recommendation:
you are creating many instances of EventManager3D (on in each CreateGeometryMode method). I would recommend to have only one EventManager3D per Viewport3D. This can improve performance with greatly reducing the number of events that need to be checked.