Ejemplo n.º 1
0
        private void Grbl_CoordinateChanged(object sender, EventArgs e)
        {
            var box = new LineBuilder();

            box.AddBox(new Vector3((float)App.Grbl.MPOS.X, (float)App.Grbl.MPOS.Y, (float)App.Grbl.MPOS.Z + 10), 1, 1, 20);
            CurrentPosition = box.ToLineGeometry3D();
        }
        static OcTreeManager()
        {
            LineBuilder b = new LineBuilder();

            b.AddBox(Vector3.Zero, 1, 1, 1);
            CellFrame = b.ToLineGeometry3D();

            EndPoint = LinesCutom.GetEndPointMarker(Vector3.Zero, (float)SNAPPOSMARKER_FACT * 0.8f);
            MidPoint = LinesCutom.GetMidPointMarker(Vector3.Zero, (float)SNAPPOSMARKER_FACT);
            IntPoint = LinesCutom.GetIntersectionMarker(Vector3.Zero, (float)SNAPPOSMARKER_FACT);

            ChamferedBoxMesh = MeshesCustom.GetChamferedBox(Vector3.Zero, 1f, 1f, 1f, 0.2f, 0.05f);
            MeshesCustom.CompressMesh(ref ChamferedBoxMesh);

            ChamferedBoxMesh_Normals = MeshesCustom.GetVertexNormalsAsLines(ChamferedBoxMesh, 0.15f);

            RedTransparent = new PhongMaterial();
            RedTransparent.DiffuseColor      = new Color4(0.8f, 0f, 0f, 0.25f);
            RedTransparent.AmbientColor      = new Color4(0.6f, 0f, 0f, 1f);
            RedTransparent.SpecularColor     = new Color4(1f, 0.75f, 0f, 1f);
            RedTransparent.SpecularShininess = 1;

            YellowTransparent = new PhongMaterial();
            YellowTransparent.DiffuseColor      = new Color4(1f, 0.93f, 0f, 0.5f);
            YellowTransparent.AmbientColor      = new Color4(0.92f, 0.69f, 0f, 1f);
            YellowTransparent.SpecularColor     = new Color4(1f, 1f, 1f, 1f);
            YellowTransparent.SpecularShininess = 3;
        }
        public override LineGeometry3D Build(double _startMarkerSize = 0.1)
        {
            if (this.contour == null)
            {
                if (this.quad == null)
                {
                    this.contour = null;
                    return(null);
                }

                int n = this.quad.Count;
                if (n < 3)
                {
                    this.contour = null;
                    return(null);
                }

                LineBuilder b = new LineBuilder();
                for (int i = 0; i < n; i++)
                {
                    b.AddLine(this.quad[i], this.quad[(i + 1) % n]);
                }
                this.contour = b.ToLineGeometry3D();
            }
            return(this.contour);
        }
Ejemplo n.º 4
0
        void VisualiseModel(ModelBase model)
        {
            Model = new MeshGeometry3D()
            {
                Positions          = model.Positions,
                Indices            = model.Indices,
                Normals            = model.Normals,
                TextureCoordinates = null,
                Tangents           = null,
                BiTangents         = null,
            };

            // визуализация граней
            //var inxs = new IntCollection();
            //model.Edges.ForEach(x => inxs.AddAll(x.Indices));
            //Edges = new LineGeometry3D { Positions = model.Positions, Indices = inxs };

            // визуализация граней Face
            var inxs2 = new IntCollection();

            model.Faces.ForEach(x => x.Edges.ForEach(x2 => inxs2.AddAll(x2.Indices)));
            Edges = new LineGeometry3D {
                Positions = model.Positions, Indices = inxs2
            };
            EdgesColor = Colors.Red;
        }
