コード例 #1
0
        public void HelixRenderPackage_AppendPointVertexColorRange_ThrowsForBadRange()
        {
            var p = new HelixRenderPackage();

            PushPointIntoPackage(p);
            PushPointIntoPackage(p);

            var testColors = WhiteByteArrayOfLength(1);

            try
            {
                p.AppendPointVertexColorRange(testColors);
            }
            catch (Exception e)
            {
                Assert.AreEqual(e.GetType(), typeof(Exception));
            }

            Assert.AreEqual(0, p.PointVertexColorCount);

            testColors = WhiteByteArrayOfLength(3);

            try
            {
                p.AppendPointVertexColorRange(testColors);
            }
            catch (Exception e)
            {
                Assert.AreEqual(e.GetType(), typeof(Exception));
            }

            Assert.AreEqual(0, p.PointVertexColorCount);
        }
コード例 #2
0
        public void HelixRenderPackage_ApplyPointVertexColors_Array_Success()
        {
            var p = new HelixRenderPackage();

            Assert.NotNull(p);

            PushPointIntoPackage(p);
            p.ApplyPointVertexColors(WhiteByteArrayOfLength(1));
            Assert.AreEqual(1, p.Points.Colors.Count);
        }
コード例 #3
0
        public void HelixRenderPackage_ApplyLineVertexColors_Array_Success()
        {
            var p = new HelixRenderPackage();

            Assert.NotNull(p);

            PushLineIntoPackage(p);
            p.ApplyLineVertexColors(WhiteByteArrayOfLength(2));
            Assert.AreEqual(2, p.Lines.Colors.Count);
        }
コード例 #4
0
        public void HelixRenderPackage_ApplyMeshVertexColors_Success()
        {
            var p = new HelixRenderPackage();

            Assert.NotNull(p);

            PushQuadIntoPackage(p);

            p.ApplyMeshVertexColors(WhiteByteArrayOfLength(6));
            Assert.AreEqual(6, p.Mesh.Colors.Count);
        }
コード例 #5
0
        public void HelixRenderPackage_MeshColorBufferCheck()
        {
            var p = new HelixRenderPackage();

            PushQuadIntoPackage(p);

            var testColors = WhiteByteArrayOfLength(6);

            p.ApplyMeshVertexColors(testColors);

            Assert.AreEqual(p.MeshVertexColors, testColors);
        }
コード例 #6
0
        public void HelixRenderPackage_PushMesh()
        {
            var p = new HelixRenderPackage();

            Assert.NotNull(p);

            PushQuadIntoPackage(p);
            Assert.AreEqual(6, p.Mesh.Positions.Count);
            Assert.AreEqual(6, p.Mesh.TextureCoordinates.Count);
            Assert.AreEqual(6, p.Mesh.Indices.Count);
            Assert.AreEqual(0, p.Mesh.Colors.Count);
        }
コード例 #7
0
        public void HelixRenderPackage_PushPoint()
        {
            var p = new HelixRenderPackage();

            Assert.NotNull(p);

            PushPointIntoPackage(p);

            Assert.AreEqual(1, p.Points.Positions.Count);
            Assert.AreEqual(1, p.Points.Indices.Count);
            Assert.AreEqual(0, p.Points.Colors.Count);
        }
コード例 #8
0
        public void HelixRenderPackage_SingleLineVertexColor_AllLineStripVerticesHaveColor_True()
        {
            var p = new HelixRenderPackage();

            Assert.NotNull(p);

            // Same line strip vertex colors.
            HelixRenderPackageTests.PushLineIntoPackage(p);
            p.AddLineStripVertexColor(255, 0, 0, 255);
            p.AddLineStripVertexColor(255, 0, 0, 255);

            Assert.True(p.AllLineStripVerticesHaveColor(Color.FromArgb(255, 255, 0, 0)));
        }
コード例 #9
0
        public void HelixRenderPackage_ManyLineVertexColors_AllLineStripVerticesHaveColor_False()
        {
            var p = new HelixRenderPackage();

            Assert.NotNull(p);

            // Different line strip vertex colors.
            HelixRenderPackageTests.PushLineIntoPackage(p);
            p.AddLineStripVertexColor(255, 0, 0, 255);
            p.AddLineStripVertexColor(255, 255, 0, 0);

            Assert.False(p.AllLineStripVerticesHaveColor(Color.FromArgb(255, 255, 0, 0)));
        }
