/// <summary>
        /// Loads and displays a 3D model with its bounding box
        /// </summary>
        /// <returns></returns>
        protected override async Task LoadModelFromFileAsync()
        {
            await base.LoadModelFromFileAsync();

            // Create a bounding box around the model
            var box = new BoundingBoxVisual3D {
                BoundingBox = Models[1].Content.Bounds,
                Fill        = BrushHelper.CreateGrayBrush(50)
            };

            Models.Add(box);

            // TODO: add lines outgoing from the center of each plane of the bounding box
        }
Exemple #2
0
        public void SelectObjs(string type, SelectedIndexCollection IDs)
        {
            ClearSelection();
            int count = 0;

            foreach (int i in IDs)
            {
                BoundingBoxVisual3D box = new BoundingBoxVisual3D();
                Models["SelectionLayer"].Add(box);
                ModelViewer.Children.Add(Models["SelectionLayer"][count++]);
                box.BoundingBox = Models[type][i].FindBounds(Transform3D.Identity);
                box.Diameter    = 10;
            }
            ModelView.UpdateLayout();
        }
 public void SelectObjs(IList <dynamic> Objs)
 {
     ClearSelection();
     foreach (dynamic o in Objs)
     {
         if (!HasModel(o))
         {
             continue;
         }
         BoundingBoxVisual3D box = new BoundingBoxVisual3D();
         selectionBoxes.Add(o, box);
         box.BoundingBox = ((ModelVisual3D)Models[o]).FindBounds(Transform3D.Identity);
         box.Diameter    = 10;
         ModelViewer.Children.Add(selectionBoxes[o]);
     }
     ModelView.UpdateLayout();
 }
Exemple #4
0
 public void SelectObjs(IList <dynamic> Objs)
 {
     ClearSelection();
     foreach (dynamic o in Objs)
     {
         if (HasModel(o))
         {
             BoundingBoxVisual3D box = new BoundingBoxVisual3D();
             selectionBoxes.Add(o, box);
             box.BoundingBox = ((ModelVisual3D)Models[o]).FindBounds(Transform3D.Identity);
             box.Diameter    = box.BoundingBox.SizeX / 20;
             ModelViewer.Children.Add(selectionBoxes[o]);
         }
         else if (HasPath(o))
         {
             selectedPaths.Add(o);
             SelectPath(o);
         }
     }
     ModelView.UpdateLayout();
 }
Exemple #5
0
        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();
            }
        }