// highlight the selection public override void HighlightSelection(System.Windows.Media.Media3D.MeshGeometry3D meshGeometry, System.Windows.Media.Color selectColor) { int nDotNo = GetDataNo(); if (nDotNo == 0) { return; } Point mapPt; for (int i = 0; i < nDotNo; i++) { if (m_vertices[i].selected) { mapPt = TextureMapping.GetMappingPosition(selectColor, false); } else { mapPt = TextureMapping.GetMappingPosition(m_vertices[i].color, false); } int nMin = m_vertices[i].nMinI; int nMax = m_vertices[i].nMaxI; for (int j = nMin; j <= nMax; j++) { meshGeometry.TextureCoordinates[j] = mapPt; } } }
public override void HighlightSelection(MeshGeometry3D meshGeometry, Color selectColor) { var nDotNo = GetDataNo(); if (nDotNo != 0) { for (var i = 0; i < nDotNo; i++) { var color = _vertices[i].IsSelected ? selectColor : _vertices[i].Color; var mapPt = TextureMapping.GetMappingPosition(color, true); var nMin = _vertices[i].MinI; meshGeometry.TextureCoordinates[nMin] = mapPt; } } }
// highlight the selection public override void HighlightSelection(MeshGeometry3D meshGeometry, System.Windows.Media.Color selectColor) { var nDotNo = GetDataNo(); if (nDotNo == 0) { return; } for (var i = 0; i < nDotNo; i++) { var mapPt = TextureMapping.GetMappingPosition(MVertices[i].selected ? selectColor : MVertices[i].color, false); var nMin = MVertices[i].nMinI; var nMax = MVertices[i].nMaxI; for (var j = nMin; j <= nMax; j++) { meshGeometry.TextureCoordinates[j] = mapPt; } } }
void SetModel(List <Mesh3D> meshs, Material backMaterial) { var nMeshNo = meshs.Count; if (nMeshNo != 0) { var triangleMesh = new MeshGeometry3D(); var nTotalVertNo = 0; for (var j = 0; j < nMeshNo; j++) { var mesh = meshs[j]; var nVertNo = mesh.GetVertexNo(); var nTriNo = mesh.GetTriangleNo(); if (nVertNo > 0 && nTriNo > 0) { var vx = new Double[nVertNo]; var vy = new Double[nVertNo]; var vz = new Double[nVertNo]; for (var i = 0; i < nVertNo; i++) { vx[i] = vy[i] = vz[i] = 0; } for (var i = 0; i < nTriNo; i++) { var tri = mesh.GetTriangle(i); var vN = mesh.GetTriangleNormal(i); var n0 = tri.N0; var n1 = tri.N1; var n2 = tri.N2; vx[n0] += vN.X; vy[n0] += vN.Y; vz[n0] += vN.Z; vx[n1] += vN.X; vy[n1] += vN.Y; vz[n1] += vN.Z; vx[n2] += vN.X; vy[n2] += vN.Y; vz[n2] += vN.Z; } for (var i = 0; i < nVertNo; i++) { var length = 1.0 / Math.Sqrt(vx[i] * vx[i] + vy[i] * vy[i] + vz[i] * vz[i]); if (length < 1e20) { vx[i] *= length; vy[i] *= length; vz[i] *= length; } triangleMesh.Positions.Add(mesh.GetPoint(i)); var color = mesh.GetColor(i); var mapPt = _mapping.GetMappingPosition(color); triangleMesh.TextureCoordinates.Add(new Point(mapPt.X, mapPt.Y)); triangleMesh.Normals.Add(new Vector3D(vx[i], vy[i], vz[i])); } for (var i = 0; i < nTriNo; i++) { var tri = mesh.GetTriangle(i); var n0 = tri.N0; var n1 = tri.N1; var n2 = tri.N2; triangleMesh.TriangleIndices.Add(nTotalVertNo + n0); triangleMesh.TriangleIndices.Add(nTotalVertNo + n1); triangleMesh.TriangleIndices.Add(nTotalVertNo + n2); } nTotalVertNo += nVertNo; } } //Material material = new DiffuseMaterial(new SolidColorBrush(Colors.Red)); var material = _mapping.Material; var triangleModel = new GeometryModel3D(triangleMesh, material); triangleModel.Transform = new Transform3DGroup(); if (backMaterial != null) { triangleModel.BackMaterial = backMaterial; } Content = triangleModel; } }