コード例 #10
0
        public void HelixRenderPackage_MeshVertexBufferCheck()
        {
            var p = new HelixRenderPackage();

            PushQuadIntoPackage(p);

            var test1 = p.MeshVertices.Skip(3).Take(3).ToArray();
            var test2 = p.MeshNormals.Take(3).ToArray();

            // Expect Y Up.
            Assert.AreEqual(test1, new double[] { 1, 0, 0 });
            Assert.AreEqual(test2, new double[] { 0, 1, 0 });
        }
コード例 #11
0
        private DynamoLineGeometryModel3D CreateLineGeometryModel3D(HelixRenderPackage rp, double thickness = 1.0)
        {
            var lineGeometry3D = new DynamoLineGeometryModel3D()
            {
                Geometry         = HelixRenderPackage.InitLineGeometry(),
                Transform        = Model1Transform,
                Color            = Color.White,
                Thickness        = thickness,
                IsHitTestVisible = false,
                IsSelected       = rp.IsSelected
            };

            return(lineGeometry3D);
        }
コード例 #12
0
        public void HelixRenderPackage_PushData_CountsAreCorrect()
        {
            var p = new HelixRenderPackage();

            Assert.NotNull(p);

            PushQuadIntoPackage(p);
            PushPointIntoPackage(p);
            PushLineIntoPackage(p);

            Assert.AreEqual(2, p.LineVertexCount);
            Assert.AreEqual(6, p.MeshVertexCount);
            Assert.AreEqual(1, p.PointVertexCount);
        }
コード例 #13
0
        private PointGeometryModel3D InitializePointWithId(string id, Vector3 location = new Vector3())
        {
            var pointGeom = HelixRenderPackage.InitPointGeometry();

            pointGeom.Positions.Add(location);
            pointGeom.Colors.Add(new Color4());
            pointGeom.Indices.Add(0);
            var point = new PointGeometryModel3D
            {
                Geometry = pointGeom,
                Name     = id
            };

            return(point);
        }
コード例 #14
0
        private DynamoPointGeometryModel3D CreatePointGeometryModel3D(HelixRenderPackage rp)
        {
            var pointGeometry3D = new DynamoPointGeometryModel3D
            {
                Geometry         = HelixRenderPackage.InitPointGeometry(),
                Transform        = Model1Transform,
                Color            = Color.White,
                Figure           = PointGeometryModel3D.PointFigure.Ellipse,
                Size             = defaultPointSize,
                IsHitTestVisible = true,
                IsSelected       = rp.IsSelected
            };

            return(pointGeometry3D);
        }
コード例 #15
0
        public void HelixRenderPackage_UpdatePointVertexColorForRange_ThrowsForBadRange()
        {
            var p = new HelixRenderPackage();

            PushPointIntoPackage(p);
            PushPointIntoPackage(p);

            //Try to update without any colors set
            try
            {
                p.UpdatePointVertexColorForRange(0, 1, 255, 255, 255, 255);
            }
            catch (Exception e)
            {
                Assert.AreEqual(e.GetType(), typeof(Exception));
            }

            Assert.AreEqual(0, p.PointVertexColorCount);

            var testColors = WhiteByteArrayOfLength(2);

            //Set colors
            p.AppendPointVertexColorRange(testColors);

            //Try to update colors with wrong range
            try
            {
                p.UpdatePointVertexColorForRange(0, 3, 255, 255, 255, 255);
            }
            catch (Exception e)
            {
                Assert.AreEqual(e.GetType(), typeof(Exception));
            }

            Assert.AreEqual(2, p.PointVertexColorCount);

            //Try to update colors with index error
            try
            {
                p.UpdatePointVertexColorForRange(1, 0, 255, 255, 255, 255);
            }
            catch (Exception e)
            {
                Assert.AreEqual(e.GetType(), typeof(Exception));
            }

            Assert.AreEqual(2, p.PointVertexColorCount);
        }
コード例 #16
0
        public void HelixRenderPackage_UpdateLineVertexColorForRange_Success()
        {
            var p = new HelixRenderPackage();

            PushLineIntoPackage(p);

            var testColors = WhiteByteArrayOfLength(2);

            //Set initial colors
            p.AppendLineVertexColorRange(testColors);

            //Update colors
            p.UpdateLineVertexColorForRange(1, 1, 255, 255, 255, 255);

            Assert.AreEqual(p.LineStripVertexColors, testColors);
        }