Ejemplo n.º 5
0
 public HelixRenderPackage()
 {
     points = InitPointGeometry();
     lines  = InitLineGeometry();
     mesh   = InitMeshGeometry();
     lineStripVertexCounts = new List <int>();
 }
        public SurfaceBasicInfo(LineGeometry3D _display_lines, HelixToolkit.SharpDX.Wpf.MeshGeometry3D _display_mesh, List <Vector3> _vertices_in_order,
                                long _volume_id, bool _is_wall, int _level_or_label, int _label_for_opeings, long _wall_lower_poly, long _wall_upper_poly,
                                double _area, double _height, double _width, long _material_id)
        {
            this.DisplayLines      = _display_lines;
            this.DisplayMesh       = _display_mesh;
            this.vertices_in_order = _vertices_in_order;
            this.SurfaceNormal     = Utils.MeshesCustom.GetPolygonNormalNewell(this.vertices_in_order);

            this.VolumeID         = _volume_id;
            this.IsWall           = _is_wall;
            this.LevelOrLabel     = _level_or_label;
            this.LabelForOpenings = _label_for_opeings;
            this.Wall_LowerPoly   = _wall_lower_poly;
            this.Wall_UpperPoly   = _wall_upper_poly;

            this.Area_AXES   = _area;
            this.Height_AXES = _height;
            this.Width_AXES  = _width;

            this.Material_ID = _material_id;

            this.Openings = new List <SurfaceBasicInfo>();

            this.Processed = false;
        }
Ejemplo n.º 7
0
 public HelixRenderPackage()
 {
     points = InitPointGeometry();
     lines  = InitLineGeometry();
     mesh   = InitMeshGeometry();
     lineStripVertexCounts = new List <int>();
     Transform             = System.Windows.Media.Media3D.Matrix3D.Identity.ToArray();
 }
Ejemplo n.º 8
0
        // alternative to base.HitTest(rayWS, ref hits);
        protected bool MyHitTest(Ray rayWS, ref List <HitTestResult> hits)
        {
            LineGeometry3D lineGeometry3D = this.Geometry as LineGeometry3D;
            Viewport3DX    viewport       = FindVisualAncestor <Viewport3DX>(this.renderHost as DependencyObject);

            if (this.Visibility == System.Windows.Visibility.Collapsed ||
                this.IsHitTestVisible == false ||
                viewport == null ||
                lineGeometry3D == null)
            {
                return(false);
            }

            var result = new HitTestResult {
                IsValid = false, Distance = double.MaxValue
            };
            var lastDist = double.MaxValue;
            var index    = 0;

            foreach (var line in lineGeometry3D.Lines)
            {
                var     t0 = Vector3.TransformCoordinate(line.P0, this.ModelMatrix);
                var     t1 = Vector3.TransformCoordinate(line.P1, this.ModelMatrix);
                Vector3 sp, tp;
                float   sc, tc;
                var     distance = GetRayToLineDistance(rayWS, t0, t1, out sp, out tp, out sc, out tc);
                var     svpm     = viewport.GetScreenViewProjectionMatrix();
                Vector4 sp4;
                Vector4 tp4;
                Vector3.Transform(ref sp, ref svpm, out sp4);
                Vector3.Transform(ref tp, ref svpm, out tp4);
                var sp3  = sp4.ToVector3();
                var tp3  = tp4.ToVector3();
                var tv2  = new Vector2(tp3.X - sp3.X, tp3.Y - sp3.Y);
                var dist = tv2.Length();
                if (dist < lastDist && dist <= this.HitTestThickness)
                {
                    lastDist           = dist;
                    result.PointHit    = sp.ToPoint3D();
                    result.NormalAtHit = (sp - tp).ToVector3D(); // not normalized to get length
                    result.Distance    = distance;
                    result.ModelHit    = this;
                    result.IsValid     = true;
                    result.Tag         = index; // ToDo: LineHitTag with additional info
                }

                index++;
            }

            if (result.IsValid)
            {
                hits.Add(result);
            }
            this.hResult = result;
            return(result.IsValid);
        }
Ejemplo n.º 9
0
        internal static LineGeometry3D InitLineGeometry()
        {
            var lines = new LineGeometry3D
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };

            return(lines);
        }
Ejemplo n.º 10
0
        private void StartSLAM()
        {
            IsSLAMOn = true;
            string temp = "";

            RealsenseControl.StartSLAM(ref temp);
            RealsenseState = temp;
            Thread.Sleep(2000);
            SLAMPointCloud           = new PointGeometry3D();
            SLAMPoseInfo             = new LineGeometry3D();
            UpdateSLAMPointCloudTask = Task.Run(() => UpdateSLAMPointCloud());
        }
