public ElementHighlighter3D() { meshGroup = new GroupModel3D(); material = new DiffuseMaterial { DiffuseColor = HighlightColor }; xrayEffect = new PostEffectMeshXRayGrid() { EffectName = "HighlighterXRayGrid", DimmingFactor = 0.5, BlendingFactor = 0.8, GridDensity = 4, GridColor = System.Windows.Media.Colors.Gray }; (xrayEffect.SceneNode as NodePostEffectXRayGrid).XRayDrawingPassName = DefaultPassNames.EffectMeshDiffuseXRayGridP3; Children.Add(meshGroup); Children.Add(xrayEffect); var binding = new Binding("Target.Transform") { RelativeSource = RelativeSource.Self }; BindingOperations.SetBinding(this, TransformProperty, binding); }
/// <summary> /// Initialization /// </summary> public void InitializeBusinessLogic() { ConfigurationHelper.RegisterSettings(Properties.Settings.Default); pointCloudViewModel = new PointcloudViewModel(new SharpDX.Size2(0, 0)); PointCloudView.ViewModel = pointCloudViewModel; PointCloudView.InitializeScene(); DataContext = pointCloudViewModel; // Moving Camera vertically up and turning it to look down PointCloudView.ViewModel.SetCvmPosition(new System.Windows.Media.Media3D.Vector3D(0, 0, groundZ), new System.Windows.Media.Media3D.Vector3D(180, 0, 90)); var planeColor = System.Windows.Media.Color.FromArgb(20, 50, 255, 50).ToColor4(); // Only points from this rectangular area are included and outliers are ignored var scenePlane = PointcloudViewModel.CreatePlane(planeColor, groundD, groundW, new SharpDX.Vector3(0, 0, 1f)); PointCloudView.SceneRoot.Children.Add(scenePlane); // For 3D texts BillboardTextModel3D text = new BillboardTextModel3D(); PointCloudView.SceneRoot.Children.Add(text); labels = new BillboardText3D(); text.Geometry = labels; boundingBoxGroup = new GroupModel3D(); PointCloudView.SceneRoot.Children.Add(boundingBoxGroup); rosControlBase.RosConnected += RosControlBase_RosConnected; rosControlBase.RosDisconnected += RosControlBase_RosDisconnected; rosControlBase.CvmDeviceInfoChaged += RosControlBase_CvmDeviceInfoChaged; }
public BoxManipulator3D() { facesGroup = new GroupModel3D(); var mb = new MeshBuilder(); mb.AddFaceNX(); negX = CreateMesh(mb); mb = new MeshBuilder(); mb.AddFaceNY(); negY = CreateMesh(mb); mb = new MeshBuilder(); mb.AddFaceNZ(); negZ = CreateMesh(mb); mb = new MeshBuilder(); mb.AddFacePX(); posX = CreateMesh(mb); mb = new MeshBuilder(); mb.AddFacePY(); posY = CreateMesh(mb); mb = new MeshBuilder(); mb.AddFacePZ(); posZ = CreateMesh(mb); negX.Mouse3DDown += Manipulation_Mouse3DDown; negY.Mouse3DDown += Manipulation_Mouse3DDown; negZ.Mouse3DDown += Manipulation_Mouse3DDown; posX.Mouse3DDown += Manipulation_Mouse3DDown; posY.Mouse3DDown += Manipulation_Mouse3DDown; posZ.Mouse3DDown += Manipulation_Mouse3DDown; negX.Mouse3DMove += Manipulation_Mouse3DMove; negY.Mouse3DMove += Manipulation_Mouse3DMove; negZ.Mouse3DMove += Manipulation_Mouse3DMove; posX.Mouse3DMove += Manipulation_Mouse3DMove; posY.Mouse3DMove += Manipulation_Mouse3DMove; posZ.Mouse3DMove += Manipulation_Mouse3DMove; negX.Mouse3DUp += Manipulation_Mouse3DUp; negY.Mouse3DUp += Manipulation_Mouse3DUp; negZ.Mouse3DUp += Manipulation_Mouse3DUp; posX.Mouse3DUp += Manipulation_Mouse3DUp; posY.Mouse3DUp += Manipulation_Mouse3DUp; posZ.Mouse3DUp += Manipulation_Mouse3DUp; facesGroup.Children.Add(negX); facesGroup.Children.Add(negY); facesGroup.Children.Add(negZ); facesGroup.Children.Add(posX); facesGroup.Children.Add(posY); facesGroup.Children.Add(posZ); Children.Add(facesGroup); }
private void OnWorldGenerated(object sender, EventArgs args) { var world = (World)sender; WorldMeshes = new GroupModel3D(); world.Voxels.ToList().ForEach(vox => { var voxel = (Voxel)vox; CubeFace face; MeshBuilder b = new MeshBuilder(); voxel.GetVisibleCubeFaces().ForEach(f => { if (voxel.Faces.TryGetValue(f, out face)) { b.AddCubeFace(face.CubeCenter, face.Normal, face.Up, face.Distance, face.Width, face.Height); } }); var mm = b.ToMesh(); var simHelper = new MeshSimplification(mm); int size = mm.Indices.Count / 3 / 2; var m = simHelper.Simplify(size, 7, true, true); var mesh = new MeshGeometryModel3D { Geometry = mm, CullMode = SharpDX.Direct3D11.CullMode.Back }; var scale = new ScaleTransform3D(1, 1, 1); var translate = new TranslateTransform3D(0, 0, 0); var group = new Transform3DGroup(); group.Children.Add(scale); group.Children.Add(translate); mesh.Transform = group; mesh.Material = voxel.PhysicalMaterial; if (((Engine.Core.World.Material)voxel.Material).PhysicalMaterial.DiffuseColor.Alpha < 1) { mesh.IsTransparent = true; } WorldMeshes.Children.Add(mesh); voxel.Mesh = mesh; }); //Viewport = InitializeViewport(); //while (Viewport == null) { Debug.WriteLine($"Waiting for Viewport..."); } }
private void DetachGroupButton_Click(object sender, RoutedEventArgs e) { if (tempGroup == null) { tempGroup = group1; view1.Items.Remove(group1); } }
private void AttachGroupButton_Click(object sender, RoutedEventArgs e) { if (tempGroup != null) { view1.Items.Add(tempGroup); tempGroup = null; } }
public override void Calculate() { if (InputPorts[0].Data == null) { return; } if (InputPorts[0].Data is string) { var extension = Path.GetExtension(InputPorts[0].Data as string); var flag = false; switch (extension) { case ".obj": var currentHelixObjReader = new ObjReader(); try { var objModel = currentHelixObjReader.Read((string)InputPorts[0].Data); var modelGroup = new GroupModel3D(); var modelGeometry = new Element3DCollection(); modelGeometry.AddRange( objModel.Select( x => new MeshGeometryModel3D { Geometry = x.Geometry as MeshGeometry3D, Material = x.Material })); modelGroup.Children = modelGeometry; Dispatcher.BeginInvoke((Action) delegate { _control.ViewPort3D.Items.Add(modelGroup); }); } catch (Exception) { // ignore } break; case ".stl": var currentHelixStlReader = new StLReader(); try { var myModel = currentHelixStlReader.Read((string)InputPorts[0].Data); // _control.ViewPort3D.Items.Add(myModel); } catch (Exception) { // ignore } break; } } }
internal Region(int sourceIndex, string name, IReadOnlyList <Permutation> permutations) { SourceIndex = sourceIndex; Name = name; Permutations = permutations; Element = new GroupModel3D(); foreach (var perm in permutations) { Element.Children.Add(perm.Element); } }
public TransformManipulator3D() { var rotationYMatrix = Matrix.RotationZ((float)Math.PI / 2); var rotationZMatrix = Matrix.RotationY(-(float)Math.PI / 2); ctrlGroup = new GroupModel3D(); #region Translation Models translationX = new MeshGeometryModel3D() { Geometry = TranslationXGeometry, Material = DiffuseMaterials.Red, CullMode = CullMode.Back, PostEffects = "ManipulatorXRayGrid" }; translationY = new MeshGeometryModel3D() { Geometry = TranslationXGeometry, Material = DiffuseMaterials.Green, CullMode = CullMode.Back, PostEffects = "ManipulatorXRayGrid" }; translationZ = new MeshGeometryModel3D() { Geometry = TranslationXGeometry, Material = DiffuseMaterials.Blue, CullMode = CullMode.Back, PostEffects = "ManipulatorXRayGrid" }; #if !NETFX_CORE translationY.Transform = new Media3D.MatrixTransform3D(rotationYMatrix.ToMatrix3D()); translationZ.Transform = new Media3D.MatrixTransform3D(rotationZMatrix.ToMatrix3D()); translationX.Mouse3DDown += Translation_Mouse3DDown; translationY.Mouse3DDown += Translation_Mouse3DDown; translationZ.Mouse3DDown += Translation_Mouse3DDown; translationX.Mouse3DMove += Translation_Mouse3DMove; translationY.Mouse3DMove += Translation_Mouse3DMove; translationZ.Mouse3DMove += Translation_Mouse3DMove; translationX.Mouse3DUp += Manipulation_Mouse3DUp; translationY.Mouse3DUp += Manipulation_Mouse3DUp; translationZ.Mouse3DUp += Manipulation_Mouse3DUp; #else translationY.Transform3D = rotationYMatrix; translationZ.Transform3D = rotationZMatrix; translationX.OnMouse3DDown += Translation_Mouse3DDown; translationY.OnMouse3DDown += Translation_Mouse3DDown; translationZ.OnMouse3DDown += Translation_Mouse3DDown; translationX.OnMouse3DMove += Translation_Mouse3DMove; translationY.OnMouse3DMove += Translation_Mouse3DMove; translationZ.OnMouse3DMove += Translation_Mouse3DMove; translationX.OnMouse3DUp += Manipulation_Mouse3DUp; translationY.OnMouse3DUp += Manipulation_Mouse3DUp; translationZ.OnMouse3DUp += Manipulation_Mouse3DUp; #endif translationGroup = new GroupModel3D(); translationGroup.Children.Add(translationX); translationGroup.Children.Add(translationY); translationGroup.Children.Add(translationZ); ctrlGroup.Children.Add(translationGroup); #endregion #region Rotation Models rotationX = new MeshGeometryModel3D() { Geometry = RotationXGeometry, Material = DiffuseMaterials.Red, CullMode = CullMode.Back, PostEffects = "ManipulatorXRayGrid" }; rotationY = new MeshGeometryModel3D() { Geometry = RotationXGeometry, Material = DiffuseMaterials.Green, CullMode = CullMode.Back, PostEffects = "ManipulatorXRayGrid" }; rotationZ = new MeshGeometryModel3D() { Geometry = RotationXGeometry, Material = DiffuseMaterials.Blue, CullMode = CullMode.Back, PostEffects = "ManipulatorXRayGrid" }; #if !NETFX_CORE rotationY.Transform = new Media3D.MatrixTransform3D(rotationYMatrix.ToMatrix3D()); rotationZ.Transform = new Media3D.MatrixTransform3D(rotationZMatrix.ToMatrix3D()); rotationX.Mouse3DDown += Rotation_Mouse3DDown; rotationY.Mouse3DDown += Rotation_Mouse3DDown; rotationZ.Mouse3DDown += Rotation_Mouse3DDown; rotationX.Mouse3DMove += Rotation_Mouse3DMove; rotationY.Mouse3DMove += Rotation_Mouse3DMove; rotationZ.Mouse3DMove += Rotation_Mouse3DMove; rotationX.Mouse3DUp += Manipulation_Mouse3DUp; rotationY.Mouse3DUp += Manipulation_Mouse3DUp; rotationZ.Mouse3DUp += Manipulation_Mouse3DUp; #else rotationY.Transform3D = rotationYMatrix; rotationZ.Transform3D = rotationZMatrix; rotationX.OnMouse3DDown += Rotation_Mouse3DDown; rotationY.OnMouse3DDown += Rotation_Mouse3DDown; rotationZ.OnMouse3DDown += Rotation_Mouse3DDown; rotationX.OnMouse3DMove += Rotation_Mouse3DMove; rotationY.OnMouse3DMove += Rotation_Mouse3DMove; rotationZ.OnMouse3DMove += Rotation_Mouse3DMove; rotationX.OnMouse3DUp += Manipulation_Mouse3DUp; rotationY.OnMouse3DUp += Manipulation_Mouse3DUp; rotationZ.OnMouse3DUp += Manipulation_Mouse3DUp; #endif rotationGroup = new GroupModel3D(); rotationGroup.Children.Add(rotationX); rotationGroup.Children.Add(rotationY); rotationGroup.Children.Add(rotationZ); ctrlGroup.Children.Add(rotationGroup); #endregion #region Scaling Models scaleX = new MeshGeometryModel3D() { Geometry = ScalingGeometry, Material = DiffuseMaterials.Red, CullMode = CullMode.Back, PostEffects = "ManipulatorXRayGrid" }; scaleY = new MeshGeometryModel3D() { Geometry = ScalingGeometry, Material = DiffuseMaterials.Green, CullMode = CullMode.Back, PostEffects = "ManipulatorXRayGrid" }; scaleZ = new MeshGeometryModel3D() { Geometry = ScalingGeometry, Material = DiffuseMaterials.Blue, CullMode = CullMode.Back, PostEffects = "ManipulatorXRayGrid" }; #if !NETFX_CORE scaleY.Transform = new Media3D.MatrixTransform3D(rotationYMatrix.ToMatrix3D()); scaleZ.Transform = new Media3D.MatrixTransform3D(rotationZMatrix.ToMatrix3D()); scaleX.Mouse3DDown += Scaling_Mouse3DDown; scaleY.Mouse3DDown += Scaling_Mouse3DDown; scaleZ.Mouse3DDown += Scaling_Mouse3DDown; scaleX.Mouse3DMove += Scaling_Mouse3DMove; scaleY.Mouse3DMove += Scaling_Mouse3DMove; scaleZ.Mouse3DMove += Scaling_Mouse3DMove; scaleX.Mouse3DUp += Manipulation_Mouse3DUp; scaleY.Mouse3DUp += Manipulation_Mouse3DUp; scaleZ.Mouse3DUp += Manipulation_Mouse3DUp; #else scaleY.Transform3D = rotationYMatrix; scaleZ.Transform3D = rotationZMatrix; scaleX.OnMouse3DDown += Scaling_Mouse3DDown; scaleY.OnMouse3DDown += Scaling_Mouse3DDown; scaleZ.OnMouse3DDown += Scaling_Mouse3DDown; scaleX.OnMouse3DMove += Scaling_Mouse3DMove; scaleY.OnMouse3DMove += Scaling_Mouse3DMove; scaleZ.OnMouse3DMove += Scaling_Mouse3DMove; scaleX.OnMouse3DUp += Manipulation_Mouse3DUp; scaleY.OnMouse3DUp += Manipulation_Mouse3DUp; scaleZ.OnMouse3DUp += Manipulation_Mouse3DUp; #endif scaleGroup = new GroupModel3D(); scaleGroup.Children.Add(scaleX); scaleGroup.Children.Add(scaleY); scaleGroup.Children.Add(scaleZ); ctrlGroup.Children.Add(scaleGroup); #endregion Children.Add(ctrlGroup); xrayEffect = new PostEffectMeshXRayGrid() { EffectName = "ManipulatorXRayGrid", DimmingFactor = 0.5, BlendingFactor = 0.8, GridDensity = 4, GridColor = Media.Colors.Gray }; (xrayEffect.SceneNode as NodePostEffectXRayGrid).XRayDrawingPassName = DefaultPassNames.EffectMeshDiffuseXRayGridP3; Children.Add(xrayEffect); SceneNode.OnAttached += SceneNode_OnAttached; SceneNode.OnDetached += SceneNode_OnDetached; }
public TransformManipulatorEx3D() { var rotationYMatrix = Matrix.RotationZ((float)Math.PI / 2); var rotationZMatrix = Matrix.RotationY(-(float)Math.PI / 2); var rotationYZMatrix = Matrix.RotationY(-(float)Math.PI / 2); var rotationXZMatrix = Matrix.RotationX((float)Math.PI / 2); ctrlGroup = new GroupModel3D(); #region Translation Models translationX = GetGeometryModel(TranslationXGeometry, DiffuseMaterials.Red); translationY = GetGeometryModel(TranslationXGeometry, DiffuseMaterials.Green); translationZ = GetGeometryModel(TranslationXGeometry, DiffuseMaterials.Blue); translationY.Transform = new Media3D.MatrixTransform3D(rotationYMatrix.ToMatrix3D()); translationZ.Transform = new Media3D.MatrixTransform3D(rotationZMatrix.ToMatrix3D()); translationX.Mouse3DDown += Translation_Mouse3DDown; translationY.Mouse3DDown += Translation_Mouse3DDown; translationZ.Mouse3DDown += Translation_Mouse3DDown; translationX.Mouse3DMove += Translation_Mouse3DMove; translationY.Mouse3DMove += Translation_Mouse3DMove; translationZ.Mouse3DMove += Translation_Mouse3DMove; translationX.Mouse3DUp += Manipulation_Mouse3DUp; translationY.Mouse3DUp += Manipulation_Mouse3DUp; translationZ.Mouse3DUp += Manipulation_Mouse3DUp; translationGroup = new GroupModel3D(); translationGroup.Children.Add(translationX); translationGroup.Children.Add(translationY); translationGroup.Children.Add(translationZ); ctrlGroup.Children.Add(translationGroup); #endregion #region Translation2D Models translationXY = GetGeometryModel(TranslationXYGeometry, DiffuseMaterials.Blue); translationYZ = GetGeometryModel(TranslationXYGeometry, DiffuseMaterials.Red); translationXZ = GetGeometryModel(TranslationXYGeometry, DiffuseMaterials.Green); translationYZ.Transform = new Media3D.MatrixTransform3D(rotationZMatrix.ToMatrix3D()); translationXZ.Transform = new Media3D.MatrixTransform3D(rotationXZMatrix.ToMatrix3D()); translationXY.Mouse3DDown += Translation_Mouse3DDown; translationYZ.Mouse3DDown += Translation_Mouse3DDown; translationXZ.Mouse3DDown += Translation_Mouse3DDown; translationXY.Mouse3DMove += Translation_Mouse3DMove; translationYZ.Mouse3DMove += Translation_Mouse3DMove; translationXZ.Mouse3DMove += Translation_Mouse3DMove; translationXY.Mouse3DUp += Manipulation_Mouse3DUp; translationYZ.Mouse3DUp += Manipulation_Mouse3DUp; translationXZ.Mouse3DUp += Manipulation_Mouse3DUp; translation2DGroup = new GroupModel3D(); translation2DGroup.Children.Add(translationXY); translation2DGroup.Children.Add(translationYZ); translation2DGroup.Children.Add(translationXZ); ctrlGroup.Children.Add(translation2DGroup); #endregion #region Rotation Models rotationX = GetGeometryModel(RotationXGeometry, DiffuseMaterials.Red); rotationY = GetGeometryModel(RotationXGeometry, DiffuseMaterials.Green); rotationZ = GetGeometryModel(RotationXGeometry, DiffuseMaterials.Blue); rotationY.Transform = new Media3D.MatrixTransform3D(rotationYMatrix.ToMatrix3D()); rotationZ.Transform = new Media3D.MatrixTransform3D(rotationZMatrix.ToMatrix3D()); rotationX.Mouse3DDown += Rotation_Mouse3DDown; rotationY.Mouse3DDown += Rotation_Mouse3DDown; rotationZ.Mouse3DDown += Rotation_Mouse3DDown; rotationX.Mouse3DMove += Rotation_Mouse3DMove; rotationY.Mouse3DMove += Rotation_Mouse3DMove; rotationZ.Mouse3DMove += Rotation_Mouse3DMove; rotationX.Mouse3DUp += Manipulation_Mouse3DUp; rotationY.Mouse3DUp += Manipulation_Mouse3DUp; rotationZ.Mouse3DUp += Manipulation_Mouse3DUp; rotationGroup = new GroupModel3D(); rotationGroup.Children.Add(rotationX); rotationGroup.Children.Add(rotationY); rotationGroup.Children.Add(rotationZ); ctrlGroup.Children.Add(rotationGroup); #endregion #region Scaling Models scaleX = GetGeometryModel(ScalingGeometry, DiffuseMaterials.Red); scaleY = GetGeometryModel(ScalingGeometry, DiffuseMaterials.Green); scaleZ = GetGeometryModel(ScalingGeometry, DiffuseMaterials.Blue); scaleY.Transform = new Media3D.MatrixTransform3D(rotationYMatrix.ToMatrix3D()); scaleZ.Transform = new Media3D.MatrixTransform3D(rotationZMatrix.ToMatrix3D()); scaleX.Mouse3DDown += Scaling_Mouse3DDown; scaleY.Mouse3DDown += Scaling_Mouse3DDown; scaleZ.Mouse3DDown += Scaling_Mouse3DDown; scaleX.Mouse3DMove += Scaling_Mouse3DMove; scaleY.Mouse3DMove += Scaling_Mouse3DMove; scaleZ.Mouse3DMove += Scaling_Mouse3DMove; scaleX.Mouse3DUp += Manipulation_Mouse3DUp; scaleY.Mouse3DUp += Manipulation_Mouse3DUp; scaleZ.Mouse3DUp += Manipulation_Mouse3DUp; scaleGroup = new GroupModel3D(); scaleGroup.Children.Add(scaleX); scaleGroup.Children.Add(scaleY); scaleGroup.Children.Add(scaleZ); ctrlGroup.Children.Add(scaleGroup); #endregion Children.Add(ctrlGroup); xrayEffect = new PostEffectMeshXRayGrid() { EffectName = xrayEffectName, DimmingFactor = 0.5, BlendingFactor = 0.8, GridDensity = 4, GridColor = Media.Colors.Gray }; (xrayEffect.SceneNode as NodePostEffectXRayGrid).XRayDrawingPassName = DefaultPassNames.EffectMeshDiffuseXRayGridP3; Children.Add(xrayEffect); SceneNode.Attached += SceneNode_OnAttached; SceneNode.Detached += SceneNode_OnDetached; }