コード例 #17
0
        public void HelixRenderPackage_UpdateMeshVertexColorForRange_Success()
        {
            var p = new HelixRenderPackage();

            PushQuadIntoPackage(p);

            var testColors = WhiteByteArrayOfLength(6);

            //Set initial colors
            p.AppendMeshVertexColorRange(testColors);

            //Update colors
            p.UpdateMeshVertexColorForRange(0, 3, 255, 255, 255, 255);

            Assert.AreEqual(p.MeshVertexColors, testColors);
        }
コード例 #18
0
        public void HelixRenderPackage_AppendLineVertexColorRange_Success()
        {
            var p = new HelixRenderPackage();

            PushLineIntoPackage(p);

            var testColors = WhiteByteArrayOfLength(2);

            p.AppendLineVertexColorRange(testColors);

            Assert.AreEqual(p.LineStripVertexColors, testColors);

            PushLineIntoPackage(p);

            p.AppendLineVertexColorRange(testColors);

            var totalColors = WhiteByteArrayOfLength(4);

            Assert.AreEqual(p.LineStripVertexColors, totalColors);
        }
コード例 #19
0
        public void HelixRenderPackage_AppendPointVertexColorRange_Success()
        {
            var p = new HelixRenderPackage();

            PushPointIntoPackage(p);

            var testColors = WhiteByteArrayOfLength(1);

            p.AppendPointVertexColorRange(testColors);

            Assert.AreEqual(p.PointVertexColors, testColors);

            PushPointIntoPackage(p);

            p.AppendPointVertexColorRange(testColors);

            var totalColors = WhiteByteArrayOfLength(2);

            Assert.AreEqual(p.PointVertexColors, totalColors);
        }
コード例 #20
0
        private DynamoGeometryModel3D CreateDynamoGeometryModel3D(HelixRenderPackage rp)
        {
            var meshGeometry3D = new DynamoGeometryModel3D(renderTechnique)
            {
                Transform                   = Model1Transform,
                Material                    = WhiteMaterial,
                IsHitTestVisible            = false,
                RequiresPerVertexColoration = rp.RequiresPerVertexColoration,
                IsSelected                  = rp.IsSelected
            };

            if (rp.Colors != null)
            {
                var pf     = PixelFormats.Bgra32;
                var stride = (rp.ColorsStride / 4 * pf.BitsPerPixel + 7) / 8;
                try
                {
                    var diffMap = BitmapSource.Create(rp.ColorsStride / 4, rp.Colors.Count() / rp.ColorsStride, 96.0, 96.0, pf, null,
                                                      rp.Colors.ToArray(), stride);
                    var diffMat = new PhongMaterial
                    {
                        Name              = "White",
                        AmbientColor      = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0),
                        DiffuseColor      = defaultMaterialColor,
                        SpecularColor     = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0),
                        EmissiveColor     = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0),
                        SpecularShininess = 12.8f,
                        DiffuseMap        = diffMap
                    };
                    meshGeometry3D.Material = diffMat;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                }
            }

            return(meshGeometry3D);
        }
コード例 #21
0
        private void CreateOrUpdateText(string baseId, Vector3 pt, IRenderPackage rp)
        {
            var textId = baseId + TextKey;
            BillboardTextModel3D bbText;

            if (Model3DDictionary.ContainsKey(textId))
            {
                bbText = Model3DDictionary[textId] as BillboardTextModel3D;
            }
            else
            {
                bbText = new BillboardTextModel3D()
                {
                    Geometry = HelixRenderPackage.InitText3D(),
                };
                Model3DDictionary.Add(textId, bbText);
            }
            var geom = bbText.Geometry as BillboardText3D;

            geom.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description),
                                           new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
        }
コード例 #22
0
        public void HelixRenderPackage_ObsoleteCheck()
        {
            var p = new HelixRenderPackage();

            PushQuadIntoPackage(p);
            PushLineIntoPackage(p);
            PushPointIntoPackage(p);

            var testColors = WhiteByteArrayOfLength(6);

            try
            {
                p.AllowLegacyColorOperations = false;
                p.ApplyMeshVertexColors(testColors);
            }
            catch (Exception e)
            {
                Assert.AreEqual(e.GetType(), typeof(LegacyRenderPackageMethodException));
            }

            Assert.AreEqual(0, p.MeshVertexColorCount);
        }
