Ejemplo n.º 1
0
 public HelixRenderPackageFactory()
 {
     TessellationParameters = new TessellationParameters()
     {
         MaxTessellationDivisions = MaxTessellationDivisionsDefault
     };
 }
 public DefaultRenderPackageFactory()
 {
     TessellationParameters = new TessellationParameters()
     {
         MaxTessellationDivisions = 32
     };
 }
Ejemplo n.º 3
0
        public void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            // Dynamo's renderer uses IRenderPackage objects
            // to store data for rendering. The Tessellate method
            // give you an IRenderPackage object which you can fill
            // with render data.

            // Set RequiresPerVertexColoration to let the renderer
            // know that you needs to use a per-vertex color shader.
            package.RequiresPerVertexColoration = true;

            AddColoredQuadToPackage(package);
            AddColoredLineToPackage(package);
        }
Ejemplo n.º 4
0
        public void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            package.RequiresPerVertexColoration = true;

            // As you add more data to the render package, you need
            // to keep track of the index where this coloration will 
            // start from.

            geometry.Tessellate(package, parameters);

            if (parameters.ShowEdges)
            {
                var surf = geometry as Surface;
                if (surf != null)
                {
                    foreach (var curve in surf.PerimeterCurves())
                    {
                        curve.Tessellate(package, parameters);
                        curve.Dispose();
                    }
                }

                var solid = geometry as Solid;
                if (solid != null)
                {
                    foreach (var geom in solid.Edges.Select(edge => edge.CurveGeometry))
                    {
                        geom.Tessellate(package, parameters);
                        geom.Dispose();
                    }
                }
            }

            if (package.LineVertexCount > 0)
            {
                package.ApplyLineVertexColors(CreateColorByteArrayOfSize(package.LineVertexCount, color.Red, color.Green, color.Blue, color.Alpha));
            }

            if (package.PointVertexCount > 0)
            {
                package.ApplyPointVertexColors(CreateColorByteArrayOfSize(package.PointVertexCount, color.Red, color.Green, color.Blue, color.Alpha));
            }

            if (package.MeshVertexCount > 0)
            {
                package.ApplyMeshVertexColors(CreateColorByteArrayOfSize(package.MeshVertexCount, color.Red, color.Green, color.Blue, color.Alpha));
            }
        }
        public void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            for (var i = 0; i < width - 1; i++)
            {
                for (var j = 0; j < length - 1; j++)
                {
                    var a = vertexCoords[i , j];
                    var b = vertexCoords[i , j + 1];
                    var c = vertexCoords[i + 1, j];
                    var d = vertexCoords[i + 1, j + 1];

                    var v1 = Vector.ByTwoPoints(b, a).Cross(Vector.ByTwoPoints(c, b)).Normalized().Reverse();
                    var v2 = Vector.ByTwoPoints(c, d).Cross(Vector.ByTwoPoints(b, d)).Normalized().Reverse();

                    PushTriangleVertex(package, a, v1);
                    PushTriangleVertex(package, b, v1);
                    PushTriangleVertex(package, c, v1);

                    PushTriangleVertex(package, d, v2);
                    PushTriangleVertex(package, c, v2);
                    PushTriangleVertex(package, b, v2);
                }
            }
        }
