public static CadObject Create(Action a, Vector3[] vertices)
 {
     var co = new CadObject();
     co.Vertices = vertices;
     co.AnonymousDraw = a;
     return co;
 }
示例#2
0
        public override void Build(CadDocumentBuilder builder)
        {
            base.Build(builder);

            foreach (var handle in this.Handles)
            {
                CadObject member = builder.GetCadObject(handle);
                if (member != null)
                {
                    this.CadObject.Members.Add(handle, member);
                }
            }
        }
示例#3
0
        public void AddCadObject()
        {
            Line        line = new Line();
            CadDocument doc  = new CadDocument();

            doc.BlockRecords[BlockRecord.ModelSpaceName].Entities.Add(line);

            CadObject l = doc.GetCadObject(line.Handle);

            //Assert existing element
            Assert.NotNull(l);
            Assert.Equal(line, l);
            Assert.False(0 == l.Handle);
            Assert.Equal(line.Handle, l.Handle);
        }
        public static void SamSave(String path, CadObject co)
        {
            TextWriter tw = new StreamWriter(path);

            if (co.Children.Length == 0)
            {
                Single[] x;
                x = co._Color._Ambient; tw.WriteLine(x[0] + "," + x[1] + "," + x[2] + "," + x[3]);
                x = co._Color._Diffuse; tw.WriteLine(x[0] + "," + x[1] + "," + x[2] + "," + x[3]);
                x = co._Color._Emission; tw.WriteLine(x[0] + "," + x[1] + "," + x[2] + "," + x[3]);
                x = co._Color._Specular; tw.WriteLine(x[0] + "," + x[1] + "," + x[2] + "," + x[3]);
                x = co._Color._Shininess; tw.WriteLine(x[0]);
                tw.WriteLine(co.Indices.Length); foreach (var i in co.Indices) tw.WriteLine(i);

                tw.WriteLine((co.Vertices.Length * 2));
                for (int i = 0; i < co.Vertices.Length; i++)
                {
                    tw.WriteLine(FormSaveAs.forVec(co.Vertices[i]));
                    tw.WriteLine(FormSaveAs.forVec(co.Normals[i]));
                }
            }
            else
            {
                tw.WriteLine("CHILD");
                for (int i = 0; i < co.Children.Length; i++)
                {
                    CadObject c = co.Children[i];

                    ;

                    String p = "";
                    bool first = true;
                    foreach (String s in path.Split(new char[] { '.' }))
                    { 
                        p += s;
                        if (first) p += "_" + i + "." ;
                        first = false;
                    }
                    tw.WriteLine(p);
                    FormSaveAs.SamSave(p, c);
                }
            }

            // close the stream
            tw.Close();
        }
示例#5
0
        private void Multiplierpanel_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.DataContext is CadObject cadObject)
            {
                this.IsEnabled = true;
                this.cadObject = cadObject;

                OtherSettingSwitch.DataContext = cadObject;
                OtherSettingSwitch.SetBinding(ToggleSwitch.IsOnProperty, "OwnedSetting");

                BindingCadObject(cadObject.ProjectionSetting);
            }
            else
            {
                this.IsEnabled               = false;
                CRSUpDn.DataContext          = null;
                RadiusSlider.DataContext     = null;
                MultiplierSlider.DataContext = null;
            }
        }
示例#6
0
        private static void assertObject(CadObject co, Node node, bool assertDictionary)
        {
            Assert.True(co.Handle == node.Handle);
            Assert.True(co.Owner.Handle == node.OwnerHandle);

            if (co.XDictionary != null && assertDictionary)
            {
                Assert.True(co.XDictionary.Handle == node.DictionaryHandle);
            }

            switch (co)
            {
            case BlockRecord record:
                assertCollection(record.Entities, node, assertDictionary);
                break;

            default:
                break;
            }
        }
示例#7
0
        private static void assertTable <T>(CadDocument doc, Table <T> table)
            where T : TableEntry
        {
            Assert.NotNull(table);

            notNull(table.Document, $"Document not assigned to table {table}");
            Assert.Equal(doc, table.Document);
            Assert.Equal(doc, table.Owner);

            Assert.True(table.Handle != 0);

            CadObject t = doc.GetCadObject(table.Handle);

            Assert.Equal(t, table);

            foreach (T entry in table)
            {
                Assert.Equal(entry.Owner.Handle, table.Handle);
                Assert.Equal(entry.Owner, table);

                documentObjectNotNull(doc, entry);
            }
        }