コード例 #23
0
        public void HelixRenderPackage_Clear_IsClearedCompletely()
        {
            var p = new HelixRenderPackage();

            PushQuadIntoPackage(p);

            p.Clear();

            Assert.IsEmpty(p.Points.Positions);
            Assert.IsEmpty(p.Points.Indices);
            Assert.IsEmpty(p.Points.Colors);

            Assert.IsEmpty(p.Mesh.Positions);
            Assert.IsEmpty(p.Mesh.Normals);
            Assert.IsEmpty(p.Mesh.Indices);
            Assert.IsEmpty(p.Mesh.TextureCoordinates);
            Assert.IsEmpty(p.Mesh.Colors);

            Assert.IsEmpty(p.Lines.Positions);
            Assert.IsEmpty(p.Lines.Indices);
            Assert.IsEmpty(p.Lines.Colors);
        }
コード例 #24
0
ファイル: Watch3DView.xaml.cs プロジェクト: heldred/Dynamo
        private void AggregateRenderPackages(PackageAggregationParams parameters)
        {
            MeshCount = 0;
            foreach (var rp in parameters.Packages)
            {
                var p = rp.Points;
                if (p.Positions.Any())
                {
                    var points = parameters.Points;

                    var startIdx = points.Positions.Count;

                    points.Positions.AddRange(p.Positions);
                    points.Colors.AddRange(p.Colors.Any() ? p.Colors : Enumerable.Repeat(defaultPointColor, points.Positions.Count));
                    points.Indices.AddRange(p.Indices.Select(i => i + startIdx));

                    var endIdx = points.Positions.Count;

                    if (rp.IsSelected)
                    {
                        for (var i = startIdx; i < endIdx; i++)
                        {
                            points.Colors[i] = selectionColor;
                        }
                    }

                    if (rp.DisplayLabels)
                    {
                        var pt = p.Positions[0];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    }
                }

                var l = rp.Lines;
                if (l.Positions.Any())
                {
                    // Choose a collection to store the line data.
                    var lineSet = rp.IsSelected ? parameters.SelectedLines : parameters.Lines;

                    var startIdx = lineSet.Positions.Count;

                    lineSet.Positions.AddRange(l.Positions);
                    lineSet.Colors.AddRange(l.Colors.Any() ? l.Colors : Enumerable.Repeat(defaultLineColor, l.Positions.Count));
                    lineSet.Indices.AddRange(l.Indices.Select(i => i + startIdx));

                    var endIdx = lineSet.Positions.Count;

                    if (rp.IsSelected)
                    {
                        for (var i = startIdx; i < endIdx; i++)
                        {
                            lineSet.Colors[i] = selectionColor;
                        }
                    }

                    if (rp.DisplayLabels)
                    {
                        var pt = lineSet.Positions[startIdx];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    }
                }

                var m = rp.Mesh;
                if (m.Positions.Any())
                {
                    // Pick a mesh to use to store the data. Selected geometry
                    // goes into the selected mesh. Geometry with
                    // colors goes into the per vertex mesh. Everything else
                    // goes into the plain mesh.

                    var meshSet = rp.IsSelected ?
                                  parameters.SelectedMesh :
                                  rp.RequiresPerVertexColoration ? parameters.PerVertexMesh : parameters.Mesh;

                    var idxCount = meshSet.Positions.Count;

                    meshSet.Positions.AddRange(m.Positions);

                    meshSet.Colors.AddRange(m.Colors);
                    meshSet.Normals.AddRange(m.Normals);
                    meshSet.TextureCoordinates.AddRange(m.TextureCoordinates);
                    meshSet.Indices.AddRange(m.Indices.Select(i => i + idxCount));

                    if (rp.DisplayLabels)
                    {
                        var pt = meshSet.Positions[idxCount];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    }

                    MeshCount++;
                }
            }
        }