Ejemplo n.º 6
0
        private static void CreateVertexColoredMesh(Point[] vertices, Color[] colors, IRenderPackage package, TessellationParameters parameters)
        {
            package.RequiresPerVertexColoration = true;

            for (var i = 0; i <= vertices.Count()-3; i+=3)
            {
                var ptA = vertices[i];
                var ptB = vertices[i+1];
                var ptC = vertices[i+2];

                if (ptA.IsAlmostEqualTo(ptB) ||
                    ptB.IsAlmostEqualTo(ptC) ||
                    ptA.IsAlmostEqualTo(ptC))
                {
                    continue;
                }

                var alongLine = false;
                using (var l = Line.ByStartPointEndPoint(ptA, ptC))
                {
                    alongLine = ptB.DistanceTo(l) < 0.00001;
                }
                if (alongLine)
                {
                    continue;
                }

                var cA = colors[i];
                var cB = colors[i+1];
                var cC = colors[i+2];

                var s1 = ptB.AsVector().Subtract(ptA.AsVector()).Normalized();
                var s2 = ptC.AsVector().Subtract(ptA.AsVector()).Normalized();
                var n = s1.Cross(s2);

                package.AddTriangleVertex(ptA.X, ptA.Y, ptA.Z);
                package.AddTriangleVertexNormal(n.X, n.Y, n.Z);
                package.AddTriangleVertexColor(cA.Red, cA.Green, cA.Blue, cA.Alpha);
                package.AddTriangleVertexUV(0, 0);

                package.AddTriangleVertex(ptB.X, ptB.Y, ptB.Z);
                package.AddTriangleVertexNormal(n.X, n.Y, n.Z);
                package.AddTriangleVertexColor(cB.Red, cB.Green, cB.Blue, cB.Alpha);
                package.AddTriangleVertexUV(0, 0);

                package.AddTriangleVertex(ptC.X, ptC.Y, ptC.Z);
                package.AddTriangleVertexNormal(n.X, n.Y, n.Z);
                package.AddTriangleVertexColor(cC.Red, cC.Green, cC.Blue, cC.Alpha);
                package.AddTriangleVertexUV(0, 0);
            }
        }
Ejemplo n.º 7
0
        private void TessellateEdges(IRenderPackage package, TessellationParameters parameters)
        {
            if (!parameters.ShowEdges) return;

            var surf = geometry as Surface;
            if (surf != null)
            {
                foreach (var curve in surf.PerimeterCurves())
                {
                    curve.Tessellate(package, parameters);
                    curve.Dispose();
                }
            }

            var solid = geometry as Solid;
            if (solid != null)
            {
                foreach (var geom in solid.Edges.Select(edge => edge.CurveGeometry))
                {
                    geom.Tessellate(package, parameters);
                    geom.Dispose();
                }
            }
        }
Ejemplo n.º 8
0
        private void CreateGeometryRenderData(Color color, IRenderPackage package, TessellationParameters parameters)
        {
            package.RequiresPerVertexColoration = true;

            // As you add more data to the render package, you need
            // to keep track of the index where this coloration will 
            // start from.

            geometry.Tessellate(package, parameters);

            TessellateEdges(package, parameters);

            if (package.LineVertexCount > 0)
            {
                package.ApplyLineVertexColors(CreateColorByteArrayOfSize(package.LineVertexCount, color.Red, color.Green,
                    color.Blue, color.Alpha));
            }

            if (package.PointVertexCount > 0)
            {
                package.ApplyPointVertexColors(CreateColorByteArrayOfSize(package.PointVertexCount, color.Red, color.Green,
                    color.Blue, color.Alpha));
            }

            if (package.MeshVertexCount > 0)
            {
                package.ApplyMeshVertexColors(CreateColorByteArrayOfSize(package.MeshVertexCount, color.Red, color.Green,
                    color.Blue, color.Alpha));
            }
        }
Ejemplo n.º 9
0
        private void CreateColorMapOnSurface(Color[][] colorMap , IRenderPackage package, TessellationParameters parameters)
        {
            const byte gray = 80;
 
            geometry.Tessellate(package, parameters);

            var colorBytes = new List<byte>();

            foreach (var colorArr in colorMap)
            {
                foreach (var c in colorArr)
                {
                    colorBytes.Add(c.Blue);
                    colorBytes.Add(c.Green);
                    colorBytes.Add(c.Red);
                    colorBytes.Add(c.Alpha);
                }
            }

            package.SetColors(colorBytes.ToArray());
            package.ColorsStride = colorMap.First().Length * 4;

            TessellateEdges(package, parameters);

            if (package.LineVertexCount > 0)
            {
                package.ApplyLineVertexColors(CreateColorByteArrayOfSize(package.LineVertexCount, gray, gray,
                    gray, 255));
            }
        }
