public SceneVisual3DPoly(Point3DCollection points, Scene[] sceneobjects, Color color, Transform3D trans) { _points = points.Clone(); KneeInnovation3D.EntityTools.Polygon3D.Transform(_points, trans); _polycolor = color; SetTheScene(sceneobjects); }
public Point3DCollection GetProjectedPointList(Point3DCollection points, FilterOptions options, double searchRadius) { Point3DCollection projectedPoints = points.Clone(); for (int i = 0; i < points.Count; i++) { projectedPoints[i] = GetProjectedPoint(points[i], options, searchRadius); } return(projectedPoints); }
//********************************************** // IClonable implementation public object Clone() { Bulkhead copy = new Bulkhead { Type = Type, m_transomAngle = TransomAngle, m_points = m_points.Clone() }; return(copy); }
public static void Reverse(Point3DCollection curve) { Point3DCollection copied = curve.Clone(); curve.Clear(); foreach (Point3D p in copied.Reverse()) { curve.Add(p); } copied = null; }
private void CompositionTarget_Rendering(object sender, EventArgs e) { RenderingEventArgs rargs = (RenderingEventArgs)e; if ((rargs.RenderingTime.TotalMilliseconds - _lastTimeRendered) > RENDER_INTERVAL && _hasWaves) { bool needRefresh = RefreshWaveData(); if (needRefresh) { _meshGeometry3D.Positions = Points; //着色 _meshGeometry3D.TextureCoordinates.Clear(); foreach (Point3D p3d in _meshGeometry3D.Positions) { double dev = Math.Abs(p3d.Z + 50) / 5; Color color = Color.FromArgb((byte)(dev * 255), (byte)(dev * 255), 0, 0); Point mapPt = _textureMapping.GetMappingPosition(color); _meshGeometry3D.TextureCoordinates.Add(new Point(mapPt.X, mapPt.Y)); } _lastTimeRendered = rargs.RenderingTime.TotalMilliseconds; } else { _meshGeometry3D.Positions = _originalPoint3DBuffer.Clone(); _currentPoint3DBuffer = _originalPoint3DBuffer.Clone(); _previousPoint3DBuffer = _originalPoint3DBuffer.Clone(); _lastTimeRendered = rargs.RenderingTime.TotalMilliseconds; lock (_updateHasWavesLock) { _hasWaves = false; } } } }
/// <summary> /// Toggles whether or not vertices are shared between triangles or not allowing smoothing of normalvectors. /// </summary> /// <remarks> /// This method assumes that the original mesh is smooth. /// </remarks> public void ToggleSmooth() { if (smooth) { var newPos = new Point3DCollection(); var newSteps = new StepInfo[_steps.Length]; var index = 0; for (int i = 0; i < _steps.Length; i++) { newSteps[i] = new StepInfo { Center = _steps[i].Center, HalfDist = _steps[i].HalfDist, triangles = new List <int[]>() }; for (int j = 0; j < _steps[i].triangles.Count; j++) { var old = _steps[i].triangles[j]; foreach (var ind in old) { newPos.Add(_mainMesh.Positions[ind]); } newSteps[i].triangles.Add(new[] { index++, index++, index++ }); } } _mainMesh.Positions = newPos; _steps = newSteps; } else { _mainMesh.Positions = smoothPos.Clone(); _steps = smoothSteps; } _mainMesh.TriangleIndices.Clear(); if (_mainMesh.Positions.Count != 0) { _mainMesh.TriangleIndices.Add(0); _mainMesh.TriangleIndices.Add(0); _mainMesh.TriangleIndices.Add(0); } _stepcount = 0; if (_showFull) { IncrementTo(MaxValue); _stepcount = _stepValue; } else { IncrementTo(_stepValue); } smooth = !smooth; }
/// <summary> /// Noktaları / üçgenleri temizleyin ve yeniler /// </summary> /// <param name="grid"></param> private void InitializePointsAndTriangles() { _ptBuffer1.Clear(); _ptBuffer2.Clear(); _triangleIndices.Clear(); int nCurrIndex = 0; // March through 1-D arrays for (int row = 0; row < _dimension; row++) { for (int col = 0; col < _dimension; col++) { //ızgarada, X / Y değerleri yalnızca satır / sütun sayılarıdır _ptBuffer1.Add(new Point3D(col, 0.0, row)); // Yeni kare tamamlandığında, 2 üçgen ekleyin if ((row > 0) && (col > 0)) { // Triangle 1 _triangleIndices.Add(nCurrIndex - _dimension - 1); _triangleIndices.Add(nCurrIndex); _triangleIndices.Add(nCurrIndex - _dimension); // Triangle 2 _triangleIndices.Add(nCurrIndex - _dimension - 1); _triangleIndices.Add(nCurrIndex - 1); _triangleIndices.Add(nCurrIndex); } nCurrIndex++; } } //2. tampon, yalnızca 2. Z değeri setine sahip _ptBuffer2 = _ptBuffer1.Clone(); }
/// <summary> /// Clear out points/triangles and regenerates /// </summary> /// <param name="grid"></param> private void InitializePointsAndTriangles() { _ptBuffer1.Clear(); _ptBuffer2.Clear(); _triangleIndices.Clear(); int nCurrIndex = 0; // March through 1-D arrays for (int row = 0; row < _dimension; row++) { for (int col = 0; col < _dimension; col++) { // In grid, X/Y values are just row/col numbers _ptBuffer1.Add(new Point3D(col, 0.0, row)); // Completing new square, add 2 triangles if ((row > 0) && (col > 0)) { // Triangle 1 _triangleIndices.Add(nCurrIndex - _dimension - 1); _triangleIndices.Add(nCurrIndex); _triangleIndices.Add(nCurrIndex - _dimension); // Triangle 2 _triangleIndices.Add(nCurrIndex - _dimension - 1); _triangleIndices.Add(nCurrIndex - 1); _triangleIndices.Add(nCurrIndex); } nCurrIndex++; } } // 2nd buffer exists only to have 2nd set of Z values _ptBuffer2 = _ptBuffer1.Clone(); }
/// <summary> /// Set height of all points in mesh to 0.0. Also resets buffers to /// original state. /// </summary> public void InitWaveMedium() { Point3D pt; for (int i = 0; i < (_dimension * _dimension); i++) { pt = _point3DBuffer1[i]; pt.Z = _zValue; _point3DBuffer1[i] = pt; } _point3DBuffer2 = _point3DBuffer1.Clone(); _currentPoint3DBuffer = _point3DBuffer2; _previousPoint3DBuffer = _point3DBuffer1; }
private void InitializeWaveMedium() { _point3DBuffer1 = new Point3DCollection(_dimension * _dimension); _triangleIndices = new Int32Collection((_dimension - 1) * (_dimension - 1) * 2); double columnUnit = (_endPoint.X - _beginPoint.X) / _dimension; double rowUnit = (_endPoint.Y - _beginPoint.Y) / _dimension; int currentIndex = 0; for (int row = 0; row < _dimension; row++) { for (int col = 0; col < _dimension; col++) { _point3DBuffer1.Add(new Point3D(col * columnUnit, row * rowUnit, _zValue)); if ((row > 0) && (col > 0)) { // Triangle 1 _triangleIndices.Add(currentIndex - _dimension - 1); _triangleIndices.Add(currentIndex); _triangleIndices.Add(currentIndex - _dimension); // Triangle 2 _triangleIndices.Add(currentIndex - _dimension - 1); _triangleIndices.Add(currentIndex - 1); _triangleIndices.Add(currentIndex); } currentIndex++; } } _point3DBuffer2 = _point3DBuffer1.Clone(); _originalPoint3DBuffer = _point3DBuffer1.Clone(); }
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock) { Point3DCollection fromVal = ((Point3DCollection)GetValue(Point3DCollectionAnimation.FromProperty)); Point3DCollection toVal = ((Point3DCollection)GetValue(Point3DCollectionAnimation.ToProperty)); Point3DCollection ret; int t = 0; if (fromVal.Count > toVal.Count) { ret = fromVal.Clone(); foreach (Point3D tov in toVal) { Point3D frov = fromVal[t]; Point3D newv = new Point3D(); newv.X = (double)animationClock.CurrentProgress * (tov.X - frov.X) + frov.X; newv.Y = (double)animationClock.CurrentProgress * (tov.Y - frov.Y) + frov.Y; newv.Z = (double)animationClock.CurrentProgress * (tov.Z - frov.Z) + frov.Z; ret[t] = newv; t++; } } else { ret = toVal.Clone(); foreach (Point3D frov in fromVal) { Point3D tov = toVal[t]; Point3D newv = new Point3D(); newv.X = (double)animationClock.CurrentProgress * (tov.X - frov.X) + frov.X; newv.Y = (double)animationClock.CurrentProgress * (tov.Y - frov.Y) + frov.Y; newv.Z = (double)animationClock.CurrentProgress * (tov.Z - frov.Z) + frov.Z; ret[t] = newv; t++; } } return(ret); }
protected override void BeginTransition3D(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport) { int xparticles = 10, yparticles = 10; Size size = transitionElement.RenderSize; if (size.Width > size.Height) { yparticles = (int)(xparticles * size.Height / size.Width); } else { xparticles = (int)(yparticles * size.Width / size.Height); } MeshGeometry3D mesh = CreateMesh(new Point3D(), new Vector3D(size.Width, 0, 0), new Vector3D(0, size.Height, 0), xparticles - 1, yparticles - 1, new Rect(0, 0, 1, 1)); Brush cloneBrush = CreateBrush(oldContent); Material clone = new DiffuseMaterial(cloneBrush); double ustep = size.Width / (xparticles - 1), vstep = size.Height / (yparticles - 1); Point3DCollection points = mesh.Positions; Point3DCollection oldPoints = points.Clone(); double timeStep = 1.0 / 30.0; DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(timeStep); double time = 0; double duration = this.Duration.HasTimeSpan ? this.Duration.TimeSpan.TotalSeconds : 2; timer.Tick += delegate { time = time + timeStep; Point mousePos = Mouse.GetPosition(viewport); Point3D mousePos3D = new Point3D(mousePos.X, mousePos.Y, -10); // Cloth physics based on work of Thomas Jakobsen http://www.ioi.dk/~thomas for (int i = 0; i < oldPoints.Count; i++) { Point3D currentPoint = points[i]; Point3D newPoint = currentPoint + 0.9 * (currentPoint - oldPoints[i]); if (newPoint.Y > size.Height) { newPoint.Y = size.Height; } oldPoints[i] = newPoint; } //for (int j = 0; j < 5; j++) //for (int i = oldPoints.Count - 1; i > 0 ; i--) for (int a = yparticles - 1; a >= 0; a--) { for (int b = xparticles - 1; b >= 0; b--) { int i = b * yparticles + a; // constrain with point to the left if (i > yparticles) { Constrain(oldPoints, i, i - yparticles, ustep); } // constrain with point to the top if (i % yparticles != 0) { Constrain(oldPoints, i, i - 1, vstep); } // constrain the sides if (a == 0) { oldPoints[i] = new Point3D(oldPoints[i].X, 0, oldPoints[i].Z); } if (a == yparticles - 1) { oldPoints[i] = new Point3D(oldPoints[i].X, size.Height, oldPoints[i].Z); } if (b == 0) { oldPoints[i] = new Point3D(0, a * size.Height / (yparticles - 1), 0); } if (b == xparticles - 1) { double angle = time / duration * Math.PI / (0.8 + 0.5 * (yparticles - (double)a) / yparticles); oldPoints[i] = new Point3D(size.Width * Math.Cos(angle), a * size.Height / (yparticles - 1), -size.Width * Math.Sin(angle)); } } } if (time > (duration - 0)) { timer.Stop(); EndTransition(transitionElement, oldContent, newContent); } // Swap position arrays mesh.Positions = oldPoints; oldPoints = points; points = mesh.Positions; }; timer.Start(); GeometryModel3D geo = new GeometryModel3D(mesh, clone); geo.BackMaterial = clone; ModelVisual3D model = new ModelVisual3D(); model.Content = geo; // Replace old content in visual tree with new 3d model transitionElement.HideContent(oldContent); viewport.Children.Add(model); }
private void Load_PositionsFromOrgMeshPos() { _Positions = _orgmeshpos.Clone(); }
protected override void BeginTransition3D(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport) { int xparticles = 15, yparticles = 15; Size size = transitionElement.RenderSize; if (size.Width > size.Height) { yparticles = (int)(xparticles * size.Height / size.Width); } else { xparticles = (int)(yparticles * size.Width / size.Height); } MeshGeometry3D mesh = CreateMesh(new Point3D(), new Vector3D(size.Width, 0, 0), new Vector3D(0, size.Height, 0), xparticles - 1, yparticles - 1, new Rect(0, 0, 1, 1)); Brush cloneBrush = CreateBrush(oldContent); Material clone = new DiffuseMaterial(cloneBrush); double ustep = size.Width / (xparticles - 1), vstep = size.Height / (yparticles - 1); Point3DCollection points = mesh.Positions; Random rand = new Random(); // add some random movement to the z order for (int i = 0; i < points.Count; i++) { points[i] += 0.1 * ustep * (rand.NextDouble() * 2 - 1) * new Vector3D(0, 0, 1); } Point3DCollection oldPoints = points.Clone(); Vector3D acceleration = new Vector3D(0, 700, 0); //gravity double timeStep = 1.0 / 60.0; DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(timeStep); bool fading = false; double time = 0; double slideVelocity = size.Width / 2.0; double windScale = 30 * size.Width * size.Height; timer.Tick += delegate { time = time + timeStep; Point mousePos = Mouse.GetPosition(viewport); Point3D mousePos3D = new Point3D(mousePos.X, mousePos.Y, -10); for (int i = 0; i < oldPoints.Count; i++) { Point3D currentPoint = points[i]; Vector3D wind = new Vector3D(0, 0, windScale / (mousePos3D - currentPoint).LengthSquared); Point3D newPoint = currentPoint + (currentPoint - oldPoints[i]) + timeStep * timeStep * (acceleration + wind); if (newPoint.Y > size.Height) { newPoint.Y = size.Height; } oldPoints[i] = newPoint; } //for (int j = 0; j < 5; j++) for (int i = oldPoints.Count - 1; i > 0; i--) { // constrain with point to the left if (i > yparticles) { Constrain(oldPoints, i, i - yparticles, ustep); } // constrain with point to the top if (i % yparticles != 0) { Constrain(oldPoints, i, i - 1, vstep); } } // slide the top row of points to the left for (int i = 0; i < xparticles; i += 1) { oldPoints[i * yparticles] = new Point3D(Math.Max(0, i * ustep - slideVelocity * time * i / (xparticles - 1)), 0, 0); } if (!fading && points[points.Count - yparticles].X < size.Width / 2) { fading = true; DoubleAnimation da = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(1.5))); da.Completed += delegate { timer.Stop(); EndTransition(transitionElement, oldContent, newContent); }; cloneBrush.BeginAnimation(Brush.OpacityProperty, da); } // Swap position arrays mesh.Positions = oldPoints; oldPoints = points; points = mesh.Positions; }; timer.Start(); GeometryModel3D geo = new GeometryModel3D(mesh, clone); geo.BackMaterial = clone; ModelVisual3D model = new ModelVisual3D(); model.Content = geo; viewport.Children.Add(model); }