コード例 #25
0
        /// <summary>
        /// Use the render packages returned from the visualization manager to update the visuals.
        /// The visualization event arguments will contain a set of render packages and an id representing
        /// the associated node. Visualizations for the background preview will return an empty id.
        /// </summary>
        /// <param name="e"></param>
        public void RenderDrawables(VisualizationEventArgs e)
        {
            //check the id, if the id is meant for another watch,
            //then ignore it
            if (e.Id != _id)
            {
                Attach();
                NotifyPropertyChanged("");
                return;
            }

            // Don't render if the user's system is incapable.
            if (renderingTier == 0)
            {
                return;
            }

#if DEBUG
            renderTimer.Start();
#endif
            Text = null;

            var packages = e.Packages.Concat(e.SelectedPackages)
                           .Cast <HelixRenderPackage>().Where(rp => rp.MeshVertexCount % 3 == 0);

            var text = HelixRenderPackage.InitText3D();

            var aggParams = new PackageAggregationParams
            {
                Packages = packages,
                Text     = text
            };

            AggregateRenderPackages(aggParams);

#if DEBUG
            renderTimer.Stop();
            Debug.WriteLine(string.Format("RENDER: {0} ellapsed for compiling assets for rendering.", renderTimer.Elapsed));
            renderTimer.Reset();
            renderTimer.Start();
#endif

            //Helix render the packages in certain order. Here, the BillBoardText has to be rendered
            //after rendering all the geometry. Otherwise, the Text will not get rendered at the right
            //position. Also, BillBoardText gets attached only once. It is not removed from the tree everytime.
            //Instead, only the geometry gets updated every time. Once it is attached (after the geometry), helix
            // renders the text at the right position.
            if (Text != null && Text.TextInfo.Any())
            {
                BillboardTextModel3D billboardText3D = new BillboardTextModel3D
                {
                    Transform = Model1Transform
                };

                if (model3DDictionary != null && !model3DDictionary.ContainsKey("BillBoardText"))
                {
                    model3DDictionary.Add("BillBoardText", billboardText3D);
                }

                var billBoardModel3D = model3DDictionary["BillBoardText"] as BillboardTextModel3D;
                billBoardModel3D.Geometry = Text;
                if (!billBoardModel3D.IsAttached)
                {
                    billBoardModel3D.Attach(View.RenderHost);
                }
            }
            else
            {
                if (model3DDictionary != null && model3DDictionary.ContainsKey("BillBoardText"))
                {
                    var billBoardModel3D = model3DDictionary["BillBoardText"] as BillboardTextModel3D;
                    billBoardModel3D.Geometry = Text;
                }
            }

            //This is required for Dynamo to send property changed notifications to helix.
            NotifyPropertyChanged("");
        }
