AB4D Forum

Full Version: Problem with selecting objects in ViewPort3D
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
[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();
transformGroup.Children.Add(_scaleTransform);
transformGroup.Children.Add(_rotateTransform);
transformGroup.Children.Add(_translateTransform);

customModel.Transform = transformGroup;
ObjectsGroup.Children.Add(customModel);

GeometryModel3D predefinedModel = Ab3d.Models.Model3DFactory.CreateBox(new Point3D(0, 0, 0), new Size3D(40, 40, 40), _normalMaterial);
predefinedModel.Transform = transformGroup;

ObjectsGroup.Children.Add(predefinedModel);



Ab3d.Utilities.EventManager3D _eventManager3D;
_eventManager3D = new Ab3d.Utilities.EventManager3D(MainViewport3D);


var modelEventSource3D = new Ab3d.Utilities.ModelEventSource3D(customModel);
modelEventSource3D.MouseEnter += BoxOnMouseEnter;
modelEventSource3D.MouseLeave += BoxOnMouseLeave;
modelEventSource3D.MouseClick += BoxOnMouseClick;
_eventManager3D.RegisterEventSource3D(modelEventSource3D);

var modelEventSource3D2 = new Ab3d.Utilities.ModelEventSource3D(predefinedModel);
modelEventSource3D2.MouseEnter += BoxOnMouseEnter;
modelEventSource3D2.MouseLeave += BoxOnMouseLeave;
modelEventSource3D2.MouseClick += BoxOnMouseClick;
_eventManager3D.RegisterEventSource3D(modelEventSource3D2);

}
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.