Ejemplo n.º 11
0
        private async Task StartSLAM()
        {
            IsSLAMOn = true;
            string temp = "";
            await Task.Run(() => RealsenseControl.StartSLAM(ref temp)).ConfigureAwait(false);

            RealsenseState           = temp;
            SLAMPointCloud           = new PointGeometry3D();
            SLAMPoseInfo             = new LineGeometry3D();
            UpdateSLAMPointCloudTask = Task.Run(() => UpdateSLAMPointCloud());
            SLAMReconTaskAsync       = Task.Run(() => SLAMRecon());
        }
Ejemplo n.º 12
0
        private void CreateWireFrameModels(IFCItem item, Vector3 center)
        {
            while (item != null)
            {
                if (item.ifcID != IntPtr.Zero && item.noVerticesForWireFrame != 0 && item.noPrimitivesForWireFrame != 0)
                {
                    var geo = new LineGeometry3D();
                    geo.Positions = new Vector3Collection();
                    geo.Indices   = new IntCollection();
                    var points = new Vector3Collection();
                    if (item.verticesForWireFrame != null)
                    {
                        for (int i = 0; i < item.noVerticesForWireFrame; i++)
                        {
                            points.Add(new Vector3((item.verticesForWireFrame[3 * i + 0] - center.X), (item.verticesForWireFrame[3 * i + 1] - center.Y), (item.verticesForWireFrame[3 * i + 2] - center.Z)));
                            geo.Positions.Add(new Vector3((item.verticesForWireFrame[3 * i + 0] - center.X), (item.verticesForWireFrame[3 * i + 1] - center.Y), (item.verticesForWireFrame[3 * i + 2] - center.Z)));
                        }
                    }

                    if (item.indicesForWireFrameLineParts != null)
                    {
                        for (int i = 0; i < item.noPrimitivesForWireFrame; i++)
                        {
                            var idx = item.indicesForWireFrameLineParts[2 * i + 0];
                            geo.Indices.Add(idx);
                            idx = item.indicesForWireFrameLineParts[2 * i + 1];
                            geo.Indices.Add(idx);
                        }
                    }
                    else
                    {
                        for (int i = 0, count = points.Count; i < count; i++)
                        {
                            geo.Indices.Add(i);
                            geo.Indices.Add((i + 1) % count);
                        }
                    }

                    LineGeometryModel3D line = new LineGeometryModel3D();
                    line.Geometry  = geo;
                    line.Color     = _defaultLineColor;
                    line.Thickness = 0.5;
                    item.Wireframe = line;

                    line.Tag = item.ifcType + ":" + item.ifcID;
                    model.Add(line);
                }

                CreateFaceModels(item.child, center);
                item = item.next;
            }
        }
        public void AdjustToVolumeChange(bool _is_wall, long _idInOwner, int _key, ICollection <Vector3> _quad, float _area, int _opening_ind = -1)
        {
            // ownership does not change
            this.IsWall       = _is_wall;
            this.KeyInOwner   = _key;
            this.IDInOwner    = _idInOwner;
            this.OpeningIndex = _opening_ind;

            // geometry
            this.quad      = new List <Vector3>(_quad);
            this.AssocArea = _area;
            this.contour   = null;
        }