コード例 #26
0
        private void AggregateRenderPackages(PackageAggregationParams parameters)
        {
            //Clear the geometry values before adding the package.
            VisualizationManager_WorkspaceOpenedClosedHandled();

            foreach (var rp in parameters.Packages)
            {
                //Node ID gets updated with a ":" everytime this function is called.
                //For example, if the same point node is called multiple times (CBN), the ID has a ":"
                //and this makes the dictionary to have multiple entries for the same node.
                var baseId = rp.Description;
                if (baseId.IndexOf(":", StringComparison.Ordinal) > 0)
                {
                    baseId = baseId.Split(':')[0];
                }
                var id = baseId;

                var p = rp.Points;
                if (p.Positions.Any())
                {
                    id = baseId + ":points";

                    PointGeometryModel3D pointGeometry3D;

                    if (model3DDictionary.ContainsKey(id))
                    {
                        pointGeometry3D = model3DDictionary[id] as PointGeometryModel3D;
                    }
                    else
                    {
                        pointGeometry3D = new PointGeometryModel3D
                        {
                            Geometry         = HelixRenderPackage.InitPointGeometry(),
                            Transform        = Model1Transform,
                            Color            = SharpDX.Color.White,
                            Figure           = PointGeometryModel3D.PointFigure.Ellipse,
                            Size             = DefaultPointSize,
                            IsHitTestVisible = true,
                            IsSelected       = rp.IsSelected
                        };
                        model3DDictionary.Add(id, pointGeometry3D);
                    }

                    var points   = pointGeometry3D.Geometry as PointGeometry3D;
                    var startIdx = points.Positions.Count;

                    points.Positions.AddRange(p.Positions);
                    points.Colors.AddRange(p.Colors.Any() ? p.Colors : Enumerable.Repeat(defaultPointColor, points.Positions.Count));
                    points.Indices.AddRange(p.Indices.Select(i => i + startIdx));

                    if (rp.DisplayLabels)
                    {
                        var pt = p.Positions[0];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                        Text = parameters.Text;
                    }

                    pointGeometry3D.Geometry     = points;
                    pointGeometry3D.Name         = baseId;
                    pointGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D;
                }

                var l = rp.Lines;
                if (l.Positions.Any())
                {
                    id = baseId + ":lines";

                    LineGeometryModel3D lineGeometry3D;

                    if (model3DDictionary.ContainsKey(id))
                    {
                        lineGeometry3D = model3DDictionary[id] as LineGeometryModel3D;
                    }
                    else
                    {
                        lineGeometry3D = new LineGeometryModel3D()
                        {
                            Geometry         = HelixRenderPackage.InitLineGeometry(),
                            Transform        = Model1Transform,
                            Color            = SharpDX.Color.White,
                            Thickness        = 0.5,
                            IsHitTestVisible = true,
                            IsSelected       = rp.IsSelected
                        };

                        model3DDictionary.Add(id, lineGeometry3D);
                    }

                    var lineSet  = lineGeometry3D.Geometry as LineGeometry3D;
                    var startIdx = lineSet.Positions.Count;

                    lineSet.Positions.AddRange(l.Positions);
                    lineSet.Colors.AddRange(l.Colors.Any() ? l.Colors : Enumerable.Repeat(defaultLineColor, l.Positions.Count));
                    lineSet.Indices.AddRange(l.Indices.Any() ? l.Indices.Select(i => i + startIdx) : Enumerable.Range(startIdx, startIdx + l.Positions.Count));

                    if (rp.DisplayLabels)
                    {
                        var pt = lineSet.Positions[startIdx];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                        Text = parameters.Text;
                    }

                    lineGeometry3D.Geometry     = lineSet;
                    lineGeometry3D.Name         = baseId;
                    lineGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D;
                }

                var m = rp.Mesh;
                if (!m.Positions.Any())
                {
                    continue;
                }

                id = ((rp.RequiresPerVertexColoration || rp.Colors != null) ? rp.Description : baseId) + ":mesh";

                DynamoGeometryModel3D meshGeometry3D;

                if (model3DDictionary.ContainsKey(id))
                {
                    meshGeometry3D = model3DDictionary[id] as DynamoGeometryModel3D;
                }
                else
                {
                    meshGeometry3D = new DynamoGeometryModel3D()
                    {
                        Transform                   = Model1Transform,
                        Material                    = WhiteMaterial,
                        IsHitTestVisible            = true,
                        RequiresPerVertexColoration = rp.RequiresPerVertexColoration,
                        IsSelected                  = rp.IsSelected,
                    };

                    if (rp.Colors != null)
                    {
                        var pf     = PixelFormats.Bgra32;
                        var stride = (rp.ColorsStride / 4 * pf.BitsPerPixel + 7) / 8;
                        try
                        {
                            var diffMap = BitmapSource.Create(rp.ColorsStride / 4, rp.Colors.Count() / rp.ColorsStride, 96.0, 96.0, pf, null,
                                                              rp.Colors.ToArray(), stride);
                            var diffMat = new PhongMaterial
                            {
                                Name              = "White",
                                AmbientColor      = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0),
                                DiffuseColor      = materialColor,
                                SpecularColor     = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0),
                                EmissiveColor     = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0),
                                SpecularShininess = 12.8f,
                                DiffuseMap        = diffMap
                            };
                            meshGeometry3D.Material = diffMat;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    ((MaterialGeometryModel3D)meshGeometry3D).SelectionColor = selectionColor;
                    model3DDictionary.Add(id, meshGeometry3D);
                }

                var mesh = meshGeometry3D.Geometry == null?HelixRenderPackage.InitMeshGeometry() : meshGeometry3D.Geometry as MeshGeometry3D;

                var idxCount = mesh.Positions.Count;

                mesh.Positions.AddRange(m.Positions);

                mesh.Colors.AddRange(m.Colors);
                mesh.Normals.AddRange(m.Normals);
                mesh.TextureCoordinates.AddRange(m.TextureCoordinates);
                mesh.Indices.AddRange(m.Indices.Select(i => i + idxCount));

                if (mesh.Colors.Any(c => c.Alpha < 1.0))
                {
                    meshGeometry3D.HasTransparency = true;
                }

                if (rp.DisplayLabels)
                {
                    var pt = mesh.Positions[idxCount];
                    parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    Text = parameters.Text;
                }

                meshGeometry3D.Geometry     = mesh;
                meshGeometry3D.Name         = baseId;
                meshGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D;
            }

            Attach();
        }
