[FriendAccessAllowed] // Built into Core, also used by Framework. #endif internal static bool SerializePoint3D(BinaryWriter writer, string stringValues) { #if PBTCOMPILER List <ThreeDoublesMarkup> point3Ds = ParseThreeDoublesCollection(stringValues, TypeConverterHelper.InvariantEnglishUS); ThreeDoublesMarkup curPoint; #else Point3DCollection point3Ds = Point3DCollection.Parse(stringValues); Point3D curPoint; #endif // Write out the size. writer.Write(( uint )point3Ds.Count); // Write out the doubles. for (int i = 0; i < point3Ds.Count; i++) { curPoint = point3Ds[i]; WriteDouble(writer, curPoint.X); WriteDouble(writer, curPoint.Y); WriteDouble(writer, curPoint.Z); } return(true); }
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); }
/// <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; }
public static MeshGeometry3D CreateSquareGeometry(string positions) { return(new MeshGeometry3D { Positions = Point3DCollection.Parse(positions), TriangleIndices = Int32Collection.Parse("0,1,2 0,2,3"), TextureCoordinates = PointCollection.Parse("0,0 0,1 1,1 1,0"), }); }
/// <summary> /// Converts a string into a Point3DCollection. /// </summary> public override object ConvertFromString(string value, IValueSerializerContext context) { if (value != null) { return(Point3DCollection.Parse(value)); } else { return(base.ConvertFromString(value, context)); } }
public void DemoString() { // this shows how to convert them all to strings var collection = CreateCollection(); IEnumerable <IList <Point3D> > tmp = collection; var strings = collection.Select(c => c.ToString()).ToList(); Trace.WriteLine("String Size: " + strings.Sum(s => s.Length)); // eh, 2x for Unicode var result = new ConcurrentBag <Point3DCollection>(strings.Select(r => Point3DCollection.Parse(r))); VerifyEquality(collection, result); }
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(Point3DCollection.Parse(source)); } return(base.ConvertFrom(context, culture, value)); }
public ChessBoard() { material = new GeometryModel3D(); mesh = new MeshGeometry3D(); material.Geometry = mesh; this.Content = material; this.Mesh.Positions = Point3DCollection.Parse(ChessBoard_Mesh.Positions); this.Mesh.TextureCoordinates = PointCollection.Parse(ChessBoard_Mesh.TextureCoordinates); this.Mesh.TriangleIndices = Int32Collection.Parse(ChessBoard_Mesh.TriangleIndices); DiffuseMaterial mat = new DiffuseMaterial(); mat.Brush = Brushes.White; mat.AmbientColor = Colors.Silver; mat.Color = Colors.Chocolate; material.Material = mat; }
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) { } }
/// <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; } }
public void DemoDeflateString() { // this shows how to convert them all to strings var collection = CreateCollection(); var formatter = new BinaryFormatter(); // not really helping much: could var strings = collection.Select(c => c.ToString()).ToList(); using (var ms = new MemoryStream()) { using (var def = new DeflateStream(ms, CompressionLevel.Optimal, true)) { formatter.Serialize(def, strings); def.Flush(); Trace.WriteLine("Deflate Size: " + ms.Position); } ms.Position = 0; using (var def = new DeflateStream(ms, CompressionMode.Decompress)) { var stringsDupe = (IList <string>)formatter.Deserialize(def); var result = new ConcurrentBag <Point3DCollection>(stringsDupe.Select(r => Point3DCollection.Parse(r))); VerifyEquality(collection, result); } } }