Пример #1
0
        public void BoxByCenterAndDimensions_ValidArgs()
        {
            var center = Point.ByCoordinates(-2, -1, 5);

            var box = Solid.BoxByCenterAndDimensions(center, 2, 5, 10);
            Assert.IsNotNull(box);

            var package = new RenderPackage();
            box.Tessellate(package);

            var modelPath = Path.Combine(TestGeometryDirectory, @"BoxByCenterAndDimensions_ValidArgs.obj");
            if (File.Exists(modelPath))
                File.Delete(modelPath);
            WriteToOBJ(modelPath, new List<RenderPackage>() { package });
        }
Пример #2
0
        public void BoxByMinimumMaximum_ValidArgs()
        {
            var min = Point.ByCoordinates(-2, -1, 5);
            var max = Point.ByCoordinates(3, 5, 10);

            var box = Solid.BoxByTwoCorners(min, max);
            Assert.IsNotNull(box);

            var package = new RenderPackage();
            box.Tessellate(package);

            var modelPath = Path.Combine(TestGeometryDirectory, @"BoxByMinimumMaximum_ValidArgs.obj");
            if (File.Exists(modelPath))
                File.Delete(modelPath);
            WriteToOBJ(modelPath, new List<RenderPackage>() { package });
        }
Пример #3
0
        private void Tesselate(Autodesk.DesignScript.Geometry.Curve curve, ref List<GeometryObject> geoms)
        {
            // use the ASM tesselation of the curve
            var pkg = new RenderPackage();
            curve.Tessellate(pkg, 0.1);

            // get necessary info to enumerate and convert the lines
            var lineCount = pkg.LineStripVertices.Count - 3;
            var verts = pkg.LineStripVertices;

            // we scale the tesselation rather than the curve
            var conv = UnitConverter.DynamoToHostFactor;

            // add the revit Lines to geometry collection
            for (var i = 0; i < lineCount; i += 3)
            {
                var xyz0 = new XYZ(verts[i] * conv, verts[i + 1] * conv, verts[i + 2] * conv);
                var xyz1 = new XYZ(verts[i + 3] * conv, verts[i + 4] * conv, verts[i + 5] * conv);

                geoms.Add(Autodesk.Revit.DB.Line.CreateBound(xyz0, xyz1));
            }
        }
        protected override void ExecuteCore()
        {
            if (nodeGuid == Guid.Empty)
            {
                throw new InvalidOperationException(
                    "UpdateRenderPackageAsyncTask.Initialize not called");
            }

            var data = from varName in drawableIds
                       select engineController.GetMirror(varName)
                       into mirror
                       where mirror != null
                       select mirror.GetData();

            var labelMap = new List<string>();
            foreach (var mirrorData in data)
            {
                AddToLabelMap(mirrorData, labelMap, previewIdentifierName);
            }

            int count = 0;
            foreach (var drawableId in drawableIds)
            {
                var graphItems = engineController.GetGraphicItems(drawableId);
                if (graphItems == null)
                    continue;

                foreach (var graphicItem in graphItems)
                {
                    var package = new RenderPackage(isNodeSelected, displayLabels)
                    {
                        Tag = labelMap.Count > count ? labelMap[count] : "?",
                    };

                    try
                    {
                        graphicItem.Tessellate(package, tol: -1.0,
                            maxGridLines: maxTesselationDivisions);
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(
                            "PushGraphicItemIntoPackage: " + e);
                    }

                    package.ItemsCount++;
                    renderPackages.Add(package);
                    count++;
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Updates the render package for this node by
        /// getting the MirrorData objects corresponding to
        /// each of the node's ports and processing the underlying
        /// CLR data as IGraphicItems.
        /// </summary>
        public virtual void UpdateRenderPackage()
        {
            //Avoid attempting an update after the controller
            //has shut down.
            if (dynSettings.Controller == null)
                return;

            //dispose of the current render package
            lock (RenderPackagesMutex)
            {
                RenderPackages.Clear();

                if (State == ElementState.Error || !IsVisible)
                {
                    return;
                }

                List<string> drawableIds = GetDrawableIds().ToList();

                int count = 0;
                var labelMap = new List<string>();
                var sizeMap = new List<double>();

                var ident = AstIdentifierForPreview.Name;

                var data = from varName in drawableIds
                           select dynSettings.Controller.EngineController.GetMirror(varName)
                           into mirror
                           where mirror != null
                           select mirror.GetData();

                foreach (var mirrorData in data)
                {
                    AddToLabelMap(mirrorData, labelMap, ident);
                    count++;
                }

                count = 0;
                foreach (var varName in drawableIds)
                {
                    var graphItems = dynSettings.Controller.EngineController.GetGraphicItems(varName);
                    if (graphItems == null)
                        continue;

                    foreach (var gItem in graphItems)
                    {
                        var package = new RenderPackage(IsSelected, DisplayLabels);

                        PushGraphicItemIntoPackage(gItem,
                            package,
                            labelMap.Count > count ? labelMap[count] : "?",
                            sizeMap.Count > count ? sizeMap[count] : -1.0);

                        package.ItemsCount++;
                        RenderPackages.Add(package);
                        count++;
                    }
                }
            }
        }
Пример #6
0
        private void ConvertMeshes(RenderPackage p,
            ICollection<Point3D> points, ICollection<Vector3D> norms,
            ICollection<int> tris)
        {
            for (int i = 0; i < p.TriangleVertices.Count; i+=3)
            {
                var new_point = new Point3D(p.TriangleVertices[i],
                                            p.TriangleVertices[i + 1],
                                            p.TriangleVertices[i + 2]);

                var normal = new Vector3D(p.TriangleNormals[i],
                                            p.TriangleNormals[i + 1],
                                            p.TriangleNormals[i + 2]);

                //find a matching point
                //compare the angle between the normals
                //to discern a 'break' angle for adjacent faces
                //int foundIndex = -1;
                //for (int j = 0; j < points.Count; j++)
                //{
                //    var testPt = points[j];
                //    var testNorm = norms[j];
                //    var ang = Vector3D.AngleBetween(normal, testNorm);

                //    if (new_point.X == testPt.X &&
                //        new_point.Y == testPt.Y &&
                //        new_point.Z == testPt.Z &&
                //        ang > 90.0000)
                //    {
                //        foundIndex = j;
                //        break;
                //    }
                //}

                //if (foundIndex != -1)
                //{
                //    tris.Add(foundIndex);
                //    continue;
                //}
                    
                tris.Add(points.Count);
                points.Add(new_point);
                norms.Add(normal);
            }

            if (tris.Count > 0)
            {
                MeshCount++;
            }
        }
Пример #7
0
 private static RenderPackage PackageRenderData(IGraphicItem gItem)
 {
     var renderPackage = new RenderPackage();
     gItem.Tessellate(renderPackage, -1.0, dynSettings.Controller.VisualizationManager.MaxTesselationDivisions);
     renderPackage.ItemsCount++;
     return renderPackage;
 }
Пример #8
0
        public void ByRevolve_ValidArgs_NonVertical()
        {
            //create a unit rectangle in the world XY plane
            var crvs = UnitRectangle();

            var origin = Point.ByCoordinates(0, 0, 0);

            var z = Vector.ByCoordinates(.5, .5, .5).Normalized();
            var zTmp = Vector.ByCoordinates(0, 0, 1);
            var x = z.Cross(zTmp).Normalized();
            var y = z.Cross(x).Normalized();

            var cs = CoordinateSystem.ByOriginVectors(origin, x, y, z);

            var planeCs = CoordinateSystem.ByOriginVectors(origin, x, z, y);
            var transCrvs = crvs.Select(crv => crv.Transform(CoordinateSystem.Identity(), planeCs)).Cast<Curve>().ToList();

            var revolve = Solid.ByRevolve(PolyCurve.ByJoinedCurves(transCrvs.ToArray()), cs, 0, 3.14);
            Assert.NotNull(revolve);

            var package = new RenderPackage();
            revolve.Tessellate(package);

            var modelPath = Path.Combine(TestGeometryDirectory, @"ByRevolve_ValidArgs_NonVertical.obj");
            if (File.Exists(modelPath))
                File.Delete(modelPath);
            WriteToOBJ(modelPath, new List<RenderPackage>() { package });
        }
Пример #9
0
        private void ConvertLines(RenderPackage p,
            ICollection<Point3D> lineColl,
            ICollection<Point3D> redLines,
            ICollection<Point3D> greenLines,
            ICollection<Point3D> blueLines,
            ICollection<BillboardTextItem> text)
        {
            int idx = 0;
            int color_idx = 0;

            int outerCount = 0;
            foreach (var count in p.LineStripVertexCounts)
            {
                for (int i = 0; i < count; ++i)
                {
                    var point = new Point3D(p.LineStripVertices[idx], p.LineStripVertices[idx + 1],
                        p.LineStripVertices[idx + 2]);

                    if (i == 0 && outerCount == 0 && p.DisplayLabels)
                    {
                        text.Add(new BillboardTextItem { Text = CleanTag(p.Tag), Position = point });
                    }

                    if (i != 0 && i != count - 1)
                    {
                        lineColl.Add(point);
                    }
                    
                    bool isAxis = false;
                    var startColor = Color.FromRgb(
                                            p.LineStripVertexColors[color_idx],
                                            p.LineStripVertexColors[color_idx + 1],
                                            p.LineStripVertexColors[color_idx + 2]);

                    if (startColor == Color.FromRgb(255, 0, 0))
                    {
                        redLines.Add(point);
                        isAxis = true;
                    }
                    else if (startColor == Color.FromRgb(0, 255, 0))
                    {
                        greenLines.Add(point);
                        isAxis = true;
                    }
                    else if (startColor == Color.FromRgb(0, 0, 255))
                    {
                        blueLines.Add(point);
                        isAxis = true;
                    }

                    if (!isAxis)
                    {
                        lineColl.Add(point);
                    } 

                    idx += 3;
                    color_idx += 4;
                }
                outerCount++;
            }
        }
Пример #10
0
        public void Sphere_ValidArgs()
        {
            var sphere = Solid.Sphere(Point.ByCoordinates(0, 5, 3), 10);
            Assert.IsNotNull(sphere);

            var package = new RenderPackage();
            sphere.Tessellate(package);

            var modelPath = Path.Combine(TestGeometryDirectory, @"Sphere_ValidArgs.obj");
            if (File.Exists(modelPath))
                File.Delete(modelPath);
            WriteToOBJ(modelPath, new List<RenderPackage>() { package });
        }
Пример #11
0
        public void Torus_ValidArgs()
        {
            var axis = Vector.ByCoordinates(.5, .5, .5);
            var center = Point.ByCoordinates(2, 3, 5);

            var torus = Solid.Torus(axis, center, 3, 1);
            Assert.IsNotNull(torus);

            var package = new RenderPackage();
            torus.Tessellate(package);

            var modelPath = Path.Combine(TestGeometryDirectory, @"Torus_ValidArgs.obj");
            if (File.Exists(modelPath))
                File.Delete(modelPath);
            WriteToOBJ(modelPath, new List<RenderPackage>() { package });
        }
Пример #12
0
        public void FromElement_ValidArgs()
        {
            var solidA = Solid.BoxByCenterAndDimensions(Point.ByCoordinates(0, 0, 0), 1, 1, 1);
            var solidB = Solid.Sphere(Point.ByCoordinates(1, 1, 0), 1);
            var difference = Solid.ByBooleanDifference(solidA, solidB);

            var ff = FreeForm.BySolid(difference);

            var extract = Solid.FromElement(ff);
            Assert.IsNotNull(extract);

            var package = new RenderPackage();
            extract.Tessellate(package);

            ExportModel("FromElement_ValidArgs.obj", package);
        }
Пример #13
0
        public void Cylinder_ValidArgs()
        {
            var cylinder = Solid.Cylinder(Point.ByCoordinates(0, 0, 0), 5, Vector.ByCoordinates(0,0,1), 10);
            Assert.IsNotNull(cylinder);

            var package = new RenderPackage();
            cylinder.Tessellate(package);

            var modelPath = Path.Combine(TestGeometryDirectory, @"Cylinder_ValidArgs.obj");
            if (File.Exists(modelPath))
                File.Delete(modelPath);
            WriteToOBJ(modelPath, new List<RenderPackage>() { package });
        }
Пример #14
0
        public void BySweptBlend_ValidArgs()
        {
            var package = new RenderPackage();

            var rect1 = UnitRectangle();

            //make the path curve
            var p1 = Point.ByCoordinates(0, 0, 0);
            var p5 = Point.ByCoordinates(0, 0, 4);

            var spine = Line.ByStartPointEndPoint(p1, p5);
            var spineRev = spine.ToRevitType();

            DrawCurve(spine.ToRevitType(), package);

            var cs1 = rect1.Select(crv => crv.Translate(0,0,0)).Cast<Curve>().ToList();
            var cs2 = rect1.Select(crv => crv.Translate(0,0,1)).Cast<Curve>().ToList();
            var cs3 = rect1.Select(crv => crv.Translate(0,0,3)).Cast<Curve>().ToList();
            var cs4 = rect1.Select(crv => crv.Translate(0, 0, 4)).Cast<Curve>().ToList();

            cs1.ForEach(x => DrawCurve(x.ToRevitType(), package));
            cs2.ForEach(x => DrawCurve(x.ToRevitType(), package));
            cs3.ForEach(x => DrawCurve(x.ToRevitType(), package));
            cs4.ForEach(x => DrawCurve(x.ToRevitType(), package));

            cs1[0].StartPoint.ShouldBeApproximately(0, 0, 0);
            cs2[0].StartPoint.ShouldBeApproximately(0, 0, 1);
            cs3[0].StartPoint.ShouldBeApproximately(0, 0, 3);
            cs4[0].StartPoint.ShouldBeApproximately(0, 0, 4);

            spine.EndPoint.ShouldBeApproximately(Point.ByCoordinates(0, 0, 4));
            spine.StartPoint.ShouldBeApproximately(Point.ByCoordinates(0, 0, 0));

            var modelPath = Path.Combine(TestGeometryDirectory, @"BySweptBlend_ValidArgs_Setup.obj");
            if (File.Exists(modelPath))
                File.Delete(modelPath);
            WriteToOBJ(modelPath, new List<RenderPackage>() { package });

            var crvList = new[] {cs1, cs2, cs3, cs4};

            var blend = Solid.BySweptBlend( crvList.Select(x => PolyCurve.ByJoinedCurves(x.ToArray()) ).ToList(), spine, new List<double> {0, 0.25, 0.75, 1});
            Assert.NotNull(blend);

            blend.Tessellate(package);

            modelPath = Path.Combine(TestGeometryDirectory, @"BySweptBlend_ValidArgs.obj");
            if (File.Exists(modelPath))
                File.Delete(modelPath);
            WriteToOBJ(modelPath, new List<RenderPackage>() { package });
        }
Пример #15
0
        /// <summary>
        /// Updates the render package for this node by
        /// getting the MirrorData objects corresponding to
        /// each of the node's ports and processing the underlying
        /// CLR data as IGraphicItems.
        /// </summary>
        public virtual void UpdateRenderPackage()
        {
            if (dynSettings.Controller == null)
            {
                return;
            }

            ClearRenderPackages();
            if (State == ElementState.Error ||
                !IsVisible ||
                CachedValue == null)
            {
                return;
            }

            List<string> drawableIds = GetDrawableIds().ToList();

            int count = 0;
            var labelMap = new List<string>();
            var sizeMap = new List<double>();

            var ident = AstIdentifierForPreview.Name;

            var data = from varName in drawableIds
                        select dynSettings.Controller.EngineController.GetMirror(varName)
                        into mirror
                        where mirror != null
                        select mirror.GetData();

            foreach (var mirrorData in data) 
            {
                AddToLabelMap(mirrorData, labelMap, ident);
                count++;
            }

            count = 0;
            List<IRenderPackage> newRenderPackages = new List<IRenderPackage>();
            foreach (var varName in drawableIds)
            {
                var graphItems = dynSettings.Controller.EngineController.GetGraphicItems(varName);
                if (graphItems == null)
                    continue;

                foreach (var gItem in graphItems)
                {
                    var package = new RenderPackage(IsSelected, DisplayLabels);
                        
                    PushGraphicItemIntoPackage(gItem, 
                        package, 
                        labelMap.Count > count ? labelMap[count] : "?",
                        sizeMap.Count > count ? sizeMap[count] : -1.0);

                    package.ItemsCount++;
                    newRenderPackages.Add(package);
                    count++;
                }
            }

            RenderPackages = newRenderPackages;
            if (RenderPackages.Any())
            {
                HasRenderPackages = true;
            }
            else
            {
                HasRenderPackages = false;
            }
        }
Пример #16
0
        public void ByBlend_ValidArgs()
        {
            var rect1 = UnitRectangle();
            var rect2 = UnitRectangle();

            var originBottom = Point.ByCoordinates(0, 0, 0);
            var x = Vector.ByCoordinates(1, 0, 0);
            var y = Vector.ByCoordinates(0, 1, 0);
            var z = Vector.ByCoordinates(0, 0, 1);

            var originTop = Point.ByCoordinates(0, 0, 10);
            var x1 = Vector.ByCoordinates(.5, .5, 0).Normalized();
            var y1 = x1.Cross(z);

            var csBottom = CoordinateSystem.ByOriginVectors(originBottom, x, y, z);
            var csTop = CoordinateSystem.ByOriginVectors(originTop, x1, y1, z);

            var bottCurves = rect1.Select(crv => crv.Transform(CoordinateSystem.Identity(), csBottom)).Cast<Curve>().ToList();
            var topCurves = rect2.Select(crv => crv.Transform(CoordinateSystem.Identity(), csTop)).Cast<Curve>().ToList();

            var blend = Solid.ByBlend(new List<PolyCurve> { PolyCurve.ByJoinedCurves(bottCurves.ToArray()),
                PolyCurve.ByJoinedCurves(topCurves.ToArray()) });
            Assert.NotNull(blend);

            var package = new RenderPackage();
            blend.Tessellate(package);

            var modelPath = Path.Combine(TestGeometryDirectory, @"ByBlend_ValidArgs.obj");
            if (File.Exists(modelPath))
                File.Delete(modelPath);
            WriteToOBJ(modelPath, new List<RenderPackage>() { package });
        }
Пример #17
0
        private void ConvertPoints(RenderPackage p,
            ICollection<Point3D> pointColl,
            ICollection<BillboardTextItem> text)
        {
            for (int i = 0; i < p.PointVertices.Count; i += 3)
            {

                var pos = new Point3D(
                    p.PointVertices[i],
                    p.PointVertices[i + 1],
                    p.PointVertices[i + 2]);

                pointColl.Add(pos);

                if (p.DisplayLabels)
                {
                    text.Add(new BillboardTextItem {Text = CleanTag(p.Tag), Position = pos});
                }
            }
        }
Пример #18
0
 private RenderPackage PackageRenderData(IGraphicItem gItem)
 {
     var renderPackage = new RenderPackage();
     gItem.Tessellate(renderPackage, -1.0, this.DynamoViewModel.VisualizationManager.MaxTesselationDivisions);
     renderPackage.ItemsCount++;
     return renderPackage;
 }
Пример #19
0
        private void ConvertMeshes(RenderPackage p,
            ICollection<Point3D> points, ICollection<Vector3D> norms,
            ICollection<int> tris)
        {
            for (int i = 0; i < p.TriangleVertices.Count; i+=3)
            {
                var new_point = new Point3D(p.TriangleVertices[i],
                                            p.TriangleVertices[i + 1],
                                            p.TriangleVertices[i + 2]);

                var normal = new Vector3D(p.TriangleNormals[i],
                                            p.TriangleNormals[i + 1],
                                            p.TriangleNormals[i + 2]);
                    
                tris.Add(points.Count);
                points.Add(new_point);
                norms.Add(normal);
            }

            if (tris.Count > 0)
            {
                MeshCount++;
            }
        }
Пример #20
0
        public void ByBooleanUnion_ValidArgs()
        {
            var solidA = Solid.BoxByCenterAndDimensions(Point.ByCoordinates(0, 0, 0), 1, 1, 1);
            var solidB = Solid.Sphere(Point.ByCoordinates(1, 1, 0), 1);
            var union = Solid.ByBooleanUnion(solidA, solidB);
            Assert.IsNotNull(union);

            var package = new RenderPackage();
            union.Tessellate(package);

            var modelPath = Path.Combine(TestGeometryDirectory, @"ByBooleanUnion_ValidArgs.obj");
            if (File.Exists(modelPath))
                File.Delete(modelPath);
            WriteToOBJ(modelPath, new List<RenderPackage>() { package });
        }