Ejemplo n.º 10
0
        public void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            if(vertices != null)
            {
                CreateVertexColoredMesh(vertices, meshVertexColors, package, parameters);
                return;
            }

            if (singleColor != null)
            {
                CreateGeometryRenderData(singleColor, package, parameters);
                return;
            }

            if (colorMap != null)
            {
                if (!colorMap.Any())
                {
                    return;
                }

                CreateColorMapOnSurface(colorMap, package, parameters);
                return;
            }
        }
Ejemplo n.º 11
0
 public void Tessellate(IRenderPackage package, TessellationParameters parameters)
 {
     // This example contains information to draw a point
     package.AddPointVertex(point.X, point.Y, point.Z);
     package.AddPointVertexColor(255, 0, 0, 255);
 }
Ejemplo n.º 12
0
 public void Tessellate(IRenderPackage package, TessellationParameters parameters)
 {
     AsVector().Tessellate(package, parameters);
 }
Ejemplo n.º 13
0
        public void Tessellate(List<object> objects, IRenderPackage package, TessellationParameters parameters)
        {
            foreach (var item in objects)
            {
                List<IGraphicItem> graphicItems = GetGraphicItems(item);
                if (null == graphicItems || graphicItems.Count == 0)
                    continue;

                foreach (var g in graphicItems)
                {
                    g.Tessellate(package, parameters);
                }
            }
        }
Ejemplo n.º 14
0
        public void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            if (singleColor != null)
            {
                CreateGeometryRenderData(singleColor, package, parameters);
            }
            else if (colorMap != null)
            {
                if (!colorMap.Any())
                {
                    return;
                }

                CreateColorMapOnSurface(colorMap, package, parameters);
            }
        }
Ejemplo n.º 15
0
 public void Tessellate(IRenderPackage package, TessellationParameters parameters)
 {
     package.AddPointVertex(point.X, point.Y, point.Z);
     package.Description = label;
 }
Ejemplo n.º 16
0
        public new void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            //Ensure that the object is still alive
            if (!IsAlive) return;

            //Location Point
            DB.LocationPoint locPoint = InternalElement.Location as DB.LocationPoint;
            GeometryPrimitiveConverter.ToPoint(InternalTransform.OfPoint(locPoint.Point)).Tessellate(package, parameters);
            package.ApplyPointVertexColors(CreateColorByteArrayOfSize(package.PointVertexCount, 255, 0, 0, 0));

            //Boundaries
            foreach (DB.BoundarySegment segment in InternalBoundarySegments)
            {
                Curve crv = RevitToProtoCurve.ToProtoType(segment.GetCurve().CreateTransformed(InternalTransform));

                crv.Tessellate(package, parameters);

                if (package.LineVertexCount > 0)
                {
                    package.ApplyLineVertexColors(CreateColorByteArrayOfSize(package.LineVertexCount, 255, 0, 0, 0));
                }
            }
        }
Ejemplo n.º 17
0
 public void Tessellate(List<object> objects, IRenderPackage package, TessellationParameters parameters)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 18
0
        public void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            //could increase performance further by cacheing this tesselation
            Geometry.Tessellate(package, parameters);

            //we use reflection here because this API was added in Dynamo 1.1 and might not exist for a user in Dynamo 1.0
            //if you do not care about ensuring comptability of your zero touch node with 1.0 you can just call SetTransform directly
            //by casting the rendering package to ITransformable.

            //look for the method SetTransform with the double[] argument list.
            var method = package.GetType().
            GetMethod("SetTransform", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance,
                    null,
                    new[] { typeof(double[]) }, null);

            //if the method exists call it using our current transform.
            if (method != null)
            {
                method.Invoke(package, new object[] { new double[]
            {transform.XAxis.X,transform.XAxis.Y,transform.XAxis.Z,0,
            transform.YAxis.X,transform.YAxis.Y,transform.YAxis.Z,0,
            transform.ZAxis.X,transform.ZAxis.Y,transform.ZAxis.Z,0,
            transform.Origin.X,transform.Origin.Y,transform.Origin.Z,1
            }});
            }
        }