Ejemplo n.º 14
0
        public DynaShapeDisplay(Solver solver)
        {
            this.solver = solver;

            pointGeometry = new PointGeometry3D
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };

            lineGeometry = new LineGeometry3D()
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };

            DynaShapeViewExtension.DynamoWindow.Dispatcher.Invoke(
                () =>
            {
                pointModel = new PointGeometryModel3D
                {
                    Size   = new Size(5, 5),
                    Figure = PointGeometryModel3D.PointFigure.Ellipse,
                    Color  = Color.White,
                };


                lineModel = new LineGeometryModel3D
                {
                    Thickness = 0.5,
                    Color     = Color.White,
                };

                List <string> info1 = new List <string>();
                foo(DynaShapeViewExtension.DynamoWindow.Content, info1, 0);

                List <string> info2 = new List <string>();
                ListContent(DynaShapeViewExtension.DynamoWindow.Content as Grid, 0, info2);
            },
                DispatcherPriority.Send);

            DynaShapeViewExtension.ViewModel.RequestViewRefresh += RequestViewRefreshHandler;

            DynaShapeViewExtension.DynamoWindow.Closed += (sender, args) =>
            {
                Dispose();
            };
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Create the grid
        /// </summary>
        private void DrawGrid()
        {
            Grid = new LineGeometry3D();
            var positions = new Vector3Collection();
            var indices   = new IntCollection();
            var colors    = new Color4Collection();

            for (var i = 0; i < 10; i += 1)
            {
                for (var j = 0; j < 10; j += 1)
                {
                    DrawGridPatch(positions, indices, colors, -50 + i * 10, -50 + j * 10);
                }
            }

            Grid.Positions = positions;
            Grid.Indices   = indices;
            Grid.Colors    = colors;

            Axes = new LineGeometry3D();
            var axesPositions = new Vector3Collection();
            var axesIndices   = new IntCollection();
            var axesColors    = new Color4Collection();

            // Draw the coordinate axes
            axesPositions.Add(new Vector3());
            axesIndices.Add(axesPositions.Count - 1);
            axesPositions.Add(new Vector3(50, 0, 0));
            axesIndices.Add(axesPositions.Count - 1);
            axesColors.Add(SharpDX.Color.Red);
            axesColors.Add(SharpDX.Color.Red);

            axesPositions.Add(new Vector3());
            axesIndices.Add(axesPositions.Count - 1);
            axesPositions.Add(new Vector3(0, 5, 0));
            axesIndices.Add(axesPositions.Count - 1);
            axesColors.Add(SharpDX.Color.Blue);
            axesColors.Add(SharpDX.Color.Blue);

            axesPositions.Add(new Vector3());
            axesIndices.Add(axesPositions.Count - 1);
            axesPositions.Add(new Vector3(0, 0, -50));
            axesIndices.Add(axesPositions.Count - 1);
            axesColors.Add(SharpDX.Color.Green);
            axesColors.Add(SharpDX.Color.Green);

            Axes.Positions = axesPositions;
            Axes.Indices   = axesIndices;
            Axes.Colors    = axesColors;
        }
Ejemplo n.º 16
0
        public void Clear()
        {
            points = null;
            mesh   = null;
            lines  = null;

            points = InitPointGeometry();
            mesh   = InitMeshGeometry();
            lines  = InitLineGeometry();

            lineStripVertexCounts.Clear();

            IsSelected    = false;
            DisplayLabels = false;
        }
        public ZonedVolumeSurfaceVis(ZonedVolume _ownerV, bool _is_wall, long _idInOwner, int _key,
                                     ICollection <Vector3> _quad, float _area, int _opening_ind = -1)
            : base(null)
        {
            // ownership
            this.OwnerVolume  = _ownerV;
            this.IsWall       = _is_wall;
            this.KeyInOwner   = _key;
            this.IDInOwner    = _idInOwner;
            this.OpeningIndex = _opening_ind;

            // geometry
            this.quad = new List <Vector3>(_quad);

            this.AssocArea = _area;
            this.contour   = null;
        }
Ejemplo n.º 18
0
        public DynaShapeDisplay(Solver solver)
        {
            this.solver = solver;

            pointGeometry = new PointGeometry3D
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };

            lineGeometry = new LineGeometry3D()
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };

            billboardText = new BillboardText3D();

            DynaShapeViewExtension.DynamoWindow.Dispatcher.Invoke(
                () =>
            {
                pointModel = new PointGeometryModel3D
                {
                    Size   = new Size(5, 5),
                    Figure = PointGeometryModel3D.PointFigure.Ellipse,
                    Color  = Color.White,
                };

                lineModel = new LineGeometryModel3D
                {
                    Thickness = 0.5,
                    Color     = Color.White,
                };

                billboardTextModel = new BillboardTextModel3D()
                {
                };
            },
                DispatcherPriority.Send);

            DynaShapeViewExtension.ViewModel.RequestViewRefresh += RequestViewRefreshHandler;
            DynaShapeViewExtension.DynamoWindow.Closed          += (sender, args) => Dispose();
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Called when [build vertex array].
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <returns></returns>
        protected override LinesVertex[] OnBuildVertexArray(LineGeometry3D geometry)
        {
            var positions   = geometry.Positions;
            var vertexCount = geometry.Positions.Count;
            var array       = vertexArrayBuffer != null && vertexArrayBuffer.Length >= vertexCount ? vertexArrayBuffer : new LinesVertex[vertexCount];
            var colors      = geometry.Colors != null?geometry.Colors.GetEnumerator() : Enumerable.Repeat(Color4.White, vertexCount).GetEnumerator();

            vertexArrayBuffer = array;

            for (var i = 0; i < vertexCount; i++)
            {
                colors.MoveNext();
                array[i].Position = new Vector4(positions[i], 1f);
                array[i].Color    = colors.Current;
            }
            colors.Dispose();
            return(array);
        }