コード例 #27
0
ファイル: Watch3DView.xaml.cs プロジェクト: heldred/Dynamo
        /// <summary>
        /// Use the render packages returned from the visualization manager to update the visuals.
        /// The visualization event arguments will contain a set of render packages and an id representing
        /// the associated node. Visualizations for the background preview will return an empty id.
        /// </summary>
        /// <param name="e"></param>
        public void RenderDrawables(VisualizationEventArgs e)
        {
            //check the id, if the id is meant for another watch,
            //then ignore it
            if (e.Id != _id)
            {
                return;
            }

#if DEBUG
            renderTimer.Start();
#endif
            Points        = null;
            Lines         = null;
            LinesSelected = null;
            Mesh          = null;
            PerVertexMesh = null;
            MeshSelected  = null;
            Text          = null;
            MeshCount     = 0;

            var packages = e.Packages.Concat(e.SelectedPackages)
                           .Cast <HelixRenderPackage>().Where(rp => rp.MeshVertexCount % 3 == 0);

            var points        = HelixRenderPackage.InitPointGeometry();
            var lines         = HelixRenderPackage.InitLineGeometry();
            var linesSel      = HelixRenderPackage.InitLineGeometry();
            var mesh          = HelixRenderPackage.InitMeshGeometry();
            var meshSel       = HelixRenderPackage.InitMeshGeometry();
            var perVertexMesh = HelixRenderPackage.InitMeshGeometry();
            var text          = HelixRenderPackage.InitText3D();

            var aggParams = new PackageAggregationParams
            {
                Packages      = packages,
                Points        = points,
                Lines         = lines,
                SelectedLines = linesSel,
                Mesh          = mesh,
                PerVertexMesh = perVertexMesh,
                SelectedMesh  = meshSel,
                Text          = text
            };

            AggregateRenderPackages(aggParams);

            if (!points.Positions.Any())
            {
                points = null;
            }

            if (!lines.Positions.Any())
            {
                lines = null;
            }

            if (!linesSel.Positions.Any())
            {
                linesSel = null;
            }

            if (!text.TextInfo.Any())
            {
                text = null;
            }

            if (!mesh.Positions.Any())
            {
                mesh = null;
            }

            if (!meshSel.Positions.Any())
            {
                meshSel = null;
            }

            if (!perVertexMesh.Positions.Any())
            {
                perVertexMesh = null;
            }

#if DEBUG
            renderTimer.Stop();
            Debug.WriteLine(string.Format("RENDER: {0} ellapsed for compiling assets for rendering.", renderTimer.Elapsed));
            renderTimer.Reset();
            renderTimer.Start();
#endif

            var updateGraphicsParams = new GraphicsUpdateParams
            {
                Points        = points,
                Lines         = lines,
                SelectedLines = linesSel,
                Mesh          = mesh,
                SelectedMesh  = meshSel,
                PerVertexMesh = perVertexMesh,
                Text          = text
            };

            SendGraphicsToView(updateGraphicsParams);

            //DrawTestMesh();
        }
コード例 #28
0
        public void HelixRenderPackage_Construction_IsInitializedCorrectly()
        {
            var p = new HelixRenderPackage();

            Assert.NotNull(p);
        }