示例#8
0
 private void CadCanvas_SelectedObject(object sender, CadObject e)
 {
     SelectedObject?.Invoke(this, e);
 }
示例#9
0
        private static CadObject xamlModelVisual3D(
            TagFile f0,
            float xScale,
            float yScale,
            float zScale,
            bool useAmbient,
            bool useDiffuse,
            bool useSpecular,
            bool useEmission
            )
        {
            CadObject co = new CadObject();
            var ret = new List<CadObject>();

            foreach (var e1 in f0._Children)
            {
                if (e1 is TagFile)
                {
                    var f1 = e1 as TagFile;
                    switch (f1._Name)
                    {
                        case "ModelVisual3D.Transform":
                            {
                                xamlParseTransform(f1, xScale, yScale, zScale, co);
                                break;
                            }
                        case "ModelVisual3D.Content":
                            {
                                xamlModelVisual3DContent(f1, xScale, yScale, zScale, useAmbient, useDiffuse, useSpecular, useEmission, ret);
                                break;
                            }
                        case "ModelVisual3D.Children":
                            {
                                foreach (var e2 in f1._Children)
                                {
                                    if (e2 is TagFile)
                                    {
                                        var f2 = e2 as TagFile;
                                        switch (f2._Name)
                                        {
                                            case "ModelVisual3D":
                                                ret.Add(xamlModelVisual3D(f2, xScale, yScale, zScale, useAmbient, useDiffuse, useSpecular, useEmission));
                                                break;
                                            
                                            default:
                                                Console.WriteLine("CadObjectGenerator." + System.Reflection.MethodBase.GetCurrentMethod().Name + " ignoring " + f2._Name);
                                                break;
                                        }
                                    }
                                }
                                break;
                            }
                        default:
                            {
#if DEBUG
                                Console.WriteLine("CadObjectGenerator." + System.Reflection.MethodBase.GetCurrentMethod().Name + " ignoring " + f1._Name);
#endif
                                break;
                            }
                    }
                }
            }

            for (int i = 0; i < ret.Count; i++)
            {
                if (ret[i].Children != null)
                    if (ret[i].Children.Length != 0)
                        continue;

                if (ret[i].Vertices != null)
                    if (ret[i].Vertices.Length != 0)
                        continue;

                ret.RemoveAt(i);
                i--;
            }

            co.Children = ret.ToArray();

            return co;
        }
示例#10
0
        public static CadObject Create(
            String FileText,
            String ObjectName = "",
            float xScale = 1.0f,
            float yScale = 1.0f,
            float zScale = 1.0f,
            float xOff = 0.0f,
            float yOff = 0.0f,
            float zOff = 0.0f,
            bool useAmbient = true,
            bool useDiffuse = true,
            bool useSpecular = true,
            bool useEmission = true,
            bool reduceComplexity = true
            )
        {
            var f = TagFile.ParseText(FileText);
            String match0 = "ModelVisual3D";
            var match0L = f.getMatches(ref match0);

            TagFile parent = null;

            switch (match0L.Count)
            {
                case 1:
                    parent = match0L[0];
                    break;
                default:
                    Console.WriteLine("CadObjectGenerator: Invalid XAML File");
                    return new CadObject();
            }


            var co = SamSeifert.GLE.CAD.Generator.FromXaml.xamlModelVisual3D(
                parent,
                xScale,
                yScale,
                zScale,
                useAmbient,
                useDiffuse,
                useSpecular,
                useEmission
                );

            co.BoolUseTranslationAndRotation = true;

            co._Matrix *= Matrix4.CreateTranslation(xOff, yOff, zOff);

            if (!reduceComplexity)
            {
                co._Name = ObjectName;
                return co;
            }

            co.GLDelete();

            // TAKE OUT TREE STRUCTURE AND MAKE SINGLE LEVEL
            var all = co.ConsolidateMatrices();
            int old = all.Count;

            for (int i = 0; i < all.Count; i++)
            {
                var linq = all[i].Vertices;
                if ((linq == null) || (linq.Length == 0))
                {
                    all[i].GLDelete();
                    all.RemoveAt(i--);
                }
                else all[i].Children = new CadObject[0];
            }

            // Console.WriteLine("Removing Tree: " + old + " to " + all.Count);
            old = all.Count;

            // COMBINE COLORS
            for (int i = 0; i < all.Count; i++)
            {
                ColorGL col = all[i]._Color;

                var verts = new List<Vector3>();
                var norms = new List<Vector3>();
                var dices = new List<uint>();

                for (int j = i; j < all.Count; j++)
                {
                    if (ColorGL.CheckMatch(all[i]._Color, all[j]._Color))
                    {
                        for (int dex = 0; dex < all[j].Indices.Length; dex++)
                            all[j].Indices[dex] += (uint)verts.Count; // CHANGE INDICES

                        verts.AddRange(all[j].Vertices);
                        norms.AddRange(all[j].Normals);
                        dices.AddRange(all[j].Indices);

                        if (i != j) all.RemoveAt(j--); // dont delete the first one!
                    }
                }

                all[i].initializeWithVectorsAndNormalsSorted(verts.ToArray(), norms.ToArray(), dices.ToArray());
            }
            // Console.WriteLine("Combine Colors: " + old + " to " + all.Count);

            var ret = new CadObject(all.ToArray(), ObjectName);
            return ret;
        }
