public ViewD3DColor(VertexD3DColorValue d3dColorValue) { dataContextValue = new VertexD3DColorValue() { A = d3dColorValue.A, R = d3dColorValue.R, G = d3dColorValue.G, B = d3dColorValue.B }; DataContext = dataContextValue; InitializeComponent(); }
private void MenuItem_Click_1(object sender, RoutedEventArgs e) { //Get the clicked MenuItem var menuItem = (MenuItem)sender; //Get the ContextMenu to which the menuItem belongs ContextMenu contextMenu = (ContextMenu)menuItem.Parent; //Find the placementTarget Vertex clickedVertex = (Vertex)((System.Windows.Controls.DataGridCell)(contextMenu.PlacementTarget)).DataContext; int columnIndex = ((System.Windows.Controls.DataGridCell)(contextMenu.PlacementTarget)).Column.DisplayIndex; if (clickedVertex.VertexComponents[columnIndex].DeclarationType == D3DDECLTYPE.D3DDECLTYPE_D3DCOLOR) { VertexD3DColorValue colorValue = (VertexD3DColorValue)clickedVertex.VertexComponents[columnIndex]; ViewD3DColor dialog = new ViewD3DColor(colorValue); if (dialog.ShowDialog() == true) { SporeMaster.RenderWare4.RW4VertexArray vertexArraySection = section.obj as SporeMaster.RenderWare4.RW4VertexArray; foreach (Vertex vertex in vertexArraySection.vertices) { foreach (IVertexComponentValue val in vertex.VertexComponents.Where(v => v.DeclarationType == D3DDECLTYPE.D3DDECLTYPE_D3DCOLOR)) { VertexD3DColorValue val2 = val as VertexD3DColorValue; if (val2.A == colorValue.A && val2.R == colorValue.R && val2.G == colorValue.G && val2.B == colorValue.B) { val2.A = dialog.A; val2.R = dialog.R; val2.G = dialog.G; val2.B = dialog.B; } } } if (section != null) { section.Changed(); } } } if (clickedVertex.VertexComponents[columnIndex].DeclarationType == D3DDECLTYPE.D3DDECLTYPE_UBYTE4) { VertexUByte4Value colorValue = (VertexUByte4Value)clickedVertex.VertexComponents[columnIndex]; ViewUByte4 dialog = new ViewUByte4(colorValue); if (dialog.ShowDialog() == true) { SporeMaster.RenderWare4.RW4VertexArray vertexArraySection = section.obj as SporeMaster.RenderWare4.RW4VertexArray; foreach (Vertex vertex in vertexArraySection.vertices) { foreach (IVertexComponentValue val in vertex.VertexComponents.Where(v => v.DeclarationType == D3DDECLTYPE.D3DDECLTYPE_D3DCOLOR)) { VertexUByte4Value val2 = val as VertexUByte4Value; if (val2.X == colorValue.X && val2.Y == colorValue.Y && val2.Z == colorValue.Z && val2.W == colorValue.W) { val2.X = dialog.X; val2.Y = dialog.Y; val2.Z = dialog.Z; val2.W = dialog.W; } } } if (section != null) { section.Changed(); } } } if (clickedVertex.VertexComponents[columnIndex].DeclarationType == D3DDECLTYPE.D3DDECLTYPE_SHORT4N) { VertexShort4NValue colorValue = (VertexShort4NValue)clickedVertex.VertexComponents[columnIndex]; ViewShort4N dialog = new ViewShort4N(colorValue); if (dialog.ShowDialog() == true) { SporeMaster.RenderWare4.RW4VertexArray vertexArraySection = section.obj as SporeMaster.RenderWare4.RW4VertexArray; foreach (Vertex vertex in vertexArraySection.vertices) { VertexShort4NValue val2 = (VertexShort4NValue)vertex.VertexComponents[columnIndex]; if (val2.X == colorValue.X && val2.Y == colorValue.Y && val2.Z == colorValue.Z && val2.W == colorValue.W) { val2.X = dialog.X; val2.Y = dialog.Y; val2.Z = dialog.Z; val2.W = dialog.W; } } if (section != null) { section.Changed(); } } } }
private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (this.DataContext != null && this.DataContext.GetType() == typeof(RW4ModelSectionView)) { matDiffuseMain.Brush = new SolidColorBrush(Colors.LightGray); RW4ModelSectionView sectionView = this.DataContext as RW4ModelSectionView; // listBoxTextures.ItemsSource = sectionView.Model.Sections.Where<RW4Section>(s => s.TypeCode == SectionTypeCodes.Texture); RW4Section section = sectionView.Section; SporeMaster.RenderWare4.RW4Mesh mesh = section.obj as SporeMaster.RenderWare4.RW4Mesh; meshMain.TriangleIndices.Clear(); meshMain.Positions.Clear(); meshMain.Normals.Clear(); meshMain.TextureCoordinates.Clear(); if (_boundingBox != null) { viewPort.Children.Remove(_boundingBox); _boundingBox = null; } RW4Section bboxSection = sectionView.Model.Sections.FirstOrDefault <RW4Section>(s => s.TypeCode == SectionTypeCodes.BBox); try { if (mesh != null) { VertexD3DColorValue lastColorValue = null; //separate the mesh into 'chunks' that can be given different textures if necessary foreach (var v in mesh.vertices.vertices) { if (v.VertexComponents.Exists(vc => vc.DeclarationType == D3DDECLTYPE.D3DDECLTYPE_D3DCOLOR)) { VertexD3DColorValue colorVal = v.VertexComponents.First(vc => vc.DeclarationType == D3DDECLTYPE.D3DDECLTYPE_D3DCOLOR) as VertexD3DColorValue; if (colorVal != lastColorValue) { //create a new 'chunk'. ModelVisual3D newChunckContainer = new ModelVisual3D(); viewPort.Children.Add(newChunckContainer); GeometryModel3D newChunk = new GeometryModel3D(); // GeometryContainer.Content.add } } VertexFloat3Value position = v.VertexComponents.First(vc => vc.Usage == D3DDECLUSAGE.D3DDECLUSAGE_POSITION) as VertexFloat3Value; meshMain.Positions.Add(new Point3D(position.X, position.Y, position.Z)); IVertexComponentValue normal = v.VertexComponents.First(vc => vc.Usage == D3DDECLUSAGE.D3DDECLUSAGE_NORMAL); if (normal != null) { if (normal is VertexUByte4Value) { VertexUByte4Value normalValue = normal as VertexUByte4Value; meshMain.Normals.Add(new Vector3D( (((float)normalValue.X) - 127.5f) / 127.5f, (((float)normalValue.Y) - 127.5f) / 127.5f, (((float)normalValue.Z) - 127.5f) / 127.5f )); } else if (normal is VertexFloat3Value) { VertexFloat3Value normalValue = normal as VertexFloat3Value; meshMain.Normals.Add(new Vector3D(normalValue.X, normalValue.Y, normalValue.Z)); } } IVertexComponentValue textureCoordinates = v.VertexComponents.First(vc => vc.Usage == D3DDECLUSAGE.D3DDECLUSAGE_TEXCOORD); if (textureCoordinates != null) { if (textureCoordinates is VertexFloat2Value) { VertexFloat2Value textureCoordinatesValue = textureCoordinates as VertexFloat2Value; meshMain.TextureCoordinates.Add(new System.Windows.Point(textureCoordinatesValue.X, textureCoordinatesValue.Y)); } if (textureCoordinates is VertexFloat4Value) { VertexFloat4Value textureCoordinatesValue = textureCoordinates as VertexFloat4Value; meshMain.TextureCoordinates.Add(new System.Windows.Point(textureCoordinatesValue.X, textureCoordinatesValue.Y)); } } } foreach (var t in mesh.triangles.triangles) { meshMain.TriangleIndices.Add((int)t.i); meshMain.TriangleIndices.Add((int)t.j); meshMain.TriangleIndices.Add((int)t.k); } } } catch { } viewPort.ZoomExtents(); } }