Ejemplo n.º 20
0
        public void Clear()
        {
            points = null;
            mesh   = null;
            lines  = null;

            points = InitPointGeometry();
            mesh   = InitMeshGeometry();
            lines  = InitLineGeometry();

            lineStripVertexCounts.Clear();

            Transform = System.Windows.Media.Media3D.Matrix3D.Identity.ToArray();

            IsSelected    = false;
            DisplayLabels = false;

            colors = null;
        }
Ejemplo n.º 21
0
        public void OnMouseLeftButtonDownHandler(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var viewport = sender as Viewport3DX;

            if (viewport == null)
            {
                return;
            }
            var point    = e.GetPosition(viewport);
            var watch    = Stopwatch.StartNew();
            var hitTests = viewport.FindHits(point);

            watch.Stop();
            Console.WriteLine("Hit test time =" + watch.ElapsedMilliseconds);
            if (hitTests.Count > 0)
            {
                var lineBuilder = new LineBuilder();
                foreach (var hit in hitTests)
                {
                    lineBuilder.AddLine(hit.PointHit, (hit.PointHit + hit.NormalAtHit * 10));
                }
                LineGeo = lineBuilder.ToLineGeometry3D();
            }
        }
Ejemplo n.º 22
0
        public MainViewModel()
        {            // titles
            this.Title     = "DynamicTexture Demo";
            this.SubTitle  = "WPF & SharpDX";
            EffectsManager = new DefaultEffectsManager();
            this.Camera    = new HelixToolkit.Wpf.SharpDX.PerspectiveCamera
            {
                Position      = new Point3D(10, 10, 10),
                LookDirection = new Vector3D(-10, -10, -10),
                UpDirection   = new Vector3D(0, 1, 0)
            };
            this.Light1Color       = Colors.White;
            this.Light1Direction   = new Vector3D(-10, -10, -10);
            this.AmbientLightColor = Colors.Black;

            var b2 = new MeshBuilder(true, true, true);

            b2.AddSphere(new Vector3(0f, 0f, 0f), 4, 64, 64);
            this.Model      = b2.ToMeshGeometry3D();
            Model.IsDynamic = true;
            this.InnerModel = new MeshGeometry3D()
            {
                Indices            = Model.Indices,
                Positions          = Model.Positions,
                Normals            = Model.Normals,
                TextureCoordinates = Model.TextureCoordinates,
                Tangents           = Model.Tangents,
                BiTangents         = Model.BiTangents,
                IsDynamic          = true
            };

            var image = TextureModel.Create(new System.Uri(@"test.png", System.UriKind.RelativeOrAbsolute).ToString());

            this.ModelMaterial = new PhongMaterial
            {
                AmbientColor      = Colors.Gray.ToColor4(),
                DiffuseColor      = Colors.White.ToColor4(),
                SpecularColor     = Colors.White.ToColor4(),
                SpecularShininess = 100f,
                DiffuseAlphaMap   = image,
                DiffuseMap        = TextureModel.Create(new System.Uri(@"TextureCheckerboard2.dds", System.UriKind.RelativeOrAbsolute).ToString()),
                NormalMap         = TextureModel.Create(new System.Uri(@"TextureCheckerboard2_dot3.dds", System.UriKind.RelativeOrAbsolute).ToString()),
            };

            this.InnerModelMaterial = new PhongMaterial
            {
                AmbientColor      = Colors.Gray.ToColor4(),
                DiffuseColor      = new Color4(0.75f, 0.75f, 0.75f, 1.0f),
                SpecularColor     = Colors.White.ToColor4(),
                SpecularShininess = 100f,
                DiffuseAlphaMap   = image,
                DiffuseMap        = TextureModel.Create(new System.Uri(@"TextureNoise1.jpg", System.UriKind.RelativeOrAbsolute).ToString()),
                NormalMap         = ModelMaterial.NormalMap
            };


            initialPosition = Model.Positions;
            initialIndicies = Model.Indices;
            #region Point Model
            PointModel = new PointGeometry3D()
            {
                IsDynamic = true, Positions = Model.Positions
            };
            int count  = PointModel.Positions.Count;
            var colors = new Color4Collection(count);
            for (int i = 0; i < count / 2; ++i)
            {
                colors.Add(new Color4(0, 1, 1, 1));
            }
            for (int i = 0; i < count / 2; ++i)
            {
                colors.Add(new Color4(0, 0, 0, 0));
            }
            PointModel.Colors = colors;
            #endregion

            #region Line Model
            LineModel = new LineGeometry3D()
            {
                IsDynamic = true, Positions = new Vector3Collection(PointModel.Positions)
            };
            LineModel.Positions.Add(Vector3.Zero);
            var indices = new IntCollection(count * 2);
            for (int i = 0; i < count; ++i)
            {
                indices.Add(count);
                indices.Add(i);
            }
            LineModel.Indices = indices;
            colors            = new Color4Collection(LineModel.Positions.Count);
            for (int i = 0; i < count; ++i)
            {
                colors.Add(new Color4((float)i / count, 1 - (float)i / count, 0, 1));
            }
            colors.Add(Colors.Blue.ToColor4());
            LineModel.Colors = colors;
            LineMaterial     = new LineArrowHeadMaterial()
            {
                Color = Colors.White, Thickness = 0.5, ArrowSize = 0.02
            };
            #endregion
            var token = cts.Token;
            Task.Run(() =>
            {
                while (!token.IsCancellationRequested)
                {
                    Timer_Tick();
                    Task.Delay(16).Wait();
                }
            }, token);
            //timer.Interval = TimeSpan.FromMilliseconds(16);
            //timer.Tick += Timer_Tick;
            //timer.Start();
        }