コード例 #29
0
        private void AggregateRenderPackages(IEnumerable <HelixRenderPackage> packages)
        {
            lock (Model3DDictionaryMutex)
            {
                foreach (var rp in packages)
                {
                    // Each node can produce multiple render packages. We want all the geometry of the
                    // same kind stored inside a RenderPackage to be pushed into one GeometryModel3D object.
                    // We strip the unique identifier for the package (i.e. the bit after the `:` in var12345:0), and replace it
                    // with `points`, `lines`, or `mesh`. For each RenderPackage, we check whether the geometry dictionary
                    // has entries for the points, lines, or mesh already. If so, we add the RenderPackage's geometry
                    // to those geometry objects.

                    var baseId = rp.Description;
                    if (baseId.IndexOf(":", StringComparison.Ordinal) > 0)
                    {
                        baseId = baseId.Split(':')[0];
                    }
                    var id = baseId;

                    var p = rp.Points;
                    if (p.Positions.Any())
                    {
                        id = baseId + PointsKey;

                        PointGeometryModel3D pointGeometry3D;

                        if (Model3DDictionary.ContainsKey(id))
                        {
                            pointGeometry3D = Model3DDictionary[id] as PointGeometryModel3D;
                        }
                        else
                        {
                            pointGeometry3D = CreatePointGeometryModel3D(rp);
                            Model3DDictionary.Add(id, pointGeometry3D);
                        }

                        var points   = pointGeometry3D.Geometry as PointGeometry3D;
                        var startIdx = points.Positions.Count;

                        points.Positions.AddRange(p.Positions);
                        points.Colors.AddRange(p.Colors.Any()
                            ? p.Colors
                            : Enumerable.Repeat(defaultPointColor, points.Positions.Count));
                        points.Indices.AddRange(p.Indices.Select(i => i + startIdx));

                        if (rp.DisplayLabels)
                        {
                            CreateOrUpdateText(baseId, p.Positions[0], rp);
                        }

                        pointGeometry3D.Geometry = points;
                        pointGeometry3D.Name     = baseId;
                    }

                    var l = rp.Lines;
                    if (l.Positions.Any())
                    {
                        id = baseId + LinesKey;

                        LineGeometryModel3D lineGeometry3D;

                        if (Model3DDictionary.ContainsKey(id))
                        {
                            lineGeometry3D = Model3DDictionary[id] as LineGeometryModel3D;
                        }
                        else
                        {
                            // If the package contains mesh vertices, then the lines represent the
                            // edges of meshes. Draw them with a different thickness.
                            lineGeometry3D = CreateLineGeometryModel3D(rp, rp.MeshVertices.Any()?0.5:1.0);
                            Model3DDictionary.Add(id, lineGeometry3D);
                        }

                        var lineSet  = lineGeometry3D.Geometry as LineGeometry3D;
                        var startIdx = lineSet.Positions.Count;

                        lineSet.Positions.AddRange(l.Positions);
                        lineSet.Colors.AddRange(l.Colors.Any()
                            ? l.Colors
                            : Enumerable.Repeat(defaultLineColor, l.Positions.Count));
                        lineSet.Indices.AddRange(l.Indices.Any()
                            ? l.Indices.Select(i => i + startIdx)
                            : Enumerable.Range(startIdx, startIdx + l.Positions.Count));

                        if (rp.DisplayLabels)
                        {
                            var pt = lineSet.Positions[startIdx];
                            CreateOrUpdateText(baseId, pt, rp);
                        }

                        lineGeometry3D.Geometry = lineSet;
                        lineGeometry3D.Name     = baseId;
                    }

                    var m = rp.Mesh;
                    if (!m.Positions.Any())
                    {
                        continue;
                    }

                    id = ((rp.RequiresPerVertexColoration || rp.Colors != null) ? rp.Description : baseId) + MeshKey;

                    DynamoGeometryModel3D meshGeometry3D;

                    if (Model3DDictionary.ContainsKey(id))
                    {
                        meshGeometry3D = Model3DDictionary[id] as DynamoGeometryModel3D;
                    }
                    else
                    {
                        meshGeometry3D = CreateDynamoGeometryModel3D(rp);
                        Model3DDictionary.Add(id, meshGeometry3D);
                    }

                    var mesh = meshGeometry3D.Geometry == null
                        ? HelixRenderPackage.InitMeshGeometry()
                        : meshGeometry3D.Geometry as MeshGeometry3D;

                    var idxCount = mesh.Positions.Count;

                    mesh.Positions.AddRange(m.Positions);
                    mesh.Colors.AddRange(m.Colors);
                    mesh.Normals.AddRange(m.Normals);
                    mesh.TextureCoordinates.AddRange(m.TextureCoordinates);
                    mesh.Indices.AddRange(m.Indices.Select(i => i + idxCount));

                    if (mesh.Colors.Any(c => c.Alpha < 1.0))
                    {
                        meshGeometry3D.SetValue(AttachedProperties.HasTransparencyProperty, true);
                    }

                    if (rp.DisplayLabels)
                    {
                        var pt = mesh.Positions[idxCount];
                        CreateOrUpdateText(baseId, pt, rp);
                    }

                    meshGeometry3D.Geometry = mesh;
                    meshGeometry3D.Name     = baseId;
                }

                AttachAllGeometryModel3DToRenderHost();
            }
        }