Exemple #1
0
        static Creature()
        {
            var egg = new MeshBuilder();
            egg.AddSphere(new Point3D(0, 0, 0.2), 0.2, 24, 12);
            eggGeometry = egg.ToMesh();

            var child = new MeshBuilder();
            child.AddSphere(new Point3D(0, 0, 1), 1, 24, 12);
            child.AddSphere(new Point3D(1, 0, 1), 0.5, 24, 12);
            child.AddSphere(new Point3D(1.5, 0.2, 1), 0.1, 24, 12);
            child.AddSphere(new Point3D(1.5, -0.2, 1), 0.1, 24, 12);
            childGeometry = child.ToMesh();

            var creature = new MeshBuilder();
            creature.AddSphere(new Point3D(0, 0, 1), 1, 24, 12);
            creature.AddSphere(new Point3D(0, 0, 2), 0.5, 24, 12);
            creature.AddSphere(new Point3D(0.5, 0.2, 2), 0.1, 24, 12);
            creature.AddSphere(new Point3D(0.5, -0.2, 2), 0.1, 24, 12);
            creatureGeometry = creature.ToMesh();

            var coffin = new MeshBuilder();
            coffin.AddBox(new Point3D(0, 0, 0.25), 1, 1, 1);
            deadGeometry = coffin.ToMesh();

            maleMaterial = MaterialHelper.CreateMaterial(Brushes.Blue);
            femaleMaterial = MaterialHelper.CreateMaterial(Brushes.IndianRed);
            eggMaterial = MaterialHelper.CreateMaterial(Brushes.AntiqueWhite);
            deadMaterial = MaterialHelper.CreateMaterial(Brushes.Black);

        }
Exemple #2
0
        static Predator()
        {
            var egg = new MeshBuilder();
            egg.AddPyramid(new Point3D(0, 0, 0), 0.2, 0.4);
            eggGeometry = egg.ToMesh();

            var child = new MeshBuilder();
            child.AddBox(new Point3D(0, 0, 0.5), 1, 1, 1);
            child.AddSphere(new Point3D(0.2, 0.2, 1), 0.2, 12, 24);
            child.AddSphere(new Point3D(0.2, -0.2, 1), 0.2, 12, 24);
            childGeometry = child.ToMesh();

            var creature = new MeshBuilder();
            creature.AddBox(new Point3D(0, 0, 0.5), 1, 1, 1);
            creature.AddCone(new Point3D(0.2, 0.2, 1), new Vector3D(0, 0, 1), 0.16, 0.04, 0.3, false, true, 12);
            creature.AddCone(new Point3D(0.2, -0.2, 1), new Vector3D(0, 0, 1), 0.16, 0.04, 0.3, false, true, 12);
            creatureGeometry = creature.ToMesh();

            var coffin = new MeshBuilder();
            coffin.AddCylinder(new Point3D(0, 0, 0), new Point3D(0, 0, 0.25), 1, 12);
            deadGeometry = coffin.ToMesh();

            maleMaterial = MaterialHelper.CreateMaterial(Brushes.Navy);
            femaleMaterial = MaterialHelper.CreateMaterial(Brushes.Violet);
            eggMaterial = MaterialHelper.CreateMaterial(Brushes.AntiqueWhite);
            deadMaterial = MaterialHelper.CreateMaterial(Brushes.Black);

        }
 private void CreateGeometry()
 {
     var builder = new MeshBuilder();
     builder.AddSphere(new Point3D(0, 0, 0), Diameter/2, ThetaDiv, PhiDiv);
     _sphere = builder.ToMesh();
     _sphere.Freeze();
 }
        private void CreateModel()
        {
            var points = new Point3DCollection();
            var edges = new Int32Collection();
            var triangles = new Int32Collection();
            switch (CurrentModelType)
            {
                case ModelTypes.StellatedOctahedron:
                case ModelTypes.Tetrahedron:
                    points.Add(+1, +1, +1);
                    points.Add(-1, -1, 1);
                    points.Add(-1, +1, -1);
                    points.Add(+1, -1, -1);
                    edges.Add(0, 1, 1, 2, 2, 0, 0, 3, 1, 3, 2, 3);
                    triangles.Add(0, 1, 2, 0, 3, 1, 1, 3, 2, 2, 3, 0);
                    break;
            }
            switch (CurrentModelType)
            {
                case ModelTypes.StellatedOctahedron:
                    // http://en.wikipedia.org/wiki/Compound_of_two_tetrahedra
                    points.Add(-1, +1, +1);
                    points.Add(1, -1, 1);
                    points.Add(1, +1, -1);
                    points.Add(-1, -1, -1);
                    edges.Add(4, 5, 5, 6, 6, 4, 4, 7, 5, 7, 6, 7);
                    triangles.Add(4, 5, 6, 4, 7, 5, 5, 7, 6, 6, 7, 4);
                    break;
            }

            var m = new Model3DGroup();

            // Add the nodes
            var gm = new MeshBuilder();
            foreach (var p in points)
            {
                gm.AddSphere(p, 0.1);
            }
            m.Children.Add(new GeometryModel3D(gm.ToMesh(), Materials.Gold));

            // Add the triangles
            var tm = new MeshBuilder();
            for (int i = 0; i < triangles.Count; i += 3)
            {
                tm.AddTriangle(points[triangles[i]], points[triangles[i + 1]], points[triangles[i + 2]]);
            }
            m.Children.Add(new GeometryModel3D(tm.ToMesh(), Materials.Red) { BackMaterial = Materials.Blue });

            // Add the edges
            var em = new MeshBuilder();
            for (int i = 0; i < edges.Count; i += 2)
            {
                em.AddCylinder(points[edges[i]], points[edges[i + 1]], 0.08, 10);
            }
            m.Children.Add(new GeometryModel3D(em.ToMesh(), Materials.Gray));

            Model = m;
        }
        public DemoElement3D()
        {
            var gm = new GeometryModel3D();
            var mb = new MeshBuilder();
            mb.AddSphere(new Point3D(0, 0, 0), 2, 100, 50);
            gm.Geometry = mb.ToMesh();
            gm.Material = Materials.Blue;

            Visual3DModel = gm;
        }
        public MainWindow()
        {
            InitializeComponent();

            var c = new ContainerUIElement3D();
            var e = new ModelUIElement3D();
            var gm = new GeometryModel3D();
            var mb = new MeshBuilder();
            mb.AddSphere(new Point3D(0, 0, 0), 2, 100, 50);
            gm.Geometry = mb.ToMesh();
            gm.Material = Materials.Red;
            e.Model = gm;
            e.Transform = new TranslateTransform3D(5, 0, 0);
            e.MouseDown += (sender, args) => gm.Material = Materials.Yellow;
            c.Children.Add(e);
            view1.Children.Add(c);

            //e.Visibility = Visibility.Hidden;
            //this.Dispatcher.BeginInvoke(DispatcherPriority.Send, new ThreadStart(delegate
            //{
            //    e.Visibility = Visibility.Visible;
            //}));
        }
 protected override MeshGeometry3D Tessellate()
 {
     var builder = new MeshBuilder(true, true);
     builder.AddSphere(Center, Radius, ThetaDiv, PhiDiv);
     return builder.ToMesh();
 }