Ejemplo n.º 23
0
        private void RenderAction()
        {
            Viewport3DX    viewport   = DynaShapeViewExtension.GetViewport();
            List <Model3D> sceneItems = viewport.ItemsSource as List <Model3D>;

            pointGeometry = new PointGeometry3D
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };

            lineGeometry = new LineGeometry3D()
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };


            foreach (MeshGeometryModel3D meshModel in meshModels)
            {
                meshModel.Detach();
                if (sceneItems.Contains(meshModel))
                {
                    sceneItems.Remove(meshModel);
                }
            }

            meshModels = new List <MeshGeometryModel3D>();


            //============================================
            // Render nodes as points
            //============================================

            for (int i = 0; i < solver.Nodes.Count; i++)
            {
                pointGeometry.Positions.Add(new Vector3(
                                                solver.Nodes[i].Position.X,
                                                solver.Nodes[i].Position.Z,
                                                -solver.Nodes[i].Position.Y));

                pointGeometry.Colors.Add(new Color4(0.8f, 0.2f, 0.2f, 1f));
                pointGeometry.Indices.Add(i);
            }


            //==============================================================
            // Render geometries from geometry binders
            //==============================================================

            foreach (GeometryBinder geometryBinder in solver.GeometryBinders)
            {
                geometryBinder.CreateDisplayedGeometries(this, solver.Nodes);
            }


            //============================================================================
            // Render GUI elements
            //============================================================================

            RenderGUI();


            //==============================================================
            // Attach the geometries to Helix render host
            //==============================================================

            if (pointGeometry.Positions.Count >= 1)
            {
                pointModel.Geometry = pointGeometry;
                if (!pointModel.IsAttached)
                {
                    pointModel.Attach(viewport.RenderHost);
                }
                if (!sceneItems.Contains(pointModel))
                {
                    sceneItems.Add(pointModel);
                }
            }
            else
            {
                pointModel.Detach();
                if (sceneItems.Contains(pointModel))
                {
                    sceneItems.Remove(pointModel);
                }
            }


            if (lineGeometry.Positions.Count >= 2)
            {
                lineModel.Geometry = lineGeometry;
                if (!lineModel.IsAttached)
                {
                    lineModel.Attach(viewport.RenderHost);
                }
                if (!sceneItems.Contains(lineModel))
                {
                    sceneItems.Add(lineModel);
                }
            }
            else
            {
                lineModel.Detach();
                if (sceneItems.Contains(lineModel))
                {
                    sceneItems.Remove(lineModel);
                }
            }


            foreach (MeshGeometryModel3D meshModel in meshModels)
            {
                if (meshModel.Geometry.Positions.Count >= 3)
                {
                    meshModel.Attach(viewport.RenderHost);
                    sceneItems.Add(meshModel);
                }
            }
        }