示例#11
0
 public CadTemplate(CadObject cadObject)
 {
     this.CadObject = cadObject;
 }
示例#12
0
        private static void xamlParseTransform(
            TagFile f0,
            float xScale,
            float yScale,
            float zScale,
            CadObject co)
        {
            var u1 = new HashSet<string>();
            foreach (var e1 in f0._Children)
            {
                if (e1 is TagFile)
                {
                    var f1 = e1 as TagFile;
                    if (u1.Contains(f1._Name)) Console.WriteLine("CadObjectGenerator." + System.Reflection.MethodBase.GetCurrentMethod().Name + " multiple " + f1._Name);
                    else
                    {
                        u1.Add(f1._Name);
                        switch (f1._Name)
                        {
                            case "MatrixTransform3D":
                                {
                                    foreach (var kv in f1._Params.AsEnumerable())
                                    {
                                        switch (kv.Key)
                                        {
                                            case "Matrix":
                                                {
                                                    var vals = kv.Value.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                                                    var points = new List<double>();
                                                    double a;
                                                    foreach (var line in vals)
                                                        if (double.TryParse(line, out a))
                                                            points.Add(a);

                                                    if (points.Count == 16)
                                                    {
                                                        int i = 0;
                                                        co.BoolUseTranslationAndRotation = true;
                                                        co._Matrix.M11 = (float)points[i++];
                                                        co._Matrix.M12 = (float)points[i++];
                                                        co._Matrix.M13 = (float)points[i++];
                                                        co._Matrix.M14 = (float)points[i++];

                                                        co._Matrix.M21 = (float)points[i++];
                                                        co._Matrix.M22 = (float)points[i++];
                                                        co._Matrix.M23 = (float)points[i++];
                                                        co._Matrix.M24 = (float)points[i++];

                                                        co._Matrix.M31 = (float)points[i++];
                                                        co._Matrix.M32 = (float)points[i++];
                                                        co._Matrix.M33 = (float)points[i++];
                                                        co._Matrix.M34 = (float)points[i++];

                                                        co._Matrix.M41 = (float)points[i++];
                                                        co._Matrix.M42 = (float)points[i++];
                                                        co._Matrix.M43 = (float)points[i++];
                                                        co._Matrix.M44 = (float)points[i++];

                                                        co._Matrix.M41 *= xScale;
                                                        co._Matrix.M42 *= yScale;
                                                        co._Matrix.M43 *= zScale;
                                                    }
#if DEBUG
                                                    else Console.WriteLine("CadObjectGenerator." + System.Reflection.MethodBase.GetCurrentMethod().Name + " matrix doesn't have 16 values!");
#endif
                                                    break;
                                                }
                                            default:
#if DEBUG
                                                Console.WriteLine("CadObjectGenerator." + System.Reflection.MethodBase.GetCurrentMethod().Name + ", MatrixTransform3D ignoring " + kv);
#endif

                                                break;
                                        }
                                    }
                                    break;
                                }
                            case "RotateTransform3D":
                                {
                                    bool no_angle = false;

                                    if (f1._Children.Length == 1)
                                    {
                                        var f2 = f1._Children[0] as TagFile;
                                        if (f2 != null)
                                        {
                                            if ((f2._Children.Length == 1) && ("RotateTransform3D.Rotation".Equals(f2._Name)))
                                            {
                                                var f3 = f2._Children[0] as TagFile;
                                                if (f3 != null)
                                                {
                                                    if ("AxisAngleRotation3D".Equals(f3._Name))
                                                    {
                                                        string angle;
                                                        if (f3._Params.TryGetValue("Angle", out angle))
                                                        {
                                                            if ("0".Equals(angle))
                                                            {
                                                                no_angle = true;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (!no_angle) f1.Display();
                                    break;
                                }
                            default:
#if DEBUG
                                Console.WriteLine("CadObjectGenerator." + System.Reflection.MethodBase.GetCurrentMethod().Name + " ignoring " + f1._Name);
#endif
                                break;
                        }
                    }
                }
            }
        }
示例#13
0
        public void DataContextUpdate(CadObject cadObject)
        {
            this.IsEnabled = true;
            XUpDn.Value    = cadObject.X;
            XUpDn.SetBinding(NumericUpDown.ValueProperty, "X");
            XUpDn.DataContext = cadObject;

            YUpDn.Value = cadObject.Y;
            YUpDn.SetBinding(NumericUpDown.ValueProperty, "Y");
            YUpDn.DataContext = cadObject;

            ZUpDn.Value = cadObject.Z;
            ZUpDn.SetBinding(NumericUpDown.ValueProperty, "Z");
            ZUpDn.DataContext = cadObject;

            MirrorCheck.DataContext = cadObject;
            MirrorCheck.IsChecked   = cadObject.Mirror;
            MirrorCheck.SetBinding(CheckBox.IsCheckedProperty, "Mirror");

            RenderCheck.IsChecked = cadObject.Render;
            RenderCheck.SetBinding(CheckBox.IsCheckedProperty, "Render");
            RenderCheck.DataContext = cadObject;

            FixCheck.IsChecked = cadObject.IsFix;
            FixCheck.SetBinding(CheckBox.IsCheckedProperty, "IsFix");
            FixCheck.DataContext = cadObject;

            AngleZUpDn.Value = cadObject.AngleZ;
            AngleZUpDn.SetBinding(NumericUpDown.ValueProperty, "AngleZ");
            AngleZUpDn.DataContext = cadObject;

            AngleYUpDn.Value = cadObject.AngleY;
            AngleYUpDn.SetBinding(NumericUpDown.ValueProperty, "AngleY");
            AngleYUpDn.DataContext = cadObject;

            AngleXUpDn.Value = cadObject.AngleX;
            AngleXUpDn.SetBinding(NumericUpDown.ValueProperty, "AngleX");
            AngleXUpDn.DataContext = cadObject;

            WidthUpDn.Value    = cadObject.ScaleX;
            WidthUpDn.Interval = MonchaCadViewer.Properties.Settings.Default.stg_scale_percent == true ? 1 : 0.01;
            Binding bindingScaleX = new Binding("ScaleX");

            bindingScaleX.Converter = new ScaleConverter(MonchaCadViewer.Properties.Settings.Default.stg_scale_percent, MonchaCadViewer.Properties.Settings.Default.stg_scale_invert);
            WidthUpDn.SetBinding(NumericUpDown.ValueProperty, bindingScaleX);
            WidthUpDn.DataContext = cadObject;

            HeightUpDn.Value    = cadObject.ScaleY;
            HeightUpDn.Interval = MonchaCadViewer.Properties.Settings.Default.stg_scale_percent == true ? 1 : 0.01;
            Binding bindingScaleY = new Binding("ScaleY");

            bindingScaleY.Converter = new ScaleConverter(MonchaCadViewer.Properties.Settings.Default.stg_scale_percent, MonchaCadViewer.Properties.Settings.Default.stg_scale_invert);
            HeightUpDn.SetBinding(NumericUpDown.ValueProperty, bindingScaleY);
            HeightUpDn.DataContext = cadObject;

            DeepUpDn.Value    = cadObject.ScaleZ;
            DeepUpDn.Interval = MonchaCadViewer.Properties.Settings.Default.stg_scale_percent == true ? 1 : 0.01;
            Binding bindingScaleZ = new Binding("ScaleZ");

            bindingScaleZ.Converter = new ScaleConverter(MonchaCadViewer.Properties.Settings.Default.stg_scale_percent, MonchaCadViewer.Properties.Settings.Default.stg_scale_invert);
            DeepUpDn.SetBinding(NumericUpDown.ValueProperty, bindingScaleZ);
            DeepUpDn.DataContext = cadObject;
        }
示例#14
0
 private void readExtendedData(CadObject cadObject)
 {
     //TODO: Handle extended data
 }
示例#15
0
        private static String XAMLconsolidateData(CadObject co)
        {
            const String m1 = "Positions";
            const String m2 = "Normals";
            const String m3 = "TriangleIndices";
            var m1a = new List<String>();
            var m2a = new List<String>();
            var m3a = new List<String>();

            foreach (var vec in co.Vertices)
                m1a.Add(vec.X + "," + vec.Y + "," + vec.Z + " ");

            foreach (var vec in co.Normals)
                m2a.Add(vec.X + "," + vec.Y + "," + vec.Z + " ");

            for (int i = 0; i < co.Indices.Length; i++)
                m3a.Add(co.Indices[i] + (((i + 1) % 3 == 0) ? " " : ","));

            return
                m1 + "=\"" + String.Join("", m1a) + "\" " +
                m2 + "=\"" + String.Join("", m2a) + "\" " +
                m3 + "=\"" + String.Join("", m3a) + "\" ";
        }
示例#16
0
        private static List<String> getDataForObject(CadObject co)
        {
            var save = new List<String>();

            if (co._GLType != CadObject.GLType.GL4) return save;

            const String match1 = "GeometryModel3D";
            const String match2 = "DiffuseMaterial";
            const String match3 = "SpecularMaterial";
            const String match4 = "AmbientMaterial";
            const String match5 = "EmissionMaterial";
            const String match6 = "MeshGeometry3D";

            save.Add("<" + match1 + ">");

            save.Add("<" + match2 + ">");
            save.Add(FormSaveAs.XAMLstring4Color(co._Color._Diffuse));
            save.Add("</" + match2 + ">");

            save.Add("<" + match3 + ">");
            save.Add(FormSaveAs.XAMLstring4Color(co._Color._Specular));
            save.Add("</" + match3 + ">");

            save.Add("<" + match4 + ">");
            save.Add(FormSaveAs.XAMLstring4Color(co._Color._Ambient));
            save.Add("</" + match4 + ">");

            save.Add("<" + match5 + ">");
            save.Add(FormSaveAs.XAMLstring4Color(co._Color._Emission));
            save.Add("</" + match5 + ">");

            save.Add("<" + match6 + " " + FormSaveAs.XAMLconsolidateData(co) + "/>");

            save.Add("</" + match1 + ">");

            return save;
        }
示例#17
0
 public FormSaveAs(CadObject cad) : this()
 {
     this._CadObject = cad;
 }
示例#18
0
 private void MainCanvas_SelectedObject(object sender, CadObject e)
 {
     MultPanel.DataContext   = e;
     ObjectPanel.DataContext = e;
 }
示例#19
0
        private static void xamlParseColor(
            TagFile f0,
            bool useAmbient,
            bool useDiffuse,
            bool useSpecular,
            bool useEmission,
            CadObject co)
        {
            //            f0.display();

            String output;
            const String SCOLOR = "Color";
            const String SOPAC = "Opacity";

            String matchD = "DiffuseMaterial";
            String matchS = "SpecularMaterial";
            String matchA = "AmbientMaterial";
            String matchE = "EmissionMaterial";
            String matchX = "SolidColorBrush";

            var matchD_ = f0.getMatches(ref matchD, ref matchX);
            var matchS_ = f0.getMatches(ref matchS, ref matchX);
            var matchA_ = f0.getMatches(ref matchA, ref matchX);
            var matchE_ = f0.getMatches(ref matchE, ref matchX);

            Color diffuse = Color.Black;
            Color specular = Color.Black;
            Color ambient = Color.Black;
            Color emission = Color.Black;

            if (matchD_.Count == 1 && useDiffuse)
            {
                var dict = matchD_[0]._Params;
                if (dict.TryGetValue(SCOLOR, out output))
                {
                    Int32 iColorInt = Convert.ToInt32(output.Substring(1), 16);
                    diffuse = System.Drawing.Color.FromArgb(iColorInt);
                }
                if (dict.TryGetValue(SOPAC, out output))
                {
                    Double a;
                    if (Double.TryParse(output, out a))
                    {
                        Byte alpha = (Byte)Math.Min(255, Math.Max(0, (a * 255)));
                        diffuse = Color.FromArgb(alpha, diffuse);
                    }
                }
            }

            if (matchS_.Count == 1 && useSpecular)
            {
                var dict = matchS_[0]._Params;
                if (dict.TryGetValue(SCOLOR, out output))
                {
                    Int32 iColorInt = Convert.ToInt32(output.Substring(1), 16);
                    specular = System.Drawing.Color.FromArgb(iColorInt);
                }
                if (dict.TryGetValue(SOPAC, out output))
                {
                    Double a;
                    if (Double.TryParse(output, out a))
                    {
                        Byte alpha = (Byte)Math.Min(255, Math.Max(0, (a * 255)));
                        specular = Color.FromArgb(alpha, specular);
                    }
                }
            }

            if (matchA_.Count == 1 && useAmbient)
            {
                var dict = matchA_[0]._Params;
                if (dict.TryGetValue(SCOLOR, out output))
                {
                    Int32 iColorInt = Convert.ToInt32(output.Substring(1), 16);
                    ambient = System.Drawing.Color.FromArgb(iColorInt);
                }
                if (dict.TryGetValue(SOPAC, out output))
                {
                    Double a;
                    if (Double.TryParse(output, out a))
                    {
                        Byte alpha = (Byte)Math.Min(255, Math.Max(0, (a * 255)));
                        ambient = Color.FromArgb(alpha, ambient);
                    }
                }
            }
            else if (useAmbient) ambient = specular;

            if (matchE_.Count == 1 && useEmission)
            {
                var dict = matchE_[0]._Params;
                if (dict.TryGetValue(SCOLOR, out output))
                {
                    Int32 iColorInt = Convert.ToInt32(output.Substring(1), 16);
                    emission = System.Drawing.Color.FromArgb(iColorInt);
                }
                if (dict.TryGetValue(SOPAC, out output))
                {
                    Double a;
                    if (Double.TryParse(output, out a))
                    {
                        Byte alpha = (Byte)Math.Min(255, Math.Max(0, (a * 255)));
                        emission = Color.FromArgb(alpha, emission);
                    }
                }
            }

            co._Color = new ColorGL();
            co._Color._Diffuse[0] = diffuse.R / 255.0f;
            co._Color._Diffuse[1] = diffuse.G / 255.0f;
            co._Color._Diffuse[2] = diffuse.B / 255.0f;
            co._Color._Diffuse[3] = diffuse.A / 255.0f;

            co._Color._Ambient[0] = ambient.R / 255.0f;
            co._Color._Ambient[1] = ambient.G / 255.0f;
            co._Color._Ambient[2] = ambient.B / 255.0f;
            co._Color._Ambient[3] = ambient.A / 255.0f;

            co._Color._Specular[0] = specular.R / 255.0f;
            co._Color._Specular[1] = specular.G / 255.0f;
            co._Color._Specular[2] = specular.B / 255.0f;
            co._Color._Specular[3] = specular.A / 255.0f;

            co._Color._Emission[0] = emission.R / 255.0f;
            co._Color._Emission[1] = emission.G / 255.0f;
            co._Color._Emission[2] = emission.B / 255.0f;
            co._Color._Emission[3] = emission.A / 255.0f;
        }
示例#20
0
 public DwgObjectTemplate(CadObject cadObject) : base(cadObject)
 {
 }
示例#21
0
 public DwgTemplate(CadObject cadObject)
 {
     CadObject = cadObject;
 }
示例#22
0
        public static CadObject CreateSphere(
            float radius,
            int resolution = 0,
            String name = "Sphere"
            )
        {
            double r = 0.5 / Math.Sin(MathHelper.DegreesToRadians(36));
            double r_sq = r * r;
            double vx = Math.Sqrt(1 - r_sq);
            double vy = (2 * r_sq - 1) / vx;

            Vector3[] middle_ring = new Vector3[10];
            Vector3 top = new Vector3(0.0f, 1, 0.0f);
            Vector3 bot = new Vector3(0.0f, -1, 0.0f);

            for (int i = 0; i < 10; i++)
            {
                float ang = i * 36;
                middle_ring[i].X = (float)(r * Math.Sin(MathHelper.DegreesToRadians(ang)));
                middle_ring[i].Z = (float)(r * Math.Cos(MathHelper.DegreesToRadians(ang)));
                middle_ring[i].Y = (float)((vy / 2) * ((i % 2) * 2 - 1));
                middle_ring[i].Normalize();
            }

            var all = new List<Vector3>();

            // Middle Ring
            all.Add(middle_ring[0]); all.Add(middle_ring[2]); all.Add(middle_ring[1]);
            all.Add(middle_ring[1]); all.Add(middle_ring[9]); all.Add(middle_ring[0]);
            all.Add(middle_ring[2]); all.Add(middle_ring[4]); all.Add(middle_ring[3]);
            all.Add(middle_ring[3]); all.Add(middle_ring[1]); all.Add(middle_ring[2]);
            all.Add(middle_ring[4]); all.Add(middle_ring[6]); all.Add(middle_ring[5]);
            all.Add(middle_ring[5]); all.Add(middle_ring[3]); all.Add(middle_ring[4]);
            all.Add(middle_ring[6]); all.Add(middle_ring[8]); all.Add(middle_ring[7]);
            all.Add(middle_ring[7]); all.Add(middle_ring[5]); all.Add(middle_ring[6]);
            all.Add(middle_ring[8]); all.Add(middle_ring[0]); all.Add(middle_ring[9]);
            all.Add(middle_ring[9]); all.Add(middle_ring[7]); all.Add(middle_ring[8]);

            // Top 5
            all.Add(middle_ring[1]); all.Add(middle_ring[3]); all.Add(top);
            all.Add(middle_ring[3]); all.Add(middle_ring[5]); all.Add(top);
            all.Add(middle_ring[5]); all.Add(middle_ring[7]); all.Add(top);
            all.Add(middle_ring[7]); all.Add(middle_ring[9]); all.Add(top);
            all.Add(middle_ring[9]); all.Add(middle_ring[1]); all.Add(top);

            // Bottom 5
            all.Add(bot); all.Add(middle_ring[2]); all.Add(middle_ring[0]);
            all.Add(bot); all.Add(middle_ring[4]); all.Add(middle_ring[2]);
            all.Add(bot); all.Add(middle_ring[6]); all.Add(middle_ring[4]);
            all.Add(bot); all.Add(middle_ring[8]); all.Add(middle_ring[6]);
            all.Add(bot); all.Add(middle_ring[0]); all.Add(middle_ring[8]);

            for (int dex = 0; dex < resolution; dex++)
            {
                Vector3 p1, p2, p3, p4, p5, p6;
                var n = new List<Vector3>();
                for (int i = 0; i < all.Count; i += 3)
                {
                    p1 = all[i];
                    p2 = all[i+1];
                    p3 = all[i+2];
                    p4 = p3 + p1;
                    p5 = p2 + p1;
                    p6 = p2 + p3;
                    p4.Normalize();
                    p5.Normalize();
                    p6.Normalize();
                    n.Add(p1); n.Add(p5); n.Add(p4);
                    n.Add(p5); n.Add(p2); n.Add(p6);
                    n.Add(p4); n.Add(p5); n.Add(p6);
                    n.Add(p4); n.Add(p6); n.Add(p3);
                }
                all = n;
            }

            List<Vector3> vs = new List<Vector3>();
            List<Vector3> ns = new List<Vector3>();

            foreach (var v in all)
            {
                ns.Add(v);
                vs.Add(v * radius);                    
            }

            CadObject co = new CadObject(vs.ToArray(), ns.ToArray(), name);

            co.setBoundingSphere(Vector3.Zero, radius);

            return co;
        }
示例#23
0
        protected void readMapped <T>(CadObject cadObject, CadTemplate template)
            where T : CadObject
        {
            DxfClassMap map = DxfClassMap.Create <T>();

            Debug.Assert(map.Name == this._reader.LastValueAsString);
            this._reader.ReadNext();

            while (this._reader.LastDxfCode != DxfCode.Start &&
                   this._reader.LastDxfCode != DxfCode.Subclass)
            {
                //Check for an extended data code
                if (this._reader.LastDxfCode >= DxfCode.ExtendedDataAsciiString)
                {
                    this.readExtendedData(cadObject);
                    this._reader.ReadNext();
                    continue;
                }
                else if (this._reader.LastDxfCode == DxfCode.ControlString)
                {
                    if (!template.CheckDxfCode(this._reader.LastCode, this._reader.LastValue))
                    {
                        this.readDefinedGroups(template);
                    }
                    else
                    {
                        this._reader.ReadNext();
                    }

                    continue;
                }

                if (!map.DxfProperties.TryGetValue(this._reader.LastCode, out DxfProperty dxfProperty))
                {
                    if (!template.CheckDxfCode(this._reader.LastCode, this._reader.LastValue))
                    {
                        this._notification?.Invoke(null, new NotificationEventArgs($"Dxf code {this._reader.LastCode} not found in map for {typeof(T)} | value : {this._reader.LastValueAsString}"));
                    }

                    this._reader.ReadNext();
                    continue;
                }

                if (dxfProperty.ReferenceType == DxfReferenceType.Handle)
                {
                    if (!template.AddHandle(this._reader.LastCode, this._reader.LastValueAsHandle))
                    {
                        this._notification?.Invoke(null, new NotificationEventArgs($"Dxf referenced code {this._reader.LastCode} not implemented in the {template.GetType().Name} for {typeof(T)} | value : {this._reader.LastValueAsHandle}"));
                    }
                }
                else if (dxfProperty.ReferenceType == DxfReferenceType.Name)
                {
                    if (!template.AddName(this._reader.LastCode, this._reader.LastValueAsString))
                    {
                        this._notification?.Invoke(null, new NotificationEventArgs($"Dxf named referenced code {this._reader.LastCode} not implemented in the {template.GetType().Name} for {typeof(T)} | value : {this._reader.LastValueAsHandle}"));
                    }
                }
                else if (dxfProperty.ReferenceType == DxfReferenceType.Count)
                {
                    //Do nothing just marks the amount
                }
                else
                {
                    switch (this._reader.LastGroupCodeValue)
                    {
                    case GroupCodeValueType.String:
                    case GroupCodeValueType.Point3D:
                    case GroupCodeValueType.Double:
                    case GroupCodeValueType.Int16:
                    case GroupCodeValueType.Int32:
                    case GroupCodeValueType.Int64:
                    case GroupCodeValueType.Chunk:
                    case GroupCodeValueType.Bool:
                        dxfProperty.SetValue(cadObject, this._reader.LastValue);
                        break;

                    case GroupCodeValueType.Comment:
                        this._notification?.Invoke(null, new NotificationEventArgs($"Comment in the file :  {this._reader.LastValueAsString}"));
                        break;

                    case GroupCodeValueType.Handle:
                    case GroupCodeValueType.ObjectId:
                    case GroupCodeValueType.None:
                    default:
                        this._notification?.Invoke(null, new NotificationEventArgs($"Group Code not handled {this._reader.LastGroupCodeValue} for {typeof(T)}, code : {this._reader.LastCode} | value : {this._reader.LastValueAsString}"));
                        break;
                    }
                }

                this._reader.ReadNext();
            }
        }
示例#24
0
        public static CadObject xamlModelGeometryModel3D(
            TagFile f0,
            float xScale,
            float yScale,
            float zScale,
            bool useAmbient,
            bool useDiffuse,
            bool useSpecular,
            bool useEmission)
        {
            var co = new CadObject();

            var u1 = new HashSet<string>();

            foreach (var e1 in f0._Children)
            {
                if (e1 is TagFile)
                {
                    var f1 = e1 as TagFile;

                    if (u1.Contains(f1._Name)) Console.WriteLine("CadObjectGenerator." + System.Reflection.MethodBase.GetCurrentMethod().Name + " multiple " + f1._Name);
                    else
                    {
                        u1.Add(f1._Name);
                        switch (f1._Name)
                        {
                            case "GeometryModel3D.Material":
                                {
                                    xamlParseColor(f1, useAmbient, useDiffuse, useSpecular, useEmission, co);
                                    break;
                                }
                            case "GeometryModel3D.Geometry":
                                var u2 = new HashSet<string>();
                                foreach (var e2 in f1._Children)
                                {
                                    if (e2 is TagFile)
                                    {
                                        var f2 = e2 as TagFile;
                                        if (u2.Contains(f2._Name)) Console.WriteLine("CadObjectGenerator." + System.Reflection.MethodBase.GetCurrentMethod().Name + " multiple " + f2._Name);
                                        else
                                        {
                                            switch (f2._Name)
                                            {
                                                case "MeshGeometry3D":
                                                    {
                                                        var data = f2._Params;
                                                        var verts = new List<Vector3>();
                                                        var norms = new List<Vector3>();
                                                        xamlParseDict(ref data, ref verts, ref norms);
                                                        var verts2array = verts.ToArray();
                                                        var norms2array = norms.ToArray();
                                                        for (int j = 0; j < verts.Count; j++)
                                                        {
                                                            verts2array[j].X *= xScale;
                                                            verts2array[j].Y *= yScale;
                                                            verts2array[j].Z *= zScale;
                                                        }
                                                        co.initializeWithVectorsAndNormals(verts2array, norms2array);
                                                        break;
                                                    }
                                                default:
                                                    Console.WriteLine("CadObjectGenerator: GeometryModel3D.Geometry ignoring " + f2._Name);
                                                    break;
                                            }
                                        }
                                    }
                                }
                                break;
                            default:
#if DEBUG
                                Console.WriteLine("CadObjectGenerator: GeometryModel3D ignoring " + f1._Name);
#endif
                                break;
                        }
                    }
                }
            }

            return co;
        }
示例#25
0
 public void Compare(CadObject cad)
 {
     foreach (DxfCodeValuePair item in Validation)
     {
     }
 }
示例#26
0
 public void addParts(CadObject[] list)
 {
     var cb = this.checkedListBox1;
     int cc = cb.Items.Count;
     cb.Items.AddRange(list);
     for (int i = 0; i < list.Length; i++) cb.SetItemCheckState(cc + i, CheckState.Checked);
 }