Example #1
0
        [FriendAccessAllowed] // Built into Core, also used by Framework.
#endif
        internal static bool SerializeVector3D(BinaryWriter writer, string stringValues)
        {
#if PBTCOMPILER
            List <ThreeDoublesMarkup> points = ParseThreeDoublesCollection(stringValues, TypeConverterHelper.InvariantEnglishUS);
            ThreeDoublesMarkup        curPoint;
#else
            Vector3DCollection points = Vector3DCollection.Parse(stringValues);
            Vector3D           curPoint;
#endif

            // Write out the size.
            writer.Write(( uint )points.Count);

            // Write out the doubles.
            for (int i = 0; i < points.Count; i++)
            {
                curPoint = points[i];

                WriteDouble(writer, curPoint.X);
                WriteDouble(writer, curPoint.Y);
                WriteDouble(writer, curPoint.Z);
            }

            return(true);
        }
Example #2
0
        private Model3DGroup CopyToWPFThread(Model3DGroup src_model)
        {
            /** disassemble */
            var geometrymodel = src_model.Children[0] as GeometryModel3D;
            var geometry      = geometrymodel.Geometry as MeshGeometry3D;

            string str_vertices = geometry.Positions.ToString();
            string str_normals  = geometry.Normals.ToString();
            string str_indices  = geometry.TriangleIndices.ToString();
            string str_textures = geometry.TextureCoordinates.ToString();

            Model3DGroup result_model = null;

            Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
            {
                result_model = new Model3DGroup();
                result_model.Children.Add(new GeometryModel3D()
                {
                    Geometry = new MeshGeometry3D()
                    {
                        /** re-assemble */
                        Positions          = Point3DCollection.Parse(str_vertices),
                        Normals            = Vector3DCollection.Parse(str_normals),
                        TriangleIndices    = Int32Collection.Parse(str_indices),
                        TextureCoordinates = PointCollection.Parse(str_textures)
                    },
                    Material = new DiffuseMaterial(new ImageBrush(new BitmapImage(new Uri(@"image/marble.jpg", UriKind.Relative))))
                });
            }));

            return(result_model);
        }
Example #3
0
        /// <summary>Initializes the boid.</summary>
        /// <param name="colors">The boids color's, Item1 for Material and Item2 for BackMaterial.</param>
        public Boid(Tuple<Color,Color> colors)
        {
            if (colors == null) throw new ArgumentNullException("colors");

            // Store the colors
            _colors = colors;
            _materialBrush = new SolidColorBrush(colors.Item1);
            _backmaterialBrush = new SolidColorBrush(colors.Item2);

            // Set up the boid's model
            base.Content = new GeometryModel3D()
            {
                Material = new DiffuseMaterial(_materialBrush),
                BackMaterial = new DiffuseMaterial(_backmaterialBrush),
                Geometry = new MeshGeometry3D()
                {
                    // Two perpendicular triangles pointing up
                    Positions = Point3DCollection.Parse("0 1 0  1 -1 0  -1 -1 0  0 1 0  0 -1 1  0 -1 -1"), 
                    Normals = Vector3DCollection.Parse("0 0 -1  1 0 0"),
                    TriangleIndices = Int32Collection.Parse("0 1 2  3 4 5")
                }
            };

            // Initialize its rotation and translation
            _rotation = new AxisAngleRotation3D(UNIT_Y, 0);
            _translation = new TranslateTransform3D(new Vector3D());

            // Add all of the necessary transforms
            var t = new Transform3DGroup();
            t.Children.Add(new ScaleTransform3D(MODEL_SCALE, MODEL_SCALE, MODEL_SCALE));
            t.Children.Add(new RotateTransform3D(_rotation));
            t.Children.Add(_translation);
            base.Transform = t;
        }
Example #4
0
 /// <summary>
 /// Converts a string into a Vector3DCollection.
 /// </summary>
 public override object ConvertFromString(string value, IValueSerializerContext context)
 {
     if (value != null)
     {
         return(Vector3DCollection.Parse(value));
     }
     else
     {
         return(base.ConvertFromString(value, context));
     }
 }
Example #5
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
            {
                throw GetConvertFromException(value);
            }

            string source = value as string;

            if (source != null)
            {
                return(Vector3DCollection.Parse(source));
            }
            return(base.ConvertFrom(context, culture, value));
        }
Example #6
0
 public Bishop()
 {
     try
     {
         this.Mesh.Normals            = Vector3DCollection.Parse(Bishop_Mesh.Normals);
         this.Mesh.Positions          = Point3DCollection.Parse(Bishop_Mesh.Positions);
         this.Mesh.TextureCoordinates = PointCollection.Parse(Bishop_Mesh.TextureCoordinates);
         this.Mesh.TriangleIndices    = Int32Collection.Parse(Bishop_Mesh.TriangleIndices);
         //initialize to default position
         TranslateTransform3D translate = new TranslateTransform3D(-3, 7, 0);
         this.Transformations.Children.Add(translate);
         this.UnmutableTransformations.Add(translate);
     }
     catch (Exception ex)
     {
     }
 }
Example #7
0
 /// <summary>
 /// Initializes a Pawn from its resource file
 /// </summary>
 public Pawn()
 {
     try
     {
         this.Mesh.Positions          = Point3DCollection.Parse(Pawn_Mesh.Positions);
         this.Mesh.TriangleIndices    = Int32Collection.Parse(Pawn_Mesh.TriangleIndices);
         this.Mesh.TextureCoordinates = PointCollection.Parse(Pawn_Mesh.TextureCoordinates);
         this.Mesh.Normals            = Vector3DCollection.Parse(Pawn_Mesh.Normals);
         //initialize pawn to default position, this centers the pawn in the middle of the board (0,0) and compensates obj imports deviations
         TranslateTransform3D translate = new TranslateTransform3D(-7, 5, 0);
         this.Transformations.Children.Add(translate);
         this.UnmutableTransformations.Add(translate);
         //RotateTransform3D rotate = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90));
         //this.Transformations.Children.Add(rotate);
         //this.UnmutableTransformations.Add(rotate);
     }
     catch (Exception ex)
     {
         throw;
     }
 }