Ejemplo n.º 24
0
        private void RenderAction()
        {
            IRenderHost    renderHost = DynaShapeViewExtension.GetViewport().RenderHost;
            List <Model3D> sceneItems = DynaShapeViewExtension.GetSceneItems();


            pointGeometry = new PointGeometry3D
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };

            lineGeometry = new LineGeometry3D()
            {
                Positions = new Vector3Collection(),
                Indices   = new IntCollection(),
                Colors    = new Color4Collection()
            };


            billboardText = new BillboardText3D();

            foreach (MeshGeometryModel3D meshModel in meshModels)
            {
                meshModel.Detach();
                if (sceneItems.Contains(meshModel))
                {
                    sceneItems.Remove(meshModel);
                }
            }

            meshModels.Clear();

            //============================================
            // Render nodes as points
            //============================================

            int n = pointGeometry.Indices.Count;

            for (int i = 0; i < solver.Nodes.Count; i++)
            {
                pointGeometry.Positions.Add(solver.Nodes[i].Position.ToVector3());
                pointGeometry.Colors.Add(DefaultPointColor);
                pointGeometry.Indices.Add(n + i);
            }

            //==============================================================
            // Render geometries from geometry binders
            //==============================================================

            foreach (GeometryBinder geometryBinder in solver.GeometryBinders)
            {
                if (geometryBinder.Show)
                {
                    geometryBinder.CreateDisplayedGeometries(this, solver.Nodes);
                }
            }

            //============================================================================
            // Render GUI elements
            //============================================================================

            RenderGUI();

            //==============================================================
            // Attach the geometries to Helix render host
            //==============================================================

            if (pointGeometry.Positions.Count >= 1)
            {
                pointModel.Geometry = pointGeometry;
                if (!sceneItems.Contains(pointModel))
                {
                    sceneItems.Add(pointModel);
                }
                if (!pointModel.IsAttached)
                {
                    pointModel.Attach(renderHost);
                }
//                sceneItems.Remove(pointModel);
//                pointModel.Detach();
//                sceneItems.Add(pointModel);
//                sw.Restart();
//                pointModel.Attach(renderHost);
//                DynamoLogger.Instance.Log(sw.Elapsed.TotalMilliseconds + "ms (Attach)");
            }
            else
            {
                if (sceneItems.Contains(pointModel))
                {
                    sceneItems.Remove(pointModel);
                }
                pointModel.Detach();
            }

            if (lineGeometry.Positions.Count >= 2)
            {
                lineModel.Geometry = lineGeometry;
                if (!sceneItems.Contains(lineModel))
                {
                    sceneItems.Add(lineModel);
                }
                if (!lineModel.IsAttached)
                {
                    lineModel.Attach(renderHost);
                }
            }
            else
            {
                if (sceneItems.Contains(lineModel))
                {
                    sceneItems.Remove(lineModel);
                }
                lineModel.Detach();
            }

            foreach (MeshGeometryModel3D meshModel in meshModels)
            {
                sceneItems.Add(meshModel);
                meshModel.Attach(renderHost);
            }

            if (billboardText.TextInfo.Count >= 1)
            {
                billboardTextModel.Geometry = billboardText;
                if (!sceneItems.Contains(billboardTextModel))
                {
                    sceneItems.Add(billboardTextModel);
                }
                if (!billboardTextModel.IsAttached)
                {
                    billboardTextModel.Attach(renderHost);
                }
            }
            else
            {
                if (sceneItems.Contains(billboardTextModel))
                {
                    sceneItems.Remove(billboardTextModel);
                }
                billboardTextModel.Detach();
            }
        }
Ejemplo n.º 25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="geometry">The geometry.</param>
 /// <returns></returns>
 protected abstract VertexStruct[] OnBuildVertexArray(LineGeometry3D geometry);