private int AddModelFaces(Matrix3D parentMatrix, Model3D model) { if (model.Transform != null) parentMatrix = model.Transform.Value * parentMatrix; int result = 0; Model3DGroup models = (model as Model3DGroup); if (models != null) { // This is a group. Recurse through the children foreach (Model3D m in models.Children) { result += AddModelFaces(parentMatrix, m); } } else { if (!(model is GeometryModel3D)) throw new InvalidOperationException("Current only GeometryModel3D models supported for TerrianCollisionMask3D."); Geometry3D geometry = ((GeometryModel3D)model).Geometry; IList<Point3D> meshPoints = GeometryHelper.GetGeometryPoints((MeshGeometry3D)geometry, parentMatrix); if (meshPoints != null) { AddFaces(meshPoints, 3, false); result = meshPoints.Count; } } return result; }
public void Export(Model3D model) { object obj = model; if (CreateResourceDictionary) obj = WrapInResourceDictionary(obj); XamlWriter.Save(obj, xw); }
public static Rect3D PreviewModelVolmetic(string modelFile, out Model3D model) { if (modelFile != null) { try { model = MeshHelper.Load(modelFile, ignoreErrors: true); } catch { model = null; return Rect3D.Empty; } if (model.Bounds == Rect3D.Empty) { model = null; return Rect3D.Empty; } return model.Bounds; } model = null; return Rect3D.Empty; }
public Pokemon3D(OnboardPokemon pokemon) { MeshGeometry3D mesh = new MeshGeometry3D(); mesh.Positions = new Point3DCollectionConverter().ConvertFromString("0,0,-1 0,1,-1 1,0,-1 1,1,-1") as Point3DCollection; mesh.TriangleIndices = TRIANGLE_INDICES; mesh.TextureCoordinates = TEXTURE_COORDINATES; Model = new GeometryModel3D(mesh, new DiffuseMaterial(Brushes.Red)); }
public MainWindow() { InitializeComponent(); viewport.DefaultCamera = defineCamera(leg.MaxLegLength); viewport.Children.Add(defineGrid(leg.MaxLegLength)); leg3dRender = new Leg3dRender(viewport, leg); model = leg3dRender.Model; mainGrid.DataContext = this; }
protected int ComparisonForSort(System.Windows.Media.Media3D.Model3D x, System.Windows.Media.Media3D.Model3D y) { if (x.Bounds.Z < y.Bounds.Z) { return(-1); } else if (x.Bounds.Z > y.Bounds.Z) { return(1); } return(0); }
public Leg3dRender(HelixViewport3D viewport,Leg legModel) { this.legModel = legModel; this.viewport = viewport; this.bodyCoxaLen = legModel.BodyCoxaLength; this.femurLen = legModel.FemurLength; this.tibiaLen = legModel.TibiaLength; this.jointDiameter = bodyCoxaLen * 0.7; this.jointHeight = jointDiameter; this.linkDiameter = jointDiameter * 0.7; this.footRadius = linkDiameter * 0.6; Model = buildLegModel(); coxaAngleLabel.Text = ""; coxaAngleLabel.FontSize = FONT_SIZE; coxaAngleLabel.FontFamily = new FontFamily("Arial"); coxaAngleLabel.Foreground = textColor; coxaAngleLabel.BorderBrush = textColor; coxaAngleLabel.Padding = new System.Windows.Thickness(5); coxaAngleLabel.BorderThickness = new System.Windows.Thickness(1); femurAngleLabel.Text = ""; femurAngleLabel.FontSize = FONT_SIZE; femurAngleLabel.FontFamily = new FontFamily("Arial"); femurAngleLabel.Foreground = textColor; femurAngleLabel.BorderBrush = textColor; femurAngleLabel.Padding = new System.Windows.Thickness(5); femurAngleLabel.BorderThickness = new System.Windows.Thickness(1); tibiaAngleLabel.Text = ""; tibiaAngleLabel.FontSize = FONT_SIZE; tibiaAngleLabel.FontFamily = new FontFamily("Arial"); tibiaAngleLabel.Foreground = textColor; tibiaAngleLabel.BorderBrush = textColor; tibiaAngleLabel.Padding = new System.Windows.Thickness(5); tibiaAngleLabel.BorderThickness = new System.Windows.Thickness(1); viewport.Children.Add(coxaAngleLabel); viewport.Children.Add(femurAngleLabel); viewport.Children.Add(tibiaAngleLabel); viewport.Children.Add(buildBody()); updateLeg(); }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors internal RayMeshGeometry3DHitTestResult( Visual3D visualHit, Model3D modelHit, MeshGeometry3D meshHit, Point3D pointHit, double distanceToRayOrigin, int vertexIndex1, int vertexIndex2, int vertexIndex3, Point barycentricCoordinate) : base (visualHit, modelHit) { _meshHit = meshHit; _pointHit = pointHit; _distanceToRayOrigin = distanceToRayOrigin; _vertexIndex1 = vertexIndex1; _vertexIndex2 = vertexIndex2; _vertexIndex3 = vertexIndex3; _barycentricCoordinate = barycentricCoordinate; }
private void WireframeHelper(Model3D model, Matrix3DStack matrixStack) { Transform3D transform = model.Transform; if (transform != null && transform != Transform3D.Identity) { matrixStack.Prepend(model.Transform.Value); } try { Model3DGroup group = model as Model3DGroup; if (group != null) { WireframeHelper(group, matrixStack); return; } GeometryModel3D geometry = model as GeometryModel3D; if (geometry != null) { WireframeHelper(geometry, matrixStack); return; } } finally { if (transform != null && transform != Transform3D.Identity) { matrixStack.Pop(); } } }
private void FileOpen() { CurrentModelPath = FileDialogService.OpenFileDialog("models", null, OpenFileFilter, ".3ds"); #if !DEBUG try { #endif CurrentModel = ModelImporter.Load(CurrentModelPath); ApplicationTitle = String.Format(TitleFormatString, CurrentModelPath); HelixView.ZoomToFit(0); #if !DEBUG } catch (Exception e) { MessageBox.Show(e.Message); } #endif }
private void UpdateModel() { // http://en.wikipedia.org/wiki/Lorenz_attractor Func<double[], double[]> lorenzAttractor = x => { var dx = new double[3]; dx[0] = sigma * (x[1] - x[0]); dx[1] = x[0] * (rho - x[2]) - x[1]; dx[2] = x[0] * x[1] - beta * x[2]; return dx; }; // solve the ODE var x0 = new[] { 0, 1, 1.05 }; IEnumerable<double[]> solution = EulerSolver(lorenzAttractor, x0, 25); // todo: should have a better ODE solver (R-K(4,5)? http://www.mathworks.com/help/techdoc/ref/ode45.html) List<Point3D> path = solution.Select(x => new Point3D(x[0], x[1], x[2])).ToList(); // create the WPF3D model var m = new Model3DGroup(); var gm = new MeshBuilder(); gm.AddTube(path, 0.8, 10, false); if (directionArrows) { // sphere at the initial point gm.AddSphere(path[0], 1); // arrow heads every 100 point for (int i = 100; i + 1 < path.Count; i += 100) { gm.AddArrow(path[i], path[i + 1], 0.8); } // arrow head at the end Point3D p0 = path[path.Count - 2]; Point3D p1 = path[path.Count - 1]; var d = new Vector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z); d.Normalize(); Point3D p2 = p1 + d * 2; gm.AddArrow(p1, p2, 0.8); } m.Children.Add(new GeometryModel3D(gm.ToMesh(), Materials.Gold)); Model = m; }
/// <summary> /// Create the base of the plot. /// This includes the arrows for North and East, the cylinder and /// the center tube. /// </summary> /// <param name="numBins">Number of bins in the plot.</param> private void CreateBase(int numBins) { // Create the North and East arrow _northArrow = NorthArrow(numBins); // Create North arrow _eastArrow = EastArrow(numBins); // Create East arrow _originTube = CreateOriginTube(numBins); // Create Origin Tube _cylinder = CreateCylinder(numBins); // Create cylinder }
// isSubpropertyChange indicates whether a subproperty on Visual3DModel changed. // In this case oldValue is ignored, since the value hasn't changed. If it isn't a // sub property change, then oldValue gives the previous value of the Visual3DModel property. private void Visual3DModelPropertyChanged(Model3D oldValue, bool isSubpropertyChange) { if (!isSubpropertyChange) { if (oldValue != null) { DisconnectAttachedResource(VisualProxyFlags.IsContentDirty, oldValue); } SetFlagsOnAllChannels(true, VisualProxyFlags.IsContentDirty); } SetFlags(false, VisualFlags.Are3DContentBoundsValid); RenderChanged(/* sender = */ this, EventArgs.Empty); }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors // Prevent 3rd parties from extending this abstract base class. internal RayHitTestResult(Visual3D visualHit, Model3D modelHit) : base (visualHit) { _modelHit = modelHit; }
/// <summary> /// Adds the a voxel adjacent to the specified model. /// </summary> /// <param name="source">The source.</param> /// <param name="normal">The normal.</param> public void Add(Model3D source, Vector3D normal) { if (!ModelToVoxel.ContainsKey(source)) return; var v = ModelToVoxel[source]; AddVoxel(v.Position + normal); }
/// <summary> /// This overload takes a model, which should contain a mesh /// </summary> public static Point3D[] GetPointsFromMesh(Model3D model, Transform3D transform = null) { List<Point3D> retVal = new List<Point3D>(); if (model is Model3DGroup) { foreach (var child in ((Model3DGroup)model).Children) { // Recurse retVal.AddRange(GetPointsFromMesh(child, transform)); } } else if (model is GeometryModel3D) { Geometry3D geometry = ((GeometryModel3D)model).Geometry; if (geometry is MeshGeometry3D) { retVal.AddRange(GetPointsFromMesh((MeshGeometry3D)geometry, null)); //NOTE: Only applying the transform passed in once } else { throw new ArgumentException("Unexpected type of geometry: " + geometry.GetType().ToString()); } } else { throw new ArgumentException("Unexpected type of model: " + model.GetType().ToString()); } // Apply transforms IEnumerable<Point3D> transformed = retVal; if (model.Transform != null && model.Transform != Transform3D.Identity) { transformed = transformed.Select(o => model.Transform.Transform(o)); } if (transform != null) { transformed = transformed.Select(o => model.Transform.Transform(o)); } return transformed.ToArray(); }
/// <summary> /// 为了旋转战斗,两个场地还是要用两个模型 /// </summary> /// <param name="x"></param> /// <param name="r"></param> /// <param name="terrain"></param> public Terrain3D(double z, double r, TerrainType terrain) { MeshGeometry3D mesh = new MeshGeometry3D(); Point3D p3d = new Point3D(); p3d.Y = 0; for (int i = 0; i < 17; i++) { p3d.X = SX[i] * r; p3d.Z = SZ[i] * r + z; mesh.Positions.Add(p3d); } mesh.TextureCoordinates = TEXTURE_COORDINATES; mesh.TriangleIndices = TRIANGLE_INDICES; Model = new GeometryModel3D(mesh, GetMaterial(terrain)); }
/// <summary> /// Exports the specified model. /// </summary> /// <param name="model"> /// The model. /// </param> public void Export(Model3D model) { object obj = model; if (this.CreateResourceDictionary) { obj = WrapInResourceDictionary(obj); } XamlWriter.Save(obj, this.writer); }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors // Prevent 3rd parties from extending this abstract base class. internal RayHitTestResult(Visual3D visualHit, Model3D modelHit) : base(visualHit) { _modelHit = modelHit; }
public void GetTransform3DGroup(Model3D model) { }
/// <summary> /// Exports the specified model. /// </summary> /// <param name="model"> /// The model. /// </param> public void Export(Model3D model) { this.ExportHeader(); Visual3DHelper.TraverseModel<GeometryModel3D>(model, this.ExportModel); }
private void LoadMesh(double fieldOfView) { if ((myViewport3D != null) && (modelGroup.Children.Count > 0)) { myViewport3D.Children.Remove(modelsVisual); modelGroup.Children.Clear(); } ((PerspectiveCamera)myViewport3D.Camera).FieldOfView = fieldOfView; // Define the material for the model. SolidColorBrush brush = new SolidColorBrush(Colors.Cyan); DiffuseMaterial colorMaterial = new DiffuseMaterial(brush); // Load the mesh for the model. MeshGeometry3D objMesh = (MeshGeometry3D)Application.Current.Resources[_mesh]; objModel = new GeometryModel3D(objMesh, colorMaterial); // Define the projection camera and add to the model. SetProjectionCamera(myViewport3D, modelGroup); modelGroup.Children.Add(objModel); // Add ambient light to the model group. if (checkBoxAmbientLight.IsChecked == true) { myLights.ShowAmbientLight(true, modelGroup); } // Add directional lights to the model group. if (checkBoxDirLightOne.IsChecked == true) { myLights.ShowDirLight(0, true, modelGroup); } if (checkBoxDirLightTwo.IsChecked == true) { myLights.ShowDirLight(1, true, modelGroup); } // Add the model group data to the viewport. modelsVisual.Content = modelGroup; myViewport3D.Children.Add(modelsVisual); checkBoxPointLight.IsChecked = false; xyzPointLight.Foreground = System.Windows.Media.Brushes.LightGray; currKeyMode = KeyMode.Camera; rbPosition1.IsChecked = true; }
/// <summary> /// Exports the specified model. /// </summary> /// <param name="model"> /// The model. /// </param> public void Export(Model3D model) { throw new NotImplementedException(); }
/// <summary> /// Highlights the specified voxel model. /// </summary> /// <param name="model">The model.</param> public void HighlightVoxel(Model3D model) { foreach (GeometryModel3D m in Model.Children) { if (!ModelToVoxel.ContainsKey(m)) continue; var v = ModelToVoxel[m]; var om = OriginalMaterial[m]; // highlight color var hc = Color.FromArgb(0x80, v.Colour.R, v.Colour.G, v.Colour.B); m.Material = m == model ? MaterialHelper.CreateMaterial(hc) : om; } }
/// <summary> /// Loads and displays the given Xaml file. Expects the root of /// the Xaml file to be a Model3D. /// </summary> public void LoadModel(System.IO.Stream fileStream) { _model = (Model3D)XamlReader.Load(fileStream); SetupScene(); }
public void Remove(Model3D model) { if (!ModelToVoxel.ContainsKey(model)) return; var v = ModelToVoxel[model]; Voxels.Remove(v); UpdateModel(); }
/// <summary> /// Determines whether the specified model is transparent. /// </summary> /// <param name="model"> /// The model. /// </param> /// <returns> /// <c>true</c> if the specified model is transparent; otherwise, <c>false</c>. /// </returns> public static bool IsTransparent(Model3D model) { var gm3D = model as GeometryModel3D; if (gm3D != null) { if (IsTransparent(gm3D)) { return true; } } var mg = model as Model3DGroup; if (mg != null) { return mg.Children.Any(IsTransparent); } return false; }
void hvpcanvas_MouseDown(object sender, MouseButtonEventArgs e) { Point location = e.GetPosition(hvpcanvas); ModelVisual3D result = GetHitTestResult(location); if (rayResult != null) { point2 = rayResult.PointHit; model2 = rayResult.ModelHit; System.Diagnostics.Debug.WriteLine(point2.X + ":" + point2.Y + ":" + point2.Z); } }
/// <summary> /// Hit test Result /// </summary> /// <param name="rawresult">Result Parameter</param> /// <returns></returns> private HitTestResultBehavior HTResult(HitTestResult rawresult) { RayHitTestResult rayResult = rawresult as RayHitTestResult; if (rayResult != null) { RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as RayMeshGeometry3DHitTestResult; if (rayMeshResult != null && rayMeshResult.VisualHit.GetType().Name == "ModelVisual3D") { hitgeo = rayMeshResult.ModelHit as GeometryModel3D; joint = Session.CurrentSession.CurrentProject.CurrentModel3D.Joints.FindJointByMatrix(hitgeo.Transform.Value); if (joint != null) { targetModel = Session.CurrentSession.CurrentProject.CurrentModel3D.Content.Find(hitgeo); BaseOffsetX = hitgeo.Transform.Value.OffsetX; BaseOffsetY = hitgeo.Transform.Value.OffsetY; BaseOffsetZ = hitgeo.Transform.Value.OffsetZ; } else hitgeo = null; } else hitgeo = null; } return HitTestResultBehavior.Stop; }
public void MakeWireframe(Model3D model) { this.Points.Clear(); if (model == null) { return; } Matrix3DStack transform = new Matrix3DStack(); transform.Push(Matrix3D.Identity); WireframeHelper(model, transform); }
/// <summary> /// Shows a preview voxel adjacent to the specified model (source). /// If source is null, hide the preview. /// </summary> /// <param name="source">The source.</param> /// <param name="normal">The normal.</param> public void PreviewVoxel(Model3D source, Vector3D normal = default(Vector3D)) { if (PreviewModel != null) Model.Children.Remove(PreviewModel); PreviewModel = null; if (source == null) return; if (!ModelToVoxel.ContainsKey(source)) return; var v = ModelToVoxel[source]; var previewColor = Color.FromArgb(0x80, CurrentColor.R, CurrentColor.G, CurrentColor.B); var pv = new Voxel(v.Position + normal, previewColor); PreviewModel = CreateVoxelModel3D(pv); Model.Children.Add(PreviewModel); }
public static ABScene3D FromAvalonObj(Model3D avalonObj) { return null; }