protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (this.IsMouseCaptured) { var hitPlaneOrigin = this.ToWorld(this.Position); var p = e.GetPosition(this.ParentViewport); var nearestPoint = this.GetNearestPoint(p, hitPlaneOrigin, this.HitPlaneNormal); if (nearestPoint == null) { return; } var delta = this.ToLocal(nearestPoint.Value) - this.lastPoint; this.Value += Vector3D.DotProduct(delta, this.Direction); if (this.TargetTransform != null) { var translateTransform = new TranslateTransform3D(delta); this.TargetTransform = Transform3DHelper.CombineTransform(translateTransform, this.TargetTransform); } else { // this.Position += delta; var transform = new TranslateTransform3D(delta); this.Transform = Transform3DHelper.CombineTransform(this.Transform, transform); } nearestPoint = this.GetNearestPoint(p, hitPlaneOrigin, this.HitPlaneNormal); if (nearestPoint != null) { this.lastPoint = this.ToLocal(nearestPoint.Value); } } }
protected void ExportModel(GeometryModel3D model, Transform3D transform) { //this.writer.WriteLine(string.Format("o object{0}", this.objectNo++)); //this.writer.WriteLine(string.Format("g group{0}", this.groupNo++)); var mesh = model.Geometry as MeshGeometry3D; this.ExportMesh(mesh, Transform3DHelper.CombineTransform(transform, model.Transform)); }
private void Traverse <T>(Visual3D visual, Transform3D transform, Action <T, Transform3D> action) where T : Model3D { var childTransform = Transform3DHelper.CombineTransform(visual.Transform, transform); var model = GetModel(visual); if (model != null) { if (jawVisual != null) { } else if (rawVisual != null) { } if (visual is TeethVisual3D) { TeethVisual3D t = (TeethVisual3D)visual; this.writer.WriteLine(string.Format("g jaw_{0}", t.Id)); } else if (visual is GumVisual3D) { GumVisual3D t = (GumVisual3D)visual; this.writer.WriteLine(string.Format("g jaw_{0}", t.Id)); } else if (visual is BraceVisual3D) { BraceVisual3D t = (BraceVisual3D)visual; this.writer.WriteLine(string.Format("g jaw_{0}", t.Id)); } else if (visual is WireVisual3D) { } else { this.writer.WriteLine(string.Format("g jaw_group{0}", this.groupNo++)); } if (visual is Manipulator || visual is BoundingBoxWireFrameVisual3D) { } else { TraverseModel(model, childTransform, action); } } foreach (var child in GetChildren(visual)) { Traverse(child, childTransform, action); } }
/// <summary> /// Invoked when an unhandled <see cref="E:System.Windows.Input.Mouse.MouseMove" /> attached event reaches an element in /// its route that is derived from this class. Implement this method to add class handling for this event. /// </summary> /// <param name="e"> /// The <see cref="T:System.Windows.Input.MouseEventArgs" /> that contains the event data. /// </param> protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (!IsMouseCaptured) { return; } var hitPlaneOrigin = ToWorld(Center); var p = e.GetPosition(ParentViewport); var nearestPoint = GetHitPlanePoint(p, hitPlaneOrigin, Normal); if (nearestPoint == null) { return; } var point = ToLocal(nearestPoint.Value); var delta = point - _lastPoint; if (TargetTransform != null) { var translateTransform = new TranslateTransform3D(delta); TargetTransform = Transform3DHelper.CombineTransform(translateTransform, TargetTransform); } else { var newcenter = Center + delta; var moveEventArgs = new MoveEventArgs(MoveEvent, newcenter); RaiseEvent(moveEventArgs); if (moveEventArgs.Cancel) { return; } Center = newcenter; } _lastPoint = point; }
public static void TraverseModel <T>(Model3D model, Transform3D transform, Action <T, Transform3D> action) where T : Model3D { var mg = model as Model3DGroup; if (mg != null) { var childTransform = Transform3DHelper.CombineTransform(model.Transform, transform); foreach (var m in mg.Children) { TraverseModel(m, childTransform, action); } } var gm = model as T; if (gm != null) { var childTransform = Transform3DHelper.CombineTransform(model.Transform, transform); action(gm, childTransform); } }
/// <summary> /// The export model. /// </summary> /// <param name="model"> /// The model. /// </param> /// <param name="transform"> /// The transform. /// </param> protected void ExportModel(GeometryModel3D model, Transform3D transform) { this.writer.WriteLine(string.Format("o object{0}", this.objectNo++)); //this.writer.WriteLine(string.Format("g group{0}", this.groupNo++)); //IEnumerable<DependencyObject> p = model.Ancestors(); if (this.exportedMaterials.ContainsKey(model.Material)) { string matName = this.exportedMaterials[model.Material]; this.writer.WriteLine(string.Format("usemtl {0}", matName)); } else { string matName = string.Format("mat{0}", this.matNo++); this.writer.WriteLine(string.Format("usemtl {0}", matName)); this.ExportMaterial(matName, model.Material, model.BackMaterial); this.exportedMaterials.Add(model.Material, matName); } var mesh = model.Geometry as MeshGeometry3D; this.ExportMesh(mesh, Transform3DHelper.CombineTransform(transform, model.Transform)); }
/// <summary> /// The export model. /// </summary> /// <param name="model"> /// The model. /// </param> /// <param name="transform"> /// The transform. /// </param> protected override void ExportModel(GeometryModel3D model, Transform3D transform) { #if TODO_MATERIAL this.writer.WriteLine(string.Format("o object{0}", this.objectNo++)); this.writer.WriteLine(string.Format("g group{0}", this.groupNo++)); if (this.exportedMaterials.ContainsKey(model.Material)) { string matName = this.exportedMaterials[model.Material]; this.writer.WriteLine(string.Format("usemtl {0}", matName)); } else { string matName = string.Format("mat{0}", this.matNo++); this.writer.WriteLine(string.Format("usemtl {0}", matName)); this.ExportMaterial(matName, model.Material, model.BackMaterial); this.exportedMaterials.Add(model.Material, matName); } var mesh = model.Geometry as MeshGeometry3D; this.ExportMesh(mesh, Transform3DHelper.CombineTransform(transform, model.Transform)); #endif }
private void CreateLotModel() { //Create the plane representing the lot (texture & size) if (UnitFileEntry.LotOverlayBoxSize != null) { Vector2Property lotSize = UnitFileEntry.LotOverlayBoxSize; RectangleVisual3D groundPlane = new RectangleVisual3D(); groundPlane.Width = (lotSize.X); groundPlane.Length = (lotSize.Y); groundPlane.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), -90)); if (UnitFileEntry.LotOverlayBoxOffset != null) { // groundPlane.Transform = Transform3DHelper.CombineTransform(groundPlane.Transform, new TranslateTransform3D(-1 * UnitFileEntry.LotOverlayBoxOffset.X, -1 * UnitFileEntry.LotOverlayBoxOffset.Y, 0)); } if (UnitFileEntry.LotPlacementTransform != null && UnitFileEntry.LotPlacementTransform.Count > 0) { groundPlane.Transform = Transform3DHelper.CombineTransform(groundPlane.Transform, (Transform3D) new MatrixTransform3D(UnitFileEntry.LotPlacementTransform[0].GetAsMatrix3D()).Inverse); } if (UnitFileEntry.LotMask != null) { DatabaseIndex index = DatabaseManager.Instance.Indices.Find(k => k.InstanceId == UnitFileEntry.LotMask.InstanceId && k.TypeId == 0x2f4e681c); if (index != null) { Color color1 = Colors.Black; Color color2 = Colors.Red; Color color3 = Colors.Green; Color color4 = Colors.Blue; if (UnitFileEntry.LotColor1 != null) { color1 = Color.FromRgb((byte)(255 * UnitFileEntry.LotColor1.R), (byte)(255 * UnitFileEntry.LotColor1.G), (byte)(255 * UnitFileEntry.LotColor1.B)); } if (UnitFileEntry.LotColor2 != null) { color2 = Color.FromRgb((byte)(255 * UnitFileEntry.LotColor2.R), (byte)(255 * UnitFileEntry.LotColor2.G), (byte)(255 * UnitFileEntry.LotColor2.B)); } if (UnitFileEntry.LotColor3 != null) { color3 = Color.FromRgb((byte)(255 * UnitFileEntry.LotColor3.R), (byte)(255 * UnitFileEntry.LotColor3.G), (byte)(255 * UnitFileEntry.LotColor3.B)); } if (UnitFileEntry.LotColor4 != null) { color4 = Color.FromRgb((byte)(255 * UnitFileEntry.LotColor4.R), (byte)(255 * UnitFileEntry.LotColor4.G), (byte)(255 * UnitFileEntry.LotColor4.B)); } using (MemoryStream byteStream = new MemoryStream(index.GetIndexData(true))) { RasterImage rasterImage = RasterImage.CreateFromStream(byteStream, RasterChannel.Preview, color4, color3, color2, color1); groundPlane.Material = new DiffuseMaterial(new ImageBrush(rasterImage.MipMaps[0])); } } groundPlane.BackMaterial = new DiffuseMaterial(new SolidColorBrush(Colors.Transparent)); } viewPort.Children.Add(groundPlane); } }